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/sn_sal.h>
13 #include <asm/sn/addrs.h>
14 #include <asm/sn/pcibus_provider_defs.h>
15 #include <asm/sn/pcidev.h>
16 #include "pci/pcibr_provider.h"
17 #include "xtalk/xwidgetdev.h"
18 #include <asm/sn/geo.h>
19 #include "xtalk/hubdev.h"
20 #include <asm/sn/io.h>
21 #include <asm/sn/simulator.h>
23 char master_baseio_wid;
24 nasid_t master_nasid = INVALID_NASID; /* Partition Master */
27 struct hubdev_info hubdev;
31 moduleid_t id; /* Module ID of this module */
32 struct slab_info slab_info[MAX_SLABS + 1];
35 int sn_ioif_inited = 0; /* SN I/O infrastructure initialized? */
37 struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
40 * Hooks and struct for unsupported pci providers
44 sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size)
50 sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
56 sn_default_pci_bus_fixup(struct pcibus_bussoft *soft)
61 static struct sn_pcibus_provider sn_pci_default_provider = {
62 .dma_map = sn_default_pci_map,
63 .dma_map_consistent = sn_default_pci_map,
64 .dma_unmap = sn_default_pci_unmap,
65 .bus_fixup = sn_default_pci_bus_fixup,
69 * Retrieve the DMA Flush List given nasid. This list is needed
70 * to implement the WAR - Flush DMA data on PIO Reads.
72 static inline uint64_t
73 sal_get_widget_dmaflush_list(u64 nasid, u64 widget_num, u64 address)
76 struct ia64_sal_retval ret_stuff;
80 SAL_CALL_NOLOCK(ret_stuff,
81 (u64) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
82 (u64) nasid, (u64) widget_num, (u64) address, 0, 0, 0,
89 * Retrieve the hub device info structure for the given nasid.
91 static inline uint64_t sal_get_hubdev_info(u64 handle, u64 address)
94 struct ia64_sal_retval ret_stuff;
98 SAL_CALL_NOLOCK(ret_stuff,
99 (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
100 (u64) handle, (u64) address, 0, 0, 0, 0, 0);
105 * Retrieve the pci bus information given the bus number.
107 static inline uint64_t sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
110 struct ia64_sal_retval ret_stuff;
111 ret_stuff.status = 0;
114 SAL_CALL_NOLOCK(ret_stuff,
115 (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
116 (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
121 * Retrieve the pci device information given the bus and device|function number.
123 static inline uint64_t
124 sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
127 struct ia64_sal_retval ret_stuff;
128 ret_stuff.status = 0;
131 SAL_CALL_NOLOCK(ret_stuff,
132 (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
133 (u64) segment, (u64) bus_number, (u64) devfn,
140 * sn_alloc_pci_sysdata() - This routine allocates a pci controller
141 * which is expected as the pci_dev and pci_bus sysdata by the Linux
142 * PCI infrastructure.
144 static inline struct pci_controller *sn_alloc_pci_sysdata(void)
146 struct pci_controller *pci_sysdata;
148 pci_sysdata = kmalloc(sizeof(*pci_sysdata), GFP_KERNEL);
152 memset(pci_sysdata, 0, sizeof(*pci_sysdata));
157 * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
158 * each node in the system.
160 static void sn_fixup_ionodes(void)
163 struct sn_flush_device_list *sn_flush_device_list;
164 struct hubdev_info *hubdev;
169 for (i = 0; i < numionodes; i++) {
170 hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
171 nasid = cnodeid_to_nasid(i);
172 status = sal_get_hubdev_info(nasid, (uint64_t) __pa(hubdev));
176 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
177 hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
179 if (!hubdev->hdi_flush_nasid_list.widget_p)
182 hubdev->hdi_flush_nasid_list.widget_p =
183 kmalloc((HUB_WIDGET_ID_MAX + 1) *
184 sizeof(struct sn_flush_device_list *), GFP_KERNEL);
186 memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
187 (HUB_WIDGET_ID_MAX + 1) *
188 sizeof(struct sn_flush_device_list *));
190 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
191 sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
193 sn_flush_device_list),
195 memset(sn_flush_device_list, 0x0,
197 sizeof(struct sn_flush_device_list));
200 sal_get_widget_dmaflush_list(nasid, widget,
203 (sn_flush_device_list));
205 kfree(sn_flush_device_list);
209 hubdev->hdi_flush_nasid_list.widget_p[widget] =
210 sn_flush_device_list;
214 hub_error_init(hubdev);
216 ice_error_init(hubdev);
222 * sn_pci_fixup_slot() - This routine sets up a slot's resources
223 * consistent with the Linux PCI abstraction layer. Resources acquired
224 * from our PCI provider include PIO maps to BAR space and interrupt
227 static void sn_pci_fixup_slot(struct pci_dev *dev)
232 struct sn_irq_info *sn_irq_info;
233 struct pci_dev *host_pci_dev;
235 struct pcibus_bussoft *bs;
237 dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
238 if (SN_PCIDEV_INFO(dev) <= 0)
239 BUG(); /* Cannot afford to run out of memory */
240 memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
242 sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
243 if (sn_irq_info <= 0)
244 BUG(); /* Cannot afford to run out of memory */
245 memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
247 /* Call to retrieve pci device information needed by kernel. */
248 status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
250 (u64) __pa(SN_PCIDEV_INFO(dev)),
251 (u64) __pa(sn_irq_info));
253 BUG(); /* Cannot get platform pci device information information */
255 /* Copy over PIO Mapped Addresses */
256 for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
257 unsigned long start, end, addr;
259 if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
262 start = dev->resource[idx].start;
263 end = dev->resource[idx].end;
265 addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
266 addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
267 dev->resource[idx].start = addr;
268 dev->resource[idx].end = addr + size;
269 if (dev->resource[idx].flags & IORESOURCE_IO)
270 dev->resource[idx].parent = &ioport_resource;
272 dev->resource[idx].parent = &iomem_resource;
275 /* set up host bus linkages */
276 bs = SN_PCIBUS_BUSSOFT(dev->bus);
278 pci_find_slot(SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32,
279 SN_PCIDEV_INFO(dev)->
280 pdi_slot_host_handle & 0xffffffff);
281 SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
282 SN_PCIDEV_INFO(host_pci_dev);
283 SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
284 SN_PCIDEV_INFO(dev)->pdi_pcibus_info = bs;
286 if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
287 SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
289 SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
292 /* Only set up IRQ stuff if this device has a host bus context */
293 if (bs && sn_irq_info->irq_irq) {
294 SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
295 dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
296 sn_irq_fixup(dev, sn_irq_info);
301 * sn_pci_controller_fixup() - This routine sets up a bus's resources
302 * consistent with the Linux PCI abstraction layer.
304 static void sn_pci_controller_fixup(int segment, int busnum)
309 struct pci_controller *controller;
310 struct pcibus_bussoft *prom_bussoft_ptr;
311 struct hubdev_info *hubdev_info;
313 struct sn_pcibus_provider *provider;
316 sal_get_pcibus_info((u64) segment, (u64) busnum,
317 (u64) ia64_tpa(&prom_bussoft_ptr));
319 return; /* bus # does not exist */
322 prom_bussoft_ptr = __va(prom_bussoft_ptr);
323 controller = sn_alloc_pci_sysdata();
324 /* controller non-zero is BUG'd in sn_alloc_pci_sysdata */
326 bus = pci_scan_bus(busnum, &pci_root_ops, controller);
328 return; /* error, or bus already scanned */
332 * Per-provider fixup. Copies the contents from prom to local
333 * area and links SN_PCIBUS_BUSSOFT().
336 if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES) {
337 return; /* unsupported asic type */
340 provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
341 if (provider == NULL) {
342 return; /* no provider registerd for this asic */
345 provider_soft = NULL;
346 if (provider->bus_fixup) {
347 provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr);
350 if (provider_soft == NULL) {
351 return; /* fixup failed or not applicable */
355 * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
359 bus->sysdata = controller;
360 PCI_CONTROLLER(bus)->platform_data = provider_soft;
362 nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
363 cnode = nasid_to_cnodeid(nasid);
364 hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
365 SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
366 &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
370 * Ugly hack to get PCI setup until we have a proper ACPI namespace.
373 #define PCI_BUSES_TO_SCAN 256
375 static int __init sn_pci_init(void)
378 struct pci_dev *pci_dev = NULL;
379 extern void sn_init_cpei_timer(void);
380 #ifdef CONFIG_PROC_FS
381 extern void register_sn_procfs(void);
384 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_SIMULATOR())
388 * prime sn_pci_provider[]. Individial provider init routines will
389 * override their respective default entries.
392 for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
393 sn_pci_provider[i] = &sn_pci_default_provider;
395 pcibr_init_provider();
398 * This is needed to avoid bounce limit checks in the blk layer
400 ia64_max_iommu_merge_mask = ~PAGE_MASK;
402 sn_irq = kmalloc(sizeof(struct sn_irq_info *) * NR_IRQS, GFP_KERNEL);
404 BUG(); /* Canno afford to run out of memory. */
405 memset(sn_irq, 0, sizeof(struct sn_irq_info *) * NR_IRQS);
407 sn_init_cpei_timer();
409 #ifdef CONFIG_PROC_FS
410 register_sn_procfs();
413 for (i = 0; i < PCI_BUSES_TO_SCAN; i++) {
414 sn_pci_controller_fixup(0, i);
418 * Generic Linux PCI Layer has created the pci_bus and pci_dev
419 * structures - time for us to add our SN PLatform specific
424 pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
425 sn_pci_fixup_slot(pci_dev);
428 sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
434 * hubdev_init_node() - Creates the HUB data structure and link them to it's
435 * own NODE specific data area.
437 void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
440 struct hubdev_info *hubdev_info;
442 if (node >= num_online_nodes()) /* Headless/memless IO nodes */
444 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
449 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
452 npda->pdinfo = (void *)hubdev_info;
457 cnodeid_get_geoid(cnodeid_t cnode)
460 struct hubdev_info *hubdev;
462 hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
463 return hubdev->hdi_geoid;
467 subsys_initcall(sn_pci_init);