blob: ef8468581862c4eb4c82d495d0e7d3da950be5a9 [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
25#include "kmd/winsys.h"
Chia-I Wu34f45182014-08-19 14:02:59 +080026#include "cmd.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080027#include "dev.h"
Chia-I Wuc5438c22014-08-19 14:03:06 +080028#include "fence.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080029#include "queue.h"
30
Chia-I Wu9ae59c12014-08-07 10:08:49 +080031XGL_RESULT intel_queue_create(struct intel_dev *dev,
32 XGL_QUEUE_TYPE type,
33 struct intel_queue **queue_ret)
Chia-I Wue09b5362014-08-07 09:25:14 +080034{
35 struct intel_queue *queue;
Chia-I Wuc5438c22014-08-19 14:03:06 +080036 enum intel_ring_type ring;
37
38 switch (type) {
39 case XGL_QUEUE_TYPE_GRAPHICS:
40 case XGL_QUEUE_TYPE_COMPUTE:
41 ring = INTEL_RING_RENDER;
42 break;
43 case XGL_QUEUE_TYPE_DMA:
44 ring = INTEL_RING_BLT;
45 break;
46 default:
47 return XGL_ERROR_INVALID_VALUE;
48 break;
49 }
Chia-I Wue09b5362014-08-07 09:25:14 +080050
Courtney Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060051 queue = (struct intel_queue *) intel_base_create(dev, sizeof(*queue),
Chia-I Wubbf2c932014-08-07 12:20:08 +080052 dev->base.dbg, XGL_DBG_OBJECT_QUEUE, NULL, 0);
Chia-I Wue09b5362014-08-07 09:25:14 +080053 if (!queue)
Chia-I Wu9ae59c12014-08-07 10:08:49 +080054 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wue09b5362014-08-07 09:25:14 +080055
Chia-I Wue09b5362014-08-07 09:25:14 +080056 queue->dev = dev;
Chia-I Wuc5438c22014-08-19 14:03:06 +080057 queue->ring = ring;
Chia-I Wue09b5362014-08-07 09:25:14 +080058
Chia-I Wu9ae59c12014-08-07 10:08:49 +080059 *queue_ret = queue;
60
61 return XGL_SUCCESS;
Chia-I Wue09b5362014-08-07 09:25:14 +080062}
63
64void intel_queue_destroy(struct intel_queue *queue)
65{
Chia-I Wubbf2c932014-08-07 12:20:08 +080066 intel_base_destroy(&queue->base);
Chia-I Wue09b5362014-08-07 09:25:14 +080067}
68
69XGL_RESULT intel_queue_wait(struct intel_queue *queue, int64_t timeout)
70{
Chia-I Wu34f45182014-08-19 14:02:59 +080071 struct intel_cmd *cmd = queue->last_submitted_cmd;
Chia-I Wue09b5362014-08-07 09:25:14 +080072
Chia-I Wu34f45182014-08-19 14:02:59 +080073 return (!cmd || intel_bo_wait(cmd->bo, timeout) == 0) ?
Chia-I Wue09b5362014-08-07 09:25:14 +080074 XGL_SUCCESS : XGL_ERROR_UNKNOWN;
75}
76
Chia-I Wuc5438c22014-08-19 14:03:06 +080077XGL_RESULT intel_queue_submit(struct intel_queue *queue,
78 struct intel_cmd *cmd)
79{
80 struct intel_winsys *winsys = queue->dev->winsys;
81 int err;
82
83 err = intel_winsys_submit_bo(winsys, queue->ring,
84 cmd->bo, cmd->used * sizeof(uint32_t), 0);
85
86 queue->last_submitted_cmd = cmd;
87
88 return (err) ? XGL_ERROR_UNKNOWN : XGL_SUCCESS;
89}
90
Chia-I Wue09b5362014-08-07 09:25:14 +080091XGL_RESULT XGLAPI intelQueueSetGlobalMemReferences(
92 XGL_QUEUE queue,
93 XGL_UINT memRefCount,
94 const XGL_MEMORY_REF* pMemRefs)
95{
96 /*
97 * The winwys maintains the list of memory references. These are ignored
98 * until we move away from the winsys.
99 */
100 return XGL_SUCCESS;
101}
102
103XGL_RESULT XGLAPI intelQueueWaitIdle(
104 XGL_QUEUE queue_)
105{
106 struct intel_queue *queue = intel_queue(queue_);
107
108 return intel_queue_wait(queue, -1);
109}
Chia-I Wu251e7d92014-08-19 13:35:42 +0800110
111XGL_RESULT XGLAPI intelQueueSubmit(
Chia-I Wuc5438c22014-08-19 14:03:06 +0800112 XGL_QUEUE queue_,
Chia-I Wu251e7d92014-08-19 13:35:42 +0800113 XGL_UINT cmdBufferCount,
114 const XGL_CMD_BUFFER* pCmdBuffers,
115 XGL_UINT memRefCount,
116 const XGL_MEMORY_REF* pMemRefs,
Chia-I Wuc5438c22014-08-19 14:03:06 +0800117 XGL_FENCE fence_)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800118{
Chia-I Wuc5438c22014-08-19 14:03:06 +0800119 struct intel_queue *queue = intel_queue(queue_);
120 XGL_RESULT ret = XGL_SUCCESS;
121 XGL_UINT i;
122
123 for (i = 0; i < cmdBufferCount; i++) {
124 struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]);
125
126 ret = intel_queue_submit(queue, cmd);
127 if (ret != XGL_SUCCESS)
128 break;
129 }
130
131 if (ret == XGL_SUCCESS && fence_ != XGL_NULL_HANDLE) {
132 struct intel_fence *fence = intel_fence(fence_);
133 intel_fence_set_cmd(fence, queue->last_submitted_cmd);
134 }
135
136 /* XGL_MEMORY_REFs are ignored as the winsys already knows them */
137
138 return ret;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800139}
140
141XGL_RESULT XGLAPI intelOpenSharedQueueSemaphore(
142 XGL_DEVICE device,
143 const XGL_QUEUE_SEMAPHORE_OPEN_INFO* pOpenInfo,
144 XGL_QUEUE_SEMAPHORE* pSemaphore)
145{
146 return XGL_ERROR_UNAVAILABLE;
147}
148
149XGL_RESULT XGLAPI intelCreateQueueSemaphore(
150 XGL_DEVICE device,
151 const XGL_QUEUE_SEMAPHORE_CREATE_INFO* pCreateInfo,
152 XGL_QUEUE_SEMAPHORE* pSemaphore)
153{
154 /*
155 * We want to find an unused semaphore register and initialize it. Signal
156 * will increment the register. Wait will atomically decrement it and
157 * block if the value is zero, or a large constant N if we do not want to
158 * go negative.
159 *
160 * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility.
161 */
162 return XGL_ERROR_UNAVAILABLE;
163}
164
165XGL_RESULT XGLAPI intelSignalQueueSemaphore(
166 XGL_QUEUE queue,
167 XGL_QUEUE_SEMAPHORE semaphore)
168{
169 return XGL_ERROR_UNAVAILABLE;
170}
171
172XGL_RESULT XGLAPI intelWaitQueueSemaphore(
173 XGL_QUEUE queue,
174 XGL_QUEUE_SEMAPHORE semaphore)
175{
176 return XGL_ERROR_UNAVAILABLE;
177}