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_decode.h"
41 read_bin_file(uint32_t devid, const char * filename)
46 if (!strcmp(filename, "-"))
49 fd = open (filename, O_RDONLY);
51 fprintf (stderr, "Failed to open %s: %s\n",
52 filename, strerror (errno));
57 while ((ret = read (fd, buf, sizeof(buf))) > 0) {
58 intel_decode (buf, ret/4, offset, devid, 1);
65 read_data_file(uint32_t devid, const char * filename)
68 uint32_t *data = NULL;
69 int data_size = 0, count = 0, line_number = 0, matched;
72 uint32_t offset, value;
73 uint32_t gtt_offset = 0;
75 if (!strcmp(filename, "-"))
78 file = fopen (filename, "r");
81 fprintf (stderr, "Failed to open %s: %s\n",
82 filename, strerror (errno));
86 while (getline (&line, &line_size, file) > 0) {
89 matched = sscanf (line, "%08x : %08x", &offset, &value);
91 printf("ignoring line %s", line);
98 if (count > data_size) {
99 data_size = data_size ? data_size * 2 : 1024;
100 data = realloc (data, data_size * sizeof (uint32_t));
102 fprintf (stderr, "Out of memory.\n");
107 data[count-1] = value;
111 intel_decode (data, count, gtt_offset, devid, 0);
121 read_autodetect_file(uint32_t devid, const char * filename)
126 file = fopen (filename, "r");
128 fprintf (stderr, "Failed to open %s: %s\n",
129 filename, strerror (errno));
133 while ((c = fgetc(file)) != EOF) {
134 /* totally lazy binary detector */
144 read_bin_file(devid, filename);
146 read_data_file(devid, filename);
152 main (int argc, char *argv[])
154 uint32_t devid = 0xa011;
156 int option_index = 0;
159 static struct option long_options[] = {
160 {"devid", 1, 0, 'd'},
161 {"ascii", 0, 0, 'a'},
162 {"binary", 0, 0, 'b'}
165 while((c = getopt_long(argc, argv, "ab",
166 long_options, &option_index)) != -1) {
169 devid = strtoul(optarg, NULL, 0);
178 printf("unkown command options\n");
183 if (optind == argc) {
184 fprintf(stderr, "no input file given\n");
188 for (i = optind; i < argc; i++) {
189 /* For stdin input, let's read as data file */
190 if (!strcmp(argv[i], "-")) {
191 read_data_file(devid, argv[i]);
195 read_bin_file(devid, argv[i]);
196 else if (binary == 0)
197 read_data_file(devid, argv[i]);
199 read_autodetect_file(devid, argv[i]);