pci-common.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * Contains common pci routines for ALL ppc platform
  3. * (based on pci_32.c and pci_64.c)
  4. *
  5. * Port for PPC64 David Engebretsen, IBM Corp.
  6. * Contains common pci routines for ppc64 platform, pSeries and iSeries brands.
  7. *
  8. * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
  9. * Rework, based on alpha PCI code.
  10. *
  11. * Common pmac/prep/chrp pci routines. -- Cort
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. */
  18. #undef DEBUG
  19. #include <linux/kernel.h>
  20. #include <linux/pci.h>
  21. #include <linux/string.h>
  22. #include <linux/init.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/mm.h>
  25. #include <linux/list.h>
  26. #include <linux/syscalls.h>
  27. #include <linux/irq.h>
  28. #include <linux/vmalloc.h>
  29. #include <asm/processor.h>
  30. #include <asm/io.h>
  31. #include <asm/prom.h>
  32. #include <asm/pci-bridge.h>
  33. #include <asm/byteorder.h>
  34. #include <asm/machdep.h>
  35. #include <asm/ppc-pci.h>
  36. #include <asm/firmware.h>
  37. #ifdef DEBUG
  38. #include <asm/udbg.h>
  39. #define DBG(fmt...) printk(fmt)
  40. #else
  41. #define DBG(fmt...)
  42. #endif
  43. static DEFINE_SPINLOCK(hose_spinlock);
  44. /* XXX kill that some day ... */
  45. static int global_phb_number; /* Global phb counter */
  46. /* ISA Memory physical address */
  47. resource_size_t isa_mem_base;
  48. struct pci_controller *pcibios_alloc_controller(struct device_node *dev)
  49. {
  50. struct pci_controller *phb;
  51. phb = zalloc_maybe_bootmem(sizeof(struct pci_controller), GFP_KERNEL);
  52. if (phb == NULL)
  53. return NULL;
  54. spin_lock(&hose_spinlock);
  55. phb->global_number = global_phb_number++;
  56. list_add_tail(&phb->list_node, &hose_list);
  57. spin_unlock(&hose_spinlock);
  58. phb->dn = dev;
  59. phb->is_dynamic = mem_init_done;
  60. #ifdef CONFIG_PPC64
  61. if (dev) {
  62. int nid = of_node_to_nid(dev);
  63. if (nid < 0 || !node_online(nid))
  64. nid = -1;
  65. PHB_SET_NODE(phb, nid);
  66. }
  67. #endif
  68. return phb;
  69. }
  70. void pcibios_free_controller(struct pci_controller *phb)
  71. {
  72. spin_lock(&hose_spinlock);
  73. list_del(&phb->list_node);
  74. spin_unlock(&hose_spinlock);
  75. if (phb->is_dynamic)
  76. kfree(phb);
  77. }
  78. int pcibios_vaddr_is_ioport(void __iomem *address)
  79. {
  80. int ret = 0;
  81. struct pci_controller *hose;
  82. unsigned long size;
  83. spin_lock(&hose_spinlock);
  84. list_for_each_entry(hose, &hose_list, list_node) {
  85. #ifdef CONFIG_PPC64
  86. size = hose->pci_io_size;
  87. #else
  88. size = hose->io_resource.end - hose->io_resource.start + 1;
  89. #endif
  90. if (address >= hose->io_base_virt &&
  91. address < (hose->io_base_virt + size)) {
  92. ret = 1;
  93. break;
  94. }
  95. }
  96. spin_unlock(&hose_spinlock);
  97. return ret;
  98. }
  99. /*
  100. * Return the domain number for this bus.
  101. */
  102. int pci_domain_nr(struct pci_bus *bus)
  103. {
  104. struct pci_controller *hose = pci_bus_to_host(bus);
  105. return hose->global_number;
  106. }
  107. EXPORT_SYMBOL(pci_domain_nr);
  108. #ifdef CONFIG_PPC_OF
  109. /* This routine is meant to be used early during boot, when the
  110. * PCI bus numbers have not yet been assigned, and you need to
  111. * issue PCI config cycles to an OF device.
  112. * It could also be used to "fix" RTAS config cycles if you want
  113. * to set pci_assign_all_buses to 1 and still use RTAS for PCI
  114. * config cycles.
  115. */
  116. struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node)
  117. {
  118. if (!have_of)
  119. return NULL;
  120. while(node) {
  121. struct pci_controller *hose, *tmp;
  122. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  123. if (hose->dn == node)
  124. return hose;
  125. node = node->parent;
  126. }
  127. return NULL;
  128. }
  129. static ssize_t pci_show_devspec(struct device *dev,
  130. struct device_attribute *attr, char *buf)
  131. {
  132. struct pci_dev *pdev;
  133. struct device_node *np;
  134. pdev = to_pci_dev (dev);
  135. np = pci_device_to_OF_node(pdev);
  136. if (np == NULL || np->full_name == NULL)
  137. return 0;
  138. return sprintf(buf, "%s", np->full_name);
  139. }
  140. static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
  141. #endif /* CONFIG_PPC_OF */
  142. /* Add sysfs properties */
  143. int pcibios_add_platform_entries(struct pci_dev *pdev)
  144. {
  145. #ifdef CONFIG_PPC_OF
  146. return device_create_file(&pdev->dev, &dev_attr_devspec);
  147. #else
  148. return 0;
  149. #endif /* CONFIG_PPC_OF */
  150. }
  151. char __devinit *pcibios_setup(char *str)
  152. {
  153. return str;
  154. }
  155. /*
  156. * Reads the interrupt pin to determine if interrupt is use by card.
  157. * If the interrupt is used, then gets the interrupt line from the
  158. * openfirmware and sets it in the pci_dev and pci_config line.
  159. */
  160. int pci_read_irq_line(struct pci_dev *pci_dev)
  161. {
  162. struct of_irq oirq;
  163. unsigned int virq;
  164. DBG("Try to map irq for %s...\n", pci_name(pci_dev));
  165. #ifdef DEBUG
  166. memset(&oirq, 0xff, sizeof(oirq));
  167. #endif
  168. /* Try to get a mapping from the device-tree */
  169. if (of_irq_map_pci(pci_dev, &oirq)) {
  170. u8 line, pin;
  171. /* If that fails, lets fallback to what is in the config
  172. * space and map that through the default controller. We
  173. * also set the type to level low since that's what PCI
  174. * interrupts are. If your platform does differently, then
  175. * either provide a proper interrupt tree or don't use this
  176. * function.
  177. */
  178. if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &pin))
  179. return -1;
  180. if (pin == 0)
  181. return -1;
  182. if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &line) ||
  183. line == 0xff) {
  184. return -1;
  185. }
  186. DBG(" -> no map ! Using irq line %d from PCI config\n", line);
  187. virq = irq_create_mapping(NULL, line);
  188. if (virq != NO_IRQ)
  189. set_irq_type(virq, IRQ_TYPE_LEVEL_LOW);
  190. } else {
  191. DBG(" -> got one, spec %d cells (0x%08x 0x%08x...) on %s\n",
  192. oirq.size, oirq.specifier[0], oirq.specifier[1],
  193. oirq.controller->full_name);
  194. virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
  195. oirq.size);
  196. }
  197. if(virq == NO_IRQ) {
  198. DBG(" -> failed to map !\n");
  199. return -1;
  200. }
  201. DBG(" -> mapped to linux irq %d\n", virq);
  202. pci_dev->irq = virq;
  203. return 0;
  204. }
  205. EXPORT_SYMBOL(pci_read_irq_line);
  206. /*
  207. * Platform support for /proc/bus/pci/X/Y mmap()s,
  208. * modelled on the sparc64 implementation by Dave Miller.
  209. * -- paulus.
  210. */
  211. /*
  212. * Adjust vm_pgoff of VMA such that it is the physical page offset
  213. * corresponding to the 32-bit pci bus offset for DEV requested by the user.
  214. *
  215. * Basically, the user finds the base address for his device which he wishes
  216. * to mmap. They read the 32-bit value from the config space base register,
  217. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  218. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  219. *
  220. * Returns negative error code on failure, zero on success.
  221. */
  222. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  223. resource_size_t *offset,
  224. enum pci_mmap_state mmap_state)
  225. {
  226. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  227. unsigned long io_offset = 0;
  228. int i, res_bit;
  229. if (hose == 0)
  230. return NULL; /* should never happen */
  231. /* If memory, add on the PCI bridge address offset */
  232. if (mmap_state == pci_mmap_mem) {
  233. #if 0 /* See comment in pci_resource_to_user() for why this is disabled */
  234. *offset += hose->pci_mem_offset;
  235. #endif
  236. res_bit = IORESOURCE_MEM;
  237. } else {
  238. io_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  239. *offset += io_offset;
  240. res_bit = IORESOURCE_IO;
  241. }
  242. /*
  243. * Check that the offset requested corresponds to one of the
  244. * resources of the device.
  245. */
  246. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  247. struct resource *rp = &dev->resource[i];
  248. int flags = rp->flags;
  249. /* treat ROM as memory (should be already) */
  250. if (i == PCI_ROM_RESOURCE)
  251. flags |= IORESOURCE_MEM;
  252. /* Active and same type? */
  253. if ((flags & res_bit) == 0)
  254. continue;
  255. /* In the range of this resource? */
  256. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  257. continue;
  258. /* found it! construct the final physical address */
  259. if (mmap_state == pci_mmap_io)
  260. *offset += hose->io_base_phys - io_offset;
  261. return rp;
  262. }
  263. return NULL;
  264. }
  265. /*
  266. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  267. * device mapping.
  268. */
  269. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  270. pgprot_t protection,
  271. enum pci_mmap_state mmap_state,
  272. int write_combine)
  273. {
  274. unsigned long prot = pgprot_val(protection);
  275. /* Write combine is always 0 on non-memory space mappings. On
  276. * memory space, if the user didn't pass 1, we check for a
  277. * "prefetchable" resource. This is a bit hackish, but we use
  278. * this to workaround the inability of /sysfs to provide a write
  279. * combine bit
  280. */
  281. if (mmap_state != pci_mmap_mem)
  282. write_combine = 0;
  283. else if (write_combine == 0) {
  284. if (rp->flags & IORESOURCE_PREFETCH)
  285. write_combine = 1;
  286. }
  287. /* XXX would be nice to have a way to ask for write-through */
  288. prot |= _PAGE_NO_CACHE;
  289. if (write_combine)
  290. prot &= ~_PAGE_GUARDED;
  291. else
  292. prot |= _PAGE_GUARDED;
  293. return __pgprot(prot);
  294. }
  295. /*
  296. * This one is used by /dev/mem and fbdev who have no clue about the
  297. * PCI device, it tries to find the PCI device first and calls the
  298. * above routine
  299. */
  300. pgprot_t pci_phys_mem_access_prot(struct file *file,
  301. unsigned long pfn,
  302. unsigned long size,
  303. pgprot_t protection)
  304. {
  305. struct pci_dev *pdev = NULL;
  306. struct resource *found = NULL;
  307. unsigned long prot = pgprot_val(protection);
  308. unsigned long offset = pfn << PAGE_SHIFT;
  309. int i;
  310. if (page_is_ram(pfn))
  311. return __pgprot(prot);
  312. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  313. for_each_pci_dev(pdev) {
  314. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  315. struct resource *rp = &pdev->resource[i];
  316. int flags = rp->flags;
  317. /* Active and same type? */
  318. if ((flags & IORESOURCE_MEM) == 0)
  319. continue;
  320. /* In the range of this resource? */
  321. if (offset < (rp->start & PAGE_MASK) ||
  322. offset > rp->end)
  323. continue;
  324. found = rp;
  325. break;
  326. }
  327. if (found)
  328. break;
  329. }
  330. if (found) {
  331. if (found->flags & IORESOURCE_PREFETCH)
  332. prot &= ~_PAGE_GUARDED;
  333. pci_dev_put(pdev);
  334. }
  335. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  336. return __pgprot(prot);
  337. }
  338. /*
  339. * Perform the actual remap of the pages for a PCI device mapping, as
  340. * appropriate for this architecture. The region in the process to map
  341. * is described by vm_start and vm_end members of VMA, the base physical
  342. * address is found in vm_pgoff.
  343. * The pci device structure is provided so that architectures may make mapping
  344. * decisions on a per-device or per-bus basis.
  345. *
  346. * Returns a negative error code on failure, zero on success.
  347. */
  348. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  349. enum pci_mmap_state mmap_state, int write_combine)
  350. {
  351. resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
  352. struct resource *rp;
  353. int ret;
  354. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  355. if (rp == NULL)
  356. return -EINVAL;
  357. vma->vm_pgoff = offset >> PAGE_SHIFT;
  358. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  359. vma->vm_page_prot,
  360. mmap_state, write_combine);
  361. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  362. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  363. return ret;
  364. }
  365. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  366. const struct resource *rsrc,
  367. resource_size_t *start, resource_size_t *end)
  368. {
  369. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  370. resource_size_t offset = 0;
  371. if (hose == NULL)
  372. return;
  373. if (rsrc->flags & IORESOURCE_IO)
  374. offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  375. /* We pass a fully fixed up address to userland for MMIO instead of
  376. * a BAR value because X is lame and expects to be able to use that
  377. * to pass to /dev/mem !
  378. *
  379. * That means that we'll have potentially 64 bits values where some
  380. * userland apps only expect 32 (like X itself since it thinks only
  381. * Sparc has 64 bits MMIO) but if we don't do that, we break it on
  382. * 32 bits CHRPs :-(
  383. *
  384. * Hopefully, the sysfs insterface is immune to that gunk. Once X
  385. * has been fixed (and the fix spread enough), we can re-enable the
  386. * 2 lines below and pass down a BAR value to userland. In that case
  387. * we'll also have to re-enable the matching code in
  388. * __pci_mmap_make_offset().
  389. *
  390. * BenH.
  391. */
  392. #if 0
  393. else if (rsrc->flags & IORESOURCE_MEM)
  394. offset = hose->pci_mem_offset;
  395. #endif
  396. *start = rsrc->start - offset;
  397. *end = rsrc->end - offset;
  398. }
  399. /**
  400. * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree
  401. * @hose: newly allocated pci_controller to be setup
  402. * @dev: device node of the host bridge
  403. * @primary: set if primary bus (32 bits only, soon to be deprecated)
  404. *
  405. * This function will parse the "ranges" property of a PCI host bridge device
  406. * node and setup the resource mapping of a pci controller based on its
  407. * content.
  408. *
  409. * Life would be boring if it wasn't for a few issues that we have to deal
  410. * with here:
  411. *
  412. * - We can only cope with one IO space range and up to 3 Memory space
  413. * ranges. However, some machines (thanks Apple !) tend to split their
  414. * space into lots of small contiguous ranges. So we have to coalesce.
  415. *
  416. * - We can only cope with all memory ranges having the same offset
  417. * between CPU addresses and PCI addresses. Unfortunately, some bridges
  418. * are setup for a large 1:1 mapping along with a small "window" which
  419. * maps PCI address 0 to some arbitrary high address of the CPU space in
  420. * order to give access to the ISA memory hole.
  421. * The way out of here that I've chosen for now is to always set the
  422. * offset based on the first resource found, then override it if we
  423. * have a different offset and the previous was set by an ISA hole.
  424. *
  425. * - Some busses have IO space not starting at 0, which causes trouble with
  426. * the way we do our IO resource renumbering. The code somewhat deals with
  427. * it for 64 bits but I would expect problems on 32 bits.
  428. *
  429. * - Some 32 bits platforms such as 4xx can have physical space larger than
  430. * 32 bits so we need to use 64 bits values for the parsing
  431. */
  432. void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
  433. struct device_node *dev,
  434. int primary)
  435. {
  436. const u32 *ranges;
  437. int rlen;
  438. int pna = of_n_addr_cells(dev);
  439. int np = pna + 5;
  440. int memno = 0, isa_hole = -1;
  441. u32 pci_space;
  442. unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size;
  443. unsigned long long isa_mb = 0;
  444. struct resource *res;
  445. printk(KERN_INFO "PCI host bridge %s %s ranges:\n",
  446. dev->full_name, primary ? "(primary)" : "");
  447. /* Get ranges property */
  448. ranges = of_get_property(dev, "ranges", &rlen);
  449. if (ranges == NULL)
  450. return;
  451. /* Parse it */
  452. while ((rlen -= np * 4) >= 0) {
  453. /* Read next ranges element */
  454. pci_space = ranges[0];
  455. pci_addr = of_read_number(ranges + 1, 2);
  456. cpu_addr = of_translate_address(dev, ranges + 3);
  457. size = of_read_number(ranges + pna + 3, 2);
  458. ranges += np;
  459. if (cpu_addr == OF_BAD_ADDR || size == 0)
  460. continue;
  461. /* Now consume following elements while they are contiguous */
  462. for (; rlen >= np * sizeof(u32);
  463. ranges += np, rlen -= np * 4) {
  464. if (ranges[0] != pci_space)
  465. break;
  466. pci_next = of_read_number(ranges + 1, 2);
  467. cpu_next = of_translate_address(dev, ranges + 3);
  468. if (pci_next != pci_addr + size ||
  469. cpu_next != cpu_addr + size)
  470. break;
  471. size += of_read_number(ranges + pna + 3, 2);
  472. }
  473. /* Act based on address space type */
  474. res = NULL;
  475. switch ((pci_space >> 24) & 0x3) {
  476. case 1: /* PCI IO space */
  477. printk(KERN_INFO
  478. " IO 0x%016llx..0x%016llx -> 0x%016llx\n",
  479. cpu_addr, cpu_addr + size - 1, pci_addr);
  480. /* We support only one IO range */
  481. if (hose->pci_io_size) {
  482. printk(KERN_INFO
  483. " \\--> Skipped (too many) !\n");
  484. continue;
  485. }
  486. #ifdef CONFIG_PPC32
  487. /* On 32 bits, limit I/O space to 16MB */
  488. if (size > 0x01000000)
  489. size = 0x01000000;
  490. /* 32 bits needs to map IOs here */
  491. hose->io_base_virt = ioremap(cpu_addr, size);
  492. /* Expect trouble if pci_addr is not 0 */
  493. if (primary)
  494. isa_io_base =
  495. (unsigned long)hose->io_base_virt;
  496. #endif /* CONFIG_PPC32 */
  497. /* pci_io_size and io_base_phys always represent IO
  498. * space starting at 0 so we factor in pci_addr
  499. */
  500. hose->pci_io_size = pci_addr + size;
  501. hose->io_base_phys = cpu_addr - pci_addr;
  502. /* Build resource */
  503. res = &hose->io_resource;
  504. res->flags = IORESOURCE_IO;
  505. res->start = pci_addr;
  506. break;
  507. case 2: /* PCI Memory space */
  508. printk(KERN_INFO
  509. " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n",
  510. cpu_addr, cpu_addr + size - 1, pci_addr,
  511. (pci_space & 0x40000000) ? "Prefetch" : "");
  512. /* We support only 3 memory ranges */
  513. if (memno >= 3) {
  514. printk(KERN_INFO
  515. " \\--> Skipped (too many) !\n");
  516. continue;
  517. }
  518. /* Handles ISA memory hole space here */
  519. if (pci_addr == 0) {
  520. isa_mb = cpu_addr;
  521. isa_hole = memno;
  522. if (primary || isa_mem_base == 0)
  523. isa_mem_base = cpu_addr;
  524. }
  525. /* We get the PCI/Mem offset from the first range or
  526. * the, current one if the offset came from an ISA
  527. * hole. If they don't match, bugger.
  528. */
  529. if (memno == 0 ||
  530. (isa_hole >= 0 && pci_addr != 0 &&
  531. hose->pci_mem_offset == isa_mb))
  532. hose->pci_mem_offset = cpu_addr - pci_addr;
  533. else if (pci_addr != 0 &&
  534. hose->pci_mem_offset != cpu_addr - pci_addr) {
  535. printk(KERN_INFO
  536. " \\--> Skipped (offset mismatch) !\n");
  537. continue;
  538. }
  539. /* Build resource */
  540. res = &hose->mem_resources[memno++];
  541. res->flags = IORESOURCE_MEM;
  542. if (pci_space & 0x40000000)
  543. res->flags |= IORESOURCE_PREFETCH;
  544. res->start = cpu_addr;
  545. break;
  546. }
  547. if (res != NULL) {
  548. res->name = dev->full_name;
  549. res->end = res->start + size - 1;
  550. res->parent = NULL;
  551. res->sibling = NULL;
  552. res->child = NULL;
  553. }
  554. }
  555. /* Out of paranoia, let's put the ISA hole last if any */
  556. if (isa_hole >= 0 && memno > 0 && isa_hole != (memno-1)) {
  557. struct resource tmp = hose->mem_resources[isa_hole];
  558. hose->mem_resources[isa_hole] = hose->mem_resources[memno-1];
  559. hose->mem_resources[memno-1] = tmp;
  560. }
  561. }
  562. /* Decide whether to display the domain number in /proc */
  563. int pci_proc_domain(struct pci_bus *bus)
  564. {
  565. struct pci_controller *hose = pci_bus_to_host(bus);
  566. #ifdef CONFIG_PPC64
  567. return hose->buid != 0;
  568. #else
  569. if (!(ppc_pci_flags & PPC_PCI_ENABLE_PROC_DOMAINS))
  570. return 0;
  571. if (ppc_pci_flags & PPC_PCI_COMPAT_DOMAIN_0)
  572. return hose->global_number != 0;
  573. return 1;
  574. #endif
  575. }
  576. void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  577. struct resource *res)
  578. {
  579. resource_size_t offset = 0, mask = (resource_size_t)-1;
  580. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  581. if (!hose)
  582. return;
  583. if (res->flags & IORESOURCE_IO) {
  584. offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  585. mask = 0xffffffffu;
  586. } else if (res->flags & IORESOURCE_MEM)
  587. offset = hose->pci_mem_offset;
  588. region->start = (res->start - offset) & mask;
  589. region->end = (res->end - offset) & mask;
  590. }
  591. EXPORT_SYMBOL(pcibios_resource_to_bus);
  592. void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  593. struct pci_bus_region *region)
  594. {
  595. resource_size_t offset = 0, mask = (resource_size_t)-1;
  596. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  597. if (!hose)
  598. return;
  599. if (res->flags & IORESOURCE_IO) {
  600. offset = (unsigned long)hose->io_base_virt - _IO_BASE;
  601. mask = 0xffffffffu;
  602. } else if (res->flags & IORESOURCE_MEM)
  603. offset = hose->pci_mem_offset;
  604. res->start = (region->start + offset) & mask;
  605. res->end = (region->end + offset) & mask;
  606. }
  607. EXPORT_SYMBOL(pcibios_bus_to_resource);