pci.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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/config.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/mm.h>
  21. #include <linux/list.h>
  22. #include <linux/syscalls.h>
  23. #include <asm/processor.h>
  24. #include <asm/io.h>
  25. #include <asm/prom.h>
  26. #include <asm/pci-bridge.h>
  27. #include <asm/byteorder.h>
  28. #include <asm/irq.h>
  29. #include <asm/machdep.h>
  30. #include <asm/udbg.h>
  31. #include "pci.h"
  32. #ifdef DEBUG
  33. #define DBG(fmt...) udbg_printf(fmt)
  34. #else
  35. #define DBG(fmt...)
  36. #endif
  37. unsigned long pci_probe_only = 1;
  38. unsigned long pci_assign_all_buses = 0;
  39. /*
  40. * legal IO pages under MAX_ISA_PORT. This is to ensure we don't touch
  41. * devices we don't have access to.
  42. */
  43. unsigned long io_page_mask;
  44. EXPORT_SYMBOL(io_page_mask);
  45. #ifdef CONFIG_PPC_MULTIPLATFORM
  46. static void fixup_resource(struct resource *res, struct pci_dev *dev);
  47. static void do_bus_setup(struct pci_bus *bus);
  48. #endif
  49. unsigned int pcibios_assign_all_busses(void)
  50. {
  51. return pci_assign_all_buses;
  52. }
  53. /* pci_io_base -- the base address from which io bars are offsets.
  54. * This is the lowest I/O base address (so bar values are always positive),
  55. * and it *must* be the start of ISA space if an ISA bus exists because
  56. * ISA drivers use hard coded offsets. If no ISA bus exists a dummy
  57. * page is mapped and isa_io_limit prevents access to it.
  58. */
  59. unsigned long isa_io_base; /* NULL if no ISA bus */
  60. EXPORT_SYMBOL(isa_io_base);
  61. unsigned long pci_io_base;
  62. EXPORT_SYMBOL(pci_io_base);
  63. void iSeries_pcibios_init(void);
  64. LIST_HEAD(hose_list);
  65. struct dma_mapping_ops pci_dma_ops;
  66. EXPORT_SYMBOL(pci_dma_ops);
  67. int global_phb_number; /* Global phb counter */
  68. /* Cached ISA bridge dev. */
  69. struct pci_dev *ppc64_isabridge_dev = NULL;
  70. static void fixup_broken_pcnet32(struct pci_dev* dev)
  71. {
  72. if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
  73. dev->vendor = PCI_VENDOR_ID_AMD;
  74. pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
  75. }
  76. }
  77. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32);
  78. void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  79. struct resource *res)
  80. {
  81. unsigned long offset = 0;
  82. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  83. if (!hose)
  84. return;
  85. if (res->flags & IORESOURCE_IO)
  86. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  87. if (res->flags & IORESOURCE_MEM)
  88. offset = hose->pci_mem_offset;
  89. region->start = res->start - offset;
  90. region->end = res->end - offset;
  91. }
  92. void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  93. struct pci_bus_region *region)
  94. {
  95. unsigned long offset = 0;
  96. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  97. if (!hose)
  98. return;
  99. if (res->flags & IORESOURCE_IO)
  100. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  101. if (res->flags & IORESOURCE_MEM)
  102. offset = hose->pci_mem_offset;
  103. res->start = region->start + offset;
  104. res->end = region->end + offset;
  105. }
  106. #ifdef CONFIG_HOTPLUG
  107. EXPORT_SYMBOL(pcibios_resource_to_bus);
  108. EXPORT_SYMBOL(pcibios_bus_to_resource);
  109. #endif
  110. /*
  111. * We need to avoid collisions with `mirrored' VGA ports
  112. * and other strange ISA hardware, so we always want the
  113. * addresses to be allocated in the 0x000-0x0ff region
  114. * modulo 0x400.
  115. *
  116. * Why? Because some silly external IO cards only decode
  117. * the low 10 bits of the IO address. The 0x00-0xff region
  118. * is reserved for motherboard devices that decode all 16
  119. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  120. * but we want to try to avoid allocating at 0x2900-0x2bff
  121. * which might have be mirrored at 0x0100-0x03ff..
  122. */
  123. void pcibios_align_resource(void *data, struct resource *res,
  124. unsigned long size, unsigned long align)
  125. {
  126. struct pci_dev *dev = data;
  127. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  128. unsigned long start = res->start;
  129. unsigned long alignto;
  130. if (res->flags & IORESOURCE_IO) {
  131. unsigned long offset = (unsigned long)hose->io_base_virt -
  132. pci_io_base;
  133. /* Make sure we start at our min on all hoses */
  134. if (start - offset < PCIBIOS_MIN_IO)
  135. start = PCIBIOS_MIN_IO + offset;
  136. /*
  137. * Put everything into 0x00-0xff region modulo 0x400
  138. */
  139. if (start & 0x300)
  140. start = (start + 0x3ff) & ~0x3ff;
  141. } else if (res->flags & IORESOURCE_MEM) {
  142. /* Make sure we start at our min on all hoses */
  143. if (start - hose->pci_mem_offset < PCIBIOS_MIN_MEM)
  144. start = PCIBIOS_MIN_MEM + hose->pci_mem_offset;
  145. /* Align to multiple of size of minimum base. */
  146. alignto = max(0x1000UL, align);
  147. start = ALIGN(start, alignto);
  148. }
  149. res->start = start;
  150. }
  151. static DEFINE_SPINLOCK(hose_spinlock);
  152. /*
  153. * pci_controller(phb) initialized common variables.
  154. */
  155. void __devinit pci_setup_pci_controller(struct pci_controller *hose)
  156. {
  157. memset(hose, 0, sizeof(struct pci_controller));
  158. spin_lock(&hose_spinlock);
  159. hose->global_number = global_phb_number++;
  160. list_add_tail(&hose->list_node, &hose_list);
  161. spin_unlock(&hose_spinlock);
  162. }
  163. static void __init pcibios_claim_one_bus(struct pci_bus *b)
  164. {
  165. struct pci_dev *dev;
  166. struct pci_bus *child_bus;
  167. list_for_each_entry(dev, &b->devices, bus_list) {
  168. int i;
  169. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  170. struct resource *r = &dev->resource[i];
  171. if (r->parent || !r->start || !r->flags)
  172. continue;
  173. pci_claim_resource(dev, i);
  174. }
  175. }
  176. list_for_each_entry(child_bus, &b->children, node)
  177. pcibios_claim_one_bus(child_bus);
  178. }
  179. #ifndef CONFIG_PPC_ISERIES
  180. static void __init pcibios_claim_of_setup(void)
  181. {
  182. struct pci_bus *b;
  183. list_for_each_entry(b, &pci_root_buses, node)
  184. pcibios_claim_one_bus(b);
  185. }
  186. #endif
  187. #ifdef CONFIG_PPC_MULTIPLATFORM
  188. static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
  189. {
  190. u32 *prop;
  191. int len;
  192. prop = (u32 *) get_property(np, name, &len);
  193. if (prop && len >= 4)
  194. return *prop;
  195. return def;
  196. }
  197. static unsigned int pci_parse_of_flags(u32 addr0)
  198. {
  199. unsigned int flags = 0;
  200. if (addr0 & 0x02000000) {
  201. flags |= IORESOURCE_MEM;
  202. if (addr0 & 0x40000000)
  203. flags |= IORESOURCE_PREFETCH;
  204. } else if (addr0 & 0x01000000)
  205. flags |= IORESOURCE_IO;
  206. return flags;
  207. }
  208. #define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
  209. static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev)
  210. {
  211. u64 base, size;
  212. unsigned int flags;
  213. struct resource *res;
  214. u32 *addrs, i;
  215. int proplen;
  216. addrs = (u32 *) get_property(node, "assigned-addresses", &proplen);
  217. if (!addrs)
  218. return;
  219. for (; proplen >= 20; proplen -= 20, addrs += 5) {
  220. flags = pci_parse_of_flags(addrs[0]);
  221. if (!flags)
  222. continue;
  223. base = GET_64BIT(addrs, 1);
  224. size = GET_64BIT(addrs, 3);
  225. if (!size)
  226. continue;
  227. i = addrs[0] & 0xff;
  228. if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
  229. res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
  230. } else if (i == dev->rom_base_reg) {
  231. res = &dev->resource[PCI_ROM_RESOURCE];
  232. flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
  233. } else {
  234. printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
  235. continue;
  236. }
  237. res->start = base;
  238. res->end = base + size - 1;
  239. res->flags = flags;
  240. res->name = pci_name(dev);
  241. fixup_resource(res, dev);
  242. }
  243. }
  244. static struct pci_dev *of_create_pci_dev(struct device_node *node,
  245. struct pci_bus *bus, int devfn)
  246. {
  247. struct pci_dev *dev;
  248. const char *type;
  249. dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
  250. if (!dev)
  251. return NULL;
  252. type = get_property(node, "device_type", NULL);
  253. if (type == NULL)
  254. type = "";
  255. memset(dev, 0, sizeof(struct pci_dev));
  256. dev->bus = bus;
  257. dev->sysdata = node;
  258. dev->dev.parent = bus->bridge;
  259. dev->dev.bus = &pci_bus_type;
  260. dev->devfn = devfn;
  261. dev->multifunction = 0; /* maybe a lie? */
  262. dev->vendor = get_int_prop(node, "vendor-id", 0xffff);
  263. dev->device = get_int_prop(node, "device-id", 0xffff);
  264. dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0);
  265. dev->subsystem_device = get_int_prop(node, "subsystem-id", 0);
  266. dev->cfg_size = 256; /*pci_cfg_space_size(dev);*/
  267. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  268. dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  269. dev->class = get_int_prop(node, "class-code", 0);
  270. dev->current_state = 4; /* unknown power state */
  271. if (!strcmp(type, "pci")) {
  272. /* a PCI-PCI bridge */
  273. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  274. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  275. } else if (!strcmp(type, "cardbus")) {
  276. dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
  277. } else {
  278. dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
  279. dev->rom_base_reg = PCI_ROM_ADDRESS;
  280. dev->irq = NO_IRQ;
  281. if (node->n_intrs > 0) {
  282. dev->irq = node->intrs[0].line;
  283. pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
  284. dev->irq);
  285. }
  286. }
  287. pci_parse_of_addrs(node, dev);
  288. pci_device_add(dev, bus);
  289. /* XXX pci_scan_msi_device(dev); */
  290. return dev;
  291. }
  292. static void of_scan_pci_bridge(struct device_node *node, struct pci_dev *dev);
  293. static void __devinit of_scan_bus(struct device_node *node,
  294. struct pci_bus *bus)
  295. {
  296. struct device_node *child = NULL;
  297. u32 *reg;
  298. int reglen, devfn;
  299. struct pci_dev *dev;
  300. while ((child = of_get_next_child(node, child)) != NULL) {
  301. reg = (u32 *) get_property(child, "reg", &reglen);
  302. if (reg == NULL || reglen < 20)
  303. continue;
  304. devfn = (reg[0] >> 8) & 0xff;
  305. /* create a new pci_dev for this device */
  306. dev = of_create_pci_dev(child, bus, devfn);
  307. if (!dev)
  308. continue;
  309. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  310. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  311. of_scan_pci_bridge(child, dev);
  312. }
  313. do_bus_setup(bus);
  314. }
  315. static void __devinit of_scan_pci_bridge(struct device_node *node,
  316. struct pci_dev *dev)
  317. {
  318. struct pci_bus *bus;
  319. u32 *busrange, *ranges;
  320. int len, i, mode;
  321. struct resource *res;
  322. unsigned int flags;
  323. u64 size;
  324. /* parse bus-range property */
  325. busrange = (u32 *) get_property(node, "bus-range", &len);
  326. if (busrange == NULL || len != 8) {
  327. printk(KERN_ERR "Can't get bus-range for PCI-PCI bridge %s\n",
  328. node->full_name);
  329. return;
  330. }
  331. ranges = (u32 *) get_property(node, "ranges", &len);
  332. if (ranges == NULL) {
  333. printk(KERN_ERR "Can't get ranges for PCI-PCI bridge %s\n",
  334. node->full_name);
  335. return;
  336. }
  337. bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
  338. if (!bus) {
  339. printk(KERN_ERR "Failed to create pci bus for %s\n",
  340. node->full_name);
  341. return;
  342. }
  343. bus->primary = dev->bus->number;
  344. bus->subordinate = busrange[1];
  345. bus->bridge_ctl = 0;
  346. bus->sysdata = node;
  347. /* parse ranges property */
  348. /* PCI #address-cells == 3 and #size-cells == 2 always */
  349. res = &dev->resource[PCI_BRIDGE_RESOURCES];
  350. for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
  351. res->flags = 0;
  352. bus->resource[i] = res;
  353. ++res;
  354. }
  355. i = 1;
  356. for (; len >= 32; len -= 32, ranges += 8) {
  357. flags = pci_parse_of_flags(ranges[0]);
  358. size = GET_64BIT(ranges, 6);
  359. if (flags == 0 || size == 0)
  360. continue;
  361. if (flags & IORESOURCE_IO) {
  362. res = bus->resource[0];
  363. if (res->flags) {
  364. printk(KERN_ERR "PCI: ignoring extra I/O range"
  365. " for bridge %s\n", node->full_name);
  366. continue;
  367. }
  368. } else {
  369. if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
  370. printk(KERN_ERR "PCI: too many memory ranges"
  371. " for bridge %s\n", node->full_name);
  372. continue;
  373. }
  374. res = bus->resource[i];
  375. ++i;
  376. }
  377. res->start = GET_64BIT(ranges, 1);
  378. res->end = res->start + size - 1;
  379. res->flags = flags;
  380. fixup_resource(res, dev);
  381. }
  382. sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
  383. bus->number);
  384. mode = PCI_PROBE_NORMAL;
  385. if (ppc_md.pci_probe_mode)
  386. mode = ppc_md.pci_probe_mode(bus);
  387. if (mode == PCI_PROBE_DEVTREE)
  388. of_scan_bus(node, bus);
  389. else if (mode == PCI_PROBE_NORMAL)
  390. pci_scan_child_bus(bus);
  391. }
  392. #endif /* CONFIG_PPC_MULTIPLATFORM */
  393. static void __devinit scan_phb(struct pci_controller *hose)
  394. {
  395. struct pci_bus *bus;
  396. struct device_node *node = hose->arch_data;
  397. int i, mode;
  398. struct resource *res;
  399. bus = pci_create_bus(NULL, hose->first_busno, hose->ops, node);
  400. if (bus == NULL) {
  401. printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
  402. hose->global_number);
  403. return;
  404. }
  405. bus->secondary = hose->first_busno;
  406. hose->bus = bus;
  407. bus->resource[0] = res = &hose->io_resource;
  408. if (res->flags && request_resource(&ioport_resource, res))
  409. printk(KERN_ERR "Failed to request PCI IO region "
  410. "on PCI domain %04x\n", hose->global_number);
  411. for (i = 0; i < 3; ++i) {
  412. res = &hose->mem_resources[i];
  413. bus->resource[i+1] = res;
  414. if (res->flags && request_resource(&iomem_resource, res))
  415. printk(KERN_ERR "Failed to request PCI memory region "
  416. "on PCI domain %04x\n", hose->global_number);
  417. }
  418. mode = PCI_PROBE_NORMAL;
  419. #ifdef CONFIG_PPC_MULTIPLATFORM
  420. if (ppc_md.pci_probe_mode)
  421. mode = ppc_md.pci_probe_mode(bus);
  422. if (mode == PCI_PROBE_DEVTREE) {
  423. bus->subordinate = hose->last_busno;
  424. of_scan_bus(node, bus);
  425. }
  426. #endif /* CONFIG_PPC_MULTIPLATFORM */
  427. if (mode == PCI_PROBE_NORMAL)
  428. hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
  429. pci_bus_add_devices(bus);
  430. }
  431. static int __init pcibios_init(void)
  432. {
  433. struct pci_controller *hose, *tmp;
  434. /* For now, override phys_mem_access_prot. If we need it,
  435. * later, we may move that initialization to each ppc_md
  436. */
  437. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  438. #ifdef CONFIG_PPC_ISERIES
  439. iSeries_pcibios_init();
  440. #endif
  441. printk("PCI: Probing PCI hardware\n");
  442. /* Scan all of the recorded PCI controllers. */
  443. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  444. scan_phb(hose);
  445. #ifndef CONFIG_PPC_ISERIES
  446. if (pci_probe_only)
  447. pcibios_claim_of_setup();
  448. else
  449. /* FIXME: `else' will be removed when
  450. pci_assign_unassigned_resources() is able to work
  451. correctly with [partially] allocated PCI tree. */
  452. pci_assign_unassigned_resources();
  453. #endif /* !CONFIG_PPC_ISERIES */
  454. /* Call machine dependent final fixup */
  455. if (ppc_md.pcibios_fixup)
  456. ppc_md.pcibios_fixup();
  457. /* Cache the location of the ISA bridge (if we have one) */
  458. ppc64_isabridge_dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  459. if (ppc64_isabridge_dev != NULL)
  460. printk("ISA bridge at %s\n", pci_name(ppc64_isabridge_dev));
  461. printk("PCI: Probing PCI hardware done\n");
  462. return 0;
  463. }
  464. subsys_initcall(pcibios_init);
  465. char __init *pcibios_setup(char *str)
  466. {
  467. return str;
  468. }
  469. int pcibios_enable_device(struct pci_dev *dev, int mask)
  470. {
  471. u16 cmd, oldcmd;
  472. int i;
  473. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  474. oldcmd = cmd;
  475. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  476. struct resource *res = &dev->resource[i];
  477. /* Only set up the requested stuff */
  478. if (!(mask & (1<<i)))
  479. continue;
  480. if (res->flags & IORESOURCE_IO)
  481. cmd |= PCI_COMMAND_IO;
  482. if (res->flags & IORESOURCE_MEM)
  483. cmd |= PCI_COMMAND_MEMORY;
  484. }
  485. if (cmd != oldcmd) {
  486. printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
  487. pci_name(dev), cmd);
  488. /* Enable the appropriate bits in the PCI command register. */
  489. pci_write_config_word(dev, PCI_COMMAND, cmd);
  490. }
  491. return 0;
  492. }
  493. /*
  494. * Return the domain number for this bus.
  495. */
  496. int pci_domain_nr(struct pci_bus *bus)
  497. {
  498. #ifdef CONFIG_PPC_ISERIES
  499. return 0;
  500. #else
  501. struct pci_controller *hose = pci_bus_to_host(bus);
  502. return hose->global_number;
  503. #endif
  504. }
  505. EXPORT_SYMBOL(pci_domain_nr);
  506. /* Decide whether to display the domain number in /proc */
  507. int pci_proc_domain(struct pci_bus *bus)
  508. {
  509. #ifdef CONFIG_PPC_ISERIES
  510. return 0;
  511. #else
  512. struct pci_controller *hose = pci_bus_to_host(bus);
  513. return hose->buid;
  514. #endif
  515. }
  516. /*
  517. * Platform support for /proc/bus/pci/X/Y mmap()s,
  518. * modelled on the sparc64 implementation by Dave Miller.
  519. * -- paulus.
  520. */
  521. /*
  522. * Adjust vm_pgoff of VMA such that it is the physical page offset
  523. * corresponding to the 32-bit pci bus offset for DEV requested by the user.
  524. *
  525. * Basically, the user finds the base address for his device which he wishes
  526. * to mmap. They read the 32-bit value from the config space base register,
  527. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  528. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  529. *
  530. * Returns negative error code on failure, zero on success.
  531. */
  532. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  533. unsigned long *offset,
  534. enum pci_mmap_state mmap_state)
  535. {
  536. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  537. unsigned long io_offset = 0;
  538. int i, res_bit;
  539. if (hose == 0)
  540. return NULL; /* should never happen */
  541. /* If memory, add on the PCI bridge address offset */
  542. if (mmap_state == pci_mmap_mem) {
  543. *offset += hose->pci_mem_offset;
  544. res_bit = IORESOURCE_MEM;
  545. } else {
  546. io_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  547. *offset += io_offset;
  548. res_bit = IORESOURCE_IO;
  549. }
  550. /*
  551. * Check that the offset requested corresponds to one of the
  552. * resources of the device.
  553. */
  554. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  555. struct resource *rp = &dev->resource[i];
  556. int flags = rp->flags;
  557. /* treat ROM as memory (should be already) */
  558. if (i == PCI_ROM_RESOURCE)
  559. flags |= IORESOURCE_MEM;
  560. /* Active and same type? */
  561. if ((flags & res_bit) == 0)
  562. continue;
  563. /* In the range of this resource? */
  564. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  565. continue;
  566. /* found it! construct the final physical address */
  567. if (mmap_state == pci_mmap_io)
  568. *offset += hose->io_base_phys - io_offset;
  569. return rp;
  570. }
  571. return NULL;
  572. }
  573. /*
  574. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  575. * device mapping.
  576. */
  577. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  578. pgprot_t protection,
  579. enum pci_mmap_state mmap_state,
  580. int write_combine)
  581. {
  582. unsigned long prot = pgprot_val(protection);
  583. /* Write combine is always 0 on non-memory space mappings. On
  584. * memory space, if the user didn't pass 1, we check for a
  585. * "prefetchable" resource. This is a bit hackish, but we use
  586. * this to workaround the inability of /sysfs to provide a write
  587. * combine bit
  588. */
  589. if (mmap_state != pci_mmap_mem)
  590. write_combine = 0;
  591. else if (write_combine == 0) {
  592. if (rp->flags & IORESOURCE_PREFETCH)
  593. write_combine = 1;
  594. }
  595. /* XXX would be nice to have a way to ask for write-through */
  596. prot |= _PAGE_NO_CACHE;
  597. if (write_combine)
  598. prot &= ~_PAGE_GUARDED;
  599. else
  600. prot |= _PAGE_GUARDED;
  601. printk("PCI map for %s:%lx, prot: %lx\n", pci_name(dev), rp->start,
  602. prot);
  603. return __pgprot(prot);
  604. }
  605. /*
  606. * This one is used by /dev/mem and fbdev who have no clue about the
  607. * PCI device, it tries to find the PCI device first and calls the
  608. * above routine
  609. */
  610. pgprot_t pci_phys_mem_access_prot(struct file *file,
  611. unsigned long offset,
  612. unsigned long size,
  613. pgprot_t protection)
  614. {
  615. struct pci_dev *pdev = NULL;
  616. struct resource *found = NULL;
  617. unsigned long prot = pgprot_val(protection);
  618. int i;
  619. if (page_is_ram(offset >> PAGE_SHIFT))
  620. return __pgprot(prot);
  621. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  622. for_each_pci_dev(pdev) {
  623. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  624. struct resource *rp = &pdev->resource[i];
  625. int flags = rp->flags;
  626. /* Active and same type? */
  627. if ((flags & IORESOURCE_MEM) == 0)
  628. continue;
  629. /* In the range of this resource? */
  630. if (offset < (rp->start & PAGE_MASK) ||
  631. offset > rp->end)
  632. continue;
  633. found = rp;
  634. break;
  635. }
  636. if (found)
  637. break;
  638. }
  639. if (found) {
  640. if (found->flags & IORESOURCE_PREFETCH)
  641. prot &= ~_PAGE_GUARDED;
  642. pci_dev_put(pdev);
  643. }
  644. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  645. return __pgprot(prot);
  646. }
  647. /*
  648. * Perform the actual remap of the pages for a PCI device mapping, as
  649. * appropriate for this architecture. The region in the process to map
  650. * is described by vm_start and vm_end members of VMA, the base physical
  651. * address is found in vm_pgoff.
  652. * The pci device structure is provided so that architectures may make mapping
  653. * decisions on a per-device or per-bus basis.
  654. *
  655. * Returns a negative error code on failure, zero on success.
  656. */
  657. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  658. enum pci_mmap_state mmap_state,
  659. int write_combine)
  660. {
  661. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  662. struct resource *rp;
  663. int ret;
  664. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  665. if (rp == NULL)
  666. return -EINVAL;
  667. vma->vm_pgoff = offset >> PAGE_SHIFT;
  668. vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
  669. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  670. vma->vm_page_prot,
  671. mmap_state, write_combine);
  672. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  673. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  674. return ret;
  675. }
  676. #ifdef CONFIG_PPC_MULTIPLATFORM
  677. static ssize_t pci_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
  678. {
  679. struct pci_dev *pdev;
  680. struct device_node *np;
  681. pdev = to_pci_dev (dev);
  682. np = pci_device_to_OF_node(pdev);
  683. if (np == NULL || np->full_name == NULL)
  684. return 0;
  685. return sprintf(buf, "%s", np->full_name);
  686. }
  687. static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
  688. #endif /* CONFIG_PPC_MULTIPLATFORM */
  689. void pcibios_add_platform_entries(struct pci_dev *pdev)
  690. {
  691. #ifdef CONFIG_PPC_MULTIPLATFORM
  692. device_create_file(&pdev->dev, &dev_attr_devspec);
  693. #endif /* CONFIG_PPC_MULTIPLATFORM */
  694. }
  695. #ifdef CONFIG_PPC_MULTIPLATFORM
  696. #define ISA_SPACE_MASK 0x1
  697. #define ISA_SPACE_IO 0x1
  698. static void __devinit pci_process_ISA_OF_ranges(struct device_node *isa_node,
  699. unsigned long phb_io_base_phys,
  700. void __iomem * phb_io_base_virt)
  701. {
  702. struct isa_range *range;
  703. unsigned long pci_addr;
  704. unsigned int isa_addr;
  705. unsigned int size;
  706. int rlen = 0;
  707. range = (struct isa_range *) get_property(isa_node, "ranges", &rlen);
  708. if (range == NULL || (rlen < sizeof(struct isa_range))) {
  709. printk(KERN_ERR "no ISA ranges or unexpected isa range size,"
  710. "mapping 64k\n");
  711. __ioremap_explicit(phb_io_base_phys,
  712. (unsigned long)phb_io_base_virt,
  713. 0x10000, _PAGE_NO_CACHE | _PAGE_GUARDED);
  714. return;
  715. }
  716. /* From "ISA Binding to 1275"
  717. * The ranges property is laid out as an array of elements,
  718. * each of which comprises:
  719. * cells 0 - 1: an ISA address
  720. * cells 2 - 4: a PCI address
  721. * (size depending on dev->n_addr_cells)
  722. * cell 5: the size of the range
  723. */
  724. if ((range->isa_addr.a_hi && ISA_SPACE_MASK) == ISA_SPACE_IO) {
  725. isa_addr = range->isa_addr.a_lo;
  726. pci_addr = (unsigned long) range->pci_addr.a_mid << 32 |
  727. range->pci_addr.a_lo;
  728. /* Assume these are both zero */
  729. if ((pci_addr != 0) || (isa_addr != 0)) {
  730. printk(KERN_ERR "unexpected isa to pci mapping: %s\n",
  731. __FUNCTION__);
  732. return;
  733. }
  734. size = PAGE_ALIGN(range->size);
  735. __ioremap_explicit(phb_io_base_phys,
  736. (unsigned long) phb_io_base_virt,
  737. size, _PAGE_NO_CACHE | _PAGE_GUARDED);
  738. }
  739. }
  740. void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
  741. struct device_node *dev)
  742. {
  743. unsigned int *ranges;
  744. unsigned long size;
  745. int rlen = 0;
  746. int memno = 0;
  747. struct resource *res;
  748. int np, na = prom_n_addr_cells(dev);
  749. unsigned long pci_addr, cpu_phys_addr;
  750. np = na + 5;
  751. /* From "PCI Binding to 1275"
  752. * The ranges property is laid out as an array of elements,
  753. * each of which comprises:
  754. * cells 0 - 2: a PCI address
  755. * cells 3 or 3+4: a CPU physical address
  756. * (size depending on dev->n_addr_cells)
  757. * cells 4+5 or 5+6: the size of the range
  758. */
  759. rlen = 0;
  760. hose->io_base_phys = 0;
  761. ranges = (unsigned int *) get_property(dev, "ranges", &rlen);
  762. while ((rlen -= np * sizeof(unsigned int)) >= 0) {
  763. res = NULL;
  764. pci_addr = (unsigned long)ranges[1] << 32 | ranges[2];
  765. cpu_phys_addr = ranges[3];
  766. if (na == 2)
  767. cpu_phys_addr = cpu_phys_addr << 32 | ranges[4];
  768. size = (unsigned long)ranges[na+3] << 32 | ranges[na+4];
  769. if (size == 0)
  770. continue;
  771. switch ((ranges[0] >> 24) & 0x3) {
  772. case 1: /* I/O space */
  773. hose->io_base_phys = cpu_phys_addr;
  774. hose->pci_io_size = size;
  775. res = &hose->io_resource;
  776. res->flags = IORESOURCE_IO;
  777. res->start = pci_addr;
  778. DBG("phb%d: IO 0x%lx -> 0x%lx\n", hose->global_number,
  779. res->start, res->start + size - 1);
  780. break;
  781. case 2: /* memory space */
  782. memno = 0;
  783. while (memno < 3 && hose->mem_resources[memno].flags)
  784. ++memno;
  785. if (memno == 0)
  786. hose->pci_mem_offset = cpu_phys_addr - pci_addr;
  787. if (memno < 3) {
  788. res = &hose->mem_resources[memno];
  789. res->flags = IORESOURCE_MEM;
  790. res->start = cpu_phys_addr;
  791. DBG("phb%d: MEM 0x%lx -> 0x%lx\n", hose->global_number,
  792. res->start, res->start + size - 1);
  793. }
  794. break;
  795. }
  796. if (res != NULL) {
  797. res->name = dev->full_name;
  798. res->end = res->start + size - 1;
  799. res->parent = NULL;
  800. res->sibling = NULL;
  801. res->child = NULL;
  802. }
  803. ranges += np;
  804. }
  805. }
  806. void __init pci_setup_phb_io(struct pci_controller *hose, int primary)
  807. {
  808. unsigned long size = hose->pci_io_size;
  809. unsigned long io_virt_offset;
  810. struct resource *res;
  811. struct device_node *isa_dn;
  812. hose->io_base_virt = reserve_phb_iospace(size);
  813. DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
  814. hose->global_number, hose->io_base_phys,
  815. (unsigned long) hose->io_base_virt);
  816. if (primary) {
  817. pci_io_base = (unsigned long)hose->io_base_virt;
  818. isa_dn = of_find_node_by_type(NULL, "isa");
  819. if (isa_dn) {
  820. isa_io_base = pci_io_base;
  821. pci_process_ISA_OF_ranges(isa_dn, hose->io_base_phys,
  822. hose->io_base_virt);
  823. of_node_put(isa_dn);
  824. /* Allow all IO */
  825. io_page_mask = -1;
  826. }
  827. }
  828. io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  829. res = &hose->io_resource;
  830. res->start += io_virt_offset;
  831. res->end += io_virt_offset;
  832. }
  833. void __devinit pci_setup_phb_io_dynamic(struct pci_controller *hose,
  834. int primary)
  835. {
  836. unsigned long size = hose->pci_io_size;
  837. unsigned long io_virt_offset;
  838. struct resource *res;
  839. hose->io_base_virt = __ioremap(hose->io_base_phys, size,
  840. _PAGE_NO_CACHE | _PAGE_GUARDED);
  841. DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
  842. hose->global_number, hose->io_base_phys,
  843. (unsigned long) hose->io_base_virt);
  844. if (primary)
  845. pci_io_base = (unsigned long)hose->io_base_virt;
  846. io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  847. res = &hose->io_resource;
  848. res->start += io_virt_offset;
  849. res->end += io_virt_offset;
  850. }
  851. static int get_bus_io_range(struct pci_bus *bus, unsigned long *start_phys,
  852. unsigned long *start_virt, unsigned long *size)
  853. {
  854. struct pci_controller *hose = pci_bus_to_host(bus);
  855. struct pci_bus_region region;
  856. struct resource *res;
  857. if (bus->self) {
  858. res = bus->resource[0];
  859. pcibios_resource_to_bus(bus->self, &region, res);
  860. *start_phys = hose->io_base_phys + region.start;
  861. *start_virt = (unsigned long) hose->io_base_virt +
  862. region.start;
  863. if (region.end > region.start)
  864. *size = region.end - region.start + 1;
  865. else {
  866. printk("%s(): unexpected region 0x%lx->0x%lx\n",
  867. __FUNCTION__, region.start, region.end);
  868. return 1;
  869. }
  870. } else {
  871. /* Root Bus */
  872. res = &hose->io_resource;
  873. *start_phys = hose->io_base_phys;
  874. *start_virt = (unsigned long) hose->io_base_virt;
  875. if (res->end > res->start)
  876. *size = res->end - res->start + 1;
  877. else {
  878. printk("%s(): unexpected region 0x%lx->0x%lx\n",
  879. __FUNCTION__, res->start, res->end);
  880. return 1;
  881. }
  882. }
  883. return 0;
  884. }
  885. int unmap_bus_range(struct pci_bus *bus)
  886. {
  887. unsigned long start_phys;
  888. unsigned long start_virt;
  889. unsigned long size;
  890. if (!bus) {
  891. printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
  892. return 1;
  893. }
  894. if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
  895. return 1;
  896. if (iounmap_explicit((void __iomem *) start_virt, size))
  897. return 1;
  898. return 0;
  899. }
  900. EXPORT_SYMBOL(unmap_bus_range);
  901. int remap_bus_range(struct pci_bus *bus)
  902. {
  903. unsigned long start_phys;
  904. unsigned long start_virt;
  905. unsigned long size;
  906. if (!bus) {
  907. printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
  908. return 1;
  909. }
  910. if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
  911. return 1;
  912. printk("mapping IO %lx -> %lx, size: %lx\n", start_phys, start_virt, size);
  913. if (__ioremap_explicit(start_phys, start_virt, size,
  914. _PAGE_NO_CACHE | _PAGE_GUARDED))
  915. return 1;
  916. return 0;
  917. }
  918. EXPORT_SYMBOL(remap_bus_range);
  919. void phbs_remap_io(void)
  920. {
  921. struct pci_controller *hose, *tmp;
  922. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  923. remap_bus_range(hose->bus);
  924. }
  925. /*
  926. * ppc64 can have multifunction devices that do not respond to function 0.
  927. * In this case we must scan all functions.
  928. * XXX this can go now, we use the OF device tree in all the
  929. * cases that caused problems. -- paulus
  930. */
  931. int pcibios_scan_all_fns(struct pci_bus *bus, int devfn)
  932. {
  933. return 0;
  934. }
  935. static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev)
  936. {
  937. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  938. unsigned long start, end, mask, offset;
  939. if (res->flags & IORESOURCE_IO) {
  940. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  941. start = res->start += offset;
  942. end = res->end += offset;
  943. /* Need to allow IO access to pages that are in the
  944. ISA range */
  945. if (start < MAX_ISA_PORT) {
  946. if (end > MAX_ISA_PORT)
  947. end = MAX_ISA_PORT;
  948. start >>= PAGE_SHIFT;
  949. end >>= PAGE_SHIFT;
  950. /* get the range of pages for the map */
  951. mask = ((1 << (end+1)) - 1) ^ ((1 << start) - 1);
  952. io_page_mask |= mask;
  953. }
  954. } else if (res->flags & IORESOURCE_MEM) {
  955. res->start += hose->pci_mem_offset;
  956. res->end += hose->pci_mem_offset;
  957. }
  958. }
  959. void __devinit pcibios_fixup_device_resources(struct pci_dev *dev,
  960. struct pci_bus *bus)
  961. {
  962. /* Update device resources. */
  963. int i;
  964. for (i = 0; i < PCI_NUM_RESOURCES; i++)
  965. if (dev->resource[i].flags)
  966. fixup_resource(&dev->resource[i], dev);
  967. }
  968. EXPORT_SYMBOL(pcibios_fixup_device_resources);
  969. static void __devinit do_bus_setup(struct pci_bus *bus)
  970. {
  971. struct pci_dev *dev;
  972. ppc_md.iommu_bus_setup(bus);
  973. list_for_each_entry(dev, &bus->devices, bus_list)
  974. ppc_md.iommu_dev_setup(dev);
  975. if (ppc_md.irq_bus_setup)
  976. ppc_md.irq_bus_setup(bus);
  977. }
  978. void __devinit pcibios_fixup_bus(struct pci_bus *bus)
  979. {
  980. struct pci_dev *dev = bus->self;
  981. if (dev && pci_probe_only &&
  982. (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  983. /* This is a subordinate bridge */
  984. pci_read_bridge_bases(bus);
  985. pcibios_fixup_device_resources(dev, bus);
  986. }
  987. do_bus_setup(bus);
  988. if (!pci_probe_only)
  989. return;
  990. list_for_each_entry(dev, &bus->devices, bus_list)
  991. if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  992. pcibios_fixup_device_resources(dev, bus);
  993. }
  994. EXPORT_SYMBOL(pcibios_fixup_bus);
  995. /*
  996. * Reads the interrupt pin to determine if interrupt is use by card.
  997. * If the interrupt is used, then gets the interrupt line from the
  998. * openfirmware and sets it in the pci_dev and pci_config line.
  999. */
  1000. int pci_read_irq_line(struct pci_dev *pci_dev)
  1001. {
  1002. u8 intpin;
  1003. struct device_node *node;
  1004. pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &intpin);
  1005. if (intpin == 0)
  1006. return 0;
  1007. node = pci_device_to_OF_node(pci_dev);
  1008. if (node == NULL)
  1009. return -1;
  1010. if (node->n_intrs == 0)
  1011. return -1;
  1012. pci_dev->irq = node->intrs[0].line;
  1013. pci_write_config_byte(pci_dev, PCI_INTERRUPT_LINE, pci_dev->irq);
  1014. return 0;
  1015. }
  1016. EXPORT_SYMBOL(pci_read_irq_line);
  1017. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  1018. const struct resource *rsrc,
  1019. u64 *start, u64 *end)
  1020. {
  1021. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  1022. unsigned long offset = 0;
  1023. if (hose == NULL)
  1024. return;
  1025. if (rsrc->flags & IORESOURCE_IO)
  1026. offset = pci_io_base - (unsigned long)hose->io_base_virt +
  1027. hose->io_base_phys;
  1028. *start = rsrc->start + offset;
  1029. *end = rsrc->end + offset;
  1030. }
  1031. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1032. #define IOBASE_BRIDGE_NUMBER 0
  1033. #define IOBASE_MEMORY 1
  1034. #define IOBASE_IO 2
  1035. #define IOBASE_ISA_IO 3
  1036. #define IOBASE_ISA_MEM 4
  1037. long sys_pciconfig_iobase(long which, unsigned long in_bus,
  1038. unsigned long in_devfn)
  1039. {
  1040. struct pci_controller* hose;
  1041. struct list_head *ln;
  1042. struct pci_bus *bus = NULL;
  1043. struct device_node *hose_node;
  1044. /* Argh ! Please forgive me for that hack, but that's the
  1045. * simplest way to get existing XFree to not lockup on some
  1046. * G5 machines... So when something asks for bus 0 io base
  1047. * (bus 0 is HT root), we return the AGP one instead.
  1048. */
  1049. #ifdef CONFIG_PPC_PMAC
  1050. if (systemcfg->platform == PLATFORM_POWERMAC &&
  1051. machine_is_compatible("MacRISC4"))
  1052. if (in_bus == 0)
  1053. in_bus = 0xf0;
  1054. #endif /* CONFIG_PPC_PMAC */
  1055. /* That syscall isn't quite compatible with PCI domains, but it's
  1056. * used on pre-domains setup. We return the first match
  1057. */
  1058. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  1059. bus = pci_bus_b(ln);
  1060. if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
  1061. break;
  1062. bus = NULL;
  1063. }
  1064. if (bus == NULL || bus->sysdata == NULL)
  1065. return -ENODEV;
  1066. hose_node = (struct device_node *)bus->sysdata;
  1067. hose = PCI_DN(hose_node)->phb;
  1068. switch (which) {
  1069. case IOBASE_BRIDGE_NUMBER:
  1070. return (long)hose->first_busno;
  1071. case IOBASE_MEMORY:
  1072. return (long)hose->pci_mem_offset;
  1073. case IOBASE_IO:
  1074. return (long)hose->io_base_phys;
  1075. case IOBASE_ISA_IO:
  1076. return (long)isa_io_base;
  1077. case IOBASE_ISA_MEM:
  1078. return -EINVAL;
  1079. }
  1080. return -EOPNOTSUPP;
  1081. }