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 "xtalk/hubdev.h"
22 #include "xtalk/xwidgetdev.h"
24 nasid_t master_nasid = INVALID_NASID; /* Partition Master */
26 static struct list_head sn_sysdata_list;
28 /* sysdata list struct */
30 struct list_head entry;
35 struct hubdev_info hubdev;
39 moduleid_t id; /* Module ID of this module */
40 struct slab_info slab_info[MAX_SLABS + 1];
43 int sn_ioif_inited = 0; /* SN I/O infrastructure initialized? */
45 struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
48 * Hooks and struct for unsupported pci providers
52 sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size)
58 sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
64 sn_default_pci_bus_fixup(struct pcibus_bussoft *soft, struct pci_controller *controller)
69 static struct sn_pcibus_provider sn_pci_default_provider = {
70 .dma_map = sn_default_pci_map,
71 .dma_map_consistent = sn_default_pci_map,
72 .dma_unmap = sn_default_pci_unmap,
73 .bus_fixup = sn_default_pci_bus_fixup,
77 * Retrieve the DMA Flush List given nasid. This list is needed
78 * to implement the WAR - Flush DMA data on PIO Reads.
80 static inline uint64_t
81 sal_get_widget_dmaflush_list(u64 nasid, u64 widget_num, u64 address)
84 struct ia64_sal_retval ret_stuff;
88 SAL_CALL_NOLOCK(ret_stuff,
89 (u64) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
90 (u64) nasid, (u64) widget_num, (u64) address, 0, 0, 0,
97 * Retrieve the hub device info structure for the given nasid.
99 static inline uint64_t sal_get_hubdev_info(u64 handle, u64 address)
102 struct ia64_sal_retval ret_stuff;
103 ret_stuff.status = 0;
106 SAL_CALL_NOLOCK(ret_stuff,
107 (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
108 (u64) handle, (u64) address, 0, 0, 0, 0, 0);
113 * Retrieve the pci bus information given the bus number.
115 static inline uint64_t sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
118 struct ia64_sal_retval ret_stuff;
119 ret_stuff.status = 0;
122 SAL_CALL_NOLOCK(ret_stuff,
123 (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
124 (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
129 * Retrieve the pci device information given the bus and device|function number.
131 static inline uint64_t
132 sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
135 struct ia64_sal_retval ret_stuff;
136 ret_stuff.status = 0;
139 SAL_CALL_NOLOCK(ret_stuff,
140 (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
141 (u64) segment, (u64) bus_number, (u64) devfn,
148 * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
149 * each node in the system.
151 static void sn_fixup_ionodes(void)
154 struct sn_flush_device_list *sn_flush_device_list;
155 struct hubdev_info *hubdev;
160 for (i = 0; i < numionodes; i++) {
161 hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
162 nasid = cnodeid_to_nasid(i);
163 status = sal_get_hubdev_info(nasid, (uint64_t) __pa(hubdev));
167 /* Attach the error interrupt handlers */
169 ice_error_init(hubdev);
171 hub_error_init(hubdev);
173 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
174 hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
176 if (!hubdev->hdi_flush_nasid_list.widget_p)
179 hubdev->hdi_flush_nasid_list.widget_p =
180 kmalloc((HUB_WIDGET_ID_MAX + 1) *
181 sizeof(struct sn_flush_device_list *), GFP_KERNEL);
183 memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
184 (HUB_WIDGET_ID_MAX + 1) *
185 sizeof(struct sn_flush_device_list *));
187 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
188 sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
190 sn_flush_device_list),
192 memset(sn_flush_device_list, 0x0,
194 sizeof(struct sn_flush_device_list));
197 sal_get_widget_dmaflush_list(nasid, widget,
200 (sn_flush_device_list));
202 kfree(sn_flush_device_list);
206 spin_lock_init(&sn_flush_device_list->sfdl_flush_lock);
207 hubdev->hdi_flush_nasid_list.widget_p[widget] =
208 sn_flush_device_list;
215 void sn_pci_unfixup_slot(struct pci_dev *dev)
217 struct pci_dev *host_pci_dev = SN_PCIDEV_INFO(dev)->host_pci_dev;
220 pci_dev_put(host_pci_dev);
225 * sn_pci_fixup_slot() - This routine sets up a slot's resources
226 * consistent with the Linux PCI abstraction layer. Resources acquired
227 * from our PCI provider include PIO maps to BAR space and interrupt
230 void sn_pci_fixup_slot(struct pci_dev *dev)
235 struct pcibus_bussoft *bs;
236 struct pci_bus *host_pci_bus;
237 struct pci_dev *host_pci_dev;
238 struct sn_irq_info *sn_irq_info;
240 unsigned int bus_no, devfn;
242 pci_dev_get(dev); /* for the sysdata pointer */
243 dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
244 if (SN_PCIDEV_INFO(dev) <= 0)
245 BUG(); /* Cannot afford to run out of memory */
246 memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
248 sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
249 if (sn_irq_info <= 0)
250 BUG(); /* Cannot afford to run out of memory */
251 memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
253 /* Call to retrieve pci device information needed by kernel. */
254 status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
256 (u64) __pa(SN_PCIDEV_INFO(dev)),
257 (u64) __pa(sn_irq_info));
259 BUG(); /* Cannot get platform pci device information */
261 /* Copy over PIO Mapped Addresses */
262 for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
263 unsigned long start, end, addr;
265 if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
268 start = dev->resource[idx].start;
269 end = dev->resource[idx].end;
271 addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
272 addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
273 dev->resource[idx].start = addr;
274 dev->resource[idx].end = addr + size;
275 if (dev->resource[idx].flags & IORESOURCE_IO)
276 dev->resource[idx].parent = &ioport_resource;
278 dev->resource[idx].parent = &iomem_resource;
282 * Using the PROMs values for the PCI host bus, get the Linux
283 * PCI host_pci_dev struct and set up host bus linkages
286 bus_no = SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32;
287 devfn = SN_PCIDEV_INFO(dev)->pdi_slot_host_handle & 0xffffffff;
288 host_pci_bus = pci_find_bus(pci_domain_nr(dev->bus), bus_no);
289 host_pci_dev = pci_get_slot(host_pci_bus, devfn);
291 SN_PCIDEV_INFO(dev)->host_pci_dev = host_pci_dev;
292 SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
293 SN_PCIDEV_INFO(host_pci_dev);
294 SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
295 bs = SN_PCIBUS_BUSSOFT(dev->bus);
296 SN_PCIDEV_INFO(dev)->pdi_pcibus_info = bs;
298 if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
299 SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
301 SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
304 /* Only set up IRQ stuff if this device has a host bus context */
305 if (bs && sn_irq_info->irq_irq) {
306 SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
307 dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
308 sn_irq_fixup(dev, sn_irq_info);
310 SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = NULL;
316 * sn_pci_controller_fixup() - This routine sets up a bus's resources
317 * consistent with the Linux PCI abstraction layer.
319 void sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
323 struct pci_controller *controller;
324 struct pcibus_bussoft *prom_bussoft_ptr;
325 struct hubdev_info *hubdev_info;
326 void *provider_soft = NULL;
327 struct sn_pcibus_provider *provider;
329 status = sal_get_pcibus_info((u64) segment, (u64) busnum,
330 (u64) ia64_tpa(&prom_bussoft_ptr));
332 return; /*bus # does not exist */
333 prom_bussoft_ptr = __va(prom_bussoft_ptr);
335 controller = kcalloc(1,sizeof(struct pci_controller), GFP_KERNEL);
340 bus = pci_scan_bus(busnum, &pci_root_ops, controller);
342 goto error_return; /* error, or bus already scanned */
347 goto error_return; /* sysdata already alloc'd */
350 * Per-provider fixup. Copies the contents from prom to local
351 * area and links SN_PCIBUS_BUSSOFT().
354 if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES)
355 goto error_return; /* unsupported asic type */
357 if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB)
358 goto error_return; /* no further fixup necessary */
360 provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
361 if (provider == NULL)
362 goto error_return; /* no provider registerd for this asic */
364 bus->sysdata = controller;
365 if (provider->bus_fixup)
366 provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr, controller);
368 if (provider_soft == NULL) {
369 /* fixup failed or not applicable */
375 * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
379 PCI_CONTROLLER(bus)->platform_data = provider_soft;
380 nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
381 cnode = nasid_to_cnodeid(nasid);
382 hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
383 SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
384 &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
387 * If the node information we obtained during the fixup phase is invalid
388 * then set controller->node to -1 (undetermined)
390 if (controller->node >= num_online_nodes()) {
391 struct pcibus_bussoft *b = SN_PCIBUS_BUSSOFT(bus);
393 printk(KERN_WARNING "Device ASIC=%u XID=%u PBUSNUM=%lu"
394 "L_IO=%lx L_MEM=%lx BASE=%lx\n",
395 b->bs_asic_type, b->bs_xid, b->bs_persist_busnum,
396 b->bs_legacy_io, b->bs_legacy_mem, b->bs_base);
397 printk(KERN_WARNING "on node %d but only %d nodes online."
398 "Association set to undetermined.\n",
399 controller->node, num_online_nodes());
400 controller->node = -1;
410 void sn_bus_store_sysdata(struct pci_dev *dev)
412 struct sysdata_el *element;
414 element = kcalloc(1, sizeof(struct sysdata_el), GFP_KERNEL);
416 dev_dbg(dev, "%s: out of memory!\n", __FUNCTION__);
419 element->sysdata = dev->sysdata;
420 list_add(&element->entry, &sn_sysdata_list);
423 void sn_bus_free_sysdata(void)
425 struct sysdata_el *element;
426 struct list_head *list;
428 sn_sysdata_free_start:
429 list_for_each(list, &sn_sysdata_list) {
430 element = list_entry(list, struct sysdata_el, entry);
431 list_del(&element->entry);
432 kfree(element->sysdata);
434 goto sn_sysdata_free_start;
440 * Ugly hack to get PCI setup until we have a proper ACPI namespace.
443 #define PCI_BUSES_TO_SCAN 256
445 static int __init sn_pci_init(void)
448 struct pci_dev *pci_dev = NULL;
449 extern void sn_init_cpei_timer(void);
450 #ifdef CONFIG_PROC_FS
451 extern void register_sn_procfs(void);
454 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
458 * prime sn_pci_provider[]. Individial provider init routines will
459 * override their respective default entries.
462 for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
463 sn_pci_provider[i] = &sn_pci_default_provider;
465 pcibr_init_provider();
466 tioca_init_provider();
469 * This is needed to avoid bounce limit checks in the blk layer
471 ia64_max_iommu_merge_mask = ~PAGE_MASK;
474 INIT_LIST_HEAD(&sn_sysdata_list);
475 sn_init_cpei_timer();
477 #ifdef CONFIG_PROC_FS
478 register_sn_procfs();
481 /* busses are not known yet ... */
482 for (i = 0; i < PCI_BUSES_TO_SCAN; i++)
483 sn_pci_controller_fixup(0, i, NULL);
486 * Generic Linux PCI Layer has created the pci_bus and pci_dev
487 * structures - time for us to add our SN PLatform specific
492 pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL)
493 sn_pci_fixup_slot(pci_dev);
495 sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
501 * hubdev_init_node() - Creates the HUB data structure and link them to it's
502 * own NODE specific data area.
504 void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
507 struct hubdev_info *hubdev_info;
509 if (node >= num_online_nodes()) /* Headless/memless IO nodes */
511 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
516 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
519 npda->pdinfo = (void *)hubdev_info;
524 cnodeid_get_geoid(cnodeid_t cnode)
527 struct hubdev_info *hubdev;
529 hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
530 return hubdev->hdi_geoid;
534 subsys_initcall(sn_pci_init);
535 EXPORT_SYMBOL(sn_pci_fixup_slot);
536 EXPORT_SYMBOL(sn_pci_unfixup_slot);
537 EXPORT_SYMBOL(sn_pci_controller_fixup);
538 EXPORT_SYMBOL(sn_bus_store_sysdata);
539 EXPORT_SYMBOL(sn_bus_free_sysdata);