2 * Copyright 2004 The Unichrome Project. All Rights Reserved.
3 * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 * Author: Thomas Hellstrom 2004, 2005.
25 * This code was written using docs obtained under NDA from VIA Inc.
27 * Don't run this code directly on an AGP buffer. Due to cache problems it will
31 #include "via_3d_reg.h"
35 #include "via_verifier.h"
51 check_for_header2_err
,
52 check_for_header1_err
,
56 check_z_buffer_addr_mode
,
57 check_destination_addr0
,
58 check_destination_addr1
,
59 check_destination_addr_mode
,
71 check_texture_addr_mode
,
72 check_for_vertex_count
,
73 check_number_texunits
,
78 * Associates each hazard above with a possible multi-command
79 * sequence. For example an address that is split over multiple
80 * commands and that needs to be checked at the first command
81 * that does not include any part of the address.
84 static drm_via_sequence_t seqs
[] = {
117 static hz_init_t init_table1
[] = {
118 {0xf2, check_for_header2_err
},
119 {0xf0, check_for_header1_err
},
120 {0xee, check_for_fire
},
121 {0xcc, check_for_dummy
},
122 {0xdd, check_for_dd
},
124 {0x10, check_z_buffer_addr0
},
125 {0x11, check_z_buffer_addr1
},
126 {0x12, check_z_buffer_addr_mode
},
144 {0x40, check_destination_addr0
},
145 {0x41, check_destination_addr1
},
146 {0x42, check_destination_addr_mode
},
165 {0x7D, check_for_vertex_count
}
168 static hz_init_t init_table2
[] = {
169 {0xf2, check_for_header2_err
},
170 {0xf0, check_for_header1_err
},
171 {0xee, check_for_fire
},
172 {0xcc, check_for_dummy
},
173 {0x00, check_texture_addr0
},
174 {0x01, check_texture_addr0
},
175 {0x02, check_texture_addr0
},
176 {0x03, check_texture_addr0
},
177 {0x04, check_texture_addr0
},
178 {0x05, check_texture_addr0
},
179 {0x06, check_texture_addr0
},
180 {0x07, check_texture_addr0
},
181 {0x08, check_texture_addr0
},
182 {0x09, check_texture_addr0
},
183 {0x20, check_texture_addr1
},
184 {0x21, check_texture_addr1
},
185 {0x22, check_texture_addr1
},
186 {0x23, check_texture_addr4
},
187 {0x2B, check_texture_addr3
},
188 {0x2C, check_texture_addr3
},
189 {0x2D, check_texture_addr3
},
190 {0x2E, check_texture_addr3
},
191 {0x2F, check_texture_addr3
},
192 {0x30, check_texture_addr3
},
193 {0x31, check_texture_addr3
},
194 {0x32, check_texture_addr3
},
195 {0x33, check_texture_addr3
},
196 {0x34, check_texture_addr3
},
197 {0x4B, check_texture_addr5
},
198 {0x4C, check_texture_addr6
},
199 {0x51, check_texture_addr7
},
200 {0x52, check_texture_addr8
},
201 {0x77, check_texture_addr2
},
205 {0x7B, check_texture_addr_mode
},
226 static hz_init_t init_table3
[] = {
227 {0xf2, check_for_header2_err
},
228 {0xf0, check_for_header1_err
},
229 {0xcc, check_for_dummy
},
230 {0x00, check_number_texunits
}
233 static hazard_t table1
[256];
234 static hazard_t table2
[256];
235 static hazard_t table3
[256];
237 static __inline__
int
238 eat_words(const uint32_t ** buf
, const uint32_t * buf_end
, unsigned num_words
)
240 if ((buf_end
- *buf
) >= num_words
) {
244 DRM_ERROR("Illegal termination of DMA command buffer\n");
249 * Partially stolen from drm_memory.h
252 static __inline__ drm_local_map_t
*via_drm_lookup_agp_map(drm_via_state_t
*seq
,
253 unsigned long offset
,
257 struct list_head
*list
;
258 drm_map_list_t
*r_list
;
259 drm_local_map_t
*map
= seq
->map_cache
;
261 if (map
&& map
->offset
<= offset
262 && (offset
+ size
) <= (map
->offset
+ map
->size
)) {
266 list_for_each(list
, &dev
->maplist
->head
) {
267 r_list
= (drm_map_list_t
*) list
;
271 if (map
->offset
<= offset
272 && (offset
+ size
) <= (map
->offset
+ map
->size
)
273 && !(map
->flags
& _DRM_RESTRICTED
)
274 && (map
->type
== _DRM_AGP
)) {
275 seq
->map_cache
= map
;
283 * Require that all AGP texture levels reside in the same AGP map which should
284 * be mappable by the client. This is not a big restriction.
285 * FIXME: To actually enforce this security policy strictly, drm_rmmap
286 * would have to wait for dma quiescent before removing an AGP map.
287 * The via_drm_lookup_agp_map call in reality seems to take
288 * very little CPU time.
291 static __inline__
int finish_current_sequence(drm_via_state_t
* cur_seq
)
293 switch (cur_seq
->unfinished
) {
295 DRM_DEBUG("Z Buffer start address is 0x%x\n", cur_seq
->z_addr
);
298 DRM_DEBUG("Destination start address is 0x%x\n",
302 if (cur_seq
->agp_texture
) {
304 cur_seq
->tex_level_lo
[cur_seq
->texture
];
305 unsigned end
= cur_seq
->tex_level_hi
[cur_seq
->texture
];
306 unsigned long lo
= ~0, hi
= 0, tmp
;
307 uint32_t *addr
, *pitch
, *height
, tex
;
316 &(cur_seq
->t_addr
[tex
= cur_seq
->texture
][start
]);
317 pitch
= &(cur_seq
->pitch
[tex
][start
]);
318 height
= &(cur_seq
->height
[tex
][start
]);
320 for (i
= start
; i
<= end
; ++i
) {
324 tmp
+= (*height
++ << *pitch
++);
329 if (!via_drm_lookup_agp_map
330 (cur_seq
, lo
, hi
- lo
, cur_seq
->dev
)) {
332 ("AGP texture is not in allowed map\n");
340 cur_seq
->unfinished
= no_sequence
;
344 static __inline__
int
345 investigate_hazard(uint32_t cmd
, hazard_t hz
, drm_via_state_t
* cur_seq
)
347 register uint32_t tmp
, *tmp_addr
;
349 if (cur_seq
->unfinished
&& (cur_seq
->unfinished
!= seqs
[hz
])) {
351 if ((ret
= finish_current_sequence(cur_seq
)))
356 case check_for_header2
:
357 if (cmd
== HALCYON_HEADER2
)
360 case check_for_header1
:
361 if ((cmd
& HALCYON_HEADER1MASK
) == HALCYON_HEADER1
)
364 case check_for_header2_err
:
365 if (cmd
== HALCYON_HEADER2
)
367 DRM_ERROR("Illegal DMA HALCYON_HEADER2 command\n");
369 case check_for_header1_err
:
370 if ((cmd
& HALCYON_HEADER1MASK
) == HALCYON_HEADER1
)
372 DRM_ERROR("Illegal DMA HALCYON_HEADER1 command\n");
375 if ((cmd
& HALCYON_FIREMASK
) == HALCYON_FIRECMD
)
377 DRM_ERROR("Illegal DMA HALCYON_FIRECMD command\n");
379 case check_for_dummy
:
382 DRM_ERROR("Illegal DMA HC_DUMMY command\n");
385 if (0xdddddddd == cmd
)
387 DRM_ERROR("Illegal DMA 0xdddddddd command\n");
389 case check_z_buffer_addr0
:
390 cur_seq
->unfinished
= z_address
;
391 cur_seq
->z_addr
= (cur_seq
->z_addr
& 0xFF000000) |
394 case check_z_buffer_addr1
:
395 cur_seq
->unfinished
= z_address
;
396 cur_seq
->z_addr
= (cur_seq
->z_addr
& 0x00FFFFFF) |
397 ((cmd
& 0xFF) << 24);
399 case check_z_buffer_addr_mode
:
400 cur_seq
->unfinished
= z_address
;
401 if ((cmd
& 0x0000C000) == 0)
403 DRM_ERROR("Attempt to place Z buffer in system memory\n");
405 case check_destination_addr0
:
406 cur_seq
->unfinished
= dest_address
;
407 cur_seq
->d_addr
= (cur_seq
->d_addr
& 0xFF000000) |
410 case check_destination_addr1
:
411 cur_seq
->unfinished
= dest_address
;
412 cur_seq
->d_addr
= (cur_seq
->d_addr
& 0x00FFFFFF) |
413 ((cmd
& 0xFF) << 24);
415 case check_destination_addr_mode
:
416 cur_seq
->unfinished
= dest_address
;
417 if ((cmd
& 0x0000C000) == 0)
420 ("Attempt to place 3D drawing buffer in system memory\n");
422 case check_texture_addr0
:
423 cur_seq
->unfinished
= tex_address
;
425 tmp_addr
= &cur_seq
->t_addr
[cur_seq
->texture
][tmp
];
426 *tmp_addr
= (*tmp_addr
& 0xFF000000) | (cmd
& 0x00FFFFFF);
428 case check_texture_addr1
:
429 cur_seq
->unfinished
= tex_address
;
430 tmp
= ((cmd
>> 24) - 0x20);
432 tmp_addr
= &cur_seq
->t_addr
[cur_seq
->texture
][tmp
];
433 *tmp_addr
= (*tmp_addr
& 0x00FFFFFF) | ((cmd
& 0xFF) << 24);
435 *tmp_addr
= (*tmp_addr
& 0x00FFFFFF) | ((cmd
& 0xFF00) << 16);
437 *tmp_addr
= (*tmp_addr
& 0x00FFFFFF) | ((cmd
& 0xFF0000) << 8);
439 case check_texture_addr2
:
440 cur_seq
->unfinished
= tex_address
;
441 cur_seq
->tex_level_lo
[tmp
= cur_seq
->texture
] = cmd
& 0x3F;
442 cur_seq
->tex_level_hi
[tmp
] = (cmd
& 0xFC0) >> 6;
444 case check_texture_addr3
:
445 cur_seq
->unfinished
= tex_address
;
446 tmp
= ((cmd
>> 24) - 0x2B);
447 cur_seq
->pitch
[cur_seq
->texture
][tmp
] =
448 (cmd
& 0x00F00000) >> 20;
449 if (!tmp
&& (cmd
& 0x000FFFFF)) {
451 ("Unimplemented texture level 0 pitch mode.\n");
455 case check_texture_addr4
:
456 cur_seq
->unfinished
= tex_address
;
457 tmp_addr
= &cur_seq
->t_addr
[cur_seq
->texture
][9];
458 *tmp_addr
= (*tmp_addr
& 0x00FFFFFF) | ((cmd
& 0xFF) << 24);
460 case check_texture_addr5
:
461 case check_texture_addr6
:
462 cur_seq
->unfinished
= tex_address
;
464 * Texture width. We don't care since we have the pitch.
467 case check_texture_addr7
:
468 cur_seq
->unfinished
= tex_address
;
469 tmp_addr
= &(cur_seq
->height
[cur_seq
->texture
][0]);
470 tmp_addr
[5] = 1 << ((cmd
& 0x00F00000) >> 20);
471 tmp_addr
[4] = 1 << ((cmd
& 0x000F0000) >> 16);
472 tmp_addr
[3] = 1 << ((cmd
& 0x0000F000) >> 12);
473 tmp_addr
[2] = 1 << ((cmd
& 0x00000F00) >> 8);
474 tmp_addr
[1] = 1 << ((cmd
& 0x000000F0) >> 4);
475 tmp_addr
[0] = 1 << (cmd
& 0x0000000F);
477 case check_texture_addr8
:
478 cur_seq
->unfinished
= tex_address
;
479 tmp_addr
= &(cur_seq
->height
[cur_seq
->texture
][0]);
480 tmp_addr
[9] = 1 << ((cmd
& 0x0000F000) >> 12);
481 tmp_addr
[8] = 1 << ((cmd
& 0x00000F00) >> 8);
482 tmp_addr
[7] = 1 << ((cmd
& 0x000000F0) >> 4);
483 tmp_addr
[6] = 1 << (cmd
& 0x0000000F);
485 case check_texture_addr_mode
:
486 cur_seq
->unfinished
= tex_address
;
487 if (2 == (tmp
= cmd
& 0x00000003)) {
489 ("Attempt to fetch texture from system memory.\n");
492 cur_seq
->agp_texture
= (tmp
== 3);
493 cur_seq
->tex_palette_size
[cur_seq
->texture
] =
494 (cmd
>> 16) & 0x000000007;
496 case check_for_vertex_count
:
497 cur_seq
->vertex_count
= cmd
& 0x0000FFFF;
499 case check_number_texunits
:
500 cur_seq
->multitex
= (cmd
>> 3) & 1;
503 DRM_ERROR("Illegal DMA data: 0x%x\n", cmd
);
509 static __inline__
int
510 via_check_prim_list(uint32_t const **buffer
, const uint32_t * buf_end
,
511 drm_via_state_t
* cur_seq
)
513 drm_via_private_t
*dev_priv
=
514 (drm_via_private_t
*) cur_seq
->dev
->dev_private
;
515 uint32_t a_fire
, bcmd
, dw_count
;
518 const uint32_t *buf
= *buffer
;
520 while (buf
< buf_end
) {
522 if ((buf_end
- buf
) < 2) {
524 ("Unexpected termination of primitive list.\n");
528 if ((*buf
& HC_ACMD_MASK
) != HC_ACMD_HCmdB
)
531 if ((*buf
& HC_ACMD_MASK
) != HC_ACMD_HCmdA
) {
532 DRM_ERROR("Expected Vertex List A command, got 0x%x\n",
538 *buf
++ | HC_HPLEND_MASK
| HC_HPMValidN_MASK
|
542 * How many dwords per vertex ?
545 if (cur_seq
->agp
&& ((bcmd
& (0xF << 11)) == 0)) {
546 DRM_ERROR("Illegal B command vertex data for AGP.\n");
553 dw_count
+= (cur_seq
->multitex
) ? 2 : 1;
555 dw_count
+= (cur_seq
->multitex
) ? 2 : 1;
558 if (bcmd
& (1 << 10))
560 if (bcmd
& (1 << 11))
562 if (bcmd
& (1 << 12))
564 if (bcmd
& (1 << 13))
566 if (bcmd
& (1 << 14))
569 while (buf
< buf_end
) {
570 if (*buf
== a_fire
) {
571 if (dev_priv
->num_fire_offsets
>=
573 DRM_ERROR("Fire offset buffer full.\n");
577 dev_priv
->fire_offsets
[dev_priv
->
578 num_fire_offsets
++] =
582 if (buf
< buf_end
&& *buf
== a_fire
)
586 if ((*buf
== HALCYON_HEADER2
) ||
587 ((*buf
& HALCYON_FIREMASK
) == HALCYON_FIRECMD
)) {
588 DRM_ERROR("Missing Vertex Fire command, "
589 "Stray Vertex Fire command or verifier "
594 if ((ret
= eat_words(&buf
, buf_end
, dw_count
)))
597 if (buf
>= buf_end
&& !have_fire
) {
598 DRM_ERROR("Missing Vertex Fire command or verifier "
603 if (cur_seq
->agp
&& ((buf
- cur_seq
->buf_start
) & 0x01)) {
604 DRM_ERROR("AGP Primitive list end misaligned.\n");
613 static __inline__ verifier_state_t
614 via_check_header2(uint32_t const **buffer
, const uint32_t * buf_end
,
615 drm_via_state_t
* hc_state
)
620 const uint32_t *buf
= *buffer
;
621 const hazard_t
*hz_table
;
623 if ((buf_end
- buf
) < 2) {
625 ("Illegal termination of DMA HALCYON_HEADER2 sequence.\n");
629 cmd
= (*buf
++ & 0xFFFF0000) >> 16;
632 case HC_ParaType_CmdVdata
:
633 if (via_check_prim_list(&buf
, buf_end
, hc_state
))
636 return state_command
;
637 case HC_ParaType_NotTex
:
640 case HC_ParaType_Tex
:
641 hc_state
->texture
= 0;
644 case (HC_ParaType_Tex
| (HC_SubType_Tex1
<< 8)):
645 hc_state
->texture
= 1;
648 case (HC_ParaType_Tex
| (HC_SubType_TexGeneral
<< 8)):
651 case HC_ParaType_Auto
:
652 if (eat_words(&buf
, buf_end
, 2))
655 return state_command
;
656 case (HC_ParaType_Palette
| (HC_SubType_Stipple
<< 8)):
657 if (eat_words(&buf
, buf_end
, 32))
660 return state_command
;
661 case (HC_ParaType_Palette
| (HC_SubType_TexPalette0
<< 8)):
662 case (HC_ParaType_Palette
| (HC_SubType_TexPalette1
<< 8)):
663 DRM_ERROR("Texture palettes are rejected because of "
664 "lack of info how to determine their size.\n");
666 case (HC_ParaType_Palette
| (HC_SubType_FogTable
<< 8)):
667 DRM_ERROR("Fog factor palettes are rejected because of "
668 "lack of info how to determine their size.\n");
673 * There are some unimplemented HC_ParaTypes here, that
674 * need to be implemented if the Mesa driver is extended.
677 DRM_ERROR("Invalid or unimplemented HALCYON_HEADER2 "
678 "DMA subcommand: 0x%x. Previous dword: 0x%x\n",
684 while (buf
< buf_end
) {
686 if ((hz
= hz_table
[cmd
>> 24])) {
687 if ((hz_mode
= investigate_hazard(cmd
, hz
, hc_state
))) {
694 } else if (hc_state
->unfinished
&&
695 finish_current_sequence(hc_state
)) {
699 if (hc_state
->unfinished
&& finish_current_sequence(hc_state
)) {
703 return state_command
;
706 static __inline__ verifier_state_t
707 via_parse_header2(drm_via_private_t
* dev_priv
, uint32_t const **buffer
,
708 const uint32_t * buf_end
, int *fire_count
)
711 const uint32_t *buf
= *buffer
;
712 const uint32_t *next_fire
;
715 next_fire
= dev_priv
->fire_offsets
[*fire_count
];
717 cmd
= (*buf
& 0xFFFF0000) >> 16;
718 VIA_WRITE(HC_REG_TRANS_SET
+ HC_REG_BASE
, *buf
++);
720 case HC_ParaType_CmdVdata
:
721 while ((buf
< buf_end
) &&
722 (*fire_count
< dev_priv
->num_fire_offsets
) &&
723 (*buf
& HC_ACMD_MASK
) == HC_ACMD_HCmdB
) {
724 while (buf
<= next_fire
) {
725 VIA_WRITE(HC_REG_TRANS_SPACE
+ HC_REG_BASE
+
726 (burst
& 63), *buf
++);
730 && ((*buf
& HALCYON_FIREMASK
) == HALCYON_FIRECMD
))
733 if (++(*fire_count
) < dev_priv
->num_fire_offsets
)
734 next_fire
= dev_priv
->fire_offsets
[*fire_count
];
738 while (buf
< buf_end
) {
740 if (*buf
== HC_HEADER2
||
741 (*buf
& HALCYON_HEADER1MASK
) == HALCYON_HEADER1
||
742 (*buf
& VIA_VIDEOMASK
) == VIA_VIDEO_HEADER5
||
743 (*buf
& VIA_VIDEOMASK
) == VIA_VIDEO_HEADER6
)
746 VIA_WRITE(HC_REG_TRANS_SPACE
+ HC_REG_BASE
+
747 (burst
& 63), *buf
++);
752 return state_command
;
755 static __inline__
int verify_mmio_address(uint32_t address
)
757 if ((address
> 0x3FF) && (address
< 0xC00)) {
758 DRM_ERROR("Invalid VIDEO DMA command. "
759 "Attempt to access 3D- or command burst area.\n");
761 } else if ((address
> 0xCFF) && (address
< 0x1300)) {
762 DRM_ERROR("Invalid VIDEO DMA command. "
763 "Attempt to access PCI DMA area.\n");
765 } else if (address
> 0x13FF) {
766 DRM_ERROR("Invalid VIDEO DMA command. "
767 "Attempt to access VGA registers.\n");
773 static __inline__
int
774 verify_video_tail(uint32_t const **buffer
, const uint32_t * buf_end
,
777 const uint32_t *buf
= *buffer
;
779 if (buf_end
- buf
< dwords
) {
780 DRM_ERROR("Illegal termination of video command.\n");
785 DRM_ERROR("Illegal video command tail.\n");
793 static __inline__ verifier_state_t
794 via_check_header1(uint32_t const **buffer
, const uint32_t * buf_end
)
797 const uint32_t *buf
= *buffer
;
798 verifier_state_t ret
= state_command
;
800 while (buf
< buf_end
) {
802 if ((cmd
> ((0x3FF >> 2) | HALCYON_HEADER1
)) &&
803 (cmd
< ((0xC00 >> 2) | HALCYON_HEADER1
))) {
804 if ((cmd
& HALCYON_HEADER1MASK
) != HALCYON_HEADER1
)
806 DRM_ERROR("Invalid HALCYON_HEADER1 command. "
807 "Attempt to access 3D- or command burst area.\n");
810 } else if (cmd
> ((0xCFF >> 2) | HALCYON_HEADER1
)) {
811 if ((cmd
& HALCYON_HEADER1MASK
) != HALCYON_HEADER1
)
813 DRM_ERROR("Invalid HALCYON_HEADER1 command. "
814 "Attempt to access VGA registers.\n");
825 static __inline__ verifier_state_t
826 via_parse_header1(drm_via_private_t
* dev_priv
, uint32_t const **buffer
,
827 const uint32_t * buf_end
)
829 register uint32_t cmd
;
830 const uint32_t *buf
= *buffer
;
832 while (buf
< buf_end
) {
834 if ((cmd
& HALCYON_HEADER1MASK
) != HALCYON_HEADER1
)
836 VIA_WRITE((cmd
& ~HALCYON_HEADER1MASK
) << 2, *++buf
);
840 return state_command
;
843 static __inline__ verifier_state_t
844 via_check_vheader5(uint32_t const **buffer
, const uint32_t * buf_end
)
847 const uint32_t *buf
= *buffer
;
849 if (buf_end
- buf
< 4) {
850 DRM_ERROR("Illegal termination of video header5 command\n");
854 data
= *buf
++ & ~VIA_VIDEOMASK
;
855 if (verify_mmio_address(data
))
859 if (*buf
++ != 0x00F50000) {
860 DRM_ERROR("Illegal header5 header data\n");
863 if (*buf
++ != 0x00000000) {
864 DRM_ERROR("Illegal header5 header data\n");
867 if (eat_words(&buf
, buf_end
, data
))
869 if ((data
& 3) && verify_video_tail(&buf
, buf_end
, 4 - (data
& 3)))
872 return state_command
;
876 static __inline__ verifier_state_t
877 via_parse_vheader5(drm_via_private_t
* dev_priv
, uint32_t const **buffer
,
878 const uint32_t * buf_end
)
880 uint32_t addr
, count
, i
;
881 const uint32_t *buf
= *buffer
;
883 addr
= *buf
++ & ~VIA_VIDEOMASK
;
887 VIA_WRITE(addr
, *buf
++);
890 buf
+= 4 - (count
& 3);
892 return state_command
;
895 static __inline__ verifier_state_t
896 via_check_vheader6(uint32_t const **buffer
, const uint32_t * buf_end
)
899 const uint32_t *buf
= *buffer
;
902 if (buf_end
- buf
< 4) {
903 DRM_ERROR("Illegal termination of video header6 command\n");
908 if (*buf
++ != 0x00F60000) {
909 DRM_ERROR("Illegal header6 header data\n");
912 if (*buf
++ != 0x00000000) {
913 DRM_ERROR("Illegal header6 header data\n");
916 if ((buf_end
- buf
) < (data
<< 1)) {
917 DRM_ERROR("Illegal termination of video header6 command\n");
920 for (i
= 0; i
< data
; ++i
) {
921 if (verify_mmio_address(*buf
++))
926 if ((data
& 3) && verify_video_tail(&buf
, buf_end
, 4 - (data
& 3)))
929 return state_command
;
932 static __inline__ verifier_state_t
933 via_parse_vheader6(drm_via_private_t
* dev_priv
, uint32_t const **buffer
,
934 const uint32_t * buf_end
)
937 uint32_t addr
, count
, i
;
938 const uint32_t *buf
= *buffer
;
944 VIA_WRITE(addr
, *buf
++);
948 buf
+= 4 - (count
& 3);
950 return state_command
;
954 via_verify_command_stream(const uint32_t * buf
, unsigned int size
,
955 drm_device_t
* dev
, int agp
)
958 drm_via_private_t
*dev_priv
= (drm_via_private_t
*) dev
->dev_private
;
959 drm_via_state_t
*hc_state
= &dev_priv
->hc_state
;
960 drm_via_state_t saved_state
= *hc_state
;
962 const uint32_t *buf_end
= buf
+ (size
>> 2);
963 verifier_state_t state
= state_command
;
964 int pro_group_a
= dev_priv
->pro_group_a
;
967 hc_state
->unfinished
= no_sequence
;
968 hc_state
->map_cache
= NULL
;
970 hc_state
->buf_start
= buf
;
971 dev_priv
->num_fire_offsets
= 0;
973 while (buf
< buf_end
) {
977 state
= via_check_header2(&buf
, buf_end
, hc_state
);
980 state
= via_check_header1(&buf
, buf_end
);
983 state
= via_check_vheader5(&buf
, buf_end
);
986 state
= via_check_vheader6(&buf
, buf_end
);
989 if (HALCYON_HEADER2
== (cmd
= *buf
))
990 state
= state_header2
;
991 else if ((cmd
& HALCYON_HEADER1MASK
) == HALCYON_HEADER1
)
992 state
= state_header1
;
994 && (cmd
& VIA_VIDEOMASK
) == VIA_VIDEO_HEADER5
)
995 state
= state_vheader5
;
997 && (cmd
& VIA_VIDEOMASK
) == VIA_VIDEO_HEADER6
)
998 state
= state_vheader6
;
1001 ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
1003 state
= state_error
;
1008 *hc_state
= saved_state
;
1009 return DRM_ERR(EINVAL
);
1012 if (state
== state_error
) {
1013 *hc_state
= saved_state
;
1014 return DRM_ERR(EINVAL
);
1020 via_parse_command_stream(drm_device_t
* dev
, const uint32_t * buf
,
1024 drm_via_private_t
*dev_priv
= (drm_via_private_t
*) dev
->dev_private
;
1026 const uint32_t *buf_end
= buf
+ (size
>> 2);
1027 verifier_state_t state
= state_command
;
1030 while (buf
< buf_end
) {
1035 via_parse_header2(dev_priv
, &buf
, buf_end
,
1039 state
= via_parse_header1(dev_priv
, &buf
, buf_end
);
1041 case state_vheader5
:
1042 state
= via_parse_vheader5(dev_priv
, &buf
, buf_end
);
1044 case state_vheader6
:
1045 state
= via_parse_vheader6(dev_priv
, &buf
, buf_end
);
1048 if (HALCYON_HEADER2
== (cmd
= *buf
))
1049 state
= state_header2
;
1050 else if ((cmd
& HALCYON_HEADER1MASK
) == HALCYON_HEADER1
)
1051 state
= state_header1
;
1052 else if ((cmd
& VIA_VIDEOMASK
) == VIA_VIDEO_HEADER5
)
1053 state
= state_vheader5
;
1054 else if ((cmd
& VIA_VIDEOMASK
) == VIA_VIDEO_HEADER6
)
1055 state
= state_vheader6
;
1058 ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
1060 state
= state_error
;
1065 return DRM_ERR(EINVAL
);
1068 if (state
== state_error
) {
1069 return DRM_ERR(EINVAL
);
1075 setup_hazard_table(hz_init_t init_table
[], hazard_t table
[], int size
)
1079 for (i
= 0; i
< 256; ++i
) {
1080 table
[i
] = forbidden_command
;
1083 for (i
= 0; i
< size
; ++i
) {
1084 table
[init_table
[i
].code
] = init_table
[i
].hz
;
1088 void via_init_command_verifier(void)
1090 setup_hazard_table(init_table1
, table1
,
1091 sizeof(init_table1
) / sizeof(hz_init_t
));
1092 setup_hazard_table(init_table2
, table2
,
1093 sizeof(init_table2
) / sizeof(hz_init_t
));
1094 setup_hazard_table(init_table3
, table3
,
1095 sizeof(init_table3
) / sizeof(hz_init_t
));