Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Daniel Vetter <daniel.vetter@ffwll.ch> (based on gem_storedw_*.c) |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> |
| 30 | #include <string.h> |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 31 | #include <fcntl.h> |
| 32 | #include <inttypes.h> |
| 33 | #include <errno.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/time.h> |
| 36 | #include "drm.h" |
| 37 | #include "i915_drm.h" |
| 38 | #include "drmtest.h" |
| 39 | #include "intel_bufmgr.h" |
| 40 | #include "intel_batchbuffer.h" |
| 41 | #include "intel_gpu_tools.h" |
| 42 | #include "i830_reg.h" |
| 43 | |
| 44 | static drm_intel_bufmgr *bufmgr; |
| 45 | struct intel_batchbuffer *batch; |
| 46 | static drm_intel_bo *target_buffer; |
| 47 | |
| 48 | /* |
| 49 | * Testcase: Basic check of ring<->ring sync using a dummy reloc |
| 50 | * |
| 51 | * Extremely efficient at catching missed irqs with semaphores=0 ... |
| 52 | */ |
| 53 | |
| 54 | #define MI_COND_BATCH_BUFFER_END (0x36<<23 | 1) |
| 55 | #define MI_DO_COMPARE (1<<21) |
| 56 | |
| 57 | static void |
Xiang, Haihao | 0a413cd | 2013-04-23 15:06:41 +0800 | [diff] [blame] | 58 | store_dword_loop(int fd) |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 59 | { |
| 60 | int i; |
Zhong Li | 8ddf84d | 2013-05-03 15:54:48 +0800 | [diff] [blame] | 61 | int num_rings = gem_get_num_rings(fd); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 62 | |
| 63 | srandom(0xdeadbeef); |
| 64 | |
Damien Lespiau | d1e8623 | 2013-03-25 20:06:20 +0000 | [diff] [blame] | 65 | for (i = 0; i < SLOW_QUICK(0x100000, 10); i++) { |
Xiang, Haihao | 0a413cd | 2013-04-23 15:06:41 +0800 | [diff] [blame] | 66 | int ring = random() % num_rings + 1; |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 67 | |
| 68 | if (ring == I915_EXEC_RENDER) { |
| 69 | BEGIN_BATCH(4); |
| 70 | OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE); |
| 71 | OUT_BATCH(0xffffffff); /* compare dword */ |
| 72 | OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER, |
| 73 | I915_GEM_DOMAIN_RENDER, 0); |
| 74 | OUT_BATCH(MI_NOOP); |
| 75 | ADVANCE_BATCH(); |
| 76 | } else { |
| 77 | BEGIN_BATCH(4); |
| 78 | OUT_BATCH(MI_FLUSH_DW | 1); |
| 79 | OUT_BATCH(0); /* reserved */ |
| 80 | OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER, |
| 81 | I915_GEM_DOMAIN_RENDER, 0); |
| 82 | OUT_BATCH(MI_NOOP | (1<<22) | (0xf)); |
| 83 | ADVANCE_BATCH(); |
| 84 | } |
| 85 | intel_batchbuffer_flush_on_ring(batch, ring); |
| 86 | } |
| 87 | |
| 88 | drm_intel_bo_map(target_buffer, 0); |
| 89 | // map to force waiting on rendering |
| 90 | drm_intel_bo_unmap(target_buffer); |
| 91 | } |
| 92 | |
| 93 | int main(int argc, char **argv) |
| 94 | { |
| 95 | int fd; |
| 96 | int devid; |
| 97 | |
| 98 | if (argc != 1) { |
| 99 | fprintf(stderr, "usage: %s\n", argv[0]); |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 100 | igt_fail(-1); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | fd = drm_open_any(); |
| 104 | devid = intel_get_drm_devid(fd); |
| 105 | if (!HAS_BLT_RING(devid)) { |
| 106 | fprintf(stderr, "inter ring check needs gen6+\n"); |
Daniel Vetter | 19d6995 | 2011-09-13 11:05:13 +0200 | [diff] [blame] | 107 | return 77; |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
| 111 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 112 | if (!bufmgr) { |
| 113 | fprintf(stderr, "failed to init libdrm\n"); |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 114 | igt_fail(-1); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 115 | } |
| 116 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 117 | |
| 118 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
| 119 | if (!batch) { |
| 120 | fprintf(stderr, "failed to create batch buffer\n"); |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 121 | igt_fail(-1); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096); |
| 125 | if (!target_buffer) { |
| 126 | fprintf(stderr, "failed to alloc target buffer\n"); |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 127 | igt_fail(-1); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Xiang, Haihao | 0a413cd | 2013-04-23 15:06:41 +0800 | [diff] [blame] | 130 | store_dword_loop(fd); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 131 | |
| 132 | drm_intel_bo_unreference(target_buffer); |
| 133 | intel_batchbuffer_free(batch); |
| 134 | drm_intel_bufmgr_destroy(bufmgr); |
| 135 | |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 136 | close(fd); |
| 137 | |
| 138 | return 0; |
| 139 | } |