source: rtems/c/src/lib/libbsp/powerpc/shared/bootloader/pci.c @ e79a1947

4.104.114.84.95
Last change on this file since e79a1947 was e79a1947, checked in by Joel Sherrill <joel.sherrill@…>, on 11/10/04 at 23:51:17

2004-11-10 Richard Campbell <richard.campbell@…>

  • Makefile.am, bootloader/misc.c, bootloader/pci.c, bootloader/pci.h, console/console.c, console/inch.c, console/reboot.c, console/uart.c, console/uart.h, irq/irq.c, irq/irq.h, irq/irq_init.c, motorola/motorola.c, motorola/motorola.h, openpic/openpic.c, openpic/openpic.h, pci/detect_raven_bridge.c, pci/pci.c, start/start.S, startup/bspstart.c, vectors/vectors_init.c, vme/vmeconfig.c: Add MVME2100 BSP and MPC8240 support. There was also a significant amount of spelling and whitespace cleanup.
  • tod/todcfg.c: New file.
  • Property mode set to 100644
File size: 41.1 KB
Line 
1/*
2 *  pci.c -- Crude pci handling for early boot.
3 *
4 *  Copyright (C) 1998, 1999 Gabriel Paubert, paubert@iram.es
5 *
6 *  Modified to compile in RTEMS development environment
7 *  by Eric Valette
8 *
9 *  Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
10 *
11 *  The license and distribution terms for this file may be
12 *  found in found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 * $Id$
16 */
17
18#include <sys/types.h>
19#include <rtems/bspIo.h>
20#include <libcpu/spr.h>
21#include "bootldr.h"
22#include "pci.h"
23#include <libcpu/io.h>
24#include <libcpu/page.h>
25#include <bsp/consoleIo.h>
26#include <string.h>
27
28#include <string.h>
29
30typedef unsigned int u32;
31
32
33
34/*
35#define DEBUG
36#define PCI_DEBUG
37*/
38
39/* Used to reorganize PCI space on stupid machines which spread resources
40 * across a wide address space. This is bad when P2P bridges are present
41 * or when it limits the mappings that a resource hog like a PCI<->VME
42 * bridge can use.
43 */
44
45typedef struct _pci_resource {
46      struct _pci_resource *next;
47      struct pci_dev *dev;
48      u_long base;    /* will be 64 bits on 64 bits machines */
49      u_long size;
50      u_char type;      /* 1 is I/O else low order 4 bits of the memory type */
51      u_char reg;       /* Register # in conf space header */
52      u_short cmd;    /* Original cmd byte */
53} pci_resource;
54
55typedef struct _pci_area {
56      struct _pci_area *next;
57      u_long start;
58      u_long end;
59      struct pci_bus *bus;
60      u_int flags;
61} pci_area;
62
63typedef struct _pci_area_head {
64      pci_area *head;
65      u_long mask;
66      int high; /* To allocate from top */
67} pci_area_head;
68
69#define PCI_AREA_PREFETCHABLE 0
70#define PCI_AREA_MEMORY 1
71#define PCI_AREA_IO 2
72
73struct _pci_private {
74      volatile u_int * config_addr;
75      volatile u_char * config_data;
76      struct pci_dev **last_dev_p;
77      struct pci_bus pci_root;
78      pci_resource *resources;
79      pci_area_head io, mem;
80
81} pci_private = {
82   config_addr: NULL,
83   config_data: (volatile u_char *) 0x80800000,
84   last_dev_p: NULL,
85   resources: NULL,
86   io: {NULL, 0xfff, 0},
87   mem: {NULL, 0xfffff, 0}
88};
89
90#define pci ((struct _pci_private *)(bd->pci_private))
91#define pci_root pci->pci_root
92
93#if !defined(DEBUG)
94#undef PCI_DEBUG
95/*
96  #else
97  #define PCI_DEBUG
98*/
99#endif
100
101#if defined(PCI_DEBUG)
102static void
103print_pci_resources(const char *s) {
104   pci_resource *p;
105   printk("%s", s);
106   for (p=pci->resources; p; p=p->next) {
107/*
108      printk("  %p:%p %06x %08lx %08lx %d\n",
109             p, p->next,
110             (p->dev->devfn<<8)+(p->dev->bus->number<<16)
111             +0x10+p->reg*4,
112             p->base,
113             p->size,
114             p->type);
115*/
116
117      printk("  %p:%p %d:%02x (%04x:%04x) %08lx %08lx %d\n",
118             p, p->next,
119             p->dev->bus->number, PCI_SLOT(p->dev->devfn),
120             p->dev->vendor, p->dev->device,
121             p->base,
122             p->size,
123             p->type);
124
125   }
126}
127
128static void
129print_pci_area(pci_area *p) {
130   for (; p; p=p->next) {
131      printk("    %p:%p %p %08lx %08lx\n",
132             p, p->next, p->bus, p->start, p->end);
133   }
134}
135
136static void
137print_pci_areas(const char *s) {
138   printk("%s  PCI I/O areas:\n",s);
139   print_pci_area(pci->io.head);
140   printk("  PCI memory areas:\n");
141   print_pci_area(pci->mem.head);
142}
143#else
144#define print_pci_areas(x)
145#define print_pci_resources(x)
146#endif
147
148/* Maybe there are some devices who use a size different
149 * from the alignment. For now we assume both are the same.
150 * The blacklist might be used for other weird things in the future too,
151 * since weird non PCI complying devices seem to proliferate these days.
152 */
153
154struct blacklist_entry {
155      u_short vendor, device;
156      u_char reg;
157      u_long actual_size;
158};
159
160#define BLACKLIST(vid, did, breg, actual_size) \
161        {PCI_VENDOR_ID_##vid, PCI_DEVICE_ID_##vid##_##did, breg, actual_size}
162
163static struct blacklist_entry blacklist[] = {
164   BLACKLIST(S3, TRIO, 0, 0x04000000),
165   {0xffff, 0, 0, 0}
166};
167
168/* This function filters resources and then inserts them into a list of
169 * configurable pci resources.
170 */
171
172#define AREA(r) \
173(((r->type&PCI_BASE_ADDRESS_SPACE)==PCI_BASE_ADDRESS_SPACE_IO) ? PCI_AREA_IO :\
174          ((r->type&PCI_BASE_ADDRESS_MEM_PREFETCH) ? PCI_AREA_PREFETCHABLE :\
175           PCI_AREA_MEMORY))
176
177static int insert_before(pci_resource *e, pci_resource *t) {
178   if (e->dev->bus->number != t->dev->bus->number)
179      return e->dev->bus->number > t->dev->bus->number;
180   if (AREA(e) != AREA(t)) return AREA(e)<AREA(t);
181   return (e->size > t->size);
182}
183
184static void insert_resource(pci_resource *r) {
185   struct blacklist_entry *b;
186   pci_resource *p;
187   if (!r) return;
188
189   /* First fixup in case we have a blacklist entry. Note that this
190    * may temporarily leave a resource in an inconsistent state: with
191    * (base & (size-1)) !=0. This is harmless.
192    */
193   for (b=blacklist; b->vendor!=0xffff; b++) {
194      if ((r->dev->vendor==b->vendor) &&
195          (r->dev->device==b->device) &&
196          (r->reg==b->reg)) {
197         r->size=b->actual_size;
198         break;
199      }
200   }
201
202   /* Motorola NT firmware does not configure pci devices which are not
203    * required for booting, others do. For now:
204    * - allocated devices in the ISA range (64kB I/O, 16Mb memory)
205    *   but non zero base registers are left as is.
206    * - all other registers, whether already allocated or not, are
207    *   reallocated unless they require an inordinate amount of
208    *   resources (>256 Mb for memory >64kB for I/O). These
209    *   devices with too large mapping requirements are simply ignored
210    *   and their bases are set to 0. This should disable the
211    *   corresponding decoders according to the PCI specification.
212    *   Many devices are buggy in this respect, however, but the
213    *   limits have hopefully been set high enough to avoid problems.
214    */
215
216   /*
217   ** This is little ugly below.  It seems that at least on the MCP750,
218   ** the PBC has some default IO space mappings that the bsp #defines
219   ** that read/write to PCI I/O space assume, particuarly the i8259
220   ** manipulation code.  So, if we allow the small IO spaces on PCI bus
221   ** 0 and 1 to be remapped, the registers can shift out from under the
222   ** #defines.  This is particuarly awful, but short of redefining the
223   ** PCI I/O primitives to be functions with base addresses read from
224   ** the hardware, we are stuck with the kludge below.  Note that
225   ** everything is remapped on the CPCI backplane and any downstream
226   ** hardware, its just the builtin stuff we're tiptoeing around.
227   **
228   ** Gregm, 7/16/2003
229   **
230   ** Gregm, changed 11/2003 so IO devices only on bus 0 zero are not
231   ** remapped.  This covers the builtin pc-like io devices- but
232   ** properly maps IO devices on higher busses.
233   */
234   if( r->dev->bus->number == 0 )
235   {
236   if ((r->type==PCI_BASE_ADDRESS_SPACE_IO)
237       ? (r->base && r->base <0x10000)
238       : (r->base && r->base <0x1000000)) {
239
240#ifdef PCI_DEBUG
241         printk("freeing region;  %p:%p %d:%02x (%04x:%04x) %08lx %08lx %d\n",
242                r, r->next,
243                r->dev->bus->number, PCI_SLOT(r->dev->devfn),
244                r->dev->vendor, r->dev->device,
245                r->base,
246                r->size,
247                r->type);
248#endif
249      sfree(r);
250      return;
251   }
252   }
253
254   if ((r->type==PCI_BASE_ADDRESS_SPACE_IO)
255       ? (r->size >= 0x10000)
256       : (r->size >= 0x10000000)) {
257      r->size  = 0;
258      r->base  = 0;
259   }
260
261   /* Now insert into the list sorting by
262    * 1) decreasing bus number
263    * 2) space: prefetchable memory, non-prefetchable and finally I/O
264    * 3) decreasing size
265    */
266   if (!pci->resources || insert_before(r, pci->resources)) {
267      r->next = pci->resources;
268      pci->resources=r;
269   } else {
270      for (p=pci->resources; p->next; p=p->next) {
271         if (insert_before(r, p->next)) break;
272      }
273      r->next=p->next;
274      p->next=r;
275   }
276}
277
278/* This version only works for bus 0. I don't have any P2P bridges to test
279 * a more sophisticated version which has therefore not been implemented.
280 * Prefetchable memory is not yet handled correctly either.
281 * And several levels of PCI bridges much less even since there must be
282 * allocated together to be able to setup correctly the top bridge.
283 */
284
285static u_long find_range(u_char bus, u_char type,
286                         pci_resource **first,
287                         pci_resource **past, u_int *flags) {
288   pci_resource *p;
289   u_long total=0;
290   u_int fl=0;
291
292   for (p=pci->resources; p; p=p->next)
293   {
294      if ((p->dev->bus->number == bus) &&
295          AREA(p)==type) break;
296   }
297
298   *first = p;
299
300   for (; p; p=p->next)
301   {
302      if ((p->dev->bus->number != bus) ||
303          AREA(p)!=type || p->size == 0) break;
304      total = total+p->size;
305      fl |= 1<<p->type;
306   }
307
308   *past = p;
309   /* This will be used later to tell whether there are any 32 bit
310    * devices in an area which could be mapped higher than 4Gb
311    * on 64 bits architectures
312    */
313   *flags = fl;
314   return total;
315}
316
317static inline void init_free_area(pci_area_head *h, u_long start,
318                                  u_long end, u_int mask, int high) {
319   pci_area *p;
320   p = salloc(sizeof(pci_area));
321   if (!p) return;
322   h->head = p;
323   p->next = NULL;
324   p->start = (start+mask)&~mask;
325   p->end = (end-mask)|mask;
326   p->bus = NULL;
327   h->mask = mask;
328   h->high = high;
329}
330
331static void insert_area(pci_area_head *h, pci_area *p) {
332   pci_area *q = h->head;
333   if (!p) return;
334   if (q && (q->start< p->start)) {
335      for(;q->next && q->next->start<p->start; q = q->next);
336      if ((q->end >= p->start) ||
337          (q->next && p->end>=q->next->start)) {
338         sfree(p);
339         printk("Overlapping pci areas!\n");
340         return;
341      }
342      p->next = q->next;
343      q->next = p;
344   } else { /* Insert at head */
345      if (q && (p->end >= q->start)) {
346         sfree(p);
347         printk("Overlapping pci areas!\n");
348         return;
349      }
350      p->next = q;
351      h->head = p;
352   }
353}
354
355static
356void remove_area(pci_area_head *h, pci_area *p)
357{
358   pci_area *q = h->head;
359
360   if (!p || !q) return;
361   if (q==p)
362   {
363      h->head = q->next;
364      return;
365   }
366   for(;q && q->next!=p; q=q->next);
367   if (q) q->next=p->next;
368}
369
370static pci_area * alloc_area(pci_area_head *h, struct pci_bus *bus,
371                             u_long required, u_long mask, u_int flags) {
372   pci_area *p;
373   pci_area *from, *split, *new;
374
375   required = (required+h->mask) & ~h->mask;
376   for (p=h->head, from=NULL; p; p=p->next)
377   {
378      u_long l1 = ((p->start+required+mask)&~mask)-1;
379      u_long l2 = ((p->start+mask)&~mask)+required-1;
380      /* Allocated areas point to the bus to which they pertain */
381      if (p->bus) continue;
382      if ((p->end)>=l1 || (p->end)>=l2) from=p;
383      if (from && !h->high) break;
384   }
385   if (!from) return NULL;
386
387   split = salloc(sizeof(pci_area));
388   new = salloc(sizeof(pci_area));
389   /* If allocation of new succeeds then allocation of split has
390    * also been successful (given the current mm algorithms) !
391    */
392   if (!new) {
393      sfree(split);
394      return NULL;
395   }
396   new->bus = bus;
397   new->flags = flags;
398   /* Now allocate pci_space taking alignment into account ! */
399   if (h->high)
400   {
401      u_long l1 = ((from->end+1)&~mask)-required;
402      u_long l2 = (from->end+1-required)&~mask;
403      new->start = (l1>l2) ? l1 : l2;
404      split->end = from->end;
405      from->end = new->start-1;
406      split->start = new->start+required;
407      new->end = new->start+required-1;
408   }
409   else
410   {
411      u_long l1 = ((from->start+mask)&~mask)+required-1;
412      u_long l2 = ((from->start+required+mask)&~mask)-1;
413      new->end = (l1<l2) ? l1 : l2;
414      split->start = from->start;
415      from->start = new->end+1;
416      new->start = new->end+1-required;
417      split->end = new->start-1;
418   }
419
420   if (from->end+1 == from->start) remove_area(h, from);
421   if (split->end+1 != split->start)
422   {
423      split->bus = NULL;
424      insert_area(h, split);
425   }
426   else
427   {
428      sfree(split);
429   }
430   insert_area(h, new);
431   print_pci_areas("alloc_area called:\n");
432   return new;
433}
434
435static inline
436void alloc_space(pci_area *p, pci_resource *r)
437{
438   if (p->start & (r->size-1)) {
439      r->base = p->end+1-r->size;
440      p->end -= r->size;
441   } else {
442      r->base = p->start;
443      p->start += r->size;
444   }
445}
446
447static void reconfigure_bus_space(u_char bus, u_char type, pci_area_head *h)
448{
449   pci_resource *first, *past, *r;
450   pci_area *area, tmp;
451   u_int flags;
452   u_int required = find_range(bus, type, &first, &past, &flags);
453
454   if (required==0) return;
455
456   area = alloc_area(h, first->dev->bus, required, first->size-1, flags);
457
458   if (!area) return;
459
460   tmp = *area;
461   for (r=first; r!=past; r=r->next)
462   {
463      alloc_space(&tmp, r);
464   }
465}
466
467#define BUS0_IO_START           0x10000
468#define BUS0_IO_END             0x1ffff
469#define BUS0_MEM_START          0x1000000
470#define BUS0_MEM_END            0x3f00000
471
472#define BUSREST_IO_START        0x20000
473#define BUSREST_IO_END          0x7ffff
474#define BUSREST_MEM_START       0x4000000
475#define BUSREST_MEM_END        0x10000000
476
477static void reconfigure_pci(void) {
478   pci_resource *r;
479   struct pci_dev *dev;
480
481   /* FIXME: for now memory is relocated from low, it's better
482    * to start from higher addresses.
483    */
484   /*
485   init_free_area(&pci->io, 0x10000, 0x7fffff, 0xfff, 0);
486   init_free_area(&pci->mem, 0x1000000, 0x3cffffff, 0xfffff, 0);
487   */
488
489   init_free_area(&pci->io, BUS0_IO_START, BUS0_IO_END, 0xfff, 0);
490   init_free_area(&pci->mem, BUS0_MEM_START, BUS0_MEM_END, 0xfffff, 0);
491
492   /* First reconfigure the I/O space, this will be more
493    * complex when there is more than 1 bus. And 64 bits
494    * devices are another kind of problems.
495    */
496   reconfigure_bus_space(0, PCI_AREA_IO, &pci->io);
497   reconfigure_bus_space(0, PCI_AREA_MEMORY, &pci->mem);
498   reconfigure_bus_space(0, PCI_AREA_PREFETCHABLE, &pci->mem);
499
500   /* Now we have to touch the configuration space of all
501    * the devices to remap them better than they are right now.
502    * This is done in 3 steps:
503    * 1) first disable I/O and memory response of all devices
504    * 2) modify the base registers
505    * 3) restore the original PCI_COMMAND register.
506    */
507   for (r=pci->resources; r; r= r->next) {
508      if (!r->dev->sysdata) {
509         r->dev->sysdata=r;
510         pci_read_config_word(r->dev, PCI_COMMAND, &r->cmd);
511         pci_write_config_word(r->dev, PCI_COMMAND,
512                               r->cmd & ~(PCI_COMMAND_IO|
513                                          PCI_COMMAND_MEMORY));
514      }
515   }
516
517   for (r=pci->resources; r; r= r->next) {
518      pci_write_config_dword(r->dev,
519                             PCI_BASE_ADDRESS_0+(r->reg<<2),
520                             r->base);
521      if ((r->type&
522           (PCI_BASE_ADDRESS_SPACE|
523            PCI_BASE_ADDRESS_MEM_TYPE_MASK)) ==
524          (PCI_BASE_ADDRESS_SPACE_MEMORY|
525           PCI_BASE_ADDRESS_MEM_TYPE_64)) {
526         pci_write_config_dword(r->dev,
527                                PCI_BASE_ADDRESS_1+(r->reg<<2),
528                                0);
529      }
530   }
531   for (dev=bd->pci_devices; dev; dev= dev->next) {
532      if (dev->sysdata) {
533         pci_write_config_word(dev, PCI_COMMAND,
534                               ((pci_resource *)dev->sysdata)
535                               ->cmd);
536         dev->sysdata=NULL;
537      }
538   }
539}
540
541static int
542indirect_pci_read_config_byte(unsigned char bus, unsigned char dev_fn,
543                              unsigned char offset, unsigned char *val) {
544   out_be32(pci->config_addr,
545            0x80|(bus<<8)|(dev_fn<<16)|((offset&~3)<<24));
546   *val=in_8(pci->config_data + (offset&3));
547   return PCIBIOS_SUCCESSFUL;
548}
549
550static int
551indirect_pci_read_config_word(unsigned char bus, unsigned char dev_fn,
552                              unsigned char offset, unsigned short *val) {
553   *val = 0xffff;
554   if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER;
555   out_be32(pci->config_addr,
556            0x80|(bus<<8)|(dev_fn<<16)|((offset&~3)<<24));
557   *val=in_le16((volatile u_short *)(pci->config_data + (offset&3)));
558   return PCIBIOS_SUCCESSFUL;
559}
560
561static int
562indirect_pci_read_config_dword(unsigned char bus, unsigned char dev_fn,
563                               unsigned char offset, unsigned int *val) {
564   *val = 0xffffffff;
565   if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER;
566   out_be32(pci->config_addr,
567            0x80|(bus<<8)|(dev_fn<<16)|(offset<<24));
568   *val=in_le32((volatile u_int *)pci->config_data);
569   return PCIBIOS_SUCCESSFUL;
570}
571
572static int
573indirect_pci_write_config_byte(unsigned char bus, unsigned char dev_fn,
574                               unsigned char offset, unsigned char val) {
575   out_be32(pci->config_addr,
576            0x80|(bus<<8)|(dev_fn<<16)|((offset&~3)<<24));
577   out_8(pci->config_data + (offset&3), val);
578   return PCIBIOS_SUCCESSFUL;
579}
580
581static int
582indirect_pci_write_config_word(unsigned char bus, unsigned char dev_fn,
583                               unsigned char offset, unsigned short val) {
584   if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER;
585   out_be32(pci->config_addr,
586            0x80|(bus<<8)|(dev_fn<<16)|((offset&~3)<<24));
587   out_le16((volatile u_short *)(pci->config_data + (offset&3)), val);
588   return PCIBIOS_SUCCESSFUL;
589}
590
591static int
592indirect_pci_write_config_dword(unsigned char bus, unsigned char dev_fn,
593                                unsigned char offset, unsigned int val) {
594   if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER;
595   out_be32(pci->config_addr,
596            0x80|(bus<<8)|(dev_fn<<16)|(offset<<24));
597   out_le32((volatile u_int *)pci->config_data, val);
598   return PCIBIOS_SUCCESSFUL;
599}
600
601static const struct pci_config_access_functions indirect_functions = {
602   indirect_pci_read_config_byte,
603   indirect_pci_read_config_word,
604   indirect_pci_read_config_dword,
605   indirect_pci_write_config_byte,
606   indirect_pci_write_config_word,
607   indirect_pci_write_config_dword
608};
609
610static int
611direct_pci_read_config_byte(unsigned char bus, unsigned char dev_fn,
612                            unsigned char offset, unsigned char *val) {
613   if (bus != 0 || (1<<PCI_SLOT(dev_fn) & 0xff8007fe)) {
614      *val=0xff;
615      return PCIBIOS_DEVICE_NOT_FOUND;
616   }
617   *val=in_8(pci->config_data + ((1<<PCI_SLOT(dev_fn))&~1)
618             + (PCI_FUNC(dev_fn)<<8) + offset);
619   return PCIBIOS_SUCCESSFUL;
620}
621
622static int
623direct_pci_read_config_word(unsigned char bus, unsigned char dev_fn,
624                            unsigned char offset, unsigned short *val) {
625   *val = 0xffff;
626   if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER;
627   if (bus != 0 || (1<<PCI_SLOT(dev_fn) & 0xff8007fe)) {
628      return PCIBIOS_DEVICE_NOT_FOUND;
629   }
630   *val=in_le16((volatile u_short *)
631                (pci->config_data + ((1<<PCI_SLOT(dev_fn))&~1)
632                 + (PCI_FUNC(dev_fn)<<8) + offset));
633   return PCIBIOS_SUCCESSFUL;
634}
635
636static int
637direct_pci_read_config_dword(unsigned char bus, unsigned char dev_fn,
638                             unsigned char offset, unsigned int *val) {
639   *val = 0xffffffff;
640   if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER;
641   if (bus != 0 || (1<<PCI_SLOT(dev_fn) & 0xff8007fe)) {
642      return PCIBIOS_DEVICE_NOT_FOUND;
643   }
644   *val=in_le32((volatile u_int *)
645                (pci->config_data + ((1<<PCI_SLOT(dev_fn))&~1)
646                 + (PCI_FUNC(dev_fn)<<8) + offset));
647   return PCIBIOS_SUCCESSFUL;
648}
649
650static int
651direct_pci_write_config_byte(unsigned char bus, unsigned char dev_fn,
652                             unsigned char offset, unsigned char val) {
653   if (bus != 0 || (1<<PCI_SLOT(dev_fn) & 0xff8007fe)) {
654      return PCIBIOS_DEVICE_NOT_FOUND;
655   }
656   out_8(pci->config_data + ((1<<PCI_SLOT(dev_fn))&~1)
657         + (PCI_FUNC(dev_fn)<<8) + offset,
658         val);
659   return PCIBIOS_SUCCESSFUL;
660}
661
662static int
663direct_pci_write_config_word(unsigned char bus, unsigned char dev_fn,
664                             unsigned char offset, unsigned short val) {
665   if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER;
666   if (bus != 0 || (1<<PCI_SLOT(dev_fn) & 0xff8007fe)) {
667      return PCIBIOS_DEVICE_NOT_FOUND;
668   }
669   out_le16((volatile u_short *)
670            (pci->config_data + ((1<<PCI_SLOT(dev_fn))&~1)
671             + (PCI_FUNC(dev_fn)<<8) + offset),
672            val);
673   return PCIBIOS_SUCCESSFUL;
674}
675
676static int
677direct_pci_write_config_dword(unsigned char bus, unsigned char dev_fn,
678                              unsigned char offset, unsigned int val) {
679   if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER;
680   if (bus != 0 || (1<<PCI_SLOT(dev_fn) & 0xff8007fe)) {
681      return PCIBIOS_DEVICE_NOT_FOUND;
682   }
683   out_le32((volatile u_int *)
684            (pci->config_data + ((1<<PCI_SLOT(dev_fn))&~1)
685             + (PCI_FUNC(dev_fn)<<8) + offset),
686            val);
687   return PCIBIOS_SUCCESSFUL;
688}
689
690static const struct pci_config_access_functions direct_functions = {
691   direct_pci_read_config_byte,
692   direct_pci_read_config_word,
693   direct_pci_read_config_dword,
694   direct_pci_write_config_byte,
695   direct_pci_write_config_word,
696   direct_pci_write_config_dword
697};
698
699void pci_read_bases(struct pci_dev *dev, unsigned int howmany)
700{
701   unsigned int reg, nextreg;
702
703#define REG (PCI_BASE_ADDRESS_0 + (reg<<2))
704
705   u_short cmd;
706   u32 l, ml;
707   pci_read_config_word(dev, PCI_COMMAND, &cmd);
708
709   for(reg=0; reg<howmany; reg=nextreg)
710   {
711      pci_resource *r;
712
713      nextreg=reg+1;
714      pci_read_config_dword(dev, REG, &l);
715#if 0
716      if (l == 0xffffffff /*AJF || !l*/) continue;
717#endif
718      /* Note that disabling the memory response of a host bridge
719       * would lose data if a DMA transfer were in progress. In a
720       * bootloader we don't care however. Also we can't print any
721       * message for a while since we might just disable the console.
722       */
723      pci_write_config_word(dev, PCI_COMMAND, cmd &
724                            ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY));
725      pci_write_config_dword(dev, REG, ~0);
726      pci_read_config_dword(dev, REG, &ml);
727      pci_write_config_dword(dev, REG, l);
728
729      /* Reenable the device now that we've played with
730       * base registers.
731       */
732      pci_write_config_word(dev, PCI_COMMAND, cmd);
733
734      /* seems to be an unused entry skip it */
735      if ( ml == 0 || ml == 0xffffffff ) continue;
736
737      if ((l &
738           (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK))
739          == (PCI_BASE_ADDRESS_MEM_TYPE_64
740              |PCI_BASE_ADDRESS_SPACE_MEMORY)) {
741         nextreg=reg+2;
742      }
743      dev->base_address[reg] = l;
744      r = salloc(sizeof(pci_resource));
745      if (!r) {
746         printk("Error allocating pci_resource struct.\n");
747         continue;
748      }
749      r->dev = dev;
750      r->reg = reg;
751      if ((l&PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) {
752         r->type = l&~PCI_BASE_ADDRESS_IO_MASK;
753         r->base = l&PCI_BASE_ADDRESS_IO_MASK;
754         /* r->size = ~(ml&PCI_BASE_ADDRESS_IO_MASK)+1; */
755      } else {
756         r->type = l&~PCI_BASE_ADDRESS_MEM_MASK;
757         r->base = l&PCI_BASE_ADDRESS_MEM_MASK;
758         /* r->size = ~(ml&PCI_BASE_ADDRESS_MEM_MASK)+1; */
759      }
760
761      /* find the first bit set to one after the base
762         address type bits to find length of region */
763      {
764         unsigned int c= 16 , val= 0;
765         while( !(val= ml & c) ) c <<= 1;
766         r->size = val;
767      }
768
769#ifdef PCI_DEBUG
770      printk("   readbase bus %d, (%04x:%04x), base %08x, size %08x, type %d\n",
771             r->dev->bus->number,
772             r->dev->vendor,
773             r->dev->device,
774             r->base,
775             r->size,
776             r->type );
777#endif
778
779      /* Check for the blacklisted entries */
780      insert_resource(r);
781   }
782}
783
784u_int pci_scan_bus(struct pci_bus *bus)
785{
786   unsigned int devfn, l, max, class;
787   unsigned char irq, hdr_type, is_multi = 0;
788   struct pci_dev *dev, **bus_last;
789   struct pci_bus *child;
790
791#if 0
792   printk("scanning pci bus %d\n", bus->number );
793#endif
794
795   bus_last = &bus->devices;
796   max = bus->secondary;
797   for (devfn = 0; devfn < 0xff; ++devfn) {
798      if (PCI_FUNC(devfn) && !is_multi) {
799         /* not a multi-function device */
800         continue;
801      }
802      if (pcibios_read_config_byte(bus->number, devfn, PCI_HEADER_TYPE, &hdr_type))
803         continue;
804      if (!PCI_FUNC(devfn))
805         is_multi = hdr_type & 0x80;
806
807      if (pcibios_read_config_dword(bus->number, devfn, PCI_VENDOR_ID, &l) ||
808          /* some broken boards return 0 if a slot is empty: */
809          l == 0xffffffff || l == 0x00000000 || l == 0x0000ffff || l == 0xffff0000) {
810         is_multi = 0;
811         continue;
812      }
813
814      dev = salloc(sizeof(*dev));
815      dev->bus = bus;
816      dev->devfn  = devfn;
817      dev->vendor = l & 0xffff;
818      dev->device = (l >> 16) & 0xffff;
819
820      pcibios_read_config_dword(bus->number, devfn,
821                                PCI_CLASS_REVISION, &class);
822      class >>= 8;                                  /* upper 3 bytes */
823      dev->class = class;
824      class >>= 8;
825      dev->hdr_type = hdr_type;
826
827      switch (hdr_type & 0x7f) {                    /* header type */
828         case PCI_HEADER_TYPE_NORMAL:               /* standard header */
829            if (class == PCI_CLASS_BRIDGE_PCI)
830               goto bad;
831            /*
832             * If the card generates interrupts, read IRQ number
833             * (some architectures change it during pcibios_fixup())
834             */
835            pcibios_read_config_byte(bus->number, dev->devfn, PCI_INTERRUPT_PIN, &irq);
836            if (irq)
837               pcibios_read_config_byte(bus->number, dev->devfn, PCI_INTERRUPT_LINE, &irq);
838            dev->irq = irq;
839            /*
840             * read base address registers, again pcibios_fixup() can
841             * tweak these
842             */
843            pci_read_bases(dev, 6);
844            pcibios_read_config_dword(bus->number, devfn, PCI_ROM_ADDRESS, &l);
845            dev->rom_address = (l == 0xffffffff) ? 0 : l;
846            break;
847         case PCI_HEADER_TYPE_BRIDGE:               /* bridge header */
848            if (class != PCI_CLASS_BRIDGE_PCI)
849               goto bad;
850            pci_read_bases(dev, 2);
851            pcibios_read_config_dword(bus->number, devfn, PCI_ROM_ADDRESS1, &l);
852            dev->rom_address = (l == 0xffffffff) ? 0 : l;
853            break;
854         case PCI_HEADER_TYPE_CARDBUS:              /* CardBus bridge header */
855            if (class != PCI_CLASS_BRIDGE_CARDBUS)
856               goto bad;
857            pci_read_bases(dev, 1);
858            break;
859
860         default:                                   /* unknown header */
861        bad:
862            printk("PCI device with unknown header type %d ignored.\n",
863                   hdr_type&0x7f);
864            continue;
865      }
866
867      /*
868       * Put it into the global PCI device chain. It's used to
869       * find devices once everything is set up.
870       */
871      *pci->last_dev_p = dev;
872      pci->last_dev_p = &dev->next;
873
874      /*
875       * Now insert it into the list of devices held
876       * by the parent bus.
877       */
878      *bus_last = dev;
879      bus_last = &dev->sibling;
880
881   }
882
883   /*
884    * After performing arch-dependent fixup of the bus, look behind
885    * all PCI-to-PCI bridges on this bus.
886    */
887   for(dev=bus->devices; dev; dev=dev->sibling)
888      /*
889       * If it's a bridge, scan the bus behind it.
890       */
891      if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
892         unsigned int buses;
893         unsigned int devfn = dev->devfn;
894         unsigned short cr;
895
896         /*
897          * Insert it into the tree of buses.
898          */
899         child = salloc(sizeof(*child));
900         child->next = bus->children;
901         bus->children = child;
902         child->self = dev;
903         child->parent = bus;
904
905         /*
906          * Set up the primary, secondary and subordinate
907          * bus numbers.
908          */
909         child->number = child->secondary = ++max;
910         child->primary = bus->secondary;
911         child->subordinate = 0xff;
912         /*
913          * Clear all status bits and turn off memory,
914          * I/O and master enables.
915          */
916         pcibios_read_config_word(bus->number, devfn, PCI_COMMAND, &cr);
917         pcibios_write_config_word(bus->number, devfn, PCI_COMMAND, 0x0000);
918         pcibios_write_config_word(bus->number, devfn, PCI_STATUS, 0xffff);
919         /*
920          * Read the existing primary/secondary/subordinate bus
921          * number configuration to determine if the PCI bridge
922          * has already been configured by the system.  If so,
923          * do not modify the configuration, merely note it.
924          */
925         pcibios_read_config_dword(bus->number, devfn, PCI_PRIMARY_BUS, &buses);
926         if ((buses & 0xFFFFFF) != 0)
927         {
928            unsigned int cmax;
929
930            child->primary = buses & 0xFF;
931            child->secondary = (buses >> 8) & 0xFF;
932            child->subordinate = (buses >> 16) & 0xFF;
933            child->number = child->secondary;
934            cmax = pci_scan_bus(child);
935            if (cmax > max) max = cmax;
936         }
937         else
938         {
939            /*
940             * Configure the bus numbers for this bridge:
941             */
942            buses &= 0xff000000;
943            buses |=
944               (((unsigned int)(child->primary)     <<  0) |
945                ((unsigned int)(child->secondary)   <<  8) |
946                ((unsigned int)(child->subordinate) << 16));
947            pcibios_write_config_dword(bus->number, devfn, PCI_PRIMARY_BUS, buses);
948            /*
949             * Now we can scan all subordinate buses:
950             */
951            max = pci_scan_bus(child);
952            /*
953             * Set the subordinate bus number to its real
954             * value:
955             */
956            child->subordinate = max;
957            buses = (buses & 0xff00ffff)
958               | ((unsigned int)(child->subordinate) << 16);
959            pcibios_write_config_dword(bus->number, devfn, PCI_PRIMARY_BUS, buses);
960         }
961         pcibios_write_config_word(bus->number, devfn, PCI_COMMAND, cr );
962      }
963
964   /*
965    * We've scanned the bus and so we know all about what's on
966    * the other side of any bridges that may be on this bus plus
967    * any devices.
968    *
969    * Return how far we've got finding sub-buses.
970    */
971   return max;
972}
973
974#if 0
975
976void
977pci_fixup(void)
978{
979   struct pci_dev *p;
980   struct pci_bus *bus;
981
982   for (bus = &pci_root; bus; bus=bus->next)
983   {
984      for (p=bus->devices; p; p=p->sibling)
985      {
986      }
987   }
988}
989
990static void print_pci_info()
991{
992   pci_resource *r;
993   struct pci_bus *pb = &pci_root;
994
995   printk("\n");
996   printk("PCI busses:\n");
997
998   for(pb= &pci_root; pb; pb=pb->children )
999   {
1000      printk("   number %d, primary %d, secondary %d, subordinate %d\n",
1001             pb->number,
1002             pb->primary,
1003             pb->secondary,
1004             pb->subordinate );
1005      printk("   bridge; vendor %04x, device %04x\n",
1006             pb->self->vendor,
1007             pb->self->device );
1008
1009      {
1010         struct pci_dev *pd;
1011
1012         for(pd= pb->devices; pd; pd=pd->sibling )
1013         {
1014            printk("       vendor %04x, device %04x, irq %d\n",
1015                   pd->vendor,
1016                   pd->device,
1017                   pd->irq );
1018
1019         }
1020         printk("\n");
1021      }
1022
1023   }
1024   printk("\n");
1025
1026   printk("PCI resources:\n");
1027   for (r=pci->resources; r; r= r->next)
1028   {
1029      printk("   bus %d, vendor %04x, device %04x, base %08x, size %08x, type %d\n",
1030             r->dev->bus->number,
1031             r->dev->vendor,
1032             r->dev->device,
1033             r->base,
1034             r->size,
1035             r->type );
1036   }
1037   printk("\n");
1038
1039   return;
1040}
1041
1042#endif
1043
1044static struct _addr_start
1045{
1046      uint32_t   start_pcimem;
1047      uint32_t   start_pciio;
1048      uint32_t   start_prefetch;
1049} astart;
1050
1051static pci_resource *enum_device_resources( struct pci_dev *pdev, int i )
1052{
1053   pci_resource *r;
1054
1055   for(r= pci->resources; r; r= r->next )
1056   {
1057      if( r->dev == pdev )
1058      {
1059         if( i-- == 0 ) break;
1060      }
1061   }
1062   return r;
1063}
1064
1065static void recursive_bus_reconfigure( struct pci_bus *pbus )
1066{
1067   struct pci_dev       *pdev;
1068   struct pci_bus       *childbus;
1069   int  isroot = 0;
1070
1071   if( !pbus )
1072   {
1073      /* start with the root bus */
1074      astart.start_pcimem   = BUSREST_MEM_START;
1075      astart.start_pciio    = BUSREST_IO_START;
1076      astart.start_prefetch = ((BUSREST_MEM_END >> 16) << 16);
1077
1078      pbus = &pci_root;
1079      isroot = -1;
1080   }
1081
1082#define WRITE_BRIDGE_IO
1083#define WRITE_BRIDGE_MEM
1084#define WRITE_BRIDGE_PF
1085#define WRITE_BRIDGE_ENABLE
1086
1087/*
1088** Run thru the p2p bridges on this bus and recurse into subordinate busses
1089*/
1090   for( childbus= pbus->children; childbus; childbus= childbus->next )
1091   {
1092      pdev= childbus->self;
1093
1094      pcibios_write_config_byte(pdev->bus->number, pdev->devfn, PCI_LATENCY_TIMER,     0x80 );
1095      pcibios_write_config_byte(pdev->bus->number, pdev->devfn, PCI_SEC_LATENCY_TIMER, 0x80 );
1096
1097      {
1098         struct _addr_start   addrhold;
1099         uint8_t              base8, limit8;
1100         uint16_t             base16, limit16, ubase16, ulimit16;
1101
1102         /* save the base address values */
1103         memcpy( &addrhold, &astart, sizeof(struct _addr_start));
1104
1105         recursive_bus_reconfigure( childbus );
1106
1107#ifdef PCI_DEBUG
1108         printk("pci: configuring bus %d bridge (%04x:%04x), bus %d : (%d-%d)\n",
1109                pdev->bus->number,
1110                pdev->vendor,
1111                pdev->device,
1112                childbus->primary,
1113                childbus->secondary,
1114                childbus->subordinate );
1115#endif
1116
1117         /*
1118          * use the current values & the saved ones to figure out
1119          * the address spaces for the bridge
1120          */
1121
1122         if( addrhold.start_pciio == astart.start_pciio )
1123         {
1124            base8 = limit8 = 0xff;
1125            ubase16 = ulimit16 = 0xffff;
1126         }
1127         else
1128         {
1129            base8    = (uint8_t) ((addrhold.start_pciio >> 8) & 0xf0);
1130            ubase16  = (uint16_t)(addrhold.start_pciio >> 16);
1131            limit8   = (uint8_t) ((astart.start_pciio >> 8 ) & 0xf0);
1132            ulimit16 = (uint16_t)(astart.start_pciio >> 16);
1133            astart.start_pciio += 0x1000;
1134         }
1135
1136#ifdef PCI_DEBUG
1137         printk("pci:     io base %08x limit %08x\n", (base8<<8)+(ubase16<<16), (limit8<<8)+(ulimit16<<16));
1138#endif
1139#ifdef WRITE_BRIDGE_IO
1140         pcibios_write_config_word(pdev->bus->number, pdev->devfn, PCI_IO_BASE_UPPER16, ubase16 );
1141         pcibios_write_config_byte(pdev->bus->number, pdev->devfn, PCI_IO_BASE, base8 );
1142
1143         pcibios_write_config_word(pdev->bus->number, pdev->devfn, PCI_IO_LIMIT_UPPER16, ulimit16 );
1144         pcibios_write_config_byte(pdev->bus->number, pdev->devfn, PCI_IO_LIMIT, limit8 );
1145#endif
1146
1147         if( addrhold.start_pcimem == astart.start_pcimem )
1148         {
1149            limit16 = 0;
1150            base16 = 0xffff;
1151         }
1152         else
1153         {
1154            limit16= (uint16_t)((astart.start_pcimem >> 16) & 0xfff0);
1155            base16 = (uint16_t)((addrhold.start_pcimem >> 16) & 0xfff0);
1156            astart.start_pcimem += 0x100000;
1157         }
1158#ifdef PCI_DEBUG
1159         printk("pci:      memory %04x, limit %04x\n", base16, limit16);
1160#endif
1161#ifdef WRITE_BRIDGE_MEM
1162         pcibios_write_config_word(pdev->bus->number, pdev->devfn, PCI_MEMORY_BASE, base16 );
1163         pcibios_write_config_word(pdev->bus->number, pdev->devfn, PCI_MEMORY_LIMIT, limit16 );
1164#endif
1165
1166
1167         if( astart.start_prefetch == addrhold.start_prefetch )
1168         {
1169            limit16 = 0;
1170            base16 = 0xffff;
1171         }
1172         else
1173         {
1174            limit16= (uint16_t)((addrhold.start_prefetch >> 16) & 0xfff0);
1175            base16 = (uint16_t)((astart.start_prefetch >> 16) & 0xfff0);
1176            astart.start_prefetch -= 0x100000;
1177         }
1178#ifdef PCI_DEBUG
1179         printk("pci:   pf memory %04x, limit %04x\n", base16, limit16);
1180#endif
1181#ifdef WRITE_BRIDGE_PF
1182         pcibios_write_config_dword(pdev->bus->number, pdev->devfn, PCI_PREF_BASE_UPPER32, 0);
1183         pcibios_write_config_word(pdev->bus->number, pdev->devfn, PCI_PREF_MEMORY_BASE, base16 );
1184         pcibios_write_config_dword(pdev->bus->number, pdev->devfn, PCI_PREF_LIMIT_UPPER32, 0);
1185         pcibios_write_config_word(pdev->bus->number, pdev->devfn, PCI_PREF_MEMORY_LIMIT, limit16 );
1186#endif
1187
1188#ifdef WRITE_BRIDGE_ENABLE
1189         pcibios_write_config_word(pdev->bus->number,
1190                                   pdev->devfn,
1191                                   PCI_BRIDGE_CONTROL,
1192                                   (unsigned16)( 0 ));
1193
1194         pcibios_write_config_word(pdev->bus->number,
1195                                   pdev->devfn,
1196                                   PCI_COMMAND,
1197                                   (unsigned16)( PCI_COMMAND_IO |
1198                                                 PCI_COMMAND_MEMORY |
1199                                                 PCI_COMMAND_MASTER ));
1200#endif
1201      }
1202   }
1203
1204   if( !isroot )
1205   {
1206#ifdef PCI_DEBUG
1207      printk("pci: Configuring devices on bus %d\n", pbus->number);
1208#endif
1209      /*
1210      ** Run thru this bus and set up addresses for all the non-bridge devices
1211      */
1212      for( pdev = pbus->devices; pdev; pdev= pdev->sibling )
1213      {
1214         if( (pdev->class >> 8) != PCI_CLASS_BRIDGE_PCI )
1215         {
1216            pci_resource *r;
1217            int i = 0;
1218            unsigned alloc;
1219
1220            /* enumerate all the resources defined by this device & reserve space
1221            ** for each of their defined regions.
1222            */
1223
1224#ifdef PCI_DEBUG
1225            printk("pci: configuring; vendor %04x, device %04x\n", pdev->vendor, pdev->device );
1226#endif
1227
1228            while( (r= enum_device_resources( pdev, i++ )) )
1229            {
1230               /*
1231               ** Force all memory spaces to be non-prefetchable because
1232               ** on the pci bus, byte-wise reads against prefetchable
1233               ** memory are applied as 32 bit reads, which is a pain
1234               ** when you're trying to talk to hardware.  This is a
1235               ** little sub-optimal because the algorithm doesn't sort
1236               ** the address regions to pack them in, OTOH, perhaps its
1237               ** not so bad because the inefficient packing will help
1238               ** avoid buffer overflow/underflow problems.
1239               */
1240#if 0
1241               if( (r->type & PCI_BASE_ADDRESS_MEM_PREFETCH) )
1242               {
1243                  /* prefetchable space */
1244
1245                  /* shift base pointer down to an integer multiple of the size of the desired region */
1246                  astart.start_prefetch -= (alloc= ((r->size / PAGE_SIZE) + 1) * PAGE_SIZE);
1247                  /* shift base pointer down to an integer multiple of the size of the desired region */
1248                  astart.start_prefetch = (astart.start_prefetch / r->size) * r->size;
1249
1250                  r->base = astart.start_prefetch;
1251#ifdef PCI_DEBUG
1252                  printk("pci:       pf %08X, size %08X, alloc %08X\n", r->base, r->size, alloc );
1253#endif
1254               }
1255#endif
1256               if( r->type & PCI_BASE_ADDRESS_SPACE_IO )
1257               {
1258                  /* io space */
1259
1260                  /* shift base pointer up to an integer multiple of the size of the desired region */
1261                  if( astart.start_pciio % r->size )
1262                     astart.start_pciio = (((astart.start_pciio / r->size) + 1) * r->size);
1263
1264                  r->base = astart.start_pciio;
1265                  astart.start_pciio += (alloc= ((r->size / PAGE_SIZE) + 1) * PAGE_SIZE);
1266#ifdef PCI_DEBUG
1267                  printk("pci:      io  %08X, size %08X, alloc %08X\n", r->base, r->size, alloc );
1268#endif
1269               }
1270               else
1271               {
1272                  /* memory space */
1273
1274                  /* shift base pointer up to an integer multiple of the size of the desired region */
1275                  if( astart.start_pcimem % r->size )
1276                     astart.start_pcimem = (((astart.start_pcimem / r->size) + 1) * r->size);
1277
1278                  r->base = astart.start_pcimem;
1279                  astart.start_pcimem += (alloc= ((r->size / PAGE_SIZE) + 1) * PAGE_SIZE);
1280#ifdef PCI_DEBUG
1281                  printk("pci:      mem %08X, size %08X, alloc %08X\n", r->base, r->size, alloc );
1282#endif
1283               }
1284            }
1285
1286         }
1287      }
1288   }
1289
1290}
1291
1292void pci_init(void)
1293{
1294   PPC_DEVICE *hostbridge;
1295
1296   if (pci->last_dev_p) {
1297      printk("Two or more calls to pci_init!\n");
1298      return;
1299   }
1300   pci->last_dev_p = &(bd->pci_devices);
1301   hostbridge=residual_find_device(PROCESSORDEVICE, NULL,
1302                                   BridgeController,
1303                                   PCIBridge, -1, 0);
1304   if (hostbridge) {
1305      if (hostbridge->DeviceId.Interface==PCIBridgeIndirect) {
1306         bd->pci_functions=&indirect_functions;
1307         /* Should be extracted from residual data,
1308          * indeed MPC106 in CHRP mode is different,
1309          * but we should not use residual data in
1310          * this case anyway.
1311          */
1312         pci->config_addr = ((volatile u_int *)
1313                             (ptr_mem_map->io_base+0xcf8));
1314         pci->config_data = ptr_mem_map->io_base+0xcfc;
1315      } else if(hostbridge->DeviceId.Interface==PCIBridgeDirect) {
1316         bd->pci_functions=&direct_functions;
1317         pci->config_data=(u_char *) 0x80800000;
1318      } else {
1319      }
1320   } else {
1321      /* Let us try by experimentation at our own risk! */
1322      u_int id0;
1323      bd->pci_functions = &direct_functions;
1324      /* On all direct bridges I know the host bridge itself
1325       * appears as device 0 function 0.
1326       */
1327      pcibios_read_config_dword(0, 0, PCI_VENDOR_ID, &id0);
1328      if (id0==~0U) {
1329         bd->pci_functions = &indirect_functions;
1330         pci->config_addr = ((volatile u_int *)
1331                             (ptr_mem_map->io_base+0xcf8));
1332         pci->config_data = ptr_mem_map->io_base+0xcfc;
1333      }
1334      /* Here we should check that the host bridge is actually
1335       * present, but if it not, we are in such a desperate
1336       * situation, that we probably can't even tell it.
1337       */
1338   }
1339   /* Now build a small database of all found PCI devices */
1340   printk("\nPCI: Probing PCI hardware\n");
1341   pci_root.subordinate=pci_scan_bus(&pci_root);
1342
1343   print_pci_resources("Installed PCI resources:\n");
1344
1345   recursive_bus_reconfigure(NULL);
1346
1347   reconfigure_pci();
1348
1349   print_pci_resources("Allocated PCI resources:\n");
1350
1351#if 0
1352   print_pci_info();
1353#endif
1354}
1355
1356/* eof */
Note: See TracBrowser for help on using the repository browser.