ioport.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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/scatterlist.h>
  38. #include <linux/of_device.h>
  39. #include <asm/io.h>
  40. #include <asm/vaddrs.h>
  41. #include <asm/oplib.h>
  42. #include <asm/prom.h>
  43. #include <asm/page.h>
  44. #include <asm/pgalloc.h>
  45. #include <asm/dma.h>
  46. #include <asm/iommu.h>
  47. #include <asm/io-unit.h>
  48. #include "dma.h"
  49. #define mmu_inval_dma_area(p, l) /* Anton pulled it out for 2.4.0-xx */
  50. static struct resource *_sparc_find_resource(struct resource *r,
  51. unsigned long);
  52. static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
  53. static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
  54. unsigned long size, char *name);
  55. static void _sparc_free_io(struct resource *res);
  56. static void register_proc_sparc_ioport(void);
  57. /* This points to the next to use virtual memory for DVMA mappings */
  58. static struct resource _sparc_dvma = {
  59. .name = "sparc_dvma", .start = DVMA_VADDR, .end = DVMA_END - 1
  60. };
  61. /* This points to the start of I/O mappings, cluable from outside. */
  62. /*ext*/ struct resource sparc_iomap = {
  63. .name = "sparc_iomap", .start = IOBASE_VADDR, .end = IOBASE_END - 1
  64. };
  65. /*
  66. * Our mini-allocator...
  67. * Boy this is gross! We need it because we must map I/O for
  68. * timers and interrupt controller before the kmalloc is available.
  69. */
  70. #define XNMLN 15
  71. #define XNRES 10 /* SS-10 uses 8 */
  72. struct xresource {
  73. struct resource xres; /* Must be first */
  74. int xflag; /* 1 == used */
  75. char xname[XNMLN+1];
  76. };
  77. static struct xresource xresv[XNRES];
  78. static struct xresource *xres_alloc(void) {
  79. struct xresource *xrp;
  80. int n;
  81. xrp = xresv;
  82. for (n = 0; n < XNRES; n++) {
  83. if (xrp->xflag == 0) {
  84. xrp->xflag = 1;
  85. return xrp;
  86. }
  87. xrp++;
  88. }
  89. return NULL;
  90. }
  91. static void xres_free(struct xresource *xrp) {
  92. xrp->xflag = 0;
  93. }
  94. /*
  95. * These are typically used in PCI drivers
  96. * which are trying to be cross-platform.
  97. *
  98. * Bus type is always zero on IIep.
  99. */
  100. void __iomem *ioremap(unsigned long offset, unsigned long size)
  101. {
  102. char name[14];
  103. sprintf(name, "phys_%08x", (u32)offset);
  104. return _sparc_alloc_io(0, offset, size, name);
  105. }
  106. /*
  107. * Comlimentary to ioremap().
  108. */
  109. void iounmap(volatile void __iomem *virtual)
  110. {
  111. unsigned long vaddr = (unsigned long) virtual & PAGE_MASK;
  112. struct resource *res;
  113. if ((res = _sparc_find_resource(&sparc_iomap, vaddr)) == NULL) {
  114. printk("free_io/iounmap: cannot free %lx\n", vaddr);
  115. return;
  116. }
  117. _sparc_free_io(res);
  118. if ((char *)res >= (char*)xresv && (char *)res < (char *)&xresv[XNRES]) {
  119. xres_free((struct xresource *)res);
  120. } else {
  121. kfree(res);
  122. }
  123. }
  124. void __iomem *of_ioremap(struct resource *res, unsigned long offset,
  125. unsigned long size, char *name)
  126. {
  127. return _sparc_alloc_io(res->flags & 0xF,
  128. res->start + offset,
  129. size, name);
  130. }
  131. EXPORT_SYMBOL(of_ioremap);
  132. void of_iounmap(struct resource *res, void __iomem *base, unsigned long size)
  133. {
  134. iounmap(base);
  135. }
  136. EXPORT_SYMBOL(of_iounmap);
  137. /*
  138. * Meat of mapping
  139. */
  140. static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
  141. unsigned long size, char *name)
  142. {
  143. static int printed_full;
  144. struct xresource *xres;
  145. struct resource *res;
  146. char *tack;
  147. int tlen;
  148. void __iomem *va; /* P3 diag */
  149. if (name == NULL) name = "???";
  150. if ((xres = xres_alloc()) != 0) {
  151. tack = xres->xname;
  152. res = &xres->xres;
  153. } else {
  154. if (!printed_full) {
  155. printk("ioremap: done with statics, switching to malloc\n");
  156. printed_full = 1;
  157. }
  158. tlen = strlen(name);
  159. tack = kmalloc(sizeof (struct resource) + tlen + 1, GFP_KERNEL);
  160. if (tack == NULL) return NULL;
  161. memset(tack, 0, sizeof(struct resource));
  162. res = (struct resource *) tack;
  163. tack += sizeof (struct resource);
  164. }
  165. strlcpy(tack, name, XNMLN+1);
  166. res->name = tack;
  167. va = _sparc_ioremap(res, busno, phys, size);
  168. /* printk("ioremap(0x%x:%08lx[0x%lx])=%p\n", busno, phys, size, va); */ /* P3 diag */
  169. return va;
  170. }
  171. /*
  172. */
  173. static void __iomem *
  174. _sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz)
  175. {
  176. unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK);
  177. if (allocate_resource(&sparc_iomap, res,
  178. (offset + sz + PAGE_SIZE-1) & PAGE_MASK,
  179. sparc_iomap.start, sparc_iomap.end, PAGE_SIZE, NULL, NULL) != 0) {
  180. /* Usually we cannot see printks in this case. */
  181. prom_printf("alloc_io_res(%s): cannot occupy\n",
  182. (res->name != NULL)? res->name: "???");
  183. prom_halt();
  184. }
  185. pa &= PAGE_MASK;
  186. sparc_mapiorange(bus, pa, res->start, res->end - res->start + 1);
  187. return (void __iomem *)(unsigned long)(res->start + offset);
  188. }
  189. /*
  190. * Comlimentary to _sparc_ioremap().
  191. */
  192. static void _sparc_free_io(struct resource *res)
  193. {
  194. unsigned long plen;
  195. plen = res->end - res->start + 1;
  196. BUG_ON((plen & (PAGE_SIZE-1)) != 0);
  197. sparc_unmapiorange(res->start, plen);
  198. release_resource(res);
  199. }
  200. #ifdef CONFIG_SBUS
  201. void sbus_set_sbus64(struct device *dev, int x)
  202. {
  203. printk("sbus_set_sbus64: unsupported\n");
  204. }
  205. /*
  206. * Allocate a chunk of memory suitable for DMA.
  207. * Typically devices use them for control blocks.
  208. * CPU may access them without any explicit flushing.
  209. */
  210. void *sbus_alloc_consistent(struct device *dev, long len, u32 *dma_addrp)
  211. {
  212. struct of_device *op = to_of_device(dev);
  213. unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK;
  214. unsigned long va;
  215. struct resource *res;
  216. int order;
  217. /* XXX why are some lengths signed, others unsigned? */
  218. if (len <= 0) {
  219. return NULL;
  220. }
  221. /* XXX So what is maxphys for us and how do drivers know it? */
  222. if (len > 256*1024) { /* __get_free_pages() limit */
  223. return NULL;
  224. }
  225. order = get_order(len_total);
  226. if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0)
  227. goto err_nopages;
  228. if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL)
  229. goto err_nomem;
  230. if (allocate_resource(&_sparc_dvma, res, len_total,
  231. _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
  232. printk("sbus_alloc_consistent: cannot occupy 0x%lx", len_total);
  233. goto err_nova;
  234. }
  235. mmu_inval_dma_area(va, len_total);
  236. // XXX The mmu_map_dma_area does this for us below, see comments.
  237. // sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
  238. /*
  239. * XXX That's where sdev would be used. Currently we load
  240. * all iommu tables with the same translations.
  241. */
  242. if (mmu_map_dma_area(dev, dma_addrp, va, res->start, len_total) != 0)
  243. goto err_noiommu;
  244. res->name = op->node->name;
  245. return (void *)(unsigned long)res->start;
  246. err_noiommu:
  247. release_resource(res);
  248. err_nova:
  249. free_pages(va, order);
  250. err_nomem:
  251. kfree(res);
  252. err_nopages:
  253. return NULL;
  254. }
  255. void sbus_free_consistent(struct device *dev, long n, void *p, u32 ba)
  256. {
  257. struct resource *res;
  258. struct page *pgv;
  259. if ((res = _sparc_find_resource(&_sparc_dvma,
  260. (unsigned long)p)) == NULL) {
  261. printk("sbus_free_consistent: cannot free %p\n", p);
  262. return;
  263. }
  264. if (((unsigned long)p & (PAGE_SIZE-1)) != 0) {
  265. printk("sbus_free_consistent: unaligned va %p\n", p);
  266. return;
  267. }
  268. n = (n + PAGE_SIZE-1) & PAGE_MASK;
  269. if ((res->end-res->start)+1 != n) {
  270. printk("sbus_free_consistent: region 0x%lx asked 0x%lx\n",
  271. (long)((res->end-res->start)+1), n);
  272. return;
  273. }
  274. release_resource(res);
  275. kfree(res);
  276. /* mmu_inval_dma_area(va, n); */ /* it's consistent, isn't it */
  277. pgv = virt_to_page(p);
  278. mmu_unmap_dma_area(dev, ba, n);
  279. __free_pages(pgv, get_order(n));
  280. }
  281. /*
  282. * Map a chunk of memory so that devices can see it.
  283. * CPU view of this memory may be inconsistent with
  284. * a device view and explicit flushing is necessary.
  285. */
  286. dma_addr_t sbus_map_single(struct device *dev, void *va, size_t len, int direction)
  287. {
  288. /* XXX why are some lengths signed, others unsigned? */
  289. if (len <= 0) {
  290. return 0;
  291. }
  292. /* XXX So what is maxphys for us and how do drivers know it? */
  293. if (len > 256*1024) { /* __get_free_pages() limit */
  294. return 0;
  295. }
  296. return mmu_get_scsi_one(dev, va, len);
  297. }
  298. void sbus_unmap_single(struct device *dev, dma_addr_t ba, size_t n, int direction)
  299. {
  300. mmu_release_scsi_one(dev, ba, n);
  301. }
  302. int sbus_map_sg(struct device *dev, struct scatterlist *sg, int n, int direction)
  303. {
  304. mmu_get_scsi_sgl(dev, sg, n);
  305. /*
  306. * XXX sparc64 can return a partial length here. sun4c should do this
  307. * but it currently panics if it can't fulfill the request - Anton
  308. */
  309. return n;
  310. }
  311. void sbus_unmap_sg(struct device *dev, struct scatterlist *sg, int n, int direction)
  312. {
  313. mmu_release_scsi_sgl(dev, sg, n);
  314. }
  315. void sbus_dma_sync_single_for_cpu(struct device *dev, dma_addr_t ba, size_t size, int direction)
  316. {
  317. }
  318. void sbus_dma_sync_single_for_device(struct device *dev, dma_addr_t ba, size_t size, int direction)
  319. {
  320. }
  321. static int __init sparc_register_ioport(void)
  322. {
  323. register_proc_sparc_ioport();
  324. return 0;
  325. }
  326. arch_initcall(sparc_register_ioport);
  327. #endif /* CONFIG_SBUS */
  328. #ifdef CONFIG_PCI
  329. /* Allocate and map kernel buffer using consistent mode DMA for a device.
  330. * hwdev should be valid struct pci_dev pointer for PCI devices.
  331. */
  332. void *pci_alloc_consistent(struct pci_dev *pdev, size_t len, dma_addr_t *pba)
  333. {
  334. unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK;
  335. unsigned long va;
  336. struct resource *res;
  337. int order;
  338. if (len == 0) {
  339. return NULL;
  340. }
  341. if (len > 256*1024) { /* __get_free_pages() limit */
  342. return NULL;
  343. }
  344. order = get_order(len_total);
  345. va = __get_free_pages(GFP_KERNEL, order);
  346. if (va == 0) {
  347. printk("pci_alloc_consistent: no %ld pages\n", len_total>>PAGE_SHIFT);
  348. return NULL;
  349. }
  350. if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
  351. free_pages(va, order);
  352. printk("pci_alloc_consistent: no core\n");
  353. return NULL;
  354. }
  355. if (allocate_resource(&_sparc_dvma, res, len_total,
  356. _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
  357. printk("pci_alloc_consistent: cannot occupy 0x%lx", len_total);
  358. free_pages(va, order);
  359. kfree(res);
  360. return NULL;
  361. }
  362. mmu_inval_dma_area(va, len_total);
  363. #if 0
  364. /* P3 */ printk("pci_alloc_consistent: kva %lx uncva %lx phys %lx size %lx\n",
  365. (long)va, (long)res->start, (long)virt_to_phys(va), len_total);
  366. #endif
  367. sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
  368. *pba = virt_to_phys(va); /* equals virt_to_bus (R.I.P.) for us. */
  369. return (void *) res->start;
  370. }
  371. /* Free and unmap a consistent DMA buffer.
  372. * cpu_addr is what was returned from pci_alloc_consistent,
  373. * size must be the same as what as passed into pci_alloc_consistent,
  374. * and likewise dma_addr must be the same as what *dma_addrp was set to.
  375. *
  376. * References to the memory and mappings associated with cpu_addr/dma_addr
  377. * past this call are illegal.
  378. */
  379. void pci_free_consistent(struct pci_dev *pdev, size_t n, void *p, dma_addr_t ba)
  380. {
  381. struct resource *res;
  382. unsigned long pgp;
  383. if ((res = _sparc_find_resource(&_sparc_dvma,
  384. (unsigned long)p)) == NULL) {
  385. printk("pci_free_consistent: cannot free %p\n", p);
  386. return;
  387. }
  388. if (((unsigned long)p & (PAGE_SIZE-1)) != 0) {
  389. printk("pci_free_consistent: unaligned va %p\n", p);
  390. return;
  391. }
  392. n = (n + PAGE_SIZE-1) & PAGE_MASK;
  393. if ((res->end-res->start)+1 != n) {
  394. printk("pci_free_consistent: region 0x%lx asked 0x%lx\n",
  395. (long)((res->end-res->start)+1), (long)n);
  396. return;
  397. }
  398. pgp = (unsigned long) phys_to_virt(ba); /* bus_to_virt actually */
  399. mmu_inval_dma_area(pgp, n);
  400. sparc_unmapiorange((unsigned long)p, n);
  401. release_resource(res);
  402. kfree(res);
  403. free_pages(pgp, get_order(n));
  404. }
  405. /* Map a single buffer of the indicated size for DMA in streaming mode.
  406. * The 32-bit bus address to use is returned.
  407. *
  408. * Once the device is given the dma address, the device owns this memory
  409. * until either pci_unmap_single or pci_dma_sync_single_* is performed.
  410. */
  411. dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size,
  412. int direction)
  413. {
  414. BUG_ON(direction == PCI_DMA_NONE);
  415. /* IIep is write-through, not flushing. */
  416. return virt_to_phys(ptr);
  417. }
  418. /* Unmap a single streaming mode DMA translation. The dma_addr and size
  419. * must match what was provided for in a previous pci_map_single call. All
  420. * other usages are undefined.
  421. *
  422. * After this call, reads by the cpu to the buffer are guaranteed to see
  423. * whatever the device wrote there.
  424. */
  425. void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t ba, size_t size,
  426. int direction)
  427. {
  428. BUG_ON(direction == PCI_DMA_NONE);
  429. if (direction != PCI_DMA_TODEVICE) {
  430. mmu_inval_dma_area((unsigned long)phys_to_virt(ba),
  431. (size + PAGE_SIZE-1) & PAGE_MASK);
  432. }
  433. }
  434. /*
  435. * Same as pci_map_single, but with pages.
  436. */
  437. dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
  438. unsigned long offset, size_t size, int direction)
  439. {
  440. BUG_ON(direction == PCI_DMA_NONE);
  441. /* IIep is write-through, not flushing. */
  442. return page_to_phys(page) + offset;
  443. }
  444. void pci_unmap_page(struct pci_dev *hwdev,
  445. dma_addr_t dma_address, size_t size, int direction)
  446. {
  447. BUG_ON(direction == PCI_DMA_NONE);
  448. /* mmu_inval_dma_area XXX */
  449. }
  450. /* Map a set of buffers described by scatterlist in streaming
  451. * mode for DMA. This is the scather-gather version of the
  452. * above pci_map_single interface. Here the scatter gather list
  453. * elements are each tagged with the appropriate dma address
  454. * and length. They are obtained via sg_dma_{address,length}(SG).
  455. *
  456. * NOTE: An implementation may be able to use a smaller number of
  457. * DMA address/length pairs than there are SG table elements.
  458. * (for example via virtual mapping capabilities)
  459. * The routine returns the number of addr/length pairs actually
  460. * used, at most nents.
  461. *
  462. * Device ownership issues as mentioned above for pci_map_single are
  463. * the same here.
  464. */
  465. int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents,
  466. int direction)
  467. {
  468. struct scatterlist *sg;
  469. int n;
  470. BUG_ON(direction == PCI_DMA_NONE);
  471. /* IIep is write-through, not flushing. */
  472. for_each_sg(sgl, sg, nents, n) {
  473. BUG_ON(page_address(sg_page(sg)) == NULL);
  474. sg->dvma_address = virt_to_phys(sg_virt(sg));
  475. sg->dvma_length = sg->length;
  476. }
  477. return nents;
  478. }
  479. /* Unmap a set of streaming mode DMA translations.
  480. * Again, cpu read rules concerning calls here are the same as for
  481. * pci_unmap_single() above.
  482. */
  483. void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents,
  484. int direction)
  485. {
  486. struct scatterlist *sg;
  487. int n;
  488. BUG_ON(direction == PCI_DMA_NONE);
  489. if (direction != PCI_DMA_TODEVICE) {
  490. for_each_sg(sgl, sg, nents, n) {
  491. BUG_ON(page_address(sg_page(sg)) == NULL);
  492. mmu_inval_dma_area(
  493. (unsigned long) page_address(sg_page(sg)),
  494. (sg->length + PAGE_SIZE-1) & PAGE_MASK);
  495. }
  496. }
  497. }
  498. /* Make physical memory consistent for a single
  499. * streaming mode DMA translation before or after a transfer.
  500. *
  501. * If you perform a pci_map_single() but wish to interrogate the
  502. * buffer using the cpu, yet do not wish to teardown the PCI dma
  503. * mapping, you must call this function before doing so. At the
  504. * next point you give the PCI dma address back to the card, you
  505. * must first perform a pci_dma_sync_for_device, and then the
  506. * device again owns the buffer.
  507. */
  508. void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction)
  509. {
  510. BUG_ON(direction == PCI_DMA_NONE);
  511. if (direction != PCI_DMA_TODEVICE) {
  512. mmu_inval_dma_area((unsigned long)phys_to_virt(ba),
  513. (size + PAGE_SIZE-1) & PAGE_MASK);
  514. }
  515. }
  516. void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction)
  517. {
  518. BUG_ON(direction == PCI_DMA_NONE);
  519. if (direction != PCI_DMA_TODEVICE) {
  520. mmu_inval_dma_area((unsigned long)phys_to_virt(ba),
  521. (size + PAGE_SIZE-1) & PAGE_MASK);
  522. }
  523. }
  524. /* Make physical memory consistent for a set of streaming
  525. * mode DMA translations after a transfer.
  526. *
  527. * The same as pci_dma_sync_single_* but for a scatter-gather list,
  528. * same rules and usage.
  529. */
  530. void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction)
  531. {
  532. struct scatterlist *sg;
  533. int n;
  534. BUG_ON(direction == PCI_DMA_NONE);
  535. if (direction != PCI_DMA_TODEVICE) {
  536. for_each_sg(sgl, sg, nents, n) {
  537. BUG_ON(page_address(sg_page(sg)) == NULL);
  538. mmu_inval_dma_area(
  539. (unsigned long) page_address(sg_page(sg)),
  540. (sg->length + PAGE_SIZE-1) & PAGE_MASK);
  541. }
  542. }
  543. }
  544. void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction)
  545. {
  546. struct scatterlist *sg;
  547. int n;
  548. BUG_ON(direction == PCI_DMA_NONE);
  549. if (direction != PCI_DMA_TODEVICE) {
  550. for_each_sg(sgl, sg, nents, n) {
  551. BUG_ON(page_address(sg_page(sg)) == NULL);
  552. mmu_inval_dma_area(
  553. (unsigned long) page_address(sg_page(sg)),
  554. (sg->length + PAGE_SIZE-1) & PAGE_MASK);
  555. }
  556. }
  557. }
  558. #endif /* CONFIG_PCI */
  559. #ifdef CONFIG_PROC_FS
  560. static int
  561. _sparc_io_get_info(char *buf, char **start, off_t fpos, int length, int *eof,
  562. void *data)
  563. {
  564. char *p = buf, *e = buf + length;
  565. struct resource *r;
  566. const char *nm;
  567. for (r = ((struct resource *)data)->child; r != NULL; r = r->sibling) {
  568. if (p + 32 >= e) /* Better than nothing */
  569. break;
  570. if ((nm = r->name) == 0) nm = "???";
  571. p += sprintf(p, "%016llx-%016llx: %s\n",
  572. (unsigned long long)r->start,
  573. (unsigned long long)r->end, nm);
  574. }
  575. return p-buf;
  576. }
  577. #endif /* CONFIG_PROC_FS */
  578. /*
  579. * This is a version of find_resource and it belongs to kernel/resource.c.
  580. * Until we have agreement with Linus and Martin, it lingers here.
  581. *
  582. * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case.
  583. * This probably warrants some sort of hashing.
  584. */
  585. static struct resource *_sparc_find_resource(struct resource *root,
  586. unsigned long hit)
  587. {
  588. struct resource *tmp;
  589. for (tmp = root->child; tmp != 0; tmp = tmp->sibling) {
  590. if (tmp->start <= hit && tmp->end >= hit)
  591. return tmp;
  592. }
  593. return NULL;
  594. }
  595. static void register_proc_sparc_ioport(void)
  596. {
  597. #ifdef CONFIG_PROC_FS
  598. create_proc_read_entry("io_map",0,NULL,_sparc_io_get_info,&sparc_iomap);
  599. create_proc_read_entry("dvma_map",0,NULL,_sparc_io_get_info,&_sparc_dvma);
  600. #endif
  601. }