pci_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Port for PPC64 David Engebretsen, IBM Corp.
  3. * Contains common pci routines for ppc64 platform, pSeries and iSeries brands.
  4. *
  5. * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
  6. * Rework, based on alpha PCI code.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #undef DEBUG
  14. #include <linux/kernel.h>
  15. #include <linux/pci.h>
  16. #include <linux/string.h>
  17. #include <linux/init.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/mm.h>
  20. #include <linux/list.h>
  21. #include <linux/syscalls.h>
  22. #include <linux/irq.h>
  23. #include <linux/vmalloc.h>
  24. #include <asm/processor.h>
  25. #include <asm/io.h>
  26. #include <asm/prom.h>
  27. #include <asm/pci-bridge.h>
  28. #include <asm/byteorder.h>
  29. #include <asm/machdep.h>
  30. #include <asm/ppc-pci.h>
  31. #ifdef DEBUG
  32. #include <asm/udbg.h>
  33. #define DBG(fmt...) printk(fmt)
  34. #else
  35. #define DBG(fmt...)
  36. #endif
  37. unsigned long pci_probe_only = 1;
  38. /* pci_io_base -- the base address from which io bars are offsets.
  39. * This is the lowest I/O base address (so bar values are always positive),
  40. * and it *must* be the start of ISA space if an ISA bus exists because
  41. * ISA drivers use hard coded offsets. If no ISA bus exists nothing
  42. * is mapped on the first 64K of IO space
  43. */
  44. unsigned long pci_io_base = ISA_IO_BASE;
  45. EXPORT_SYMBOL(pci_io_base);
  46. LIST_HEAD(hose_list);
  47. static struct dma_mapping_ops *pci_dma_ops;
  48. void set_pci_dma_ops(struct dma_mapping_ops *dma_ops)
  49. {
  50. pci_dma_ops = dma_ops;
  51. }
  52. struct dma_mapping_ops *get_pci_dma_ops(void)
  53. {
  54. return pci_dma_ops;
  55. }
  56. EXPORT_SYMBOL(get_pci_dma_ops);
  57. int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
  58. {
  59. return dma_set_mask(&dev->dev, mask);
  60. }
  61. int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
  62. {
  63. int rc;
  64. rc = dma_set_mask(&dev->dev, mask);
  65. dev->dev.coherent_dma_mask = dev->dma_mask;
  66. return rc;
  67. }
  68. static void fixup_broken_pcnet32(struct pci_dev* dev)
  69. {
  70. if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
  71. dev->vendor = PCI_VENDOR_ID_AMD;
  72. pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
  73. }
  74. }
  75. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32);
  76. static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
  77. {
  78. const u32 *prop;
  79. int len;
  80. prop = of_get_property(np, name, &len);
  81. if (prop && len >= 4)
  82. return *prop;
  83. return def;
  84. }
  85. static unsigned int pci_parse_of_flags(u32 addr0)
  86. {
  87. unsigned int flags = 0;
  88. if (addr0 & 0x02000000) {
  89. flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY;
  90. flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64;
  91. flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M;
  92. if (addr0 & 0x40000000)
  93. flags |= IORESOURCE_PREFETCH
  94. | PCI_BASE_ADDRESS_MEM_PREFETCH;
  95. } else if (addr0 & 0x01000000)
  96. flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
  97. return flags;
  98. }
  99. static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev)
  100. {
  101. u64 base, size;
  102. unsigned int flags;
  103. struct resource *res;
  104. const u32 *addrs;
  105. u32 i;
  106. int proplen;
  107. addrs = of_get_property(node, "assigned-addresses", &proplen);
  108. if (!addrs)
  109. return;
  110. DBG(" parse addresses (%d bytes) @ %p\n", proplen, addrs);
  111. for (; proplen >= 20; proplen -= 20, addrs += 5) {
  112. flags = pci_parse_of_flags(addrs[0]);
  113. if (!flags)
  114. continue;
  115. base = of_read_number(&addrs[1], 2);
  116. size = of_read_number(&addrs[3], 2);
  117. if (!size)
  118. continue;
  119. i = addrs[0] & 0xff;
  120. DBG(" base: %llx, size: %llx, i: %x\n",
  121. (unsigned long long)base, (unsigned long long)size, i);
  122. if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
  123. res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
  124. } else if (i == dev->rom_base_reg) {
  125. res = &dev->resource[PCI_ROM_RESOURCE];
  126. flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
  127. } else {
  128. printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
  129. continue;
  130. }
  131. res->start = base;
  132. res->end = base + size - 1;
  133. res->flags = flags;
  134. res->name = pci_name(dev);
  135. }
  136. }
  137. struct pci_dev *of_create_pci_dev(struct device_node *node,
  138. struct pci_bus *bus, int devfn)
  139. {
  140. struct pci_dev *dev;
  141. const char *type;
  142. dev = alloc_pci_dev();
  143. if (!dev)
  144. return NULL;
  145. type = of_get_property(node, "device_type", NULL);
  146. if (type == NULL)
  147. type = "";
  148. DBG(" create device, devfn: %x, type: %s\n", devfn, type);
  149. dev->bus = bus;
  150. dev->sysdata = node;
  151. dev->dev.parent = bus->bridge;
  152. dev->dev.bus = &pci_bus_type;
  153. dev->devfn = devfn;
  154. dev->multifunction = 0; /* maybe a lie? */
  155. dev->vendor = get_int_prop(node, "vendor-id", 0xffff);
  156. dev->device = get_int_prop(node, "device-id", 0xffff);
  157. dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0);
  158. dev->subsystem_device = get_int_prop(node, "subsystem-id", 0);
  159. dev->cfg_size = pci_cfg_space_size(dev);
  160. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  161. dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  162. dev->class = get_int_prop(node, "class-code", 0);
  163. dev->revision = get_int_prop(node, "revision-id", 0);
  164. DBG(" class: 0x%x\n", dev->class);
  165. DBG(" revision: 0x%x\n", dev->revision);
  166. dev->current_state = 4; /* unknown power state */
  167. dev->error_state = pci_channel_io_normal;
  168. dev->dma_mask = 0xffffffff;
  169. if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
  170. /* a PCI-PCI bridge */
  171. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  172. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  173. } else if (!strcmp(type, "cardbus")) {
  174. dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
  175. } else {
  176. dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
  177. dev->rom_base_reg = PCI_ROM_ADDRESS;
  178. /* Maybe do a default OF mapping here */
  179. dev->irq = NO_IRQ;
  180. }
  181. pci_parse_of_addrs(node, dev);
  182. DBG(" adding to system ...\n");
  183. pci_device_add(dev, bus);
  184. return dev;
  185. }
  186. EXPORT_SYMBOL(of_create_pci_dev);
  187. void __devinit of_scan_bus(struct device_node *node,
  188. struct pci_bus *bus)
  189. {
  190. struct device_node *child = NULL;
  191. const u32 *reg;
  192. int reglen, devfn;
  193. struct pci_dev *dev;
  194. DBG("of_scan_bus(%s) bus no %d... \n", node->full_name, bus->number);
  195. /* Scan direct children */
  196. while ((child = of_get_next_child(node, child)) != NULL) {
  197. DBG(" * %s\n", child->full_name);
  198. reg = of_get_property(child, "reg", &reglen);
  199. if (reg == NULL || reglen < 20)
  200. continue;
  201. devfn = (reg[0] >> 8) & 0xff;
  202. /* create a new pci_dev for this device */
  203. dev = of_create_pci_dev(child, bus, devfn);
  204. if (!dev)
  205. continue;
  206. DBG(" dev header type: %x\n", dev->hdr_type);
  207. }
  208. /* Ally all fixups */
  209. pcibios_fixup_of_probed_bus(bus);
  210. /* Now scan child busses */
  211. list_for_each_entry(dev, &bus->devices, bus_list) {
  212. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  213. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
  214. struct device_node *child = pci_device_to_OF_node(dev);
  215. if (dev)
  216. of_scan_pci_bridge(child, dev);
  217. }
  218. }
  219. }
  220. EXPORT_SYMBOL(of_scan_bus);
  221. void __devinit of_scan_pci_bridge(struct device_node *node,
  222. struct pci_dev *dev)
  223. {
  224. struct pci_bus *bus;
  225. const u32 *busrange, *ranges;
  226. int len, i, mode;
  227. struct resource *res;
  228. unsigned int flags;
  229. u64 size;
  230. DBG("of_scan_pci_bridge(%s)\n", node->full_name);
  231. /* parse bus-range property */
  232. busrange = of_get_property(node, "bus-range", &len);
  233. if (busrange == NULL || len != 8) {
  234. printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %s\n",
  235. node->full_name);
  236. return;
  237. }
  238. ranges = of_get_property(node, "ranges", &len);
  239. if (ranges == NULL) {
  240. printk(KERN_DEBUG "Can't get ranges for PCI-PCI bridge %s\n",
  241. node->full_name);
  242. return;
  243. }
  244. bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
  245. if (!bus) {
  246. printk(KERN_ERR "Failed to create pci bus for %s\n",
  247. node->full_name);
  248. return;
  249. }
  250. bus->primary = dev->bus->number;
  251. bus->subordinate = busrange[1];
  252. bus->bridge_ctl = 0;
  253. bus->sysdata = node;
  254. /* parse ranges property */
  255. /* PCI #address-cells == 3 and #size-cells == 2 always */
  256. res = &dev->resource[PCI_BRIDGE_RESOURCES];
  257. for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
  258. res->flags = 0;
  259. bus->resource[i] = res;
  260. ++res;
  261. }
  262. i = 1;
  263. for (; len >= 32; len -= 32, ranges += 8) {
  264. flags = pci_parse_of_flags(ranges[0]);
  265. size = of_read_number(&ranges[6], 2);
  266. if (flags == 0 || size == 0)
  267. continue;
  268. if (flags & IORESOURCE_IO) {
  269. res = bus->resource[0];
  270. if (res->flags) {
  271. printk(KERN_ERR "PCI: ignoring extra I/O range"
  272. " for bridge %s\n", node->full_name);
  273. continue;
  274. }
  275. } else {
  276. if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
  277. printk(KERN_ERR "PCI: too many memory ranges"
  278. " for bridge %s\n", node->full_name);
  279. continue;
  280. }
  281. res = bus->resource[i];
  282. ++i;
  283. }
  284. res->start = of_read_number(&ranges[1], 2);
  285. res->end = res->start + size - 1;
  286. res->flags = flags;
  287. }
  288. sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
  289. bus->number);
  290. DBG(" bus name: %s\n", bus->name);
  291. mode = PCI_PROBE_NORMAL;
  292. if (ppc_md.pci_probe_mode)
  293. mode = ppc_md.pci_probe_mode(bus);
  294. DBG(" probe mode: %d\n", mode);
  295. if (mode == PCI_PROBE_DEVTREE)
  296. of_scan_bus(node, bus);
  297. else if (mode == PCI_PROBE_NORMAL)
  298. pci_scan_child_bus(bus);
  299. }
  300. EXPORT_SYMBOL(of_scan_pci_bridge);
  301. void __devinit scan_phb(struct pci_controller *hose)
  302. {
  303. struct pci_bus *bus;
  304. struct device_node *node = hose->dn;
  305. int i, mode;
  306. struct resource *res;
  307. DBG("PCI: Scanning PHB %s\n", node ? node->full_name : "<NO NAME>");
  308. /* Create an empty bus for the toplevel */
  309. bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, node);
  310. if (bus == NULL) {
  311. printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
  312. hose->global_number);
  313. return;
  314. }
  315. bus->secondary = hose->first_busno;
  316. hose->bus = bus;
  317. /* Get some IO space for the new PHB */
  318. pcibios_map_io_space(bus);
  319. /* Wire up PHB bus resources */
  320. if (hose->io_resource.flags) {
  321. DBG("PCI: PHB IO resource = %016lx-%016lx [%lx]\n",
  322. hose->io_resource.start, hose->io_resource.end,
  323. hose->io_resource.flags);
  324. bus->resource[0] = res = &hose->io_resource;
  325. }
  326. for (i = 0; i < 3; ++i) {
  327. DBG("PCI: PHB MEM resource %d = %016lx-%016lx [%lx]\n", i,
  328. hose->mem_resources[i].start,
  329. hose->mem_resources[i].end,
  330. hose->mem_resources[i].flags);
  331. bus->resource[i+1] = &hose->mem_resources[i];
  332. }
  333. DBG("PCI: PHB MEM offset = %016lx\n", hose->pci_mem_offset);
  334. DBG("PCI: PHB IO offset = %08lx\n",
  335. (unsigned long)hose->io_base_virt - _IO_BASE);
  336. /* Get probe mode and perform scan */
  337. mode = PCI_PROBE_NORMAL;
  338. if (node && ppc_md.pci_probe_mode)
  339. mode = ppc_md.pci_probe_mode(bus);
  340. DBG(" probe mode: %d\n", mode);
  341. if (mode == PCI_PROBE_DEVTREE) {
  342. bus->subordinate = hose->last_busno;
  343. of_scan_bus(node, bus);
  344. }
  345. if (mode == PCI_PROBE_NORMAL)
  346. hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
  347. }
  348. static int __init pcibios_init(void)
  349. {
  350. struct pci_controller *hose, *tmp;
  351. printk(KERN_INFO "PCI: Probing PCI hardware\n");
  352. /* For now, override phys_mem_access_prot. If we need it,
  353. * later, we may move that initialization to each ppc_md
  354. */
  355. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  356. if (pci_probe_only)
  357. ppc_pci_flags |= PPC_PCI_PROBE_ONLY;
  358. /* Scan all of the recorded PCI controllers. */
  359. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  360. scan_phb(hose);
  361. pci_bus_add_devices(hose->bus);
  362. }
  363. /* Call common code to handle resource allocation */
  364. pcibios_resource_survey();
  365. printk(KERN_DEBUG "PCI: Probing PCI hardware done\n");
  366. return 0;
  367. }
  368. subsys_initcall(pcibios_init);
  369. #ifdef CONFIG_HOTPLUG
  370. int pcibios_unmap_io_space(struct pci_bus *bus)
  371. {
  372. struct pci_controller *hose;
  373. WARN_ON(bus == NULL);
  374. /* If this is not a PHB, we only flush the hash table over
  375. * the area mapped by this bridge. We don't play with the PTE
  376. * mappings since we might have to deal with sub-page alignemnts
  377. * so flushing the hash table is the only sane way to make sure
  378. * that no hash entries are covering that removed bridge area
  379. * while still allowing other busses overlapping those pages
  380. */
  381. if (bus->self) {
  382. struct resource *res = bus->resource[0];
  383. DBG("IO unmapping for PCI-PCI bridge %s\n",
  384. pci_name(bus->self));
  385. __flush_hash_table_range(&init_mm, res->start + _IO_BASE,
  386. res->end - res->start + 1);
  387. return 0;
  388. }
  389. /* Get the host bridge */
  390. hose = pci_bus_to_host(bus);
  391. /* Check if we have IOs allocated */
  392. if (hose->io_base_alloc == 0)
  393. return 0;
  394. DBG("IO unmapping for PHB %s\n", hose->dn->full_name);
  395. DBG(" alloc=0x%p\n", hose->io_base_alloc);
  396. /* This is a PHB, we fully unmap the IO area */
  397. vunmap(hose->io_base_alloc);
  398. return 0;
  399. }
  400. EXPORT_SYMBOL_GPL(pcibios_unmap_io_space);
  401. #endif /* CONFIG_HOTPLUG */
  402. int __devinit pcibios_map_io_space(struct pci_bus *bus)
  403. {
  404. struct vm_struct *area;
  405. unsigned long phys_page;
  406. unsigned long size_page;
  407. unsigned long io_virt_offset;
  408. struct pci_controller *hose;
  409. WARN_ON(bus == NULL);
  410. /* If this not a PHB, nothing to do, page tables still exist and
  411. * thus HPTEs will be faulted in when needed
  412. */
  413. if (bus->self) {
  414. DBG("IO mapping for PCI-PCI bridge %s\n",
  415. pci_name(bus->self));
  416. DBG(" virt=0x%016lx...0x%016lx\n",
  417. bus->resource[0]->start + _IO_BASE,
  418. bus->resource[0]->end + _IO_BASE);
  419. return 0;
  420. }
  421. /* Get the host bridge */
  422. hose = pci_bus_to_host(bus);
  423. phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
  424. size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE);
  425. /* Make sure IO area address is clear */
  426. hose->io_base_alloc = NULL;
  427. /* If there's no IO to map on that bus, get away too */
  428. if (hose->pci_io_size == 0 || hose->io_base_phys == 0)
  429. return 0;
  430. /* Let's allocate some IO space for that guy. We don't pass
  431. * VM_IOREMAP because we don't care about alignment tricks that
  432. * the core does in that case. Maybe we should due to stupid card
  433. * with incomplete address decoding but I'd rather not deal with
  434. * those outside of the reserved 64K legacy region.
  435. */
  436. area = __get_vm_area(size_page, 0, PHB_IO_BASE, PHB_IO_END);
  437. if (area == NULL)
  438. return -ENOMEM;
  439. hose->io_base_alloc = area->addr;
  440. hose->io_base_virt = (void __iomem *)(area->addr +
  441. hose->io_base_phys - phys_page);
  442. DBG("IO mapping for PHB %s\n", hose->dn->full_name);
  443. DBG(" phys=0x%016lx, virt=0x%p (alloc=0x%p)\n",
  444. hose->io_base_phys, hose->io_base_virt, hose->io_base_alloc);
  445. DBG(" size=0x%016lx (alloc=0x%016lx)\n",
  446. hose->pci_io_size, size_page);
  447. /* Establish the mapping */
  448. if (__ioremap_at(phys_page, area->addr, size_page,
  449. _PAGE_NO_CACHE | _PAGE_GUARDED) == NULL)
  450. return -ENOMEM;
  451. /* Fixup hose IO resource */
  452. io_virt_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  453. hose->io_resource.start += io_virt_offset;
  454. hose->io_resource.end += io_virt_offset;
  455. DBG(" hose->io_resource=0x%016lx...0x%016lx\n",
  456. hose->io_resource.start, hose->io_resource.end);
  457. return 0;
  458. }
  459. EXPORT_SYMBOL_GPL(pcibios_map_io_space);
  460. void __devinit pcibios_setup_new_device(struct pci_dev *dev)
  461. {
  462. struct dev_archdata *sd = &dev->dev.archdata;
  463. sd->of_node = pci_device_to_OF_node(dev);
  464. DBG("PCI: device %s OF node: %s\n", pci_name(dev),
  465. sd->of_node ? sd->of_node->full_name : "<none>");
  466. sd->dma_ops = pci_dma_ops;
  467. #ifdef CONFIG_NUMA
  468. sd->numa_node = pcibus_to_node(dev->bus);
  469. #else
  470. sd->numa_node = -1;
  471. #endif
  472. if (ppc_md.pci_dma_dev_setup)
  473. ppc_md.pci_dma_dev_setup(dev);
  474. }
  475. EXPORT_SYMBOL(pcibios_setup_new_device);
  476. void __devinit pcibios_do_bus_setup(struct pci_bus *bus)
  477. {
  478. struct pci_dev *dev;
  479. if (ppc_md.pci_dma_bus_setup)
  480. ppc_md.pci_dma_bus_setup(bus);
  481. list_for_each_entry(dev, &bus->devices, bus_list)
  482. pcibios_setup_new_device(dev);
  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. if (address >= hose->io_base_phys &&
  489. address < (hose->io_base_phys + hose->pci_io_size)) {
  490. unsigned long base =
  491. (unsigned long)hose->io_base_virt - _IO_BASE;
  492. return base + (address - hose->io_base_phys);
  493. }
  494. }
  495. return (unsigned int)-1;
  496. }
  497. EXPORT_SYMBOL_GPL(pci_address_to_pio);
  498. #define IOBASE_BRIDGE_NUMBER 0
  499. #define IOBASE_MEMORY 1
  500. #define IOBASE_IO 2
  501. #define IOBASE_ISA_IO 3
  502. #define IOBASE_ISA_MEM 4
  503. long sys_pciconfig_iobase(long which, unsigned long in_bus,
  504. unsigned long in_devfn)
  505. {
  506. struct pci_controller* hose;
  507. struct list_head *ln;
  508. struct pci_bus *bus = NULL;
  509. struct device_node *hose_node;
  510. /* Argh ! Please forgive me for that hack, but that's the
  511. * simplest way to get existing XFree to not lockup on some
  512. * G5 machines... So when something asks for bus 0 io base
  513. * (bus 0 is HT root), we return the AGP one instead.
  514. */
  515. if (machine_is_compatible("MacRISC4"))
  516. if (in_bus == 0)
  517. in_bus = 0xf0;
  518. /* That syscall isn't quite compatible with PCI domains, but it's
  519. * used on pre-domains setup. We return the first match
  520. */
  521. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  522. bus = pci_bus_b(ln);
  523. if (in_bus >= bus->number && in_bus <= bus->subordinate)
  524. break;
  525. bus = NULL;
  526. }
  527. if (bus == NULL || bus->sysdata == NULL)
  528. return -ENODEV;
  529. hose_node = (struct device_node *)bus->sysdata;
  530. hose = PCI_DN(hose_node)->phb;
  531. switch (which) {
  532. case IOBASE_BRIDGE_NUMBER:
  533. return (long)hose->first_busno;
  534. case IOBASE_MEMORY:
  535. return (long)hose->pci_mem_offset;
  536. case IOBASE_IO:
  537. return (long)hose->io_base_phys;
  538. case IOBASE_ISA_IO:
  539. return (long)isa_io_base;
  540. case IOBASE_ISA_MEM:
  541. return -EINVAL;
  542. }
  543. return -EOPNOTSUPP;
  544. }
  545. #ifdef CONFIG_NUMA
  546. int pcibus_to_node(struct pci_bus *bus)
  547. {
  548. struct pci_controller *phb = pci_bus_to_host(bus);
  549. return phb->node;
  550. }
  551. EXPORT_SYMBOL(pcibus_to_node);
  552. #endif