/drivers/gpu/msm/kgsl_sharedmem.h

https://bitbucket.org/cresqo/cm7-p500-kernel · C Header · 122 lines · 70 code · 21 blank · 31 comment · 1 complexity · bccff7584f9beb5662bbd87a19ef0f6d MD5 · raw file

  1. /* Copyright (c) 2002,2007-2010, Code Aurora Forum. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above
  9. * copyright notice, this list of conditions and the following
  10. * disclaimer in the documentation and/or other materials provided
  11. * with the distribution.
  12. * * Neither the name of Code Aurora Forum, Inc. nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  26. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. */
  29. #ifndef __GSL_SHAREDMEM_H
  30. #define __GSL_SHAREDMEM_H
  31. #include <linux/dma-mapping.h>
  32. #define KGSL_PAGESIZE 0x1000
  33. #define KGSL_PAGESIZE_SHIFT 12
  34. #define KGSL_PAGEMASK (~(KGSL_PAGESIZE - 1))
  35. struct kgsl_pagetable;
  36. /* Memflags for caching operations */
  37. #define KGSL_MEMFLAGS_CACHE_INV 0x00000001
  38. #define KGSL_MEMFLAGS_CACHE_FLUSH 0x00000002
  39. #define KGSL_MEMFLAGS_CACHE_CLEAN 0x00000004
  40. #define KGSL_MEMFLAGS_CACHE_MASK 0x0000000F
  41. /* Flags to differentiate memory types */
  42. #define KGSL_MEMFLAGS_CONPHYS 0x00001000
  43. #define KGSL_MEMFLAGS_VMALLOC_MEM 0x00002000
  44. #define KGSL_MEMFLAGS_HOSTADDR 0x00004000
  45. #define KGSL_MEMFLAGS_ALIGNANY 0x00000000
  46. #define KGSL_MEMFLAGS_ALIGN32 0x00000000
  47. #define KGSL_MEMFLAGS_ALIGN64 0x00060000
  48. #define KGSL_MEMFLAGS_ALIGN128 0x00070000
  49. #define KGSL_MEMFLAGS_ALIGN256 0x00080000
  50. #define KGSL_MEMFLAGS_ALIGN512 0x00090000
  51. #define KGSL_MEMFLAGS_ALIGN1K 0x000A0000
  52. #define KGSL_MEMFLAGS_ALIGN2K 0x000B0000
  53. #define KGSL_MEMFLAGS_ALIGN4K 0x000C0000
  54. #define KGSL_MEMFLAGS_ALIGN8K 0x000D0000
  55. #define KGSL_MEMFLAGS_ALIGN16K 0x000E0000
  56. #define KGSL_MEMFLAGS_ALIGN32K 0x000F0000
  57. #define KGSL_MEMFLAGS_ALIGN64K 0x00100000
  58. #define KGSL_MEMFLAGS_ALIGNPAGE KGSL_MEMFLAGS_ALIGN4K
  59. #define KGSL_MEMFLAGS_ALIGN_MASK 0x00FF0000
  60. #define KGSL_MEMFLAGS_ALIGN_SHIFT 16
  61. /* shared memory allocation */
  62. struct kgsl_memdesc {
  63. struct kgsl_pagetable *pagetable;
  64. void *hostptr;
  65. unsigned int gpuaddr;
  66. unsigned int physaddr;
  67. unsigned int size;
  68. unsigned int priv;
  69. };
  70. int kgsl_sharedmem_vmalloc(struct kgsl_memdesc *memdesc,
  71. struct kgsl_pagetable *pagetable, size_t size);
  72. static inline int
  73. kgsl_sharedmem_alloc_coherent(struct kgsl_memdesc *memdesc, size_t size)
  74. {
  75. size = ALIGN(size, KGSL_PAGESIZE);
  76. memdesc->hostptr = dma_alloc_coherent(NULL, size, &memdesc->physaddr,
  77. GFP_KERNEL);
  78. if (!memdesc->hostptr)
  79. return -ENOMEM;
  80. memdesc->size = size;
  81. memdesc->priv = KGSL_MEMFLAGS_CONPHYS;
  82. return 0;
  83. }
  84. void kgsl_sharedmem_free(struct kgsl_memdesc *memdesc);
  85. int kgsl_sharedmem_readl(const struct kgsl_memdesc *memdesc,
  86. uint32_t *dst,
  87. unsigned int offsetbytes);
  88. int kgsl_sharedmem_read(const struct kgsl_memdesc *memdesc, void *dst,
  89. unsigned int offsetbytes, unsigned int sizebytes);
  90. int kgsl_sharedmem_writel(const struct kgsl_memdesc *memdesc,
  91. unsigned int offsetbytes,
  92. uint32_t src);
  93. int kgsl_sharedmem_write(const struct kgsl_memdesc *memdesc,
  94. unsigned int offsetbytes,
  95. void *src, unsigned int sizebytes);
  96. int kgsl_sharedmem_set(const struct kgsl_memdesc *memdesc,
  97. unsigned int offsetbytes, unsigned int value,
  98. unsigned int sizebytes);
  99. void kgsl_cache_range_op(unsigned long addr, int size,
  100. unsigned int flags);
  101. #endif /* __GSL_SHAREDMEM_H */