source: rtems/bsps/powerpc/motorola_powerpc/bootloader/pci.c

Last change on this file was fdd3b85, checked in by Sebastian Huber <sebastian.huber@…>, on 11/09/18 at 09:46:50

bsp/motorola_powerpc: Include <sys/param.h>

Update #3598.

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