pci.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*
  2. * Common prep/chrp pci routines. -- Cort
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/pci.h>
  6. #include <linux/delay.h>
  7. #include <linux/string.h>
  8. #include <linux/init.h>
  9. #include <linux/capability.h>
  10. #include <linux/sched.h>
  11. #include <linux/errno.h>
  12. #include <linux/bootmem.h>
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. #include <asm/prom.h>
  16. #include <asm/sections.h>
  17. #include <asm/pci-bridge.h>
  18. #include <asm/byteorder.h>
  19. #include <asm/irq.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/machdep.h>
  22. #undef DEBUG
  23. #ifdef DEBUG
  24. #define DBG(x...) printk(x)
  25. #else
  26. #define DBG(x...)
  27. #endif
  28. unsigned long isa_io_base = 0;
  29. unsigned long isa_mem_base = 0;
  30. unsigned long pci_dram_offset = 0;
  31. int pcibios_assign_bus_offset = 1;
  32. void pcibios_make_OF_bus_map(void);
  33. static int pci_relocate_bridge_resource(struct pci_bus *bus, int i);
  34. static int probe_resource(struct pci_bus *parent, struct resource *pr,
  35. struct resource *res, struct resource **conflict);
  36. static void update_bridge_base(struct pci_bus *bus, int i);
  37. static void pcibios_fixup_resources(struct pci_dev* dev);
  38. static void fixup_broken_pcnet32(struct pci_dev* dev);
  39. static int reparent_resources(struct resource *parent, struct resource *res);
  40. static void fixup_cpc710_pci64(struct pci_dev* dev);
  41. /* By default, we don't re-assign bus numbers.
  42. */
  43. int pci_assign_all_buses;
  44. struct pci_controller* hose_head;
  45. struct pci_controller** hose_tail = &hose_head;
  46. static int pci_bus_count;
  47. static void
  48. fixup_broken_pcnet32(struct pci_dev* dev)
  49. {
  50. if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
  51. dev->vendor = PCI_VENDOR_ID_AMD;
  52. pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
  53. }
  54. }
  55. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32);
  56. static void
  57. fixup_cpc710_pci64(struct pci_dev* dev)
  58. {
  59. /* Hide the PCI64 BARs from the kernel as their content doesn't
  60. * fit well in the resource management
  61. */
  62. dev->resource[0].start = dev->resource[0].end = 0;
  63. dev->resource[0].flags = 0;
  64. dev->resource[1].start = dev->resource[1].end = 0;
  65. dev->resource[1].flags = 0;
  66. }
  67. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64);
  68. static void
  69. pcibios_fixup_resources(struct pci_dev *dev)
  70. {
  71. struct pci_controller* hose = (struct pci_controller *)dev->sysdata;
  72. int i;
  73. unsigned long offset;
  74. if (!hose) {
  75. printk(KERN_ERR "No hose for PCI dev %s!\n", pci_name(dev));
  76. return;
  77. }
  78. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  79. struct resource *res = dev->resource + i;
  80. if (!res->flags)
  81. continue;
  82. if (res->end == 0xffffffff) {
  83. DBG("PCI:%s Resource %d [%016llx-%016llx] is unassigned\n",
  84. pci_name(dev), i,
  85. (unsigned long long)res->start,
  86. (unsigned long long)res->end);
  87. res->end -= res->start;
  88. res->start = 0;
  89. res->flags |= IORESOURCE_UNSET;
  90. continue;
  91. }
  92. offset = 0;
  93. if (res->flags & IORESOURCE_MEM) {
  94. offset = hose->pci_mem_offset;
  95. } else if (res->flags & IORESOURCE_IO) {
  96. offset = (unsigned long) hose->io_base_virt
  97. - isa_io_base;
  98. }
  99. if (offset != 0) {
  100. res->start += offset;
  101. res->end += offset;
  102. #ifdef DEBUG
  103. printk("Fixup res %d (%lx) of dev %s: %lx -> %lx\n",
  104. i, res->flags, pci_name(dev),
  105. res->start - offset, res->start);
  106. #endif
  107. }
  108. }
  109. /* Call machine specific resource fixup */
  110. if (ppc_md.pcibios_fixup_resources)
  111. ppc_md.pcibios_fixup_resources(dev);
  112. }
  113. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources);
  114. void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  115. struct resource *res)
  116. {
  117. unsigned long offset = 0;
  118. struct pci_controller *hose = dev->sysdata;
  119. if (hose && res->flags & IORESOURCE_IO)
  120. offset = (unsigned long)hose->io_base_virt - isa_io_base;
  121. else if (hose && res->flags & IORESOURCE_MEM)
  122. offset = hose->pci_mem_offset;
  123. region->start = res->start - offset;
  124. region->end = res->end - offset;
  125. }
  126. EXPORT_SYMBOL(pcibios_resource_to_bus);
  127. void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  128. struct pci_bus_region *region)
  129. {
  130. unsigned long offset = 0;
  131. struct pci_controller *hose = dev->sysdata;
  132. if (hose && res->flags & IORESOURCE_IO)
  133. offset = (unsigned long)hose->io_base_virt - isa_io_base;
  134. else if (hose && res->flags & IORESOURCE_MEM)
  135. offset = hose->pci_mem_offset;
  136. res->start = region->start + offset;
  137. res->end = region->end + offset;
  138. }
  139. EXPORT_SYMBOL(pcibios_bus_to_resource);
  140. /*
  141. * We need to avoid collisions with `mirrored' VGA ports
  142. * and other strange ISA hardware, so we always want the
  143. * addresses to be allocated in the 0x000-0x0ff region
  144. * modulo 0x400.
  145. *
  146. * Why? Because some silly external IO cards only decode
  147. * the low 10 bits of the IO address. The 0x00-0xff region
  148. * is reserved for motherboard devices that decode all 16
  149. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  150. * but we want to try to avoid allocating at 0x2900-0x2bff
  151. * which might have be mirrored at 0x0100-0x03ff..
  152. */
  153. void pcibios_align_resource(void *data, struct resource *res,
  154. resource_size_t size, resource_size_t align)
  155. {
  156. struct pci_dev *dev = data;
  157. if (res->flags & IORESOURCE_IO) {
  158. resource_size_t start = res->start;
  159. if (size > 0x100) {
  160. printk(KERN_ERR "PCI: I/O Region %s/%d too large"
  161. " (%lld bytes)\n", pci_name(dev),
  162. dev->resource - res, (unsigned long long)size);
  163. }
  164. if (start & 0x300) {
  165. start = (start + 0x3ff) & ~0x3ff;
  166. res->start = start;
  167. }
  168. }
  169. }
  170. EXPORT_SYMBOL(pcibios_align_resource);
  171. /*
  172. * Handle resources of PCI devices. If the world were perfect, we could
  173. * just allocate all the resource regions and do nothing more. It isn't.
  174. * On the other hand, we cannot just re-allocate all devices, as it would
  175. * require us to know lots of host bridge internals. So we attempt to
  176. * keep as much of the original configuration as possible, but tweak it
  177. * when it's found to be wrong.
  178. *
  179. * Known BIOS problems we have to work around:
  180. * - I/O or memory regions not configured
  181. * - regions configured, but not enabled in the command register
  182. * - bogus I/O addresses above 64K used
  183. * - expansion ROMs left enabled (this may sound harmless, but given
  184. * the fact the PCI specs explicitly allow address decoders to be
  185. * shared between expansion ROMs and other resource regions, it's
  186. * at least dangerous)
  187. *
  188. * Our solution:
  189. * (1) Allocate resources for all buses behind PCI-to-PCI bridges.
  190. * This gives us fixed barriers on where we can allocate.
  191. * (2) Allocate resources for all enabled devices. If there is
  192. * a collision, just mark the resource as unallocated. Also
  193. * disable expansion ROMs during this step.
  194. * (3) Try to allocate resources for disabled devices. If the
  195. * resources were assigned correctly, everything goes well,
  196. * if they weren't, they won't disturb allocation of other
  197. * resources.
  198. * (4) Assign new addresses to resources which were either
  199. * not configured at all or misconfigured. If explicitly
  200. * requested by the user, configure expansion ROM address
  201. * as well.
  202. */
  203. static void __init
  204. pcibios_allocate_bus_resources(struct list_head *bus_list)
  205. {
  206. struct pci_bus *bus;
  207. int i;
  208. struct resource *res, *pr;
  209. /* Depth-First Search on bus tree */
  210. list_for_each_entry(bus, bus_list, node) {
  211. for (i = 0; i < 4; ++i) {
  212. if ((res = bus->resource[i]) == NULL || !res->flags
  213. || res->start > res->end)
  214. continue;
  215. if (bus->parent == NULL)
  216. pr = (res->flags & IORESOURCE_IO)?
  217. &ioport_resource: &iomem_resource;
  218. else {
  219. pr = pci_find_parent_resource(bus->self, res);
  220. if (pr == res) {
  221. /* this happens when the generic PCI
  222. * code (wrongly) decides that this
  223. * bridge is transparent -- paulus
  224. */
  225. continue;
  226. }
  227. }
  228. DBG("PCI: bridge rsrc %llx..%llx (%lx), parent %p\n",
  229. (unsigned long long)res->start,
  230. (unsigned long long)res->end, res->flags, pr);
  231. if (pr) {
  232. if (request_resource(pr, res) == 0)
  233. continue;
  234. /*
  235. * Must be a conflict with an existing entry.
  236. * Move that entry (or entries) under the
  237. * bridge resource and try again.
  238. */
  239. if (reparent_resources(pr, res) == 0)
  240. continue;
  241. }
  242. printk(KERN_ERR "PCI: Cannot allocate resource region "
  243. "%d of PCI bridge %d\n", i, bus->number);
  244. if (pci_relocate_bridge_resource(bus, i))
  245. bus->resource[i] = NULL;
  246. }
  247. pcibios_allocate_bus_resources(&bus->children);
  248. }
  249. }
  250. /*
  251. * Reparent resource children of pr that conflict with res
  252. * under res, and make res replace those children.
  253. */
  254. static int __init
  255. reparent_resources(struct resource *parent, struct resource *res)
  256. {
  257. struct resource *p, **pp;
  258. struct resource **firstpp = NULL;
  259. for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {
  260. if (p->end < res->start)
  261. continue;
  262. if (res->end < p->start)
  263. break;
  264. if (p->start < res->start || p->end > res->end)
  265. return -1; /* not completely contained */
  266. if (firstpp == NULL)
  267. firstpp = pp;
  268. }
  269. if (firstpp == NULL)
  270. return -1; /* didn't find any conflicting entries? */
  271. res->parent = parent;
  272. res->child = *firstpp;
  273. res->sibling = *pp;
  274. *firstpp = res;
  275. *pp = NULL;
  276. for (p = res->child; p != NULL; p = p->sibling) {
  277. p->parent = res;
  278. DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n",
  279. p->name, (unsigned long long)p->start,
  280. (unsigned long long)p->end, res->name);
  281. }
  282. return 0;
  283. }
  284. /*
  285. * A bridge has been allocated a range which is outside the range
  286. * of its parent bridge, so it needs to be moved.
  287. */
  288. static int __init
  289. pci_relocate_bridge_resource(struct pci_bus *bus, int i)
  290. {
  291. struct resource *res, *pr, *conflict;
  292. unsigned long try, size;
  293. int j;
  294. struct pci_bus *parent = bus->parent;
  295. if (parent == NULL) {
  296. /* shouldn't ever happen */
  297. printk(KERN_ERR "PCI: can't move host bridge resource\n");
  298. return -1;
  299. }
  300. res = bus->resource[i];
  301. if (res == NULL)
  302. return -1;
  303. pr = NULL;
  304. for (j = 0; j < 4; j++) {
  305. struct resource *r = parent->resource[j];
  306. if (!r)
  307. continue;
  308. if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
  309. continue;
  310. if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) {
  311. pr = r;
  312. break;
  313. }
  314. if (res->flags & IORESOURCE_PREFETCH)
  315. pr = r;
  316. }
  317. if (pr == NULL)
  318. return -1;
  319. size = res->end - res->start;
  320. if (pr->start > pr->end || size > pr->end - pr->start)
  321. return -1;
  322. try = pr->end;
  323. for (;;) {
  324. res->start = try - size;
  325. res->end = try;
  326. if (probe_resource(bus->parent, pr, res, &conflict) == 0)
  327. break;
  328. if (conflict->start <= pr->start + size)
  329. return -1;
  330. try = conflict->start - 1;
  331. }
  332. if (request_resource(pr, res)) {
  333. DBG(KERN_ERR "PCI: huh? couldn't move to %llx..%llx\n",
  334. (unsigned long long)res->start,
  335. (unsigned long long)res->end);
  336. return -1; /* "can't happen" */
  337. }
  338. update_bridge_base(bus, i);
  339. printk(KERN_INFO "PCI: bridge %d resource %d moved to %llx..%llx\n",
  340. bus->number, i, (unsigned long long)res->start,
  341. (unsigned long long)res->end);
  342. return 0;
  343. }
  344. static int __init
  345. probe_resource(struct pci_bus *parent, struct resource *pr,
  346. struct resource *res, struct resource **conflict)
  347. {
  348. struct pci_bus *bus;
  349. struct pci_dev *dev;
  350. struct resource *r;
  351. int i;
  352. for (r = pr->child; r != NULL; r = r->sibling) {
  353. if (r->end >= res->start && res->end >= r->start) {
  354. *conflict = r;
  355. return 1;
  356. }
  357. }
  358. list_for_each_entry(bus, &parent->children, node) {
  359. for (i = 0; i < 4; ++i) {
  360. if ((r = bus->resource[i]) == NULL)
  361. continue;
  362. if (!r->flags || r->start > r->end || r == res)
  363. continue;
  364. if (pci_find_parent_resource(bus->self, r) != pr)
  365. continue;
  366. if (r->end >= res->start && res->end >= r->start) {
  367. *conflict = r;
  368. return 1;
  369. }
  370. }
  371. }
  372. list_for_each_entry(dev, &parent->devices, bus_list) {
  373. for (i = 0; i < 6; ++i) {
  374. r = &dev->resource[i];
  375. if (!r->flags || (r->flags & IORESOURCE_UNSET))
  376. continue;
  377. if (pci_find_parent_resource(dev, r) != pr)
  378. continue;
  379. if (r->end >= res->start && res->end >= r->start) {
  380. *conflict = r;
  381. return 1;
  382. }
  383. }
  384. }
  385. return 0;
  386. }
  387. static void __init
  388. update_bridge_base(struct pci_bus *bus, int i)
  389. {
  390. struct resource *res = bus->resource[i];
  391. u8 io_base_lo, io_limit_lo;
  392. u16 mem_base, mem_limit;
  393. u16 cmd;
  394. unsigned long start, end, off;
  395. struct pci_dev *dev = bus->self;
  396. struct pci_controller *hose = dev->sysdata;
  397. if (!hose) {
  398. printk("update_bridge_base: no hose?\n");
  399. return;
  400. }
  401. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  402. pci_write_config_word(dev, PCI_COMMAND,
  403. cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
  404. if (res->flags & IORESOURCE_IO) {
  405. off = (unsigned long) hose->io_base_virt - isa_io_base;
  406. start = res->start - off;
  407. end = res->end - off;
  408. io_base_lo = (start >> 8) & PCI_IO_RANGE_MASK;
  409. io_limit_lo = (end >> 8) & PCI_IO_RANGE_MASK;
  410. if (end > 0xffff) {
  411. pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
  412. start >> 16);
  413. pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
  414. end >> 16);
  415. io_base_lo |= PCI_IO_RANGE_TYPE_32;
  416. } else
  417. io_base_lo |= PCI_IO_RANGE_TYPE_16;
  418. pci_write_config_byte(dev, PCI_IO_BASE, io_base_lo);
  419. pci_write_config_byte(dev, PCI_IO_LIMIT, io_limit_lo);
  420. } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
  421. == IORESOURCE_MEM) {
  422. off = hose->pci_mem_offset;
  423. mem_base = ((res->start - off) >> 16) & PCI_MEMORY_RANGE_MASK;
  424. mem_limit = ((res->end - off) >> 16) & PCI_MEMORY_RANGE_MASK;
  425. pci_write_config_word(dev, PCI_MEMORY_BASE, mem_base);
  426. pci_write_config_word(dev, PCI_MEMORY_LIMIT, mem_limit);
  427. } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
  428. == (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
  429. off = hose->pci_mem_offset;
  430. mem_base = ((res->start - off) >> 16) & PCI_PREF_RANGE_MASK;
  431. mem_limit = ((res->end - off) >> 16) & PCI_PREF_RANGE_MASK;
  432. pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, mem_base);
  433. pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, mem_limit);
  434. } else {
  435. DBG(KERN_ERR "PCI: ugh, bridge %s res %d has flags=%lx\n",
  436. pci_name(dev), i, res->flags);
  437. }
  438. pci_write_config_word(dev, PCI_COMMAND, cmd);
  439. }
  440. static inline void alloc_resource(struct pci_dev *dev, int idx)
  441. {
  442. struct resource *pr, *r = &dev->resource[idx];
  443. DBG("PCI:%s: Resource %d: %016llx-%016llx (f=%lx)\n",
  444. pci_name(dev), idx, (unsigned long long)r->start,
  445. (unsigned long long)r->end, r->flags);
  446. pr = pci_find_parent_resource(dev, r);
  447. if (!pr || request_resource(pr, r) < 0) {
  448. printk(KERN_ERR "PCI: Cannot allocate resource region %d"
  449. " of device %s\n", idx, pci_name(dev));
  450. if (pr)
  451. DBG("PCI: parent is %p: %016llx-%016llx (f=%lx)\n",
  452. pr, (unsigned long long)pr->start,
  453. (unsigned long long)pr->end, pr->flags);
  454. /* We'll assign a new address later */
  455. r->flags |= IORESOURCE_UNSET;
  456. r->end -= r->start;
  457. r->start = 0;
  458. }
  459. }
  460. static void __init
  461. pcibios_allocate_resources(int pass)
  462. {
  463. struct pci_dev *dev = NULL;
  464. int idx, disabled;
  465. u16 command;
  466. struct resource *r;
  467. for_each_pci_dev(dev) {
  468. pci_read_config_word(dev, PCI_COMMAND, &command);
  469. for (idx = 0; idx < 6; idx++) {
  470. r = &dev->resource[idx];
  471. if (r->parent) /* Already allocated */
  472. continue;
  473. if (!r->flags || (r->flags & IORESOURCE_UNSET))
  474. continue; /* Not assigned at all */
  475. if (r->flags & IORESOURCE_IO)
  476. disabled = !(command & PCI_COMMAND_IO);
  477. else
  478. disabled = !(command & PCI_COMMAND_MEMORY);
  479. if (pass == disabled)
  480. alloc_resource(dev, idx);
  481. }
  482. if (pass)
  483. continue;
  484. r = &dev->resource[PCI_ROM_RESOURCE];
  485. if (r->flags & IORESOURCE_ROM_ENABLE) {
  486. /* Turn the ROM off, leave the resource region, but keep it unregistered. */
  487. u32 reg;
  488. DBG("PCI: Switching off ROM of %s\n", pci_name(dev));
  489. r->flags &= ~IORESOURCE_ROM_ENABLE;
  490. pci_read_config_dword(dev, dev->rom_base_reg, &reg);
  491. pci_write_config_dword(dev, dev->rom_base_reg,
  492. reg & ~PCI_ROM_ADDRESS_ENABLE);
  493. }
  494. }
  495. }
  496. static void __init
  497. pcibios_assign_resources(void)
  498. {
  499. struct pci_dev *dev = NULL;
  500. int idx;
  501. struct resource *r;
  502. for_each_pci_dev(dev) {
  503. int class = dev->class >> 8;
  504. /* Don't touch classless devices and host bridges */
  505. if (!class || class == PCI_CLASS_BRIDGE_HOST)
  506. continue;
  507. for (idx = 0; idx < 6; idx++) {
  508. r = &dev->resource[idx];
  509. /*
  510. * We shall assign a new address to this resource,
  511. * either because the BIOS (sic) forgot to do so
  512. * or because we have decided the old address was
  513. * unusable for some reason.
  514. */
  515. if ((r->flags & IORESOURCE_UNSET) && r->end &&
  516. (!ppc_md.pcibios_enable_device_hook ||
  517. !ppc_md.pcibios_enable_device_hook(dev, 1))) {
  518. r->flags &= ~IORESOURCE_UNSET;
  519. pci_assign_resource(dev, idx);
  520. }
  521. }
  522. #if 0 /* don't assign ROMs */
  523. r = &dev->resource[PCI_ROM_RESOURCE];
  524. r->end -= r->start;
  525. r->start = 0;
  526. if (r->end)
  527. pci_assign_resource(dev, PCI_ROM_RESOURCE);
  528. #endif
  529. }
  530. }
  531. int
  532. pcibios_enable_resources(struct pci_dev *dev, int mask)
  533. {
  534. u16 cmd, old_cmd;
  535. int idx;
  536. struct resource *r;
  537. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  538. old_cmd = cmd;
  539. for (idx=0; idx<6; idx++) {
  540. /* Only set up the requested stuff */
  541. if (!(mask & (1<<idx)))
  542. continue;
  543. r = &dev->resource[idx];
  544. if (r->flags & IORESOURCE_UNSET) {
  545. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  546. return -EINVAL;
  547. }
  548. if (r->flags & IORESOURCE_IO)
  549. cmd |= PCI_COMMAND_IO;
  550. if (r->flags & IORESOURCE_MEM)
  551. cmd |= PCI_COMMAND_MEMORY;
  552. }
  553. if (dev->resource[PCI_ROM_RESOURCE].start)
  554. cmd |= PCI_COMMAND_MEMORY;
  555. if (cmd != old_cmd) {
  556. printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
  557. pci_write_config_word(dev, PCI_COMMAND, cmd);
  558. }
  559. return 0;
  560. }
  561. static int next_controller_index;
  562. struct pci_controller * __init
  563. pcibios_alloc_controller(void)
  564. {
  565. struct pci_controller *hose;
  566. hose = (struct pci_controller *)alloc_bootmem(sizeof(*hose));
  567. memset(hose, 0, sizeof(struct pci_controller));
  568. *hose_tail = hose;
  569. hose_tail = &hose->next;
  570. hose->index = next_controller_index++;
  571. return hose;
  572. }
  573. void pcibios_make_OF_bus_map(void)
  574. {
  575. }
  576. static int __init
  577. pcibios_init(void)
  578. {
  579. struct pci_controller *hose;
  580. struct pci_bus *bus;
  581. int next_busno;
  582. printk(KERN_INFO "PCI: Probing PCI hardware\n");
  583. /* Scan all of the recorded PCI controllers. */
  584. for (next_busno = 0, hose = hose_head; hose; hose = hose->next) {
  585. if (pci_assign_all_buses)
  586. hose->first_busno = next_busno;
  587. hose->last_busno = 0xff;
  588. bus = pci_scan_bus(hose->first_busno, hose->ops, hose);
  589. hose->last_busno = bus->subordinate;
  590. if (pci_assign_all_buses || next_busno <= hose->last_busno)
  591. next_busno = hose->last_busno + pcibios_assign_bus_offset;
  592. }
  593. pci_bus_count = next_busno;
  594. /* OpenFirmware based machines need a map of OF bus
  595. * numbers vs. kernel bus numbers since we may have to
  596. * remap them.
  597. */
  598. if (pci_assign_all_buses && have_of)
  599. pcibios_make_OF_bus_map();
  600. /* Do machine dependent PCI interrupt routing */
  601. if (ppc_md.pci_swizzle && ppc_md.pci_map_irq)
  602. pci_fixup_irqs(ppc_md.pci_swizzle, ppc_md.pci_map_irq);
  603. /* Call machine dependent fixup */
  604. if (ppc_md.pcibios_fixup)
  605. ppc_md.pcibios_fixup();
  606. /* Allocate and assign resources */
  607. pcibios_allocate_bus_resources(&pci_root_buses);
  608. pcibios_allocate_resources(0);
  609. pcibios_allocate_resources(1);
  610. pcibios_assign_resources();
  611. /* Call machine dependent post-init code */
  612. if (ppc_md.pcibios_after_init)
  613. ppc_md.pcibios_after_init();
  614. return 0;
  615. }
  616. subsys_initcall(pcibios_init);
  617. unsigned char __init
  618. common_swizzle(struct pci_dev *dev, unsigned char *pinp)
  619. {
  620. struct pci_controller *hose = dev->sysdata;
  621. if (dev->bus->number != hose->first_busno) {
  622. u8 pin = *pinp;
  623. do {
  624. pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
  625. /* Move up the chain of bridges. */
  626. dev = dev->bus->self;
  627. } while (dev->bus->self);
  628. *pinp = pin;
  629. /* The slot is the idsel of the last bridge. */
  630. }
  631. return PCI_SLOT(dev->devfn);
  632. }
  633. unsigned long resource_fixup(struct pci_dev * dev, struct resource * res,
  634. unsigned long start, unsigned long size)
  635. {
  636. return start;
  637. }
  638. void __init pcibios_fixup_bus(struct pci_bus *bus)
  639. {
  640. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  641. unsigned long io_offset;
  642. struct resource *res;
  643. int i;
  644. io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
  645. if (bus->parent == NULL) {
  646. /* This is a host bridge - fill in its resources */
  647. hose->bus = bus;
  648. bus->resource[0] = res = &hose->io_resource;
  649. if (!res->flags) {
  650. if (io_offset)
  651. printk(KERN_ERR "I/O resource not set for host"
  652. " bridge %d\n", hose->index);
  653. res->start = 0;
  654. res->end = IO_SPACE_LIMIT;
  655. res->flags = IORESOURCE_IO;
  656. }
  657. res->start += io_offset;
  658. res->end += io_offset;
  659. for (i = 0; i < 3; ++i) {
  660. res = &hose->mem_resources[i];
  661. if (!res->flags) {
  662. if (i > 0)
  663. continue;
  664. printk(KERN_ERR "Memory resource not set for "
  665. "host bridge %d\n", hose->index);
  666. res->start = hose->pci_mem_offset;
  667. res->end = ~0U;
  668. res->flags = IORESOURCE_MEM;
  669. }
  670. bus->resource[i+1] = res;
  671. }
  672. } else {
  673. /* This is a subordinate bridge */
  674. pci_read_bridge_bases(bus);
  675. for (i = 0; i < 4; ++i) {
  676. if ((res = bus->resource[i]) == NULL)
  677. continue;
  678. if (!res->flags)
  679. continue;
  680. if (io_offset && (res->flags & IORESOURCE_IO)) {
  681. res->start += io_offset;
  682. res->end += io_offset;
  683. } else if (hose->pci_mem_offset
  684. && (res->flags & IORESOURCE_MEM)) {
  685. res->start += hose->pci_mem_offset;
  686. res->end += hose->pci_mem_offset;
  687. }
  688. }
  689. }
  690. if (ppc_md.pcibios_fixup_bus)
  691. ppc_md.pcibios_fixup_bus(bus);
  692. }
  693. char __init *pcibios_setup(char *str)
  694. {
  695. return str;
  696. }
  697. /* the next one is stolen from the alpha port... */
  698. void __init
  699. pcibios_update_irq(struct pci_dev *dev, int irq)
  700. {
  701. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  702. /* XXX FIXME - update OF device tree node interrupt property */
  703. }
  704. int pcibios_enable_device(struct pci_dev *dev, int mask)
  705. {
  706. u16 cmd, old_cmd;
  707. int idx;
  708. struct resource *r;
  709. if (ppc_md.pcibios_enable_device_hook)
  710. if (ppc_md.pcibios_enable_device_hook(dev, 0))
  711. return -EINVAL;
  712. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  713. old_cmd = cmd;
  714. for (idx=0; idx<6; idx++) {
  715. r = &dev->resource[idx];
  716. if (r->flags & IORESOURCE_UNSET) {
  717. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  718. return -EINVAL;
  719. }
  720. if (r->flags & IORESOURCE_IO)
  721. cmd |= PCI_COMMAND_IO;
  722. if (r->flags & IORESOURCE_MEM)
  723. cmd |= PCI_COMMAND_MEMORY;
  724. }
  725. if (cmd != old_cmd) {
  726. printk("PCI: Enabling device %s (%04x -> %04x)\n",
  727. pci_name(dev), old_cmd, cmd);
  728. pci_write_config_word(dev, PCI_COMMAND, cmd);
  729. }
  730. return 0;
  731. }
  732. struct pci_controller*
  733. pci_bus_to_hose(int bus)
  734. {
  735. struct pci_controller* hose = hose_head;
  736. for (; hose; hose = hose->next)
  737. if (bus >= hose->first_busno && bus <= hose->last_busno)
  738. return hose;
  739. return NULL;
  740. }
  741. void __iomem *
  742. pci_bus_io_base(unsigned int bus)
  743. {
  744. struct pci_controller *hose;
  745. hose = pci_bus_to_hose(bus);
  746. if (!hose)
  747. return NULL;
  748. return hose->io_base_virt;
  749. }
  750. unsigned long
  751. pci_bus_io_base_phys(unsigned int bus)
  752. {
  753. struct pci_controller *hose;
  754. hose = pci_bus_to_hose(bus);
  755. if (!hose)
  756. return 0;
  757. return hose->io_base_phys;
  758. }
  759. unsigned long
  760. pci_bus_mem_base_phys(unsigned int bus)
  761. {
  762. struct pci_controller *hose;
  763. hose = pci_bus_to_hose(bus);
  764. if (!hose)
  765. return 0;
  766. return hose->pci_mem_offset;
  767. }
  768. unsigned long
  769. pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
  770. {
  771. /* Hack alert again ! See comments in chrp_pci.c
  772. */
  773. struct pci_controller* hose =
  774. (struct pci_controller *)pdev->sysdata;
  775. if (hose && res->flags & IORESOURCE_MEM)
  776. return res->start - hose->pci_mem_offset;
  777. /* We may want to do something with IOs here... */
  778. return res->start;
  779. }
  780. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  781. resource_size_t *offset,
  782. enum pci_mmap_state mmap_state)
  783. {
  784. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  785. unsigned long io_offset = 0;
  786. int i, res_bit;
  787. if (hose == 0)
  788. return NULL; /* should never happen */
  789. /* If memory, add on the PCI bridge address offset */
  790. if (mmap_state == pci_mmap_mem) {
  791. #if 0 /* See comment in pci_resource_to_user() for why this is disabled */
  792. *offset += hose->pci_mem_offset;
  793. #endif
  794. res_bit = IORESOURCE_MEM;
  795. } else {
  796. io_offset = hose->io_base_virt - ___IO_BASE;
  797. *offset += io_offset;
  798. res_bit = IORESOURCE_IO;
  799. }
  800. /*
  801. * Check that the offset requested corresponds to one of the
  802. * resources of the device.
  803. */
  804. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  805. struct resource *rp = &dev->resource[i];
  806. int flags = rp->flags;
  807. /* treat ROM as memory (should be already) */
  808. if (i == PCI_ROM_RESOURCE)
  809. flags |= IORESOURCE_MEM;
  810. /* Active and same type? */
  811. if ((flags & res_bit) == 0)
  812. continue;
  813. /* In the range of this resource? */
  814. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  815. continue;
  816. /* found it! construct the final physical address */
  817. if (mmap_state == pci_mmap_io)
  818. *offset += hose->io_base_phys - io_offset;
  819. return rp;
  820. }
  821. return NULL;
  822. }
  823. /*
  824. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  825. * device mapping.
  826. */
  827. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  828. pgprot_t protection,
  829. enum pci_mmap_state mmap_state,
  830. int write_combine)
  831. {
  832. unsigned long prot = pgprot_val(protection);
  833. /* Write combine is always 0 on non-memory space mappings. On
  834. * memory space, if the user didn't pass 1, we check for a
  835. * "prefetchable" resource. This is a bit hackish, but we use
  836. * this to workaround the inability of /sysfs to provide a write
  837. * combine bit
  838. */
  839. if (mmap_state != pci_mmap_mem)
  840. write_combine = 0;
  841. else if (write_combine == 0) {
  842. if (rp->flags & IORESOURCE_PREFETCH)
  843. write_combine = 1;
  844. }
  845. /* XXX would be nice to have a way to ask for write-through */
  846. prot |= _PAGE_NO_CACHE;
  847. if (write_combine)
  848. prot &= ~_PAGE_GUARDED;
  849. else
  850. prot |= _PAGE_GUARDED;
  851. printk("PCI map for %s:%llx, prot: %lx\n", pci_name(dev),
  852. (unsigned long long)rp->start, prot);
  853. return __pgprot(prot);
  854. }
  855. /*
  856. * This one is used by /dev/mem and fbdev who have no clue about the
  857. * PCI device, it tries to find the PCI device first and calls the
  858. * above routine
  859. */
  860. pgprot_t pci_phys_mem_access_prot(struct file *file,
  861. unsigned long pfn,
  862. unsigned long size,
  863. pgprot_t protection)
  864. {
  865. struct pci_dev *pdev = NULL;
  866. struct resource *found = NULL;
  867. unsigned long prot = pgprot_val(protection);
  868. unsigned long offset = pfn << PAGE_SHIFT;
  869. int i;
  870. if (page_is_ram(pfn))
  871. return prot;
  872. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  873. for_each_pci_dev(pdev) {
  874. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  875. struct resource *rp = &pdev->resource[i];
  876. int flags = rp->flags;
  877. /* Active and same type? */
  878. if ((flags & IORESOURCE_MEM) == 0)
  879. continue;
  880. /* In the range of this resource? */
  881. if (offset < (rp->start & PAGE_MASK) ||
  882. offset > rp->end)
  883. continue;
  884. found = rp;
  885. break;
  886. }
  887. if (found)
  888. break;
  889. }
  890. if (found) {
  891. if (found->flags & IORESOURCE_PREFETCH)
  892. prot &= ~_PAGE_GUARDED;
  893. pci_dev_put(pdev);
  894. }
  895. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  896. return __pgprot(prot);
  897. }
  898. /*
  899. * Perform the actual remap of the pages for a PCI device mapping, as
  900. * appropriate for this architecture. The region in the process to map
  901. * is described by vm_start and vm_end members of VMA, the base physical
  902. * address is found in vm_pgoff.
  903. * The pci device structure is provided so that architectures may make mapping
  904. * decisions on a per-device or per-bus basis.
  905. *
  906. * Returns a negative error code on failure, zero on success.
  907. */
  908. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  909. enum pci_mmap_state mmap_state,
  910. int write_combine)
  911. {
  912. resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
  913. struct resource *rp;
  914. int ret;
  915. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  916. if (rp == NULL)
  917. return -EINVAL;
  918. vma->vm_pgoff = offset >> PAGE_SHIFT;
  919. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  920. vma->vm_page_prot,
  921. mmap_state, write_combine);
  922. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  923. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  924. return ret;
  925. }
  926. /* Obsolete functions. Should be removed once the symbios driver
  927. * is fixed
  928. */
  929. unsigned long
  930. phys_to_bus(unsigned long pa)
  931. {
  932. struct pci_controller *hose;
  933. int i;
  934. for (hose = hose_head; hose; hose = hose->next) {
  935. for (i = 0; i < 3; ++i) {
  936. if (pa >= hose->mem_resources[i].start
  937. && pa <= hose->mem_resources[i].end) {
  938. /*
  939. * XXX the hose->pci_mem_offset really
  940. * only applies to mem_resources[0].
  941. * We need a way to store an offset for
  942. * the others. -- paulus
  943. */
  944. if (i == 0)
  945. pa -= hose->pci_mem_offset;
  946. return pa;
  947. }
  948. }
  949. }
  950. /* hmmm, didn't find it */
  951. return 0;
  952. }
  953. unsigned long
  954. pci_phys_to_bus(unsigned long pa, int busnr)
  955. {
  956. struct pci_controller* hose = pci_bus_to_hose(busnr);
  957. if (!hose)
  958. return pa;
  959. return pa - hose->pci_mem_offset;
  960. }
  961. unsigned long
  962. pci_bus_to_phys(unsigned int ba, int busnr)
  963. {
  964. struct pci_controller* hose = pci_bus_to_hose(busnr);
  965. if (!hose)
  966. return ba;
  967. return ba + hose->pci_mem_offset;
  968. }
  969. /* Provide information on locations of various I/O regions in physical
  970. * memory. Do this on a per-card basis so that we choose the right
  971. * root bridge.
  972. * Note that the returned IO or memory base is a physical address
  973. */
  974. long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
  975. {
  976. struct pci_controller* hose;
  977. long result = -EOPNOTSUPP;
  978. hose = pci_bus_to_hose(bus);
  979. if (!hose)
  980. return -ENODEV;
  981. switch (which) {
  982. case IOBASE_BRIDGE_NUMBER:
  983. return (long)hose->first_busno;
  984. case IOBASE_MEMORY:
  985. return (long)hose->pci_mem_offset;
  986. case IOBASE_IO:
  987. return (long)hose->io_base_phys;
  988. case IOBASE_ISA_IO:
  989. return (long)isa_io_base;
  990. case IOBASE_ISA_MEM:
  991. return (long)isa_mem_base;
  992. }
  993. return result;
  994. }
  995. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  996. const struct resource *rsrc,
  997. resource_size_t *start, resource_size_t *end)
  998. {
  999. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  1000. resource_size_t offset = 0;
  1001. if (hose == NULL)
  1002. return;
  1003. if (rsrc->flags & IORESOURCE_IO)
  1004. offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  1005. /* We pass a fully fixed up address to userland for MMIO instead of
  1006. * a BAR value because X is lame and expects to be able to use that
  1007. * to pass to /dev/mem !
  1008. *
  1009. * That means that we'll have potentially 64 bits values where some
  1010. * userland apps only expect 32 (like X itself since it thinks only
  1011. * Sparc has 64 bits MMIO) but if we don't do that, we break it on
  1012. * 32 bits CHRPs :-(
  1013. *
  1014. * Hopefully, the sysfs insterface is immune to that gunk. Once X
  1015. * has been fixed (and the fix spread enough), we can re-enable the
  1016. * 2 lines below and pass down a BAR value to userland. In that case
  1017. * we'll also have to re-enable the matching code in
  1018. * __pci_mmap_make_offset().
  1019. *
  1020. * BenH.
  1021. */
  1022. #if 0
  1023. else if (rsrc->flags & IORESOURCE_MEM)
  1024. offset = hose->pci_mem_offset;
  1025. #endif
  1026. *start = rsrc->start - offset;
  1027. *end = rsrc->end - offset;
  1028. }
  1029. void __init pci_init_resource(struct resource *res, resource_size_t start,
  1030. resource_size_t end, int flags, char *name)
  1031. {
  1032. res->start = start;
  1033. res->end = end;
  1034. res->flags = flags;
  1035. res->name = name;
  1036. res->parent = NULL;
  1037. res->sibling = NULL;
  1038. res->child = NULL;
  1039. }
  1040. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
  1041. {
  1042. unsigned long start = pci_resource_start(dev, bar);
  1043. unsigned long len = pci_resource_len(dev, bar);
  1044. unsigned long flags = pci_resource_flags(dev, bar);
  1045. if (!len)
  1046. return NULL;
  1047. if (max && len > max)
  1048. len = max;
  1049. if (flags & IORESOURCE_IO)
  1050. return ioport_map(start, len);
  1051. if (flags & IORESOURCE_MEM)
  1052. /* Not checking IORESOURCE_CACHEABLE because PPC does
  1053. * not currently distinguish between ioremap and
  1054. * ioremap_nocache.
  1055. */
  1056. return ioremap(start, len);
  1057. /* What? */
  1058. return NULL;
  1059. }
  1060. void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
  1061. {
  1062. /* Nothing to do */
  1063. }
  1064. EXPORT_SYMBOL(pci_iomap);
  1065. EXPORT_SYMBOL(pci_iounmap);
  1066. unsigned long pci_address_to_pio(phys_addr_t address)
  1067. {
  1068. struct pci_controller* hose = hose_head;
  1069. for (; hose; hose = hose->next) {
  1070. unsigned int size = hose->io_resource.end -
  1071. hose->io_resource.start + 1;
  1072. if (address >= hose->io_base_phys &&
  1073. address < (hose->io_base_phys + size)) {
  1074. unsigned long base =
  1075. (unsigned long)hose->io_base_virt - _IO_BASE;
  1076. return base + (address - hose->io_base_phys);
  1077. }
  1078. }
  1079. return (unsigned int)-1;
  1080. }
  1081. EXPORT_SYMBOL(pci_address_to_pio);
  1082. /*
  1083. * Null PCI config access functions, for the case when we can't
  1084. * find a hose.
  1085. */
  1086. #define NULL_PCI_OP(rw, size, type) \
  1087. static int \
  1088. null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
  1089. { \
  1090. return PCIBIOS_DEVICE_NOT_FOUND; \
  1091. }
  1092. static int
  1093. null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  1094. int len, u32 *val)
  1095. {
  1096. return PCIBIOS_DEVICE_NOT_FOUND;
  1097. }
  1098. static int
  1099. null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  1100. int len, u32 val)
  1101. {
  1102. return PCIBIOS_DEVICE_NOT_FOUND;
  1103. }
  1104. static struct pci_ops null_pci_ops =
  1105. {
  1106. null_read_config,
  1107. null_write_config
  1108. };
  1109. /*
  1110. * These functions are used early on before PCI scanning is done
  1111. * and all of the pci_dev and pci_bus structures have been created.
  1112. */
  1113. static struct pci_bus *
  1114. fake_pci_bus(struct pci_controller *hose, int busnr)
  1115. {
  1116. static struct pci_bus bus;
  1117. if (hose == 0) {
  1118. hose = pci_bus_to_hose(busnr);
  1119. if (hose == 0)
  1120. printk(KERN_ERR "Can't find hose for PCI bus %d!\n", busnr);
  1121. }
  1122. bus.number = busnr;
  1123. bus.sysdata = hose;
  1124. bus.ops = hose? hose->ops: &null_pci_ops;
  1125. return &bus;
  1126. }
  1127. #define EARLY_PCI_OP(rw, size, type) \
  1128. int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
  1129. int devfn, int offset, type value) \
  1130. { \
  1131. return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
  1132. devfn, offset, value); \
  1133. }
  1134. EARLY_PCI_OP(read, byte, u8 *)
  1135. EARLY_PCI_OP(read, word, u16 *)
  1136. EARLY_PCI_OP(read, dword, u32 *)
  1137. EARLY_PCI_OP(write, byte, u8)
  1138. EARLY_PCI_OP(write, word, u16)
  1139. EARLY_PCI_OP(write, dword, u32)