etnaviv_dump.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #include <linux/devcoredump.h>
  17. #include "etnaviv_cmdbuf.h"
  18. #include "etnaviv_dump.h"
  19. #include "etnaviv_gem.h"
  20. #include "etnaviv_gpu.h"
  21. #include "etnaviv_mmu.h"
  22. #include "state.xml.h"
  23. #include "state_hi.xml.h"
  24. struct core_dump_iterator {
  25. void *start;
  26. struct etnaviv_dump_object_header *hdr;
  27. void *data;
  28. };
  29. static const unsigned short etnaviv_dump_registers[] = {
  30. VIVS_HI_AXI_STATUS,
  31. VIVS_HI_CLOCK_CONTROL,
  32. VIVS_HI_IDLE_STATE,
  33. VIVS_HI_AXI_CONFIG,
  34. VIVS_HI_INTR_ENBL,
  35. VIVS_HI_CHIP_IDENTITY,
  36. VIVS_HI_CHIP_FEATURE,
  37. VIVS_HI_CHIP_MODEL,
  38. VIVS_HI_CHIP_REV,
  39. VIVS_HI_CHIP_DATE,
  40. VIVS_HI_CHIP_TIME,
  41. VIVS_HI_CHIP_MINOR_FEATURE_0,
  42. VIVS_HI_CACHE_CONTROL,
  43. VIVS_HI_AXI_CONTROL,
  44. VIVS_PM_POWER_CONTROLS,
  45. VIVS_PM_MODULE_CONTROLS,
  46. VIVS_PM_MODULE_STATUS,
  47. VIVS_PM_PULSE_EATER,
  48. VIVS_MC_MMU_FE_PAGE_TABLE,
  49. VIVS_MC_MMU_TX_PAGE_TABLE,
  50. VIVS_MC_MMU_PE_PAGE_TABLE,
  51. VIVS_MC_MMU_PEZ_PAGE_TABLE,
  52. VIVS_MC_MMU_RA_PAGE_TABLE,
  53. VIVS_MC_DEBUG_MEMORY,
  54. VIVS_MC_MEMORY_BASE_ADDR_RA,
  55. VIVS_MC_MEMORY_BASE_ADDR_FE,
  56. VIVS_MC_MEMORY_BASE_ADDR_TX,
  57. VIVS_MC_MEMORY_BASE_ADDR_PEZ,
  58. VIVS_MC_MEMORY_BASE_ADDR_PE,
  59. VIVS_MC_MEMORY_TIMING_CONTROL,
  60. VIVS_MC_BUS_CONFIG,
  61. VIVS_FE_DMA_STATUS,
  62. VIVS_FE_DMA_DEBUG_STATE,
  63. VIVS_FE_DMA_ADDRESS,
  64. VIVS_FE_DMA_LOW,
  65. VIVS_FE_DMA_HIGH,
  66. VIVS_FE_AUTO_FLUSH,
  67. };
  68. static void etnaviv_core_dump_header(struct core_dump_iterator *iter,
  69. u32 type, void *data_end)
  70. {
  71. struct etnaviv_dump_object_header *hdr = iter->hdr;
  72. hdr->magic = cpu_to_le32(ETDUMP_MAGIC);
  73. hdr->type = cpu_to_le32(type);
  74. hdr->file_offset = cpu_to_le32(iter->data - iter->start);
  75. hdr->file_size = cpu_to_le32(data_end - iter->data);
  76. iter->hdr++;
  77. iter->data += hdr->file_size;
  78. }
  79. static void etnaviv_core_dump_registers(struct core_dump_iterator *iter,
  80. struct etnaviv_gpu *gpu)
  81. {
  82. struct etnaviv_dump_registers *reg = iter->data;
  83. unsigned int i;
  84. for (i = 0; i < ARRAY_SIZE(etnaviv_dump_registers); i++, reg++) {
  85. reg->reg = etnaviv_dump_registers[i];
  86. reg->value = gpu_read(gpu, etnaviv_dump_registers[i]);
  87. }
  88. etnaviv_core_dump_header(iter, ETDUMP_BUF_REG, reg);
  89. }
  90. static void etnaviv_core_dump_mmu(struct core_dump_iterator *iter,
  91. struct etnaviv_gpu *gpu, size_t mmu_size)
  92. {
  93. etnaviv_iommu_dump(gpu->mmu, iter->data);
  94. etnaviv_core_dump_header(iter, ETDUMP_BUF_MMU, iter->data + mmu_size);
  95. }
  96. static void etnaviv_core_dump_mem(struct core_dump_iterator *iter, u32 type,
  97. void *ptr, size_t size, u64 iova)
  98. {
  99. memcpy(iter->data, ptr, size);
  100. iter->hdr->iova = cpu_to_le64(iova);
  101. etnaviv_core_dump_header(iter, type, iter->data + size);
  102. }
  103. void etnaviv_core_dump(struct etnaviv_gpu *gpu)
  104. {
  105. struct core_dump_iterator iter;
  106. struct etnaviv_vram_mapping *vram;
  107. struct etnaviv_gem_object *obj;
  108. struct etnaviv_cmdbuf *cmd;
  109. unsigned int n_obj, n_bomap_pages;
  110. size_t file_size, mmu_size;
  111. __le64 *bomap, *bomap_start;
  112. mmu_size = etnaviv_iommu_dump_size(gpu->mmu);
  113. /* We always dump registers, mmu, ring and end marker */
  114. n_obj = 4;
  115. n_bomap_pages = 0;
  116. file_size = ARRAY_SIZE(etnaviv_dump_registers) *
  117. sizeof(struct etnaviv_dump_registers) +
  118. mmu_size + gpu->buffer->size;
  119. /* Add in the active command buffers */
  120. list_for_each_entry(cmd, &gpu->active_cmd_list, node) {
  121. file_size += cmd->size;
  122. n_obj++;
  123. }
  124. /* Add in the active buffer objects */
  125. list_for_each_entry(vram, &gpu->mmu->mappings, mmu_node) {
  126. if (!vram->use)
  127. continue;
  128. obj = vram->object;
  129. file_size += obj->base.size;
  130. n_bomap_pages += obj->base.size >> PAGE_SHIFT;
  131. n_obj++;
  132. }
  133. /* If we have any buffer objects, add a bomap object */
  134. if (n_bomap_pages) {
  135. file_size += n_bomap_pages * sizeof(__le64);
  136. n_obj++;
  137. }
  138. /* Add the size of the headers */
  139. file_size += sizeof(*iter.hdr) * n_obj;
  140. /* Allocate the file in vmalloc memory, it's likely to be big */
  141. iter.start = __vmalloc(file_size, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY,
  142. PAGE_KERNEL);
  143. if (!iter.start) {
  144. dev_warn(gpu->dev, "failed to allocate devcoredump file\n");
  145. return;
  146. }
  147. /* Point the data member after the headers */
  148. iter.hdr = iter.start;
  149. iter.data = &iter.hdr[n_obj];
  150. memset(iter.hdr, 0, iter.data - iter.start);
  151. etnaviv_core_dump_registers(&iter, gpu);
  152. etnaviv_core_dump_mmu(&iter, gpu, mmu_size);
  153. etnaviv_core_dump_mem(&iter, ETDUMP_BUF_RING, gpu->buffer->vaddr,
  154. gpu->buffer->size,
  155. etnaviv_cmdbuf_get_va(gpu->buffer));
  156. list_for_each_entry(cmd, &gpu->active_cmd_list, node)
  157. etnaviv_core_dump_mem(&iter, ETDUMP_BUF_CMD, cmd->vaddr,
  158. cmd->size, etnaviv_cmdbuf_get_va(cmd));
  159. /* Reserve space for the bomap */
  160. if (n_bomap_pages) {
  161. bomap_start = bomap = iter.data;
  162. memset(bomap, 0, sizeof(*bomap) * n_bomap_pages);
  163. etnaviv_core_dump_header(&iter, ETDUMP_BUF_BOMAP,
  164. bomap + n_bomap_pages);
  165. } else {
  166. /* Silence warning */
  167. bomap_start = bomap = NULL;
  168. }
  169. list_for_each_entry(vram, &gpu->mmu->mappings, mmu_node) {
  170. struct page **pages;
  171. void *vaddr;
  172. if (vram->use == 0)
  173. continue;
  174. obj = vram->object;
  175. mutex_lock(&obj->lock);
  176. pages = etnaviv_gem_get_pages(obj);
  177. mutex_unlock(&obj->lock);
  178. if (pages) {
  179. int j;
  180. iter.hdr->data[0] = bomap - bomap_start;
  181. for (j = 0; j < obj->base.size >> PAGE_SHIFT; j++)
  182. *bomap++ = cpu_to_le64(page_to_phys(*pages++));
  183. }
  184. iter.hdr->iova = cpu_to_le64(vram->iova);
  185. vaddr = etnaviv_gem_vmap(&obj->base);
  186. if (vaddr)
  187. memcpy(iter.data, vaddr, obj->base.size);
  188. etnaviv_core_dump_header(&iter, ETDUMP_BUF_BO, iter.data +
  189. obj->base.size);
  190. }
  191. etnaviv_core_dump_header(&iter, ETDUMP_BUF_END, iter.data);
  192. dev_coredumpv(gpu->dev, iter.start, iter.data - iter.start, GFP_KERNEL);
  193. }