clear.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* THIS FILE WAS AUTOGENERATED BY PANWRAP. FEEL FREE TO EDIT THOUGH, HON <3 */
  2. #define _LARGEFILE64_SOURCE 1
  3. #define CACHE_LINE_SIZE 1024 /* TODO */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <sys/mman.h>
  7. #include "pandev.h"
  8. void main(void) {
  9. int fd = pandev_raw_open(), rc;
  10. if (fd < 0) {
  11. printf("Error opening kernel\n");
  12. }
  13. struct mali_ioctl_get_version get_version_0 = {
  14. .major = 10,
  15. .minor = 6,
  16. };
  17. rc = pandev_ioctl(fd, MALI_IOCTL_GET_VERSION, &get_version_0);
  18. if (rc) printf("Error %d in GET_VERSION_0\n", rc);
  19. pandev_map_mtp(fd);
  20. struct mali_ioctl_set_flags set_flags_1 = {
  21. .create_flags = 00000000,
  22. };
  23. rc = pandev_ioctl(fd, MALI_IOCTL_SET_FLAGS, &set_flags_1);
  24. if (rc) printf("Error %d in SET_FLAGS_1\n", rc);
  25. struct mali_ioctl_mem_alloc mem_alloc_4 = {
  26. .va_pages = 32,
  27. .commit_pages = 32,
  28. .extent = 0x0,
  29. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD,
  30. // GPU memory allocated at GPU VA 0x102000000
  31. };
  32. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_4);
  33. if (rc) printf("Error %d in MEM_ALLOC_4\n", rc);
  34. struct mali_ioctl_mem_alloc mem_alloc_5 = {
  35. .va_pages = 1,
  36. .commit_pages = 1,
  37. .extent = 0x0,
  38. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR | MALI_MEM_SAME_VA,
  39. // GPU memory allocated at GPU VA 0x41000
  40. };
  41. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_5);
  42. if (rc) printf("Error %d in MEM_ALLOC_5\n", rc);
  43. uint32_t *memory_5 = mmap64(NULL, 4096, 3, 1, fd, mem_alloc_5.gpu_va);
  44. if (memory_5 == MAP_FAILED) printf("Error mapping memory_5\n");
  45. struct mali_ioctl_mem_alloc mem_alloc_6 = {
  46. .va_pages = 1,
  47. .commit_pages = 1,
  48. .extent = 0x0,
  49. .flags = MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD,
  50. // GPU memory allocated at GPU VA 0x102020000
  51. };
  52. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_6);
  53. if (rc) printf("Error %d in MEM_ALLOC_6\n", rc);
  54. uint32_t *memory_6 = mmap64(NULL, 4096, 2, 1, fd, mem_alloc_6.gpu_va);
  55. if (memory_6 == MAP_FAILED) printf("Error mapping memory_6\n");
  56. struct mali_ioctl_mem_alloc mem_alloc_8 = {
  57. .va_pages = 64,
  58. .commit_pages = 64,
  59. .extent = 0x0,
  60. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR //| MALI_MEM_CACHED_CPU,
  61. // GPU memory allocated at GPU VA 0x102021000
  62. };
  63. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_8);
  64. if (rc) printf("Error %d in MEM_ALLOC_8\n", rc);
  65. struct mali_ioctl_mem_alloc mem_alloc_9 = {
  66. .va_pages = 64,
  67. .commit_pages = 64,
  68. .extent = 0x0,
  69. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR | MALI_MEM_SAME_VA,
  70. // GPU memory allocated at GPU VA 0x41000
  71. };
  72. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_9);
  73. if (rc) printf("Error %d in MEM_ALLOC_9\n", rc);
  74. uint32_t *memory_9 = mmap64(NULL, 262144, 3, 1, fd, mem_alloc_9.gpu_va);
  75. if (memory_9 == MAP_FAILED) printf("Error mapping memory_9\n");
  76. struct mali_ioctl_mem_alloc mem_alloc_11 = {
  77. .va_pages = 8,
  78. .commit_pages = 8,
  79. .extent = 0x0,
  80. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR,
  81. // GPU memory allocated at GPU VA 0x102061000
  82. };
  83. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_11);
  84. if (rc) printf("Error %d in MEM_ALLOC_11\n", rc);
  85. struct mali_ioctl_mem_alloc mem_alloc_12 = {
  86. .va_pages = 4096,
  87. .commit_pages = 1,
  88. .extent = 0x0,
  89. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_EX,
  90. // GPU memory allocated at GPU VA 0x101000000
  91. };
  92. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_12);
  93. if (rc) printf("Error %d in MEM_ALLOC_12\n", rc);
  94. uint32_t *shader_12 = mmap64(NULL, 4096, 3, 1, fd, mem_alloc_12.gpu_va);
  95. if (shader_12 == MAP_FAILED) printf("Error mapping shader_12\n");
  96. struct mali_ioctl_mem_alloc mem_alloc_14 = {
  97. .va_pages = 1,
  98. .commit_pages = 1,
  99. .extent = 0x0,
  100. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR,
  101. // GPU memory allocated at GPU VA 0x102069000
  102. };
  103. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_14);
  104. if (rc) printf("Error %d in MEM_ALLOC_14\n", rc);
  105. uint32_t *framebuffer;
  106. posix_memalign((void **) &framebuffer, CACHE_LINE_SIZE, 4096*4096*4);
  107. struct mali_mem_import_user_buffer framebuffer_handle = { .ptr = (uint64_t) (uintptr_t) framebuffer, .length = 4096*4096*4 };
  108. struct mali_ioctl_mem_import mem_import_15 = {
  109. .phandle = (uint64_t) (uintptr_t) &framebuffer_handle,
  110. .type = MALI_MEM_IMPORT_TYPE_USER_BUFFER,
  111. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR,
  112. };
  113. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_IMPORT, &mem_import_15);
  114. if (rc) printf("Error %d in MEM_IMPORT_15\n", rc);
  115. uint64_t framebuffer_va = mem_import_15.gpu_va;
  116. struct mali_ioctl_mem_alloc mem_alloc_17 = {
  117. .va_pages = 95,
  118. .commit_pages = 95,
  119. .extent = 0x0,
  120. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR,
  121. // GPU memory allocated at GPU VA 0x1020c8000
  122. };
  123. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_17);
  124. if (rc) printf("Error %d in MEM_ALLOC_17\n", rc);
  125. struct mali_ioctl_mem_alloc mem_alloc_18 = {
  126. .va_pages = 8,
  127. .commit_pages = 8,
  128. .extent = 0x0,
  129. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR /*| MALI_MEM_CACHED_CPU */| MALI_MEM_SAME_VA,
  130. // GPU memory allocated at GPU VA 0x41000
  131. };
  132. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_18);
  133. if (rc) printf("Error %d in MEM_ALLOC_18\n", rc);
  134. uint32_t *memory_18 = mmap64(NULL, 32768, 3, 1, fd, mem_alloc_18.gpu_va);
  135. if (memory_18 == MAP_FAILED) printf("Error mapping memory_18\n");
  136. struct mali_ioctl_mem_alloc mem_alloc_19 = {
  137. .va_pages = 8,
  138. .commit_pages = 8,
  139. .extent = 0x0,
  140. .flags = MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD | MALI_MEM_PROT_GPU_WR | MALI_MEM_SAME_VA,
  141. // GPU memory allocated at GPU VA 0x41000
  142. };
  143. rc = pandev_ioctl(fd, MALI_IOCTL_MEM_ALLOC, &mem_alloc_19);
  144. if (rc) printf("Error %d in MEM_ALLOC_19\n", rc);
  145. uint32_t *memory_19 = mmap64(NULL, 32768, 3, 1, fd, mem_alloc_19.gpu_va);
  146. if (memory_19 == MAP_FAILED) printf("Error mapping memory_19\n");
  147. struct mali_job_descriptor_header job_0 = {
  148. .job_type = 9,
  149. .job_descriptor_size = 0,
  150. .exception_status = 0,
  151. .first_incomplete_task = 0,
  152. .fault_pointer = 0x0,
  153. .job_barrier = 0,
  154. .job_index = 1,
  155. .job_dependency_index_1 = 0,
  156. .job_dependency_index_1 = 0,
  157. .next_job = 0x0,
  158. };
  159. memcpy(memory_18 + 0, &job_0, sizeof(job_0));
  160. struct mali_payload_fragment fragment_0 = {
  161. ._min_tile_coord = MALI_COORDINATE_TO_TILE_MIN(0, 0, 0),
  162. ._max_tile_coord = MALI_COORDINATE_TO_TILE_MAX(400, 240, 0),
  163. .fbd = mem_alloc_19.gpu_va + (8064*4) | MALI_SFBD,
  164. };
  165. memcpy(memory_18 + 8, &fragment_0, sizeof(fragment_0));
  166. struct mali_tentative_sfbd fbd_0 = {
  167. .unknown1 = 0x0,
  168. .flags = 0x1f,
  169. .heap_free_address = 0x0,
  170. .unknown2 = 0xb84e0281,
  171. .unknown3 = 0x141100,
  172. .unknown4 = 0xef018f,
  173. .weights = { 0x0, 0x0, 0x0, 0x0, 0x20c75c0, 0x1, 0xfffff9c0, 0x0, },
  174. .pdcm_1_1 = 0x1020c8000,
  175. .pdcm_1_2 = 0x6400,
  176. .pdcm_2_1 = 0x1020c8000,
  177. .pdcm_2_2 = 0x6400,
  178. .clear_color_1 = 0x664c331a,
  179. .clear_color_2 = 0x664c331a,
  180. .clear_color_3 = 0x664c331a,
  181. .clear_color_4 = 0x664c331a,
  182. .clear_depth_1 = 0.750000,
  183. .clear_depth_2 = 0.750000,
  184. .clear_depth_3 = 0.750000,
  185. .clear_depth_4 = 0.750000,
  186. .clear_stencil = 0xf1,
  187. .unknown_address_1 = mem_alloc_5.gpu_va + 0,
  188. .unknown_address_2 = mem_alloc_5.gpu_va + 512,
  189. .shader_1 = 0x102061000,
  190. .unknown8 = 0x200,
  191. .unknown9 = 0x1000,
  192. .shader_3 = 0x102000000,
  193. .shader_4 = 0x102000000,
  194. };
  195. memcpy(memory_19 + 8064, &fbd_0, sizeof(fbd_0));
  196. mali_external_resource resources_0_0[] = {
  197. framebuffer_va | MALI_EXT_RES_ACCESS_EXCLUSIVE,
  198. };
  199. struct mali_jd_atom_v2 atoms_0[] = {
  200. {
  201. .jc = mem_alloc_18.gpu_va + 0,
  202. .nr_ext_res = 1,
  203. .ext_res_list = resources_0_0,
  204. .pre_dep = {
  205. },
  206. .atom_number = 1,
  207. .prio = 0,
  208. .device_nr = 0,
  209. .compat_core_req = MALI_JD_REQ_FS | MALI_JD_REQ_EXTERNAL_RESOURCES
  210. },
  211. };
  212. struct mali_ioctl_job_submit job_submit_21 = {
  213. .addr = atoms_0,
  214. .nr_atoms = 1,
  215. .stride = 48,
  216. };
  217. rc = pandev_ioctl(fd, MALI_IOCTL_JOB_SUBMIT, &job_submit_21);
  218. if (rc) printf("Error %d in JOB_SUBMIT_21\n", rc);
  219. FILE *fp = fopen("/dev/shm/framebuffer.bin", "wb");
  220. fwrite(framebuffer, 1, 4096*4096*4, fp);
  221. fclose(fp);
  222. }