pg-dma.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * arch/sh/mm/pg-dma.c
  3. *
  4. * Fast clear_page()/copy_page() implementation using the SH DMAC
  5. *
  6. * Copyright (C) 2003 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <asm/semaphore.h>
  16. #include <asm/mmu_context.h>
  17. #include <asm/addrspace.h>
  18. #include <asm/atomic.h>
  19. #include <asm/page.h>
  20. #include <asm/dma.h>
  21. #include <asm/io.h>
  22. /* Channel to use for page ops, must be dual-address mode capable. */
  23. static int dma_channel = CONFIG_DMA_PAGE_OPS_CHANNEL;
  24. static void copy_page_dma(void *to, void *from)
  25. {
  26. /*
  27. * This doesn't seem to get triggered until further along in the
  28. * boot process, at which point the DMAC is already initialized.
  29. * Fix this in the same fashion as clear_page_dma() in the event
  30. * that this crashes due to the DMAC not being initialized.
  31. */
  32. flush_icache_range((unsigned long)from, PAGE_SIZE);
  33. dma_write_page(dma_channel, (unsigned long)from, (unsigned long)to);
  34. dma_wait_for_completion(dma_channel);
  35. }
  36. static void clear_page_dma(void *to)
  37. {
  38. extern unsigned long empty_zero_page[1024];
  39. /*
  40. * We get invoked quite early on, if the DMAC hasn't been initialized
  41. * yet, fall back on the slow manual implementation.
  42. */
  43. if (dma_info[dma_channel].chan != dma_channel) {
  44. clear_page_slow(to);
  45. return;
  46. }
  47. dma_write_page(dma_channel, (unsigned long)empty_zero_page,
  48. (unsigned long)to);
  49. /*
  50. * FIXME: Something is a bit racy here, if we poll the counter right
  51. * away, we seem to lock. flushing the page from the dcache doesn't
  52. * seem to make a difference one way or the other, though either a full
  53. * icache or dcache flush does.
  54. *
  55. * The location of this is important as well, and must happen prior to
  56. * the completion loop but after the transfer was initiated.
  57. *
  58. * Oddly enough, this doesn't appear to be an issue for copy_page()..
  59. */
  60. flush_icache_range((unsigned long)to, PAGE_SIZE);
  61. dma_wait_for_completion(dma_channel);
  62. }
  63. static int __init pg_dma_init(void)
  64. {
  65. int ret;
  66. ret = request_dma(dma_channel, "page ops");
  67. if (ret != 0)
  68. return ret;
  69. copy_page = copy_page_dma;
  70. clear_page = clear_page_dma;
  71. return ret;
  72. }
  73. static void __exit pg_dma_exit(void)
  74. {
  75. free_dma(dma_channel);
  76. }
  77. module_init(pg_dma_init);
  78. module_exit(pg_dma_exit);
  79. MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
  80. MODULE_DESCRIPTION("Optimized page copy/clear routines using a dual-address mode capable DMAC channel");
  81. MODULE_LICENSE("GPL");