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-2003 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/vmalloc.h>
10 #include <linux/slab.h>
11 #include <asm/sn/sgi.h>
12 #include <asm/sn/pci/pci_bus_cvlink.h>
13 #include <asm/sn/sn_cpuid.h>
14 #include <asm/sn/simulator.h>
16 extern int bridge_rev_b_data_check_disable
;
18 vertex_hdl_t busnum_to_pcibr_vhdl
[MAX_PCI_XWIDGET
];
19 nasid_t busnum_to_nid
[MAX_PCI_XWIDGET
];
20 void * busnum_to_atedmamaps
[MAX_PCI_XWIDGET
];
21 unsigned char num_bridges
;
22 static int done_probing
;
23 extern irqpda_t
*irqpdaindr
;
25 static int pci_bus_map_create(struct pcibr_list_s
*softlistp
, moduleid_t io_moduleid
);
26 vertex_hdl_t
devfn_to_vertex(unsigned char busnum
, unsigned int devfn
);
28 extern void register_pcibr_intr(int irq
, pcibr_intr_t intr
);
30 static struct sn_flush_device_list
*sn_dma_flush_init(unsigned long start
,
32 int idx
, int pin
, int slot
);
33 extern int cbrick_type_get_nasid(nasid_t
);
34 extern void ioconfig_bus_new_entries(void);
35 extern void ioconfig_get_busnum(char *, int *);
36 extern int iomoduleid_get(nasid_t
);
37 extern int pcibr_widget_to_bus(vertex_hdl_t
);
38 extern int isIO9(int);
40 #define IS_OPUS(nasid) (cbrick_type_get_nasid(nasid) == MODULE_OPUSBRICK)
41 #define IS_ALTIX(nasid) (cbrick_type_get_nasid(nasid) == MODULE_CBRICK)
44 * Init the provider asic for a given device
47 static inline void __init
48 set_pci_provider(struct sn_device_sysdata
*device_sysdata
)
50 pciio_info_t pciio_info
= pciio_info_get(device_sysdata
->vhdl
);
52 device_sysdata
->pci_provider
= pciio_info_pops_get(pciio_info
);
56 * pci_bus_cvlink_init() - To be called once during initialization before
57 * SGI IO Infrastructure init is called.
60 pci_bus_cvlink_init(void)
63 extern int ioconfig_bus_init(void);
65 memset(busnum_to_pcibr_vhdl
, 0x0, sizeof(vertex_hdl_t
) * MAX_PCI_XWIDGET
);
66 memset(busnum_to_nid
, 0x0, sizeof(nasid_t
) * MAX_PCI_XWIDGET
);
68 memset(busnum_to_atedmamaps
, 0x0, sizeof(void *) * MAX_PCI_XWIDGET
);
72 return ioconfig_bus_init();
76 * pci_bus_to_vertex() - Given a logical Linux Bus Number returns the associated
77 * pci bus vertex from the SGI IO Infrastructure.
79 static inline vertex_hdl_t
80 pci_bus_to_vertex(unsigned char busnum
)
83 vertex_hdl_t pci_bus
= NULL
;
87 * First get the xwidget vertex.
89 pci_bus
= busnum_to_pcibr_vhdl
[busnum
];
94 * devfn_to_vertex() - returns the vertex of the device given the bus, slot,
95 * and function numbers.
98 devfn_to_vertex(unsigned char busnum
, unsigned int devfn
)
104 vertex_hdl_t pci_bus
= NULL
;
105 vertex_hdl_t device_vertex
= (vertex_hdl_t
)NULL
;
108 * Go get the pci bus vertex.
110 pci_bus
= pci_bus_to_vertex(busnum
);
113 * During probing, the Linux pci code invents non-existent
114 * bus numbers and pci_dev structures and tries to access
115 * them to determine existence. Don't crib during probing.
118 printk("devfn_to_vertex: Invalid bus number %d given.\n", busnum
);
124 * Go get the slot&function vertex.
125 * Should call pciio_slot_func_to_name() when ready.
127 slot
= PCI_SLOT(devfn
);
128 func
= PCI_FUNC(devfn
);
131 * For a NON Multi-function card the name of the device looks like:
132 * ../pci/1, ../pci/2 ..
135 sprintf(name
, "%d", slot
);
136 if (hwgraph_traverse(pci_bus
, name
, &device_vertex
) ==
139 return(device_vertex
);
145 * This maybe a multifunction card. It's names look like:
146 * ../pci/1a, ../pci/1b, etc.
148 sprintf(name
, "%d%c", slot
, 'a'+func
);
149 if (hwgraph_traverse(pci_bus
, name
, &device_vertex
) != GRAPH_SUCCESS
) {
150 if (!device_vertex
) {
155 return(device_vertex
);
159 * sn_alloc_pci_sysdata() - This routine allocates a pci controller
160 * which is expected as the pci_dev and pci_bus sysdata by the Linux
161 * PCI infrastructure.
163 static struct pci_controller
*
164 sn_alloc_pci_sysdata(void)
166 struct pci_controller
*pci_sysdata
;
168 pci_sysdata
= kmalloc(sizeof(*pci_sysdata
), GFP_KERNEL
);
172 memset(pci_sysdata
, 0, sizeof(*pci_sysdata
));
177 * sn_pci_fixup_bus() - This routine sets up a bus's resources
178 * consistent with the Linux PCI abstraction layer.
181 sn_pci_fixup_bus(struct pci_bus
*bus
)
183 struct pci_controller
*pci_sysdata
;
184 struct sn_widget_sysdata
*widget_sysdata
;
186 pci_sysdata
= sn_alloc_pci_sysdata();
188 printk(KERN_WARNING
"sn_pci_fixup_bus(): Unable to "
189 "allocate memory for pci_sysdata\n");
192 widget_sysdata
= kmalloc(sizeof(struct sn_widget_sysdata
),
194 if (!widget_sysdata
) {
195 printk(KERN_WARNING
"sn_pci_fixup_bus(): Unable to "
196 "allocate memory for widget_sysdata\n");
201 widget_sysdata
->vhdl
= pci_bus_to_vertex(bus
->number
);
202 pci_sysdata
->platform_data
= (void *)widget_sysdata
;
203 bus
->sysdata
= pci_sysdata
;
209 * sn_pci_fixup_slot() - This routine sets up a slot's resources
210 * consistent with the Linux PCI abstraction layer. Resources acquired
211 * from our PCI provider include PIO maps to BAR space and interrupt
215 sn_pci_fixup_slot(struct pci_dev
*dev
)
217 extern int bit_pos_to_irq(int);
223 struct pci_controller
*pci_sysdata
;
224 struct sn_device_sysdata
*device_sysdata
;
225 pciio_intr_line_t lines
= 0;
226 vertex_hdl_t device_vertex
;
227 pciio_provider_t
*pci_provider
;
228 pciio_intr_t intr_handle
;
230 /* Allocate a controller structure */
231 pci_sysdata
= sn_alloc_pci_sysdata();
233 printk(KERN_WARNING
"sn_pci_fixup_slot: Unable to "
234 "allocate memory for pci_sysdata\n");
238 /* Set the device vertex */
239 device_sysdata
= kmalloc(sizeof(struct sn_device_sysdata
), GFP_KERNEL
);
240 if (!device_sysdata
) {
241 printk(KERN_WARNING
"sn_pci_fixup_slot: Unable to "
242 "allocate memory for device_sysdata\n");
247 device_sysdata
->vhdl
= devfn_to_vertex(dev
->bus
->number
, dev
->devfn
);
248 pci_sysdata
->platform_data
= (void *) device_sysdata
;
249 dev
->sysdata
= pci_sysdata
;
250 set_pci_provider(device_sysdata
);
252 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
255 * Set the resources address correctly. The assumption here
256 * is that the addresses in the resource structure has been
257 * read from the card and it was set in the card by our
258 * Infrastructure. NOTE: PIC and TIOCP don't have big-window
259 * upport for PCI I/O space. So by mapping the I/O space
260 * first we will attempt to use Device(x) registers for I/O
261 * BARs (which can't use big windows like MEM BARs can).
263 vhdl
= device_sysdata
->vhdl
;
265 /* Allocate the IORESOURCE_IO space first */
266 for (idx
= 0; idx
< PCI_ROM_RESOURCE
; idx
++) {
267 unsigned long start
, end
, addr
;
269 device_sysdata
->pio_map
[idx
] = NULL
;
271 if (!(dev
->resource
[idx
].flags
& IORESOURCE_IO
))
274 start
= dev
->resource
[idx
].start
;
275 end
= dev
->resource
[idx
].end
;
280 addr
= (unsigned long)pciio_pio_addr(vhdl
, 0,
281 PCIIO_SPACE_WIN(idx
), 0, size
,
282 &device_sysdata
->pio_map
[idx
], 0);
285 dev
->resource
[idx
].start
= 0;
286 dev
->resource
[idx
].end
= 0;
287 printk("sn_pci_fixup(): pio map failure for "
288 "%s bar%d\n", dev
->slot_name
, idx
);
290 addr
|= __IA64_UNCACHED_OFFSET
;
291 dev
->resource
[idx
].start
= addr
;
292 dev
->resource
[idx
].end
= addr
+ size
;
293 dev
->resource
[idx
].parent
= &ioport_resource
;
296 if (dev
->resource
[idx
].flags
& IORESOURCE_IO
)
297 cmd
|= PCI_COMMAND_IO
;
300 /* Allocate the IORESOURCE_MEM space next */
301 for (idx
= 0; idx
< PCI_ROM_RESOURCE
; idx
++) {
302 unsigned long start
, end
, addr
;
304 if ((dev
->resource
[idx
].flags
& IORESOURCE_IO
))
307 start
= dev
->resource
[idx
].start
;
308 end
= dev
->resource
[idx
].end
;
313 addr
= (unsigned long)pciio_pio_addr(vhdl
, 0,
314 PCIIO_SPACE_WIN(idx
), 0, size
,
315 &device_sysdata
->pio_map
[idx
], 0);
318 dev
->resource
[idx
].start
= 0;
319 dev
->resource
[idx
].end
= 0;
320 printk("sn_pci_fixup(): pio map failure for "
321 "%s bar%d\n", dev
->slot_name
, idx
);
323 addr
|= __IA64_UNCACHED_OFFSET
;
324 dev
->resource
[idx
].start
= addr
;
325 dev
->resource
[idx
].end
= addr
+ size
;
326 dev
->resource
[idx
].parent
= &iomem_resource
;
329 if (dev
->resource
[idx
].flags
& IORESOURCE_MEM
)
330 cmd
|= PCI_COMMAND_MEMORY
;
334 * Assign addresses to the ROMs, but don't enable them yet
335 * Also note that we only map display card ROMs due to PIO mapping
338 if ((dev
->class >> 16) == PCI_BASE_CLASS_DISPLAY
) {
340 size
= dev
->resource
[PCI_ROM_RESOURCE
].end
-
341 dev
->resource
[PCI_ROM_RESOURCE
].start
;
344 addr
= (unsigned long) pciio_pio_addr(vhdl
, 0,
346 0, size
, 0, PIOMAP_FIXED
);
348 dev
->resource
[PCI_ROM_RESOURCE
].start
= 0;
349 dev
->resource
[PCI_ROM_RESOURCE
].end
= 0;
350 printk("sn_pci_fixup(): ROM pio map failure "
351 "for %s\n", dev
->slot_name
);
353 addr
|= __IA64_UNCACHED_OFFSET
;
354 dev
->resource
[PCI_ROM_RESOURCE
].start
= addr
;
355 dev
->resource
[PCI_ROM_RESOURCE
].end
= addr
+ size
;
356 dev
->resource
[idx
].parent
= &iomem_resource
;
357 if (dev
->resource
[PCI_ROM_RESOURCE
].flags
& IORESOURCE_MEM
)
358 cmd
|= PCI_COMMAND_MEMORY
;
362 * Remove other ROM resources since they don't have valid
365 size
= dev
->resource
[PCI_ROM_RESOURCE
].end
-
366 dev
->resource
[PCI_ROM_RESOURCE
].start
;
369 dev
->resource
[PCI_ROM_RESOURCE
].start
= 0;
370 dev
->resource
[PCI_ROM_RESOURCE
].end
= 0;
371 dev
->resource
[PCI_ROM_RESOURCE
].flags
= 0;
376 * Update the Command Word on the Card.
378 cmd
|= PCI_COMMAND_MASTER
; /* If the device doesn't support */
379 /* bit gets dropped .. no harm */
380 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
382 pci_read_config_byte(dev
, PCI_INTERRUPT_PIN
, (unsigned char *)&lines
);
383 device_vertex
= device_sysdata
->vhdl
;
384 pci_provider
= device_sysdata
->pci_provider
;
385 device_sysdata
->intr_handle
= NULL
;
390 irqpdaindr
->curr
= dev
;
392 intr_handle
= (pci_provider
->intr_alloc
)(device_vertex
, NULL
, lines
, device_vertex
);
393 if (intr_handle
== NULL
) {
394 printk(KERN_WARNING
"sn_pci_fixup: pcibr_intr_alloc() failed\n");
396 kfree(device_sysdata
);
400 device_sysdata
->intr_handle
= intr_handle
;
401 irq
= intr_handle
->pi_irq
;
402 irqpdaindr
->device_dev
[irq
] = dev
;
403 (pci_provider
->intr_connect
)(intr_handle
, (intr_func_t
)0, (intr_arg_t
)0);
406 register_pcibr_intr(irq
, (pcibr_intr_t
)intr_handle
);
408 for (idx
= 0; idx
< PCI_ROM_RESOURCE
; idx
++) {
409 int ibits
= ((pcibr_intr_t
)intr_handle
)->bi_ibits
;
412 size
= dev
->resource
[idx
].end
-
413 dev
->resource
[idx
].start
;
414 if (size
== 0) continue;
416 for (i
=0; i
<8; i
++) {
417 if (ibits
& (1 << i
) ) {
418 extern pcibr_info_t
pcibr_info_get(vertex_hdl_t
);
419 device_sysdata
->dma_flush_list
=
420 sn_dma_flush_init(dev
->resource
[idx
].start
,
421 dev
->resource
[idx
].end
,
424 PCIBR_INFO_SLOT_GET_EXT(pcibr_info_get(device_sysdata
->vhdl
)));
431 #ifdef CONFIG_HOTPLUG_PCI_SGI
434 sn_dma_flush_clear(struct sn_flush_device_list
*dma_flush_list
,
435 unsigned long start
, unsigned long end
)
440 dma_flush_list
->pin
= -1;
441 dma_flush_list
->bus
= -1;
442 dma_flush_list
->slot
= -1;
444 for (i
= 0; i
< PCI_ROM_RESOURCE
; i
++)
445 if ((dma_flush_list
->bar_list
[i
].start
== start
) &&
446 (dma_flush_list
->bar_list
[i
].end
== end
)) {
447 dma_flush_list
->bar_list
[i
].start
= 0;
448 dma_flush_list
->bar_list
[i
].end
= 0;
455 * sn_pci_unfixup_slot() - This routine frees a slot's resources
456 * consistent with the Linux PCI abstraction layer. Resources released
457 * back to our PCI provider include PIO maps to BAR space and interrupt
461 sn_pci_unfixup_slot(struct pci_dev
*dev
)
463 struct sn_device_sysdata
*device_sysdata
;
465 pciio_intr_t intr_handle
;
470 device_sysdata
= SN_DEVICE_SYSDATA(dev
);
472 vhdl
= device_sysdata
->vhdl
;
474 if (device_sysdata
->dma_flush_list
)
475 for (idx
= 0; idx
< PCI_ROM_RESOURCE
; idx
++) {
476 size
= dev
->resource
[idx
].end
-
477 dev
->resource
[idx
].start
;
478 if (size
== 0) continue;
480 sn_dma_flush_clear(device_sysdata
->dma_flush_list
,
481 dev
->resource
[idx
].start
,
482 dev
->resource
[idx
].end
);
485 intr_handle
= device_sysdata
->intr_handle
;
487 extern void unregister_pcibr_intr(int, pcibr_intr_t
);
488 irq
= intr_handle
->pi_irq
;
489 irqpdaindr
->device_dev
[irq
] = NULL
;
490 unregister_pcibr_intr(irq
, (pcibr_intr_t
) intr_handle
);
491 pciio_intr_disconnect(intr_handle
);
492 pciio_intr_free(intr_handle
);
495 for (idx
= 0; idx
< PCI_ROM_RESOURCE
; idx
++) {
496 if (device_sysdata
->pio_map
[idx
]) {
497 pciio_piomap_done (device_sysdata
->pio_map
[idx
]);
498 pciio_piomap_free (device_sysdata
->pio_map
[idx
]);
503 #endif /* CONFIG_HOTPLUG_PCI_SGI */
505 struct sn_flush_nasid_entry flush_nasid_list
[MAX_NASIDS
];
507 /* Initialize the data structures for flushing write buffers after a PIO read.
509 * Take an unused int. pin and associate it with a pin that is in use.
510 * After a PIO read, force an interrupt on the unused pin, forcing a write buffer flush
511 * on the in use pin. This will prevent the race condition between PIO read responses and
514 static struct sn_flush_device_list
*
515 sn_dma_flush_init(unsigned long start
, unsigned long end
, int idx
, int pin
, int slot
)
518 unsigned long dnasid
;
521 struct sn_flush_device_list
*p
;
526 nasid
= NASID_GET(start
);
527 wid_num
= SWIN_WIDGETNUM(start
);
528 bus
= (start
>> 23) & 0x1;
529 bwin
= BWIN_WINDOWNUM(start
);
531 if (flush_nasid_list
[nasid
].widget_p
== NULL
) {
532 flush_nasid_list
[nasid
].widget_p
= (struct sn_flush_device_list
**)kmalloc((HUB_WIDGET_ID_MAX
+1) *
533 sizeof(struct sn_flush_device_list
*), GFP_KERNEL
);
534 if (!flush_nasid_list
[nasid
].widget_p
) {
535 printk(KERN_WARNING
"sn_dma_flush_init: Cannot allocate memory for nasid list\n");
538 memset(flush_nasid_list
[nasid
].widget_p
, 0, (HUB_WIDGET_ID_MAX
+1) * sizeof(struct sn_flush_device_list
*));
541 int itte_index
= bwin
- 1;
544 itte
= HUB_L(IIO_ITTE_GET(nasid
, itte_index
));
545 flush_nasid_list
[nasid
].iio_itte
[bwin
] = itte
;
546 wid_num
= (itte
>> IIO_ITTE_WIDGET_SHIFT
)
547 & IIO_ITTE_WIDGET_MASK
;
548 bus
= itte
& IIO_ITTE_OFFSET_MASK
;
549 if (bus
== 0x4 || bus
== 0x8) {
556 /* if it's IO9, bus 1, we don't care about slots 1 and 4. This is
557 * because these are the IOC4 slots and we don't flush them.
559 if (isIO9(nasid
) && bus
== 0 && (slot
== 1 || slot
== 4)) {
562 if (flush_nasid_list
[nasid
].widget_p
[wid_num
] == NULL
) {
563 flush_nasid_list
[nasid
].widget_p
[wid_num
] = (struct sn_flush_device_list
*)kmalloc(
564 DEV_PER_WIDGET
* sizeof (struct sn_flush_device_list
), GFP_KERNEL
);
565 if (!flush_nasid_list
[nasid
].widget_p
[wid_num
]) {
566 printk(KERN_WARNING
"sn_dma_flush_init: Cannot allocate memory for nasid sub-list\n");
569 memset(flush_nasid_list
[nasid
].widget_p
[wid_num
], 0,
570 DEV_PER_WIDGET
* sizeof (struct sn_flush_device_list
));
571 p
= &flush_nasid_list
[nasid
].widget_p
[wid_num
][0];
572 for (i
=0; i
<DEV_PER_WIDGET
;i
++) {
580 p
= &flush_nasid_list
[nasid
].widget_p
[wid_num
][0];
581 for (i
=0;i
<DEV_PER_WIDGET
; i
++) {
582 if (p
->pin
== pin
&& p
->bus
== bus
&& p
->slot
== slot
) break;
592 for (i
=0; i
<PCI_ROM_RESOURCE
; i
++) {
593 if (p
->bar_list
[i
].start
== 0) {
594 p
->bar_list
[i
].start
= start
;
595 p
->bar_list
[i
].end
= end
;
599 b
= (void *)(NODE_SWIN_BASE(nasid
, wid_num
) | (bus
<< 23) );
601 /* If it's IO9, then slot 2 maps to slot 7 and slot 6 maps to slot 8.
602 * To see this is non-trivial. By drawing pictures and reading manuals and talking
603 * to HW guys, we can see that on IO9 bus 1, slots 7 and 8 are always unused.
604 * Further, since we short-circuit slots 1, 3, and 4 above, we only have to worry
605 * about the case when there is a card in slot 2. A multifunction card will appear
606 * to be in slot 6 (from an interrupt point of view) also. That's the most we'll
607 * have to worry about. A four function card will overload the interrupt lines in
609 * We also need to special case the 12160 device in slot 3. Fortunately, we have
610 * a spare intr. line for pin 4, so we'll use that for the 12160.
611 * All other buses have slot 3 and 4 and slots 7 and 8 unused. Since we can only
612 * see slots 1 and 2 and slots 5 and 6 coming through here for those buses (this
613 * is true only on Pxbricks with 2 physical slots per bus), we just need to add
614 * 2 to the slot number to find an unused slot.
615 * We have convinced ourselves that we will never see a case where two different cards
616 * in two different slots will ever share an interrupt line, so there is no need to
620 if (isIO9(nasid
) && ( (IS_ALTIX(nasid
) && wid_num
== 0xc)
621 || (IS_OPUS(nasid
) && wid_num
== 0xf) )
624 p
->force_int_addr
= (unsigned long)pcireg_bridge_force_always_addr_get(b
, 6);
625 pcireg_bridge_intr_device_bit_set(b
, (1<<18));
626 dnasid
= NASID_GET(virt_to_phys(&p
->flush_addr
));
627 pcireg_bridge_intr_addr_set(b
, 6, ((virt_to_phys(&p
->flush_addr
) & 0xfffffffff) |
628 (dnasid
<< 36) | (0xfUL
<< 48)));
629 } else if (pin
== 2) { /* 12160 SCSI device in IO9 */
630 p
->force_int_addr
= (unsigned long)pcireg_bridge_force_always_addr_get(b
, 4);
631 pcireg_bridge_intr_device_bit_set(b
, (2<<12));
632 dnasid
= NASID_GET(virt_to_phys(&p
->flush_addr
));
633 pcireg_bridge_intr_addr_set(b
, 4,
634 ((virt_to_phys(&p
->flush_addr
) & 0xfffffffff) |
635 (dnasid
<< 36) | (0xfUL
<< 48)));
636 } else { /* slot == 6 */
637 p
->force_int_addr
= (unsigned long)pcireg_bridge_force_always_addr_get(b
, 7);
638 pcireg_bridge_intr_device_bit_set(b
, (5<<21));
639 dnasid
= NASID_GET(virt_to_phys(&p
->flush_addr
));
640 pcireg_bridge_intr_addr_set(b
, 7,
641 ((virt_to_phys(&p
->flush_addr
) & 0xfffffffff) |
642 (dnasid
<< 36) | (0xfUL
<< 48)));
645 p
->force_int_addr
= (unsigned long)pcireg_bridge_force_always_addr_get(b
, (pin
+2));
646 pcireg_bridge_intr_device_bit_set(b
, (pin
<< (pin
* 3)));
647 dnasid
= NASID_GET(virt_to_phys(&p
->flush_addr
));
648 pcireg_bridge_intr_addr_set(b
, (pin
+ 2),
649 ((virt_to_phys(&p
->flush_addr
) & 0xfffffffff) |
650 (dnasid
<< 36) | (0xfUL
<< 48)));
657 * linux_bus_cvlink() Creates a link between the Linux PCI Bus number
658 * to the actual hardware component that it represents:
659 * /dev/hw/linux/busnum/0 -> ../../../hw/module/001c01/slab/0/Ibrick/xtalk/15/pci
661 * The bus vertex, when called to devfs_generate_path() returns:
662 * hw/module/001c01/slab/0/Ibrick/xtalk/15/pci
663 * hw/module/001c01/slab/1/Pbrick/xtalk/12/pci-x/0
664 * hw/module/001c01/slab/1/Pbrick/xtalk/12/pci-x/1
667 linux_bus_cvlink(void)
672 for (index
=0; index
< MAX_PCI_XWIDGET
; index
++) {
673 if (!busnum_to_pcibr_vhdl
[index
])
676 sprintf(name
, "%x", index
);
677 (void) hwgraph_edge_add(linux_busnum
, busnum_to_pcibr_vhdl
[index
],
683 * pci_bus_map_create() - Called by pci_bus_to_hcl_cvlink() to finish the job.
685 * Linux PCI Bus numbers are assigned from lowest module_id numbers
689 pci_bus_map_create(struct pcibr_list_s
*softlistp
, moduleid_t moduleid
)
692 int basebus_num
, bus_number
;
693 vertex_hdl_t pci_bus
= softlistp
->bl_vhdl
;
694 char moduleid_str
[16];
696 memset(moduleid_str
, 0, 16);
697 format_module_id(moduleid_str
, moduleid
, MODULE_FORMAT_BRIEF
);
698 (void) ioconfig_get_busnum((char *)moduleid_str
, &basebus_num
);
701 * Assign the correct bus number and also the nasid of this
704 bus_number
= basebus_num
+ pcibr_widget_to_bus(pci_bus
);
707 char hwpath
[MAXDEVNAME
] = "\0";
708 extern int hwgraph_vertex_name_get(vertex_hdl_t
, char *, uint
);
710 pcibr_soft_t pcibr_soft
= softlistp
->bl_soft
;
711 hwgraph_vertex_name_get(pci_bus
, hwpath
, MAXDEVNAME
);
712 printk("%s:\n\tbus_num %d, basebus_num %d, brick_bus %d, "
713 "bus_vhdl 0x%lx, brick_type %d\n", hwpath
, bus_number
,
714 basebus_num
, pcibr_widget_to_bus(pci_bus
),
715 (uint64_t)pci_bus
, pcibr_soft
->bs_bricktype
);
718 busnum_to_pcibr_vhdl
[bus_number
] = pci_bus
;
721 * Pre assign DMA maps needed for 32 Bits Page Map DMA.
723 busnum_to_atedmamaps
[bus_number
] = (void *) vmalloc(
724 sizeof(struct pcibr_dmamap_s
)*MAX_ATE_MAPS
);
725 if (busnum_to_atedmamaps
[bus_number
] <= 0) {
726 printk("pci_bus_map_create: Cannot allocate memory for ate maps\n");
729 memset(busnum_to_atedmamaps
[bus_number
], 0x0,
730 sizeof(struct pcibr_dmamap_s
) * MAX_ATE_MAPS
);
735 * pci_bus_to_hcl_cvlink() - This routine is called after SGI IO Infrastructure
736 * initialization has completed to set up the mappings between PCI BRIDGE
737 * ASIC and logical pci bus numbers.
739 * Must be called before pci_init() is invoked.
742 pci_bus_to_hcl_cvlink(void)
745 extern pcibr_list_p pcibr_list
;
747 for (i
= 0; i
< nummodules
; i
++) {
748 struct pcibr_list_s
*softlistp
= pcibr_list
;
749 struct pcibr_list_s
*first_in_list
= NULL
;
750 struct pcibr_list_s
*last_in_list
= NULL
;
752 /* Walk the list of pcibr_soft structs looking for matches */
754 struct pcibr_soft_s
*pcibr_soft
= softlistp
->bl_soft
;
757 /* Is this PCI bus associated with this moduleid? */
758 moduleid
= NODE_MODULEID(
759 nasid_to_cnodeid(pcibr_soft
->bs_nasid
));
760 if (sn_modules
[i
]->id
== moduleid
) {
761 struct pcibr_list_s
*new_element
;
763 new_element
= kmalloc(sizeof (struct pcibr_soft_s
), GFP_KERNEL
);
764 if (new_element
== NULL
) {
765 printk("%s: Couldn't allocate memory\n",__FUNCTION__
);
768 new_element
->bl_soft
= softlistp
->bl_soft
;
769 new_element
->bl_vhdl
= softlistp
->bl_vhdl
;
770 new_element
->bl_next
= NULL
;
772 /* list empty so just put it on the list */
773 if (first_in_list
== NULL
) {
774 first_in_list
= new_element
;
775 last_in_list
= new_element
;
776 softlistp
= softlistp
->bl_next
;
781 * BASEIO IObricks attached to a module have
782 * a higher priority than non BASEIO IOBricks
783 * when it comes to persistant pci bus
784 * numbering, so put them on the front of the
787 if (isIO9(pcibr_soft
->bs_nasid
)) {
788 new_element
->bl_next
= first_in_list
;
789 first_in_list
= new_element
;
791 last_in_list
->bl_next
= new_element
;
792 last_in_list
= new_element
;
795 softlistp
= softlistp
->bl_next
;
799 * We now have a list of all the pci bridges associated with
800 * the module_id, sn_modules[i]. Call pci_bus_map_create() for
803 softlistp
= first_in_list
;
806 struct pcibr_list_s
*next
= softlistp
->bl_next
;
807 iobrick
= iomoduleid_get(softlistp
->bl_soft
->bs_nasid
);
808 pci_bus_map_create(softlistp
, iobrick
);
815 * Create the Linux PCI bus number vertex link.
817 (void)linux_bus_cvlink();
818 (void)ioconfig_bus_new_entries();
824 * Ugly hack to get PCI setup until we have a proper ACPI namespace.
827 #define PCI_BUSES_TO_SCAN 256
829 extern struct pci_ops sn_pci_ops
;
834 struct pci_controller
*controller
;
835 struct list_head
*ln
;
836 struct pci_bus
*pci_bus
= NULL
;
837 struct pci_dev
*pci_dev
= NULL
;
839 #ifdef CONFIG_PROC_FS
840 extern void register_sn_procfs(void);
842 extern void sgi_master_io_infr_init(void);
843 extern void sn_init_cpei_timer(void);
846 if (!ia64_platform_is("sn2") || IS_RUNNING_ON_SIMULATOR())
850 * This is needed to avoid bounce limit checks in the blk layer
852 ia64_max_iommu_merge_mask
= ~PAGE_MASK
;
855 * set pci_raw_ops, etc.
857 sgi_master_io_infr_init();
859 sn_init_cpei_timer();
861 #ifdef CONFIG_PROC_FS
862 register_sn_procfs();
865 controller
= kmalloc(sizeof(struct pci_controller
), GFP_KERNEL
);
867 printk(KERN_WARNING
"cannot allocate PCI controller\n");
871 memset(controller
, 0, sizeof(struct pci_controller
));
873 for (i
= 0; i
< PCI_BUSES_TO_SCAN
; i
++)
874 if (pci_bus_to_vertex(i
))
875 pci_scan_bus(i
, &sn_pci_ops
, controller
);
880 * Initialize the pci bus vertex in the pci_bus struct.
882 for( ln
= pci_root_buses
.next
; ln
!= &pci_root_buses
; ln
= ln
->next
) {
883 pci_bus
= pci_bus_b(ln
);
884 ret
= sn_pci_fixup_bus(pci_bus
);
887 "sn_pci_fixup: sn_pci_fixup_bus fails : error %d\n",
894 * set the root start and end so that drivers calling check_region()
895 * won't see a conflict
897 ioport_resource
.start
= 0xc000000000000000;
898 ioport_resource
.end
= 0xcfffffffffffffff;
901 * Set the root start and end for Mem Resource.
903 iomem_resource
.start
= 0;
904 iomem_resource
.end
= 0xffffffffffffffff;
907 * Initialize the device vertex in the pci_dev struct.
909 while ((pci_dev
= pci_find_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_dev
)) != NULL
) {
910 ret
= sn_pci_fixup_slot(pci_dev
);
913 "sn_pci_fixup: sn_pci_fixup_slot fails : error %d\n",
922 subsys_initcall(sn_pci_init
);