1 /*
2 * Copyright © 2014 Intel Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Mika Kuoppala <mika.kuoppala@intel.com>
25 * Armin Reese <armin.c.reese@intel.com>
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <assert.h>
32
33 #include "intel_renderstate.h"
34 #include "intel_batchbuffer.h"
35
36 static int debug = 0;
37
print_usage(char * s)38 static void print_usage(char *s)
39 {
40 fprintf(stderr, "%s: <gen>\n"
41 " gen: gen to generate for (6,7,8,9)\n",
42 s);
43 }
44
45 /* Creates the intel_renderstate_genX.c file for the particular
46 * GEN product
47 */
print_state(int gen,struct intel_batchbuffer * batch)48 static int print_state(int gen, struct intel_batchbuffer *batch)
49 {
50 int i;
51 unsigned long cmds;
52
53 fprintf(stderr, "Generating for gen%d\n", gen);
54
55 printf("#include \"intel_renderstate.h\"\n\n");
56
57 /* Relocation offsets. These are byte offsets in the golden context
58 * batch buffer where the BB graphics address will be added to
59 * the indirect state offset already stored in those locations. The
60 * resulting value will inform the GPU where the indirect states are.
61 */
62 printf("static const u32 gen%d_null_state_relocs[] = {\n", gen);
63 for (i = 0; i < batch->cmds->num_items; i++) {
64 if (intel_batch_is_reloc(batch, i))
65 printf("\t0x%08x,\n", i * 4);
66 }
67 printf("\t-1,\n};\n\n");
68
69 /* GPU commands to execute to set up the RCS golden state. This
70 * state will become the default config.
71 */
72 printf("static const u32 gen%d_null_state_batch[] = {\n", gen);
73 for (i = 0; i < intel_batch_num_cmds(batch); i++) {
74 const int offset = i * 4;
75 const struct bb_item *cmd = intel_batch_cmd_get(batch, i);
76 printf("\t0x%08x,", cmd->data);
77
78 if (debug)
79 printf("\t /* 0x%08x %s '%s' */", offset,
80 intel_batch_type_as_str(cmd), cmd->str);
81
82 if (offset == batch->cmds_end_offset) {
83 cmds = i + 1;
84 printf("\t /* cmds end */");
85 }
86
87 if (intel_batch_is_reloc(batch, i))
88 printf("\t /* reloc */");
89
90 if (offset == batch->state_start_offset)
91 printf("\t /* state start */");
92
93 if (i == intel_batch_num_cmds(batch) - 1)
94 printf("\t /* state end */");
95
96 printf("\n");
97 }
98
99 printf("};\n\nRO_RENDERSTATE(%d);\n", gen);
100
101 fprintf(stderr, "Commands %lu (%lu bytes)\n", cmds, cmds * 4);
102 fprintf(stderr, "State %lu (%lu bytes)\n", batch->state->num_items, batch->state->num_items * 4);
103 fprintf(stderr, "Total %lu (%lu bytes)\n", batch->cmds->num_items, batch->cmds->num_items * 4);
104 fprintf(stderr, "\n");
105
106 return 0;
107 }
108
109 /* Selects generator function for the given product and executes it. */
do_generate(int gen)110 static int do_generate(int gen)
111 {
112 struct intel_batchbuffer *batch;
113 int ret = -EINVAL;
114 void (*null_state_gen)(struct intel_batchbuffer *batch) = NULL;
115
116 batch = intel_batchbuffer_create();
117 if (batch == NULL)
118 return -ENOMEM;
119
120 switch (gen) {
121 case 6:
122 null_state_gen = gen6_setup_null_render_state;
123 break;
124
125 case 7:
126 null_state_gen = gen7_setup_null_render_state;
127 break;
128
129 case 8:
130 null_state_gen = gen8_setup_null_render_state;
131 break;
132 case 9:
133 null_state_gen = gen9_setup_null_render_state;
134 break;
135 }
136
137 if (null_state_gen == NULL) {
138 printf("no generator found for %d\n", gen);
139 return -EINVAL;
140 }
141
142 null_state_gen(batch);
143 intel_batch_relocate_state(batch);
144
145 ret = print_state(gen, batch);
146
147 return ret;
148 }
149
main(int argc,char * argv[])150 int main(int argc, char *argv[])
151 {
152 if (argc < 2) {
153 print_usage(argv[0]);
154 return 1;
155 }
156
157 if (argc > 2)
158 debug = 1;
159
160 return do_generate(atoi(argv[1]));
161 }
162