pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /* $Id: pci.c,v 1.39 2002/01/05 01:13:43 davem Exp $
  2. * pci.c: UltraSparc PCI controller support.
  3. *
  4. * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
  6. * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <linux/sched.h>
  12. #include <linux/capability.h>
  13. #include <linux/errno.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/msi.h>
  16. #include <linux/irq.h>
  17. #include <linux/init.h>
  18. #include <asm/uaccess.h>
  19. #include <asm/pbm.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/irq.h>
  22. #include <asm/ebus.h>
  23. #include <asm/isa.h>
  24. #include <asm/prom.h>
  25. unsigned long pci_memspace_mask = 0xffffffffUL;
  26. #ifndef CONFIG_PCI
  27. /* A "nop" PCI implementation. */
  28. asmlinkage int sys_pciconfig_read(unsigned long bus, unsigned long dfn,
  29. unsigned long off, unsigned long len,
  30. unsigned char *buf)
  31. {
  32. return 0;
  33. }
  34. asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn,
  35. unsigned long off, unsigned long len,
  36. unsigned char *buf)
  37. {
  38. return 0;
  39. }
  40. #else
  41. /* List of all PCI controllers found in the system. */
  42. struct pci_controller_info *pci_controller_root = NULL;
  43. /* Each PCI controller found gets a unique index. */
  44. int pci_num_controllers = 0;
  45. volatile int pci_poke_in_progress;
  46. volatile int pci_poke_cpu = -1;
  47. volatile int pci_poke_faulted;
  48. static DEFINE_SPINLOCK(pci_poke_lock);
  49. void pci_config_read8(u8 *addr, u8 *ret)
  50. {
  51. unsigned long flags;
  52. u8 byte;
  53. spin_lock_irqsave(&pci_poke_lock, flags);
  54. pci_poke_cpu = smp_processor_id();
  55. pci_poke_in_progress = 1;
  56. pci_poke_faulted = 0;
  57. __asm__ __volatile__("membar #Sync\n\t"
  58. "lduba [%1] %2, %0\n\t"
  59. "membar #Sync"
  60. : "=r" (byte)
  61. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  62. : "memory");
  63. pci_poke_in_progress = 0;
  64. pci_poke_cpu = -1;
  65. if (!pci_poke_faulted)
  66. *ret = byte;
  67. spin_unlock_irqrestore(&pci_poke_lock, flags);
  68. }
  69. void pci_config_read16(u16 *addr, u16 *ret)
  70. {
  71. unsigned long flags;
  72. u16 word;
  73. spin_lock_irqsave(&pci_poke_lock, flags);
  74. pci_poke_cpu = smp_processor_id();
  75. pci_poke_in_progress = 1;
  76. pci_poke_faulted = 0;
  77. __asm__ __volatile__("membar #Sync\n\t"
  78. "lduha [%1] %2, %0\n\t"
  79. "membar #Sync"
  80. : "=r" (word)
  81. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  82. : "memory");
  83. pci_poke_in_progress = 0;
  84. pci_poke_cpu = -1;
  85. if (!pci_poke_faulted)
  86. *ret = word;
  87. spin_unlock_irqrestore(&pci_poke_lock, flags);
  88. }
  89. void pci_config_read32(u32 *addr, u32 *ret)
  90. {
  91. unsigned long flags;
  92. u32 dword;
  93. spin_lock_irqsave(&pci_poke_lock, flags);
  94. pci_poke_cpu = smp_processor_id();
  95. pci_poke_in_progress = 1;
  96. pci_poke_faulted = 0;
  97. __asm__ __volatile__("membar #Sync\n\t"
  98. "lduwa [%1] %2, %0\n\t"
  99. "membar #Sync"
  100. : "=r" (dword)
  101. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  102. : "memory");
  103. pci_poke_in_progress = 0;
  104. pci_poke_cpu = -1;
  105. if (!pci_poke_faulted)
  106. *ret = dword;
  107. spin_unlock_irqrestore(&pci_poke_lock, flags);
  108. }
  109. void pci_config_write8(u8 *addr, u8 val)
  110. {
  111. unsigned long flags;
  112. spin_lock_irqsave(&pci_poke_lock, flags);
  113. pci_poke_cpu = smp_processor_id();
  114. pci_poke_in_progress = 1;
  115. pci_poke_faulted = 0;
  116. __asm__ __volatile__("membar #Sync\n\t"
  117. "stba %0, [%1] %2\n\t"
  118. "membar #Sync"
  119. : /* no outputs */
  120. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  121. : "memory");
  122. pci_poke_in_progress = 0;
  123. pci_poke_cpu = -1;
  124. spin_unlock_irqrestore(&pci_poke_lock, flags);
  125. }
  126. void pci_config_write16(u16 *addr, u16 val)
  127. {
  128. unsigned long flags;
  129. spin_lock_irqsave(&pci_poke_lock, flags);
  130. pci_poke_cpu = smp_processor_id();
  131. pci_poke_in_progress = 1;
  132. pci_poke_faulted = 0;
  133. __asm__ __volatile__("membar #Sync\n\t"
  134. "stha %0, [%1] %2\n\t"
  135. "membar #Sync"
  136. : /* no outputs */
  137. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  138. : "memory");
  139. pci_poke_in_progress = 0;
  140. pci_poke_cpu = -1;
  141. spin_unlock_irqrestore(&pci_poke_lock, flags);
  142. }
  143. void pci_config_write32(u32 *addr, u32 val)
  144. {
  145. unsigned long flags;
  146. spin_lock_irqsave(&pci_poke_lock, flags);
  147. pci_poke_cpu = smp_processor_id();
  148. pci_poke_in_progress = 1;
  149. pci_poke_faulted = 0;
  150. __asm__ __volatile__("membar #Sync\n\t"
  151. "stwa %0, [%1] %2\n\t"
  152. "membar #Sync"
  153. : /* no outputs */
  154. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  155. : "memory");
  156. pci_poke_in_progress = 0;
  157. pci_poke_cpu = -1;
  158. spin_unlock_irqrestore(&pci_poke_lock, flags);
  159. }
  160. /* Probe for all PCI controllers in the system. */
  161. extern void sabre_init(struct device_node *, const char *);
  162. extern void psycho_init(struct device_node *, const char *);
  163. extern void schizo_init(struct device_node *, const char *);
  164. extern void schizo_plus_init(struct device_node *, const char *);
  165. extern void tomatillo_init(struct device_node *, const char *);
  166. extern void sun4v_pci_init(struct device_node *, const char *);
  167. static struct {
  168. char *model_name;
  169. void (*init)(struct device_node *, const char *);
  170. } pci_controller_table[] __initdata = {
  171. { "SUNW,sabre", sabre_init },
  172. { "pci108e,a000", sabre_init },
  173. { "pci108e,a001", sabre_init },
  174. { "SUNW,psycho", psycho_init },
  175. { "pci108e,8000", psycho_init },
  176. { "SUNW,schizo", schizo_init },
  177. { "pci108e,8001", schizo_init },
  178. { "SUNW,schizo+", schizo_plus_init },
  179. { "pci108e,8002", schizo_plus_init },
  180. { "SUNW,tomatillo", tomatillo_init },
  181. { "pci108e,a801", tomatillo_init },
  182. { "SUNW,sun4v-pci", sun4v_pci_init },
  183. };
  184. #define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
  185. sizeof(pci_controller_table[0]))
  186. static int __init pci_controller_init(const char *model_name, int namelen, struct device_node *dp)
  187. {
  188. int i;
  189. for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
  190. if (!strncmp(model_name,
  191. pci_controller_table[i].model_name,
  192. namelen)) {
  193. pci_controller_table[i].init(dp, model_name);
  194. return 1;
  195. }
  196. }
  197. return 0;
  198. }
  199. static int __init pci_is_controller(const char *model_name, int namelen, struct device_node *dp)
  200. {
  201. int i;
  202. for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
  203. if (!strncmp(model_name,
  204. pci_controller_table[i].model_name,
  205. namelen)) {
  206. return 1;
  207. }
  208. }
  209. return 0;
  210. }
  211. static int __init pci_controller_scan(int (*handler)(const char *, int, struct device_node *))
  212. {
  213. struct device_node *dp;
  214. int count = 0;
  215. for_each_node_by_name(dp, "pci") {
  216. struct property *prop;
  217. int len;
  218. prop = of_find_property(dp, "model", &len);
  219. if (!prop)
  220. prop = of_find_property(dp, "compatible", &len);
  221. if (prop) {
  222. const char *model = prop->value;
  223. int item_len = 0;
  224. /* Our value may be a multi-valued string in the
  225. * case of some compatible properties. For sanity,
  226. * only try the first one.
  227. */
  228. while (model[item_len] && len) {
  229. len--;
  230. item_len++;
  231. }
  232. if (handler(model, item_len, dp))
  233. count++;
  234. }
  235. }
  236. return count;
  237. }
  238. /* Is there some PCI controller in the system? */
  239. int __init pcic_present(void)
  240. {
  241. return pci_controller_scan(pci_is_controller);
  242. }
  243. struct pci_iommu_ops *pci_iommu_ops;
  244. EXPORT_SYMBOL(pci_iommu_ops);
  245. extern struct pci_iommu_ops pci_sun4u_iommu_ops,
  246. pci_sun4v_iommu_ops;
  247. /* Find each controller in the system, attach and initialize
  248. * software state structure for each and link into the
  249. * pci_controller_root. Setup the controller enough such
  250. * that bus scanning can be done.
  251. */
  252. static void __init pci_controller_probe(void)
  253. {
  254. if (tlb_type == hypervisor)
  255. pci_iommu_ops = &pci_sun4v_iommu_ops;
  256. else
  257. pci_iommu_ops = &pci_sun4u_iommu_ops;
  258. printk("PCI: Probing for controllers.\n");
  259. pci_controller_scan(pci_controller_init);
  260. }
  261. static void __init pci_scan_each_controller_bus(void)
  262. {
  263. struct pci_controller_info *p;
  264. for (p = pci_controller_root; p; p = p->next)
  265. p->scan_bus(p);
  266. }
  267. extern void power_init(void);
  268. static int __init pcibios_init(void)
  269. {
  270. pci_controller_probe();
  271. if (pci_controller_root == NULL)
  272. return 0;
  273. pci_scan_each_controller_bus();
  274. isa_init();
  275. ebus_init();
  276. power_init();
  277. return 0;
  278. }
  279. subsys_initcall(pcibios_init);
  280. void pcibios_fixup_bus(struct pci_bus *pbus)
  281. {
  282. struct pci_pbm_info *pbm = pbus->sysdata;
  283. /* Generic PCI bus probing sets these to point at
  284. * &io{port,mem}_resouce which is wrong for us.
  285. */
  286. pbus->resource[0] = &pbm->io_space;
  287. pbus->resource[1] = &pbm->mem_space;
  288. }
  289. struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r)
  290. {
  291. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  292. struct resource *root = NULL;
  293. if (r->flags & IORESOURCE_IO)
  294. root = &pbm->io_space;
  295. if (r->flags & IORESOURCE_MEM)
  296. root = &pbm->mem_space;
  297. return root;
  298. }
  299. void pcibios_update_irq(struct pci_dev *pdev, int irq)
  300. {
  301. }
  302. void pcibios_align_resource(void *data, struct resource *res,
  303. resource_size_t size, resource_size_t align)
  304. {
  305. }
  306. int pcibios_enable_device(struct pci_dev *pdev, int mask)
  307. {
  308. return 0;
  309. }
  310. void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
  311. struct resource *res)
  312. {
  313. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  314. struct resource zero_res, *root;
  315. zero_res.start = 0;
  316. zero_res.end = 0;
  317. zero_res.flags = res->flags;
  318. if (res->flags & IORESOURCE_IO)
  319. root = &pbm->io_space;
  320. else
  321. root = &pbm->mem_space;
  322. pbm->parent->resource_adjust(pdev, &zero_res, root);
  323. region->start = res->start - zero_res.start;
  324. region->end = res->end - zero_res.start;
  325. }
  326. EXPORT_SYMBOL(pcibios_resource_to_bus);
  327. void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
  328. struct pci_bus_region *region)
  329. {
  330. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  331. struct resource *root;
  332. res->start = region->start;
  333. res->end = region->end;
  334. if (res->flags & IORESOURCE_IO)
  335. root = &pbm->io_space;
  336. else
  337. root = &pbm->mem_space;
  338. pbm->parent->resource_adjust(pdev, res, root);
  339. }
  340. EXPORT_SYMBOL(pcibios_bus_to_resource);
  341. char * __init pcibios_setup(char *str)
  342. {
  343. return str;
  344. }
  345. /* Platform support for /proc/bus/pci/X/Y mmap()s. */
  346. /* If the user uses a host-bridge as the PCI device, he may use
  347. * this to perform a raw mmap() of the I/O or MEM space behind
  348. * that controller.
  349. *
  350. * This can be useful for execution of x86 PCI bios initialization code
  351. * on a PCI card, like the xfree86 int10 stuff does.
  352. */
  353. static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma,
  354. enum pci_mmap_state mmap_state)
  355. {
  356. struct pcidev_cookie *pcp = pdev->sysdata;
  357. struct pci_pbm_info *pbm;
  358. struct pci_controller_info *p;
  359. unsigned long space_size, user_offset, user_size;
  360. if (!pcp)
  361. return -ENXIO;
  362. pbm = pcp->pbm;
  363. if (!pbm)
  364. return -ENXIO;
  365. p = pbm->parent;
  366. if (p->pbms_same_domain) {
  367. unsigned long lowest, highest;
  368. lowest = ~0UL; highest = 0UL;
  369. if (mmap_state == pci_mmap_io) {
  370. if (p->pbm_A.io_space.flags) {
  371. lowest = p->pbm_A.io_space.start;
  372. highest = p->pbm_A.io_space.end + 1;
  373. }
  374. if (p->pbm_B.io_space.flags) {
  375. if (lowest > p->pbm_B.io_space.start)
  376. lowest = p->pbm_B.io_space.start;
  377. if (highest < p->pbm_B.io_space.end + 1)
  378. highest = p->pbm_B.io_space.end + 1;
  379. }
  380. space_size = highest - lowest;
  381. } else {
  382. if (p->pbm_A.mem_space.flags) {
  383. lowest = p->pbm_A.mem_space.start;
  384. highest = p->pbm_A.mem_space.end + 1;
  385. }
  386. if (p->pbm_B.mem_space.flags) {
  387. if (lowest > p->pbm_B.mem_space.start)
  388. lowest = p->pbm_B.mem_space.start;
  389. if (highest < p->pbm_B.mem_space.end + 1)
  390. highest = p->pbm_B.mem_space.end + 1;
  391. }
  392. space_size = highest - lowest;
  393. }
  394. } else {
  395. if (mmap_state == pci_mmap_io) {
  396. space_size = (pbm->io_space.end -
  397. pbm->io_space.start) + 1;
  398. } else {
  399. space_size = (pbm->mem_space.end -
  400. pbm->mem_space.start) + 1;
  401. }
  402. }
  403. /* Make sure the request is in range. */
  404. user_offset = vma->vm_pgoff << PAGE_SHIFT;
  405. user_size = vma->vm_end - vma->vm_start;
  406. if (user_offset >= space_size ||
  407. (user_offset + user_size) > space_size)
  408. return -EINVAL;
  409. if (p->pbms_same_domain) {
  410. unsigned long lowest = ~0UL;
  411. if (mmap_state == pci_mmap_io) {
  412. if (p->pbm_A.io_space.flags)
  413. lowest = p->pbm_A.io_space.start;
  414. if (p->pbm_B.io_space.flags &&
  415. lowest > p->pbm_B.io_space.start)
  416. lowest = p->pbm_B.io_space.start;
  417. } else {
  418. if (p->pbm_A.mem_space.flags)
  419. lowest = p->pbm_A.mem_space.start;
  420. if (p->pbm_B.mem_space.flags &&
  421. lowest > p->pbm_B.mem_space.start)
  422. lowest = p->pbm_B.mem_space.start;
  423. }
  424. vma->vm_pgoff = (lowest + user_offset) >> PAGE_SHIFT;
  425. } else {
  426. if (mmap_state == pci_mmap_io) {
  427. vma->vm_pgoff = (pbm->io_space.start +
  428. user_offset) >> PAGE_SHIFT;
  429. } else {
  430. vma->vm_pgoff = (pbm->mem_space.start +
  431. user_offset) >> PAGE_SHIFT;
  432. }
  433. }
  434. return 0;
  435. }
  436. /* Adjust vm_pgoff of VMA such that it is the physical page offset corresponding
  437. * to the 32-bit pci bus offset for DEV requested by the user.
  438. *
  439. * Basically, the user finds the base address for his device which he wishes
  440. * to mmap. They read the 32-bit value from the config space base register,
  441. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  442. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  443. *
  444. * Returns negative error code on failure, zero on success.
  445. */
  446. static int __pci_mmap_make_offset(struct pci_dev *dev, struct vm_area_struct *vma,
  447. enum pci_mmap_state mmap_state)
  448. {
  449. unsigned long user_offset = vma->vm_pgoff << PAGE_SHIFT;
  450. unsigned long user32 = user_offset & pci_memspace_mask;
  451. unsigned long largest_base, this_base, addr32;
  452. int i;
  453. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
  454. return __pci_mmap_make_offset_bus(dev, vma, mmap_state);
  455. /* Figure out which base address this is for. */
  456. largest_base = 0UL;
  457. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  458. struct resource *rp = &dev->resource[i];
  459. /* Active? */
  460. if (!rp->flags)
  461. continue;
  462. /* Same type? */
  463. if (i == PCI_ROM_RESOURCE) {
  464. if (mmap_state != pci_mmap_mem)
  465. continue;
  466. } else {
  467. if ((mmap_state == pci_mmap_io &&
  468. (rp->flags & IORESOURCE_IO) == 0) ||
  469. (mmap_state == pci_mmap_mem &&
  470. (rp->flags & IORESOURCE_MEM) == 0))
  471. continue;
  472. }
  473. this_base = rp->start;
  474. addr32 = (this_base & PAGE_MASK) & pci_memspace_mask;
  475. if (mmap_state == pci_mmap_io)
  476. addr32 &= 0xffffff;
  477. if (addr32 <= user32 && this_base > largest_base)
  478. largest_base = this_base;
  479. }
  480. if (largest_base == 0UL)
  481. return -EINVAL;
  482. /* Now construct the final physical address. */
  483. if (mmap_state == pci_mmap_io)
  484. vma->vm_pgoff = (((largest_base & ~0xffffffUL) | user32) >> PAGE_SHIFT);
  485. else
  486. vma->vm_pgoff = (((largest_base & ~(pci_memspace_mask)) | user32) >> PAGE_SHIFT);
  487. return 0;
  488. }
  489. /* Set vm_flags of VMA, as appropriate for this architecture, for a pci device
  490. * mapping.
  491. */
  492. static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
  493. enum pci_mmap_state mmap_state)
  494. {
  495. vma->vm_flags |= (VM_IO | VM_RESERVED);
  496. }
  497. /* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  498. * device mapping.
  499. */
  500. static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
  501. enum pci_mmap_state mmap_state)
  502. {
  503. /* Our io_remap_pfn_range takes care of this, do nothing. */
  504. }
  505. /* Perform the actual remap of the pages for a PCI device mapping, as appropriate
  506. * for this architecture. The region in the process to map is described by vm_start
  507. * and vm_end members of VMA, the base physical address is found in vm_pgoff.
  508. * The pci device structure is provided so that architectures may make mapping
  509. * decisions on a per-device or per-bus basis.
  510. *
  511. * Returns a negative error code on failure, zero on success.
  512. */
  513. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  514. enum pci_mmap_state mmap_state,
  515. int write_combine)
  516. {
  517. int ret;
  518. ret = __pci_mmap_make_offset(dev, vma, mmap_state);
  519. if (ret < 0)
  520. return ret;
  521. __pci_mmap_set_flags(dev, vma, mmap_state);
  522. __pci_mmap_set_pgprot(dev, vma, mmap_state);
  523. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  524. ret = io_remap_pfn_range(vma, vma->vm_start,
  525. vma->vm_pgoff,
  526. vma->vm_end - vma->vm_start,
  527. vma->vm_page_prot);
  528. if (ret)
  529. return ret;
  530. return 0;
  531. }
  532. /* Return the domain nuber for this pci bus */
  533. int pci_domain_nr(struct pci_bus *pbus)
  534. {
  535. struct pci_pbm_info *pbm = pbus->sysdata;
  536. int ret;
  537. if (pbm == NULL || pbm->parent == NULL) {
  538. ret = -ENXIO;
  539. } else {
  540. struct pci_controller_info *p = pbm->parent;
  541. ret = p->index;
  542. if (p->pbms_same_domain == 0)
  543. ret = ((ret << 1) +
  544. ((pbm == &pbm->parent->pbm_B) ? 1 : 0));
  545. }
  546. return ret;
  547. }
  548. EXPORT_SYMBOL(pci_domain_nr);
  549. #ifdef CONFIG_PCI_MSI
  550. int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
  551. {
  552. struct pcidev_cookie *pcp = pdev->sysdata;
  553. struct pci_pbm_info *pbm = pcp->pbm;
  554. struct pci_controller_info *p = pbm->parent;
  555. int virt_irq, err;
  556. if (!pbm->msi_num || !p->setup_msi_irq)
  557. return -EINVAL;
  558. err = p->setup_msi_irq(&virt_irq, pdev, desc);
  559. if (err < 0)
  560. return err;
  561. return virt_irq;
  562. }
  563. void arch_teardown_msi_irq(unsigned int virt_irq)
  564. {
  565. struct msi_desc *entry = get_irq_data(virt_irq);
  566. struct pci_dev *pdev = entry->dev;
  567. struct pcidev_cookie *pcp = pdev->sysdata;
  568. struct pci_pbm_info *pbm = pcp->pbm;
  569. struct pci_controller_info *p = pbm->parent;
  570. if (!pbm->msi_num || !p->setup_msi_irq)
  571. return;
  572. return p->teardown_msi_irq(virt_irq, pdev);
  573. }
  574. #endif /* !(CONFIG_PCI_MSI) */
  575. #endif /* !(CONFIG_PCI) */