pci.c 17 KB

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