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 hubdev->hdi_flush_nasid_list.widget_p[widget] =
226 sn_flush_device_list;
233 void sn_pci_unfixup_slot(struct pci_dev *dev)
235 struct pci_dev *host_pci_dev = SN_PCIDEV_INFO(dev)->host_pci_dev;
238 pci_dev_put(host_pci_dev);
243 * sn_pci_fixup_slot() - This routine sets up a slot's resources
244 * consistent with the Linux PCI abstraction layer. Resources acquired
245 * from our PCI provider include PIO maps to BAR space and interrupt
248 void sn_pci_fixup_slot(struct pci_dev *dev)
251 int segment = pci_domain_nr(dev->bus);
253 struct pcibus_bussoft *bs;
254 struct pci_bus *host_pci_bus;
255 struct pci_dev *host_pci_dev;
256 struct sn_irq_info *sn_irq_info;
258 unsigned int bus_no, devfn;
260 pci_dev_get(dev); /* for the sysdata pointer */
261 dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
262 if (SN_PCIDEV_INFO(dev) <= 0)
263 BUG(); /* Cannot afford to run out of memory */
264 memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
266 sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
267 if (sn_irq_info <= 0)
268 BUG(); /* Cannot afford to run out of memory */
269 memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
271 /* Call to retrieve pci device information needed by kernel. */
272 status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
274 (u64) __pa(SN_PCIDEV_INFO(dev)),
275 (u64) __pa(sn_irq_info));
277 BUG(); /* Cannot get platform pci device information */
279 /* Copy over PIO Mapped Addresses */
280 for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
281 unsigned long start, end, addr;
283 if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
286 start = dev->resource[idx].start;
287 end = dev->resource[idx].end;
289 addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
290 addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
291 dev->resource[idx].start = addr;
292 dev->resource[idx].end = addr + size;
293 if (dev->resource[idx].flags & IORESOURCE_IO)
294 dev->resource[idx].parent = &ioport_resource;
296 dev->resource[idx].parent = &iomem_resource;
300 * Using the PROMs values for the PCI host bus, get the Linux
301 * PCI host_pci_dev struct and set up host bus linkages
304 bus_no = (SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32) & 0xff;
305 devfn = SN_PCIDEV_INFO(dev)->pdi_slot_host_handle & 0xffffffff;
306 host_pci_bus = pci_find_bus(segment, bus_no);
307 host_pci_dev = pci_get_slot(host_pci_bus, devfn);
309 SN_PCIDEV_INFO(dev)->host_pci_dev = host_pci_dev;
310 SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
311 SN_PCIDEV_INFO(host_pci_dev);
312 SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
313 bs = SN_PCIBUS_BUSSOFT(dev->bus);
314 SN_PCIDEV_INFO(dev)->pdi_pcibus_info = bs;
316 if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
317 SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
319 SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
322 /* Only set up IRQ stuff if this device has a host bus context */
323 if (bs && sn_irq_info->irq_irq) {
324 SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
325 dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
326 sn_irq_fixup(dev, sn_irq_info);
328 SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = NULL;
334 * sn_pci_controller_fixup() - This routine sets up a bus's resources
335 * consistent with the Linux PCI abstraction layer.
337 void sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
341 struct pci_controller *controller;
342 struct pcibus_bussoft *prom_bussoft_ptr;
343 struct hubdev_info *hubdev_info;
345 struct sn_pcibus_provider *provider;
347 status = sal_get_pcibus_info((u64) segment, (u64) busnum,
348 (u64) ia64_tpa(&prom_bussoft_ptr));
350 return; /*bus # does not exist */
351 prom_bussoft_ptr = __va(prom_bussoft_ptr);
353 controller = kcalloc(1,sizeof(struct pci_controller), GFP_KERNEL);
354 controller->segment = segment;
359 bus = pci_scan_bus(busnum, &pci_root_ops, controller);
361 return; /* error, or bus already scanned */
366 goto error_return; /* sysdata already alloc'd */
369 * Per-provider fixup. Copies the contents from prom to local
370 * area and links SN_PCIBUS_BUSSOFT().
373 if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES)
374 return; /* unsupported asic type */
376 if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB)
377 goto error_return; /* no further fixup necessary */
379 provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
380 if (provider == NULL)
381 return; /* no provider registerd for this asic */
383 provider_soft = NULL;
384 if (provider->bus_fixup)
385 provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr, controller);
387 if (provider_soft == NULL)
388 return; /* fixup failed or not applicable */
391 * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
395 bus->sysdata = controller;
396 PCI_CONTROLLER(bus)->platform_data = provider_soft;
397 nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
398 cnode = nasid_to_cnodeid(nasid);
399 hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
400 SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
401 &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
404 * If the node information we obtained during the fixup phase is invalid
405 * then set controller->node to -1 (undetermined)
407 if (controller->node >= num_online_nodes()) {
408 struct pcibus_bussoft *b = SN_PCIBUS_BUSSOFT(bus);
410 printk(KERN_WARNING "Device ASIC=%u XID=%u PBUSNUM=%u"
411 "L_IO=%lx L_MEM=%lx BASE=%lx\n",
412 b->bs_asic_type, b->bs_xid, b->bs_persist_busnum,
413 b->bs_legacy_io, b->bs_legacy_mem, b->bs_base);
414 printk(KERN_WARNING "on node %d but only %d nodes online."
415 "Association set to undetermined.\n",
416 controller->node, num_online_nodes());
417 controller->node = -1;
427 void sn_bus_store_sysdata(struct pci_dev *dev)
429 struct sysdata_el *element;
431 element = kcalloc(1, sizeof(struct sysdata_el), GFP_KERNEL);
433 dev_dbg(dev, "%s: out of memory!\n", __FUNCTION__);
436 element->sysdata = dev->sysdata;
437 list_add(&element->entry, &sn_sysdata_list);
440 void sn_bus_free_sysdata(void)
442 struct sysdata_el *element;
443 struct list_head *list;
445 sn_sysdata_free_start:
446 list_for_each(list, &sn_sysdata_list) {
447 element = list_entry(list, struct sysdata_el, entry);
448 list_del(&element->entry);
449 kfree(element->sysdata);
451 goto sn_sysdata_free_start;
457 * Ugly hack to get PCI setup until we have a proper ACPI namespace.
460 #define PCI_BUSES_TO_SCAN 256
462 static int __init sn_pci_init(void)
466 struct pci_dev *pci_dev = NULL;
467 extern void sn_init_cpei_timer(void);
468 #ifdef CONFIG_PROC_FS
469 extern void register_sn_procfs(void);
472 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
476 * prime sn_pci_provider[]. Individial provider init routines will
477 * override their respective default entries.
480 for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
481 sn_pci_provider[i] = &sn_pci_default_provider;
483 pcibr_init_provider();
484 tioca_init_provider();
485 tioce_init_provider();
488 * This is needed to avoid bounce limit checks in the blk layer
490 ia64_max_iommu_merge_mask = ~PAGE_MASK;
493 INIT_LIST_HEAD(&sn_sysdata_list);
494 sn_init_cpei_timer();
496 #ifdef CONFIG_PROC_FS
497 register_sn_procfs();
500 /* busses are not known yet ... */
501 for (i = 0; i <= max_segment_number; i++)
502 for (j = 0; j <= max_pcibus_number; j++)
503 sn_pci_controller_fixup(i, j, NULL);
506 * Generic Linux PCI Layer has created the pci_bus and pci_dev
507 * structures - time for us to add our SN PLatform specific
512 pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL)
513 sn_pci_fixup_slot(pci_dev);
515 sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
521 * hubdev_init_node() - Creates the HUB data structure and link them to it's
522 * own NODE specific data area.
524 void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
527 struct hubdev_info *hubdev_info;
529 if (node >= num_online_nodes()) /* Headless/memless IO nodes */
531 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
536 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
539 npda->pdinfo = (void *)hubdev_info;
544 cnodeid_get_geoid(cnodeid_t cnode)
547 struct hubdev_info *hubdev;
549 hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
550 return hubdev->hdi_geoid;
554 subsys_initcall(sn_pci_init);
555 EXPORT_SYMBOL(sn_pci_fixup_slot);
556 EXPORT_SYMBOL(sn_pci_unfixup_slot);
557 EXPORT_SYMBOL(sn_pci_controller_fixup);
558 EXPORT_SYMBOL(sn_bus_store_sysdata);
559 EXPORT_SYMBOL(sn_bus_free_sysdata);