pci_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. dev_set_name(&dev->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;
  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. for_each_child_of_node(node, child) {
  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. DBG("PCI: Scanning PHB %s\n", node ? node->full_name : "<NO NAME>");
  307. /* Create an empty bus for the toplevel */
  308. bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, node);
  309. if (bus == NULL) {
  310. printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
  311. hose->global_number);
  312. return;
  313. }
  314. bus->secondary = hose->first_busno;
  315. hose->bus = bus;
  316. /* Get some IO space for the new PHB */
  317. pcibios_map_io_space(bus);
  318. /* Wire up PHB bus resources */
  319. DBG("PCI: PHB IO resource = %016lx-%016lx [%lx]\n",
  320. hose->io_resource.start, hose->io_resource.end,
  321. hose->io_resource.flags);
  322. bus->resource[0] = &hose->io_resource;
  323. for (i = 0; i < 3; ++i) {
  324. DBG("PCI: PHB MEM resource %d = %016lx-%016lx [%lx]\n", i,
  325. hose->mem_resources[i].start,
  326. hose->mem_resources[i].end,
  327. hose->mem_resources[i].flags);
  328. bus->resource[i+1] = &hose->mem_resources[i];
  329. }
  330. DBG("PCI: PHB MEM offset = %016lx\n", hose->pci_mem_offset);
  331. DBG("PCI: PHB IO offset = %08lx\n",
  332. (unsigned long)hose->io_base_virt - _IO_BASE);
  333. /* Get probe mode and perform scan */
  334. mode = PCI_PROBE_NORMAL;
  335. if (node && ppc_md.pci_probe_mode)
  336. mode = ppc_md.pci_probe_mode(bus);
  337. DBG(" probe mode: %d\n", mode);
  338. if (mode == PCI_PROBE_DEVTREE) {
  339. bus->subordinate = hose->last_busno;
  340. of_scan_bus(node, bus);
  341. }
  342. if (mode == PCI_PROBE_NORMAL)
  343. hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
  344. }
  345. static int __init pcibios_init(void)
  346. {
  347. struct pci_controller *hose, *tmp;
  348. printk(KERN_INFO "PCI: Probing PCI hardware\n");
  349. /* For now, override phys_mem_access_prot. If we need it,
  350. * later, we may move that initialization to each ppc_md
  351. */
  352. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  353. if (pci_probe_only)
  354. ppc_pci_flags |= PPC_PCI_PROBE_ONLY;
  355. /* Scan all of the recorded PCI controllers. */
  356. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  357. scan_phb(hose);
  358. pci_bus_add_devices(hose->bus);
  359. }
  360. /* Call common code to handle resource allocation */
  361. pcibios_resource_survey();
  362. printk(KERN_DEBUG "PCI: Probing PCI hardware done\n");
  363. return 0;
  364. }
  365. subsys_initcall(pcibios_init);
  366. #ifdef CONFIG_HOTPLUG
  367. int pcibios_unmap_io_space(struct pci_bus *bus)
  368. {
  369. struct pci_controller *hose;
  370. WARN_ON(bus == NULL);
  371. /* If this is not a PHB, we only flush the hash table over
  372. * the area mapped by this bridge. We don't play with the PTE
  373. * mappings since we might have to deal with sub-page alignemnts
  374. * so flushing the hash table is the only sane way to make sure
  375. * that no hash entries are covering that removed bridge area
  376. * while still allowing other busses overlapping those pages
  377. */
  378. if (bus->self) {
  379. struct resource *res = bus->resource[0];
  380. DBG("IO unmapping for PCI-PCI bridge %s\n",
  381. pci_name(bus->self));
  382. __flush_hash_table_range(&init_mm, res->start + _IO_BASE,
  383. res->end - res->start + 1);
  384. return 0;
  385. }
  386. /* Get the host bridge */
  387. hose = pci_bus_to_host(bus);
  388. /* Check if we have IOs allocated */
  389. if (hose->io_base_alloc == 0)
  390. return 0;
  391. DBG("IO unmapping for PHB %s\n", hose->dn->full_name);
  392. DBG(" alloc=0x%p\n", hose->io_base_alloc);
  393. /* This is a PHB, we fully unmap the IO area */
  394. vunmap(hose->io_base_alloc);
  395. return 0;
  396. }
  397. EXPORT_SYMBOL_GPL(pcibios_unmap_io_space);
  398. #endif /* CONFIG_HOTPLUG */
  399. int __devinit pcibios_map_io_space(struct pci_bus *bus)
  400. {
  401. struct vm_struct *area;
  402. unsigned long phys_page;
  403. unsigned long size_page;
  404. unsigned long io_virt_offset;
  405. struct pci_controller *hose;
  406. WARN_ON(bus == NULL);
  407. /* If this not a PHB, nothing to do, page tables still exist and
  408. * thus HPTEs will be faulted in when needed
  409. */
  410. if (bus->self) {
  411. DBG("IO mapping for PCI-PCI bridge %s\n",
  412. pci_name(bus->self));
  413. DBG(" virt=0x%016lx...0x%016lx\n",
  414. bus->resource[0]->start + _IO_BASE,
  415. bus->resource[0]->end + _IO_BASE);
  416. return 0;
  417. }
  418. /* Get the host bridge */
  419. hose = pci_bus_to_host(bus);
  420. phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
  421. size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE);
  422. /* Make sure IO area address is clear */
  423. hose->io_base_alloc = NULL;
  424. /* If there's no IO to map on that bus, get away too */
  425. if (hose->pci_io_size == 0 || hose->io_base_phys == 0)
  426. return 0;
  427. /* Let's allocate some IO space for that guy. We don't pass
  428. * VM_IOREMAP because we don't care about alignment tricks that
  429. * the core does in that case. Maybe we should due to stupid card
  430. * with incomplete address decoding but I'd rather not deal with
  431. * those outside of the reserved 64K legacy region.
  432. */
  433. area = __get_vm_area(size_page, 0, PHB_IO_BASE, PHB_IO_END);
  434. if (area == NULL)
  435. return -ENOMEM;
  436. hose->io_base_alloc = area->addr;
  437. hose->io_base_virt = (void __iomem *)(area->addr +
  438. hose->io_base_phys - phys_page);
  439. DBG("IO mapping for PHB %s\n", hose->dn->full_name);
  440. DBG(" phys=0x%016lx, virt=0x%p (alloc=0x%p)\n",
  441. hose->io_base_phys, hose->io_base_virt, hose->io_base_alloc);
  442. DBG(" size=0x%016lx (alloc=0x%016lx)\n",
  443. hose->pci_io_size, size_page);
  444. /* Establish the mapping */
  445. if (__ioremap_at(phys_page, area->addr, size_page,
  446. _PAGE_NO_CACHE | _PAGE_GUARDED) == NULL)
  447. return -ENOMEM;
  448. /* Fixup hose IO resource */
  449. io_virt_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  450. hose->io_resource.start += io_virt_offset;
  451. hose->io_resource.end += io_virt_offset;
  452. DBG(" hose->io_resource=0x%016lx...0x%016lx\n",
  453. hose->io_resource.start, hose->io_resource.end);
  454. return 0;
  455. }
  456. EXPORT_SYMBOL_GPL(pcibios_map_io_space);
  457. void __devinit pcibios_setup_new_device(struct pci_dev *dev)
  458. {
  459. struct dev_archdata *sd = &dev->dev.archdata;
  460. sd->of_node = pci_device_to_OF_node(dev);
  461. DBG("PCI: device %s OF node: %s\n", pci_name(dev),
  462. sd->of_node ? sd->of_node->full_name : "<none>");
  463. sd->dma_ops = pci_dma_ops;
  464. #ifdef CONFIG_NUMA
  465. sd->numa_node = pcibus_to_node(dev->bus);
  466. #else
  467. sd->numa_node = -1;
  468. #endif
  469. if (ppc_md.pci_dma_dev_setup)
  470. ppc_md.pci_dma_dev_setup(dev);
  471. }
  472. EXPORT_SYMBOL(pcibios_setup_new_device);
  473. void __devinit pcibios_do_bus_setup(struct pci_bus *bus)
  474. {
  475. struct pci_dev *dev;
  476. if (ppc_md.pci_dma_bus_setup)
  477. ppc_md.pci_dma_bus_setup(bus);
  478. list_for_each_entry(dev, &bus->devices, bus_list)
  479. pcibios_setup_new_device(dev);
  480. }
  481. unsigned long pci_address_to_pio(phys_addr_t address)
  482. {
  483. struct pci_controller *hose, *tmp;
  484. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  485. if (address >= hose->io_base_phys &&
  486. address < (hose->io_base_phys + hose->pci_io_size)) {
  487. unsigned long base =
  488. (unsigned long)hose->io_base_virt - _IO_BASE;
  489. return base + (address - hose->io_base_phys);
  490. }
  491. }
  492. return (unsigned int)-1;
  493. }
  494. EXPORT_SYMBOL_GPL(pci_address_to_pio);
  495. #define IOBASE_BRIDGE_NUMBER 0
  496. #define IOBASE_MEMORY 1
  497. #define IOBASE_IO 2
  498. #define IOBASE_ISA_IO 3
  499. #define IOBASE_ISA_MEM 4
  500. long sys_pciconfig_iobase(long which, unsigned long in_bus,
  501. unsigned long in_devfn)
  502. {
  503. struct pci_controller* hose;
  504. struct list_head *ln;
  505. struct pci_bus *bus = NULL;
  506. struct device_node *hose_node;
  507. /* Argh ! Please forgive me for that hack, but that's the
  508. * simplest way to get existing XFree to not lockup on some
  509. * G5 machines... So when something asks for bus 0 io base
  510. * (bus 0 is HT root), we return the AGP one instead.
  511. */
  512. if (machine_is_compatible("MacRISC4"))
  513. if (in_bus == 0)
  514. in_bus = 0xf0;
  515. /* That syscall isn't quite compatible with PCI domains, but it's
  516. * used on pre-domains setup. We return the first match
  517. */
  518. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  519. bus = pci_bus_b(ln);
  520. if (in_bus >= bus->number && in_bus <= bus->subordinate)
  521. break;
  522. bus = NULL;
  523. }
  524. if (bus == NULL || bus->sysdata == NULL)
  525. return -ENODEV;
  526. hose_node = (struct device_node *)bus->sysdata;
  527. hose = PCI_DN(hose_node)->phb;
  528. switch (which) {
  529. case IOBASE_BRIDGE_NUMBER:
  530. return (long)hose->first_busno;
  531. case IOBASE_MEMORY:
  532. return (long)hose->pci_mem_offset;
  533. case IOBASE_IO:
  534. return (long)hose->io_base_phys;
  535. case IOBASE_ISA_IO:
  536. return (long)isa_io_base;
  537. case IOBASE_ISA_MEM:
  538. return -EINVAL;
  539. }
  540. return -EOPNOTSUPP;
  541. }
  542. #ifdef CONFIG_NUMA
  543. int pcibus_to_node(struct pci_bus *bus)
  544. {
  545. struct pci_controller *phb = pci_bus_to_host(bus);
  546. return phb->node;
  547. }
  548. EXPORT_SYMBOL(pcibus_to_node);
  549. #endif