sram.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * mach-davinci/sram.c - DaVinci simple SRAM allocator
  3. *
  4. * Copyright (C) 2009 David Brownell
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/genalloc.h>
  15. #include <mach/common.h>
  16. #include "sram.h"
  17. static struct gen_pool *sram_pool;
  18. struct gen_pool *sram_get_gen_pool(void)
  19. {
  20. return sram_pool;
  21. }
  22. void *sram_alloc(size_t len, dma_addr_t *dma)
  23. {
  24. dma_addr_t dma_base = davinci_soc_info.sram_dma;
  25. if (dma)
  26. *dma = 0;
  27. if (!sram_pool || (dma && !dma_base))
  28. return NULL;
  29. return gen_pool_dma_alloc(sram_pool, len, dma);
  30. }
  31. EXPORT_SYMBOL(sram_alloc);
  32. void sram_free(void *addr, size_t len)
  33. {
  34. gen_pool_free(sram_pool, (unsigned long) addr, len);
  35. }
  36. EXPORT_SYMBOL(sram_free);
  37. /*
  38. * REVISIT This supports CPU and DMA access to/from SRAM, but it
  39. * doesn't (yet?) support some other notable uses of SRAM: as TCM
  40. * for data and/or instructions; and holding code needed to enter
  41. * and exit suspend states (while DRAM can't be used).
  42. */
  43. static int __init sram_init(void)
  44. {
  45. phys_addr_t phys = davinci_soc_info.sram_dma;
  46. unsigned len = davinci_soc_info.sram_len;
  47. int status = 0;
  48. void __iomem *addr;
  49. if (len) {
  50. len = min_t(unsigned, len, SRAM_SIZE);
  51. sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
  52. if (!sram_pool)
  53. status = -ENOMEM;
  54. }
  55. if (sram_pool) {
  56. addr = ioremap(phys, len);
  57. if (!addr)
  58. return -ENOMEM;
  59. status = gen_pool_add_virt(sram_pool, (unsigned long) addr,
  60. phys, len, -1);
  61. if (status < 0)
  62. iounmap(addr);
  63. }
  64. WARN_ON(status < 0);
  65. return status;
  66. }
  67. core_initcall(sram_init);