ioport.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * ioport.c: Simple io mapping allocator.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. *
  7. * 1996: sparc_free_io, 1999: ioremap()/iounmap() by Pete Zaitcev.
  8. *
  9. * 2000/01/29
  10. * <rth> zait: as long as pci_alloc_consistent produces something addressable,
  11. * things are ok.
  12. * <zaitcev> rth: no, it is relevant, because get_free_pages returns you a
  13. * pointer into the big page mapping
  14. * <rth> zait: so what?
  15. * <rth> zait: remap_it_my_way(virt_to_phys(get_free_page()))
  16. * <zaitcev> Hmm
  17. * <zaitcev> Suppose I did this remap_it_my_way(virt_to_phys(get_free_page())).
  18. * So far so good.
  19. * <zaitcev> Now, driver calls pci_free_consistent(with result of
  20. * remap_it_my_way()).
  21. * <zaitcev> How do you find the address to pass to free_pages()?
  22. * <rth> zait: walk the page tables? It's only two or three level after all.
  23. * <rth> zait: you have to walk them anyway to remove the mapping.
  24. * <zaitcev> Hmm
  25. * <zaitcev> Sounds reasonable
  26. */
  27. #include <linux/module.h>
  28. #include <linux/sched.h>
  29. #include <linux/kernel.h>
  30. #include <linux/errno.h>
  31. #include <linux/types.h>
  32. #include <linux/ioport.h>
  33. #include <linux/mm.h>
  34. #include <linux/slab.h>
  35. #include <linux/pci.h> /* struct pci_dev */
  36. #include <linux/proc_fs.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/scatterlist.h>
  39. #include <linux/of_device.h>
  40. #include <asm/io.h>
  41. #include <asm/vaddrs.h>
  42. #include <asm/oplib.h>
  43. #include <asm/prom.h>
  44. #include <asm/page.h>
  45. #include <asm/pgalloc.h>
  46. #include <asm/dma.h>
  47. #include <asm/iommu.h>
  48. #include <asm/io-unit.h>
  49. #include <asm/leon.h>
  50. /* This function must make sure that caches and memory are coherent after DMA
  51. * On LEON systems without cache snooping it flushes the entire D-CACHE.
  52. */
  53. #ifndef CONFIG_SPARC_LEON
  54. static inline void dma_make_coherent(unsigned long pa, unsigned long len)
  55. {
  56. }
  57. #else
  58. static inline void dma_make_coherent(unsigned long pa, unsigned long len)
  59. {
  60. if (!sparc_leon3_snooping_enabled())
  61. leon_flush_dcache_all();
  62. }
  63. #endif
  64. static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
  65. static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
  66. unsigned long size, char *name);
  67. static void _sparc_free_io(struct resource *res);
  68. static void register_proc_sparc_ioport(void);
  69. /* This points to the next to use virtual memory for DVMA mappings */
  70. static struct resource _sparc_dvma = {
  71. .name = "sparc_dvma", .start = DVMA_VADDR, .end = DVMA_END - 1
  72. };
  73. /* This points to the start of I/O mappings, cluable from outside. */
  74. /*ext*/ struct resource sparc_iomap = {
  75. .name = "sparc_iomap", .start = IOBASE_VADDR, .end = IOBASE_END - 1
  76. };
  77. /*
  78. * Our mini-allocator...
  79. * Boy this is gross! We need it because we must map I/O for
  80. * timers and interrupt controller before the kmalloc is available.
  81. */
  82. #define XNMLN 15
  83. #define XNRES 10 /* SS-10 uses 8 */
  84. struct xresource {
  85. struct resource xres; /* Must be first */
  86. int xflag; /* 1 == used */
  87. char xname[XNMLN+1];
  88. };
  89. static struct xresource xresv[XNRES];
  90. static struct xresource *xres_alloc(void) {
  91. struct xresource *xrp;
  92. int n;
  93. xrp = xresv;
  94. for (n = 0; n < XNRES; n++) {
  95. if (xrp->xflag == 0) {
  96. xrp->xflag = 1;
  97. return xrp;
  98. }
  99. xrp++;
  100. }
  101. return NULL;
  102. }
  103. static void xres_free(struct xresource *xrp) {
  104. xrp->xflag = 0;
  105. }
  106. /*
  107. * These are typically used in PCI drivers
  108. * which are trying to be cross-platform.
  109. *
  110. * Bus type is always zero on IIep.
  111. */
  112. void __iomem *ioremap(unsigned long offset, unsigned long size)
  113. {
  114. char name[14];
  115. sprintf(name, "phys_%08x", (u32)offset);
  116. return _sparc_alloc_io(0, offset, size, name);
  117. }
  118. EXPORT_SYMBOL(ioremap);
  119. /*
  120. * Comlimentary to ioremap().
  121. */
  122. void iounmap(volatile void __iomem *virtual)
  123. {
  124. unsigned long vaddr = (unsigned long) virtual & PAGE_MASK;
  125. struct resource *res;
  126. /*
  127. * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case.
  128. * This probably warrants some sort of hashing.
  129. */
  130. if ((res = lookup_resource(&sparc_iomap, vaddr)) == NULL) {
  131. printk("free_io/iounmap: cannot free %lx\n", vaddr);
  132. return;
  133. }
  134. _sparc_free_io(res);
  135. if ((char *)res >= (char*)xresv && (char *)res < (char *)&xresv[XNRES]) {
  136. xres_free((struct xresource *)res);
  137. } else {
  138. kfree(res);
  139. }
  140. }
  141. EXPORT_SYMBOL(iounmap);
  142. void __iomem *of_ioremap(struct resource *res, unsigned long offset,
  143. unsigned long size, char *name)
  144. {
  145. return _sparc_alloc_io(res->flags & 0xF,
  146. res->start + offset,
  147. size, name);
  148. }
  149. EXPORT_SYMBOL(of_ioremap);
  150. void of_iounmap(struct resource *res, void __iomem *base, unsigned long size)
  151. {
  152. iounmap(base);
  153. }
  154. EXPORT_SYMBOL(of_iounmap);
  155. /*
  156. * Meat of mapping
  157. */
  158. static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
  159. unsigned long size, char *name)
  160. {
  161. static int printed_full;
  162. struct xresource *xres;
  163. struct resource *res;
  164. char *tack;
  165. int tlen;
  166. void __iomem *va; /* P3 diag */
  167. if (name == NULL) name = "???";
  168. if ((xres = xres_alloc()) != 0) {
  169. tack = xres->xname;
  170. res = &xres->xres;
  171. } else {
  172. if (!printed_full) {
  173. printk("ioremap: done with statics, switching to malloc\n");
  174. printed_full = 1;
  175. }
  176. tlen = strlen(name);
  177. tack = kmalloc(sizeof (struct resource) + tlen + 1, GFP_KERNEL);
  178. if (tack == NULL) return NULL;
  179. memset(tack, 0, sizeof(struct resource));
  180. res = (struct resource *) tack;
  181. tack += sizeof (struct resource);
  182. }
  183. strlcpy(tack, name, XNMLN+1);
  184. res->name = tack;
  185. va = _sparc_ioremap(res, busno, phys, size);
  186. /* printk("ioremap(0x%x:%08lx[0x%lx])=%p\n", busno, phys, size, va); */ /* P3 diag */
  187. return va;
  188. }
  189. /*
  190. */
  191. static void __iomem *
  192. _sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz)
  193. {
  194. unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK);
  195. if (allocate_resource(&sparc_iomap, res,
  196. (offset + sz + PAGE_SIZE-1) & PAGE_MASK,
  197. sparc_iomap.start, sparc_iomap.end, PAGE_SIZE, NULL, NULL) != 0) {
  198. /* Usually we cannot see printks in this case. */
  199. prom_printf("alloc_io_res(%s): cannot occupy\n",
  200. (res->name != NULL)? res->name: "???");
  201. prom_halt();
  202. }
  203. pa &= PAGE_MASK;
  204. sparc_mapiorange(bus, pa, res->start, resource_size(res));
  205. return (void __iomem *)(unsigned long)(res->start + offset);
  206. }
  207. /*
  208. * Comlimentary to _sparc_ioremap().
  209. */
  210. static void _sparc_free_io(struct resource *res)
  211. {
  212. unsigned long plen;
  213. plen = resource_size(res);
  214. BUG_ON((plen & (PAGE_SIZE-1)) != 0);
  215. sparc_unmapiorange(res->start, plen);
  216. release_resource(res);
  217. }
  218. #ifdef CONFIG_SBUS
  219. void sbus_set_sbus64(struct device *dev, int x)
  220. {
  221. printk("sbus_set_sbus64: unsupported\n");
  222. }
  223. EXPORT_SYMBOL(sbus_set_sbus64);
  224. /*
  225. * Allocate a chunk of memory suitable for DMA.
  226. * Typically devices use them for control blocks.
  227. * CPU may access them without any explicit flushing.
  228. */
  229. static void *sbus_alloc_coherent(struct device *dev, size_t len,
  230. dma_addr_t *dma_addrp, gfp_t gfp)
  231. {
  232. struct platform_device *op = to_platform_device(dev);
  233. unsigned long len_total = PAGE_ALIGN(len);
  234. unsigned long va;
  235. struct resource *res;
  236. int order;
  237. /* XXX why are some lengths signed, others unsigned? */
  238. if (len <= 0) {
  239. return NULL;
  240. }
  241. /* XXX So what is maxphys for us and how do drivers know it? */
  242. if (len > 256*1024) { /* __get_free_pages() limit */
  243. return NULL;
  244. }
  245. order = get_order(len_total);
  246. if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0)
  247. goto err_nopages;
  248. if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL)
  249. goto err_nomem;
  250. if (allocate_resource(&_sparc_dvma, res, len_total,
  251. _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
  252. printk("sbus_alloc_consistent: cannot occupy 0x%lx", len_total);
  253. goto err_nova;
  254. }
  255. // XXX The mmu_map_dma_area does this for us below, see comments.
  256. // sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
  257. /*
  258. * XXX That's where sdev would be used. Currently we load
  259. * all iommu tables with the same translations.
  260. */
  261. if (mmu_map_dma_area(dev, dma_addrp, va, res->start, len_total) != 0)
  262. goto err_noiommu;
  263. res->name = op->dev.of_node->name;
  264. return (void *)(unsigned long)res->start;
  265. err_noiommu:
  266. release_resource(res);
  267. err_nova:
  268. kfree(res);
  269. err_nomem:
  270. free_pages(va, order);
  271. err_nopages:
  272. return NULL;
  273. }
  274. static void sbus_free_coherent(struct device *dev, size_t n, void *p,
  275. dma_addr_t ba)
  276. {
  277. struct resource *res;
  278. struct page *pgv;
  279. if ((res = lookup_resource(&_sparc_dvma,
  280. (unsigned long)p)) == NULL) {
  281. printk("sbus_free_consistent: cannot free %p\n", p);
  282. return;
  283. }
  284. if (((unsigned long)p & (PAGE_SIZE-1)) != 0) {
  285. printk("sbus_free_consistent: unaligned va %p\n", p);
  286. return;
  287. }
  288. n = PAGE_ALIGN(n);
  289. if (resource_size(res) != n) {
  290. printk("sbus_free_consistent: region 0x%lx asked 0x%zx\n",
  291. (long)resource_size(res), n);
  292. return;
  293. }
  294. release_resource(res);
  295. kfree(res);
  296. pgv = virt_to_page(p);
  297. mmu_unmap_dma_area(dev, ba, n);
  298. __free_pages(pgv, get_order(n));
  299. }
  300. /*
  301. * Map a chunk of memory so that devices can see it.
  302. * CPU view of this memory may be inconsistent with
  303. * a device view and explicit flushing is necessary.
  304. */
  305. static dma_addr_t sbus_map_page(struct device *dev, struct page *page,
  306. unsigned long offset, size_t len,
  307. enum dma_data_direction dir,
  308. struct dma_attrs *attrs)
  309. {
  310. void *va = page_address(page) + offset;
  311. /* XXX why are some lengths signed, others unsigned? */
  312. if (len <= 0) {
  313. return 0;
  314. }
  315. /* XXX So what is maxphys for us and how do drivers know it? */
  316. if (len > 256*1024) { /* __get_free_pages() limit */
  317. return 0;
  318. }
  319. return mmu_get_scsi_one(dev, va, len);
  320. }
  321. static void sbus_unmap_page(struct device *dev, dma_addr_t ba, size_t n,
  322. enum dma_data_direction dir, struct dma_attrs *attrs)
  323. {
  324. mmu_release_scsi_one(dev, ba, n);
  325. }
  326. static int sbus_map_sg(struct device *dev, struct scatterlist *sg, int n,
  327. enum dma_data_direction dir, struct dma_attrs *attrs)
  328. {
  329. mmu_get_scsi_sgl(dev, sg, n);
  330. /*
  331. * XXX sparc64 can return a partial length here. sun4c should do this
  332. * but it currently panics if it can't fulfill the request - Anton
  333. */
  334. return n;
  335. }
  336. static void sbus_unmap_sg(struct device *dev, struct scatterlist *sg, int n,
  337. enum dma_data_direction dir, struct dma_attrs *attrs)
  338. {
  339. mmu_release_scsi_sgl(dev, sg, n);
  340. }
  341. static void sbus_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
  342. int n, enum dma_data_direction dir)
  343. {
  344. BUG();
  345. }
  346. static void sbus_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
  347. int n, enum dma_data_direction dir)
  348. {
  349. BUG();
  350. }
  351. struct dma_map_ops sbus_dma_ops = {
  352. .alloc_coherent = sbus_alloc_coherent,
  353. .free_coherent = sbus_free_coherent,
  354. .map_page = sbus_map_page,
  355. .unmap_page = sbus_unmap_page,
  356. .map_sg = sbus_map_sg,
  357. .unmap_sg = sbus_unmap_sg,
  358. .sync_sg_for_cpu = sbus_sync_sg_for_cpu,
  359. .sync_sg_for_device = sbus_sync_sg_for_device,
  360. };
  361. static int __init sparc_register_ioport(void)
  362. {
  363. register_proc_sparc_ioport();
  364. return 0;
  365. }
  366. arch_initcall(sparc_register_ioport);
  367. #endif /* CONFIG_SBUS */
  368. /* LEON reuses PCI DMA ops */
  369. #if defined(CONFIG_PCI) || defined(CONFIG_SPARC_LEON)
  370. /* Allocate and map kernel buffer using consistent mode DMA for a device.
  371. * hwdev should be valid struct pci_dev pointer for PCI devices.
  372. */
  373. static void *pci32_alloc_coherent(struct device *dev, size_t len,
  374. dma_addr_t *pba, gfp_t gfp)
  375. {
  376. unsigned long len_total = PAGE_ALIGN(len);
  377. void *va;
  378. struct resource *res;
  379. int order;
  380. if (len == 0) {
  381. return NULL;
  382. }
  383. if (len > 256*1024) { /* __get_free_pages() limit */
  384. return NULL;
  385. }
  386. order = get_order(len_total);
  387. va = (void *) __get_free_pages(GFP_KERNEL, order);
  388. if (va == NULL) {
  389. printk("pci_alloc_consistent: no %ld pages\n", len_total>>PAGE_SHIFT);
  390. goto err_nopages;
  391. }
  392. if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
  393. printk("pci_alloc_consistent: no core\n");
  394. goto err_nomem;
  395. }
  396. if (allocate_resource(&_sparc_dvma, res, len_total,
  397. _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
  398. printk("pci_alloc_consistent: cannot occupy 0x%lx", len_total);
  399. goto err_nova;
  400. }
  401. sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
  402. *pba = virt_to_phys(va); /* equals virt_to_bus (R.I.P.) for us. */
  403. return (void *) res->start;
  404. err_nova:
  405. kfree(res);
  406. err_nomem:
  407. free_pages((unsigned long)va, order);
  408. err_nopages:
  409. return NULL;
  410. }
  411. /* Free and unmap a consistent DMA buffer.
  412. * cpu_addr is what was returned from pci_alloc_consistent,
  413. * size must be the same as what as passed into pci_alloc_consistent,
  414. * and likewise dma_addr must be the same as what *dma_addrp was set to.
  415. *
  416. * References to the memory and mappings associated with cpu_addr/dma_addr
  417. * past this call are illegal.
  418. */
  419. static void pci32_free_coherent(struct device *dev, size_t n, void *p,
  420. dma_addr_t ba)
  421. {
  422. struct resource *res;
  423. if ((res = lookup_resource(&_sparc_dvma,
  424. (unsigned long)p)) == NULL) {
  425. printk("pci_free_consistent: cannot free %p\n", p);
  426. return;
  427. }
  428. if (((unsigned long)p & (PAGE_SIZE-1)) != 0) {
  429. printk("pci_free_consistent: unaligned va %p\n", p);
  430. return;
  431. }
  432. n = PAGE_ALIGN(n);
  433. if (resource_size(res) != n) {
  434. printk("pci_free_consistent: region 0x%lx asked 0x%lx\n",
  435. (long)resource_size(res), (long)n);
  436. return;
  437. }
  438. dma_make_coherent(ba, n);
  439. sparc_unmapiorange((unsigned long)p, n);
  440. release_resource(res);
  441. kfree(res);
  442. free_pages((unsigned long)phys_to_virt(ba), get_order(n));
  443. }
  444. /*
  445. * Same as pci_map_single, but with pages.
  446. */
  447. static dma_addr_t pci32_map_page(struct device *dev, struct page *page,
  448. unsigned long offset, size_t size,
  449. enum dma_data_direction dir,
  450. struct dma_attrs *attrs)
  451. {
  452. /* IIep is write-through, not flushing. */
  453. return page_to_phys(page) + offset;
  454. }
  455. static void pci32_unmap_page(struct device *dev, dma_addr_t ba, size_t size,
  456. enum dma_data_direction dir, struct dma_attrs *attrs)
  457. {
  458. if (dir != PCI_DMA_TODEVICE)
  459. dma_make_coherent(ba, PAGE_ALIGN(size));
  460. }
  461. /* Map a set of buffers described by scatterlist in streaming
  462. * mode for DMA. This is the scather-gather version of the
  463. * above pci_map_single interface. Here the scatter gather list
  464. * elements are each tagged with the appropriate dma address
  465. * and length. They are obtained via sg_dma_{address,length}(SG).
  466. *
  467. * NOTE: An implementation may be able to use a smaller number of
  468. * DMA address/length pairs than there are SG table elements.
  469. * (for example via virtual mapping capabilities)
  470. * The routine returns the number of addr/length pairs actually
  471. * used, at most nents.
  472. *
  473. * Device ownership issues as mentioned above for pci_map_single are
  474. * the same here.
  475. */
  476. static int pci32_map_sg(struct device *device, struct scatterlist *sgl,
  477. int nents, enum dma_data_direction dir,
  478. struct dma_attrs *attrs)
  479. {
  480. struct scatterlist *sg;
  481. int n;
  482. /* IIep is write-through, not flushing. */
  483. for_each_sg(sgl, sg, nents, n) {
  484. sg->dma_address = sg_phys(sg);
  485. sg->dma_length = sg->length;
  486. }
  487. return nents;
  488. }
  489. /* Unmap a set of streaming mode DMA translations.
  490. * Again, cpu read rules concerning calls here are the same as for
  491. * pci_unmap_single() above.
  492. */
  493. static void pci32_unmap_sg(struct device *dev, struct scatterlist *sgl,
  494. int nents, enum dma_data_direction dir,
  495. struct dma_attrs *attrs)
  496. {
  497. struct scatterlist *sg;
  498. int n;
  499. if (dir != PCI_DMA_TODEVICE) {
  500. for_each_sg(sgl, sg, nents, n) {
  501. dma_make_coherent(sg_phys(sg), PAGE_ALIGN(sg->length));
  502. }
  503. }
  504. }
  505. /* Make physical memory consistent for a single
  506. * streaming mode DMA translation before or after a transfer.
  507. *
  508. * If you perform a pci_map_single() but wish to interrogate the
  509. * buffer using the cpu, yet do not wish to teardown the PCI dma
  510. * mapping, you must call this function before doing so. At the
  511. * next point you give the PCI dma address back to the card, you
  512. * must first perform a pci_dma_sync_for_device, and then the
  513. * device again owns the buffer.
  514. */
  515. static void pci32_sync_single_for_cpu(struct device *dev, dma_addr_t ba,
  516. size_t size, enum dma_data_direction dir)
  517. {
  518. if (dir != PCI_DMA_TODEVICE) {
  519. dma_make_coherent(ba, PAGE_ALIGN(size));
  520. }
  521. }
  522. static void pci32_sync_single_for_device(struct device *dev, dma_addr_t ba,
  523. size_t size, enum dma_data_direction dir)
  524. {
  525. if (dir != PCI_DMA_TODEVICE) {
  526. dma_make_coherent(ba, PAGE_ALIGN(size));
  527. }
  528. }
  529. /* Make physical memory consistent for a set of streaming
  530. * mode DMA translations after a transfer.
  531. *
  532. * The same as pci_dma_sync_single_* but for a scatter-gather list,
  533. * same rules and usage.
  534. */
  535. static void pci32_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl,
  536. int nents, enum dma_data_direction dir)
  537. {
  538. struct scatterlist *sg;
  539. int n;
  540. if (dir != PCI_DMA_TODEVICE) {
  541. for_each_sg(sgl, sg, nents, n) {
  542. dma_make_coherent(sg_phys(sg), PAGE_ALIGN(sg->length));
  543. }
  544. }
  545. }
  546. static void pci32_sync_sg_for_device(struct device *device, struct scatterlist *sgl,
  547. int nents, enum dma_data_direction dir)
  548. {
  549. struct scatterlist *sg;
  550. int n;
  551. if (dir != PCI_DMA_TODEVICE) {
  552. for_each_sg(sgl, sg, nents, n) {
  553. dma_make_coherent(sg_phys(sg), PAGE_ALIGN(sg->length));
  554. }
  555. }
  556. }
  557. struct dma_map_ops pci32_dma_ops = {
  558. .alloc_coherent = pci32_alloc_coherent,
  559. .free_coherent = pci32_free_coherent,
  560. .map_page = pci32_map_page,
  561. .unmap_page = pci32_unmap_page,
  562. .map_sg = pci32_map_sg,
  563. .unmap_sg = pci32_unmap_sg,
  564. .sync_single_for_cpu = pci32_sync_single_for_cpu,
  565. .sync_single_for_device = pci32_sync_single_for_device,
  566. .sync_sg_for_cpu = pci32_sync_sg_for_cpu,
  567. .sync_sg_for_device = pci32_sync_sg_for_device,
  568. };
  569. EXPORT_SYMBOL(pci32_dma_ops);
  570. #endif /* CONFIG_PCI || CONFIG_SPARC_LEON */
  571. #ifdef CONFIG_SPARC_LEON
  572. struct dma_map_ops *dma_ops = &pci32_dma_ops;
  573. #elif defined(CONFIG_SBUS)
  574. struct dma_map_ops *dma_ops = &sbus_dma_ops;
  575. #endif
  576. EXPORT_SYMBOL(dma_ops);
  577. /*
  578. * Return whether the given PCI device DMA address mask can be
  579. * supported properly. For example, if your device can only drive the
  580. * low 24-bits during PCI bus mastering, then you would pass
  581. * 0x00ffffff as the mask to this function.
  582. */
  583. int dma_supported(struct device *dev, u64 mask)
  584. {
  585. #ifdef CONFIG_PCI
  586. if (dev->bus == &pci_bus_type)
  587. return 1;
  588. #endif
  589. return 0;
  590. }
  591. EXPORT_SYMBOL(dma_supported);
  592. #ifdef CONFIG_PROC_FS
  593. static int sparc_io_proc_show(struct seq_file *m, void *v)
  594. {
  595. struct resource *root = m->private, *r;
  596. const char *nm;
  597. for (r = root->child; r != NULL; r = r->sibling) {
  598. if ((nm = r->name) == 0) nm = "???";
  599. seq_printf(m, "%016llx-%016llx: %s\n",
  600. (unsigned long long)r->start,
  601. (unsigned long long)r->end, nm);
  602. }
  603. return 0;
  604. }
  605. static int sparc_io_proc_open(struct inode *inode, struct file *file)
  606. {
  607. return single_open(file, sparc_io_proc_show, PDE(inode)->data);
  608. }
  609. static const struct file_operations sparc_io_proc_fops = {
  610. .owner = THIS_MODULE,
  611. .open = sparc_io_proc_open,
  612. .read = seq_read,
  613. .llseek = seq_lseek,
  614. .release = single_release,
  615. };
  616. #endif /* CONFIG_PROC_FS */
  617. static void register_proc_sparc_ioport(void)
  618. {
  619. #ifdef CONFIG_PROC_FS
  620. proc_create_data("io_map", 0, NULL, &sparc_io_proc_fops, &sparc_iomap);
  621. proc_create_data("dvma_map", 0, NULL, &sparc_io_proc_fops, &_sparc_dvma);
  622. #endif
  623. }