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,
255 struct drm_device *dev)
258 struct drm_map_list *r_list;
260 drm_local_map_t *map = seq->map_cache;
262 if (map && map->offset <= offset
263 && (offset + size) <= (map->offset + map->size)) {
267 list_for_each_entry(r_list, &dev->maplist, head) {
272 TAILQ_FOREACH(map, &dev->maplist, link) {
274 if (map->offset <= offset
275 && (offset + size) <= (map->offset + map->size)
276 && !(map->flags & _DRM_RESTRICTED)
277 && (map->type == _DRM_AGP)) {
278 seq->map_cache = map;
286 * Require that all AGP texture levels reside in the same AGP map which should
287 * be mappable by the client. This is not a big restriction.
288 * FIXME: To actually enforce this security policy strictly, drm_rmmap
289 * would have to wait for dma quiescent before removing an AGP map.
290 * The via_drm_lookup_agp_map call in reality seems to take
291 * very little CPU time.
294 static __inline__ int finish_current_sequence(drm_via_state_t * cur_seq)
296 switch (cur_seq->unfinished) {
298 DRM_DEBUG("Z Buffer start address is 0x%x\n", cur_seq->z_addr);
301 DRM_DEBUG("Destination start address is 0x%x\n",
305 if (cur_seq->agp_texture) {
307 cur_seq->tex_level_lo[cur_seq->texture];
308 unsigned end = cur_seq->tex_level_hi[cur_seq->texture];
309 unsigned long lo = ~0, hi = 0, tmp;
310 uint32_t *addr, *pitch, *height, tex;
320 &(cur_seq->t_addr[tex = cur_seq->texture][start]);
321 pitch = &(cur_seq->pitch[tex][start]);
322 height = &(cur_seq->height[tex][start]);
323 npot = cur_seq->tex_npot[tex];
324 for (i = start; i <= end; ++i) {
329 tmp += (*height++ * *pitch++);
331 tmp += (*height++ << *pitch++);
336 if (!via_drm_lookup_agp_map
337 (cur_seq, lo, hi - lo, cur_seq->dev)) {
339 ("AGP texture is not in allowed map\n");
347 cur_seq->unfinished = no_sequence;
351 static __inline__ int
352 investigate_hazard(uint32_t cmd, hazard_t hz, drm_via_state_t * cur_seq)
354 register uint32_t tmp, *tmp_addr;
356 if (cur_seq->unfinished && (cur_seq->unfinished != seqs[hz])) {
358 if ((ret = finish_current_sequence(cur_seq)))
363 case check_for_header2:
364 if (cmd == HALCYON_HEADER2)
367 case check_for_header1:
368 if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
371 case check_for_header2_err:
372 if (cmd == HALCYON_HEADER2)
374 DRM_ERROR("Illegal DMA HALCYON_HEADER2 command\n");
376 case check_for_header1_err:
377 if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
379 DRM_ERROR("Illegal DMA HALCYON_HEADER1 command\n");
382 if ((cmd & HALCYON_FIREMASK) == HALCYON_FIRECMD)
384 DRM_ERROR("Illegal DMA HALCYON_FIRECMD command\n");
386 case check_for_dummy:
389 DRM_ERROR("Illegal DMA HC_DUMMY command\n");
392 if (0xdddddddd == cmd)
394 DRM_ERROR("Illegal DMA 0xdddddddd command\n");
396 case check_z_buffer_addr0:
397 cur_seq->unfinished = z_address;
398 cur_seq->z_addr = (cur_seq->z_addr & 0xFF000000) |
401 case check_z_buffer_addr1:
402 cur_seq->unfinished = z_address;
403 cur_seq->z_addr = (cur_seq->z_addr & 0x00FFFFFF) |
404 ((cmd & 0xFF) << 24);
406 case check_z_buffer_addr_mode:
407 cur_seq->unfinished = z_address;
408 if ((cmd & 0x0000C000) == 0)
410 DRM_ERROR("Attempt to place Z buffer in system memory\n");
412 case check_destination_addr0:
413 cur_seq->unfinished = dest_address;
414 cur_seq->d_addr = (cur_seq->d_addr & 0xFF000000) |
417 case check_destination_addr1:
418 cur_seq->unfinished = dest_address;
419 cur_seq->d_addr = (cur_seq->d_addr & 0x00FFFFFF) |
420 ((cmd & 0xFF) << 24);
422 case check_destination_addr_mode:
423 cur_seq->unfinished = dest_address;
424 if ((cmd & 0x0000C000) == 0)
427 ("Attempt to place 3D drawing buffer in system memory\n");
429 case check_texture_addr0:
430 cur_seq->unfinished = tex_address;
432 tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
433 *tmp_addr = (*tmp_addr & 0xFF000000) | (cmd & 0x00FFFFFF);
435 case check_texture_addr1:
436 cur_seq->unfinished = tex_address;
437 tmp = ((cmd >> 24) - 0x20);
439 tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
440 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
442 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF00) << 16);
444 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF0000) << 8);
446 case check_texture_addr2:
447 cur_seq->unfinished = tex_address;
448 cur_seq->tex_level_lo[tmp = cur_seq->texture] = cmd & 0x3F;
449 cur_seq->tex_level_hi[tmp] = (cmd & 0xFC0) >> 6;
451 case check_texture_addr3:
452 cur_seq->unfinished = tex_address;
453 tmp = ((cmd >> 24) - HC_SubA_HTXnL0Pit);
455 (cmd & HC_HTXnEnPit_MASK)) {
456 cur_seq->pitch[cur_seq->texture][tmp] =
457 (cmd & HC_HTXnLnPit_MASK);
458 cur_seq->tex_npot[cur_seq->texture] = 1;
460 cur_seq->pitch[cur_seq->texture][tmp] =
461 (cmd & HC_HTXnLnPitE_MASK) >> HC_HTXnLnPitE_SHIFT;
462 cur_seq->tex_npot[cur_seq->texture] = 0;
463 if (cmd & 0x000FFFFF) {
465 ("Unimplemented texture level 0 pitch mode.\n");
470 case check_texture_addr4:
471 cur_seq->unfinished = tex_address;
472 tmp_addr = &cur_seq->t_addr[cur_seq->texture][9];
473 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
475 case check_texture_addr5:
476 case check_texture_addr6:
477 cur_seq->unfinished = tex_address;
479 * Texture width. We don't care since we have the pitch.
482 case check_texture_addr7:
483 cur_seq->unfinished = tex_address;
484 tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
485 tmp_addr[5] = 1 << ((cmd & 0x00F00000) >> 20);
486 tmp_addr[4] = 1 << ((cmd & 0x000F0000) >> 16);
487 tmp_addr[3] = 1 << ((cmd & 0x0000F000) >> 12);
488 tmp_addr[2] = 1 << ((cmd & 0x00000F00) >> 8);
489 tmp_addr[1] = 1 << ((cmd & 0x000000F0) >> 4);
490 tmp_addr[0] = 1 << (cmd & 0x0000000F);
492 case check_texture_addr8:
493 cur_seq->unfinished = tex_address;
494 tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
495 tmp_addr[9] = 1 << ((cmd & 0x0000F000) >> 12);
496 tmp_addr[8] = 1 << ((cmd & 0x00000F00) >> 8);
497 tmp_addr[7] = 1 << ((cmd & 0x000000F0) >> 4);
498 tmp_addr[6] = 1 << (cmd & 0x0000000F);
500 case check_texture_addr_mode:
501 cur_seq->unfinished = tex_address;
502 if (2 == (tmp = cmd & 0x00000003)) {
504 ("Attempt to fetch texture from system memory.\n");
507 cur_seq->agp_texture = (tmp == 3);
508 cur_seq->tex_palette_size[cur_seq->texture] =
509 (cmd >> 16) & 0x000000007;
511 case check_for_vertex_count:
512 cur_seq->vertex_count = cmd & 0x0000FFFF;
514 case check_number_texunits:
515 cur_seq->multitex = (cmd >> 3) & 1;
518 DRM_ERROR("Illegal DMA data: 0x%x\n", cmd);
524 static __inline__ int
525 via_check_prim_list(uint32_t const **buffer, const uint32_t * buf_end,
526 drm_via_state_t * cur_seq)
528 drm_via_private_t *dev_priv =
529 (drm_via_private_t *) cur_seq->dev->dev_private;
530 uint32_t a_fire, bcmd, dw_count;
533 const uint32_t *buf = *buffer;
535 while (buf < buf_end) {
537 if ((buf_end - buf) < 2) {
539 ("Unexpected termination of primitive list.\n");
543 if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdB)
546 if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdA) {
547 DRM_ERROR("Expected Vertex List A command, got 0x%x\n",
553 *buf++ | HC_HPLEND_MASK | HC_HPMValidN_MASK |
557 * How many dwords per vertex ?
560 if (cur_seq->agp && ((bcmd & (0xF << 11)) == 0)) {
561 DRM_ERROR("Illegal B command vertex data for AGP.\n");
568 dw_count += (cur_seq->multitex) ? 2 : 1;
570 dw_count += (cur_seq->multitex) ? 2 : 1;
573 if (bcmd & (1 << 10))
575 if (bcmd & (1 << 11))
577 if (bcmd & (1 << 12))
579 if (bcmd & (1 << 13))
581 if (bcmd & (1 << 14))
584 while (buf < buf_end) {
585 if (*buf == a_fire) {
586 if (dev_priv->num_fire_offsets >=
588 DRM_ERROR("Fire offset buffer full.\n");
592 dev_priv->fire_offsets[dev_priv->
593 num_fire_offsets++] =
597 if (buf < buf_end && *buf == a_fire)
601 if ((*buf == HALCYON_HEADER2) ||
602 ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD)) {
603 DRM_ERROR("Missing Vertex Fire command, "
604 "Stray Vertex Fire command or verifier "
609 if ((ret = eat_words(&buf, buf_end, dw_count)))
612 if (buf >= buf_end && !have_fire) {
613 DRM_ERROR("Missing Vertex Fire command or verifier "
618 if (cur_seq->agp && ((buf - cur_seq->buf_start) & 0x01)) {
619 DRM_ERROR("AGP Primitive list end misaligned.\n");
628 static __inline__ verifier_state_t
629 via_check_header2(uint32_t const **buffer, const uint32_t * buf_end,
630 drm_via_state_t * hc_state)
635 const uint32_t *buf = *buffer;
636 const hazard_t *hz_table;
638 if ((buf_end - buf) < 2) {
640 ("Illegal termination of DMA HALCYON_HEADER2 sequence.\n");
644 cmd = (*buf++ & 0xFFFF0000) >> 16;
647 case HC_ParaType_CmdVdata:
648 if (via_check_prim_list(&buf, buf_end, hc_state))
651 return state_command;
652 case HC_ParaType_NotTex:
655 case HC_ParaType_Tex:
656 hc_state->texture = 0;
659 case (HC_ParaType_Tex | (HC_SubType_Tex1 << 8)):
660 hc_state->texture = 1;
663 case (HC_ParaType_Tex | (HC_SubType_TexGeneral << 8)):
666 case HC_ParaType_Auto:
667 if (eat_words(&buf, buf_end, 2))
670 return state_command;
671 case (HC_ParaType_Palette | (HC_SubType_Stipple << 8)):
672 if (eat_words(&buf, buf_end, 32))
675 return state_command;
676 case (HC_ParaType_Palette | (HC_SubType_TexPalette0 << 8)):
677 case (HC_ParaType_Palette | (HC_SubType_TexPalette1 << 8)):
678 DRM_ERROR("Texture palettes are rejected because of "
679 "lack of info how to determine their size.\n");
681 case (HC_ParaType_Palette | (HC_SubType_FogTable << 8)):
682 DRM_ERROR("Fog factor palettes are rejected because of "
683 "lack of info how to determine their size.\n");
688 * There are some unimplemented HC_ParaTypes here, that
689 * need to be implemented if the Mesa driver is extended.
692 DRM_ERROR("Invalid or unimplemented HALCYON_HEADER2 "
693 "DMA subcommand: 0x%x. Previous dword: 0x%x\n",
699 while (buf < buf_end) {
701 if ((hz = hz_table[cmd >> 24])) {
702 if ((hz_mode = investigate_hazard(cmd, hz, hc_state))) {
709 } else if (hc_state->unfinished &&
710 finish_current_sequence(hc_state)) {
714 if (hc_state->unfinished && finish_current_sequence(hc_state)) {
718 return state_command;
721 static __inline__ verifier_state_t
722 via_parse_header2(drm_via_private_t * dev_priv, uint32_t const **buffer,
723 const uint32_t * buf_end, int *fire_count)
726 const uint32_t *buf = *buffer;
727 const uint32_t *next_fire;
730 next_fire = dev_priv->fire_offsets[*fire_count];
732 cmd = (*buf & 0xFFFF0000) >> 16;
733 VIA_WRITE(HC_REG_TRANS_SET + HC_REG_BASE, *buf++);
735 case HC_ParaType_CmdVdata:
736 while ((buf < buf_end) &&
737 (*fire_count < dev_priv->num_fire_offsets) &&
738 (*buf & HC_ACMD_MASK) == HC_ACMD_HCmdB) {
739 while (buf <= next_fire) {
740 VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE +
741 (burst & 63), *buf++);
745 && ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD))
748 if (++(*fire_count) < dev_priv->num_fire_offsets)
749 next_fire = dev_priv->fire_offsets[*fire_count];
753 while (buf < buf_end) {
755 if (*buf == HC_HEADER2 ||
756 (*buf & HALCYON_HEADER1MASK) == HALCYON_HEADER1 ||
757 (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5 ||
758 (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
761 VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE +
762 (burst & 63), *buf++);
767 return state_command;
770 static __inline__ int verify_mmio_address(uint32_t address)
772 if ((address > 0x3FF) && (address < 0xC00)) {
773 DRM_ERROR("Invalid VIDEO DMA command. "
774 "Attempt to access 3D- or command burst area.\n");
776 } else if ((address > 0xCFF) && (address < 0x1300)) {
777 DRM_ERROR("Invalid VIDEO DMA command. "
778 "Attempt to access PCI DMA area.\n");
780 } else if (address > 0x13FF) {
781 DRM_ERROR("Invalid VIDEO DMA command. "
782 "Attempt to access VGA registers.\n");
788 static __inline__ int
789 verify_video_tail(uint32_t const **buffer, const uint32_t * buf_end,
792 const uint32_t *buf = *buffer;
794 if (buf_end - buf < dwords) {
795 DRM_ERROR("Illegal termination of video command.\n");
800 DRM_ERROR("Illegal video command tail.\n");
808 static __inline__ verifier_state_t
809 via_check_header1(uint32_t const **buffer, const uint32_t * buf_end)
812 const uint32_t *buf = *buffer;
813 verifier_state_t ret = state_command;
815 while (buf < buf_end) {
817 if ((cmd > ((0x3FF >> 2) | HALCYON_HEADER1)) &&
818 (cmd < ((0xC00 >> 2) | HALCYON_HEADER1))) {
819 if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
821 DRM_ERROR("Invalid HALCYON_HEADER1 command. "
822 "Attempt to access 3D- or command burst area.\n");
825 } else if (cmd > ((0xCFF >> 2) | HALCYON_HEADER1)) {
826 if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
828 DRM_ERROR("Invalid HALCYON_HEADER1 command. "
829 "Attempt to access VGA registers.\n");
840 static __inline__ verifier_state_t
841 via_parse_header1(drm_via_private_t * dev_priv, uint32_t const **buffer,
842 const uint32_t * buf_end)
844 register uint32_t cmd;
845 const uint32_t *buf = *buffer;
847 while (buf < buf_end) {
849 if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
851 VIA_WRITE((cmd & ~HALCYON_HEADER1MASK) << 2, *++buf);
855 return state_command;
858 static __inline__ verifier_state_t
859 via_check_vheader5(uint32_t const **buffer, const uint32_t * buf_end)
862 const uint32_t *buf = *buffer;
864 if (buf_end - buf < 4) {
865 DRM_ERROR("Illegal termination of video header5 command\n");
869 data = *buf++ & ~VIA_VIDEOMASK;
870 if (verify_mmio_address(data))
874 if (*buf++ != 0x00F50000) {
875 DRM_ERROR("Illegal header5 header data\n");
878 if (*buf++ != 0x00000000) {
879 DRM_ERROR("Illegal header5 header data\n");
882 if (eat_words(&buf, buf_end, data))
884 if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
887 return state_command;
891 static __inline__ verifier_state_t
892 via_parse_vheader5(drm_via_private_t * dev_priv, uint32_t const **buffer,
893 const uint32_t * buf_end)
895 uint32_t addr, count, i;
896 const uint32_t *buf = *buffer;
898 addr = *buf++ & ~VIA_VIDEOMASK;
902 VIA_WRITE(addr, *buf++);
905 buf += 4 - (count & 3);
907 return state_command;
910 static __inline__ verifier_state_t
911 via_check_vheader6(uint32_t const **buffer, const uint32_t * buf_end)
914 const uint32_t *buf = *buffer;
917 if (buf_end - buf < 4) {
918 DRM_ERROR("Illegal termination of video header6 command\n");
923 if (*buf++ != 0x00F60000) {
924 DRM_ERROR("Illegal header6 header data\n");
927 if (*buf++ != 0x00000000) {
928 DRM_ERROR("Illegal header6 header data\n");
931 if ((buf_end - buf) < (data << 1)) {
932 DRM_ERROR("Illegal termination of video header6 command\n");
935 for (i = 0; i < data; ++i) {
936 if (verify_mmio_address(*buf++))
941 if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
944 return state_command;
947 static __inline__ verifier_state_t
948 via_parse_vheader6(drm_via_private_t * dev_priv, uint32_t const **buffer,
949 const uint32_t * buf_end)
952 uint32_t addr, count, i;
953 const uint32_t *buf = *buffer;
959 VIA_WRITE(addr, *buf++);
963 buf += 4 - (count & 3);
965 return state_command;
969 via_verify_command_stream(const uint32_t * buf, unsigned int size,
970 struct drm_device * dev, int agp)
973 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
974 drm_via_state_t *hc_state = &dev_priv->hc_state;
975 drm_via_state_t saved_state = *hc_state;
977 const uint32_t *buf_end = buf + (size >> 2);
978 verifier_state_t state = state_command;
982 cme_video = (dev_priv->chipset == VIA_PRO_GROUP_A ||
983 dev_priv->chipset == VIA_DX9_0);
985 supported_3d = dev_priv->chipset != VIA_DX9_0;
988 hc_state->unfinished = no_sequence;
989 hc_state->map_cache = NULL;
991 hc_state->buf_start = buf;
992 dev_priv->num_fire_offsets = 0;
994 while (buf < buf_end) {
998 state = via_check_header2(&buf, buf_end, hc_state);
1001 state = via_check_header1(&buf, buf_end);
1003 case state_vheader5:
1004 state = via_check_vheader5(&buf, buf_end);
1006 case state_vheader6:
1007 state = via_check_vheader6(&buf, buf_end);
1010 if ((HALCYON_HEADER2 == (cmd = *buf)) &&
1012 state = state_header2;
1013 else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
1014 state = state_header1;
1016 && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
1017 state = state_vheader5;
1019 && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
1020 state = state_vheader6;
1021 else if ((cmd == HALCYON_HEADER2) && !supported_3d) {
1022 DRM_ERROR("Accelerated 3D is not supported on this chipset yet.\n");
1023 state = state_error;
1026 ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
1028 state = state_error;
1033 *hc_state = saved_state;
1037 if (state == state_error) {
1038 *hc_state = saved_state;
1045 via_parse_command_stream(struct drm_device * dev, const uint32_t * buf,
1049 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
1051 const uint32_t *buf_end = buf + (size >> 2);
1052 verifier_state_t state = state_command;
1055 while (buf < buf_end) {
1060 via_parse_header2(dev_priv, &buf, buf_end,
1064 state = via_parse_header1(dev_priv, &buf, buf_end);
1066 case state_vheader5:
1067 state = via_parse_vheader5(dev_priv, &buf, buf_end);
1069 case state_vheader6:
1070 state = via_parse_vheader6(dev_priv, &buf, buf_end);
1073 if (HALCYON_HEADER2 == (cmd = *buf))
1074 state = state_header2;
1075 else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
1076 state = state_header1;
1077 else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
1078 state = state_vheader5;
1079 else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
1080 state = state_vheader6;
1083 ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
1085 state = state_error;
1093 if (state == state_error) {
1100 setup_hazard_table(hz_init_t init_table[], hazard_t table[], int size)
1104 for (i = 0; i < 256; ++i) {
1105 table[i] = forbidden_command;
1108 for (i = 0; i < size; ++i) {
1109 table[init_table[i].code] = init_table[i].hz;
1113 void via_init_command_verifier(void)
1115 setup_hazard_table(init_table1, table1,
1116 sizeof(init_table1) / sizeof(hz_init_t));
1117 setup_hazard_table(init_table2, table2,
1118 sizeof(init_table2) / sizeof(hz_init_t));
1119 setup_hazard_table(init_table3, table3,
1120 sizeof(init_table3) / sizeof(hz_init_t));