2 * Low-Level PCI Support for PC
4 * (c) 1999--2000 Martin Mares <mj@suse.cz>
7 #include <linux/config.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/pci.h>
12 #include <linux/init.h>
13 #include <linux/ioport.h>
15 #include <asm/segment.h>
21 unsigned int pci_probe
= PCI_PROBE_BIOS
| PCI_PROBE_CONF1
| PCI_PROBE_CONF2
;
23 int pcibios_last_bus
= -1;
24 struct pci_bus
*pci_root_bus
;
25 struct pci_ops
*pci_root_ops
;
28 * Direct access to PCI hardware...
31 #ifdef CONFIG_PCI_DIRECT
34 * Functions for accessing PCI configuration space with type 1 accesses
37 #define CONFIG_CMD(dev, where) (0x80000000 | (dev->bus->number << 16) | (dev->devfn << 8) | (where & ~3))
39 static int pci_conf1_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
41 outl(CONFIG_CMD(dev
,where
), 0xCF8);
42 *value
= inb(0xCFC + (where
&3));
43 return PCIBIOS_SUCCESSFUL
;
46 static int pci_conf1_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
48 outl(CONFIG_CMD(dev
,where
), 0xCF8);
49 *value
= inw(0xCFC + (where
&2));
50 return PCIBIOS_SUCCESSFUL
;
53 static int pci_conf1_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
55 outl(CONFIG_CMD(dev
,where
), 0xCF8);
57 return PCIBIOS_SUCCESSFUL
;
60 static int pci_conf1_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
62 outl(CONFIG_CMD(dev
,where
), 0xCF8);
63 outb(value
, 0xCFC + (where
&3));
64 return PCIBIOS_SUCCESSFUL
;
67 static int pci_conf1_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
69 outl(CONFIG_CMD(dev
,where
), 0xCF8);
70 outw(value
, 0xCFC + (where
&2));
71 return PCIBIOS_SUCCESSFUL
;
74 static int pci_conf1_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
76 outl(CONFIG_CMD(dev
,where
), 0xCF8);
78 return PCIBIOS_SUCCESSFUL
;
83 static struct pci_ops pci_direct_conf1
= {
84 pci_conf1_read_config_byte
,
85 pci_conf1_read_config_word
,
86 pci_conf1_read_config_dword
,
87 pci_conf1_write_config_byte
,
88 pci_conf1_write_config_word
,
89 pci_conf1_write_config_dword
93 * Functions for accessing PCI configuration space with type 2 accesses
96 #define IOADDR(devfn, where) ((0xC000 | ((devfn & 0x78) << 5)) + where)
97 #define FUNC(devfn) (((devfn & 7) << 1) | 0xf0)
98 #define SET(dev) if (dev->devfn & 0x80) return PCIBIOS_DEVICE_NOT_FOUND; \
99 outb(FUNC(dev->devfn), 0xCF8); \
100 outb(dev->bus->number, 0xCFA);
102 static int pci_conf2_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
105 *value
= inb(IOADDR(dev
->devfn
,where
));
107 return PCIBIOS_SUCCESSFUL
;
110 static int pci_conf2_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
113 *value
= inw(IOADDR(dev
->devfn
,where
));
115 return PCIBIOS_SUCCESSFUL
;
118 static int pci_conf2_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
121 *value
= inl (IOADDR(dev
->devfn
,where
));
123 return PCIBIOS_SUCCESSFUL
;
126 static int pci_conf2_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
129 outb (value
, IOADDR(dev
->devfn
,where
));
131 return PCIBIOS_SUCCESSFUL
;
134 static int pci_conf2_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
137 outw (value
, IOADDR(dev
->devfn
,where
));
139 return PCIBIOS_SUCCESSFUL
;
142 static int pci_conf2_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
145 outl (value
, IOADDR(dev
->devfn
,where
));
147 return PCIBIOS_SUCCESSFUL
;
154 static struct pci_ops pci_direct_conf2
= {
155 pci_conf2_read_config_byte
,
156 pci_conf2_read_config_word
,
157 pci_conf2_read_config_dword
,
158 pci_conf2_write_config_byte
,
159 pci_conf2_write_config_word
,
160 pci_conf2_write_config_dword
164 * Before we decide to use direct hardware access mechanisms, we try to do some
165 * trivial checks to ensure it at least _seems_ to be working -- we just test
166 * whether bus 00 contains a host bridge (this is similar to checking
167 * techniques used in XFree86, but ours should be more reliable since we
168 * attempt to make use of direct access hints provided by the PCI BIOS).
170 * This should be close to trivial, but it isn't, because there are buggy
171 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
173 static int __init
pci_sanity_check(struct pci_ops
*o
)
176 struct pci_bus bus
; /* Fake bus and device */
179 if (pci_probe
& PCI_NO_CHECKS
)
183 for(dev
.devfn
=0; dev
.devfn
< 0x100; dev
.devfn
++)
184 if ((!o
->read_word(&dev
, PCI_CLASS_DEVICE
, &x
) &&
185 (x
== PCI_CLASS_BRIDGE_HOST
|| x
== PCI_CLASS_DISPLAY_VGA
)) ||
186 (!o
->read_word(&dev
, PCI_VENDOR_ID
, &x
) &&
187 (x
== PCI_VENDOR_ID_INTEL
|| x
== PCI_VENDOR_ID_COMPAQ
)))
189 DBG("PCI: Sanity check failed\n");
193 static struct pci_ops
* __init
pci_check_direct(void)
198 __save_flags(flags
); __cli();
201 * Check if configuration type 1 works.
203 if (pci_probe
& PCI_PROBE_CONF1
) {
206 outl (0x80000000, 0xCF8);
207 if (inl (0xCF8) == 0x80000000 &&
208 pci_sanity_check(&pci_direct_conf1
)) {
210 __restore_flags(flags
);
211 printk("PCI: Using configuration type 1\n");
212 request_region(0xCF8, 8, "PCI conf1");
213 return &pci_direct_conf1
;
219 * Check if configuration type 2 works.
221 if (pci_probe
& PCI_PROBE_CONF2
) {
225 if (inb (0xCF8) == 0x00 && inb (0xCFA) == 0x00 &&
226 pci_sanity_check(&pci_direct_conf2
)) {
227 __restore_flags(flags
);
228 printk("PCI: Using configuration type 2\n");
229 request_region(0xCF8, 4, "PCI conf2");
230 return &pci_direct_conf2
;
234 __restore_flags(flags
);
241 * BIOS32 and PCI BIOS handling.
244 #ifdef CONFIG_PCI_BIOS
246 #define PCIBIOS_PCI_FUNCTION_ID 0xb1XX
247 #define PCIBIOS_PCI_BIOS_PRESENT 0xb101
248 #define PCIBIOS_FIND_PCI_DEVICE 0xb102
249 #define PCIBIOS_FIND_PCI_CLASS_CODE 0xb103
250 #define PCIBIOS_GENERATE_SPECIAL_CYCLE 0xb106
251 #define PCIBIOS_READ_CONFIG_BYTE 0xb108
252 #define PCIBIOS_READ_CONFIG_WORD 0xb109
253 #define PCIBIOS_READ_CONFIG_DWORD 0xb10a
254 #define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b
255 #define PCIBIOS_WRITE_CONFIG_WORD 0xb10c
256 #define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d
257 #define PCIBIOS_GET_ROUTING_OPTIONS 0xb10e
258 #define PCIBIOS_SET_PCI_HW_INT 0xb10f
260 /* BIOS32 signature: "_32_" */
261 #define BIOS32_SIGNATURE (('_' << 0) + ('3' << 8) + ('2' << 16) + ('_' << 24))
263 /* PCI signature: "PCI " */
264 #define PCI_SIGNATURE (('P' << 0) + ('C' << 8) + ('I' << 16) + (' ' << 24))
266 /* PCI service signature: "$PCI" */
267 #define PCI_SERVICE (('$' << 0) + ('P' << 8) + ('C' << 16) + ('I' << 24))
269 /* PCI BIOS hardware mechanism flags */
270 #define PCIBIOS_HW_TYPE1 0x01
271 #define PCIBIOS_HW_TYPE2 0x02
272 #define PCIBIOS_HW_TYPE1_SPEC 0x10
273 #define PCIBIOS_HW_TYPE2_SPEC 0x20
276 * This is the standard structure used to identify the entry point
277 * to the BIOS32 Service Directory, as documented in
278 * Standard BIOS 32-bit Service Directory Proposal
279 * Revision 0.4 May 24, 1993
280 * Phoenix Technologies Ltd.
282 * and the PCI BIOS specification.
287 unsigned long signature
; /* _32_ */
288 unsigned long entry
; /* 32 bit physical address */
289 unsigned char revision
; /* Revision level, 0 */
290 unsigned char length
; /* Length in paragraphs should be 01 */
291 unsigned char checksum
; /* All bytes must add up to zero */
292 unsigned char reserved
[5]; /* Must be zero */
298 * Physical address of the service directory. I don't know if we're
299 * allowed to have more than one of these or not, so just in case
300 * we'll make pcibios_present() take a memory start parameter and store
305 unsigned long address
;
306 unsigned short segment
;
307 } bios32_indirect
= { 0, __KERNEL_CS
};
310 * Returns the entry point for the given service, NULL on error
313 static unsigned long bios32_service(unsigned long service
)
315 unsigned char return_code
; /* %al */
316 unsigned long address
; /* %ebx */
317 unsigned long length
; /* %ecx */
318 unsigned long entry
; /* %edx */
321 __save_flags(flags
); __cli();
322 __asm__("lcall (%%edi); cld"
323 : "=a" (return_code
),
329 "D" (&bios32_indirect
));
330 __restore_flags(flags
);
332 switch (return_code
) {
334 return address
+ entry
;
335 case 0x80: /* Not present */
336 printk("bios32_service(0x%lx): not present\n", service
);
338 default: /* Shouldn't happen */
339 printk("bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
340 service
, return_code
);
346 unsigned long address
;
347 unsigned short segment
;
348 } pci_indirect
= { 0, __KERNEL_CS
};
350 static int pci_bios_present
;
352 static int __init
check_pcibios(void)
354 u32 signature
, eax
, ebx
, ecx
;
355 u8 status
, major_ver
, minor_ver
, hw_mech
;
356 unsigned long flags
, pcibios_entry
;
358 if ((pcibios_entry
= bios32_service(PCI_SERVICE
))) {
359 pci_indirect
.address
= pcibios_entry
+ PAGE_OFFSET
;
361 __save_flags(flags
); __cli();
363 "lcall (%%edi); cld\n\t"
371 : "1" (PCIBIOS_PCI_BIOS_PRESENT
),
374 __restore_flags(flags
);
376 status
= (eax
>> 8) & 0xff;
377 hw_mech
= eax
& 0xff;
378 major_ver
= (ebx
>> 8) & 0xff;
379 minor_ver
= ebx
& 0xff;
380 if (pcibios_last_bus
< 0)
381 pcibios_last_bus
= ecx
& 0xff;
382 DBG("PCI: BIOS probe returned s=%02x hw=%02x ver=%02x.%02x l=%02x\n",
383 status
, hw_mech
, major_ver
, minor_ver
, pcibios_last_bus
);
384 if (status
|| signature
!= PCI_SIGNATURE
) {
385 printk (KERN_ERR
"PCI: BIOS BUG #%x[%08x] found, report to <mj@suse.cz>\n",
389 printk("PCI: PCI BIOS revision %x.%02x entry at 0x%lx, last bus=%d\n",
390 major_ver
, minor_ver
, pcibios_entry
, pcibios_last_bus
);
391 #ifdef CONFIG_PCI_DIRECT
392 if (!(hw_mech
& PCIBIOS_HW_TYPE1
))
393 pci_probe
&= ~PCI_PROBE_CONF1
;
394 if (!(hw_mech
& PCIBIOS_HW_TYPE2
))
395 pci_probe
&= ~PCI_PROBE_CONF2
;
402 static int __init
pci_bios_find_device (unsigned short vendor
, unsigned short device_id
,
403 unsigned short index
, unsigned char *bus
, unsigned char *device_fn
)
408 __asm__("lcall (%%edi); cld\n\t"
414 : "1" (PCIBIOS_FIND_PCI_DEVICE
),
418 "D" (&pci_indirect
));
419 *bus
= (bx
>> 8) & 0xff;
420 *device_fn
= bx
& 0xff;
421 return (int) (ret
& 0xff00) >> 8;
424 static int pci_bios_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
427 unsigned long bx
= (dev
->bus
->number
<< 8) | dev
->devfn
;
429 __asm__("lcall (%%esi); cld\n\t"
435 : "1" (PCIBIOS_READ_CONFIG_BYTE
),
438 "S" (&pci_indirect
));
439 return (int) (ret
& 0xff00) >> 8;
442 static int pci_bios_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
445 unsigned long bx
= (dev
->bus
->number
<< 8) | dev
->devfn
;
447 __asm__("lcall (%%esi); cld\n\t"
453 : "1" (PCIBIOS_READ_CONFIG_WORD
),
456 "S" (&pci_indirect
));
457 return (int) (ret
& 0xff00) >> 8;
460 static int pci_bios_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
463 unsigned long bx
= (dev
->bus
->number
<< 8) | dev
->devfn
;
465 __asm__("lcall (%%esi); cld\n\t"
471 : "1" (PCIBIOS_READ_CONFIG_DWORD
),
474 "S" (&pci_indirect
));
475 return (int) (ret
& 0xff00) >> 8;
478 static int pci_bios_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
481 unsigned long bx
= (dev
->bus
->number
<< 8) | dev
->devfn
;
483 __asm__("lcall (%%esi); cld\n\t"
488 : "0" (PCIBIOS_WRITE_CONFIG_BYTE
),
492 "S" (&pci_indirect
));
493 return (int) (ret
& 0xff00) >> 8;
496 static int pci_bios_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
499 unsigned long bx
= (dev
->bus
->number
<< 8) | dev
->devfn
;
501 __asm__("lcall (%%esi); cld\n\t"
506 : "0" (PCIBIOS_WRITE_CONFIG_WORD
),
510 "S" (&pci_indirect
));
511 return (int) (ret
& 0xff00) >> 8;
514 static int pci_bios_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
517 unsigned long bx
= (dev
->bus
->number
<< 8) | dev
->devfn
;
519 __asm__("lcall (%%esi); cld\n\t"
524 : "0" (PCIBIOS_WRITE_CONFIG_DWORD
),
528 "S" (&pci_indirect
));
529 return (int) (ret
& 0xff00) >> 8;
533 * Function table for BIOS32 access
536 static struct pci_ops pci_bios_access
= {
537 pci_bios_read_config_byte
,
538 pci_bios_read_config_word
,
539 pci_bios_read_config_dword
,
540 pci_bios_write_config_byte
,
541 pci_bios_write_config_word
,
542 pci_bios_write_config_dword
546 * Try to find PCI BIOS.
549 static struct pci_ops
* __init
pci_find_bios(void)
556 * Follow the standard procedure for locating the BIOS32 Service
557 * directory by scanning the permissible address range from
558 * 0xe0000 through 0xfffff for a valid BIOS32 structure.
561 for (check
= (union bios32
*) __va(0xe0000);
562 check
<= (union bios32
*) __va(0xffff0);
564 if (check
->fields
.signature
!= BIOS32_SIGNATURE
)
566 length
= check
->fields
.length
* 16;
570 for (i
= 0; i
< length
; ++i
)
571 sum
+= check
->chars
[i
];
574 if (check
->fields
.revision
!= 0) {
575 printk("PCI: unsupported BIOS32 revision %d at 0x%p, report to <mj@suse.cz>\n",
576 check
->fields
.revision
, check
);
579 DBG("PCI: BIOS32 Service Directory structure at 0x%p\n", check
);
580 if (check
->fields
.entry
>= 0x100000) {
581 printk("PCI: BIOS32 entry (0x%p) in high memory, cannot use.\n", check
);
584 unsigned long bios32_entry
= check
->fields
.entry
;
585 DBG("PCI: BIOS32 Service Directory entry at 0x%lx\n", bios32_entry
);
586 bios32_indirect
.address
= bios32_entry
+ PAGE_OFFSET
;
588 return &pci_bios_access
;
590 break; /* Hopefully more than one BIOS32 cannot happen... */
597 * Sort the device list according to PCI BIOS. Nasty hack, but since some
598 * fool forgot to define the `correct' device order in the PCI BIOS specs
599 * and we want to be (possibly bug-to-bug ;-]) compatible with older kernels
600 * which used BIOS ordering, we are bound to do this...
603 static void __init
pcibios_sort(void)
605 LIST_HEAD(sorted_devices
);
606 struct list_head
*ln
;
607 struct pci_dev
*dev
, *d
;
609 unsigned char bus
, devfn
;
611 DBG("PCI: Sorting device list...\n");
612 while (!list_empty(&pci_devices
)) {
613 ln
= pci_devices
.next
;
616 while (pci_bios_find_device(dev
->vendor
, dev
->device
, idx
, &bus
, &devfn
) == PCIBIOS_SUCCESSFUL
) {
618 for (ln
=pci_devices
.next
; ln
!= &pci_devices
; ln
=ln
->next
) {
620 if (d
->bus
->number
== bus
&& d
->devfn
== devfn
) {
621 list_del(&d
->global_list
);
622 list_add_tail(&d
->global_list
, &sorted_devices
);
628 if (ln
== &pci_devices
) {
629 printk("PCI: BIOS reporting unknown device %02x:%02x\n", bus
, devfn
);
631 * We must not continue scanning as several buggy BIOSes
632 * return garbage after the last device. Grr.
638 printk("PCI: Device %02x:%02x not found by BIOS\n",
639 dev
->bus
->number
, dev
->devfn
);
640 list_del(&dev
->global_list
);
641 list_add_tail(&dev
->global_list
, &sorted_devices
);
644 list_splice(&sorted_devices
, &pci_devices
);
648 * BIOS Functions for IRQ Routing
651 struct irq_routing_options
{
653 struct irq_info
*table
;
655 } __attribute__((packed
));
657 struct irq_routing_table
* __init
pcibios_get_irq_routing_table(void)
659 struct irq_routing_options opt
;
660 struct irq_routing_table
*rt
= NULL
;
664 if (!pci_bios_present
)
666 page
= __get_free_page(GFP_KERNEL
);
669 opt
.table
= (struct irq_info
*) page
;
670 opt
.size
= PAGE_SIZE
;
671 opt
.segment
= __KERNEL_DS
;
673 DBG("PCI: Fetching IRQ routing table... ");
674 __asm__("push %%es\n\t"
677 "lcall (%%esi); cld\n\t"
684 : "0" (PCIBIOS_GET_ROUTING_OPTIONS
),
687 "S" (&pci_indirect
));
688 DBG("OK ret=%d, size=%d, map=%x\n", ret
, opt
.size
, map
);
690 printk(KERN_ERR
"PCI: Error %02x when fetching IRQ routing table.\n", (ret
>> 8) & 0xff);
692 rt
= kmalloc(sizeof(struct irq_routing_table
) + opt
.size
, GFP_KERNEL
);
694 memset(rt
, 0, sizeof(struct irq_routing_table
));
695 rt
->size
= opt
.size
+ sizeof(struct irq_routing_table
);
696 rt
->exclusive_irqs
= map
;
697 memcpy(rt
->slots
, (void *) page
, opt
.size
);
698 printk("PCI: Using BIOS Interrupt Routing Table\n");
706 int pcibios_set_irq_routing(struct pci_dev
*dev
, int pin
, int irq
)
710 __asm__("lcall (%%esi); cld\n\t"
715 : "0" (PCIBIOS_SET_PCI_HW_INT
),
716 "b" ((dev
->bus
->number
<< 8) | dev
->devfn
),
717 "c" ((irq
<< 8) | (pin
+ 10)),
718 "S" (&pci_indirect
));
719 return !(ret
& 0xff00);
725 * Several buggy motherboards address only 16 devices and mirror
726 * them to next 16 IDs. We try to detect this `feature' on all
727 * primary buses (those containing host bridges as they are
728 * expected to be unique) and remove the ghost devices.
731 static void __init
pcibios_fixup_ghosts(struct pci_bus
*b
)
733 struct list_head
*ln
, *mn
;
734 struct pci_dev
*d
, *e
;
735 int mirror
= PCI_DEVFN(16,0);
736 int seen_host_bridge
= 0;
739 DBG("PCI: Scanning for ghost devices on bus %d\n", b
->number
);
740 for (ln
=b
->devices
.next
; ln
!= &b
->devices
; ln
=ln
->next
) {
742 if ((d
->class >> 8) == PCI_CLASS_BRIDGE_HOST
)
744 for (mn
=ln
->next
; mn
!= &b
->devices
; mn
=mn
->next
) {
746 if (e
->devfn
!= d
->devfn
+ mirror
||
747 e
->vendor
!= d
->vendor
||
748 e
->device
!= d
->device
||
749 e
->class != d
->class)
751 for(i
=0; i
<PCI_NUM_RESOURCES
; i
++)
752 if (e
->resource
[i
].start
!= d
->resource
[i
].start
||
753 e
->resource
[i
].end
!= d
->resource
[i
].end
||
754 e
->resource
[i
].flags
!= d
->resource
[i
].flags
)
758 if (mn
== &b
->devices
)
761 if (!seen_host_bridge
)
763 printk("PCI: Ignoring ghost devices on bus %02x\n", b
->number
);
766 while (ln
->next
!= &b
->devices
) {
767 d
= pci_dev_b(ln
->next
);
768 if (d
->devfn
>= mirror
) {
769 list_del(&d
->global_list
);
770 list_del(&d
->bus_list
);
778 * Discover remaining PCI buses in case there are peer host bridges.
779 * We use the number of last PCI bus provided by the PCI BIOS.
781 static void __init
pcibios_fixup_peer_bridges(void)
788 if (pcibios_last_bus
<= 0 || pcibios_last_bus
>= 0xff)
790 DBG("PCI: Peer bridge fixup\n");
791 for (n
=0; n
<= pcibios_last_bus
; n
++) {
792 if (pci_bus_exists(&pci_root_buses
, n
))
795 bus
.ops
= pci_root_ops
;
797 for(dev
.devfn
=0; dev
.devfn
<256; dev
.devfn
+= 8)
798 if (!pci_read_config_word(&dev
, PCI_VENDOR_ID
, &l
) &&
799 l
!= 0x0000 && l
!= 0xffff) {
800 DBG("Found device at %02x:%02x [%04x]\n", n
, dev
.devfn
, l
);
801 printk("PCI: Discovered peer bus %02x\n", n
);
802 pci_scan_bus(n
, pci_root_ops
, NULL
);
809 * Exceptions for specific devices. Usually work-arounds for fatal design flaws.
812 static void __init
pci_fixup_i450nx(struct pci_dev
*d
)
815 * i450NX -- Find and scan all secondary buses on all PXB's.
818 u8 busno
, suba
, subb
;
819 printk("PCI: Searching for i450NX host bridges on %s\n", d
->slot_name
);
821 for(pxb
=0; pxb
<2; pxb
++) {
822 pci_read_config_byte(d
, reg
++, &busno
);
823 pci_read_config_byte(d
, reg
++, &suba
);
824 pci_read_config_byte(d
, reg
++, &subb
);
825 DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb
, busno
, suba
, subb
);
827 pci_scan_bus(busno
, pci_root_ops
, NULL
); /* Bus A */
829 pci_scan_bus(suba
+1, pci_root_ops
, NULL
); /* Bus B */
831 pcibios_last_bus
= -1;
834 static void __init
pci_fixup_i450gx(struct pci_dev
*d
)
837 * i450GX and i450KX -- Find and scan all secondary buses.
838 * (called separately for each PCI bridge found)
841 pci_read_config_byte(d
, 0x4a, &busno
);
842 printk("PCI: i440KX/GX host bridge %s: secondary bus %02x\n", d
->slot_name
, busno
);
843 pci_scan_bus(busno
, pci_root_ops
, NULL
);
844 pcibios_last_bus
= -1;
847 static void __init
pci_fixup_serverworks(struct pci_dev
*d
)
850 * ServerWorks host bridges -- Find and scan all secondary buses.
851 * Register 0x44 contains first, 0x45 last bus number routed there.
854 pci_read_config_byte(d
, 0x44, &busno
);
855 printk("PCI: ServerWorks host bridge: secondary bus %02x\n", busno
);
856 pci_scan_bus(busno
, pci_root_ops
, NULL
);
857 pcibios_last_bus
= -1;
860 static void __init
pci_fixup_compaq(struct pci_dev
*d
)
863 * Compaq host bridges -- Find and scan all secondary buses.
864 * This time registers 0xc8 and 0xc9.
867 pci_read_config_byte(d
, 0xc8, &busno
);
868 printk("PCI: Compaq host bridge: secondary bus %02x\n", busno
);
869 pci_scan_bus(busno
, pci_root_ops
, NULL
);
870 pcibios_last_bus
= -1;
873 static void __init
pci_fixup_umc_ide(struct pci_dev
*d
)
876 * UM8886BF IDE controller sets region type bits incorrectly,
877 * therefore they look like memory despite of them being I/O.
881 printk("PCI: Fixing base address flags for device %s\n", d
->slot_name
);
883 d
->resource
[i
].flags
|= PCI_BASE_ADDRESS_SPACE_IO
;
886 static void __init
pci_fixup_ide_bases(struct pci_dev
*d
)
891 * PCI IDE controllers use non-standard I/O port decoding, respect it.
893 if ((d
->class >> 8) != PCI_CLASS_STORAGE_IDE
)
895 DBG("PCI: IDE base address fixup for %s\n", d
->slot_name
);
897 struct resource
*r
= &d
->resource
[i
];
898 if ((r
->start
& ~0x80) == 0x374) {
905 static void __init
pci_fixup_ide_trash(struct pci_dev
*d
)
910 * There exist PCI IDE controllers which have utter garbage
911 * in first four base registers. Ignore that.
913 DBG("PCI: IDE base address trash cleared for %s\n", d
->slot_name
);
915 d
->resource
[i
].start
= d
->resource
[i
].end
= d
->resource
[i
].flags
= 0;
918 static void __init
pci_fixup_latency(struct pci_dev
*d
)
921 * SiS 5597 and 5598 chipsets require latency timer set to
922 * at most 32 to avoid lockups.
924 DBG("PCI: Setting max latency to 32\n");
925 pcibios_max_latency
= 32;
928 struct pci_fixup pcibios_fixups
[] = {
929 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82451NX
, pci_fixup_i450nx
},
930 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82454GX
, pci_fixup_i450gx
},
931 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_SERVERWORKS
, PCI_DEVICE_ID_SERVERWORKS_HE
, pci_fixup_serverworks
},
932 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_SERVERWORKS
, PCI_DEVICE_ID_SERVERWORKS_LE
, pci_fixup_serverworks
},
933 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_SERVERWORKS
, PCI_DEVICE_ID_SERVERWORKS_CMIC_HE
, pci_fixup_serverworks
},
934 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_6010
, pci_fixup_compaq
},
935 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_UMC
, PCI_DEVICE_ID_UMC_UM8886BF
, pci_fixup_umc_ide
},
936 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_5513
, pci_fixup_ide_trash
},
937 { PCI_FIXUP_HEADER
, PCI_ANY_ID
, PCI_ANY_ID
, pci_fixup_ide_bases
},
938 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_5597
, pci_fixup_latency
},
939 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_5598
, pci_fixup_latency
},
944 * Called after each bus is probed, but before its children
948 void __init
pcibios_fixup_bus(struct pci_bus
*b
)
950 pcibios_fixup_ghosts(b
);
951 pci_read_bridge_bases(b
);
955 * Initialization. Try all known PCI access methods. Note that we support
956 * using both PCI BIOS and direct access: in such cases, we use I/O ports
957 * to access config space, but we still keep BIOS order of cards to be
958 * compatible with 2.0.X. This should go away some day.
961 void __init
pcibios_init(void)
963 struct pci_ops
*bios
= NULL
;
964 struct pci_ops
*dir
= NULL
;
966 #ifdef CONFIG_PCI_BIOS
967 if ((pci_probe
& PCI_PROBE_BIOS
) && ((bios
= pci_find_bios()))) {
968 pci_probe
|= PCI_BIOS_SORT
;
969 pci_bios_present
= 1;
972 #ifdef CONFIG_PCI_DIRECT
973 if (pci_probe
& (PCI_PROBE_CONF1
| PCI_PROBE_CONF2
))
974 dir
= pci_check_direct();
981 printk("PCI: No PCI bus detected\n");
985 printk("PCI: Probing PCI hardware\n");
986 pci_root_bus
= pci_scan_bus(0, pci_root_ops
, NULL
);
989 pcibios_fixup_peer_bridges();
990 pcibios_fixup_irqs();
991 pcibios_resource_survey();
993 #ifdef CONFIG_PCI_BIOS
994 if ((pci_probe
& PCI_BIOS_SORT
) && !(pci_probe
& PCI_NO_SORT
))
999 char * __init
pcibios_setup(char *str
)
1001 if (!strcmp(str
, "off")) {
1005 #ifdef CONFIG_PCI_BIOS
1006 else if (!strcmp(str
, "bios")) {
1007 pci_probe
= PCI_PROBE_BIOS
;
1009 } else if (!strcmp(str
, "nobios")) {
1010 pci_probe
&= ~PCI_PROBE_BIOS
;
1012 } else if (!strcmp(str
, "nosort")) {
1013 pci_probe
|= PCI_NO_SORT
;
1015 } else if (!strcmp(str
, "biosirq")) {
1016 pci_probe
|= PCI_BIOS_IRQ_SCAN
;
1020 #ifdef CONFIG_PCI_DIRECT
1021 else if (!strcmp(str
, "conf1")) {
1022 pci_probe
= PCI_PROBE_CONF1
| PCI_NO_CHECKS
;
1025 else if (!strcmp(str
, "conf2")) {
1026 pci_probe
= PCI_PROBE_CONF2
| PCI_NO_CHECKS
;
1030 else if (!strcmp(str
, "rom")) {
1031 pci_probe
|= PCI_ASSIGN_ROMS
;
1033 } else if (!strncmp(str
, "irqmask=", 8)) {
1034 pcibios_irq_mask
= simple_strtol(str
+8, NULL
, 0);
1036 } else if (!strncmp(str
, "lastbus=", 8)) {
1037 pcibios_last_bus
= simple_strtol(str
+8, NULL
, 0);
1043 int pcibios_enable_device(struct pci_dev
*dev
)
1047 if ((err
= pcibios_enable_resources(dev
)) < 0)
1051 pci_read_config_byte(dev
, PCI_INTERRUPT_PIN
, &pin
);
1052 if (pin
&& !pcibios_lookup_irq(dev
, 1))
1053 printk(KERN_WARNING
"PCI: No IRQ known for interrupt pin %c of device %s.%s\n",
1054 'A' + pin
- 1, dev
->slot_name
,
1055 (pci_probe
& PCI_BIOS_IRQ_SCAN
) ? "" : " Please try using pci=biosirq.");