Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The Unichrome Project. All Rights Reserved. |
| 3 | * Copyright 2005 Thomas Hellstrom. All Rights Reserved. |
| 4 | * |
| 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: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial portions |
| 14 | * of the Software. |
| 15 | * |
| 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. |
| 23 | * |
| 24 | * Author: Thomas Hellstrom 2004, 2005. |
| 25 | * This code was written using docs obtained under NDA from VIA Inc. |
| 26 | * |
| 27 | * Don't run this code directly on an AGP buffer. Due to cache problems it will |
| 28 | * be very slow. |
| 29 | */ |
| 30 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 31 | #include "via_3d_reg.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 32 | #include <drm/drmP.h> |
| 33 | #include <drm/via_drm.h> |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 34 | #include "via_verifier.h" |
| 35 | #include "via_drv.h" |
| 36 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 37 | typedef enum { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 38 | state_command, |
| 39 | state_header2, |
| 40 | state_header1, |
| 41 | state_vheader5, |
| 42 | state_vheader6, |
| 43 | state_error |
| 44 | } verifier_state_t; |
| 45 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 46 | typedef enum { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 47 | no_check = 0, |
| 48 | check_for_header2, |
| 49 | check_for_header1, |
| 50 | check_for_header2_err, |
| 51 | check_for_header1_err, |
| 52 | check_for_fire, |
| 53 | check_z_buffer_addr0, |
| 54 | check_z_buffer_addr1, |
| 55 | check_z_buffer_addr_mode, |
| 56 | check_destination_addr0, |
| 57 | check_destination_addr1, |
| 58 | check_destination_addr_mode, |
| 59 | check_for_dummy, |
| 60 | check_for_dd, |
| 61 | check_texture_addr0, |
| 62 | check_texture_addr1, |
| 63 | check_texture_addr2, |
| 64 | check_texture_addr3, |
| 65 | check_texture_addr4, |
| 66 | check_texture_addr5, |
| 67 | check_texture_addr6, |
| 68 | check_texture_addr7, |
| 69 | check_texture_addr8, |
| 70 | check_texture_addr_mode, |
| 71 | check_for_vertex_count, |
| 72 | check_number_texunits, |
| 73 | forbidden_command |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 74 | } hazard_t; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Associates each hazard above with a possible multi-command |
| 78 | * sequence. For example an address that is split over multiple |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 79 | * commands and that needs to be checked at the first command |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 80 | * that does not include any part of the address. |
| 81 | */ |
| 82 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 83 | static drm_via_sequence_t seqs[] = { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 84 | no_sequence, |
| 85 | no_sequence, |
| 86 | no_sequence, |
| 87 | no_sequence, |
| 88 | no_sequence, |
| 89 | no_sequence, |
| 90 | z_address, |
| 91 | z_address, |
| 92 | z_address, |
| 93 | dest_address, |
| 94 | dest_address, |
| 95 | dest_address, |
| 96 | no_sequence, |
| 97 | no_sequence, |
| 98 | tex_address, |
| 99 | tex_address, |
| 100 | tex_address, |
| 101 | tex_address, |
| 102 | tex_address, |
| 103 | tex_address, |
| 104 | tex_address, |
| 105 | tex_address, |
| 106 | tex_address, |
| 107 | tex_address, |
| 108 | no_sequence |
| 109 | }; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 110 | |
| 111 | typedef struct { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 112 | unsigned int code; |
| 113 | hazard_t hz; |
| 114 | } hz_init_t; |
| 115 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 116 | static hz_init_t init_table1[] = { |
| 117 | {0xf2, check_for_header2_err}, |
| 118 | {0xf0, check_for_header1_err}, |
| 119 | {0xee, check_for_fire}, |
| 120 | {0xcc, check_for_dummy}, |
| 121 | {0xdd, check_for_dd}, |
| 122 | {0x00, no_check}, |
| 123 | {0x10, check_z_buffer_addr0}, |
| 124 | {0x11, check_z_buffer_addr1}, |
| 125 | {0x12, check_z_buffer_addr_mode}, |
| 126 | {0x13, no_check}, |
| 127 | {0x14, no_check}, |
| 128 | {0x15, no_check}, |
| 129 | {0x23, no_check}, |
| 130 | {0x24, no_check}, |
| 131 | {0x33, no_check}, |
| 132 | {0x34, no_check}, |
| 133 | {0x35, no_check}, |
| 134 | {0x36, no_check}, |
| 135 | {0x37, no_check}, |
| 136 | {0x38, no_check}, |
| 137 | {0x39, no_check}, |
| 138 | {0x3A, no_check}, |
| 139 | {0x3B, no_check}, |
| 140 | {0x3C, no_check}, |
| 141 | {0x3D, no_check}, |
| 142 | {0x3E, no_check}, |
| 143 | {0x40, check_destination_addr0}, |
| 144 | {0x41, check_destination_addr1}, |
| 145 | {0x42, check_destination_addr_mode}, |
| 146 | {0x43, no_check}, |
| 147 | {0x44, no_check}, |
| 148 | {0x50, no_check}, |
| 149 | {0x51, no_check}, |
| 150 | {0x52, no_check}, |
| 151 | {0x53, no_check}, |
| 152 | {0x54, no_check}, |
| 153 | {0x55, no_check}, |
| 154 | {0x56, no_check}, |
| 155 | {0x57, no_check}, |
| 156 | {0x58, no_check}, |
| 157 | {0x70, no_check}, |
| 158 | {0x71, no_check}, |
| 159 | {0x78, no_check}, |
| 160 | {0x79, no_check}, |
| 161 | {0x7A, no_check}, |
| 162 | {0x7B, no_check}, |
| 163 | {0x7C, no_check}, |
| 164 | {0x7D, check_for_vertex_count} |
| 165 | }; |
| 166 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 167 | static hz_init_t init_table2[] = { |
| 168 | {0xf2, check_for_header2_err}, |
| 169 | {0xf0, check_for_header1_err}, |
| 170 | {0xee, check_for_fire}, |
| 171 | {0xcc, check_for_dummy}, |
| 172 | {0x00, check_texture_addr0}, |
| 173 | {0x01, check_texture_addr0}, |
| 174 | {0x02, check_texture_addr0}, |
| 175 | {0x03, check_texture_addr0}, |
| 176 | {0x04, check_texture_addr0}, |
| 177 | {0x05, check_texture_addr0}, |
| 178 | {0x06, check_texture_addr0}, |
| 179 | {0x07, check_texture_addr0}, |
| 180 | {0x08, check_texture_addr0}, |
| 181 | {0x09, check_texture_addr0}, |
| 182 | {0x20, check_texture_addr1}, |
| 183 | {0x21, check_texture_addr1}, |
| 184 | {0x22, check_texture_addr1}, |
| 185 | {0x23, check_texture_addr4}, |
| 186 | {0x2B, check_texture_addr3}, |
| 187 | {0x2C, check_texture_addr3}, |
| 188 | {0x2D, check_texture_addr3}, |
| 189 | {0x2E, check_texture_addr3}, |
| 190 | {0x2F, check_texture_addr3}, |
| 191 | {0x30, check_texture_addr3}, |
| 192 | {0x31, check_texture_addr3}, |
| 193 | {0x32, check_texture_addr3}, |
| 194 | {0x33, check_texture_addr3}, |
| 195 | {0x34, check_texture_addr3}, |
| 196 | {0x4B, check_texture_addr5}, |
| 197 | {0x4C, check_texture_addr6}, |
| 198 | {0x51, check_texture_addr7}, |
| 199 | {0x52, check_texture_addr8}, |
| 200 | {0x77, check_texture_addr2}, |
| 201 | {0x78, no_check}, |
| 202 | {0x79, no_check}, |
| 203 | {0x7A, no_check}, |
| 204 | {0x7B, check_texture_addr_mode}, |
| 205 | {0x7C, no_check}, |
| 206 | {0x7D, no_check}, |
| 207 | {0x7E, no_check}, |
| 208 | {0x7F, no_check}, |
| 209 | {0x80, no_check}, |
| 210 | {0x81, no_check}, |
| 211 | {0x82, no_check}, |
| 212 | {0x83, no_check}, |
| 213 | {0x85, no_check}, |
| 214 | {0x86, no_check}, |
| 215 | {0x87, no_check}, |
| 216 | {0x88, no_check}, |
| 217 | {0x89, no_check}, |
| 218 | {0x8A, no_check}, |
| 219 | {0x90, no_check}, |
| 220 | {0x91, no_check}, |
| 221 | {0x92, no_check}, |
| 222 | {0x93, no_check} |
| 223 | }; |
| 224 | |
| 225 | static hz_init_t init_table3[] = { |
| 226 | {0xf2, check_for_header2_err}, |
| 227 | {0xf0, check_for_header1_err}, |
| 228 | {0xcc, check_for_dummy}, |
| 229 | {0x00, check_number_texunits} |
| 230 | }; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 231 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 232 | static hazard_t table1[256]; |
| 233 | static hazard_t table2[256]; |
| 234 | static hazard_t table3[256]; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 235 | |
| 236 | static __inline__ int |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 237 | eat_words(const uint32_t **buf, const uint32_t *buf_end, unsigned num_words) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 238 | { |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 239 | if ((buf_end - *buf) >= num_words) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 240 | *buf += num_words; |
| 241 | return 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 242 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 243 | DRM_ERROR("Illegal termination of DMA command buffer\n"); |
| 244 | return 1; |
| 245 | } |
| 246 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 247 | /* |
| 248 | * Partially stolen from drm_memory.h |
| 249 | */ |
| 250 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 251 | static __inline__ drm_local_map_t *via_drm_lookup_agp_map(drm_via_state_t *seq, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 252 | unsigned long offset, |
| 253 | unsigned long size, |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 254 | struct drm_device *dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 255 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 256 | struct drm_map_list *r_list; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 257 | drm_local_map_t *map = seq->map_cache; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 258 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 259 | if (map && map->offset <= offset |
| 260 | && (offset + size) <= (map->offset + map->size)) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 261 | return map; |
| 262 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 263 | |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 264 | list_for_each_entry(r_list, &dev->maplist, head) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 265 | map = r_list->map; |
| 266 | if (!map) |
| 267 | continue; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 268 | if (map->offset <= offset |
| 269 | && (offset + size) <= (map->offset + map->size) |
| 270 | && !(map->flags & _DRM_RESTRICTED) |
| 271 | && (map->type == _DRM_AGP)) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 272 | seq->map_cache = map; |
| 273 | return map; |
| 274 | } |
| 275 | } |
| 276 | return NULL; |
| 277 | } |
| 278 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 279 | /* |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 280 | * Require that all AGP texture levels reside in the same AGP map which should |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 281 | * be mappable by the client. This is not a big restriction. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 282 | * FIXME: To actually enforce this security policy strictly, drm_rmmap |
| 283 | * would have to wait for dma quiescent before removing an AGP map. |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 284 | * The via_drm_lookup_agp_map call in reality seems to take |
| 285 | * very little CPU time. |
| 286 | */ |
| 287 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 288 | static __inline__ int finish_current_sequence(drm_via_state_t * cur_seq) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 289 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 290 | switch (cur_seq->unfinished) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 291 | case z_address: |
| 292 | DRM_DEBUG("Z Buffer start address is 0x%x\n", cur_seq->z_addr); |
| 293 | break; |
| 294 | case dest_address: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 295 | DRM_DEBUG("Destination start address is 0x%x\n", |
| 296 | cur_seq->d_addr); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 297 | break; |
| 298 | case tex_address: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 299 | if (cur_seq->agp_texture) { |
| 300 | unsigned start = |
| 301 | cur_seq->tex_level_lo[cur_seq->texture]; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 302 | unsigned end = cur_seq->tex_level_hi[cur_seq->texture]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 303 | unsigned long lo = ~0, hi = 0, tmp; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 304 | uint32_t *addr, *pitch, *height, tex; |
| 305 | unsigned i; |
Thomas Hellstrom | 9b8d9d0 | 2007-01-08 21:21:41 +1100 | [diff] [blame] | 306 | int npot; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 307 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 308 | if (end > 9) |
| 309 | end = 9; |
| 310 | if (start > 9) |
| 311 | start = 9; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 312 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 313 | addr = |
| 314 | &(cur_seq->t_addr[tex = cur_seq->texture][start]); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 315 | pitch = &(cur_seq->pitch[tex][start]); |
| 316 | height = &(cur_seq->height[tex][start]); |
Thomas Hellstrom | 9b8d9d0 | 2007-01-08 21:21:41 +1100 | [diff] [blame] | 317 | npot = cur_seq->tex_npot[tex]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 318 | for (i = start; i <= end; ++i) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 319 | tmp = *addr++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 320 | if (tmp < lo) |
| 321 | lo = tmp; |
Thomas Hellstrom | 9b8d9d0 | 2007-01-08 21:21:41 +1100 | [diff] [blame] | 322 | if (i == 0 && npot) |
| 323 | tmp += (*height++ * *pitch++); |
| 324 | else |
| 325 | tmp += (*height++ << *pitch++); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 326 | if (tmp > hi) |
| 327 | hi = tmp; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 328 | } |
| 329 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 330 | if (!via_drm_lookup_agp_map |
| 331 | (cur_seq, lo, hi - lo, cur_seq->dev)) { |
| 332 | DRM_ERROR |
| 333 | ("AGP texture is not in allowed map\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 334 | return 2; |
| 335 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 336 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 337 | break; |
| 338 | default: |
| 339 | break; |
| 340 | } |
| 341 | cur_seq->unfinished = no_sequence; |
| 342 | return 0; |
| 343 | } |
| 344 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 345 | static __inline__ int |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 346 | investigate_hazard(uint32_t cmd, hazard_t hz, drm_via_state_t *cur_seq) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 347 | { |
| 348 | register uint32_t tmp, *tmp_addr; |
| 349 | |
| 350 | if (cur_seq->unfinished && (cur_seq->unfinished != seqs[hz])) { |
| 351 | int ret; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 352 | if ((ret = finish_current_sequence(cur_seq))) |
| 353 | return ret; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 354 | } |
| 355 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 356 | switch (hz) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 357 | case check_for_header2: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 358 | if (cmd == HALCYON_HEADER2) |
| 359 | return 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 360 | return 0; |
| 361 | case check_for_header1: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 362 | if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1) |
| 363 | return 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 364 | return 0; |
| 365 | case check_for_header2_err: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 366 | if (cmd == HALCYON_HEADER2) |
| 367 | return 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 368 | DRM_ERROR("Illegal DMA HALCYON_HEADER2 command\n"); |
| 369 | break; |
| 370 | case check_for_header1_err: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 371 | if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1) |
| 372 | return 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 373 | DRM_ERROR("Illegal DMA HALCYON_HEADER1 command\n"); |
| 374 | break; |
| 375 | case check_for_fire: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 376 | if ((cmd & HALCYON_FIREMASK) == HALCYON_FIRECMD) |
| 377 | return 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 378 | DRM_ERROR("Illegal DMA HALCYON_FIRECMD command\n"); |
| 379 | break; |
| 380 | case check_for_dummy: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 381 | if (HC_DUMMY == cmd) |
| 382 | return 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 383 | DRM_ERROR("Illegal DMA HC_DUMMY command\n"); |
| 384 | break; |
| 385 | case check_for_dd: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 386 | if (0xdddddddd == cmd) |
| 387 | return 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 388 | DRM_ERROR("Illegal DMA 0xdddddddd command\n"); |
| 389 | break; |
| 390 | case check_z_buffer_addr0: |
| 391 | cur_seq->unfinished = z_address; |
| 392 | cur_seq->z_addr = (cur_seq->z_addr & 0xFF000000) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 393 | (cmd & 0x00FFFFFF); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 394 | return 0; |
| 395 | case check_z_buffer_addr1: |
| 396 | cur_seq->unfinished = z_address; |
| 397 | cur_seq->z_addr = (cur_seq->z_addr & 0x00FFFFFF) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 398 | ((cmd & 0xFF) << 24); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 399 | return 0; |
| 400 | case check_z_buffer_addr_mode: |
| 401 | cur_seq->unfinished = z_address; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 402 | if ((cmd & 0x0000C000) == 0) |
| 403 | return 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 404 | DRM_ERROR("Attempt to place Z buffer in system memory\n"); |
| 405 | return 2; |
| 406 | case check_destination_addr0: |
| 407 | cur_seq->unfinished = dest_address; |
| 408 | cur_seq->d_addr = (cur_seq->d_addr & 0xFF000000) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 409 | (cmd & 0x00FFFFFF); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 410 | return 0; |
| 411 | case check_destination_addr1: |
| 412 | cur_seq->unfinished = dest_address; |
| 413 | cur_seq->d_addr = (cur_seq->d_addr & 0x00FFFFFF) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 414 | ((cmd & 0xFF) << 24); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 415 | return 0; |
| 416 | case check_destination_addr_mode: |
| 417 | cur_seq->unfinished = dest_address; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 418 | if ((cmd & 0x0000C000) == 0) |
| 419 | return 0; |
| 420 | DRM_ERROR |
| 421 | ("Attempt to place 3D drawing buffer in system memory\n"); |
| 422 | return 2; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 423 | case check_texture_addr0: |
| 424 | cur_seq->unfinished = tex_address; |
| 425 | tmp = (cmd >> 24); |
| 426 | tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp]; |
| 427 | *tmp_addr = (*tmp_addr & 0xFF000000) | (cmd & 0x00FFFFFF); |
| 428 | return 0; |
| 429 | case check_texture_addr1: |
| 430 | cur_seq->unfinished = tex_address; |
| 431 | tmp = ((cmd >> 24) - 0x20); |
| 432 | tmp += tmp << 1; |
| 433 | tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp]; |
| 434 | *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24); |
| 435 | tmp_addr++; |
| 436 | *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF00) << 16); |
| 437 | tmp_addr++; |
| 438 | *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF0000) << 8); |
| 439 | return 0; |
| 440 | case check_texture_addr2: |
| 441 | cur_seq->unfinished = tex_address; |
| 442 | cur_seq->tex_level_lo[tmp = cur_seq->texture] = cmd & 0x3F; |
| 443 | cur_seq->tex_level_hi[tmp] = (cmd & 0xFC0) >> 6; |
| 444 | return 0; |
| 445 | case check_texture_addr3: |
| 446 | cur_seq->unfinished = tex_address; |
Thomas Hellstrom | 9b8d9d0 | 2007-01-08 21:21:41 +1100 | [diff] [blame] | 447 | tmp = ((cmd >> 24) - HC_SubA_HTXnL0Pit); |
| 448 | if (tmp == 0 && |
| 449 | (cmd & HC_HTXnEnPit_MASK)) { |
| 450 | cur_seq->pitch[cur_seq->texture][tmp] = |
| 451 | (cmd & HC_HTXnLnPit_MASK); |
| 452 | cur_seq->tex_npot[cur_seq->texture] = 1; |
| 453 | } else { |
| 454 | cur_seq->pitch[cur_seq->texture][tmp] = |
| 455 | (cmd & HC_HTXnLnPitE_MASK) >> HC_HTXnLnPitE_SHIFT; |
| 456 | cur_seq->tex_npot[cur_seq->texture] = 0; |
| 457 | if (cmd & 0x000FFFFF) { |
| 458 | DRM_ERROR |
| 459 | ("Unimplemented texture level 0 pitch mode.\n"); |
| 460 | return 2; |
| 461 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 462 | } |
| 463 | return 0; |
| 464 | case check_texture_addr4: |
| 465 | cur_seq->unfinished = tex_address; |
| 466 | tmp_addr = &cur_seq->t_addr[cur_seq->texture][9]; |
| 467 | *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24); |
| 468 | return 0; |
| 469 | case check_texture_addr5: |
| 470 | case check_texture_addr6: |
| 471 | cur_seq->unfinished = tex_address; |
| 472 | /* |
| 473 | * Texture width. We don't care since we have the pitch. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 474 | */ |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 475 | return 0; |
| 476 | case check_texture_addr7: |
| 477 | cur_seq->unfinished = tex_address; |
| 478 | tmp_addr = &(cur_seq->height[cur_seq->texture][0]); |
| 479 | tmp_addr[5] = 1 << ((cmd & 0x00F00000) >> 20); |
| 480 | tmp_addr[4] = 1 << ((cmd & 0x000F0000) >> 16); |
| 481 | tmp_addr[3] = 1 << ((cmd & 0x0000F000) >> 12); |
| 482 | tmp_addr[2] = 1 << ((cmd & 0x00000F00) >> 8); |
| 483 | tmp_addr[1] = 1 << ((cmd & 0x000000F0) >> 4); |
| 484 | tmp_addr[0] = 1 << (cmd & 0x0000000F); |
| 485 | return 0; |
| 486 | case check_texture_addr8: |
| 487 | cur_seq->unfinished = tex_address; |
| 488 | tmp_addr = &(cur_seq->height[cur_seq->texture][0]); |
| 489 | tmp_addr[9] = 1 << ((cmd & 0x0000F000) >> 12); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 490 | tmp_addr[8] = 1 << ((cmd & 0x00000F00) >> 8); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 491 | tmp_addr[7] = 1 << ((cmd & 0x000000F0) >> 4); |
| 492 | tmp_addr[6] = 1 << (cmd & 0x0000000F); |
| 493 | return 0; |
| 494 | case check_texture_addr_mode: |
| 495 | cur_seq->unfinished = tex_address; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 496 | if (2 == (tmp = cmd & 0x00000003)) { |
| 497 | DRM_ERROR |
| 498 | ("Attempt to fetch texture from system memory.\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 499 | return 2; |
| 500 | } |
| 501 | cur_seq->agp_texture = (tmp == 3); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 502 | cur_seq->tex_palette_size[cur_seq->texture] = |
| 503 | (cmd >> 16) & 0x000000007; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 504 | return 0; |
| 505 | case check_for_vertex_count: |
| 506 | cur_seq->vertex_count = cmd & 0x0000FFFF; |
| 507 | return 0; |
| 508 | case check_number_texunits: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 509 | cur_seq->multitex = (cmd >> 3) & 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 510 | return 0; |
| 511 | default: |
| 512 | DRM_ERROR("Illegal DMA data: 0x%x\n", cmd); |
| 513 | return 2; |
| 514 | } |
| 515 | return 2; |
| 516 | } |
| 517 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 518 | static __inline__ int |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 519 | via_check_prim_list(uint32_t const **buffer, const uint32_t * buf_end, |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 520 | drm_via_state_t *cur_seq) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 521 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 522 | drm_via_private_t *dev_priv = |
| 523 | (drm_via_private_t *) cur_seq->dev->dev_private; |
| 524 | uint32_t a_fire, bcmd, dw_count; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 525 | int ret = 0; |
| 526 | int have_fire; |
| 527 | const uint32_t *buf = *buffer; |
| 528 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 529 | while (buf < buf_end) { |
| 530 | have_fire = 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 531 | if ((buf_end - buf) < 2) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 532 | DRM_ERROR |
| 533 | ("Unexpected termination of primitive list.\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 534 | ret = 1; |
| 535 | break; |
| 536 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 537 | if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdB) |
| 538 | break; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 539 | bcmd = *buf++; |
| 540 | if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdA) { |
| 541 | DRM_ERROR("Expected Vertex List A command, got 0x%x\n", |
| 542 | *buf); |
| 543 | ret = 1; |
| 544 | break; |
| 545 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 546 | a_fire = |
| 547 | *buf++ | HC_HPLEND_MASK | HC_HPMValidN_MASK | |
| 548 | HC_HE3Fire_MASK; |
| 549 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 550 | /* |
| 551 | * How many dwords per vertex ? |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 552 | */ |
| 553 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 554 | if (cur_seq->agp && ((bcmd & (0xF << 11)) == 0)) { |
| 555 | DRM_ERROR("Illegal B command vertex data for AGP.\n"); |
| 556 | ret = 1; |
| 557 | break; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 558 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 559 | |
| 560 | dw_count = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 561 | if (bcmd & (1 << 7)) |
| 562 | dw_count += (cur_seq->multitex) ? 2 : 1; |
| 563 | if (bcmd & (1 << 8)) |
| 564 | dw_count += (cur_seq->multitex) ? 2 : 1; |
| 565 | if (bcmd & (1 << 9)) |
| 566 | dw_count++; |
| 567 | if (bcmd & (1 << 10)) |
| 568 | dw_count++; |
| 569 | if (bcmd & (1 << 11)) |
| 570 | dw_count++; |
| 571 | if (bcmd & (1 << 12)) |
| 572 | dw_count++; |
| 573 | if (bcmd & (1 << 13)) |
| 574 | dw_count++; |
| 575 | if (bcmd & (1 << 14)) |
| 576 | dw_count++; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 577 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 578 | while (buf < buf_end) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 579 | if (*buf == a_fire) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 580 | if (dev_priv->num_fire_offsets >= |
| 581 | VIA_FIRE_BUF_SIZE) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 582 | DRM_ERROR("Fire offset buffer full.\n"); |
| 583 | ret = 1; |
| 584 | break; |
| 585 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 586 | dev_priv->fire_offsets[dev_priv-> |
| 587 | num_fire_offsets++] = |
| 588 | buf; |
| 589 | have_fire = 1; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 590 | buf++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 591 | if (buf < buf_end && *buf == a_fire) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 592 | buf++; |
| 593 | break; |
| 594 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 595 | if ((*buf == HALCYON_HEADER2) || |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 596 | ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD)) { |
| 597 | DRM_ERROR("Missing Vertex Fire command, " |
| 598 | "Stray Vertex Fire command or verifier " |
| 599 | "lost sync.\n"); |
| 600 | ret = 1; |
| 601 | break; |
| 602 | } |
| 603 | if ((ret = eat_words(&buf, buf_end, dw_count))) |
| 604 | break; |
| 605 | } |
| 606 | if (buf >= buf_end && !have_fire) { |
| 607 | DRM_ERROR("Missing Vertex Fire command or verifier " |
| 608 | "lost sync.\n"); |
| 609 | ret = 1; |
| 610 | break; |
| 611 | } |
| 612 | if (cur_seq->agp && ((buf - cur_seq->buf_start) & 0x01)) { |
| 613 | DRM_ERROR("AGP Primitive list end misaligned.\n"); |
| 614 | ret = 1; |
| 615 | break; |
| 616 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 617 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 618 | *buffer = buf; |
| 619 | return ret; |
| 620 | } |
| 621 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 622 | static __inline__ verifier_state_t |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 623 | via_check_header2(uint32_t const **buffer, const uint32_t *buf_end, |
| 624 | drm_via_state_t *hc_state) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 625 | { |
| 626 | uint32_t cmd; |
| 627 | int hz_mode; |
| 628 | hazard_t hz; |
| 629 | const uint32_t *buf = *buffer; |
| 630 | const hazard_t *hz_table; |
| 631 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 632 | if ((buf_end - buf) < 2) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 633 | DRM_ERROR |
| 634 | ("Illegal termination of DMA HALCYON_HEADER2 sequence.\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 635 | return state_error; |
| 636 | } |
| 637 | buf++; |
| 638 | cmd = (*buf++ & 0xFFFF0000) >> 16; |
| 639 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 640 | switch (cmd) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 641 | case HC_ParaType_CmdVdata: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 642 | if (via_check_prim_list(&buf, buf_end, hc_state)) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 643 | return state_error; |
| 644 | *buffer = buf; |
| 645 | return state_command; |
| 646 | case HC_ParaType_NotTex: |
| 647 | hz_table = table1; |
| 648 | break; |
| 649 | case HC_ParaType_Tex: |
| 650 | hc_state->texture = 0; |
| 651 | hz_table = table2; |
| 652 | break; |
| 653 | case (HC_ParaType_Tex | (HC_SubType_Tex1 << 8)): |
| 654 | hc_state->texture = 1; |
| 655 | hz_table = table2; |
| 656 | break; |
| 657 | case (HC_ParaType_Tex | (HC_SubType_TexGeneral << 8)): |
| 658 | hz_table = table3; |
| 659 | break; |
| 660 | case HC_ParaType_Auto: |
| 661 | if (eat_words(&buf, buf_end, 2)) |
| 662 | return state_error; |
| 663 | *buffer = buf; |
| 664 | return state_command; |
| 665 | case (HC_ParaType_Palette | (HC_SubType_Stipple << 8)): |
| 666 | if (eat_words(&buf, buf_end, 32)) |
| 667 | return state_error; |
| 668 | *buffer = buf; |
| 669 | return state_command; |
| 670 | case (HC_ParaType_Palette | (HC_SubType_TexPalette0 << 8)): |
| 671 | case (HC_ParaType_Palette | (HC_SubType_TexPalette1 << 8)): |
| 672 | DRM_ERROR("Texture palettes are rejected because of " |
| 673 | "lack of info how to determine their size.\n"); |
| 674 | return state_error; |
| 675 | case (HC_ParaType_Palette | (HC_SubType_FogTable << 8)): |
| 676 | DRM_ERROR("Fog factor palettes are rejected because of " |
| 677 | "lack of info how to determine their size.\n"); |
| 678 | return state_error; |
| 679 | default: |
| 680 | |
| 681 | /* |
| 682 | * There are some unimplemented HC_ParaTypes here, that |
| 683 | * need to be implemented if the Mesa driver is extended. |
| 684 | */ |
| 685 | |
| 686 | DRM_ERROR("Invalid or unimplemented HALCYON_HEADER2 " |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 687 | "DMA subcommand: 0x%x. Previous dword: 0x%x\n", |
| 688 | cmd, *(buf - 2)); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 689 | *buffer = buf; |
| 690 | return state_error; |
| 691 | } |
| 692 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 693 | while (buf < buf_end) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 694 | cmd = *buf++; |
| 695 | if ((hz = hz_table[cmd >> 24])) { |
| 696 | if ((hz_mode = investigate_hazard(cmd, hz, hc_state))) { |
| 697 | if (hz_mode == 1) { |
| 698 | buf--; |
| 699 | break; |
| 700 | } |
| 701 | return state_error; |
| 702 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 703 | } else if (hc_state->unfinished && |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 704 | finish_current_sequence(hc_state)) { |
| 705 | return state_error; |
| 706 | } |
| 707 | } |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 708 | if (hc_state->unfinished && finish_current_sequence(hc_state)) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 709 | return state_error; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 710 | *buffer = buf; |
| 711 | return state_command; |
| 712 | } |
| 713 | |
| 714 | static __inline__ verifier_state_t |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 715 | via_parse_header2(drm_via_private_t *dev_priv, uint32_t const **buffer, |
| 716 | const uint32_t *buf_end, int *fire_count) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 717 | { |
| 718 | uint32_t cmd; |
| 719 | const uint32_t *buf = *buffer; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 720 | const uint32_t *next_fire; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 721 | int burst = 0; |
| 722 | |
| 723 | next_fire = dev_priv->fire_offsets[*fire_count]; |
| 724 | buf++; |
| 725 | cmd = (*buf & 0xFFFF0000) >> 16; |
| 726 | VIA_WRITE(HC_REG_TRANS_SET + HC_REG_BASE, *buf++); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 727 | switch (cmd) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 728 | case HC_ParaType_CmdVdata: |
| 729 | while ((buf < buf_end) && |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 730 | (*fire_count < dev_priv->num_fire_offsets) && |
| 731 | (*buf & HC_ACMD_MASK) == HC_ACMD_HCmdB) { |
| 732 | while (buf <= next_fire) { |
| 733 | VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE + |
| 734 | (burst & 63), *buf++); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 735 | burst += 4; |
| 736 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 737 | if ((buf < buf_end) |
| 738 | && ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD)) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 739 | buf++; |
| 740 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 741 | if (++(*fire_count) < dev_priv->num_fire_offsets) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 742 | next_fire = dev_priv->fire_offsets[*fire_count]; |
| 743 | } |
| 744 | break; |
| 745 | default: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 746 | while (buf < buf_end) { |
| 747 | |
| 748 | if (*buf == HC_HEADER2 || |
| 749 | (*buf & HALCYON_HEADER1MASK) == HALCYON_HEADER1 || |
| 750 | (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5 || |
| 751 | (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6) |
| 752 | break; |
| 753 | |
| 754 | VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE + |
| 755 | (burst & 63), *buf++); |
| 756 | burst += 4; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | *buffer = buf; |
| 760 | return state_command; |
| 761 | } |
| 762 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 763 | static __inline__ int verify_mmio_address(uint32_t address) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 764 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 765 | if ((address > 0x3FF) && (address < 0xC00)) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 766 | DRM_ERROR("Invalid VIDEO DMA command. " |
| 767 | "Attempt to access 3D- or command burst area.\n"); |
| 768 | return 1; |
| 769 | } else if ((address > 0xCFF) && (address < 0x1300)) { |
| 770 | DRM_ERROR("Invalid VIDEO DMA command. " |
| 771 | "Attempt to access PCI DMA area.\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 772 | return 1; |
| 773 | } else if (address > 0x13FF) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 774 | DRM_ERROR("Invalid VIDEO DMA command. " |
| 775 | "Attempt to access VGA registers.\n"); |
| 776 | return 1; |
| 777 | } |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static __inline__ int |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 782 | verify_video_tail(uint32_t const **buffer, const uint32_t * buf_end, |
| 783 | uint32_t dwords) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 784 | { |
| 785 | const uint32_t *buf = *buffer; |
| 786 | |
| 787 | if (buf_end - buf < dwords) { |
| 788 | DRM_ERROR("Illegal termination of video command.\n"); |
| 789 | return 1; |
| 790 | } |
| 791 | while (dwords--) { |
| 792 | if (*buf++) { |
| 793 | DRM_ERROR("Illegal video command tail.\n"); |
| 794 | return 1; |
| 795 | } |
| 796 | } |
| 797 | *buffer = buf; |
| 798 | return 0; |
| 799 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 800 | |
| 801 | static __inline__ verifier_state_t |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 802 | via_check_header1(uint32_t const **buffer, const uint32_t * buf_end) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 803 | { |
| 804 | uint32_t cmd; |
| 805 | const uint32_t *buf = *buffer; |
| 806 | verifier_state_t ret = state_command; |
| 807 | |
| 808 | while (buf < buf_end) { |
| 809 | cmd = *buf; |
| 810 | if ((cmd > ((0x3FF >> 2) | HALCYON_HEADER1)) && |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 811 | (cmd < ((0xC00 >> 2) | HALCYON_HEADER1))) { |
| 812 | if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 813 | break; |
| 814 | DRM_ERROR("Invalid HALCYON_HEADER1 command. " |
| 815 | "Attempt to access 3D- or command burst area.\n"); |
| 816 | ret = state_error; |
| 817 | break; |
| 818 | } else if (cmd > ((0xCFF >> 2) | HALCYON_HEADER1)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 819 | if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 820 | break; |
| 821 | DRM_ERROR("Invalid HALCYON_HEADER1 command. " |
| 822 | "Attempt to access VGA registers.\n"); |
| 823 | ret = state_error; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 824 | break; |
| 825 | } else { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 826 | buf += 2; |
| 827 | } |
| 828 | } |
| 829 | *buffer = buf; |
| 830 | return ret; |
| 831 | } |
| 832 | |
| 833 | static __inline__ verifier_state_t |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 834 | via_parse_header1(drm_via_private_t *dev_priv, uint32_t const **buffer, |
| 835 | const uint32_t *buf_end) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 836 | { |
| 837 | register uint32_t cmd; |
| 838 | const uint32_t *buf = *buffer; |
| 839 | |
| 840 | while (buf < buf_end) { |
| 841 | cmd = *buf; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 842 | if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1) |
| 843 | break; |
| 844 | VIA_WRITE((cmd & ~HALCYON_HEADER1MASK) << 2, *++buf); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 845 | buf++; |
| 846 | } |
| 847 | *buffer = buf; |
| 848 | return state_command; |
| 849 | } |
| 850 | |
| 851 | static __inline__ verifier_state_t |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 852 | via_check_vheader5(uint32_t const **buffer, const uint32_t *buf_end) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 853 | { |
| 854 | uint32_t data; |
| 855 | const uint32_t *buf = *buffer; |
| 856 | |
| 857 | if (buf_end - buf < 4) { |
| 858 | DRM_ERROR("Illegal termination of video header5 command\n"); |
| 859 | return state_error; |
| 860 | } |
| 861 | |
| 862 | data = *buf++ & ~VIA_VIDEOMASK; |
| 863 | if (verify_mmio_address(data)) |
| 864 | return state_error; |
| 865 | |
| 866 | data = *buf++; |
| 867 | if (*buf++ != 0x00F50000) { |
| 868 | DRM_ERROR("Illegal header5 header data\n"); |
| 869 | return state_error; |
| 870 | } |
| 871 | if (*buf++ != 0x00000000) { |
| 872 | DRM_ERROR("Illegal header5 header data\n"); |
| 873 | return state_error; |
| 874 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 875 | if (eat_words(&buf, buf_end, data)) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 876 | return state_error; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 877 | if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3))) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 878 | return state_error; |
| 879 | *buffer = buf; |
| 880 | return state_command; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 881 | |
| 882 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 883 | |
| 884 | static __inline__ verifier_state_t |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 885 | via_parse_vheader5(drm_via_private_t *dev_priv, uint32_t const **buffer, |
| 886 | const uint32_t *buf_end) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 887 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 888 | uint32_t addr, count, i; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 889 | const uint32_t *buf = *buffer; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 890 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 891 | addr = *buf++ & ~VIA_VIDEOMASK; |
| 892 | i = count = *buf; |
| 893 | buf += 3; |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 894 | while (i--) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 895 | VIA_WRITE(addr, *buf++); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 896 | if (count & 3) |
| 897 | buf += 4 - (count & 3); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 898 | *buffer = buf; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 899 | return state_command; |
| 900 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 901 | |
| 902 | static __inline__ verifier_state_t |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 903 | via_check_vheader6(uint32_t const **buffer, const uint32_t * buf_end) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 904 | { |
| 905 | uint32_t data; |
| 906 | const uint32_t *buf = *buffer; |
| 907 | uint32_t i; |
| 908 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 909 | if (buf_end - buf < 4) { |
| 910 | DRM_ERROR("Illegal termination of video header6 command\n"); |
| 911 | return state_error; |
| 912 | } |
| 913 | buf++; |
| 914 | data = *buf++; |
| 915 | if (*buf++ != 0x00F60000) { |
| 916 | DRM_ERROR("Illegal header6 header data\n"); |
| 917 | return state_error; |
| 918 | } |
| 919 | if (*buf++ != 0x00000000) { |
| 920 | DRM_ERROR("Illegal header6 header data\n"); |
| 921 | return state_error; |
| 922 | } |
| 923 | if ((buf_end - buf) < (data << 1)) { |
| 924 | DRM_ERROR("Illegal termination of video header6 command\n"); |
| 925 | return state_error; |
| 926 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 927 | for (i = 0; i < data; ++i) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 928 | if (verify_mmio_address(*buf++)) |
| 929 | return state_error; |
| 930 | buf++; |
| 931 | } |
| 932 | data <<= 1; |
| 933 | if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3))) |
| 934 | return state_error; |
| 935 | *buffer = buf; |
| 936 | return state_command; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 937 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 938 | |
| 939 | static __inline__ verifier_state_t |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 940 | via_parse_vheader6(drm_via_private_t *dev_priv, uint32_t const **buffer, |
| 941 | const uint32_t *buf_end) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 942 | { |
| 943 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 944 | uint32_t addr, count, i; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 945 | const uint32_t *buf = *buffer; |
| 946 | |
| 947 | i = count = *++buf; |
| 948 | buf += 3; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 949 | while (i--) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 950 | addr = *buf++; |
| 951 | VIA_WRITE(addr, *buf++); |
| 952 | } |
| 953 | count <<= 1; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 954 | if (count & 3) |
| 955 | buf += 4 - (count & 3); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 956 | *buffer = buf; |
| 957 | return state_command; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 958 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 959 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 960 | int |
| 961 | via_verify_command_stream(const uint32_t * buf, unsigned int size, |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 962 | struct drm_device * dev, int agp) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 963 | { |
| 964 | |
| 965 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 966 | drm_via_state_t *hc_state = &dev_priv->hc_state; |
| 967 | drm_via_state_t saved_state = *hc_state; |
| 968 | uint32_t cmd; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 969 | const uint32_t *buf_end = buf + (size >> 2); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 970 | verifier_state_t state = state_command; |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 971 | int cme_video; |
| 972 | int supported_3d; |
| 973 | |
| 974 | cme_video = (dev_priv->chipset == VIA_PRO_GROUP_A || |
| 975 | dev_priv->chipset == VIA_DX9_0); |
| 976 | |
| 977 | supported_3d = dev_priv->chipset != VIA_DX9_0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 978 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 979 | hc_state->dev = dev; |
| 980 | hc_state->unfinished = no_sequence; |
| 981 | hc_state->map_cache = NULL; |
| 982 | hc_state->agp = agp; |
| 983 | hc_state->buf_start = buf; |
| 984 | dev_priv->num_fire_offsets = 0; |
| 985 | |
| 986 | while (buf < buf_end) { |
| 987 | |
| 988 | switch (state) { |
| 989 | case state_header2: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 990 | state = via_check_header2(&buf, buf_end, hc_state); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 991 | break; |
| 992 | case state_header1: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 993 | state = via_check_header1(&buf, buf_end); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 994 | break; |
| 995 | case state_vheader5: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 996 | state = via_check_vheader5(&buf, buf_end); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 997 | break; |
| 998 | case state_vheader6: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 999 | state = via_check_vheader6(&buf, buf_end); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1000 | break; |
| 1001 | case state_command: |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 1002 | if ((HALCYON_HEADER2 == (cmd = *buf)) && |
| 1003 | supported_3d) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1004 | state = state_header2; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1005 | else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1006 | state = state_header1; |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 1007 | else if (cme_video |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1008 | && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1009 | state = state_vheader5; |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 1010 | else if (cme_video |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1011 | && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1012 | state = state_vheader6; |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 1013 | else if ((cmd == HALCYON_HEADER2) && !supported_3d) { |
| 1014 | DRM_ERROR("Accelerated 3D is not supported on this chipset yet.\n"); |
| 1015 | state = state_error; |
| 1016 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1017 | DRM_ERROR |
| 1018 | ("Invalid / Unimplemented DMA HEADER command. 0x%x\n", |
| 1019 | cmd); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1020 | state = state_error; |
| 1021 | } |
| 1022 | break; |
| 1023 | case state_error: |
| 1024 | default: |
| 1025 | *hc_state = saved_state; |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1026 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1027 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1028 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1029 | if (state == state_error) { |
| 1030 | *hc_state = saved_state; |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1031 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1032 | } |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1036 | int |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 1037 | via_parse_command_stream(struct drm_device *dev, const uint32_t *buf, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1038 | unsigned int size) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1039 | { |
| 1040 | |
| 1041 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 1042 | uint32_t cmd; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1043 | const uint32_t *buf_end = buf + (size >> 2); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1044 | verifier_state_t state = state_command; |
| 1045 | int fire_count = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1046 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1047 | while (buf < buf_end) { |
| 1048 | |
| 1049 | switch (state) { |
| 1050 | case state_header2: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1051 | state = |
| 1052 | via_parse_header2(dev_priv, &buf, buf_end, |
| 1053 | &fire_count); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1054 | break; |
| 1055 | case state_header1: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1056 | state = via_parse_header1(dev_priv, &buf, buf_end); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1057 | break; |
| 1058 | case state_vheader5: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1059 | state = via_parse_vheader5(dev_priv, &buf, buf_end); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1060 | break; |
| 1061 | case state_vheader6: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1062 | state = via_parse_vheader6(dev_priv, &buf, buf_end); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1063 | break; |
| 1064 | case state_command: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1065 | if (HALCYON_HEADER2 == (cmd = *buf)) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1066 | state = state_header2; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1067 | else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1068 | state = state_header1; |
| 1069 | else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5) |
| 1070 | state = state_vheader5; |
| 1071 | else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6) |
| 1072 | state = state_vheader6; |
| 1073 | else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1074 | DRM_ERROR |
| 1075 | ("Invalid / Unimplemented DMA HEADER command. 0x%x\n", |
| 1076 | cmd); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1077 | state = state_error; |
| 1078 | } |
| 1079 | break; |
| 1080 | case state_error: |
| 1081 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1082 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1083 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1084 | } |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 1085 | if (state == state_error) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1086 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1090 | static void |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1091 | setup_hazard_table(hz_init_t init_table[], hazard_t table[], int size) |
| 1092 | { |
| 1093 | int i; |
| 1094 | |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 1095 | for (i = 0; i < 256; ++i) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1096 | table[i] = forbidden_command; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1097 | |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 1098 | for (i = 0; i < size; ++i) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1099 | table[init_table[i].code] = init_table[i].hz; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1100 | } |
| 1101 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1102 | void via_init_command_verifier(void) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1103 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1104 | setup_hazard_table(init_table1, table1, |
| 1105 | sizeof(init_table1) / sizeof(hz_init_t)); |
| 1106 | setup_hazard_table(init_table2, table2, |
| 1107 | sizeof(init_table2) / sizeof(hz_init_t)); |
| 1108 | setup_hazard_table(init_table3, table3, |
| 1109 | sizeof(init_table3) / sizeof(hz_init_t)); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1110 | } |