pci_64.c 18 KB

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