pci.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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. /* Add sysfs properties */
  577. void pcibios_add_platform_entries(struct pci_dev *pdev)
  578. {
  579. }
  580. static int __init
  581. pcibios_init(void)
  582. {
  583. struct pci_controller *hose;
  584. struct pci_bus *bus;
  585. int next_busno;
  586. printk(KERN_INFO "PCI: Probing PCI hardware\n");
  587. /* Scan all of the recorded PCI controllers. */
  588. for (next_busno = 0, hose = hose_head; hose; hose = hose->next) {
  589. if (pci_assign_all_buses)
  590. hose->first_busno = next_busno;
  591. hose->last_busno = 0xff;
  592. bus = pci_scan_bus(hose->first_busno, hose->ops, hose);
  593. hose->last_busno = bus->subordinate;
  594. if (pci_assign_all_buses || next_busno <= hose->last_busno)
  595. next_busno = hose->last_busno + pcibios_assign_bus_offset;
  596. }
  597. pci_bus_count = next_busno;
  598. /* OpenFirmware based machines need a map of OF bus
  599. * numbers vs. kernel bus numbers since we may have to
  600. * remap them.
  601. */
  602. if (pci_assign_all_buses && have_of)
  603. pcibios_make_OF_bus_map();
  604. /* Do machine dependent PCI interrupt routing */
  605. if (ppc_md.pci_swizzle && ppc_md.pci_map_irq)
  606. pci_fixup_irqs(ppc_md.pci_swizzle, ppc_md.pci_map_irq);
  607. /* Call machine dependent fixup */
  608. if (ppc_md.pcibios_fixup)
  609. ppc_md.pcibios_fixup();
  610. /* Allocate and assign resources */
  611. pcibios_allocate_bus_resources(&pci_root_buses);
  612. pcibios_allocate_resources(0);
  613. pcibios_allocate_resources(1);
  614. pcibios_assign_resources();
  615. /* Call machine dependent post-init code */
  616. if (ppc_md.pcibios_after_init)
  617. ppc_md.pcibios_after_init();
  618. return 0;
  619. }
  620. subsys_initcall(pcibios_init);
  621. unsigned char __init
  622. common_swizzle(struct pci_dev *dev, unsigned char *pinp)
  623. {
  624. struct pci_controller *hose = dev->sysdata;
  625. if (dev->bus->number != hose->first_busno) {
  626. u8 pin = *pinp;
  627. do {
  628. pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
  629. /* Move up the chain of bridges. */
  630. dev = dev->bus->self;
  631. } while (dev->bus->self);
  632. *pinp = pin;
  633. /* The slot is the idsel of the last bridge. */
  634. }
  635. return PCI_SLOT(dev->devfn);
  636. }
  637. unsigned long resource_fixup(struct pci_dev * dev, struct resource * res,
  638. unsigned long start, unsigned long size)
  639. {
  640. return start;
  641. }
  642. void __init pcibios_fixup_bus(struct pci_bus *bus)
  643. {
  644. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  645. unsigned long io_offset;
  646. struct resource *res;
  647. int i;
  648. io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
  649. if (bus->parent == NULL) {
  650. /* This is a host bridge - fill in its resources */
  651. hose->bus = bus;
  652. bus->resource[0] = res = &hose->io_resource;
  653. if (!res->flags) {
  654. if (io_offset)
  655. printk(KERN_ERR "I/O resource not set for host"
  656. " bridge %d\n", hose->index);
  657. res->start = 0;
  658. res->end = IO_SPACE_LIMIT;
  659. res->flags = IORESOURCE_IO;
  660. }
  661. res->start += io_offset;
  662. res->end += io_offset;
  663. for (i = 0; i < 3; ++i) {
  664. res = &hose->mem_resources[i];
  665. if (!res->flags) {
  666. if (i > 0)
  667. continue;
  668. printk(KERN_ERR "Memory resource not set for "
  669. "host bridge %d\n", hose->index);
  670. res->start = hose->pci_mem_offset;
  671. res->end = ~0U;
  672. res->flags = IORESOURCE_MEM;
  673. }
  674. bus->resource[i+1] = res;
  675. }
  676. } else {
  677. /* This is a subordinate bridge */
  678. pci_read_bridge_bases(bus);
  679. for (i = 0; i < 4; ++i) {
  680. if ((res = bus->resource[i]) == NULL)
  681. continue;
  682. if (!res->flags)
  683. continue;
  684. if (io_offset && (res->flags & IORESOURCE_IO)) {
  685. res->start += io_offset;
  686. res->end += io_offset;
  687. } else if (hose->pci_mem_offset
  688. && (res->flags & IORESOURCE_MEM)) {
  689. res->start += hose->pci_mem_offset;
  690. res->end += hose->pci_mem_offset;
  691. }
  692. }
  693. }
  694. if (ppc_md.pcibios_fixup_bus)
  695. ppc_md.pcibios_fixup_bus(bus);
  696. }
  697. char __init *pcibios_setup(char *str)
  698. {
  699. return str;
  700. }
  701. /* the next one is stolen from the alpha port... */
  702. void __init
  703. pcibios_update_irq(struct pci_dev *dev, int irq)
  704. {
  705. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  706. /* XXX FIXME - update OF device tree node interrupt property */
  707. }
  708. int pcibios_enable_device(struct pci_dev *dev, int mask)
  709. {
  710. u16 cmd, old_cmd;
  711. int idx;
  712. struct resource *r;
  713. if (ppc_md.pcibios_enable_device_hook)
  714. if (ppc_md.pcibios_enable_device_hook(dev, 0))
  715. return -EINVAL;
  716. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  717. old_cmd = cmd;
  718. for (idx=0; idx<6; idx++) {
  719. r = &dev->resource[idx];
  720. if (r->flags & IORESOURCE_UNSET) {
  721. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  722. return -EINVAL;
  723. }
  724. if (r->flags & IORESOURCE_IO)
  725. cmd |= PCI_COMMAND_IO;
  726. if (r->flags & IORESOURCE_MEM)
  727. cmd |= PCI_COMMAND_MEMORY;
  728. }
  729. if (cmd != old_cmd) {
  730. printk("PCI: Enabling device %s (%04x -> %04x)\n",
  731. pci_name(dev), old_cmd, cmd);
  732. pci_write_config_word(dev, PCI_COMMAND, cmd);
  733. }
  734. return 0;
  735. }
  736. struct pci_controller*
  737. pci_bus_to_hose(int bus)
  738. {
  739. struct pci_controller* hose = hose_head;
  740. for (; hose; hose = hose->next)
  741. if (bus >= hose->first_busno && bus <= hose->last_busno)
  742. return hose;
  743. return NULL;
  744. }
  745. void __iomem *
  746. pci_bus_io_base(unsigned int bus)
  747. {
  748. struct pci_controller *hose;
  749. hose = pci_bus_to_hose(bus);
  750. if (!hose)
  751. return NULL;
  752. return hose->io_base_virt;
  753. }
  754. unsigned long
  755. pci_bus_io_base_phys(unsigned int bus)
  756. {
  757. struct pci_controller *hose;
  758. hose = pci_bus_to_hose(bus);
  759. if (!hose)
  760. return 0;
  761. return hose->io_base_phys;
  762. }
  763. unsigned long
  764. pci_bus_mem_base_phys(unsigned int bus)
  765. {
  766. struct pci_controller *hose;
  767. hose = pci_bus_to_hose(bus);
  768. if (!hose)
  769. return 0;
  770. return hose->pci_mem_offset;
  771. }
  772. unsigned long
  773. pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
  774. {
  775. /* Hack alert again ! See comments in chrp_pci.c
  776. */
  777. struct pci_controller* hose =
  778. (struct pci_controller *)pdev->sysdata;
  779. if (hose && res->flags & IORESOURCE_MEM)
  780. return res->start - hose->pci_mem_offset;
  781. /* We may want to do something with IOs here... */
  782. return res->start;
  783. }
  784. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  785. resource_size_t *offset,
  786. enum pci_mmap_state mmap_state)
  787. {
  788. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  789. unsigned long io_offset = 0;
  790. int i, res_bit;
  791. if (hose == 0)
  792. return NULL; /* should never happen */
  793. /* If memory, add on the PCI bridge address offset */
  794. if (mmap_state == pci_mmap_mem) {
  795. #if 0 /* See comment in pci_resource_to_user() for why this is disabled */
  796. *offset += hose->pci_mem_offset;
  797. #endif
  798. res_bit = IORESOURCE_MEM;
  799. } else {
  800. io_offset = hose->io_base_virt - ___IO_BASE;
  801. *offset += io_offset;
  802. res_bit = IORESOURCE_IO;
  803. }
  804. /*
  805. * Check that the offset requested corresponds to one of the
  806. * resources of the device.
  807. */
  808. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  809. struct resource *rp = &dev->resource[i];
  810. int flags = rp->flags;
  811. /* treat ROM as memory (should be already) */
  812. if (i == PCI_ROM_RESOURCE)
  813. flags |= IORESOURCE_MEM;
  814. /* Active and same type? */
  815. if ((flags & res_bit) == 0)
  816. continue;
  817. /* In the range of this resource? */
  818. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  819. continue;
  820. /* found it! construct the final physical address */
  821. if (mmap_state == pci_mmap_io)
  822. *offset += hose->io_base_phys - io_offset;
  823. return rp;
  824. }
  825. return NULL;
  826. }
  827. /*
  828. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  829. * device mapping.
  830. */
  831. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  832. pgprot_t protection,
  833. enum pci_mmap_state mmap_state,
  834. int write_combine)
  835. {
  836. unsigned long prot = pgprot_val(protection);
  837. /* Write combine is always 0 on non-memory space mappings. On
  838. * memory space, if the user didn't pass 1, we check for a
  839. * "prefetchable" resource. This is a bit hackish, but we use
  840. * this to workaround the inability of /sysfs to provide a write
  841. * combine bit
  842. */
  843. if (mmap_state != pci_mmap_mem)
  844. write_combine = 0;
  845. else if (write_combine == 0) {
  846. if (rp->flags & IORESOURCE_PREFETCH)
  847. write_combine = 1;
  848. }
  849. /* XXX would be nice to have a way to ask for write-through */
  850. prot |= _PAGE_NO_CACHE;
  851. if (write_combine)
  852. prot &= ~_PAGE_GUARDED;
  853. else
  854. prot |= _PAGE_GUARDED;
  855. printk("PCI map for %s:%llx, prot: %lx\n", pci_name(dev),
  856. (unsigned long long)rp->start, prot);
  857. return __pgprot(prot);
  858. }
  859. /*
  860. * This one is used by /dev/mem and fbdev who have no clue about the
  861. * PCI device, it tries to find the PCI device first and calls the
  862. * above routine
  863. */
  864. pgprot_t pci_phys_mem_access_prot(struct file *file,
  865. unsigned long pfn,
  866. unsigned long size,
  867. pgprot_t protection)
  868. {
  869. struct pci_dev *pdev = NULL;
  870. struct resource *found = NULL;
  871. unsigned long prot = pgprot_val(protection);
  872. unsigned long offset = pfn << PAGE_SHIFT;
  873. int i;
  874. if (page_is_ram(pfn))
  875. return prot;
  876. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  877. for_each_pci_dev(pdev) {
  878. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  879. struct resource *rp = &pdev->resource[i];
  880. int flags = rp->flags;
  881. /* Active and same type? */
  882. if ((flags & IORESOURCE_MEM) == 0)
  883. continue;
  884. /* In the range of this resource? */
  885. if (offset < (rp->start & PAGE_MASK) ||
  886. offset > rp->end)
  887. continue;
  888. found = rp;
  889. break;
  890. }
  891. if (found)
  892. break;
  893. }
  894. if (found) {
  895. if (found->flags & IORESOURCE_PREFETCH)
  896. prot &= ~_PAGE_GUARDED;
  897. pci_dev_put(pdev);
  898. }
  899. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  900. return __pgprot(prot);
  901. }
  902. /*
  903. * Perform the actual remap of the pages for a PCI device mapping, as
  904. * appropriate for this architecture. The region in the process to map
  905. * is described by vm_start and vm_end members of VMA, the base physical
  906. * address is found in vm_pgoff.
  907. * The pci device structure is provided so that architectures may make mapping
  908. * decisions on a per-device or per-bus basis.
  909. *
  910. * Returns a negative error code on failure, zero on success.
  911. */
  912. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  913. enum pci_mmap_state mmap_state,
  914. int write_combine)
  915. {
  916. resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
  917. struct resource *rp;
  918. int ret;
  919. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  920. if (rp == NULL)
  921. return -EINVAL;
  922. vma->vm_pgoff = offset >> PAGE_SHIFT;
  923. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  924. vma->vm_page_prot,
  925. mmap_state, write_combine);
  926. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  927. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  928. return ret;
  929. }
  930. /* Obsolete functions. Should be removed once the symbios driver
  931. * is fixed
  932. */
  933. unsigned long
  934. phys_to_bus(unsigned long pa)
  935. {
  936. struct pci_controller *hose;
  937. int i;
  938. for (hose = hose_head; hose; hose = hose->next) {
  939. for (i = 0; i < 3; ++i) {
  940. if (pa >= hose->mem_resources[i].start
  941. && pa <= hose->mem_resources[i].end) {
  942. /*
  943. * XXX the hose->pci_mem_offset really
  944. * only applies to mem_resources[0].
  945. * We need a way to store an offset for
  946. * the others. -- paulus
  947. */
  948. if (i == 0)
  949. pa -= hose->pci_mem_offset;
  950. return pa;
  951. }
  952. }
  953. }
  954. /* hmmm, didn't find it */
  955. return 0;
  956. }
  957. unsigned long
  958. pci_phys_to_bus(unsigned long pa, int busnr)
  959. {
  960. struct pci_controller* hose = pci_bus_to_hose(busnr);
  961. if (!hose)
  962. return pa;
  963. return pa - hose->pci_mem_offset;
  964. }
  965. unsigned long
  966. pci_bus_to_phys(unsigned int ba, int busnr)
  967. {
  968. struct pci_controller* hose = pci_bus_to_hose(busnr);
  969. if (!hose)
  970. return ba;
  971. return ba + hose->pci_mem_offset;
  972. }
  973. /* Provide information on locations of various I/O regions in physical
  974. * memory. Do this on a per-card basis so that we choose the right
  975. * root bridge.
  976. * Note that the returned IO or memory base is a physical address
  977. */
  978. long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
  979. {
  980. struct pci_controller* hose;
  981. long result = -EOPNOTSUPP;
  982. hose = pci_bus_to_hose(bus);
  983. if (!hose)
  984. return -ENODEV;
  985. switch (which) {
  986. case IOBASE_BRIDGE_NUMBER:
  987. return (long)hose->first_busno;
  988. case IOBASE_MEMORY:
  989. return (long)hose->pci_mem_offset;
  990. case IOBASE_IO:
  991. return (long)hose->io_base_phys;
  992. case IOBASE_ISA_IO:
  993. return (long)isa_io_base;
  994. case IOBASE_ISA_MEM:
  995. return (long)isa_mem_base;
  996. }
  997. return result;
  998. }
  999. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  1000. const struct resource *rsrc,
  1001. resource_size_t *start, resource_size_t *end)
  1002. {
  1003. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  1004. resource_size_t offset = 0;
  1005. if (hose == NULL)
  1006. return;
  1007. if (rsrc->flags & IORESOURCE_IO)
  1008. offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  1009. /* We pass a fully fixed up address to userland for MMIO instead of
  1010. * a BAR value because X is lame and expects to be able to use that
  1011. * to pass to /dev/mem !
  1012. *
  1013. * That means that we'll have potentially 64 bits values where some
  1014. * userland apps only expect 32 (like X itself since it thinks only
  1015. * Sparc has 64 bits MMIO) but if we don't do that, we break it on
  1016. * 32 bits CHRPs :-(
  1017. *
  1018. * Hopefully, the sysfs insterface is immune to that gunk. Once X
  1019. * has been fixed (and the fix spread enough), we can re-enable the
  1020. * 2 lines below and pass down a BAR value to userland. In that case
  1021. * we'll also have to re-enable the matching code in
  1022. * __pci_mmap_make_offset().
  1023. *
  1024. * BenH.
  1025. */
  1026. #if 0
  1027. else if (rsrc->flags & IORESOURCE_MEM)
  1028. offset = hose->pci_mem_offset;
  1029. #endif
  1030. *start = rsrc->start - offset;
  1031. *end = rsrc->end - offset;
  1032. }
  1033. void __init pci_init_resource(struct resource *res, resource_size_t start,
  1034. resource_size_t end, int flags, char *name)
  1035. {
  1036. res->start = start;
  1037. res->end = end;
  1038. res->flags = flags;
  1039. res->name = name;
  1040. res->parent = NULL;
  1041. res->sibling = NULL;
  1042. res->child = NULL;
  1043. }
  1044. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
  1045. {
  1046. unsigned long start = pci_resource_start(dev, bar);
  1047. unsigned long len = pci_resource_len(dev, bar);
  1048. unsigned long flags = pci_resource_flags(dev, bar);
  1049. if (!len)
  1050. return NULL;
  1051. if (max && len > max)
  1052. len = max;
  1053. if (flags & IORESOURCE_IO)
  1054. return ioport_map(start, len);
  1055. if (flags & IORESOURCE_MEM)
  1056. /* Not checking IORESOURCE_CACHEABLE because PPC does
  1057. * not currently distinguish between ioremap and
  1058. * ioremap_nocache.
  1059. */
  1060. return ioremap(start, len);
  1061. /* What? */
  1062. return NULL;
  1063. }
  1064. void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
  1065. {
  1066. /* Nothing to do */
  1067. }
  1068. EXPORT_SYMBOL(pci_iomap);
  1069. EXPORT_SYMBOL(pci_iounmap);
  1070. unsigned long pci_address_to_pio(phys_addr_t address)
  1071. {
  1072. struct pci_controller* hose = hose_head;
  1073. for (; hose; hose = hose->next) {
  1074. unsigned int size = hose->io_resource.end -
  1075. hose->io_resource.start + 1;
  1076. if (address >= hose->io_base_phys &&
  1077. address < (hose->io_base_phys + size)) {
  1078. unsigned long base =
  1079. (unsigned long)hose->io_base_virt - _IO_BASE;
  1080. return base + (address - hose->io_base_phys);
  1081. }
  1082. }
  1083. return (unsigned int)-1;
  1084. }
  1085. EXPORT_SYMBOL(pci_address_to_pio);
  1086. /*
  1087. * Null PCI config access functions, for the case when we can't
  1088. * find a hose.
  1089. */
  1090. #define NULL_PCI_OP(rw, size, type) \
  1091. static int \
  1092. null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
  1093. { \
  1094. return PCIBIOS_DEVICE_NOT_FOUND; \
  1095. }
  1096. static int
  1097. null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  1098. int len, u32 *val)
  1099. {
  1100. return PCIBIOS_DEVICE_NOT_FOUND;
  1101. }
  1102. static int
  1103. null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  1104. int len, u32 val)
  1105. {
  1106. return PCIBIOS_DEVICE_NOT_FOUND;
  1107. }
  1108. static struct pci_ops null_pci_ops =
  1109. {
  1110. null_read_config,
  1111. null_write_config
  1112. };
  1113. /*
  1114. * These functions are used early on before PCI scanning is done
  1115. * and all of the pci_dev and pci_bus structures have been created.
  1116. */
  1117. static struct pci_bus *
  1118. fake_pci_bus(struct pci_controller *hose, int busnr)
  1119. {
  1120. static struct pci_bus bus;
  1121. if (hose == 0) {
  1122. hose = pci_bus_to_hose(busnr);
  1123. if (hose == 0)
  1124. printk(KERN_ERR "Can't find hose for PCI bus %d!\n", busnr);
  1125. }
  1126. bus.number = busnr;
  1127. bus.sysdata = hose;
  1128. bus.ops = hose? hose->ops: &null_pci_ops;
  1129. return &bus;
  1130. }
  1131. #define EARLY_PCI_OP(rw, size, type) \
  1132. int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
  1133. int devfn, int offset, type value) \
  1134. { \
  1135. return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
  1136. devfn, offset, value); \
  1137. }
  1138. EARLY_PCI_OP(read, byte, u8 *)
  1139. EARLY_PCI_OP(read, word, u16 *)
  1140. EARLY_PCI_OP(read, dword, u32 *)
  1141. EARLY_PCI_OP(write, byte, u8)
  1142. EARLY_PCI_OP(write, word, u16)
  1143. EARLY_PCI_OP(write, dword, u32)