2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1992 - 1997, 2000-2004 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/bootmem.h>
10 #include <linux/nodemask.h>
11 #include <asm/sn/types.h>
12 #include <asm/sn/addrs.h>
13 #include <asm/sn/geo.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/pcibr_provider.h>
16 #include <asm/sn/pcibus_provider_defs.h>
17 #include <asm/sn/pcidev.h>
18 #include <asm/sn/simulator.h>
19 #include <asm/sn/sn_sal.h>
20 #include <asm/sn/tioca_provider.h>
21 #include <asm/sn/tioce_provider.h>
22 #include "xtalk/hubdev.h"
23 #include "xtalk/xwidgetdev.h"
25 nasid_t master_nasid
= INVALID_NASID
; /* Partition Master */
27 static struct list_head sn_sysdata_list
;
29 /* sysdata list struct */
31 struct list_head entry
;
36 struct hubdev_info hubdev
;
40 moduleid_t id
; /* Module ID of this module */
41 struct slab_info slab_info
[MAX_SLABS
+ 1];
44 int sn_ioif_inited
= 0; /* SN I/O infrastructure initialized? */
46 struct sn_pcibus_provider
*sn_pci_provider
[PCIIO_ASIC_MAX_TYPES
]; /* indexed by asic type */
48 static int max_segment_number
= 0; /* Default highest segment number */
49 static int max_pcibus_number
= 255; /* Default highest pci bus number */
52 * Hooks and struct for unsupported pci providers
56 sn_default_pci_map(struct pci_dev
*pdev
, unsigned long paddr
, size_t size
)
62 sn_default_pci_unmap(struct pci_dev
*pdev
, dma_addr_t addr
, int direction
)
68 sn_default_pci_bus_fixup(struct pcibus_bussoft
*soft
, struct pci_controller
*controller
)
73 static struct sn_pcibus_provider sn_pci_default_provider
= {
74 .dma_map
= sn_default_pci_map
,
75 .dma_map_consistent
= sn_default_pci_map
,
76 .dma_unmap
= sn_default_pci_unmap
,
77 .bus_fixup
= sn_default_pci_bus_fixup
,
81 * Retrieve the DMA Flush List given nasid. This list is needed
82 * to implement the WAR - Flush DMA data on PIO Reads.
84 static inline uint64_t
85 sal_get_widget_dmaflush_list(u64 nasid
, u64 widget_num
, u64 address
)
88 struct ia64_sal_retval ret_stuff
;
92 SAL_CALL_NOLOCK(ret_stuff
,
93 (u64
) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST
,
94 (u64
) nasid
, (u64
) widget_num
, (u64
) address
, 0, 0, 0,
101 * Retrieve the hub device info structure for the given nasid.
103 static inline uint64_t sal_get_hubdev_info(u64 handle
, u64 address
)
106 struct ia64_sal_retval ret_stuff
;
107 ret_stuff
.status
= 0;
110 SAL_CALL_NOLOCK(ret_stuff
,
111 (u64
) SN_SAL_IOIF_GET_HUBDEV_INFO
,
112 (u64
) handle
, (u64
) address
, 0, 0, 0, 0, 0);
117 * Retrieve the pci bus information given the bus number.
119 static inline uint64_t sal_get_pcibus_info(u64 segment
, u64 busnum
, u64 address
)
122 struct ia64_sal_retval ret_stuff
;
123 ret_stuff
.status
= 0;
126 SAL_CALL_NOLOCK(ret_stuff
,
127 (u64
) SN_SAL_IOIF_GET_PCIBUS_INFO
,
128 (u64
) segment
, (u64
) busnum
, (u64
) address
, 0, 0, 0, 0);
133 * Retrieve the pci device information given the bus and device|function number.
135 static inline uint64_t
136 sal_get_pcidev_info(u64 segment
, u64 bus_number
, u64 devfn
, u64 pci_dev
,
139 struct ia64_sal_retval ret_stuff
;
140 ret_stuff
.status
= 0;
143 SAL_CALL_NOLOCK(ret_stuff
,
144 (u64
) SN_SAL_IOIF_GET_PCIDEV_INFO
,
145 (u64
) segment
, (u64
) bus_number
, (u64
) devfn
,
152 * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
153 * each node in the system.
155 static void sn_fixup_ionodes(void)
158 struct sn_flush_device_list
*sn_flush_device_list
;
159 struct hubdev_info
*hubdev
;
165 * Get SGI Specific HUB chipset information.
166 * Inform Prom that this kernel can support domain bus numbering.
168 for (i
= 0; i
< numionodes
; i
++) {
169 hubdev
= (struct hubdev_info
*)(NODEPDA(i
)->pdinfo
);
170 nasid
= cnodeid_to_nasid(i
);
171 hubdev
->max_segment_number
= 0xffffffff;
172 hubdev
->max_pcibus_number
= 0xff;
173 status
= sal_get_hubdev_info(nasid
, (uint64_t) __pa(hubdev
));
177 /* Save the largest Domain and pcibus numbers found. */
178 if (hubdev
->max_segment_number
) {
180 * Dealing with a Prom that supports segments.
182 max_segment_number
= hubdev
->max_segment_number
;
183 max_pcibus_number
= hubdev
->max_pcibus_number
;
186 /* Attach the error interrupt handlers */
188 ice_error_init(hubdev
);
190 hub_error_init(hubdev
);
192 for (widget
= 0; widget
<= HUB_WIDGET_ID_MAX
; widget
++)
193 hubdev
->hdi_xwidget_info
[widget
].xwi_hubinfo
= hubdev
;
195 if (!hubdev
->hdi_flush_nasid_list
.widget_p
)
198 hubdev
->hdi_flush_nasid_list
.widget_p
=
199 kmalloc((HUB_WIDGET_ID_MAX
+ 1) *
200 sizeof(struct sn_flush_device_list
*), GFP_KERNEL
);
202 memset(hubdev
->hdi_flush_nasid_list
.widget_p
, 0x0,
203 (HUB_WIDGET_ID_MAX
+ 1) *
204 sizeof(struct sn_flush_device_list
*));
206 for (widget
= 0; widget
<= HUB_WIDGET_ID_MAX
; widget
++) {
207 sn_flush_device_list
= kmalloc(DEV_PER_WIDGET
*
209 sn_flush_device_list
),
211 memset(sn_flush_device_list
, 0x0,
213 sizeof(struct sn_flush_device_list
));
216 sal_get_widget_dmaflush_list(nasid
, widget
,
219 (sn_flush_device_list
));
221 kfree(sn_flush_device_list
);
225 spin_lock_init(&sn_flush_device_list
->sfdl_flush_lock
);
226 hubdev
->hdi_flush_nasid_list
.widget_p
[widget
] =
227 sn_flush_device_list
;
234 void sn_pci_unfixup_slot(struct pci_dev
*dev
)
236 struct pci_dev
*host_pci_dev
= SN_PCIDEV_INFO(dev
)->host_pci_dev
;
239 pci_dev_put(host_pci_dev
);
244 * sn_pci_fixup_slot() - This routine sets up a slot's resources
245 * consistent with the Linux PCI abstraction layer. Resources acquired
246 * from our PCI provider include PIO maps to BAR space and interrupt
249 void sn_pci_fixup_slot(struct pci_dev
*dev
)
252 int segment
= pci_domain_nr(dev
->bus
);
254 struct pcibus_bussoft
*bs
;
255 struct pci_bus
*host_pci_bus
;
256 struct pci_dev
*host_pci_dev
;
257 struct sn_irq_info
*sn_irq_info
;
259 unsigned int bus_no
, devfn
;
261 pci_dev_get(dev
); /* for the sysdata pointer */
262 dev
->sysdata
= kmalloc(sizeof(struct pcidev_info
), GFP_KERNEL
);
263 if (SN_PCIDEV_INFO(dev
) <= 0)
264 BUG(); /* Cannot afford to run out of memory */
265 memset(SN_PCIDEV_INFO(dev
), 0, sizeof(struct pcidev_info
));
267 sn_irq_info
= kmalloc(sizeof(struct sn_irq_info
), GFP_KERNEL
);
268 if (sn_irq_info
<= 0)
269 BUG(); /* Cannot afford to run out of memory */
270 memset(sn_irq_info
, 0, sizeof(struct sn_irq_info
));
272 /* Call to retrieve pci device information needed by kernel. */
273 status
= sal_get_pcidev_info((u64
) segment
, (u64
) dev
->bus
->number
,
275 (u64
) __pa(SN_PCIDEV_INFO(dev
)),
276 (u64
) __pa(sn_irq_info
));
278 BUG(); /* Cannot get platform pci device information */
280 /* Copy over PIO Mapped Addresses */
281 for (idx
= 0; idx
<= PCI_ROM_RESOURCE
; idx
++) {
282 unsigned long start
, end
, addr
;
284 if (!SN_PCIDEV_INFO(dev
)->pdi_pio_mapped_addr
[idx
])
287 start
= dev
->resource
[idx
].start
;
288 end
= dev
->resource
[idx
].end
;
290 addr
= SN_PCIDEV_INFO(dev
)->pdi_pio_mapped_addr
[idx
];
291 addr
= ((addr
<< 4) >> 4) | __IA64_UNCACHED_OFFSET
;
292 dev
->resource
[idx
].start
= addr
;
293 dev
->resource
[idx
].end
= addr
+ size
;
294 if (dev
->resource
[idx
].flags
& IORESOURCE_IO
)
295 dev
->resource
[idx
].parent
= &ioport_resource
;
297 dev
->resource
[idx
].parent
= &iomem_resource
;
301 * Using the PROMs values for the PCI host bus, get the Linux
302 * PCI host_pci_dev struct and set up host bus linkages
305 bus_no
= (SN_PCIDEV_INFO(dev
)->pdi_slot_host_handle
>> 32) & 0xff;
306 devfn
= SN_PCIDEV_INFO(dev
)->pdi_slot_host_handle
& 0xffffffff;
307 host_pci_bus
= pci_find_bus(segment
, bus_no
);
308 host_pci_dev
= pci_get_slot(host_pci_bus
, devfn
);
310 SN_PCIDEV_INFO(dev
)->host_pci_dev
= host_pci_dev
;
311 SN_PCIDEV_INFO(dev
)->pdi_host_pcidev_info
=
312 SN_PCIDEV_INFO(host_pci_dev
);
313 SN_PCIDEV_INFO(dev
)->pdi_linux_pcidev
= dev
;
314 bs
= SN_PCIBUS_BUSSOFT(dev
->bus
);
315 SN_PCIDEV_INFO(dev
)->pdi_pcibus_info
= bs
;
317 if (bs
&& bs
->bs_asic_type
< PCIIO_ASIC_MAX_TYPES
) {
318 SN_PCIDEV_BUSPROVIDER(dev
) = sn_pci_provider
[bs
->bs_asic_type
];
320 SN_PCIDEV_BUSPROVIDER(dev
) = &sn_pci_default_provider
;
323 /* Only set up IRQ stuff if this device has a host bus context */
324 if (bs
&& sn_irq_info
->irq_irq
) {
325 SN_PCIDEV_INFO(dev
)->pdi_sn_irq_info
= sn_irq_info
;
326 dev
->irq
= SN_PCIDEV_INFO(dev
)->pdi_sn_irq_info
->irq_irq
;
327 sn_irq_fixup(dev
, sn_irq_info
);
329 SN_PCIDEV_INFO(dev
)->pdi_sn_irq_info
= NULL
;
335 * sn_pci_controller_fixup() - This routine sets up a bus's resources
336 * consistent with the Linux PCI abstraction layer.
338 void sn_pci_controller_fixup(int segment
, int busnum
, struct pci_bus
*bus
)
342 struct pci_controller
*controller
;
343 struct pcibus_bussoft
*prom_bussoft_ptr
;
344 struct hubdev_info
*hubdev_info
;
345 void *provider_soft
= NULL
;
346 struct sn_pcibus_provider
*provider
;
348 status
= sal_get_pcibus_info((u64
) segment
, (u64
) busnum
,
349 (u64
) ia64_tpa(&prom_bussoft_ptr
));
351 return; /*bus # does not exist */
352 prom_bussoft_ptr
= __va(prom_bussoft_ptr
);
354 controller
= kcalloc(1,sizeof(struct pci_controller
), GFP_KERNEL
);
355 controller
->segment
= segment
;
360 bus
= pci_scan_bus(busnum
, &pci_root_ops
, controller
);
362 goto error_return
; /* error, or bus already scanned */
367 goto error_return
; /* sysdata already alloc'd */
370 * Per-provider fixup. Copies the contents from prom to local
371 * area and links SN_PCIBUS_BUSSOFT().
374 if (prom_bussoft_ptr
->bs_asic_type
>= PCIIO_ASIC_MAX_TYPES
)
375 goto error_return
; /* unsupported asic type */
377 if (prom_bussoft_ptr
->bs_asic_type
== PCIIO_ASIC_TYPE_PPB
)
378 goto error_return
; /* no further fixup necessary */
380 provider
= sn_pci_provider
[prom_bussoft_ptr
->bs_asic_type
];
381 if (provider
== NULL
)
382 goto error_return
; /* no provider registerd for this asic */
384 bus
->sysdata
= controller
;
385 if (provider
->bus_fixup
)
386 provider_soft
= (*provider
->bus_fixup
) (prom_bussoft_ptr
, controller
);
388 if (provider_soft
== NULL
) {
389 /* fixup failed or not applicable */
395 * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
399 PCI_CONTROLLER(bus
)->platform_data
= provider_soft
;
400 nasid
= NASID_GET(SN_PCIBUS_BUSSOFT(bus
)->bs_base
);
401 cnode
= nasid_to_cnodeid(nasid
);
402 hubdev_info
= (struct hubdev_info
*)(NODEPDA(cnode
)->pdinfo
);
403 SN_PCIBUS_BUSSOFT(bus
)->bs_xwidget_info
=
404 &(hubdev_info
->hdi_xwidget_info
[SN_PCIBUS_BUSSOFT(bus
)->bs_xid
]);
407 * If the node information we obtained during the fixup phase is invalid
408 * then set controller->node to -1 (undetermined)
410 if (controller
->node
>= num_online_nodes()) {
411 struct pcibus_bussoft
*b
= SN_PCIBUS_BUSSOFT(bus
);
413 printk(KERN_WARNING
"Device ASIC=%u XID=%u PBUSNUM=%u"
414 "L_IO=%lx L_MEM=%lx BASE=%lx\n",
415 b
->bs_asic_type
, b
->bs_xid
, b
->bs_persist_busnum
,
416 b
->bs_legacy_io
, b
->bs_legacy_mem
, b
->bs_base
);
417 printk(KERN_WARNING
"on node %d but only %d nodes online."
418 "Association set to undetermined.\n",
419 controller
->node
, num_online_nodes());
420 controller
->node
= -1;
430 void sn_bus_store_sysdata(struct pci_dev
*dev
)
432 struct sysdata_el
*element
;
434 element
= kzalloc(sizeof(struct sysdata_el
), GFP_KERNEL
);
436 dev_dbg(dev
, "%s: out of memory!\n", __FUNCTION__
);
439 element
->sysdata
= dev
->sysdata
;
440 list_add(&element
->entry
, &sn_sysdata_list
);
443 void sn_bus_free_sysdata(void)
445 struct sysdata_el
*element
;
446 struct list_head
*list
;
448 sn_sysdata_free_start
:
449 list_for_each(list
, &sn_sysdata_list
) {
450 element
= list_entry(list
, struct sysdata_el
, entry
);
451 list_del(&element
->entry
);
452 kfree(element
->sysdata
);
454 goto sn_sysdata_free_start
;
460 * Ugly hack to get PCI setup until we have a proper ACPI namespace.
463 #define PCI_BUSES_TO_SCAN 256
465 static int __init
sn_pci_init(void)
469 struct pci_dev
*pci_dev
= NULL
;
470 extern void sn_init_cpei_timer(void);
471 #ifdef CONFIG_PROC_FS
472 extern void register_sn_procfs(void);
475 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
479 * prime sn_pci_provider[]. Individial provider init routines will
480 * override their respective default entries.
483 for (i
= 0; i
< PCIIO_ASIC_MAX_TYPES
; i
++)
484 sn_pci_provider
[i
] = &sn_pci_default_provider
;
486 pcibr_init_provider();
487 tioca_init_provider();
488 tioce_init_provider();
491 * This is needed to avoid bounce limit checks in the blk layer
493 ia64_max_iommu_merge_mask
= ~PAGE_MASK
;
496 INIT_LIST_HEAD(&sn_sysdata_list
);
497 sn_init_cpei_timer();
499 #ifdef CONFIG_PROC_FS
500 register_sn_procfs();
503 /* busses are not known yet ... */
504 for (i
= 0; i
<= max_segment_number
; i
++)
505 for (j
= 0; j
<= max_pcibus_number
; j
++)
506 sn_pci_controller_fixup(i
, j
, NULL
);
509 * Generic Linux PCI Layer has created the pci_bus and pci_dev
510 * structures - time for us to add our SN PLatform specific
515 pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_dev
)) != NULL
)
516 sn_pci_fixup_slot(pci_dev
);
518 sn_ioif_inited
= 1; /* sn I/O infrastructure now initialized */
524 * hubdev_init_node() - Creates the HUB data structure and link them to it's
525 * own NODE specific data area.
527 void hubdev_init_node(nodepda_t
* npda
, cnodeid_t node
)
530 struct hubdev_info
*hubdev_info
;
532 if (node
>= num_online_nodes()) /* Headless/memless IO nodes */
534 (struct hubdev_info
*)alloc_bootmem_node(NODE_DATA(0),
539 (struct hubdev_info
*)alloc_bootmem_node(NODE_DATA(node
),
542 npda
->pdinfo
= (void *)hubdev_info
;
547 cnodeid_get_geoid(cnodeid_t cnode
)
550 struct hubdev_info
*hubdev
;
552 hubdev
= (struct hubdev_info
*)(NODEPDA(cnode
)->pdinfo
);
553 return hubdev
->hdi_geoid
;
557 subsys_initcall(sn_pci_init
);
558 EXPORT_SYMBOL(sn_pci_fixup_slot
);
559 EXPORT_SYMBOL(sn_pci_unfixup_slot
);
560 EXPORT_SYMBOL(sn_pci_controller_fixup
);
561 EXPORT_SYMBOL(sn_bus_store_sysdata
);
562 EXPORT_SYMBOL(sn_bus_free_sysdata
);