pci_32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Common pmac/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 <linux/irq.h>
  14. #include <linux/list.h>
  15. #include <asm/processor.h>
  16. #include <asm/io.h>
  17. #include <asm/prom.h>
  18. #include <asm/sections.h>
  19. #include <asm/pci-bridge.h>
  20. #include <asm/byteorder.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/machdep.h>
  23. #undef DEBUG
  24. #ifdef DEBUG
  25. #define DBG(x...) printk(x)
  26. #else
  27. #define DBG(x...)
  28. #endif
  29. unsigned long isa_io_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 void fixup_broken_pcnet32(struct pci_dev* dev);
  34. static void fixup_cpc710_pci64(struct pci_dev* dev);
  35. #ifdef CONFIG_PPC_OF
  36. static u8* pci_to_OF_bus_map;
  37. #endif
  38. /* By default, we don't re-assign bus numbers. We do this only on
  39. * some pmacs
  40. */
  41. static int pci_assign_all_buses;
  42. LIST_HEAD(hose_list);
  43. static int pci_bus_count;
  44. static void
  45. fixup_hide_host_resource_fsl(struct pci_dev* dev)
  46. {
  47. int i, class = dev->class >> 8;
  48. if ((class == PCI_CLASS_PROCESSOR_POWERPC) &&
  49. (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) &&
  50. (dev->bus->parent == NULL)) {
  51. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  52. dev->resource[i].start = 0;
  53. dev->resource[i].end = 0;
  54. dev->resource[i].flags = 0;
  55. }
  56. }
  57. }
  58. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MOTOROLA, PCI_ANY_ID, fixup_hide_host_resource_fsl);
  59. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, fixup_hide_host_resource_fsl);
  60. static void
  61. fixup_broken_pcnet32(struct pci_dev* dev)
  62. {
  63. if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
  64. dev->vendor = PCI_VENDOR_ID_AMD;
  65. pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
  66. }
  67. }
  68. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32);
  69. static void
  70. fixup_cpc710_pci64(struct pci_dev* dev)
  71. {
  72. /* Hide the PCI64 BARs from the kernel as their content doesn't
  73. * fit well in the resource management
  74. */
  75. dev->resource[0].start = dev->resource[0].end = 0;
  76. dev->resource[0].flags = 0;
  77. dev->resource[1].start = dev->resource[1].end = 0;
  78. dev->resource[1].flags = 0;
  79. }
  80. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64);
  81. void __init
  82. update_bridge_resource(struct pci_dev *dev, struct resource *res)
  83. {
  84. u8 io_base_lo, io_limit_lo;
  85. u16 mem_base, mem_limit;
  86. u16 cmd;
  87. resource_size_t start, end, off;
  88. struct pci_controller *hose = dev->sysdata;
  89. if (!hose) {
  90. printk("update_bridge_base: no hose?\n");
  91. return;
  92. }
  93. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  94. pci_write_config_word(dev, PCI_COMMAND,
  95. cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
  96. if (res->flags & IORESOURCE_IO) {
  97. off = (unsigned long) hose->io_base_virt - isa_io_base;
  98. start = res->start - off;
  99. end = res->end - off;
  100. io_base_lo = (start >> 8) & PCI_IO_RANGE_MASK;
  101. io_limit_lo = (end >> 8) & PCI_IO_RANGE_MASK;
  102. if (end > 0xffff)
  103. io_base_lo |= PCI_IO_RANGE_TYPE_32;
  104. else
  105. io_base_lo |= PCI_IO_RANGE_TYPE_16;
  106. pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
  107. start >> 16);
  108. pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
  109. end >> 16);
  110. pci_write_config_byte(dev, PCI_IO_BASE, io_base_lo);
  111. pci_write_config_byte(dev, PCI_IO_LIMIT, io_limit_lo);
  112. } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
  113. == IORESOURCE_MEM) {
  114. off = hose->pci_mem_offset;
  115. mem_base = ((res->start - off) >> 16) & PCI_MEMORY_RANGE_MASK;
  116. mem_limit = ((res->end - off) >> 16) & PCI_MEMORY_RANGE_MASK;
  117. pci_write_config_word(dev, PCI_MEMORY_BASE, mem_base);
  118. pci_write_config_word(dev, PCI_MEMORY_LIMIT, mem_limit);
  119. } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
  120. == (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
  121. off = hose->pci_mem_offset;
  122. mem_base = ((res->start - off) >> 16) & PCI_PREF_RANGE_MASK;
  123. mem_limit = ((res->end - off) >> 16) & PCI_PREF_RANGE_MASK;
  124. pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, mem_base);
  125. pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, mem_limit);
  126. } else {
  127. DBG(KERN_ERR "PCI: ugh, bridge %s res has flags=%lx\n",
  128. pci_name(dev), res->flags);
  129. }
  130. pci_write_config_word(dev, PCI_COMMAND, cmd);
  131. }
  132. #ifdef CONFIG_PPC_OF
  133. /*
  134. * Functions below are used on OpenFirmware machines.
  135. */
  136. static void
  137. make_one_node_map(struct device_node* node, u8 pci_bus)
  138. {
  139. const int *bus_range;
  140. int len;
  141. if (pci_bus >= pci_bus_count)
  142. return;
  143. bus_range = of_get_property(node, "bus-range", &len);
  144. if (bus_range == NULL || len < 2 * sizeof(int)) {
  145. printk(KERN_WARNING "Can't get bus-range for %s, "
  146. "assuming it starts at 0\n", node->full_name);
  147. pci_to_OF_bus_map[pci_bus] = 0;
  148. } else
  149. pci_to_OF_bus_map[pci_bus] = bus_range[0];
  150. for (node=node->child; node != 0;node = node->sibling) {
  151. struct pci_dev* dev;
  152. const unsigned int *class_code, *reg;
  153. class_code = of_get_property(node, "class-code", NULL);
  154. if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
  155. (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
  156. continue;
  157. reg = of_get_property(node, "reg", NULL);
  158. if (!reg)
  159. continue;
  160. dev = pci_get_bus_and_slot(pci_bus, ((reg[0] >> 8) & 0xff));
  161. if (!dev || !dev->subordinate) {
  162. pci_dev_put(dev);
  163. continue;
  164. }
  165. make_one_node_map(node, dev->subordinate->number);
  166. pci_dev_put(dev);
  167. }
  168. }
  169. void
  170. pcibios_make_OF_bus_map(void)
  171. {
  172. int i;
  173. struct pci_controller *hose, *tmp;
  174. struct property *map_prop;
  175. struct device_node *dn;
  176. pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL);
  177. if (!pci_to_OF_bus_map) {
  178. printk(KERN_ERR "Can't allocate OF bus map !\n");
  179. return;
  180. }
  181. /* We fill the bus map with invalid values, that helps
  182. * debugging.
  183. */
  184. for (i=0; i<pci_bus_count; i++)
  185. pci_to_OF_bus_map[i] = 0xff;
  186. /* For each hose, we begin searching bridges */
  187. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  188. struct device_node* node = hose->dn;
  189. if (!node)
  190. continue;
  191. make_one_node_map(node, hose->first_busno);
  192. }
  193. dn = of_find_node_by_path("/");
  194. map_prop = of_find_property(dn, "pci-OF-bus-map", NULL);
  195. if (map_prop) {
  196. BUG_ON(pci_bus_count > map_prop->length);
  197. memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
  198. }
  199. of_node_put(dn);
  200. #ifdef DEBUG
  201. printk("PCI->OF bus map:\n");
  202. for (i=0; i<pci_bus_count; i++) {
  203. if (pci_to_OF_bus_map[i] == 0xff)
  204. continue;
  205. printk("%d -> %d\n", i, pci_to_OF_bus_map[i]);
  206. }
  207. #endif
  208. }
  209. typedef int (*pci_OF_scan_iterator)(struct device_node* node, void* data);
  210. static struct device_node*
  211. scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void* data)
  212. {
  213. struct device_node* sub_node;
  214. for (; node != 0;node = node->sibling) {
  215. const unsigned int *class_code;
  216. if (filter(node, data))
  217. return node;
  218. /* For PCI<->PCI bridges or CardBus bridges, we go down
  219. * Note: some OFs create a parent node "multifunc-device" as
  220. * a fake root for all functions of a multi-function device,
  221. * we go down them as well.
  222. */
  223. class_code = of_get_property(node, "class-code", NULL);
  224. if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
  225. (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
  226. strcmp(node->name, "multifunc-device"))
  227. continue;
  228. sub_node = scan_OF_pci_childs(node->child, filter, data);
  229. if (sub_node)
  230. return sub_node;
  231. }
  232. return NULL;
  233. }
  234. static struct device_node *scan_OF_for_pci_dev(struct device_node *parent,
  235. unsigned int devfn)
  236. {
  237. struct device_node *np = NULL;
  238. const u32 *reg;
  239. unsigned int psize;
  240. while ((np = of_get_next_child(parent, np)) != NULL) {
  241. reg = of_get_property(np, "reg", &psize);
  242. if (reg == NULL || psize < 4)
  243. continue;
  244. if (((reg[0] >> 8) & 0xff) == devfn)
  245. return np;
  246. }
  247. return NULL;
  248. }
  249. static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
  250. {
  251. struct device_node *parent, *np;
  252. /* Are we a root bus ? */
  253. if (bus->self == NULL || bus->parent == NULL) {
  254. struct pci_controller *hose = pci_bus_to_host(bus);
  255. if (hose == NULL)
  256. return NULL;
  257. return of_node_get(hose->dn);
  258. }
  259. /* not a root bus, we need to get our parent */
  260. parent = scan_OF_for_pci_bus(bus->parent);
  261. if (parent == NULL)
  262. return NULL;
  263. /* now iterate for children for a match */
  264. np = scan_OF_for_pci_dev(parent, bus->self->devfn);
  265. of_node_put(parent);
  266. return np;
  267. }
  268. /*
  269. * Scans the OF tree for a device node matching a PCI device
  270. */
  271. struct device_node *
  272. pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
  273. {
  274. struct device_node *parent, *np;
  275. if (!have_of)
  276. return NULL;
  277. DBG("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn);
  278. parent = scan_OF_for_pci_bus(bus);
  279. if (parent == NULL)
  280. return NULL;
  281. DBG(" parent is %s\n", parent ? parent->full_name : "<NULL>");
  282. np = scan_OF_for_pci_dev(parent, devfn);
  283. of_node_put(parent);
  284. DBG(" result is %s\n", np ? np->full_name : "<NULL>");
  285. /* XXX most callers don't release the returned node
  286. * mostly because ppc64 doesn't increase the refcount,
  287. * we need to fix that.
  288. */
  289. return np;
  290. }
  291. EXPORT_SYMBOL(pci_busdev_to_OF_node);
  292. struct device_node*
  293. pci_device_to_OF_node(struct pci_dev *dev)
  294. {
  295. return pci_busdev_to_OF_node(dev->bus, dev->devfn);
  296. }
  297. EXPORT_SYMBOL(pci_device_to_OF_node);
  298. static int
  299. find_OF_pci_device_filter(struct device_node* node, void* data)
  300. {
  301. return ((void *)node == data);
  302. }
  303. /*
  304. * Returns the PCI device matching a given OF node
  305. */
  306. int
  307. pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
  308. {
  309. const unsigned int *reg;
  310. struct pci_controller* hose;
  311. struct pci_dev* dev = NULL;
  312. if (!have_of)
  313. return -ENODEV;
  314. /* Make sure it's really a PCI device */
  315. hose = pci_find_hose_for_OF_device(node);
  316. if (!hose || !hose->dn)
  317. return -ENODEV;
  318. if (!scan_OF_pci_childs(hose->dn->child,
  319. find_OF_pci_device_filter, (void *)node))
  320. return -ENODEV;
  321. reg = of_get_property(node, "reg", NULL);
  322. if (!reg)
  323. return -ENODEV;
  324. *bus = (reg[0] >> 16) & 0xff;
  325. *devfn = ((reg[0] >> 8) & 0xff);
  326. /* Ok, here we need some tweak. If we have already renumbered
  327. * all busses, we can't rely on the OF bus number any more.
  328. * the pci_to_OF_bus_map is not enough as several PCI busses
  329. * may match the same OF bus number.
  330. */
  331. if (!pci_to_OF_bus_map)
  332. return 0;
  333. for_each_pci_dev(dev)
  334. if (pci_to_OF_bus_map[dev->bus->number] == *bus &&
  335. dev->devfn == *devfn) {
  336. *bus = dev->bus->number;
  337. pci_dev_put(dev);
  338. return 0;
  339. }
  340. return -ENODEV;
  341. }
  342. EXPORT_SYMBOL(pci_device_from_OF_node);
  343. /* We create the "pci-OF-bus-map" property now so it appears in the
  344. * /proc device tree
  345. */
  346. void __init
  347. pci_create_OF_bus_map(void)
  348. {
  349. struct property* of_prop;
  350. struct device_node *dn;
  351. of_prop = (struct property*) alloc_bootmem(sizeof(struct property) + 256);
  352. if (!of_prop)
  353. return;
  354. dn = of_find_node_by_path("/");
  355. if (dn) {
  356. memset(of_prop, -1, sizeof(struct property) + 256);
  357. of_prop->name = "pci-OF-bus-map";
  358. of_prop->length = 256;
  359. of_prop->value = &of_prop[1];
  360. prom_add_property(dn, of_prop);
  361. of_node_put(dn);
  362. }
  363. }
  364. #else /* CONFIG_PPC_OF */
  365. void pcibios_make_OF_bus_map(void)
  366. {
  367. }
  368. #endif /* CONFIG_PPC_OF */
  369. static int __init pcibios_init(void)
  370. {
  371. struct pci_controller *hose, *tmp;
  372. struct pci_bus *bus;
  373. int next_busno = 0;
  374. printk(KERN_INFO "PCI: Probing PCI hardware\n");
  375. if (ppc_pci_flags & PPC_PCI_REASSIGN_ALL_BUS)
  376. pci_assign_all_buses = 1;
  377. /* Scan all of the recorded PCI controllers. */
  378. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  379. if (pci_assign_all_buses)
  380. hose->first_busno = next_busno;
  381. hose->last_busno = 0xff;
  382. bus = pci_scan_bus_parented(hose->parent, hose->first_busno,
  383. hose->ops, hose);
  384. if (bus)
  385. pci_bus_add_devices(bus);
  386. hose->last_busno = bus->subordinate;
  387. if (pci_assign_all_buses || next_busno <= hose->last_busno)
  388. next_busno = hose->last_busno + pcibios_assign_bus_offset;
  389. }
  390. pci_bus_count = next_busno;
  391. /* OpenFirmware based machines need a map of OF bus
  392. * numbers vs. kernel bus numbers since we may have to
  393. * remap them.
  394. */
  395. if (pci_assign_all_buses && have_of)
  396. pcibios_make_OF_bus_map();
  397. /* Call common code to handle resource allocation */
  398. pcibios_resource_survey();
  399. /* Call machine dependent post-init code */
  400. if (ppc_md.pcibios_after_init)
  401. ppc_md.pcibios_after_init();
  402. return 0;
  403. }
  404. subsys_initcall(pcibios_init);
  405. void __devinit pcibios_do_bus_setup(struct pci_bus *bus)
  406. {
  407. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  408. unsigned long io_offset;
  409. struct resource *res;
  410. int i;
  411. /* Hookup PHB resources */
  412. io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
  413. if (bus->parent == NULL) {
  414. /* This is a host bridge - fill in its resources */
  415. hose->bus = bus;
  416. bus->resource[0] = res = &hose->io_resource;
  417. if (!res->flags) {
  418. if (io_offset)
  419. printk(KERN_ERR "I/O resource not set for host"
  420. " bridge %d\n", hose->global_number);
  421. res->start = 0;
  422. res->end = IO_SPACE_LIMIT;
  423. res->flags = IORESOURCE_IO;
  424. }
  425. res->start = (res->start + io_offset) & 0xffffffffu;
  426. res->end = (res->end + io_offset) & 0xffffffffu;
  427. for (i = 0; i < 3; ++i) {
  428. res = &hose->mem_resources[i];
  429. if (!res->flags) {
  430. if (i > 0)
  431. continue;
  432. printk(KERN_ERR "Memory resource not set for "
  433. "host bridge %d\n", hose->global_number);
  434. res->start = hose->pci_mem_offset;
  435. res->end = ~0U;
  436. res->flags = IORESOURCE_MEM;
  437. }
  438. bus->resource[i+1] = res;
  439. }
  440. }
  441. }
  442. /* the next one is stolen from the alpha port... */
  443. void __init
  444. pcibios_update_irq(struct pci_dev *dev, int irq)
  445. {
  446. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  447. /* XXX FIXME - update OF device tree node interrupt property */
  448. }
  449. static struct pci_controller*
  450. pci_bus_to_hose(int bus)
  451. {
  452. struct pci_controller *hose, *tmp;
  453. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  454. if (bus >= hose->first_busno && bus <= hose->last_busno)
  455. return hose;
  456. return NULL;
  457. }
  458. /* Provide information on locations of various I/O regions in physical
  459. * memory. Do this on a per-card basis so that we choose the right
  460. * root bridge.
  461. * Note that the returned IO or memory base is a physical address
  462. */
  463. long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
  464. {
  465. struct pci_controller* hose;
  466. long result = -EOPNOTSUPP;
  467. hose = pci_bus_to_hose(bus);
  468. if (!hose)
  469. return -ENODEV;
  470. switch (which) {
  471. case IOBASE_BRIDGE_NUMBER:
  472. return (long)hose->first_busno;
  473. case IOBASE_MEMORY:
  474. return (long)hose->pci_mem_offset;
  475. case IOBASE_IO:
  476. return (long)hose->io_base_phys;
  477. case IOBASE_ISA_IO:
  478. return (long)isa_io_base;
  479. case IOBASE_ISA_MEM:
  480. return (long)isa_mem_base;
  481. }
  482. return result;
  483. }
  484. unsigned long pci_address_to_pio(phys_addr_t address)
  485. {
  486. struct pci_controller *hose, *tmp;
  487. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  488. unsigned int size = hose->io_resource.end -
  489. hose->io_resource.start + 1;
  490. if (address >= hose->io_base_phys &&
  491. address < (hose->io_base_phys + size)) {
  492. unsigned long base =
  493. (unsigned long)hose->io_base_virt - _IO_BASE;
  494. return base + (address - hose->io_base_phys);
  495. }
  496. }
  497. return (unsigned int)-1;
  498. }
  499. EXPORT_SYMBOL(pci_address_to_pio);
  500. /*
  501. * Null PCI config access functions, for the case when we can't
  502. * find a hose.
  503. */
  504. #define NULL_PCI_OP(rw, size, type) \
  505. static int \
  506. null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
  507. { \
  508. return PCIBIOS_DEVICE_NOT_FOUND; \
  509. }
  510. static int
  511. null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  512. int len, u32 *val)
  513. {
  514. return PCIBIOS_DEVICE_NOT_FOUND;
  515. }
  516. static int
  517. null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  518. int len, u32 val)
  519. {
  520. return PCIBIOS_DEVICE_NOT_FOUND;
  521. }
  522. static struct pci_ops null_pci_ops =
  523. {
  524. .read = null_read_config,
  525. .write = null_write_config,
  526. };
  527. /*
  528. * These functions are used early on before PCI scanning is done
  529. * and all of the pci_dev and pci_bus structures have been created.
  530. */
  531. static struct pci_bus *
  532. fake_pci_bus(struct pci_controller *hose, int busnr)
  533. {
  534. static struct pci_bus bus;
  535. if (hose == 0) {
  536. hose = pci_bus_to_hose(busnr);
  537. if (hose == 0)
  538. printk(KERN_ERR "Can't find hose for PCI bus %d!\n", busnr);
  539. }
  540. bus.number = busnr;
  541. bus.sysdata = hose;
  542. bus.ops = hose? hose->ops: &null_pci_ops;
  543. return &bus;
  544. }
  545. #define EARLY_PCI_OP(rw, size, type) \
  546. int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
  547. int devfn, int offset, type value) \
  548. { \
  549. return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
  550. devfn, offset, value); \
  551. }
  552. EARLY_PCI_OP(read, byte, u8 *)
  553. EARLY_PCI_OP(read, word, u16 *)
  554. EARLY_PCI_OP(read, dword, u32 *)
  555. EARLY_PCI_OP(write, byte, u8)
  556. EARLY_PCI_OP(write, word, u16)
  557. EARLY_PCI_OP(write, dword, u32)
  558. extern int pci_bus_find_capability (struct pci_bus *bus, unsigned int devfn, int cap);
  559. int early_find_capability(struct pci_controller *hose, int bus, int devfn,
  560. int cap)
  561. {
  562. return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap);
  563. }