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 <asm/sn/types.h>
11 #include <asm/sn/sn_sal.h>
12 #include <asm/sn/addrs.h>
13 #include "pci/pcibus_provider_defs.h"
14 #include "pci/pcidev.h"
15 #include "pci/pcibr_provider.h"
16 #include "xtalk/xwidgetdev.h"
17 #include <asm/sn/geo.h>
18 #include "xtalk/hubdev.h"
19 #include <asm/sn/io.h>
20 #include <asm/sn/simulator.h>
22 char master_baseio_wid;
23 nasid_t master_nasid = INVALID_NASID; /* Partition Master */
26 struct hubdev_info hubdev;
30 moduleid_t id; /* Module ID of this module */
31 struct slab_info slab_info[MAX_SLABS + 1];
34 int sn_ioif_inited = 0; /* SN I/O infrastructure initialized? */
37 * Retrieve the DMA Flush List given nasid. This list is needed
38 * to implement the WAR - Flush DMA data on PIO Reads.
40 static inline uint64_t
41 sal_get_widget_dmaflush_list(u64 nasid, u64 widget_num, u64 address)
44 struct ia64_sal_retval ret_stuff;
48 SAL_CALL_NOLOCK(ret_stuff,
49 (u64) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
50 (u64) nasid, (u64) widget_num, (u64) address, 0, 0, 0,
57 * Retrieve the hub device info structure for the given nasid.
59 static inline uint64_t sal_get_hubdev_info(u64 handle, u64 address)
62 struct ia64_sal_retval ret_stuff;
66 SAL_CALL_NOLOCK(ret_stuff,
67 (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
68 (u64) handle, (u64) address, 0, 0, 0, 0, 0);
73 * Retrieve the pci bus information given the bus number.
75 static inline uint64_t sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
78 struct ia64_sal_retval ret_stuff;
82 SAL_CALL_NOLOCK(ret_stuff,
83 (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
84 (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
89 * Retrieve the pci device information given the bus and device|function number.
91 static inline uint64_t
92 sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
95 struct ia64_sal_retval ret_stuff;
99 SAL_CALL_NOLOCK(ret_stuff,
100 (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
101 (u64) segment, (u64) bus_number, (u64) devfn,
108 * sn_alloc_pci_sysdata() - This routine allocates a pci controller
109 * which is expected as the pci_dev and pci_bus sysdata by the Linux
110 * PCI infrastructure.
112 static inline struct pci_controller *sn_alloc_pci_sysdata(void)
114 struct pci_controller *pci_sysdata;
116 pci_sysdata = kmalloc(sizeof(*pci_sysdata), GFP_KERNEL);
120 memset(pci_sysdata, 0, sizeof(*pci_sysdata));
125 * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
126 * each node in the system.
128 static void sn_fixup_ionodes(void)
131 struct sn_flush_device_list *sn_flush_device_list;
132 struct hubdev_info *hubdev;
137 for (i = 0; i < numionodes; i++) {
138 hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
139 nasid = cnodeid_to_nasid(i);
140 status = sal_get_hubdev_info(nasid, (uint64_t) __pa(hubdev));
144 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
145 hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
147 if (!hubdev->hdi_flush_nasid_list.widget_p)
150 hubdev->hdi_flush_nasid_list.widget_p =
151 kmalloc((HUB_WIDGET_ID_MAX + 1) *
152 sizeof(struct sn_flush_device_list *), GFP_KERNEL);
154 memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
155 (HUB_WIDGET_ID_MAX + 1) *
156 sizeof(struct sn_flush_device_list *));
158 for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
159 sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
161 sn_flush_device_list),
163 memset(sn_flush_device_list, 0x0,
165 sizeof(struct sn_flush_device_list));
168 sal_get_widget_dmaflush_list(nasid, widget,
171 (sn_flush_device_list));
173 kfree(sn_flush_device_list);
177 hubdev->hdi_flush_nasid_list.widget_p[widget] =
178 sn_flush_device_list;
182 hub_error_init(hubdev);
184 ice_error_init(hubdev);
190 * sn_pci_fixup_slot() - This routine sets up a slot's resources
191 * consistent with the Linux PCI abstraction layer. Resources acquired
192 * from our PCI provider include PIO maps to BAR space and interrupt
195 static void sn_pci_fixup_slot(struct pci_dev *dev)
200 struct sn_irq_info *sn_irq_info;
201 struct pci_dev *host_pci_dev;
204 SN_PCIDEV_INFO(dev) = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
205 if (SN_PCIDEV_INFO(dev) <= 0)
206 BUG(); /* Cannot afford to run out of memory */
207 memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
209 sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
210 if (sn_irq_info <= 0)
211 BUG(); /* Cannot afford to run out of memory */
212 memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
214 /* Call to retrieve pci device information needed by kernel. */
215 status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
217 (u64) __pa(SN_PCIDEV_INFO(dev)),
218 (u64) __pa(sn_irq_info));
220 BUG(); /* Cannot get platform pci device information information */
222 /* Copy over PIO Mapped Addresses */
223 for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
224 unsigned long start, end, addr;
226 if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
229 start = dev->resource[idx].start;
230 end = dev->resource[idx].end;
232 addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
233 addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
234 dev->resource[idx].start = addr;
235 dev->resource[idx].end = addr + size;
236 if (dev->resource[idx].flags & IORESOURCE_IO)
237 dev->resource[idx].parent = &ioport_resource;
239 dev->resource[idx].parent = &iomem_resource;
242 /* set up host bus linkages */
244 pci_find_slot(SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32,
245 SN_PCIDEV_INFO(dev)->
246 pdi_slot_host_handle & 0xffffffff);
247 SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
248 SN_PCIDEV_INFO(host_pci_dev);
249 SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
250 SN_PCIDEV_INFO(dev)->pdi_pcibus_info = SN_PCIBUS_BUSSOFT(dev->bus);
252 /* Only set up IRQ stuff if this device has a host bus context */
253 if (SN_PCIDEV_BUSSOFT(dev) && sn_irq_info->irq_irq) {
254 SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
255 dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
256 sn_irq_fixup(dev, sn_irq_info);
261 * sn_pci_controller_fixup() - This routine sets up a bus's resources
262 * consistent with the Linux PCI abstraction layer.
264 static void sn_pci_controller_fixup(int segment, int busnum)
269 struct pci_controller *controller;
270 struct pcibus_bussoft *prom_bussoft_ptr;
271 struct hubdev_info *hubdev_info;
275 sal_get_pcibus_info((u64) segment, (u64) busnum,
276 (u64) ia64_tpa(&prom_bussoft_ptr));
278 return; /* bus # does not exist */
281 prom_bussoft_ptr = __va(prom_bussoft_ptr);
282 controller = sn_alloc_pci_sysdata();
283 /* controller non-zero is BUG'd in sn_alloc_pci_sysdata */
285 bus = pci_scan_bus(busnum, &pci_root_ops, controller);
287 return; /* error, or bus already scanned */
291 * Per-provider fixup. Copies the contents from prom to local
292 * area and links SN_PCIBUS_BUSSOFT().
294 * Note: Provider is responsible for ensuring that prom_bussoft_ptr
295 * represents an asic-type that it can handle.
298 if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB) {
299 return; /* no further fixup necessary */
302 provider_soft = pcibr_bus_fixup(prom_bussoft_ptr);
303 if (provider_soft == NULL) {
304 return; /* fixup failed or not applicable */
308 * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
312 PCI_CONTROLLER(bus) = controller;
313 SN_PCIBUS_BUSSOFT(bus) = provider_soft;
315 nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
316 cnode = nasid_to_cnodeid(nasid);
317 hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
318 SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
319 &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
323 * Ugly hack to get PCI setup until we have a proper ACPI namespace.
326 #define PCI_BUSES_TO_SCAN 256
328 static int __init sn_pci_init(void)
331 struct pci_dev *pci_dev = NULL;
332 extern void sn_init_cpei_timer(void);
333 #ifdef CONFIG_PROC_FS
334 extern void register_sn_procfs(void);
337 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_SIMULATOR())
341 * This is needed to avoid bounce limit checks in the blk layer
343 ia64_max_iommu_merge_mask = ~PAGE_MASK;
345 sn_irq = kmalloc(sizeof(struct sn_irq_info *) * NR_IRQS, GFP_KERNEL);
347 BUG(); /* Canno afford to run out of memory. */
348 memset(sn_irq, 0, sizeof(struct sn_irq_info *) * NR_IRQS);
350 sn_init_cpei_timer();
352 #ifdef CONFIG_PROC_FS
353 register_sn_procfs();
356 for (i = 0; i < PCI_BUSES_TO_SCAN; i++) {
357 sn_pci_controller_fixup(0, i);
361 * Generic Linux PCI Layer has created the pci_bus and pci_dev
362 * structures - time for us to add our SN PLatform specific
367 pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
368 sn_pci_fixup_slot(pci_dev);
371 sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
377 * hubdev_init_node() - Creates the HUB data structure and link them to it's
378 * own NODE specific data area.
380 void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
383 struct hubdev_info *hubdev_info;
385 if (node >= numnodes) /* Headless/memless IO nodes */
387 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
392 (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
395 npda->pdinfo = (void *)hubdev_info;
400 cnodeid_get_geoid(cnodeid_t cnode)
403 struct hubdev_info *hubdev;
405 hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
406 return hubdev->hdi_geoid;
410 subsys_initcall(sn_pci_init);