pandriver.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * © Copyright 2017 The BiOpenly Community
  3. *
  4. * This program is free software and is provided to you under the terms of the
  5. * GNU General Public License version 2 as published by the Free Software
  6. * Foundation, and any use by you of this program is subject to the terms
  7. * of such GNU license.
  8. *
  9. * A copy of the licence is included with the program, and can also be obtained
  10. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  11. * Boston, MA 02110-1301, USA.
  12. *
  13. */
  14. #ifndef __PANDRIVER_H__
  15. #define __PANDRIVER_H__
  16. #include <stddef.h>
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. #ifdef HAVE_USER_H
  20. #include <sys/user.h>
  21. #endif
  22. #include <mali-ioctl.h>
  23. #include <jobs.h>
  24. #include <chai-notes.h>
  25. /* TODO: Find non-hackish memory allocator */
  26. void init_cbma(int fd);
  27. void* galloc(size_t sz);
  28. void gfree(void* ptr);
  29. /* Integer types used in the shim. */
  30. typedef int8_t s8;
  31. typedef int16_t s16;
  32. typedef int32_t s32;
  33. typedef int64_t s64;
  34. typedef uint8_t u8;
  35. typedef uint16_t u16;
  36. typedef uint32_t u32;
  37. typedef uint64_t u64;
  38. /* We don't have PAGE_SIZE at all, provide our own */
  39. #ifndef PAGE_SIZE
  40. #define PAGE_SHIFT 12
  41. #define PAGE_SIZE (1 << PAGE_SHIFT)
  42. #define PAGE_MASK (~(PAGE_SIZE - 1))
  43. #else
  44. /* Android bionic doesn't have PAGE_SHIFT, define it using __builtin_ffs() if
  45. * possible, otherwise fallback to slightly slower stdlib ffs
  46. */
  47. #ifndef PAGE_SHIFT
  48. #ifdef HAVE_BUILTIN_FFS
  49. #define PAGE_SHIFT (__builtin_ffs(PAGE_SIZE) - 1)
  50. #else
  51. #include <strings.h>
  52. #define PAGE_SHIFT (ffs(PAGE_SIZE) - 1)
  53. #endif /* HAVE_BUILTIN_FFS */
  54. #endif /* PAGE_SHIFT */
  55. #endif /* PAGE_SIZE */
  56. /* Thin wrappers around ioctls */
  57. int open_kernel_module();
  58. uint64_t alloc_gpu_pages(int fd, int pages, int e_flags);
  59. uint64_t alloc_gpu_heap(int fd, int pages);
  60. void free_gpu(int fd, uint64_t addr);
  61. void sync_gpu(int fd, uint8_t* cpu, uint64_t gpu, size_t size);
  62. void submit_job(int fd, struct mali_jd_atom_v2 atom);
  63. void flush_job_queue(int fd);
  64. uint8_t* mmap_gpu(int fd, uint64_t addr, int page_count);
  65. void stream_create(int fd, char *stream);
  66. void query_gpu_props(int fd);
  67. /* Raw command stream generation */
  68. struct job_descriptor_header* set_value_helper(uint64_t out);
  69. uint64_t make_mfbd(bool tiler, uint64_t heap_free_address,
  70. uint64_t scratchpad);
  71. uint32_t job_chain_fragment(int fd, uint64_t framebuffer,
  72. uint64_t heap_free_address, uint64_t scratchpad);
  73. uint64_t import_shader(int fd, uint8_t *shader, size_t sz, bool frag);
  74. uint32_t upload_vertices(float *vertices, size_t sz);
  75. struct job_descriptor_header* vertex_tiler_helper(int fd, bool tiler,
  76. uint32_t fbd,
  77. uint32_t vertex_buffer,
  78. uint32_t zero_buffer,
  79. uint32_t mode,
  80. void *shader,
  81. size_t shader_size);
  82. uint32_t job_chain_vertex_tiler(int fd, float *vertices, size_t vertex_size,
  83. int mode,
  84. void *vertex_shader, size_t vs_sz,
  85. void *fragment_shader, size_t fs_sz,
  86. uint64_t heap_free_address,
  87. uint64_t scratchpad);
  88. void job_chain_replay(int fd, uint32_t tiler_jc, uint32_t fragment_jc,
  89. uint64_t heap_free_address, uint64_t framebuffer);
  90. #endif