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>
34 #include "xlib_brw_aub.h"
35 #include "pipe/p_context.h"
36 #include "pipe/p_state.h"
37 #include "util/u_debug.h"
38 #include "util/u_memory.h"
39 #include "softpipe/sp_texture.h"
44 unsigned next_free_page
;
48 extern char *__progname
;
51 struct aub_file_header
{
52 unsigned int instruction_type
;
56 unsigned char application
[8*4];
60 unsigned int timezone
:8;
61 unsigned int second
:8;
62 unsigned int minute
:8;
64 unsigned int comment_length
:16;
68 struct aub_block_header
{
69 unsigned int instruction_type
;
70 unsigned int operation
:8;
72 unsigned int address_space
:8;
74 unsigned int general_state_type
:8;
75 unsigned int surface_state_type
:8;
82 unsigned int instruction_type
;
85 unsigned int pitch
:16;
87 unsigned int format
:8;
88 unsigned int xsize
:16;
89 unsigned int ysize
:16;
100 BH_CONFIG_MEMORY_MAP
,
104 enum command_write_type
{
107 CW_PRIMARY_RING_B
, /* XXX - disagreement with listaub! */
112 enum memory_map_type
{
126 #define AUB_FILE_HEADER 0xe085000b
127 #define AUB_BLOCK_HEADER 0xe0c10003
128 #define AUB_DUMP_BMP 0xe09e0004
130 /* Registers to control page table
132 #define PGETBL_CTL 0x2020
133 #define PGETBL_ENABLED 0x1
135 #define NR_GTT_ENTRIES 65536 /* 256 mb */
139 fprintf(stderr, "failed to write aub data at %s/%d\n", __FUNCTION__, __LINE__); \
144 /* Emit the headers at the top of each aubfile. Initialize the GTT.
146 static void init_aubfile( FILE *aub_file
)
148 struct aub_file_header fh
;
149 struct aub_block_header bh
;
156 /* Emit the aub header:
158 memset(&fh
, 0, sizeof(fh
));
160 fh
.instruction_type
= AUB_FILE_HEADER
;
163 memcpy(fh
.application
, __progname
, sizeof(fh
.application
));
164 fh
.day
= (nr
>>24) & 0xff;
168 fh
.second
= nr
& 0xff;
169 fh
.minute
= (nr
>>8) & 0xff;
170 fh
.hour
= (nr
>>16) & 0xff;
171 fh
.comment_length
= 0x0;
173 if (fwrite(&fh
, sizeof(fh
), 1, aub_file
) < 0)
176 /* Setup the GTT starting at main memory address zero (!):
178 memset(&bh
, 0, sizeof(bh
));
180 bh
.instruction_type
= AUB_BLOCK_HEADER
;
181 bh
.operation
= BH_MMI0_WRITE32
;
183 bh
.address_space
= ADDR_GTT
; /* ??? */
184 bh
.general_state_type
= 0x0;
185 bh
.surface_state_type
= 0x0;
186 bh
.address
= PGETBL_CTL
;
189 if (fwrite(&bh
, sizeof(bh
), 1, aub_file
) < 0)
192 data
= 0x0 | PGETBL_ENABLED
;
194 if (fwrite(&data
, sizeof(data
), 1, aub_file
) < 0)
199 static void init_aub_gtt( struct brw_aubfile
*aubfile
,
200 unsigned start_offset
,
203 FILE *aub_file
= aubfile
->file
;
204 struct aub_block_header bh
;
207 assert(start_offset
+ size
< NR_GTT_ENTRIES
* 4096);
210 memset(&bh
, 0, sizeof(bh
));
212 bh
.instruction_type
= AUB_BLOCK_HEADER
;
213 bh
.operation
= BH_DATA_WRITE
;
215 bh
.address_space
= ADDR_MAIN
;
216 bh
.general_state_type
= 0x0;
217 bh
.surface_state_type
= 0x0;
218 bh
.address
= start_offset
/ 4096 * 4;
219 bh
.length
= size
/ 4096 * 4;
221 if (fwrite(&bh
, sizeof(bh
), 1, aub_file
) < 0)
224 for (i
= 0; i
< size
/ 4096; i
++) {
225 unsigned data
= aubfile
->next_free_page
| 1;
227 aubfile
->next_free_page
+= 4096;
229 if (fwrite(&data
, sizeof(data
), 1, aub_file
) < 0)
235 static void write_block_header( FILE *aub_file
,
236 struct aub_block_header
*bh
,
237 const unsigned *data
,
242 if (fwrite(bh
, sizeof(*bh
), 1, aub_file
) < 0)
245 if (fwrite(data
, sz
, 1, aub_file
) < 0)
252 static void write_dump_bmp( FILE *aub_file
,
253 struct aub_dump_bmp
*db
)
255 if (fwrite(db
, sizeof(*db
), 1, aub_file
) < 0)
263 void brw_aub_gtt_data( struct brw_aubfile
*aubfile
,
268 unsigned state_type
)
270 struct aub_block_header bh
;
272 bh
.instruction_type
= AUB_BLOCK_HEADER
;
273 bh
.operation
= BH_DATA_WRITE
;
275 bh
.address_space
= ADDR_GTT
;
278 if (type
== DW_GENERAL_STATE
) {
279 bh
.general_state_type
= state_type
;
280 bh
.surface_state_type
= 0;
283 bh
.general_state_type
= 0;
284 bh
.surface_state_type
= state_type
;
291 write_block_header(aubfile
->file
, &bh
, data
, sz
);
296 void brw_aub_gtt_cmds( struct brw_aubfile
*aubfile
,
301 struct aub_block_header bh
;
302 unsigned type
= CW_PRIMARY_RING_A
;
305 bh
.instruction_type
= AUB_BLOCK_HEADER
;
306 bh
.operation
= BH_COMMAND_WRITE
;
308 bh
.address_space
= ADDR_GTT
;
310 bh
.general_state_type
= 0;
311 bh
.surface_state_type
= 0;
316 write_block_header(aubfile
->file
, &bh
, data
, sz
);
319 void brw_aub_dump_bmp( struct brw_aubfile
*aubfile
,
320 struct pipe_surface
*surface
,
321 unsigned gtt_offset
)
323 struct aub_dump_bmp db
;
326 assert(surface
->texture
->block
.width
== 1);
327 assert(surface
->texture
->block
.height
== 1);
329 if (surface
->texture
->block
.size
== 4)
334 db
.instruction_type
= AUB_DUMP_BMP
;
338 db
.bpp
= surface
->texture
->block
.size
* 8;
339 db
.pitch
= softpipe_texture(surface
->texture
)->stride
[surface
->level
] /
340 surface
->texture
->block
.size
;
341 db
.xsize
= surface
->width
;
342 db
.ysize
= surface
->height
;
343 db
.addr
= gtt_offset
;
344 db
.unknown
= /* surface->tiled ? 0x4 : */ 0x0;
346 write_dump_bmp(aubfile
->file
, &db
);
351 struct brw_aubfile
*brw_aubfile_create( void )
353 struct brw_aubfile
*aubfile
= CALLOC_STRUCT(brw_aubfile
);
360 if (getenv("INTEL_AUBFILE")) {
361 val
= snprintf(filename
, sizeof(filename
), "%s%d.aub", getenv("INTEL_AUBFILE"), i
%4);
362 debug_printf("--> Aub file: %s\n", filename
);
363 aubfile
->file
= fopen(filename
, "w");
366 val
= snprintf(filename
, sizeof(filename
), "%s.aub", __progname
);
367 if (val
< 0 || val
> sizeof(filename
))
368 strcpy(filename
, "default.aub");
370 debug_printf("--> Aub file: %s\n", filename
);
371 aubfile
->file
= fopen(filename
, "w");
374 if (!aubfile
->file
) {
375 debug_printf("couldn't open aubfile\n");
379 init_aubfile(aubfile
->file
);
381 /* The GTT is located starting address zero in main memory. Pages
382 * to populate the gtt start after this point.
384 aubfile
->next_free_page
= (NR_GTT_ENTRIES
* 4 + 4095) & ~4095;
386 /* More or less correspond with all the agp regions mapped by the
389 init_aub_gtt(aubfile
, 0, 4096*4);
390 init_aub_gtt(aubfile
, AUB_BUF_START
, AUB_BUF_SIZE
);
395 void brw_aub_destroy( struct brw_aubfile
*aubfile
)
397 fclose(aubfile
->file
);