Revert "pci stuff: too much hax now, trying rd890 patch (not merged yet)"
[coreboot.git] / src / devices / pci_device.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * It was originally based on the Linux kernel (drivers/pci/pci.c).
5  *
6  * Modifications are:
7  * Copyright (C) 2003-2004 Linux Networx
8  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
9  * Copyright (C) 2003-2006 Ronald G. Minnich <rminnich@gmail.com>
10  * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov>
11  * Copyright (C) 2005-2006 Tyan
12  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
13  * Copyright (C) 2005-2009 coresystems GmbH
14  * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
15  */
16
17 /*
18  * PCI Bus Services, see include/linux/pci.h for further explanation.
19  *
20  * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
21  * David Mosberger-Tang
22  *
23  * Copyright 1997 -- 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
24  */
25
26 #include <console/console.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <bitops.h>
30 #include <string.h>
31 #include <arch/io.h>
32 #include <device/device.h>
33 #include <device/pci.h>
34 #include <device/pci_ids.h>
35 #include <delay.h>
36 #if CONFIG_HYPERTRANSPORT_PLUGIN_SUPPORT == 1
37 #include <device/hypertransport.h>
38 #endif
39 #if CONFIG_PCIX_PLUGIN_SUPPORT == 1
40 #include <device/pcix.h>
41 #endif
42 #if CONFIG_PCIEXP_PLUGIN_SUPPORT == 1
43 #include <device/pciexp.h>
44 #endif
45 #if CONFIG_AGP_PLUGIN_SUPPORT == 1
46 #include <device/agp.h>
47 #endif
48 #if CONFIG_CARDBUS_PLUGIN_SUPPORT == 1
49 #include <device/cardbus.h>
50 #endif
51 #if CONFIG_PC80_SYSTEM == 1
52 #include <pc80/i8259.h>
53 #endif
54 #if CONFIG_HAVE_ACPI_RESUME && !CONFIG_S3_VGA_ROM_RUN
55 #include <arch/acpi.h>
56 #endif
57 #if CONFIG_CHROMEOS
58 #include <vendorcode/google/chromeos/chromeos.h>
59 #endif
60
61 u8 pci_moving_config8(struct device *dev, unsigned int reg)
62 {
63         u8 value, ones, zeroes;
64
65         value = pci_read_config8(dev, reg);
66
67         pci_write_config8(dev, reg, 0xff);
68         ones = pci_read_config8(dev, reg);
69
70         pci_write_config8(dev, reg, 0x00);
71         zeroes = pci_read_config8(dev, reg);
72
73         pci_write_config8(dev, reg, value);
74
75         return ones ^ zeroes;
76 }
77
78 u16 pci_moving_config16(struct device *dev, unsigned int reg)
79 {
80         u16 value, ones, zeroes;
81
82         value = pci_read_config16(dev, reg);
83
84         pci_write_config16(dev, reg, 0xffff);
85         ones = pci_read_config16(dev, reg);
86
87         pci_write_config16(dev, reg, 0x0000);
88         zeroes = pci_read_config16(dev, reg);
89
90         pci_write_config16(dev, reg, value);
91
92         return ones ^ zeroes;
93 }
94
95 u32 pci_moving_config32(struct device *dev, unsigned int reg)
96 {
97         u32 value, ones, zeroes;
98
99         value = pci_read_config32(dev, reg);
100
101         pci_write_config32(dev, reg, 0xffffffff);
102         ones = pci_read_config32(dev, reg);
103
104         pci_write_config32(dev, reg, 0x00000000);
105         zeroes = pci_read_config32(dev, reg);
106
107         pci_write_config32(dev, reg, value);
108
109         return ones ^ zeroes;
110 }
111
112 /**
113  * Given a device, a capability type, and a last position, return the next
114  * matching capability. Always start at the head of the list.
115  *
116  * @param dev Pointer to the device structure.
117  * @param cap PCI_CAP_LIST_ID of the PCI capability we're looking for.
118  * @param last Location of the PCI capability register to start from.
119  * @return The next matching capability.
120  */
121 unsigned pci_find_next_capability(struct device *dev, unsigned cap,
122                                   unsigned last)
123 {
124         unsigned pos = 0;
125         u16 status;
126         unsigned reps = 48;
127
128         status = pci_read_config16(dev, PCI_STATUS);
129         if (!(status & PCI_STATUS_CAP_LIST))
130                 return 0;
131
132         switch (dev->hdr_type & 0x7f) {
133         case PCI_HEADER_TYPE_NORMAL:
134         case PCI_HEADER_TYPE_BRIDGE:
135                 pos = PCI_CAPABILITY_LIST;
136                 break;
137         case PCI_HEADER_TYPE_CARDBUS:
138                 pos = PCI_CB_CAPABILITY_LIST;
139                 break;
140         default:
141                 return 0;
142         }
143
144         pos = pci_read_config8(dev, pos);
145         while (reps-- && (pos >= 0x40)) { /* Loop through the linked list. */
146                 int this_cap;
147
148                 pos &= ~3;
149                 this_cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID);
150                 printk(BIOS_SPEW, "Capability: type 0x%02x @ 0x%02x\n",
151                        this_cap, pos);
152                 if (this_cap == 0xff)
153                         break;
154
155                 if (!last && (this_cap == cap))
156                         return pos;
157
158                 if (last == pos)
159                         last = 0;
160
161                 pos = pci_read_config8(dev, pos + PCI_CAP_LIST_NEXT);
162         }
163         return 0;
164 }
165
166 /**
167  * Given a device, and a capability type, return the next matching
168  * capability. Always start at the head of the list.
169  *
170  * @param dev Pointer to the device structure.
171  * @param cap PCI_CAP_LIST_ID of the PCI capability we're looking for.
172  * @return The next matching capability.
173  */
174 unsigned pci_find_capability(device_t dev, unsigned cap)
175 {
176         return pci_find_next_capability(dev, cap, 0);
177 }
178
179 /**
180  * Given a device and register, read the size of the BAR for that register.
181  *
182  * @param dev Pointer to the device structure.
183  * @param index Address of the PCI configuration register.
184  * @return TODO
185  */
186 struct resource *pci_get_resource(struct device *dev, unsigned long index)
187 {
188         struct resource *resource;
189         unsigned long value, attr;
190         resource_t moving, limit;
191
192         /* Initialize the resources to nothing. */
193         resource = new_resource(dev, index);
194
195         /* Get the initial value. */
196         value = pci_read_config32(dev, index);
197
198         /* See which bits move. */
199         moving = pci_moving_config32(dev, index);
200
201         /* Initialize attr to the bits that do not move. */
202         attr = value & ~moving;
203
204         /* If it is a 64bit resource look at the high half as well. */
205         if (((attr & PCI_BASE_ADDRESS_SPACE_IO) == 0) &&
206             ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) ==
207              PCI_BASE_ADDRESS_MEM_LIMIT_64)) {
208                 /* Find the high bits that move. */
209                 moving |=
210                     ((resource_t) pci_moving_config32(dev, index + 4)) << 32;
211         }
212
213         /* Find the resource constraints.
214          * Start by finding the bits that move. From there:
215          * - Size is the least significant bit of the bits that move.
216          * - Limit is all of the bits that move plus all of the lower bits.
217          * See PCI Spec 6.2.5.1.
218          */
219         limit = 0;
220         if (moving) {
221                 resource->size = 1;
222                 resource->align = resource->gran = 0;
223                 while (!(moving & resource->size)) {
224                         resource->size <<= 1;
225                         resource->align += 1;
226                         resource->gran += 1;
227                 }
228                 resource->limit = limit = moving | (resource->size - 1);
229         }
230
231         /*
232          * Some broken hardware has read-only registers that do not
233          * really size correctly.
234          *
235          * Example: the Acer M7229 has BARs 1-4 normally read-only,
236          * so BAR1 at offset 0x10 reads 0x1f1. If you size that register
237          * by writing 0xffffffff to it, it will read back as 0x1f1 -- which
238          * is a violation of the spec.
239          *
240          * We catch this case and ignore it by observing which bits move.
241          *
242          * This also catches the common case of unimplemented registers
243          * that always read back as 0.
244          */
245         if (moving == 0) {
246                 if (value != 0) {
247                         printk(BIOS_DEBUG, "%s register %02lx(%08lx), "
248                                "read-only ignoring it\n",
249                                dev_path(dev), index, value);
250                 }
251                 resource->flags = 0;
252         } else if (attr & PCI_BASE_ADDRESS_SPACE_IO) {
253                 /* An I/O mapped base address. */
254                 attr &= PCI_BASE_ADDRESS_IO_ATTR_MASK;
255                 resource->flags |= IORESOURCE_IO;
256                 /* I don't want to deal with 32bit I/O resources. */
257                 resource->limit = 0xffff;
258         } else {
259                 /* A Memory mapped base address. */
260                 attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK;
261                 resource->flags |= IORESOURCE_MEM;
262                 if (attr & PCI_BASE_ADDRESS_MEM_PREFETCH)
263                         resource->flags |= IORESOURCE_PREFETCH;
264                 attr &= PCI_BASE_ADDRESS_MEM_LIMIT_MASK;
265                 if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) {
266                         /* 32bit limit. */
267                         resource->limit = 0xffffffffUL;
268                 } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) {
269                         /* 1MB limit. */
270                         resource->limit = 0x000fffffUL;
271                 } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) {
272                         /* 64bit limit. */
273                         resource->limit = 0xffffffffffffffffULL;
274                         resource->flags |= IORESOURCE_PCI64;
275                 } else {
276                         /* Invalid value. */
277                         printk(BIOS_ERR, "Broken BAR with value %lx\n", attr);
278                         printk(BIOS_ERR, " on dev %s at index %02lx\n",
279                                dev_path(dev), index);
280                         resource->flags = 0;
281                 }
282         }
283
284         /* Don't let the limit exceed which bits can move. */
285         if (resource->limit > limit)
286                 resource->limit = limit;
287
288         return resource;
289 }
290
291 /**
292  * Given a device and an index, read the size of the BAR for that register.
293  *
294  * @param dev Pointer to the device structure.
295  * @param index Address of the PCI configuration register.
296  */
297 static void pci_get_rom_resource(struct device *dev, unsigned long index)
298 {
299         struct resource *resource;
300         unsigned long value;
301         resource_t moving;
302
303         /* Initialize the resources to nothing. */
304         resource = new_resource(dev, index);
305
306         /* Get the initial value. */
307         value = pci_read_config32(dev, index);
308
309         /* See which bits move. */
310         moving = pci_moving_config32(dev, index);
311
312         /* Clear the Enable bit. */
313         moving = moving & ~PCI_ROM_ADDRESS_ENABLE;
314
315         /* Find the resource constraints.
316          * Start by finding the bits that move. From there:
317          * - Size is the least significant bit of the bits that move.
318          * - Limit is all of the bits that move plus all of the lower bits.
319          * See PCI Spec 6.2.5.1.
320          */
321         if (moving) {
322                 resource->size = 1;
323                 resource->align = resource->gran = 0;
324                 while (!(moving & resource->size)) {
325                         resource->size <<= 1;
326                         resource->align += 1;
327                         resource->gran += 1;
328                 }
329                 resource->limit = moving | (resource->size - 1);
330                 resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY;
331         } else {
332                 if (value != 0) {
333                         printk(BIOS_DEBUG, "%s register %02lx(%08lx), "
334                                "read-only ignoring it\n",
335                                dev_path(dev), index, value);
336                 }
337                 resource->flags = 0;
338         }
339         compact_resources(dev);
340 }
341
342 /**
343  * Read the base address registers for a given device.
344  *
345  * @param dev Pointer to the dev structure.
346  * @param howmany How many registers to read (6 for device, 2 for bridge).
347  */
348 static void pci_read_bases(struct device *dev, unsigned int howmany)
349 {
350         unsigned long index;
351
352         for (index = PCI_BASE_ADDRESS_0;
353              (index < PCI_BASE_ADDRESS_0 + (howmany << 2));) {
354                 struct resource *resource;
355                 resource = pci_get_resource(dev, index);
356                 index += (resource->flags & IORESOURCE_PCI64) ? 8 : 4;
357         }
358
359         compact_resources(dev);
360 }
361
362 static void pci_record_bridge_resource(struct device *dev, resource_t moving,
363                                        unsigned index, unsigned long type)
364 {
365         struct resource *resource;
366         unsigned long gran;
367         resource_t step;
368
369         resource = NULL;
370
371         if (!moving)
372                 return;
373
374         /* Initialize the constraints on the current bus. */
375         resource = new_resource(dev, index);
376         resource->size = 0;
377         gran = 0;
378         step = 1;
379         while ((moving & step) == 0) {
380                 gran += 1;
381                 step <<= 1;
382         }
383         resource->gran = gran;
384         resource->align = gran;
385         resource->limit = moving | (step - 1);
386         resource->flags = type | IORESOURCE_PCI_BRIDGE |
387                           IORESOURCE_BRIDGE;
388 }
389
390 static void pci_bridge_read_bases(struct device *dev)
391 {
392         resource_t moving_base, moving_limit, moving;
393
394         /* See if the bridge I/O resources are implemented. */
395         moving_base = ((u32) pci_moving_config8(dev, PCI_IO_BASE)) << 8;
396         moving_base |=
397           ((u32) pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16;
398
399         moving_limit = ((u32) pci_moving_config8(dev, PCI_IO_LIMIT)) << 8;
400         moving_limit |=
401           ((u32) pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16;
402
403         moving = moving_base & moving_limit;
404
405         /* Initialize the I/O space constraints on the current bus. */
406         pci_record_bridge_resource(dev, moving, PCI_IO_BASE, IORESOURCE_IO);
407
408         /* See if the bridge prefmem resources are implemented. */
409         moving_base =
410           ((resource_t) pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16;
411         moving_base |=
412           ((resource_t) pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32;
413
414         moving_limit =
415           ((resource_t) pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16;
416         moving_limit |=
417           ((resource_t) pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32;
418
419         moving = moving_base & moving_limit;
420         /* Initialize the prefetchable memory constraints on the current bus. */
421         pci_record_bridge_resource(dev, moving, PCI_PREF_MEMORY_BASE,
422                                    IORESOURCE_MEM | IORESOURCE_PREFETCH);
423
424         /* See if the bridge mem resources are implemented. */
425         moving_base = ((u32) pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16;
426         moving_limit = ((u32) pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16;
427
428         moving = moving_base & moving_limit;
429
430         /* Initialize the memory resources on the current bus. */
431         pci_record_bridge_resource(dev, moving, PCI_MEMORY_BASE,
432                                    IORESOURCE_MEM);
433
434         compact_resources(dev);
435 }
436
437 void pci_dev_read_resources(struct device *dev)
438 {
439         pci_read_bases(dev, 6);
440         pci_get_rom_resource(dev, PCI_ROM_ADDRESS);
441 }
442
443 void pci_bus_read_resources(struct device *dev)
444 {
445         pci_bridge_read_bases(dev);
446         pci_read_bases(dev, 2);
447         pci_get_rom_resource(dev, PCI_ROM_ADDRESS1);
448 }
449
450 void pci_domain_read_resources(struct device *dev)
451 {
452         struct resource *res;
453
454         /* Initialize the system-wide I/O space constraints. */
455         res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
456         res->limit = 0xffffUL;
457         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
458                      IORESOURCE_ASSIGNED;
459
460         /* Initialize the system-wide memory resources constraints. */
461         res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
462         res->limit = 0xffffffffULL;
463         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
464                      IORESOURCE_ASSIGNED;
465 }
466
467 static void pci_set_resource(struct device *dev, struct resource *resource)
468 {
469         resource_t base, end;
470
471         /* Make certain the resource has actually been assigned a value. */
472         if (!(resource->flags & IORESOURCE_ASSIGNED)) {
473                 printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010llx not "
474                        "assigned\n", dev_path(dev), resource->index,
475                        resource_type(resource), resource->size);
476                 return;
477         }
478
479         /* If this resource is fixed don't worry about it. */
480         if (resource->flags & IORESOURCE_FIXED)
481                 return;
482
483         /* If I have already stored this resource don't worry about it. */
484         if (resource->flags & IORESOURCE_STORED)
485                 return;
486
487         /* If the resource is subtractive don't worry about it. */
488         if (resource->flags & IORESOURCE_SUBTRACTIVE)
489                 return;
490
491         /* Only handle PCI memory and I/O resources for now. */
492         if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
493                 return;
494
495         /* Enable the resources in the command register. */
496         if (resource->size) {
497                 if (resource->flags & IORESOURCE_MEM)
498                         dev->command |= PCI_COMMAND_MEMORY;
499                 if (resource->flags & IORESOURCE_IO)
500                         dev->command |= PCI_COMMAND_IO;
501                 if (resource->flags & IORESOURCE_PCI_BRIDGE)
502                         dev->command |= PCI_COMMAND_MASTER;
503         }
504
505         /* Get the base address. */
506         base = resource->base;
507
508         /* Get the end. */
509         end = resource_end(resource);
510
511         /* Now store the resource. */
512         resource->flags |= IORESOURCE_STORED;
513
514         /*
515          * PCI bridges have no enable bit. They are disabled if the base of
516          * the range is greater than the limit. If the size is zero, disable
517          * by setting the base = limit and end = limit - 2^gran.
518          */
519         if (resource->size == 0 && (resource->flags & IORESOURCE_PCI_BRIDGE)) {
520                 base = resource->limit;
521                 end = resource->limit - (1 << resource->gran);
522                 resource->base = base;
523         }
524
525         if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) {
526                 unsigned long base_lo, base_hi;
527
528                 /*
529                  * Some chipsets allow us to set/clear the I/O bit
530                  * (e.g. VIA 82C686A). So set it to be safe.
531                  */
532                 base_lo = base & 0xffffffff;
533                 base_hi = (base >> 32) & 0xffffffff;
534                 if (resource->flags & IORESOURCE_IO)
535                         base_lo |= PCI_BASE_ADDRESS_SPACE_IO;
536                 pci_write_config32(dev, resource->index, base_lo);
537                 if (resource->flags & IORESOURCE_PCI64)
538                         pci_write_config32(dev, resource->index + 4, base_hi);
539         } else if (resource->index == PCI_IO_BASE) {
540                 /* Set the I/O ranges. */
541                 pci_write_config8(dev, PCI_IO_BASE, base >> 8);
542                 pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16);
543                 pci_write_config8(dev, PCI_IO_LIMIT, end >> 8);
544                 pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16);
545         } else if (resource->index == PCI_MEMORY_BASE) {
546                 /* Set the memory range. */
547                 pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16);
548                 pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16);
549         } else if (resource->index == PCI_PREF_MEMORY_BASE) {
550                 /* Set the prefetchable memory range. */
551                 pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16);
552                 pci_write_config32(dev, PCI_PREF_BASE_UPPER32, base >> 32);
553                 pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, end >> 16);
554                 pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, end >> 32);
555         } else {
556                 /* Don't let me think I stored the resource. */
557                 resource->flags &= ~IORESOURCE_STORED;
558                 printk(BIOS_ERR, "ERROR: invalid resource->index %lx\n",
559                        resource->index);
560         }
561
562         report_resource_stored(dev, resource, "");
563 }
564
565 void pci_dev_set_resources(struct device *dev)
566 {
567         struct resource *res;
568         struct bus *bus;
569         u8 line;
570
571         for (res = dev->resource_list; res; res = res->next)
572                 pci_set_resource(dev, res);
573
574         for (bus = dev->link_list; bus; bus = bus->next) {
575                 if (bus->children)
576                         assign_resources(bus);
577         }
578
579         /* Set a default latency timer. */
580         pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40);
581
582         /* Set a default secondary latency timer. */
583         if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE)
584                 pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40);
585
586         /* Zero the IRQ settings. */
587         line = pci_read_config8(dev, PCI_INTERRUPT_PIN);
588         if (line)
589                 pci_write_config8(dev, PCI_INTERRUPT_LINE, 0);
590
591         /* Set the cache line size, so far 64 bytes is good for everyone. */
592         pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2);
593 }
594
595 void pci_dev_enable_resources(struct device *dev)
596 {
597         const struct pci_operations *ops;
598         u16 command;
599
600         /* Set the subsystem vendor and device ID for mainboard devices. */
601         ops = ops_pci(dev);
602         if (dev->on_mainboard && ops && ops->set_subsystem) {
603                 printk(BIOS_DEBUG, "%s subsystem <- %04x/%04x\n",
604                         dev_path(dev), dev->subsystem_vendor,
605                         dev->subsystem_device);
606                 ops->set_subsystem(dev, dev->subsystem_vendor,
607                         dev->subsystem_device);
608         }
609         command = pci_read_config16(dev, PCI_COMMAND);
610         command |= dev->command;
611
612         /* v3 has
613          * command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR);  // Error check.
614          */
615
616         printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command);
617         pci_write_config16(dev, PCI_COMMAND, command);
618 }
619
620 void pci_bus_enable_resources(struct device *dev)
621 {
622         u16 ctrl;
623
624         /*
625          * Enable I/O in command register if there is VGA card
626          * connected with (even it does not claim I/O resource).
627          */
628         if (dev->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
629                 dev->command |= PCI_COMMAND_IO;
630         ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
631         ctrl |= dev->link_list->bridge_ctrl;
632         ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* Error check. */
633         printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
634         pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
635
636         pci_dev_enable_resources(dev);
637 }
638
639 void pci_bus_reset(struct bus *bus)
640 {
641         u16 ctl;
642
643         ctl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL);
644         ctl |= PCI_BRIDGE_CTL_BUS_RESET;
645         pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl);
646         mdelay(10);
647
648         ctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
649         pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl);
650         delay(1);
651 }
652
653 void pci_dev_set_subsystem(struct device *dev, unsigned vendor, unsigned device)
654 {
655         pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
656                            ((device & 0xffff) << 16) | (vendor & 0xffff));
657 }
658
659 /** Default handler: only runs the relevant PCI BIOS. */
660 void pci_dev_init(struct device *dev)
661 {
662 #if CONFIG_PCI_ROM_RUN == 1 || CONFIG_VGA_ROM_RUN == 1
663         struct rom_header *rom, *ram;
664
665         if (CONFIG_PCI_ROM_RUN != 1 && /* Only execute VGA ROMs. */
666             ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA))
667                 return;
668
669         if (CONFIG_VGA_ROM_RUN != 1 && /* Only execute non-VGA ROMs. */
670             ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA))
671                 return;
672
673 #if CONFIG_CHROMEOS
674         /* In ChromeOS we want to boot blazingly fast. Therefore
675          * we don't run (VGA) option ROMs, unless we have to print
676          * something on the screen before the kernel is loaded.
677          */
678         if (!developer_mode_enabled() && !recovery_mode_enabled())
679                 return;
680 #endif
681
682         rom = pci_rom_probe(dev);
683         if (rom == NULL)
684                 return;
685
686         ram = pci_rom_load(dev, rom);
687         if (ram == NULL)
688                 return;
689
690 #if CONFIG_HAVE_ACPI_RESUME && !CONFIG_S3_VGA_ROM_RUN
691         /* If S3_VGA_ROM_RUN is disabled, skip running VGA option
692          * ROMs when coming out of an S3 resume.
693          */
694         if ((acpi_slp_type == 3) &&
695                 ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA))
696                 return;
697 #endif
698         run_bios(dev, (unsigned long)ram);
699 #endif /* CONFIG_PCI_ROM_RUN || CONFIG_VGA_ROM_RUN */
700 }
701
702 /** Default device operation for PCI devices */
703 static struct pci_operations pci_dev_ops_pci = {
704         .set_subsystem = pci_dev_set_subsystem,
705 };
706
707 struct device_operations default_pci_ops_dev = {
708         .read_resources   = pci_dev_read_resources,
709         .set_resources    = pci_dev_set_resources,
710         .enable_resources = pci_dev_enable_resources,
711         .init             = pci_dev_init,
712         .scan_bus         = 0,
713         .enable           = 0,
714         .ops_pci          = &pci_dev_ops_pci,
715 };
716
717 /** Default device operations for PCI bridges */
718 static struct pci_operations pci_bus_ops_pci = {
719         .set_subsystem = 0,
720 };
721
722 struct device_operations default_pci_ops_bus = {
723         .read_resources   = pci_bus_read_resources,
724         .set_resources    = pci_dev_set_resources,
725         .enable_resources = pci_bus_enable_resources,
726         .init             = 0,
727         .scan_bus         = pci_scan_bridge,
728         .enable           = 0,
729         .reset_bus        = pci_bus_reset,
730         .ops_pci          = &pci_bus_ops_pci,
731 };
732
733 /**
734  * Detect the type of downstream bridge.
735  *
736  * This function is a heuristic to detect which type of bus is downstream
737  * of a PCI-to-PCI bridge. This functions by looking for various capability
738  * blocks to figure out the type of downstream bridge. PCI-X, PCI-E, and
739  * Hypertransport all seem to have appropriate capabilities.
740  *
741  * When only a PCI-Express capability is found the type is examined to see
742  * which type of bridge we have.
743  *
744  * @param dev Pointer to the device structure of the bridge.
745  * @return Appropriate bridge operations.
746  */
747 static struct device_operations *get_pci_bridge_ops(device_t dev)
748 {
749         unsigned int pos;
750
751 #if CONFIG_PCIX_PLUGIN_SUPPORT == 1
752         pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
753         if (pos) {
754                 printk(BIOS_DEBUG, "%s subordinate bus PCI-X\n", dev_path(dev));
755                 return &default_pcix_ops_bus;
756         }
757 #endif
758 #if CONFIG_AGP_PLUGIN_SUPPORT == 1
759         /* How do I detect a PCI to AGP bridge? */
760 #endif
761 #if CONFIG_HYPERTRANSPORT_PLUGIN_SUPPORT == 1
762         pos = 0;
763         while ((pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos))) {
764                 u16 flags;
765                 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
766                 if ((flags >> 13) == 1) {
767                         /* Host or Secondary Interface */
768                         printk(BIOS_DEBUG, "%s subordinate bus HT\n",
769                                dev_path(dev));
770                         return &default_ht_ops_bus;
771                 }
772         }
773 #endif
774 #if CONFIG_PCIEXP_PLUGIN_SUPPORT == 1
775         pos = pci_find_capability(dev, PCI_CAP_ID_PCIE);
776         if (pos) {
777                 u16 flags;
778                 flags = pci_read_config16(dev, pos + PCI_EXP_FLAGS);
779                 switch ((flags & PCI_EXP_FLAGS_TYPE) >> 4) {
780                 case PCI_EXP_TYPE_ROOT_PORT:
781                 case PCI_EXP_TYPE_UPSTREAM:
782                 case PCI_EXP_TYPE_DOWNSTREAM:
783                         printk(BIOS_DEBUG, "%s subordinate bus PCI Express\n",
784                                dev_path(dev));
785                         return &default_pciexp_ops_bus;
786                 case PCI_EXP_TYPE_PCI_BRIDGE:
787                         printk(BIOS_DEBUG, "%s subordinate PCI\n",
788                                dev_path(dev));
789                         return &default_pci_ops_bus;
790                 default:
791                         break;
792                 }
793         }
794 #endif
795         return &default_pci_ops_bus;
796 }
797
798 /**
799  * Set up PCI device operation.
800  *
801  * Check if it already has a driver. If not, use find_device_operations(),
802  * or set to a default based on type.
803  *
804  * @param dev Pointer to the device whose pci_ops you want to set.
805  * @see pci_drivers
806  */
807 static void set_pci_ops(struct device *dev)
808 {
809         struct pci_driver *driver;
810
811         if (dev->ops)
812                 return;
813
814         /*
815          * Look through the list of setup drivers and find one for
816          * this PCI device.
817          */
818         for (driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) {
819                 if ((driver->vendor == dev->vendor) &&
820                     (driver->device == dev->device)) {
821                         dev->ops = (struct device_operations *)driver->ops;
822                         printk(BIOS_SPEW, "%s [%04x/%04x] %sops\n",
823                                dev_path(dev), driver->vendor, driver->device,
824                                (driver->ops->scan_bus ? "bus " : ""));
825                         return;
826                 }
827         }
828
829         /* If I don't have a specific driver use the default operations. */
830         switch (dev->hdr_type & 0x7f) { /* Header type */
831         case PCI_HEADER_TYPE_NORMAL:
832                 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)
833                         goto bad;
834                 dev->ops = &default_pci_ops_dev;
835                 break;
836         case PCI_HEADER_TYPE_BRIDGE:
837                 if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
838                         goto bad;
839                 dev->ops = get_pci_bridge_ops(dev);
840                 break;
841 #if CONFIG_CARDBUS_PLUGIN_SUPPORT == 1
842         case PCI_HEADER_TYPE_CARDBUS:
843                 dev->ops = &default_cardbus_ops_bus;
844                 break;
845 #endif
846 default:
847 bad:
848                 if (dev->enabled) {
849                         printk(BIOS_ERR, "%s [%04x/%04x/%06x] has unknown "
850                                "header type %02x, ignoring.\n", dev_path(dev),
851                                dev->vendor, dev->device,
852                                dev->class >> 8, dev->hdr_type);
853                 }
854         }
855 }
856
857 /**
858  * See if we have already allocated a device structure for a given devfn.
859  *
860  * Given a linked list of PCI device structures and a devfn number, find the
861  * device structure correspond to the devfn, if present. This function also
862  * removes the device structure from the linked list.
863  *
864  * @param list The device structure list.
865  * @param devfn A device/function number.
866  * @return Pointer to the device structure found or NULL if we have not
867  *         allocated a device for this devfn yet.
868  */
869 static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn)
870 {
871         struct device *dev;
872
873         dev = 0;
874         for (; *list; list = &(*list)->sibling) {
875                 if ((*list)->path.type != DEVICE_PATH_PCI) {
876                         printk(BIOS_ERR, "child %s not a PCI device\n",
877                                dev_path(*list));
878                         continue;
879                 }
880                 if ((*list)->path.pci.devfn == devfn) {
881                         /* Unlink from the list. */
882                         dev = *list;
883                         *list = (*list)->sibling;
884                         dev->sibling = NULL;
885                         break;
886                 }
887         }
888
889         /*
890          * Just like alloc_dev() add the device to the list of devices on the
891          * bus. When the list of devices was formed we removed all of the
892          * parents children, and now we are interleaving static and dynamic
893          * devices in order on the bus.
894          */
895         if (dev) {
896                 struct device *child;
897
898                 /* Find the last child of our parent. */
899                 for (child = dev->bus->children; child && child->sibling;)
900                         child = child->sibling;
901
902                 /* Place the device on the list of children of its parent. */
903                 if (child)
904                         child->sibling = dev;
905                 else
906                         dev->bus->children = dev;
907         }
908
909         return dev;
910 }
911
912 /**
913  * Scan a PCI bus.
914  *
915  * Determine the existence of a given PCI device. Allocate a new struct device
916  * if dev==NULL was passed in and the device exists in hardware.
917  *
918  * @param dev Pointer to the dev structure.
919  * @param bus Pointer to the bus structure.
920  * @param devfn A device/function number to look at.
921  * @return The device structure for the device (if found), NULL otherwise.
922  */
923 device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn)
924 {
925         u32 id, class;
926         u8 hdr_type;
927
928         /* Detect if a device is present. */
929         if (!dev) {
930                 struct device dummy;
931
932                 dummy.bus = bus;
933                 dummy.path.type = DEVICE_PATH_PCI;
934                 dummy.path.pci.devfn = devfn;
935
936                 id = pci_read_config32(&dummy, PCI_VENDOR_ID);
937                 /*
938                  * Have we found something? Some broken boards return 0 if a
939                  * slot is empty, but the expected answer is 0xffffffff.
940                  */
941                 if (id == 0xffffffff)
942                         return NULL;
943
944                 if ((id == 0x00000000) || (id == 0x0000ffff) ||
945                     (id == 0xffff0000)) {
946                         printk(BIOS_SPEW, "%s, bad id 0x%x\n",
947                                dev_path(&dummy), id);
948                         return NULL;
949                 }
950                 dev = alloc_dev(bus, &dummy.path);
951         } else {
952                 /*
953                  * Enable/disable the device. Once we have found the device-
954                  * specific operations this operations we will disable the
955                  * device with those as well.
956                  *
957                  * This is geared toward devices that have subfunctions
958                  * that do not show up by default.
959                  *
960                  * If a device is a stuff option on the motherboard
961                  * it may be absent and enable_dev() must cope.
962                  */
963                 /* Run the magic enable sequence for the device. */
964                 if (dev->chip_ops && dev->chip_ops->enable_dev)
965                         dev->chip_ops->enable_dev(dev);
966
967                 /* Now read the vendor and device ID. */
968                 id = pci_read_config32(dev, PCI_VENDOR_ID);
969
970                 /*
971                  * If the device does not have a PCI ID disable it. Possibly
972                  * this is because we have already disabled the device. But
973                  * this also handles optional devices that may not always
974                  * show up.
975                  */
976                 /* If the chain is fully enumerated quit */
977                 if ((id == 0xffffffff) || (id == 0x00000000) ||
978                     (id == 0x0000ffff) || (id == 0xffff0000)) {
979                         if (dev->enabled) {
980                                 printk(BIOS_INFO, "PCI: Static device %s not "
981                                        "found, disabling it.\n", dev_path(dev));
982                                 dev->enabled = 0;
983                         }
984                         return dev;
985                 }
986         }
987
988         /* Read the rest of the PCI configuration information. */
989         hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
990         class = pci_read_config32(dev, PCI_CLASS_REVISION);
991
992         /* Store the interesting information in the device structure. */
993         dev->vendor = id & 0xffff;
994         dev->device = (id >> 16) & 0xffff;
995         dev->hdr_type = hdr_type;
996
997         /* Class code, the upper 3 bytes of PCI_CLASS_REVISION. */
998         dev->class = class >> 8;
999
1000         /* Architectural/System devices always need to be bus masters. */
1001         if ((dev->class >> 16) == PCI_BASE_CLASS_SYSTEM)
1002                 dev->command |= PCI_COMMAND_MASTER;
1003
1004         /*
1005          * Look at the vendor and device ID, or at least the header type and
1006          * class and figure out which set of configuration methods to use.
1007          * Unless we already have some PCI ops.
1008          */
1009         set_pci_ops(dev);
1010
1011         /* Now run the magic enable/disable sequence for the device. */
1012         if (dev->ops && dev->ops->enable)
1013                 dev->ops->enable(dev);
1014
1015         /* Display the device. */
1016         printk(BIOS_DEBUG, "%s [%04x/%04x] %s%s\n", dev_path(dev),
1017                dev->vendor, dev->device, dev->enabled ? "enabled" : "disabled",
1018                dev->ops ? "" : " No operations");
1019
1020         return dev;
1021 }
1022
1023 /**
1024  * Scan a PCI bus.
1025  *
1026  * Determine the existence of devices and bridges on a PCI bus. If there are
1027  * bridges on the bus, recursively scan the buses behind the bridges.
1028  *
1029  * This function is the default scan_bus() method for the root device
1030  * 'dev_root'.
1031  *
1032  * @param bus Pointer to the bus structure.
1033  * @param min_devfn Minimum devfn to look at in the scan, usually 0x00.
1034  * @param max_devfn Maximum devfn to look at in the scan, usually 0xff.
1035  * @param max Current bus number.
1036  * @return The maximum bus number found, after scanning all subordinate busses.
1037  */
1038 unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn,
1039                           unsigned max_devfn, unsigned int max)
1040 {
1041         unsigned int devfn;
1042         struct device *old_devices;
1043         struct device *child;
1044
1045 #if CONFIG_PCI_BUS_SEGN_BITS
1046         printk(BIOS_DEBUG, "PCI: pci_scan_bus for bus %04x:%02x\n",
1047                bus->secondary >> 8, bus->secondary & 0xff);
1048 #else
1049         printk(BIOS_DEBUG, "PCI: pci_scan_bus for bus %02x\n", bus->secondary);
1050 #endif
1051
1052         /* Maximum sane devfn is 0xFF. */
1053         if (max_devfn > 0xff) {
1054                 printk(BIOS_ERR, "PCI: pci_scan_bus limits devfn %x - "
1055                        "devfn %x\n", min_devfn, max_devfn);
1056                 printk(BIOS_ERR, "PCI: pci_scan_bus upper limit too big. "
1057                        "Using 0xff.\n");
1058                 max_devfn=0x08;
1059         }
1060
1061         old_devices = bus->children;
1062         bus->children = NULL;
1063
1064         post_code(0x24);
1065
1066         /*
1067          * Probe all devices/functions on this bus with some optimization for
1068          * non-existence and single function devices.
1069          */
1070         for (devfn = min_devfn; devfn <= max_devfn; devfn++) {
1071                 struct device *dev;
1072
1073                 /* First thing setup the device structure. */
1074                 printk(BIOS_INFO, "%s: before pci_scan_get_dev! devfn: %d\n", __func__, devfn);
1075                 dev = pci_scan_get_dev(&old_devices, devfn);
1076                 printk(BIOS_INFO, "%s: after  pci_scan_get_dev!\n", __func__);
1077
1078                 /* See if a device is present and setup the device structure. */
1079                 printk(BIOS_INFO, "%s: before pci_probe_dev!\n", __func__);
1080                 dev = pci_probe_dev(dev, bus, devfn);
1081                 printk(BIOS_INFO, "%s: after  pci_probe_dev!\n", __func__);
1082
1083                 /*
1084                  * If this is not a multi function device, or the device is
1085                  * not present don't waste time probing another function.
1086                  * Skip to next device.
1087                  */
1088                 if ((PCI_FUNC(devfn) == 0x00) && (!dev
1089                      || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) {
1090                         devfn += 0x07;
1091                 }
1092         }
1093
1094         post_code(0x25);
1095
1096         /*
1097          * Warn if any leftover static devices are are found.
1098          * There's probably a problem in devicetree.cb.
1099          */
1100         if (old_devices) {
1101                 device_t left;
1102                 printk(BIOS_WARNING, "PCI: Left over static devices:\n");
1103                 for (left = old_devices; left; left = left->sibling)
1104                         printk(BIOS_WARNING, "%s\n", dev_path(left));
1105
1106                 printk(BIOS_WARNING, "PCI: Check your devicetree.cb.\n");
1107         }
1108
1109         /*
1110          * For all children that implement scan_bus() (i.e. bridges)
1111          * scan the bus behind that child.
1112          */
1113         for (child = bus->children; child; child = child->sibling)
1114                 max = scan_bus(child, max);
1115
1116         /*
1117          * We've scanned the bus and so we know all about what's on the other
1118          * side of any bridges that may be on this bus plus any devices.
1119          * Return how far we've got finding sub-buses.
1120          */
1121         printk(BIOS_DEBUG, "PCI: pci_scan_bus returning with max=%03x\n", max);
1122         post_code(0x55);
1123         return max;
1124 }
1125
1126 /**
1127  * Scan a PCI bridge and the buses behind the bridge.
1128  *
1129  * Determine the existence of buses behind the bridge. Set up the bridge
1130  * according to the result of the scan.
1131  *
1132  * This function is the default scan_bus() method for PCI bridge devices.
1133  *
1134  * @param dev Pointer to the bridge device.
1135  * @param max The highest bus number assigned up to now.
1136  * @param do_scan_bus TODO
1137  * @return The maximum bus number found, after scanning all subordinate buses.
1138  */
1139 unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max,
1140                                 unsigned int (*do_scan_bus) (struct bus * bus,
1141                                                              unsigned min_devfn,
1142                                                              unsigned max_devfn,
1143                                                              unsigned int max))
1144 {
1145         struct bus *bus;
1146         u32 buses;
1147         u16 cr;
1148
1149         printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(dev));
1150
1151         if (dev->link_list == NULL) {
1152                 struct bus *link;
1153                 link = malloc(sizeof(*link));
1154                 if (link == NULL)
1155                         die("Couldn't allocate a link!\n");
1156                 memset(link, 0, sizeof(*link));
1157                 link->dev = dev;
1158                 dev->link_list = link;
1159         }
1160
1161         bus = dev->link_list;
1162
1163         /*
1164          * Set up the primary, secondary and subordinate bus numbers. We have
1165          * no idea how many buses are behind this bridge yet, so we set the
1166          * subordinate bus number to 0xff for the moment.
1167          */
1168         bus->secondary = ++max;
1169         bus->subordinate = 0xff;
1170
1171         /* Clear all status bits and turn off memory, I/O and master enables. */
1172         cr = pci_read_config16(dev, PCI_COMMAND);
1173         pci_write_config16(dev, PCI_COMMAND, 0x0000);
1174         pci_write_config16(dev, PCI_STATUS, 0xffff);
1175
1176         /*
1177          * Read the existing primary/secondary/subordinate bus
1178          * number configuration.
1179          */
1180         buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
1181
1182         /*
1183          * Configure the bus numbers for this bridge: the configuration
1184          * transactions will not be propagated by the bridge if it is not
1185          * correctly configured.
1186          */
1187         buses &= 0xff000000;
1188         buses |= (((unsigned int)(dev->bus->secondary) << 0) |
1189                   ((unsigned int)(bus->secondary) << 8) |
1190                   ((unsigned int)(bus->subordinate) << 16));
1191         pci_write_config32(dev, PCI_PRIMARY_BUS, buses);
1192
1193         /* Now we can scan all subordinate buses (those behind the bridge). */
1194         max = do_scan_bus(bus, 0x00, 0xff, max);
1195
1196         /*
1197          * We know the number of buses behind this bridge. Set the subordinate
1198          * bus number to its real value.
1199          */
1200         bus->subordinate = max;
1201         buses = (buses & 0xff00ffff) | ((unsigned int)(bus->subordinate) << 16);
1202         pci_write_config32(dev, PCI_PRIMARY_BUS, buses);
1203         pci_write_config16(dev, PCI_COMMAND, cr);
1204
1205         printk(BIOS_SPEW, "%s returns max %d\n", __func__, max);
1206         return max;
1207 }
1208
1209 /**
1210  * Scan a PCI bridge and the buses behind the bridge.
1211  *
1212  * Determine the existence of buses behind the bridge. Set up the bridge
1213  * according to the result of the scan.
1214  *
1215  * This function is the default scan_bus() method for PCI bridge devices.
1216  *
1217  * @param dev Pointer to the bridge device.
1218  * @param max The highest bus number assigned up to now.
1219  * @return The maximum bus number found, after scanning all subordinate buses.
1220  */
1221 unsigned int pci_scan_bridge(struct device *dev, unsigned int max)
1222 {
1223         return do_pci_scan_bridge(dev, max, pci_scan_bus);
1224 }
1225
1226 /**
1227  * Scan a PCI domain.
1228  *
1229  * This function is the default scan_bus() method for PCI domains.
1230  *
1231  * @param dev Pointer to the domain.
1232  * @param max The highest bus number assigned up to now.
1233  * @return The maximum bus number found, after scanning all subordinate busses.
1234  */
1235 unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
1236 {
1237         max = pci_scan_bus(dev->link_list, PCI_DEVFN(0, 0), 0xff, max);
1238         return max;
1239 }
1240
1241 #if CONFIG_PC80_SYSTEM == 1
1242 /**
1243  * Assign IRQ numbers.
1244  *
1245  * This function assigns IRQs for all functions contained within the indicated
1246  * device address. If the device does not exist or does not require interrupts
1247  * then this function has no effect.
1248  *
1249  * This function should be called for each PCI slot in your system.
1250  *
1251  * @param bus Pointer to the bus structure.
1252  * @param slot TODO
1253  * @param pIntAtoD An array of IRQ #s that are assigned to PINTA through PINTD
1254  *        of this slot. The particular IRQ #s that are passed in depend on the
1255  *        routing inside your southbridge and on your board.
1256  */
1257 void pci_assign_irqs(unsigned bus, unsigned slot,
1258                      const unsigned char pIntAtoD[4])
1259 {
1260         unsigned int funct;
1261         device_t pdev;
1262         u8 line, irq;
1263
1264         /* Each slot may contain up to eight functions. */
1265         for (funct = 0; funct < 8; funct++) {
1266                 pdev = dev_find_slot(bus, (slot << 3) + funct);
1267
1268                 if (!pdev)
1269                         continue;
1270
1271                 line = pci_read_config8(pdev, PCI_INTERRUPT_PIN);
1272
1273                 /* PCI spec says all values except 1..4 are reserved. */
1274                 if ((line < 1) || (line > 4))
1275                         continue;
1276
1277                 irq = pIntAtoD[line - 1];
1278
1279                 printk(BIOS_DEBUG, "Assigning IRQ %d to %d:%x.%d\n",
1280                        irq, bus, slot, funct);
1281
1282                 pci_write_config8(pdev, PCI_INTERRUPT_LINE,
1283                                   pIntAtoD[line - 1]);
1284
1285 #ifdef PARANOID_IRQ_ASSIGNMENTS
1286                 irq = pci_read_config8(pdev, PCI_INTERRUPT_LINE);
1287                 printk(BIOS_DEBUG, "  Readback = %d\n", irq);
1288 #endif
1289
1290 #if CONFIG_PC80_SYSTEM == 1
1291                 /* Change to level triggered. */
1292                 i8259_configure_irq_trigger(pIntAtoD[line - 1],
1293                                             IRQ_LEVEL_TRIGGERED);
1294 #endif
1295         }
1296 }
1297 #endif