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_util.h"
38 #include "pipe/p_debug.h"
43 unsigned next_free_page
;
47 extern char *__progname
;
50 struct aub_file_header
{
51 unsigned int instruction_type
;
55 unsigned char application
[8*4];
59 unsigned int timezone
:8;
60 unsigned int second
:8;
61 unsigned int minute
:8;
63 unsigned int comment_length
:16;
67 struct aub_block_header
{
68 unsigned int instruction_type
;
69 unsigned int operation
:8;
71 unsigned int address_space
:8;
73 unsigned int general_state_type
:8;
74 unsigned int surface_state_type
:8;
81 unsigned int instruction_type
;
84 unsigned int pitch
:16;
86 unsigned int format
:8;
87 unsigned int xsize
:16;
88 unsigned int ysize
:16;
103 enum command_write_type
{
106 CW_PRIMARY_RING_B
, /* XXX - disagreement with listaub! */
111 enum memory_map_type
{
125 #define AUB_FILE_HEADER 0xe085000b
126 #define AUB_BLOCK_HEADER 0xe0c10003
127 #define AUB_DUMP_BMP 0xe09e0004
129 /* Registers to control page table
131 #define PGETBL_CTL 0x2020
132 #define PGETBL_ENABLED 0x1
134 #define NR_GTT_ENTRIES 65536 /* 256 mb */
138 fprintf(stderr, "failed to write aub data at %s/%d\n", __FUNCTION__, __LINE__); \
143 /* Emit the headers at the top of each aubfile. Initialize the GTT.
145 static void init_aubfile( FILE *aub_file
)
147 struct aub_file_header fh
;
148 struct aub_block_header bh
;
155 /* Emit the aub header:
157 memset(&fh
, 0, sizeof(fh
));
159 fh
.instruction_type
= AUB_FILE_HEADER
;
162 memcpy(fh
.application
, __progname
, sizeof(fh
.application
));
163 fh
.day
= (nr
>>24) & 0xff;
167 fh
.second
= nr
& 0xff;
168 fh
.minute
= (nr
>>8) & 0xff;
169 fh
.hour
= (nr
>>16) & 0xff;
170 fh
.comment_length
= 0x0;
172 if (fwrite(&fh
, sizeof(fh
), 1, aub_file
) < 0)
175 /* Setup the GTT starting at main memory address zero (!):
177 memset(&bh
, 0, sizeof(bh
));
179 bh
.instruction_type
= AUB_BLOCK_HEADER
;
180 bh
.operation
= BH_MMI0_WRITE32
;
182 bh
.address_space
= ADDR_GTT
; /* ??? */
183 bh
.general_state_type
= 0x0;
184 bh
.surface_state_type
= 0x0;
185 bh
.address
= PGETBL_CTL
;
188 if (fwrite(&bh
, sizeof(bh
), 1, aub_file
) < 0)
191 data
= 0x0 | PGETBL_ENABLED
;
193 if (fwrite(&data
, sizeof(data
), 1, aub_file
) < 0)
198 static void init_aub_gtt( struct brw_aubfile
*aubfile
,
199 unsigned start_offset
,
202 FILE *aub_file
= aubfile
->file
;
203 struct aub_block_header bh
;
206 assert(start_offset
+ size
< NR_GTT_ENTRIES
* 4096);
209 memset(&bh
, 0, sizeof(bh
));
211 bh
.instruction_type
= AUB_BLOCK_HEADER
;
212 bh
.operation
= BH_DATA_WRITE
;
214 bh
.address_space
= ADDR_MAIN
;
215 bh
.general_state_type
= 0x0;
216 bh
.surface_state_type
= 0x0;
217 bh
.address
= start_offset
/ 4096 * 4;
218 bh
.length
= size
/ 4096 * 4;
220 if (fwrite(&bh
, sizeof(bh
), 1, aub_file
) < 0)
223 for (i
= 0; i
< size
/ 4096; i
++) {
224 unsigned data
= aubfile
->next_free_page
| 1;
226 aubfile
->next_free_page
+= 4096;
228 if (fwrite(&data
, sizeof(data
), 1, aub_file
) < 0)
234 static void write_block_header( FILE *aub_file
,
235 struct aub_block_header
*bh
,
236 const unsigned *data
,
241 if (fwrite(bh
, sizeof(*bh
), 1, aub_file
) < 0)
244 if (fwrite(data
, sz
, 1, aub_file
) < 0)
251 static void write_dump_bmp( FILE *aub_file
,
252 struct aub_dump_bmp
*db
)
254 if (fwrite(db
, sizeof(*db
), 1, aub_file
) < 0)
262 void brw_aub_gtt_data( struct brw_aubfile
*aubfile
,
267 unsigned state_type
)
269 struct aub_block_header bh
;
271 bh
.instruction_type
= AUB_BLOCK_HEADER
;
272 bh
.operation
= BH_DATA_WRITE
;
274 bh
.address_space
= ADDR_GTT
;
277 if (type
== DW_GENERAL_STATE
) {
278 bh
.general_state_type
= state_type
;
279 bh
.surface_state_type
= 0;
282 bh
.general_state_type
= 0;
283 bh
.surface_state_type
= state_type
;
290 write_block_header(aubfile
->file
, &bh
, data
, sz
);
295 void brw_aub_gtt_cmds( struct brw_aubfile
*aubfile
,
300 struct aub_block_header bh
;
301 unsigned type
= CW_PRIMARY_RING_A
;
304 bh
.instruction_type
= AUB_BLOCK_HEADER
;
305 bh
.operation
= BH_COMMAND_WRITE
;
307 bh
.address_space
= ADDR_GTT
;
309 bh
.general_state_type
= 0;
310 bh
.surface_state_type
= 0;
315 write_block_header(aubfile
->file
, &bh
, data
, sz
);
318 void brw_aub_dump_bmp( struct brw_aubfile
*aubfile
,
319 struct pipe_surface
*surface
,
320 unsigned gtt_offset
)
322 struct aub_dump_bmp db
;
325 if (surface
->cpp
== 4)
330 db
.instruction_type
= AUB_DUMP_BMP
;
334 db
.bpp
= surface
->cpp
* 8;
335 db
.pitch
= surface
->pitch
;
336 db
.xsize
= surface
->width
;
337 db
.ysize
= surface
->height
;
338 db
.addr
= gtt_offset
;
339 db
.unknown
= /* surface->tiled ? 0x4 : */ 0x0;
341 write_dump_bmp(aubfile
->file
, &db
);
346 struct brw_aubfile
*brw_aubfile_create( void )
348 struct brw_aubfile
*aubfile
= CALLOC_STRUCT(brw_aubfile
);
355 if (getenv("INTEL_AUBFILE")) {
356 val
= snprintf(filename
, sizeof(filename
), "%s%d.aub", getenv("INTEL_AUBFILE"), i
%4);
357 debug_printf("--> Aub file: %s\n", filename
);
358 aubfile
->file
= fopen(filename
, "w");
361 val
= snprintf(filename
, sizeof(filename
), "%s.aub", __progname
);
362 if (val
< 0 || val
> sizeof(filename
))
363 strcpy(filename
, "default.aub");
365 debug_printf("--> Aub file: %s\n", filename
);
366 aubfile
->file
= fopen(filename
, "w");
369 if (!aubfile
->file
) {
370 debug_printf("couldn't open aubfile\n");
374 init_aubfile(aubfile
->file
);
376 /* The GTT is located starting address zero in main memory. Pages
377 * to populate the gtt start after this point.
379 aubfile
->next_free_page
= (NR_GTT_ENTRIES
* 4 + 4095) & ~4095;
381 /* More or less correspond with all the agp regions mapped by the
384 init_aub_gtt(aubfile
, 0, 4096*4);
385 init_aub_gtt(aubfile
, AUB_BUF_START
, AUB_BUF_SIZE
);
390 void brw_aub_destroy( struct brw_aubfile
*aubfile
)
392 fclose(aubfile
->file
);