Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 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 |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions 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 NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 25 | #include "genhw/genhw.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 26 | #include "kmd/winsys.h" |
Chia-I Wu | 34f4518 | 2014-08-19 14:02:59 +0800 | [diff] [blame] | 27 | #include "cmd.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 28 | #include "dev.h" |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 29 | #include "fence.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 30 | #include "queue.h" |
| 31 | |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 32 | static XGL_RESULT queue_submit_bo(struct intel_queue *queue, |
| 33 | struct intel_bo *bo, |
| 34 | XGL_GPU_SIZE used) |
| 35 | { |
| 36 | struct intel_winsys *winsys = queue->dev->winsys; |
| 37 | int err; |
| 38 | |
| 39 | if (intel_debug & INTEL_DEBUG_BATCH) |
| 40 | intel_winsys_decode_bo(winsys, bo, used); |
| 41 | |
| 42 | if (intel_debug & INTEL_DEBUG_NOHW) |
| 43 | err = 0; |
| 44 | else |
| 45 | err = intel_winsys_submit_bo(winsys, queue->ring, bo, used, 0); |
| 46 | |
| 47 | return (err) ? XGL_ERROR_UNKNOWN : XGL_SUCCESS; |
| 48 | } |
| 49 | |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 50 | static XGL_RESULT queue_init_hw_and_bo(struct intel_queue *queue) |
| 51 | { |
| 52 | struct intel_winsys *winsys = queue->dev->winsys; |
| 53 | struct intel_bo *bo; |
| 54 | uint32_t *cmd; |
| 55 | XGL_UINT used; |
| 56 | XGL_RESULT ret; |
| 57 | |
| 58 | bo = intel_winsys_alloc_buffer(winsys, |
| 59 | "queue buffer", 4096, INTEL_DOMAIN_CPU); |
| 60 | if (!bo) |
| 61 | return XGL_ERROR_OUT_OF_GPU_MEMORY; |
| 62 | |
| 63 | cmd = (uint32_t *) intel_bo_map(bo, true); |
| 64 | if (!cmd) { |
| 65 | intel_bo_unreference(bo); |
| 66 | return XGL_ERROR_MEMORY_MAP_FAILED; |
| 67 | } |
| 68 | |
| 69 | used = 0; |
| 70 | |
| 71 | /* disable SIP and VF statistics */ |
| 72 | cmd[used++] = GEN_RENDER_CMD(COMMON, GEN6, STATE_SIP); |
| 73 | cmd[used++] = 0; |
| 74 | cmd[used++] = GEN_RENDER_CMD(SINGLE_DW, GEN6, 3DSTATE_VF_STATISTICS); |
| 75 | |
| 76 | cmd[used++] = GEN_MI_CMD(MI_BATCH_BUFFER_END); |
| 77 | if (used & 1) |
| 78 | cmd[used++] = GEN_MI_CMD(MI_NOOP); |
| 79 | |
| 80 | intel_bo_unmap(bo); |
| 81 | |
| 82 | ret = queue_submit_bo(queue, bo, sizeof(cmd[0]) * used); |
| 83 | if (ret != XGL_SUCCESS) { |
| 84 | intel_bo_unreference(bo); |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | /* reuse the bo for atomic counters */ |
| 89 | queue->bo = bo; |
| 90 | |
| 91 | return XGL_SUCCESS; |
| 92 | } |
| 93 | |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 94 | XGL_RESULT intel_queue_create(struct intel_dev *dev, |
Chia-I Wu | cdcff73 | 2014-08-19 14:44:15 +0800 | [diff] [blame] | 95 | enum intel_gpu_engine_type engine, |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 96 | struct intel_queue **queue_ret) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 97 | { |
| 98 | struct intel_queue *queue; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 99 | enum intel_ring_type ring; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 100 | XGL_RESULT ret; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 101 | |
Chia-I Wu | cdcff73 | 2014-08-19 14:44:15 +0800 | [diff] [blame] | 102 | switch (engine) { |
| 103 | case INTEL_GPU_ENGINE_3D: |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 104 | ring = INTEL_RING_RENDER; |
| 105 | break; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 106 | default: |
| 107 | return XGL_ERROR_INVALID_VALUE; |
| 108 | break; |
| 109 | } |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 110 | |
Courtney Goeltzenleuchter | fb4fb53 | 2014-08-14 09:35:21 -0600 | [diff] [blame] | 111 | queue = (struct intel_queue *) intel_base_create(dev, sizeof(*queue), |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 112 | dev->base.dbg, XGL_DBG_OBJECT_QUEUE, NULL, 0); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 113 | if (!queue) |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 114 | return XGL_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 115 | |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 116 | queue->dev = dev; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 117 | queue->ring = ring; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 118 | |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 119 | ret = queue_init_hw_and_bo(queue); |
| 120 | if (ret != XGL_SUCCESS) { |
| 121 | intel_queue_destroy(queue); |
| 122 | return ret; |
| 123 | } |
| 124 | |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 125 | *queue_ret = queue; |
| 126 | |
| 127 | return XGL_SUCCESS; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void intel_queue_destroy(struct intel_queue *queue) |
| 131 | { |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 132 | if (queue->bo) |
| 133 | intel_bo_unreference(queue->bo); |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 134 | intel_base_destroy(&queue->base); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | XGL_RESULT intel_queue_wait(struct intel_queue *queue, int64_t timeout) |
| 138 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 139 | struct intel_bo *bo = (queue->last_submitted_cmd) ? |
| 140 | intel_cmd_get_batch(queue->last_submitted_cmd, NULL) : NULL; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 141 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 142 | return (!bo || intel_bo_wait(bo, timeout) == 0) ? |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 143 | XGL_SUCCESS : XGL_ERROR_UNKNOWN; |
| 144 | } |
| 145 | |
| 146 | XGL_RESULT XGLAPI intelQueueSetGlobalMemReferences( |
| 147 | XGL_QUEUE queue, |
| 148 | XGL_UINT memRefCount, |
| 149 | const XGL_MEMORY_REF* pMemRefs) |
| 150 | { |
| 151 | /* |
| 152 | * The winwys maintains the list of memory references. These are ignored |
| 153 | * until we move away from the winsys. |
| 154 | */ |
| 155 | return XGL_SUCCESS; |
| 156 | } |
| 157 | |
| 158 | XGL_RESULT XGLAPI intelQueueWaitIdle( |
| 159 | XGL_QUEUE queue_) |
| 160 | { |
| 161 | struct intel_queue *queue = intel_queue(queue_); |
| 162 | |
| 163 | return intel_queue_wait(queue, -1); |
| 164 | } |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 165 | |
| 166 | XGL_RESULT XGLAPI intelQueueSubmit( |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 167 | XGL_QUEUE queue_, |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 168 | XGL_UINT cmdBufferCount, |
| 169 | const XGL_CMD_BUFFER* pCmdBuffers, |
| 170 | XGL_UINT memRefCount, |
| 171 | const XGL_MEMORY_REF* pMemRefs, |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 172 | XGL_FENCE fence_) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 173 | { |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 174 | struct intel_queue *queue = intel_queue(queue_); |
| 175 | XGL_RESULT ret = XGL_SUCCESS; |
| 176 | XGL_UINT i; |
| 177 | |
| 178 | for (i = 0; i < cmdBufferCount; i++) { |
| 179 | struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]); |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 180 | struct intel_bo *bo; |
| 181 | XGL_GPU_SIZE used; |
| 182 | XGL_RESULT ret; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 183 | |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 184 | bo = intel_cmd_get_batch(cmd, &used); |
| 185 | ret = queue_submit_bo(queue, bo, used); |
| 186 | queue->last_submitted_cmd = cmd; |
| 187 | |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 188 | if (ret != XGL_SUCCESS) |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | if (ret == XGL_SUCCESS && fence_ != XGL_NULL_HANDLE) { |
| 193 | struct intel_fence *fence = intel_fence(fence_); |
| 194 | intel_fence_set_cmd(fence, queue->last_submitted_cmd); |
| 195 | } |
| 196 | |
| 197 | /* XGL_MEMORY_REFs are ignored as the winsys already knows them */ |
| 198 | |
| 199 | return ret; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | XGL_RESULT XGLAPI intelOpenSharedQueueSemaphore( |
| 203 | XGL_DEVICE device, |
| 204 | const XGL_QUEUE_SEMAPHORE_OPEN_INFO* pOpenInfo, |
| 205 | XGL_QUEUE_SEMAPHORE* pSemaphore) |
| 206 | { |
| 207 | return XGL_ERROR_UNAVAILABLE; |
| 208 | } |
| 209 | |
| 210 | XGL_RESULT XGLAPI intelCreateQueueSemaphore( |
| 211 | XGL_DEVICE device, |
| 212 | const XGL_QUEUE_SEMAPHORE_CREATE_INFO* pCreateInfo, |
| 213 | XGL_QUEUE_SEMAPHORE* pSemaphore) |
| 214 | { |
| 215 | /* |
| 216 | * We want to find an unused semaphore register and initialize it. Signal |
| 217 | * will increment the register. Wait will atomically decrement it and |
| 218 | * block if the value is zero, or a large constant N if we do not want to |
| 219 | * go negative. |
| 220 | * |
| 221 | * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility. |
| 222 | */ |
| 223 | return XGL_ERROR_UNAVAILABLE; |
| 224 | } |
| 225 | |
| 226 | XGL_RESULT XGLAPI intelSignalQueueSemaphore( |
| 227 | XGL_QUEUE queue, |
| 228 | XGL_QUEUE_SEMAPHORE semaphore) |
| 229 | { |
| 230 | return XGL_ERROR_UNAVAILABLE; |
| 231 | } |
| 232 | |
| 233 | XGL_RESULT XGLAPI intelWaitQueueSemaphore( |
| 234 | XGL_QUEUE queue, |
| 235 | XGL_QUEUE_SEMAPHORE semaphore) |
| 236 | { |
| 237 | return XGL_ERROR_UNAVAILABLE; |
| 238 | } |