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" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 37 | #include "ioctl_wrappers.h" |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 38 | #include "drmtest.h" |
| 39 | #include "intel_bufmgr.h" |
| 40 | #include "intel_batchbuffer.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 41 | #include "intel_io.h" |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 42 | #include "i830_reg.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 43 | #include "intel_chipset.h" |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 44 | |
| 45 | static drm_intel_bufmgr *bufmgr; |
| 46 | struct intel_batchbuffer *batch; |
| 47 | static drm_intel_bo *target_buffer; |
| 48 | |
| 49 | /* |
| 50 | * Testcase: Basic check of ring<->ring sync using a dummy reloc |
| 51 | * |
| 52 | * Extremely efficient at catching missed irqs with semaphores=0 ... |
| 53 | */ |
| 54 | |
| 55 | #define MI_COND_BATCH_BUFFER_END (0x36<<23 | 1) |
| 56 | #define MI_DO_COMPARE (1<<21) |
| 57 | |
| 58 | static void |
Xiang, Haihao | 0a413cd | 2013-04-23 15:06:41 +0800 | [diff] [blame] | 59 | store_dword_loop(int fd) |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 60 | { |
| 61 | int i; |
Zhong Li | 8ddf84d | 2013-05-03 15:54:48 +0800 | [diff] [blame] | 62 | int num_rings = gem_get_num_rings(fd); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 63 | |
| 64 | srandom(0xdeadbeef); |
| 65 | |
Damien Lespiau | d1e8623 | 2013-03-25 20:06:20 +0000 | [diff] [blame] | 66 | for (i = 0; i < SLOW_QUICK(0x100000, 10); i++) { |
Xiang, Haihao | 0a413cd | 2013-04-23 15:06:41 +0800 | [diff] [blame] | 67 | int ring = random() % num_rings + 1; |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 68 | |
| 69 | if (ring == I915_EXEC_RENDER) { |
Chris Wilson | 10552b5 | 2014-08-30 11:44:51 +0100 | [diff] [blame^] | 70 | BEGIN_BATCH(4, 1); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 71 | OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE); |
| 72 | OUT_BATCH(0xffffffff); /* compare dword */ |
| 73 | OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER, |
| 74 | I915_GEM_DOMAIN_RENDER, 0); |
| 75 | OUT_BATCH(MI_NOOP); |
| 76 | ADVANCE_BATCH(); |
| 77 | } else { |
Chris Wilson | 10552b5 | 2014-08-30 11:44:51 +0100 | [diff] [blame^] | 78 | BEGIN_BATCH(4, 1); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 79 | OUT_BATCH(MI_FLUSH_DW | 1); |
| 80 | OUT_BATCH(0); /* reserved */ |
| 81 | OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER, |
| 82 | I915_GEM_DOMAIN_RENDER, 0); |
| 83 | OUT_BATCH(MI_NOOP | (1<<22) | (0xf)); |
| 84 | ADVANCE_BATCH(); |
| 85 | } |
| 86 | intel_batchbuffer_flush_on_ring(batch, ring); |
| 87 | } |
| 88 | |
| 89 | drm_intel_bo_map(target_buffer, 0); |
| 90 | // map to force waiting on rendering |
| 91 | drm_intel_bo_unmap(target_buffer); |
| 92 | } |
| 93 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 94 | igt_simple_main |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 95 | { |
| 96 | int fd; |
| 97 | int devid; |
| 98 | |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 99 | fd = drm_open_any(); |
| 100 | devid = intel_get_drm_devid(fd); |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 101 | gem_require_ring(fd, I915_EXEC_BLT); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 102 | |
| 103 | |
| 104 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
Daniel Vetter | f3c54d0 | 2013-09-25 14:36:59 +0200 | [diff] [blame] | 105 | igt_assert(bufmgr); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 106 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 107 | |
| 108 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
Daniel Vetter | f3c54d0 | 2013-09-25 14:36:59 +0200 | [diff] [blame] | 109 | igt_assert(batch); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 110 | |
| 111 | target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096); |
Daniel Vetter | f3c54d0 | 2013-09-25 14:36:59 +0200 | [diff] [blame] | 112 | igt_assert(target_buffer); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 113 | |
Xiang, Haihao | 0a413cd | 2013-04-23 15:06:41 +0800 | [diff] [blame] | 114 | store_dword_loop(fd); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 115 | |
| 116 | drm_intel_bo_unreference(target_buffer); |
| 117 | intel_batchbuffer_free(batch); |
| 118 | drm_intel_bufmgr_destroy(bufmgr); |
| 119 | |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 120 | close(fd); |
Daniel Vetter | 61b9806 | 2011-09-09 20:44:27 +0200 | [diff] [blame] | 121 | } |