pci_32.c 17 KB

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