1 /* $Id: pci_common.c,v 1.12 2000/05/01 06:32:49 davem Exp $
2 * pci_common.c: PCI controller common support.
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
7 #include <linux/string.h>
8 #include <linux/malloc.h>
9 #include <linux/init.h>
13 /* Find the OBP PROM device tree node for a PCI device.
14 * Return zero if not found.
16 static int __init
find_device_prom_node(struct pci_pbm_info
*pbm
,
19 struct linux_prom_pci_registers
*pregs
,
25 * Return the PBM's PROM node in case we are it's PCI device,
26 * as the PBM's reg property is different to standard PCI reg
27 * properties. We would delete this device entry otherwise,
28 * which confuses XFree86's device probing...
30 if ((pdev
->bus
->number
== pbm
->pci_bus
->number
) && (pdev
->devfn
== 0) &&
31 (pdev
->vendor
== PCI_VENDOR_ID_SUN
) &&
32 (pdev
->device
== PCI_DEVICE_ID_SUN_PBM
)) {
37 node
= prom_getchild(bus_prom_node
);
39 int err
= prom_getproperty(node
, "reg",
41 sizeof(*pregs
) * PROMREG_MAX
);
42 if (err
== 0 || err
== -1)
44 if (((pregs
[0].phys_hi
>> 8) & 0xff) == pdev
->devfn
) {
45 *nregs
= err
/ sizeof(*pregs
);
50 node
= prom_getsibling(node
);
55 /* Remove a PCI device from the device trees, then
56 * free it up. Note that this must run before
57 * the device's resources are registered because we
58 * do not handle unregistering them here.
60 static void pci_device_delete(struct pci_dev
*pdev
)
62 list_del(&pdev
->global_list
);
63 list_del(&pdev
->bus_list
);
65 /* Ok, all references are gone, free it up. */
69 /* Older versions of OBP on PCI systems encode 64-bit MEM
70 * space assignments incorrectly, this fixes them up.
72 static void __init
fixup_obp_assignments(struct pcidev_cookie
*pcp
)
76 for (i
= 0; i
< pcp
->num_prom_assignments
; i
++) {
77 struct linux_prom_pci_registers
*ap
;
80 ap
= &pcp
->prom_assignments
[i
];
81 space
= ap
->phys_hi
>> 24;
82 if ((space
& 0x3) == 2 &&
84 ap
->phys_hi
&= ~(0x7 << 24);
85 ap
->phys_hi
|= 0x3 << 24;
90 /* Fill in the PCI device cookie sysdata for the given
91 * PCI device. This cookie is the means by which one
92 * can get to OBP and PCI controller specific information
95 static void __init
pdev_cookie_fillin(struct pci_pbm_info
*pbm
,
99 struct linux_prom_pci_registers pregs
[PROMREG_MAX
];
100 struct pcidev_cookie
*pcp
;
101 int device_prom_node
, nregs
, err
;
103 device_prom_node
= find_device_prom_node(pbm
, pdev
, bus_prom_node
,
105 if (device_prom_node
== 0) {
106 /* If it is not in the OBP device tree then
107 * there must be a damn good reason for it.
109 * So what we do is delete the device from the
110 * PCI device tree completely. This scenerio
111 * is seen, for example, on CP1500 for the
112 * second EBUS/HappyMeal pair if the external
113 * connector for it is not present.
115 pci_device_delete(pdev
);
119 pcp
= kmalloc(sizeof(*pcp
), GFP_ATOMIC
);
121 prom_printf("PCI_COOKIE: Fatal malloc error, aborting...\n");
125 pcp
->prom_node
= device_prom_node
;
126 memcpy(pcp
->prom_regs
, pregs
, sizeof(pcp
->prom_regs
));
127 pcp
->num_prom_regs
= nregs
;
128 err
= prom_getproperty(device_prom_node
, "name",
129 pcp
->prom_name
, sizeof(pcp
->prom_name
));
131 pcp
->prom_name
[err
] = 0;
133 pcp
->prom_name
[0] = 0;
134 if (strcmp(pcp
->prom_name
, "ebus") == 0) {
135 struct linux_prom_ebus_ranges erng
[PROM_PCIRNG_MAX
];
138 /* EBUS is special... */
139 err
= prom_getproperty(device_prom_node
, "ranges",
140 (char *)&erng
[0], sizeof(erng
));
141 if (err
== 0 || err
== -1) {
142 prom_printf("EBUS: Fatal error, no range property\n");
145 err
= (err
/ sizeof(erng
[0]));
146 for(iter
= 0; iter
< err
; iter
++) {
147 struct linux_prom_ebus_ranges
*ep
= &erng
[iter
];
148 struct linux_prom_pci_registers
*ap
;
150 ap
= &pcp
->prom_assignments
[iter
];
152 ap
->phys_hi
= ep
->parent_phys_hi
;
153 ap
->phys_mid
= ep
->parent_phys_mid
;
154 ap
->phys_lo
= ep
->parent_phys_lo
;
156 ap
->size_lo
= ep
->size
;
158 pcp
->num_prom_assignments
= err
;
160 err
= prom_getproperty(device_prom_node
,
161 "assigned-addresses",
162 (char *)pcp
->prom_assignments
,
163 sizeof(pcp
->prom_assignments
));
164 if (err
== 0 || err
== -1)
165 pcp
->num_prom_assignments
= 0;
167 pcp
->num_prom_assignments
=
168 (err
/ sizeof(pcp
->prom_assignments
[0]));
171 fixup_obp_assignments(pcp
);
176 void __init
pci_fill_in_pbm_cookies(struct pci_bus
*pbus
,
177 struct pci_pbm_info
*pbm
,
180 struct list_head
*walk
= &pbus
->devices
;
182 /* This loop is coded like this because the cookie
183 * fillin routine can delete devices from the tree.
186 while (walk
!= &pbus
->devices
) {
187 struct pci_dev
*pdev
= pci_dev_b(walk
);
188 struct list_head
*walk_next
= walk
->next
;
190 pdev_cookie_fillin(pbm
, pdev
, prom_node
);
195 walk
= &pbus
->children
;
197 while (walk
!= &pbus
->children
) {
198 struct pci_bus
*this_pbus
= pci_bus_b(walk
);
199 struct pcidev_cookie
*pcp
= this_pbus
->self
->sysdata
;
200 struct list_head
*walk_next
= walk
->next
;
202 pci_fill_in_pbm_cookies(this_pbus
, pbm
, pcp
->prom_node
);
208 static void __init
bad_assignment(struct linux_prom_pci_registers
*ap
,
209 struct resource
*res
,
212 prom_printf("PCI: Bogus PROM assignment.\n");
214 prom_printf("PCI: phys[%08x:%08x:%08x] size[%08x:%08x]\n",
215 ap
->phys_hi
, ap
->phys_mid
, ap
->phys_lo
,
216 ap
->size_hi
, ap
->size_lo
);
218 prom_printf("PCI: RES[%016lx-->%016lx:(%lx)]\n",
219 res
->start
, res
->end
, res
->flags
);
220 prom_printf("Please email this information to davem@redhat.com\n");
225 static struct resource
*
226 __init
get_root_resource(struct linux_prom_pci_registers
*ap
,
227 struct pci_pbm_info
*pbm
)
229 int space
= (ap
->phys_hi
>> 24) & 3;
233 /* Configuration space, silently ignore it. */
237 /* 16-bit IO space */
238 return &pbm
->io_space
;
241 /* 32-bit MEM space */
242 return &pbm
->mem_space
;
245 /* 64-bit MEM space, these are allocated out of
246 * the 32-bit mem_space range for the PBM, ie.
247 * we just zero out the upper 32-bits.
249 return &pbm
->mem_space
;
252 printk("PCI: What is resource space %x? "
253 "Tell davem@redhat.com about it!\n", space
);
258 static struct resource
*
259 __init
get_device_resource(struct linux_prom_pci_registers
*ap
,
260 struct pci_dev
*pdev
)
262 struct resource
*res
;
263 int breg
= (ap
->phys_hi
& 0xff);
264 int space
= (ap
->phys_hi
>> 24) & 3;
267 case PCI_ROM_ADDRESS
:
268 /* It had better be MEM space. */
270 bad_assignment(ap
, NULL
, 0);
272 res
= &pdev
->resource
[PCI_ROM_RESOURCE
];
275 case PCI_BASE_ADDRESS_0
:
276 case PCI_BASE_ADDRESS_1
:
277 case PCI_BASE_ADDRESS_2
:
278 case PCI_BASE_ADDRESS_3
:
279 case PCI_BASE_ADDRESS_4
:
280 case PCI_BASE_ADDRESS_5
:
281 res
= &pdev
->resource
[(breg
- PCI_BASE_ADDRESS_0
) / 4];
285 bad_assignment(ap
, NULL
, 0);
293 static void __init
pdev_record_assignments(struct pci_pbm_info
*pbm
,
294 struct pci_dev
*pdev
)
296 struct pcidev_cookie
*pcp
= pdev
->sysdata
;
299 for (i
= 0; i
< pcp
->num_prom_assignments
; i
++) {
300 struct linux_prom_pci_registers
*ap
;
301 struct resource
*root
, *res
;
303 /* The format of this property is specified in
304 * the PCI Bus Binding to IEEE1275-1994.
306 ap
= &pcp
->prom_assignments
[i
];
307 root
= get_root_resource(ap
, pbm
);
308 res
= get_device_resource(ap
, pdev
);
309 if (root
== NULL
|| res
== NULL
)
312 /* Ok we know which resource this PROM assignment is
313 * for, sanity check it.
315 if ((res
->start
& 0xffffffffUL
) != ap
->phys_lo
)
316 bad_assignment(ap
, res
, 1);
318 /* If it is a 64-bit MEM space assignment, verify that
319 * the resource is too and that the upper 32-bits match.
321 if (((ap
->phys_hi
>> 24) & 3) == 3) {
322 if (((res
->flags
& IORESOURCE_MEM
) == 0) ||
323 ((res
->flags
& PCI_BASE_ADDRESS_MEM_TYPE_MASK
)
324 != PCI_BASE_ADDRESS_MEM_TYPE_64
))
325 bad_assignment(ap
, res
, 1);
326 if ((res
->start
>> 32) != ap
->phys_mid
)
327 bad_assignment(ap
, res
, 1);
329 /* PBM cannot generate cpu initiated PIOs
330 * to the full 64-bit space. Therefore the
331 * upper 32-bits better be zero. If it is
332 * not, just skip it and we will assign it
333 * properly ourselves.
335 if ((res
->start
>> 32) != 0UL) {
336 printk(KERN_ERR
"PCI: OBP assigns out of range MEM address "
337 "%016lx for region %ld on device %s\n",
338 res
->start
, (res
- &pdev
->resource
[0]), pdev
->name
);
343 /* Adjust the resource into the physical address space
346 pbm
->parent
->resource_adjust(pdev
, res
, root
);
348 if (request_resource(root
, res
) < 0) {
349 /* OK, there is some conflict. But this is fine
350 * since we'll reassign it in the fixup pass.
351 * Nevertheless notify the user that OBP made
354 printk(KERN_ERR
"PCI: Address space collision on region %ld "
356 (res
- &pdev
->resource
[0]), pdev
->name
);
361 void __init
pci_record_assignments(struct pci_pbm_info
*pbm
,
362 struct pci_bus
*pbus
)
364 struct list_head
*walk
= &pbus
->devices
;
366 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
)
367 pdev_record_assignments(pbm
, pci_dev_b(walk
));
369 walk
= &pbus
->children
;
370 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
371 pci_record_assignments(pbm
, pci_bus_b(walk
));
374 static void __init
pdev_assign_unassigned(struct pci_pbm_info
*pbm
,
375 struct pci_dev
*pdev
)
379 int i
, io_seen
, mem_seen
;
381 io_seen
= mem_seen
= 0;
382 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++) {
383 struct resource
*root
, *res
;
384 unsigned long size
, min
, max
, align
;
386 res
= &pdev
->resource
[i
];
388 if (res
->flags
& IORESOURCE_IO
)
390 else if (res
->flags
& IORESOURCE_MEM
)
393 /* If it is already assigned or the resource does
394 * not exist, there is nothing to do.
396 if (res
->parent
!= NULL
|| res
->flags
== 0UL)
399 /* Determine the root we allocate from. */
400 if (res
->flags
& IORESOURCE_IO
) {
401 root
= &pbm
->io_space
;
402 min
= root
->start
+ 0x400UL
;
405 root
= &pbm
->mem_space
;
407 max
= min
+ 0x80000000UL
;
410 size
= res
->end
- res
->start
;
412 if (allocate_resource(root
, res
, size
+ 1, min
, max
, align
, NULL
, NULL
) < 0) {
414 prom_printf("PCI: Failed to allocate resource %d for %s\n",
419 /* Update PCI config space. */
420 pbm
->parent
->base_address_update(pdev
, i
);
423 /* Special case, disable the ROM. Several devices
424 * act funny (ie. do not respond to memory space writes)
425 * when it is left enabled. A good example are Qlogic,ISP
428 pci_read_config_dword(pdev
, PCI_ROM_ADDRESS
, ®
);
429 reg
&= ~PCI_ROM_ADDRESS_ENABLE
;
430 pci_write_config_dword(pdev
, PCI_ROM_ADDRESS
, reg
);
432 /* If we saw I/O or MEM resources, enable appropriate
433 * bits in PCI command register.
435 if (io_seen
|| mem_seen
) {
436 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
438 cmd
|= PCI_COMMAND_IO
;
440 cmd
|= PCI_COMMAND_MEMORY
;
441 pci_write_config_word(pdev
, PCI_COMMAND
, cmd
);
444 /* If this is a PCI bridge or an IDE controller,
445 * enable bus mastering. In the former case also
446 * set the cache line size correctly.
448 if (((pdev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
) ||
449 (((pdev
->class >> 8) == PCI_CLASS_STORAGE_IDE
) &&
450 ((pdev
->class & 0x80) != 0))) {
451 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
452 cmd
|= PCI_COMMAND_MASTER
;
453 pci_write_config_word(pdev
, PCI_COMMAND
, cmd
);
455 if ((pdev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
)
456 pci_write_config_byte(pdev
,
462 void __init
pci_assign_unassigned(struct pci_pbm_info
*pbm
,
463 struct pci_bus
*pbus
)
465 struct list_head
*walk
= &pbus
->devices
;
467 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
)
468 pdev_assign_unassigned(pbm
, pci_dev_b(walk
));
470 walk
= &pbus
->children
;
471 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
472 pci_assign_unassigned(pbm
, pci_bus_b(walk
));
475 static int __init
pci_intmap_match(struct pci_dev
*pdev
, unsigned int *interrupt
)
477 struct pcidev_cookie
*dev_pcp
= pdev
->sysdata
;
478 struct pci_pbm_info
*pbm
= dev_pcp
->pbm
;
479 struct linux_prom_pci_registers
*pregs
= dev_pcp
->prom_regs
;
480 unsigned int hi
, mid
, lo
, irq
;
483 if (pbm
->num_pbm_intmap
== 0)
486 /* If we are underneath a PCI bridge, use PROM register
487 * property of the parent bridge which is closest to
490 if (pdev
->bus
->number
!= pbm
->pci_first_busno
) {
491 struct pcidev_cookie
*bus_pcp
;
492 struct pci_dev
*pwalk
;
495 pwalk
= pdev
->bus
->self
;
497 pwalk
->bus
->number
!= pbm
->pci_first_busno
)
498 pwalk
= pwalk
->bus
->self
;
500 bus_pcp
= pwalk
->sysdata
;
501 pregs
= bus_pcp
->prom_regs
;
503 offset
= prom_getint(dev_pcp
->prom_node
,
506 /* Did PROM know better and assign an interrupt other
507 * than #INTA to the device? - We test here for presence of
508 * FCODE on the card, in this case we assume PROM has set
509 * correct 'interrupts' property, unless it is quadhme.
512 !strcmp(dev_pcp
->prom_name
, "SUNW,qfe") ||
513 !strcmp(dev_pcp
->prom_name
, "qfe")) {
515 * No, use low slot number bits of child as IRQ line.
517 *interrupt
= ((*interrupt
- 1 + PCI_SLOT(pdev
->devfn
)) & 3) + 1;
521 hi
= pregs
->phys_hi
& pbm
->pbm_intmask
.phys_hi
;
522 mid
= pregs
->phys_mid
& pbm
->pbm_intmask
.phys_mid
;
523 lo
= pregs
->phys_lo
& pbm
->pbm_intmask
.phys_lo
;
524 irq
= *interrupt
& pbm
->pbm_intmask
.interrupt
;
526 for (i
= 0; i
< pbm
->num_pbm_intmap
; i
++) {
527 if (pbm
->pbm_intmap
[i
].phys_hi
== hi
&&
528 pbm
->pbm_intmap
[i
].phys_mid
== mid
&&
529 pbm
->pbm_intmap
[i
].phys_lo
== lo
&&
530 pbm
->pbm_intmap
[i
].interrupt
== irq
) {
531 *interrupt
= pbm
->pbm_intmap
[i
].cinterrupt
;
536 prom_printf("pbm_intmap_match: bus %02x, devfn %02x: ",
537 pdev
->bus
->number
, pdev
->devfn
);
538 prom_printf("IRQ [%08x.%08x.%08x.%08x] not found in interrupt-map\n",
539 pregs
->phys_hi
, pregs
->phys_mid
, pregs
->phys_lo
, *interrupt
);
540 prom_printf("Please email this information to davem@redhat.com\n");
544 static void __init
pdev_fixup_irq(struct pci_dev
*pdev
)
546 struct pcidev_cookie
*pcp
= pdev
->sysdata
;
547 struct pci_pbm_info
*pbm
= pcp
->pbm
;
548 struct pci_controller_info
*p
= pbm
->parent
;
549 unsigned int portid
= p
->portid
;
550 unsigned int prom_irq
;
551 int prom_node
= pcp
->prom_node
;
554 err
= prom_getproperty(prom_node
, "interrupts",
555 (char *)&prom_irq
, sizeof(prom_irq
));
556 if (err
== 0 || err
== -1) {
561 /* Fully specified already? */
562 if (((prom_irq
& PCI_IRQ_IGN
) >> 6) == portid
) {
563 pdev
->irq
= p
->irq_build(p
, pdev
, prom_irq
);
567 /* An onboard device? (bit 5 set) */
568 if ((prom_irq
& PCI_IRQ_INO
) & 0x20) {
569 pdev
->irq
= p
->irq_build(p
, pdev
, (portid
<< 6 | prom_irq
));
573 /* Can we find a matching entry in the interrupt-map? */
574 if (pci_intmap_match(pdev
, &prom_irq
)) {
575 pdev
->irq
= p
->irq_build(p
, pdev
, (portid
<< 6) | prom_irq
);
579 /* Ok, we have to do it the hard way. */
581 unsigned int bus
, slot
, line
;
583 bus
= (pbm
== &pbm
->parent
->pbm_B
) ? (1 << 4) : 0;
585 /* If we have a legal interrupt property, use it as
588 if (prom_irq
> 0 && prom_irq
< 5) {
589 line
= ((prom_irq
- 1) & 3);
593 /* Else just directly consult PCI config space. */
594 pci_read_config_byte(pdev
, PCI_INTERRUPT_PIN
, &pci_irq_line
);
595 line
= ((pci_irq_line
- 1) & 3);
598 /* Now figure out the slot. */
599 if (pdev
->bus
->number
== pbm
->pci_first_busno
) {
600 if (pbm
== &pbm
->parent
->pbm_A
)
601 slot
= (pdev
->devfn
>> 3) - 1;
603 slot
= (pdev
->devfn
>> 3) - 2;
605 if (pbm
== &pbm
->parent
->pbm_A
)
606 slot
= (pdev
->bus
->self
->devfn
>> 3) - 1;
608 slot
= (pdev
->bus
->self
->devfn
>> 3) - 2;
612 pdev
->irq
= p
->irq_build(p
, pdev
,
613 ((portid
<< 6) & PCI_IRQ_IGN
) |
614 (bus
| slot
| line
));
618 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
,
619 pdev
->irq
& PCI_IRQ_INO
);
622 void __init
pci_fixup_irq(struct pci_pbm_info
*pbm
,
623 struct pci_bus
*pbus
)
625 struct list_head
*walk
= &pbus
->devices
;
627 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
)
628 pdev_fixup_irq(pci_dev_b(walk
));
630 walk
= &pbus
->children
;
631 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
632 pci_fixup_irq(pbm
, pci_bus_b(walk
));
635 #undef DEBUG_BUSMASTERING
637 static void pdev_setup_busmastering(struct pci_dev
*pdev
, int is_66mhz
)
640 u8 hdr_type
, min_gnt
, ltimer
;
642 #ifdef DEBUG_BUSMASTERING
643 printk("PCI: Checking DEV(%s), ", pdev
->name
);
646 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
647 cmd
|= PCI_COMMAND_MASTER
;
648 pci_write_config_word(pdev
, PCI_COMMAND
, cmd
);
650 /* Read it back, if the mastering bit did not
651 * get set, the device does not support bus
652 * mastering so we have nothing to do here.
654 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
655 if ((cmd
& PCI_COMMAND_MASTER
) == 0) {
656 #ifdef DEBUG_BUSMASTERING
657 printk("no bus mastering...\n");
662 /* Set correct cache line size, 64-byte on all
663 * Sparc64 PCI systems. Note that the value is
664 * measured in 32-bit words.
666 #ifdef DEBUG_BUSMASTERING
667 printk("set cachelinesize, ");
669 pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
,
672 pci_read_config_byte(pdev
, PCI_HEADER_TYPE
, &hdr_type
);
674 if (hdr_type
!= PCI_HEADER_TYPE_NORMAL
) {
675 #ifdef DEBUG_BUSMASTERING
676 printk("hdr_type=%x, exit\n", hdr_type
);
681 /* If the latency timer is already programmed with a non-zero
682 * value, assume whoever set it (OBP or whoever) knows what
685 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, <imer
);
687 #ifdef DEBUG_BUSMASTERING
688 printk("ltimer was %x, exit\n", ltimer
);
693 /* XXX Since I'm tipping off the min grant value to
694 * XXX choose a suitable latency timer value, I also
695 * XXX considered making use of the max latency value
696 * XXX as well. Unfortunately I've seen too many bogusly
697 * XXX low settings for it to the point where it lacks
698 * XXX any usefulness. In one case, an ethernet card
699 * XXX claimed a min grant of 10 and a max latency of 5.
700 * XXX Now, if I had two such cards on the same bus I
701 * XXX could not set the desired burst period (calculated
702 * XXX from min grant) without violating the max latency
705 * XXX I blame dumb PC bios implementors for stuff like
706 * XXX this, most of them don't even try to do something
707 * XXX sensible with latency timer values and just set some
708 * XXX default value (usually 32) into every device.
711 pci_read_config_byte(pdev
, PCI_MIN_GNT
, &min_gnt
);
714 /* If no min_gnt setting then use a default
729 /* Use a default value when the min_gnt value
730 * is erroneously high.
732 if (((unsigned int) min_gnt
<< shift_factor
) > 512 ||
733 ((min_gnt
<< shift_factor
) & 0xff) == 0) {
734 ltimer
= 8 << shift_factor
;
736 ltimer
= min_gnt
<< shift_factor
;
740 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, ltimer
);
741 #ifdef DEBUG_BUSMASTERING
742 printk("set ltimer to %x\n", ltimer
);
746 void pci_determine_66mhz_disposition(struct pci_pbm_info
*pbm
,
747 struct pci_bus
*pbus
)
749 struct list_head
*walk
;
753 if (pbm
->is_66mhz_capable
== 0) {
758 walk
= &pbus
->devices
;
760 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
) {
761 struct pci_dev
*pdev
= pci_dev_b(walk
);
763 pci_read_config_word(pdev
, PCI_STATUS
, &status
);
764 if (!(status
& PCI_STATUS_66MHZ
)) {
770 pbm
->all_devs_66mhz
= all_are_66mhz
;
772 printk("PCI%d(PBM%c): Bus running at %dMHz\n",
774 (pbm
== &pbm
->parent
->pbm_A
) ? 'A' : 'B',
775 (all_are_66mhz
? 66 : 33));
778 void pci_setup_busmastering(struct pci_pbm_info
*pbm
,
779 struct pci_bus
*pbus
)
781 struct list_head
*walk
= &pbus
->devices
;
784 is_66mhz
= pbm
->is_66mhz_capable
&& pbm
->all_devs_66mhz
;
786 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
)
787 pdev_setup_busmastering(pci_dev_b(walk
), is_66mhz
);
789 walk
= &pbus
->children
;
790 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
791 pci_setup_busmastering(pbm
, pci_bus_b(walk
));
794 /* Generic helper routines for PCI error reporting. */
795 void pci_scan_for_target_abort(struct pci_controller_info
*p
,
796 struct pci_pbm_info
*pbm
,
797 struct pci_bus
*pbus
)
799 struct list_head
*walk
= &pbus
->devices
;
801 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
) {
802 struct pci_dev
*pdev
= pci_dev_b(walk
);
803 u16 status
, error_bits
;
805 pci_read_config_word(pdev
, PCI_STATUS
, &status
);
807 (status
& (PCI_STATUS_SIG_TARGET_ABORT
|
808 PCI_STATUS_REC_TARGET_ABORT
));
810 pci_write_config_word(pdev
, PCI_STATUS
, error_bits
);
811 printk("PCI%d(PBM%c): Device [%s] saw Target Abort [%016x]\n",
812 p
->index
, ((pbm
== &p
->pbm_A
) ? 'A' : 'B'),
817 walk
= &pbus
->children
;
818 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
819 pci_scan_for_target_abort(p
, pbm
, pci_bus_b(walk
));
822 void pci_scan_for_master_abort(struct pci_controller_info
*p
,
823 struct pci_pbm_info
*pbm
,
824 struct pci_bus
*pbus
)
826 struct list_head
*walk
= &pbus
->devices
;
828 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
) {
829 struct pci_dev
*pdev
= pci_dev_b(walk
);
830 u16 status
, error_bits
;
832 pci_read_config_word(pdev
, PCI_STATUS
, &status
);
834 (status
& (PCI_STATUS_REC_MASTER_ABORT
));
836 pci_write_config_word(pdev
, PCI_STATUS
, error_bits
);
837 printk("PCI%d(PBM%c): Device [%s] received Master Abort [%016x]\n",
838 p
->index
, ((pbm
== &p
->pbm_A
) ? 'A' : 'B'),
843 walk
= &pbus
->children
;
844 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
845 pci_scan_for_master_abort(p
, pbm
, pci_bus_b(walk
));
848 void pci_scan_for_parity_error(struct pci_controller_info
*p
,
849 struct pci_pbm_info
*pbm
,
850 struct pci_bus
*pbus
)
852 struct list_head
*walk
= &pbus
->devices
;
854 for (walk
= walk
->next
; walk
!= &pbus
->devices
; walk
= walk
->next
) {
855 struct pci_dev
*pdev
= pci_dev_b(walk
);
856 u16 status
, error_bits
;
858 pci_read_config_word(pdev
, PCI_STATUS
, &status
);
860 (status
& (PCI_STATUS_PARITY
|
861 PCI_STATUS_DETECTED_PARITY
));
863 pci_write_config_word(pdev
, PCI_STATUS
, error_bits
);
864 printk("PCI%d(PBM%c): Device [%s] saw Parity Error [%016x]\n",
865 p
->index
, ((pbm
== &p
->pbm_A
) ? 'A' : 'B'),
870 walk
= &pbus
->children
;
871 for (walk
= walk
->next
; walk
!= &pbus
->children
; walk
= walk
->next
)
872 pci_scan_for_parity_error(p
, pbm
, pci_bus_b(walk
));