2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "pipe/p_context.h"
36 #include "pipe/p_state.h"
37 #include "pipe/p_debug.h"
42 unsigned next_free_page
;
46 extern char *__progname
;
49 struct aub_file_header
{
50 unsigned int instruction_type
;
54 unsigned char application
[8*4];
58 unsigned int timezone
:8;
59 unsigned int second
:8;
60 unsigned int minute
:8;
62 unsigned int comment_length
:16;
66 struct aub_block_header
{
67 unsigned int instruction_type
;
68 unsigned int operation
:8;
70 unsigned int address_space
:8;
72 unsigned int general_state_type
:8;
73 unsigned int surface_state_type
:8;
80 unsigned int instruction_type
;
83 unsigned int pitch
:16;
85 unsigned int format
:8;
86 unsigned int xsize
:16;
87 unsigned int ysize
:16;
102 enum command_write_type
{
105 CW_PRIMARY_RING_B
, /* XXX - disagreement with listaub! */
110 enum memory_map_type
{
124 #define AUB_FILE_HEADER 0xe085000b
125 #define AUB_BLOCK_HEADER 0xe0c10003
126 #define AUB_DUMP_BMP 0xe09e0004
128 /* Registers to control page table
130 #define PGETBL_CTL 0x2020
131 #define PGETBL_ENABLED 0x1
133 #define NR_GTT_ENTRIES 65536 /* 256 mb */
137 fprintf(stderr, "failed to write aub data at %s/%d\n", __FUNCTION__, __LINE__); \
142 /* Emit the headers at the top of each aubfile. Initialize the GTT.
144 static void init_aubfile( FILE *aub_file
)
146 struct aub_file_header fh
;
147 struct aub_block_header bh
;
154 /* Emit the aub header:
156 memset(&fh
, 0, sizeof(fh
));
158 fh
.instruction_type
= AUB_FILE_HEADER
;
161 memcpy(fh
.application
, __progname
, sizeof(fh
.application
));
162 fh
.day
= (nr
>>24) & 0xff;
166 fh
.second
= nr
& 0xff;
167 fh
.minute
= (nr
>>8) & 0xff;
168 fh
.hour
= (nr
>>16) & 0xff;
169 fh
.comment_length
= 0x0;
171 if (fwrite(&fh
, sizeof(fh
), 1, aub_file
) < 0)
174 /* Setup the GTT starting at main memory address zero (!):
176 memset(&bh
, 0, sizeof(bh
));
178 bh
.instruction_type
= AUB_BLOCK_HEADER
;
179 bh
.operation
= BH_MMI0_WRITE32
;
181 bh
.address_space
= ADDR_GTT
; /* ??? */
182 bh
.general_state_type
= 0x0;
183 bh
.surface_state_type
= 0x0;
184 bh
.address
= PGETBL_CTL
;
187 if (fwrite(&bh
, sizeof(bh
), 1, aub_file
) < 0)
190 data
= 0x0 | PGETBL_ENABLED
;
192 if (fwrite(&data
, sizeof(data
), 1, aub_file
) < 0)
197 static void init_aub_gtt( struct brw_aubfile
*aubfile
,
198 unsigned start_offset
,
201 FILE *aub_file
= aubfile
->file
;
202 struct aub_block_header bh
;
205 assert(start_offset
+ size
< NR_GTT_ENTRIES
* 4096);
208 memset(&bh
, 0, sizeof(bh
));
210 bh
.instruction_type
= AUB_BLOCK_HEADER
;
211 bh
.operation
= BH_DATA_WRITE
;
213 bh
.address_space
= ADDR_MAIN
;
214 bh
.general_state_type
= 0x0;
215 bh
.surface_state_type
= 0x0;
216 bh
.address
= start_offset
/ 4096 * 4;
217 bh
.length
= size
/ 4096 * 4;
219 if (fwrite(&bh
, sizeof(bh
), 1, aub_file
) < 0)
222 for (i
= 0; i
< size
/ 4096; i
++) {
223 unsigned data
= aubfile
->next_free_page
| 1;
225 aubfile
->next_free_page
+= 4096;
227 if (fwrite(&data
, sizeof(data
), 1, aub_file
) < 0)
233 static void write_block_header( FILE *aub_file
,
234 struct aub_block_header
*bh
,
235 const unsigned *data
,
240 if (fwrite(bh
, sizeof(*bh
), 1, aub_file
) < 0)
243 if (fwrite(data
, sz
, 1, aub_file
) < 0)
250 static void write_dump_bmp( FILE *aub_file
,
251 struct aub_dump_bmp
*db
)
253 if (fwrite(db
, sizeof(*db
), 1, aub_file
) < 0)
261 void brw_aub_gtt_data( struct brw_aubfile
*aubfile
,
266 unsigned state_type
)
268 struct aub_block_header bh
;
270 bh
.instruction_type
= AUB_BLOCK_HEADER
;
271 bh
.operation
= BH_DATA_WRITE
;
273 bh
.address_space
= ADDR_GTT
;
276 if (type
== DW_GENERAL_STATE
) {
277 bh
.general_state_type
= state_type
;
278 bh
.surface_state_type
= 0;
281 bh
.general_state_type
= 0;
282 bh
.surface_state_type
= state_type
;
289 write_block_header(aubfile
->file
, &bh
, data
, sz
);
294 void brw_aub_gtt_cmds( struct brw_aubfile
*aubfile
,
299 struct aub_block_header bh
;
300 unsigned type
= CW_PRIMARY_RING_A
;
303 bh
.instruction_type
= AUB_BLOCK_HEADER
;
304 bh
.operation
= BH_COMMAND_WRITE
;
306 bh
.address_space
= ADDR_GTT
;
308 bh
.general_state_type
= 0;
309 bh
.surface_state_type
= 0;
314 write_block_header(aubfile
->file
, &bh
, data
, sz
);
317 void brw_aub_dump_bmp( struct brw_aubfile
*aubfile
,
318 struct pipe_surface
*surface
,
319 unsigned gtt_offset
)
321 struct aub_dump_bmp db
;
324 assert(surface
->block
.width
== 1);
325 assert(surface
->block
.height
== 1);
327 if (surface
->block
.size
== 4)
332 db
.instruction_type
= AUB_DUMP_BMP
;
336 db
.bpp
= surface
->block
.size
* 8;
337 db
.pitch
= surface
->stride
/surface
->block
.size
;
338 db
.xsize
= surface
->width
;
339 db
.ysize
= surface
->height
;
340 db
.addr
= gtt_offset
;
341 db
.unknown
= /* surface->tiled ? 0x4 : */ 0x0;
343 write_dump_bmp(aubfile
->file
, &db
);
348 struct brw_aubfile
*brw_aubfile_create( void )
350 struct brw_aubfile
*aubfile
= CALLOC_STRUCT(brw_aubfile
);
357 if (getenv("INTEL_AUBFILE")) {
358 val
= snprintf(filename
, sizeof(filename
), "%s%d.aub", getenv("INTEL_AUBFILE"), i
%4);
359 debug_printf("--> Aub file: %s\n", filename
);
360 aubfile
->file
= fopen(filename
, "w");
363 val
= snprintf(filename
, sizeof(filename
), "%s.aub", __progname
);
364 if (val
< 0 || val
> sizeof(filename
))
365 strcpy(filename
, "default.aub");
367 debug_printf("--> Aub file: %s\n", filename
);
368 aubfile
->file
= fopen(filename
, "w");
371 if (!aubfile
->file
) {
372 debug_printf("couldn't open aubfile\n");
376 init_aubfile(aubfile
->file
);
378 /* The GTT is located starting address zero in main memory. Pages
379 * to populate the gtt start after this point.
381 aubfile
->next_free_page
= (NR_GTT_ENTRIES
* 4 + 4095) & ~4095;
383 /* More or less correspond with all the agp regions mapped by the
386 init_aub_gtt(aubfile
, 0, 4096*4);
387 init_aub_gtt(aubfile
, AUB_BUF_START
, AUB_BUF_SIZE
);
392 void brw_aub_destroy( struct brw_aubfile
*aubfile
)
394 fclose(aubfile
->file
);