/drivers/gpu/msm/kgsl.h

https://gitlab.com/TeamTators/hp-kernel-tenderloin · C Header · 233 lines · 148 code · 44 blank · 41 comment · 6 complexity · ad1f7806366c2173d8c307a2a3cd73b0 MD5 · raw file

  1. /* Copyright (c) 2008-2011, 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_DRIVER_H
  30. #define _GSL_DRIVER_H
  31. #include <linux/types.h>
  32. #include <linux/msm_kgsl.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/clk.h>
  35. #include <linux/mutex.h>
  36. #include <linux/cdev.h>
  37. #include <linux/regulator/consumer.h>
  38. #include <asm/atomic.h>
  39. #include "kgsl_device.h"
  40. #include "kgsl_sharedmem.h"
  41. #define DRIVER_NAME "kgsl"
  42. #define CLASS_NAME "msm_kgsl"
  43. #define CHIP_REV_251 0x020501
  44. /* Flags to control whether to flush or invalidate a cached memory range */
  45. #define KGSL_CACHE_INV 0x00000000
  46. #define KGSL_CACHE_CLEAN 0x00000001
  47. #define KGSL_CACHE_FLUSH 0x00000002
  48. #define KGSL_CACHE_USER_ADDR 0x00000010
  49. #define KGSL_CACHE_VMALLOC_ADDR 0x00000020
  50. /*cache coherency ops */
  51. #define DRM_KGSL_GEM_CACHE_OP_TO_DEV 0x0001
  52. #define DRM_KGSL_GEM_CACHE_OP_FROM_DEV 0x0002
  53. #define KGSL_NUM_2D_DEVICES 2
  54. #define IDX_2D(X) ((X)-KGSL_DEVICE_2D0)
  55. /* The size of each entry in a page table */
  56. #define KGSL_PAGETABLE_ENTRY_SIZE 4
  57. /* Pagetable Virtual Address base */
  58. #define KGSL_PAGETABLE_BASE 0x66000000
  59. /* Extra accounting entries needed in the pagetable */
  60. #define KGSL_PT_EXTRA_ENTRIES 16
  61. #define KGSL_PAGETABLE_ENTRIES(_sz) (((_sz) >> KGSL_PAGESIZE_SHIFT) + \
  62. KGSL_PT_EXTRA_ENTRIES)
  63. #ifdef CONFIG_KGSL_PER_PROCESS_PAGE_TABLE
  64. #define KGSL_PAGETABLE_COUNT (CONFIG_MSM_KGSL_PAGE_TABLE_COUNT)
  65. #else
  66. #define KGSL_PAGETABLE_COUNT 1
  67. #endif
  68. /* Casting using container_of() for structures that kgsl owns. */
  69. #define KGSL_CONTAINER_OF(ptr, type, member) \
  70. container_of(ptr, type, member)
  71. #define KGSL_YAMATO_DEVICE(device) \
  72. KGSL_CONTAINER_OF(device, struct kgsl_yamato_device, dev)
  73. #define KGSL_G12_DEVICE(device) \
  74. KGSL_CONTAINER_OF(device, struct kgsl_g12_device, dev)
  75. struct kgsl_driver {
  76. struct cdev cdev;
  77. dev_t dev_num;
  78. struct class *class;
  79. struct kgsl_device *devp[KGSL_DEVICE_MAX];
  80. int num_devs;
  81. struct platform_device *pdev;
  82. uint32_t flags_debug;
  83. /* Global lilst of open processes */
  84. struct list_head process_list;
  85. /* Global list of pagetables */
  86. struct list_head pagetable_list;
  87. /* Mutex for accessing the pagetable list */
  88. struct mutex pt_mutex;
  89. /* Mutex for accessing the process list */
  90. struct mutex process_mutex;
  91. struct kgsl_pagetable *global_pt;
  92. /* Size (in bytes) for each pagetable */
  93. unsigned int ptsize;
  94. struct kgsl_ptpool ptpool;
  95. };
  96. extern struct kgsl_driver kgsl_driver;
  97. struct kgsl_mem_entry {
  98. struct kgsl_memdesc memdesc;
  99. struct file *file_ptr;
  100. struct list_head list;
  101. uint32_t free_timestamp;
  102. /* back pointer to private structure under whose context this
  103. * allocation is made */
  104. struct kgsl_process_private *priv;
  105. };
  106. enum kgsl_status {
  107. KGSL_SUCCESS = 0,
  108. KGSL_FAILURE = 1
  109. };
  110. #define KGSL_TRUE 1
  111. #define KGSL_FALSE 0
  112. #ifdef CONFIG_MSM_KGSL_MMU_PAGE_FAULT
  113. #define MMU_CONFIG 2
  114. #else
  115. #define MMU_CONFIG 1
  116. #endif
  117. void kgsl_destroy_mem_entry(struct kgsl_mem_entry *entry);
  118. uint8_t *kgsl_gpuaddr_to_vaddr(const struct kgsl_memdesc *memdesc,
  119. unsigned int gpuaddr, unsigned int *size);
  120. struct kgsl_mem_entry *kgsl_sharedmem_find_region(
  121. struct kgsl_process_private *private, unsigned int gpuaddr,
  122. size_t size);
  123. uint8_t *kgsl_sharedmem_convertaddr(struct kgsl_device *device,
  124. unsigned int pt_base, unsigned int gpuaddr, unsigned int *size);
  125. int kgsl_idle(struct kgsl_device *device, unsigned int timeout);
  126. int kgsl_setstate(struct kgsl_device *device, uint32_t flags);
  127. static inline void kgsl_regread(struct kgsl_device *device,
  128. unsigned int offsetwords,
  129. unsigned int *value)
  130. {
  131. device->ftbl.device_regread(device, offsetwords, value);
  132. }
  133. static inline void kgsl_regwrite(struct kgsl_device *device,
  134. unsigned int offsetwords,
  135. unsigned int value)
  136. {
  137. device->ftbl.device_regwrite(device, offsetwords, value);
  138. }
  139. static inline void kgsl_regread_isr(struct kgsl_device *device,
  140. unsigned int offsetwords,
  141. unsigned int *value)
  142. {
  143. device->ftbl.device_regread_isr(device, offsetwords, value);
  144. }
  145. static inline void kgsl_regwrite_isr(struct kgsl_device *device,
  146. unsigned int offsetwords,
  147. unsigned int value)
  148. {
  149. device->ftbl.device_regwrite_isr(device, offsetwords, value);
  150. }
  151. int kgsl_check_timestamp(struct kgsl_device *device, unsigned int timestamp);
  152. int kgsl_setup_pt(struct kgsl_pagetable *);
  153. int kgsl_cleanup_pt(struct kgsl_pagetable *);
  154. int kgsl_register_ts_notifier(struct kgsl_device *device,
  155. struct notifier_block *nb);
  156. int kgsl_unregister_ts_notifier(struct kgsl_device *device,
  157. struct notifier_block *nb);
  158. #ifdef CONFIG_MSM_KGSL_DRM
  159. extern int kgsl_drm_init(struct platform_device *dev);
  160. extern void kgsl_drm_exit(void);
  161. extern void kgsl_gpu_mem_flush(int op);
  162. #else
  163. static inline int kgsl_drm_init(struct platform_device *dev)
  164. {
  165. return 0;
  166. }
  167. static inline void kgsl_drm_exit(void)
  168. {
  169. }
  170. #endif
  171. static inline int kgsl_gpuaddr_in_memdesc(const struct kgsl_memdesc *memdesc,
  172. unsigned int gpuaddr)
  173. {
  174. if (gpuaddr >= memdesc->gpuaddr && (gpuaddr + sizeof(unsigned int)) <=
  175. (memdesc->gpuaddr + memdesc->size)) {
  176. return 1;
  177. }
  178. return 0;
  179. }
  180. static inline struct kgsl_device *kgsl_device_from_dev(struct device *dev)
  181. {
  182. int i;
  183. for (i = 0; i < KGSL_DEVICE_MAX; i++) {
  184. if (kgsl_driver.devp[i] && kgsl_driver.devp[i]->dev == dev)
  185. return kgsl_driver.devp[i];
  186. }
  187. return NULL;
  188. }
  189. #endif /* _GSL_DRIVER_H */