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 fd = open (filename, O_RDONLY);
48 fprintf (stderr, "Failed to open %s: %s\n",
49 filename, strerror (errno));
54 while ((ret = read (fd, buf, sizeof(buf))) > 0) {
55 intel_decode (buf, ret/4, offset, devid, 1);
62 read_data_file(uint32_t devid, const char * filename)
65 uint32_t *data = NULL;
66 int data_size = 0, count = 0, line_number = 0, matched;
69 uint32_t offset, value;
70 uint32_t gtt_offset = 0;
72 file = fopen (filename, "r");
74 fprintf (stderr, "Failed to open %s: %s\n",
75 filename, strerror (errno));
79 while (getline (&line, &line_size, file) > 0) {
82 matched = sscanf (line, "%08x : %08x", &offset, &value);
84 printf("ignoring line %s", line);
91 if (count > data_size) {
92 data_size = data_size ? data_size * 2 : 1024;
93 data = realloc (data, data_size * sizeof (uint32_t));
95 fprintf (stderr, "Out of memory.\n");
100 data[count-1] = value;
104 intel_decode (data, count, gtt_offset, devid, 0);
114 read_autodetect_file(uint32_t devid, const char * filename)
119 file = fopen (filename, "r");
121 fprintf (stderr, "Failed to open %s: %s\n",
122 filename, strerror (errno));
126 while ((c = fgetc(file)) != EOF) {
127 /* totally lazy binary detector */
137 read_bin_file(devid, filename);
139 read_data_file(devid, filename);
145 main (int argc, char *argv[])
147 uint32_t devid = 0xa011;
149 int option_index = 0;
152 static struct option long_options[] = {
153 {"devid", 1, 0, 'd'},
154 {"ascii", 0, 0, 'a'},
155 {"binary", 0, 0, 'b'}
158 while((c = getopt_long(argc, argv, "ab",
159 long_options, &option_index)) != -1) {
162 devid = strtoul(optarg, NULL, 0);
171 printf("unkown command options\n");
176 if (optind == argc) {
177 fprintf(stderr, "no input file given\n");
181 for (i = optind; i < argc; i++) {
183 read_bin_file(devid, argv[i]);
184 else if (binary == 0)
185 read_data_file(devid, argv[i]);
187 read_autodetect_file(devid, argv[i]);