2 * Copyright © 2010 Intel Corporation
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:
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
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Chris Wilson <chris@chris-wilson.co.uk>
38 #include <intel_bufmgr.h>
40 struct drm_intel_decode *ctx;
43 read_bin_file(const char * filename)
48 if (!strcmp(filename, "-"))
51 fd = open (filename, O_RDONLY);
53 fprintf (stderr, "Failed to open %s: %s\n",
54 filename, strerror (errno));
58 drm_intel_decode_set_dump_past_end(ctx, 1);
61 while ((ret = read (fd, buf, sizeof(buf))) > 0) {
62 drm_intel_decode_set_batch_pointer(ctx, buf, offset, ret/4);
63 drm_intel_decode(ctx);
70 read_data_file(const char * filename)
73 uint32_t *data = NULL;
74 int data_size = 0, count = 0, line_number = 0, matched;
77 uint32_t offset, value;
78 uint32_t gtt_offset = 0;
80 if (!strcmp(filename, "-"))
83 file = fopen (filename, "r");
86 fprintf (stderr, "Failed to open %s: %s\n",
87 filename, strerror (errno));
91 while (getline (&line, &line_size, file) > 0) {
94 matched = sscanf (line, "%08x : %08x", &offset, &value);
96 printf("ignoring line %s", line);
103 if (count > data_size) {
104 data_size = data_size ? data_size * 2 : 1024;
105 data = realloc (data, data_size * sizeof (uint32_t));
107 fprintf (stderr, "Out of memory.\n");
112 data[count-1] = value;
116 drm_intel_decode_set_batch_pointer(ctx, data, gtt_offset, count);
117 drm_intel_decode(ctx);
127 read_autodetect_file(const char * filename)
132 file = fopen (filename, "r");
134 fprintf (stderr, "Failed to open %s: %s\n",
135 filename, strerror (errno));
139 while ((c = fgetc(file)) != EOF) {
140 /* totally lazy binary detector */
150 read_bin_file(filename);
152 read_data_file(filename);
158 main (int argc, char *argv[])
160 uint32_t devid = 0xa011;
162 int option_index = 0;
165 static struct option long_options[] = {
166 {"devid", 1, 0, 'd'},
167 {"ascii", 0, 0, 'a'},
168 {"binary", 0, 0, 'b'}
171 while((c = getopt_long(argc, argv, "ad:b",
172 long_options, &option_index)) != -1) {
175 devid = strtoul(optarg, NULL, 0);
184 printf("unkown command options\n");
189 ctx = drm_intel_decode_context_alloc(devid);
191 if (optind == argc) {
192 fprintf(stderr, "no input file given\n");
196 for (i = optind; i < argc; i++) {
197 /* For stdin input, let's read as data file */
198 if (!strcmp(argv[i], "-")) {
199 read_data_file(argv[i]);
203 read_bin_file(argv[i]);
204 else if (binary == 0)
205 read_data_file(argv[i]);
207 read_autodetect_file(argv[i]);