pan/midgard: Fix REGISTER_OFFSET
[mesa.git] / src / panfrost / pandecode / cmdline.c
1 /*
2 * Copyright (C) 2019 Alyssa Rosenzweig
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
27 #include <stdint.h>
28 #include <string.h>
29
30 #include "decode.h"
31
32 /* Parsing */
33
34 static FILE *
35 pandecode_read_filename(const char *base, const char *name)
36 {
37 char *fn = NULL;
38 asprintf(&fn, "%s/%s", base, name);
39
40 FILE *fp = fopen(fn, "rb");
41 free(fn);
42
43 return fp;
44 }
45
46 static void
47 pandecode_read_memory(const char *base, const char *name, mali_ptr gpu_va)
48 {
49 FILE *fp = pandecode_read_filename(base, name);
50
51 if (!fp) {
52 fprintf(stderr, "Warning: missing %s\n", name);
53 return;
54 }
55
56 fseek(fp, 0, SEEK_END);
57 long sz = ftell(fp);
58 fseek(fp, 0, SEEK_SET);
59
60 char *buf = malloc(sz);
61 assert(buf);
62 fread(buf, 1, sz, fp);
63 fclose(fp);
64
65 pandecode_inject_mmap(gpu_va, buf, sz, name);
66 }
67
68 static void
69 pandecode_read_mmap(const char *base, const char *line)
70 {
71 assert(strlen(line) < 500);
72
73 mali_ptr addr;
74 char name[512];
75
76 sscanf(line, "MMAP %" PRIx64 " %s", &addr, name);
77 pandecode_read_memory(base, name, addr);
78 }
79
80 static void
81 pandecode_read_job_submit(const char *base, const char *line)
82 {
83 mali_ptr addr;
84 unsigned core_req;
85 unsigned is_bifrost;
86
87 sscanf(line, "JS %" PRIx64 " %x %x", &addr, &core_req, &is_bifrost);
88 pandecode_jc(addr, is_bifrost);
89 }
90
91
92
93 /* Reads the control file, processing as it goes. */
94
95 static void
96 pandecode_read_control(const char *base)
97 {
98 FILE *fp = pandecode_read_filename(base, "control.log");
99
100 if (!fp) {
101 fprintf(stderr, "Invalid directory path\n");
102 return;
103 }
104
105 char *line = NULL;
106 size_t len = 0;
107
108 while (getline(&line, &len, fp) != -1) {
109 switch (line[0]) {
110 case 'M':
111 pandecode_read_mmap(base, line);
112 break;
113
114 case 'J':
115 pandecode_read_job_submit(base, line);
116 break;
117
118 default:
119 assert(0);
120 break;
121 }
122 }
123 }
124
125 int
126 main(int argc, char **argv)
127 {
128 if (argc < 2) {
129 fprintf(stderr, "Usage: pandecode [directory]\n");
130 exit(1);
131 }
132
133 pandecode_initialize();
134 pandecode_read_control(argv[1]);
135 }