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) 2006 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/bootmem.h>
10 #include <asm/sn/types.h>
11 #include <asm/sn/addrs.h>
12 #include <asm/sn/sn_feature_sets.h>
13 #include <asm/sn/geo.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/l1.h>
16 #include <asm/sn/module.h>
17 #include <asm/sn/pcibr_provider.h>
18 #include <asm/sn/pcibus_provider_defs.h>
19 #include <asm/sn/pcidev.h>
20 #include <asm/sn/simulator.h>
21 #include <asm/sn/sn_sal.h>
22 #include <asm/sn/tioca_provider.h>
23 #include <asm/sn/tioce_provider.h>
24 #include "xtalk/hubdev.h"
25 #include "xtalk/xwidgetdev.h"
26 #include <linux/acpi.h>
27 #include <asm/sn/sn2/sn_hwperf.h>
29 extern void sn_init_cpei_timer(void);
30 extern void register_sn_procfs(void);
31 extern void sn_acpi_bus_fixup(struct pci_bus *);
32 extern void sn_bus_fixup(struct pci_bus *);
33 extern void sn_acpi_slot_fixup(struct pci_dev *, struct pcidev_info *);
34 extern void sn_more_slot_fixup(struct pci_dev *, struct pcidev_info *);
35 extern void sn_legacy_pci_window_fixup(struct pci_controller *, u64, u64);
36 extern void sn_io_acpi_init(void);
37 extern void sn_io_init(void);
39 static struct list_head sn_sysdata_list;
41 /* sysdata list struct */
43 struct list_head entry;
47 int sn_ioif_inited; /* SN I/O infrastructure initialized? */
49 struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
51 int sn_acpi_base_support()
53 struct acpi_table_header *header;
54 (void)acpi_get_table_by_index(ACPI_TABLE_INDEX_DSDT, &header);
55 if (header && header->oem_revision >= 0x20101)
61 * Hooks and struct for unsupported pci providers
65 sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size, int type)
71 sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
77 sn_default_pci_bus_fixup(struct pcibus_bussoft *soft, struct pci_controller *controller)
82 static struct sn_pcibus_provider sn_pci_default_provider = {
83 .dma_map = sn_default_pci_map,
84 .dma_map_consistent = sn_default_pci_map,
85 .dma_unmap = sn_default_pci_unmap,
86 .bus_fixup = sn_default_pci_bus_fixup,
90 * Retrieve the DMA Flush List given nasid, widget, and device.
91 * This list is needed to implement the WAR - Flush DMA data on PIO Reads.
94 sal_get_device_dmaflush_list(u64 nasid, u64 widget_num, u64 device_num,
97 struct ia64_sal_retval ret_stuff;
101 SAL_CALL_NOLOCK(ret_stuff,
102 (u64) SN_SAL_IOIF_GET_DEVICE_DMAFLUSH_LIST,
103 (u64) nasid, (u64) widget_num,
104 (u64) device_num, (u64) address, 0, 0, 0);
105 return ret_stuff.status;
109 * Retrieve the pci device information given the bus and device|function number.
112 sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
115 struct ia64_sal_retval ret_stuff;
116 ret_stuff.status = 0;
119 SAL_CALL_NOLOCK(ret_stuff,
120 (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
121 (u64) segment, (u64) bus_number, (u64) devfn,
128 * sn_pcidev_info_get() - Retrieve the pcidev_info struct for the specified
131 inline struct pcidev_info *
132 sn_pcidev_info_get(struct pci_dev *dev)
134 struct pcidev_info *pcidev;
136 list_for_each_entry(pcidev,
137 &(SN_PLATFORM_DATA(dev)->pcidev_info), pdi_list) {
138 if (pcidev->pdi_linux_pcidev == dev)
144 /* Older PROM flush WAR
146 * 01/16/06 -- This war will be in place until a new official PROM is released.
147 * Additionally note that the struct sn_flush_device_war also has to be
148 * removed from arch/ia64/sn/include/xtalk/hubdev.h
150 static u8 war_implemented = 0;
152 static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device,
153 struct sn_flush_device_common *common)
155 struct sn_flush_device_war *war_list;
156 struct sn_flush_device_war *dev_entry;
157 struct ia64_sal_retval isrv = {0,0,0,0};
159 if (!war_implemented) {
160 printk(KERN_WARNING "PROM version < 4.50 -- implementing old "
165 war_list = kzalloc(DEV_PER_WIDGET * sizeof(*war_list), GFP_KERNEL);
169 SAL_CALL_NOLOCK(isrv, SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
170 nasid, widget, __pa(war_list), 0, 0, 0 ,0);
172 panic("sn_device_fixup_war failed: %s\n",
173 ia64_sal_strerror(isrv.status));
175 dev_entry = war_list + device;
176 memcpy(common,dev_entry, sizeof(*common));
183 * sn_common_hubdev_init() - This routine is called to initialize the HUB data
184 * structure for each node in the system.
187 sn_common_hubdev_init(struct hubdev_info *hubdev)
190 struct sn_flush_device_kernel *sn_flush_device_kernel;
191 struct sn_flush_device_kernel *dev_entry;
193 int widget, device, size;
195 /* Attach the error interrupt handlers */
196 if (hubdev->hdi_nasid & 1) /* If TIO */
197 ice_error_init(hubdev);
199 hub_error_init(hubdev);
201 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
202 hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
204 if (!hubdev->hdi_flush_nasid_list.widget_p)
207 size = (HUB_WIDGET_ID_MAX + 1) *
208 sizeof(struct sn_flush_device_kernel *);
209 hubdev->hdi_flush_nasid_list.widget_p =
210 kzalloc(size, GFP_KERNEL);
211 if (!hubdev->hdi_flush_nasid_list.widget_p)
214 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
215 size = DEV_PER_WIDGET *
216 sizeof(struct sn_flush_device_kernel);
217 sn_flush_device_kernel = kzalloc(size, GFP_KERNEL);
218 if (!sn_flush_device_kernel)
221 dev_entry = sn_flush_device_kernel;
222 for (device = 0; device < DEV_PER_WIDGET;
223 device++, dev_entry++) {
224 size = sizeof(struct sn_flush_device_common);
225 dev_entry->common = kzalloc(size, GFP_KERNEL);
226 if (!dev_entry->common)
228 if (sn_prom_feature_available(PRF_DEVICE_FLUSH_LIST))
229 status = sal_get_device_dmaflush_list(
230 hubdev->hdi_nasid, widget, device,
231 (u64)(dev_entry->common));
233 status = sn_device_fixup_war(hubdev->hdi_nasid,
236 if (status != SALRET_OK)
237 panic("SAL call failed: %s\n",
238 ia64_sal_strerror(status));
240 spin_lock_init(&dev_entry->sfdl_flush_lock);
243 if (sn_flush_device_kernel)
244 hubdev->hdi_flush_nasid_list.widget_p[widget] =
245 sn_flush_device_kernel;
249 void sn_pci_unfixup_slot(struct pci_dev *dev)
251 struct pci_dev *host_pci_dev = SN_PCIDEV_INFO(dev)->host_pci_dev;
254 pci_dev_put(host_pci_dev);
259 * sn_pci_fixup_slot() - This routine sets up a slot's resources consistent
260 * with the Linux PCI abstraction layer. Resources
261 * acquired from our PCI provider include PIO maps
262 * to BAR space and interrupt objects.
264 void sn_pci_fixup_slot(struct pci_dev *dev)
266 int segment = pci_domain_nr(dev->bus);
268 struct pcibus_bussoft *bs;
269 struct pci_bus *host_pci_bus;
270 struct pci_dev *host_pci_dev;
271 struct pcidev_info *pcidev_info;
272 struct sn_irq_info *sn_irq_info;
273 unsigned int bus_no, devfn;
275 pci_dev_get(dev); /* for the sysdata pointer */
276 pcidev_info = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
278 BUG(); /* Cannot afford to run out of memory */
280 sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
282 BUG(); /* Cannot afford to run out of memory */
284 /* Call to retrieve pci device information needed by kernel. */
285 status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
287 (u64) __pa(pcidev_info),
288 (u64) __pa(sn_irq_info));
290 BUG(); /* Cannot get platform pci device information */
292 /* Add pcidev_info to list in pci_controller.platform_data */
293 list_add_tail(&pcidev_info->pdi_list,
294 &(SN_PLATFORM_DATA(dev->bus)->pcidev_info));
296 if (sn_acpi_base_support())
297 sn_acpi_slot_fixup(dev, pcidev_info);
299 sn_more_slot_fixup(dev, pcidev_info);
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 = (pcidev_info->pdi_slot_host_handle >> 32) & 0xff;
306 devfn = pcidev_info->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 pcidev_info->host_pci_dev = host_pci_dev;
311 pcidev_info->pdi_linux_pcidev = dev;
312 pcidev_info->pdi_host_pcidev_info = SN_PCIDEV_INFO(host_pci_dev);
313 bs = SN_PCIBUS_BUSSOFT(dev->bus);
314 pcidev_info->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 pcidev_info->pdi_sn_irq_info = sn_irq_info;
325 dev->irq = pcidev_info->pdi_sn_irq_info->irq_irq;
326 sn_irq_fixup(dev, sn_irq_info);
328 pcidev_info->pdi_sn_irq_info = NULL;
334 * sn_common_bus_fixup - Perform platform specific bus fixup.
335 * Execute the ASIC specific fixup routine
339 sn_common_bus_fixup(struct pci_bus *bus,
340 struct pcibus_bussoft *prom_bussoft_ptr)
343 struct pci_controller *controller;
344 struct hubdev_info *hubdev_info;
347 struct sn_pcibus_provider *provider;
348 struct sn_platform_data *sn_platform_data;
350 controller = PCI_CONTROLLER(bus);
352 * Per-provider fixup. Copies the bus soft structure from prom
353 * to local area and links SN_PCIBUS_BUSSOFT().
356 if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES) {
357 printk(KERN_WARNING "sn_common_bus_fixup: Unsupported asic type, %d",
358 prom_bussoft_ptr->bs_asic_type);
362 if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB)
363 return; /* no further fixup necessary */
365 provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
366 if (provider == NULL)
367 panic("sn_common_bus_fixup: No provider registered for this asic type, %d",
368 prom_bussoft_ptr->bs_asic_type);
370 if (provider->bus_fixup)
371 provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr,
374 provider_soft = NULL;
377 * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
380 controller->platform_data = kzalloc(sizeof(struct sn_platform_data),
382 if (controller->platform_data == NULL)
385 (struct sn_platform_data *) controller->platform_data;
386 sn_platform_data->provider_soft = provider_soft;
387 INIT_LIST_HEAD(&((struct sn_platform_data *)
388 controller->platform_data)->pcidev_info);
389 nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
390 cnode = nasid_to_cnodeid(nasid);
391 hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
392 SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
393 &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
396 * If the node information we obtained during the fixup phase is
397 * invalid then set controller->node to -1 (undetermined)
399 if (controller->node >= num_online_nodes()) {
400 struct pcibus_bussoft *b = SN_PCIBUS_BUSSOFT(bus);
402 printk(KERN_WARNING "Device ASIC=%u XID=%u PBUSNUM=%u"
403 "L_IO=%lx L_MEM=%lx BASE=%lx\n",
404 b->bs_asic_type, b->bs_xid, b->bs_persist_busnum,
405 b->bs_legacy_io, b->bs_legacy_mem, b->bs_base);
406 printk(KERN_WARNING "on node %d but only %d nodes online."
407 "Association set to undetermined.\n",
408 controller->node, num_online_nodes());
409 controller->node = -1;
413 void sn_bus_store_sysdata(struct pci_dev *dev)
415 struct sysdata_el *element;
417 element = kzalloc(sizeof(struct sysdata_el), GFP_KERNEL);
419 dev_dbg(dev, "%s: out of memory!\n", __FUNCTION__);
422 element->sysdata = SN_PCIDEV_INFO(dev);
423 list_add(&element->entry, &sn_sysdata_list);
426 void sn_bus_free_sysdata(void)
428 struct sysdata_el *element;
429 struct list_head *list, *safe;
431 list_for_each_safe(list, safe, &sn_sysdata_list) {
432 element = list_entry(list, struct sysdata_el, entry);
433 list_del(&element->entry);
434 list_del(&(((struct pcidev_info *)
435 (element->sysdata))->pdi_list));
436 kfree(element->sysdata);
443 * hubdev_init_node() - Creates the HUB data structure and link them to it's
444 * own NODE specific data area.
446 void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
448 struct hubdev_info *hubdev_info;
452 size = sizeof(struct hubdev_info);
454 if (node >= num_online_nodes()) /* Headless/memless IO nodes */
457 pg = NODE_DATA(node);
459 hubdev_info = (struct hubdev_info *)alloc_bootmem_node(pg, size);
461 npda->pdinfo = (void *)hubdev_info;
465 cnodeid_get_geoid(cnodeid_t cnode)
467 struct hubdev_info *hubdev;
469 hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
470 return hubdev->hdi_geoid;
473 void sn_generate_path(struct pci_bus *pci_bus, char *address)
481 nasid = NASID_GET(SN_PCIBUS_BUSSOFT(pci_bus)->bs_base);
482 cnode = nasid_to_cnodeid(nasid);
483 geoid = cnodeid_get_geoid(cnode);
484 moduleid = geo_module(geoid);
486 sprintf(address, "module_%c%c%c%c%.2d",
487 '0'+RACK_GET_CLASS(MODULE_GET_RACK(moduleid)),
488 '0'+RACK_GET_GROUP(MODULE_GET_RACK(moduleid)),
489 '0'+RACK_GET_NUM(MODULE_GET_RACK(moduleid)),
490 MODULE_GET_BTCHAR(moduleid), MODULE_GET_BPOS(moduleid));
492 /* Tollhouse requires slot id to be displayed */
493 bricktype = MODULE_GET_BTYPE(moduleid);
494 if ((bricktype == L1_BRICKTYPE_191010) ||
495 (bricktype == L1_BRICKTYPE_1932))
496 sprintf(address, "%s^%d", address, geo_slot(geoid));
500 * sn_pci_fixup_bus() - Perform SN specific setup of software structs
501 * (pcibus_bussoft, pcidev_info) and hardware
502 * registers, for the specified bus and devices under it.
505 sn_pci_fixup_bus(struct pci_bus *bus)
508 if (sn_acpi_base_support())
509 sn_acpi_bus_fixup(bus);
515 * sn_io_early_init - Perform early IO (and some non-IO) initialization.
516 * In particular, setup the sn_pci_provider[] array.
517 * This needs to be done prior to any bus scanning
518 * (acpi_scan_init()) in the ACPI case, as the SN
519 * bus fixup code will reference the array.
522 sn_io_early_init(void)
526 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
530 * prime sn_pci_provider[]. Individial provider init routines will
531 * override their respective default entries.
534 for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
535 sn_pci_provider[i] = &sn_pci_default_provider;
537 pcibr_init_provider();
538 tioca_init_provider();
539 tioce_init_provider();
542 * This is needed to avoid bounce limit checks in the blk layer
544 ia64_max_iommu_merge_mask = ~PAGE_MASK;
547 INIT_LIST_HEAD(&sn_sysdata_list);
548 sn_init_cpei_timer();
550 #ifdef CONFIG_PROC_FS
551 register_sn_procfs();
554 printk(KERN_INFO "ACPI DSDT OEM Rev 0x%x\n",
555 acpi_gbl_DSDT->oem_revision);
556 if (sn_acpi_base_support())
563 arch_initcall(sn_io_early_init);
566 * sn_io_late_init() - Perform any final platform specific IO initialization.
570 sn_io_late_init(void)
573 struct pcibus_bussoft *bussoft;
576 cnodeid_t near_cnode;
578 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
582 * Setup closest node in pci_controller->node for
583 * PIC, TIOCP, TIOCE (TIOCA does it during bus fixup using
584 * info from the PROM).
587 while ((bus = pci_find_next_bus(bus)) != NULL) {
588 bussoft = SN_PCIBUS_BUSSOFT(bus);
589 nasid = NASID_GET(bussoft->bs_base);
590 cnode = nasid_to_cnodeid(nasid);
591 if ((bussoft->bs_asic_type == PCIIO_ASIC_TYPE_TIOCP) ||
592 (bussoft->bs_asic_type == PCIIO_ASIC_TYPE_TIOCE)) {
593 /* TIO PCI Bridge: find nearest node with CPUs */
594 int e = sn_hwperf_get_nearest_node(cnode, NULL,
597 near_cnode = (cnodeid_t)-1; /* use any node */
598 printk(KERN_WARNING "pcibr_bus_fixup: failed "
599 "to find near node with CPUs to TIO "
600 "node %d, err=%d\n", cnode, e);
602 PCI_CONTROLLER(bus)->node = near_cnode;
603 } else if (bussoft->bs_asic_type == PCIIO_ASIC_TYPE_PIC) {
604 PCI_CONTROLLER(bus)->node = cnode;
608 sn_ioif_inited = 1; /* SN I/O infrastructure now initialized */
613 fs_initcall(sn_io_late_init);
615 EXPORT_SYMBOL(sn_pci_fixup_slot);
616 EXPORT_SYMBOL(sn_pci_unfixup_slot);
617 EXPORT_SYMBOL(sn_bus_store_sysdata);
618 EXPORT_SYMBOL(sn_bus_free_sysdata);
619 EXPORT_SYMBOL(sn_generate_path);