| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: i915_cmd_parser.c,v 1.19 2019/12/05 20:03:09 maya Exp $ */ | | 1 | /* $NetBSD: i915_cmd_parser.c,v 1.20 2019/12/05 20:25:54 maya Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright © 2013 Intel Corporation | | 4 | * Copyright © 2013 Intel Corporation |
5 | * | | 5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a | | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), | | 7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation | | 8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | | 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the | | 10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: | | 11 | * Software is furnished to do so, subject to the following conditions: |
12 | * | | 12 | * |
13 | * The above copyright notice and this permission notice (including the next | | 13 | * The above copyright notice and this permission notice (including the next |
14 | * paragraph) shall be included in all copies or substantial portions of the | | 14 | * paragraph) shall be included in all copies or substantial portions of the |
| @@ -18,30 +18,31 @@ | | | @@ -18,30 +18,31 @@ |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | | 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | | 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
23 | * IN THE SOFTWARE. | | 23 | * IN THE SOFTWARE. |
24 | * | | 24 | * |
25 | * Authors: | | 25 | * Authors: |
26 | * Brad Volkin <bradley.d.volkin@intel.com> | | 26 | * Brad Volkin <bradley.d.volkin@intel.com> |
27 | * | | 27 | * |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: i915_cmd_parser.c,v 1.19 2019/12/05 20:03:09 maya Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: i915_cmd_parser.c,v 1.20 2019/12/05 20:25:54 maya Exp $"); |
32 | | | 32 | |
33 | #include "i915_drv.h" | | 33 | #include "i915_drv.h" |
34 | #include <linux/bitmap.h> | | 34 | #include <linux/bitmap.h> |
| | | 35 | #include <linux/log2.h> |
35 | | | 36 | |
36 | /** | | 37 | /** |
37 | * DOC: batch buffer command parser | | 38 | * DOC: batch buffer command parser |
38 | * | | 39 | * |
39 | * Motivation: | | 40 | * Motivation: |
40 | * Certain OpenGL features (e.g. transform feedback, performance monitoring) | | 41 | * Certain OpenGL features (e.g. transform feedback, performance monitoring) |
41 | * require userspace code to submit batches containing commands such as | | 42 | * require userspace code to submit batches containing commands such as |
42 | * MI_LOAD_REGISTER_IMM to access various registers. Unfortunately, some | | 43 | * MI_LOAD_REGISTER_IMM to access various registers. Unfortunately, some |
43 | * generations of the hardware will noop these commands in "unsecure" batches | | 44 | * generations of the hardware will noop these commands in "unsecure" batches |
44 | * (which includes all userspace batches submitted via i915) even though the | | 45 | * (which includes all userspace batches submitted via i915) even though the |
45 | * commands may be safe and represent the intended programming model of the | | 46 | * commands may be safe and represent the intended programming model of the |
46 | * device. | | 47 | * device. |
47 | * | | 48 | * |
| @@ -1249,27 +1250,27 @@ static int check_bbstart(struct intel_co | | | @@ -1249,27 +1250,27 @@ static int check_bbstart(struct intel_co |
1249 | } else if (!test_bit(target_cmd_index, ctx->jump_whitelist)) { | | 1250 | } else if (!test_bit(target_cmd_index, ctx->jump_whitelist)) { |
1250 | DRM_DEBUG("CMD: BB_START to 0x%"PRIx64" not a previously executed cmd\n", | | 1251 | DRM_DEBUG("CMD: BB_START to 0x%"PRIx64" not a previously executed cmd\n", |
1251 | jump_target); | | 1252 | jump_target); |
1252 | return -EINVAL; | | 1253 | return -EINVAL; |
1253 | } | | 1254 | } |
1254 | | | 1255 | |
1255 | return 0; | | 1256 | return 0; |
1256 | } | | 1257 | } |
1257 | | | 1258 | |
1258 | static void init_whitelist(struct intel_context *ctx, u32 batch_len) | | 1259 | static void init_whitelist(struct intel_context *ctx, u32 batch_len) |
1259 | { | | 1260 | { |
1260 | const u32 batch_cmds = DIV_ROUND_UP(batch_len, sizeof(u32)); | | 1261 | const u32 batch_cmds = DIV_ROUND_UP(batch_len, sizeof(u32)); |
1261 | const u32 exact_size = BITS_TO_LONGS(batch_cmds); | | 1262 | const u32 exact_size = BITS_TO_LONGS(batch_cmds); |
1262 | u32 next_size = BITS_TO_LONGS(powerof2(batch_cmds)); | | 1263 | u32 next_size = BITS_TO_LONGS(roundup_pow_of_two(batch_cmds)); |
1263 | unsigned long *next_whitelist; | | 1264 | unsigned long *next_whitelist; |
1264 | | | 1265 | |
1265 | if (CMDPARSER_USES_GGTT(ctx->i915)) | | 1266 | if (CMDPARSER_USES_GGTT(ctx->i915)) |
1266 | return; | | 1267 | return; |
1267 | | | 1268 | |
1268 | if (batch_cmds <= ctx->jump_whitelist_cmds) { | | 1269 | if (batch_cmds <= ctx->jump_whitelist_cmds) { |
1269 | bitmap_zero(ctx->jump_whitelist, batch_cmds); | | 1270 | bitmap_zero(ctx->jump_whitelist, batch_cmds); |
1270 | return; | | 1271 | return; |
1271 | } | | 1272 | } |
1272 | | | 1273 | |
1273 | again: | | 1274 | again: |
1274 | next_whitelist = kcalloc(next_size, sizeof(long), GFP_KERNEL); | | 1275 | next_whitelist = kcalloc(next_size, sizeof(long), GFP_KERNEL); |
1275 | if (next_whitelist) { | | 1276 | if (next_whitelist) { |