blob: 06133b6e700296d573ab34da7f37d89ec4318df5 [file] [log] [blame]
Chia-I Wue09b5362014-08-07 09:25:14 +08001/*
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 Wu3ad3c542014-08-25 11:09:17 +080025#include "genhw/genhw.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080026#include "kmd/winsys.h"
Chia-I Wu34f45182014-08-19 14:02:59 +080027#include "cmd.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080028#include "dev.h"
Chia-I Wuc5438c22014-08-19 14:03:06 +080029#include "fence.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080030#include "queue.h"
31
Chia-I Wu94d2fba2014-08-25 11:38:08 +080032static 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 Wu3ad3c542014-08-25 11:09:17 +080050static 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 Wu9ae59c12014-08-07 10:08:49 +080094XGL_RESULT intel_queue_create(struct intel_dev *dev,
Chia-I Wucdcff732014-08-19 14:44:15 +080095 enum intel_gpu_engine_type engine,
Chia-I Wu9ae59c12014-08-07 10:08:49 +080096 struct intel_queue **queue_ret)
Chia-I Wue09b5362014-08-07 09:25:14 +080097{
98 struct intel_queue *queue;
Chia-I Wuc5438c22014-08-19 14:03:06 +080099 enum intel_ring_type ring;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800100 XGL_RESULT ret;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800101
Chia-I Wucdcff732014-08-19 14:44:15 +0800102 switch (engine) {
103 case INTEL_GPU_ENGINE_3D:
Chia-I Wuc5438c22014-08-19 14:03:06 +0800104 ring = INTEL_RING_RENDER;
105 break;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800106 default:
107 return XGL_ERROR_INVALID_VALUE;
108 break;
109 }
Chia-I Wue09b5362014-08-07 09:25:14 +0800110
Courtney Goeltzenleuchterfb4fb532014-08-14 09:35:21 -0600111 queue = (struct intel_queue *) intel_base_create(dev, sizeof(*queue),
Chia-I Wubbf2c932014-08-07 12:20:08 +0800112 dev->base.dbg, XGL_DBG_OBJECT_QUEUE, NULL, 0);
Chia-I Wue09b5362014-08-07 09:25:14 +0800113 if (!queue)
Chia-I Wu9ae59c12014-08-07 10:08:49 +0800114 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wue09b5362014-08-07 09:25:14 +0800115
Chia-I Wue09b5362014-08-07 09:25:14 +0800116 queue->dev = dev;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800117 queue->ring = ring;
Chia-I Wue09b5362014-08-07 09:25:14 +0800118
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800119 ret = queue_init_hw_and_bo(queue);
120 if (ret != XGL_SUCCESS) {
121 intel_queue_destroy(queue);
122 return ret;
123 }
124
Chia-I Wu9ae59c12014-08-07 10:08:49 +0800125 *queue_ret = queue;
126
127 return XGL_SUCCESS;
Chia-I Wue09b5362014-08-07 09:25:14 +0800128}
129
130void intel_queue_destroy(struct intel_queue *queue)
131{
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800132 if (queue->bo)
133 intel_bo_unreference(queue->bo);
Chia-I Wubbf2c932014-08-07 12:20:08 +0800134 intel_base_destroy(&queue->base);
Chia-I Wue09b5362014-08-07 09:25:14 +0800135}
136
137XGL_RESULT intel_queue_wait(struct intel_queue *queue, int64_t timeout)
138{
Chia-I Wue24c3292014-08-21 14:05:23 +0800139 struct intel_bo *bo = (queue->last_submitted_cmd) ?
140 intel_cmd_get_batch(queue->last_submitted_cmd, NULL) : NULL;
Chia-I Wue09b5362014-08-07 09:25:14 +0800141
Chia-I Wue24c3292014-08-21 14:05:23 +0800142 return (!bo || intel_bo_wait(bo, timeout) == 0) ?
Chia-I Wue09b5362014-08-07 09:25:14 +0800143 XGL_SUCCESS : XGL_ERROR_UNKNOWN;
144}
145
146XGL_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
158XGL_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 Wu251e7d92014-08-19 13:35:42 +0800165
166XGL_RESULT XGLAPI intelQueueSubmit(
Chia-I Wuc5438c22014-08-19 14:03:06 +0800167 XGL_QUEUE queue_,
Chia-I Wu251e7d92014-08-19 13:35:42 +0800168 XGL_UINT cmdBufferCount,
169 const XGL_CMD_BUFFER* pCmdBuffers,
170 XGL_UINT memRefCount,
171 const XGL_MEMORY_REF* pMemRefs,
Chia-I Wuc5438c22014-08-19 14:03:06 +0800172 XGL_FENCE fence_)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800173{
Chia-I Wuc5438c22014-08-19 14:03:06 +0800174 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 Wu94d2fba2014-08-25 11:38:08 +0800180 struct intel_bo *bo;
181 XGL_GPU_SIZE used;
182 XGL_RESULT ret;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800183
Chia-I Wu94d2fba2014-08-25 11:38:08 +0800184 bo = intel_cmd_get_batch(cmd, &used);
185 ret = queue_submit_bo(queue, bo, used);
186 queue->last_submitted_cmd = cmd;
187
Chia-I Wuc5438c22014-08-19 14:03:06 +0800188 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 Wu251e7d92014-08-19 13:35:42 +0800200}
201
202XGL_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
210XGL_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
226XGL_RESULT XGLAPI intelSignalQueueSemaphore(
227 XGL_QUEUE queue,
228 XGL_QUEUE_SEMAPHORE semaphore)
229{
230 return XGL_ERROR_UNAVAILABLE;
231}
232
233XGL_RESULT XGLAPI intelWaitQueueSemaphore(
234 XGL_QUEUE queue,
235 XGL_QUEUE_SEMAPHORE semaphore)
236{
237 return XGL_ERROR_UNAVAILABLE;
238}