etnaviv_drv.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2015 Etnaviv Project
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published by
  6. * the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ETNAVIV_DRV_H__
  17. #define __ETNAVIV_DRV_H__
  18. #include <linux/kernel.h>
  19. #include <linux/clk.h>
  20. #include <linux/cpufreq.h>
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/pm.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/slab.h>
  26. #include <linux/list.h>
  27. #include <linux/types.h>
  28. #include <linux/sizes.h>
  29. #include <drm/drmP.h>
  30. #include <drm/drm_crtc_helper.h>
  31. #include <drm/drm_fb_helper.h>
  32. #include <drm/drm_gem.h>
  33. #include <drm/etnaviv_drm.h>
  34. #include <drm/gpu_scheduler.h>
  35. struct etnaviv_cmdbuf;
  36. struct etnaviv_gpu;
  37. struct etnaviv_mmu;
  38. struct etnaviv_gem_object;
  39. struct etnaviv_gem_submit;
  40. struct etnaviv_file_private {
  41. /*
  42. * When per-context address spaces are supported we'd keep track of
  43. * the context's page-tables here.
  44. */
  45. struct drm_sched_entity sched_entity[ETNA_MAX_PIPES];
  46. };
  47. struct etnaviv_drm_private {
  48. int num_gpus;
  49. struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
  50. /* list of GEM objects: */
  51. struct mutex gem_lock;
  52. struct list_head gem_list;
  53. };
  54. int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
  55. struct drm_file *file);
  56. int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  57. int etnaviv_gem_fault(struct vm_fault *vmf);
  58. int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
  59. struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
  60. void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
  61. void etnaviv_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  62. int etnaviv_gem_prime_mmap(struct drm_gem_object *obj,
  63. struct vm_area_struct *vma);
  64. struct reservation_object *etnaviv_gem_prime_res_obj(struct drm_gem_object *obj);
  65. struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
  66. struct dma_buf_attachment *attach, struct sg_table *sg);
  67. int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
  68. void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
  69. void *etnaviv_gem_vmap(struct drm_gem_object *obj);
  70. int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
  71. struct timespec *timeout);
  72. int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
  73. void etnaviv_gem_free_object(struct drm_gem_object *obj);
  74. int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
  75. u32 size, u32 flags, u32 *handle);
  76. int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
  77. uintptr_t ptr, u32 size, u32 flags, u32 *handle);
  78. u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
  79. u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr);
  80. u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu);
  81. void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
  82. void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event);
  83. void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
  84. unsigned int event, struct etnaviv_cmdbuf *cmdbuf);
  85. void etnaviv_validate_init(void);
  86. bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
  87. u32 *stream, unsigned int size,
  88. struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);
  89. #ifdef CONFIG_DEBUG_FS
  90. void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
  91. struct seq_file *m);
  92. #endif
  93. void __iomem *etnaviv_ioremap(struct platform_device *pdev, const char *name,
  94. const char *dbgname);
  95. void etnaviv_writel(u32 data, void __iomem *addr);
  96. u32 etnaviv_readl(const void __iomem *addr);
  97. #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  98. #define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  99. /*
  100. * Return the storage size of a structure with a variable length array.
  101. * The array is nelem elements of elem_size, where the base structure
  102. * is defined by base. If the size overflows size_t, return zero.
  103. */
  104. static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
  105. {
  106. if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
  107. return 0;
  108. return base + nelem * elem_size;
  109. }
  110. /* returns true if fence a comes after fence b */
  111. static inline bool fence_after(u32 a, u32 b)
  112. {
  113. return (s32)(a - b) > 0;
  114. }
  115. static inline bool fence_after_eq(u32 a, u32 b)
  116. {
  117. return (s32)(a - b) >= 0;
  118. }
  119. static inline unsigned long etnaviv_timeout_to_jiffies(
  120. const struct timespec *timeout)
  121. {
  122. unsigned long timeout_jiffies = timespec_to_jiffies(timeout);
  123. unsigned long start_jiffies = jiffies;
  124. unsigned long remaining_jiffies;
  125. if (time_after(start_jiffies, timeout_jiffies))
  126. remaining_jiffies = 0;
  127. else
  128. remaining_jiffies = timeout_jiffies - start_jiffies;
  129. return remaining_jiffies;
  130. }
  131. #endif /* __ETNAVIV_DRV_H__ */