blob: 23aa5efb060500b6a540027f89dc260377179d15 [file] [log] [blame]
Chia-I Wu00a23b22014-08-20 15:28:08 +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#ifndef CMD_PRIV_H
26#define CMD_PRIV_H
27
Chia-I Wue24c3292014-08-21 14:05:23 +080028#include "genhw/genhw.h"
Chia-I Wu32710d72014-08-20 16:05:22 +080029#include "dev.h"
30#include "gpu.h"
Chia-I Wu00a23b22014-08-20 15:28:08 +080031#include "cmd.h"
32
Chia-I Wu32710d72014-08-20 16:05:22 +080033#define CMD_ASSERT(cmd, min_gen, max_gen) \
34 INTEL_GPU_ASSERT((cmd)->dev->gpu, (min_gen), (max_gen))
35
Chia-I Wu958d1b72014-08-21 11:28:11 +080036struct intel_cmd_reloc {
Chia-I Wue24c3292014-08-21 14:05:23 +080037 struct intel_cmd_writer *writer;
Chia-I Wu958d1b72014-08-21 11:28:11 +080038 XGL_UINT pos;
39
40 uint32_t val;
41 const struct intel_mem *mem;
42
43 /*
44 * With application state tracking promised by XGL, we should be able to
45 * set
46 *
47 * I915_EXEC_NO_RELOC
48 * I915_EXEC_HANDLE_LUT
49 * I915_EXEC_IS_PINNED
50 *
51 * once we figure them out.
52 */
53 uint16_t read_domains;
54 uint16_t write_domain;
55};
56
Chia-I Wu9f039862014-08-20 15:39:56 +080057static inline int cmd_gen(const struct intel_cmd *cmd)
58{
59 return intel_gpu_gen(cmd->dev->gpu);
60}
61
Chia-I Wue24c3292014-08-21 14:05:23 +080062void cmd_writer_grow(struct intel_cmd *cmd,
63 struct intel_cmd_writer *writer);
Chia-I Wu00a23b22014-08-20 15:28:08 +080064
Chia-I Wu32710d72014-08-20 16:05:22 +080065/**
Chia-I Wue24c3292014-08-21 14:05:23 +080066 * Reserve \p len DWords and return a pointer to the reserved region for
67 * writing.
Chia-I Wu32710d72014-08-20 16:05:22 +080068 */
Chia-I Wue24c3292014-08-21 14:05:23 +080069static inline uint32_t *cmd_writer_ptr(struct intel_cmd *cmd,
70 struct intel_cmd_writer *writer,
71 XGL_UINT len)
Chia-I Wu32710d72014-08-20 16:05:22 +080072{
Chia-I Wue24c3292014-08-21 14:05:23 +080073 if (writer->used + len > writer->size)
74 cmd_writer_grow(cmd, writer);
75
76 assert(writer->used + len <= writer->size);
77
78 return &((uint32_t *) writer->ptr_opaque)[writer->used];
Chia-I Wu32710d72014-08-20 16:05:22 +080079}
80
81/**
Chia-I Wue24c3292014-08-21 14:05:23 +080082 * Add a reloc for the value at \p offset, relative to the current writer
83 * position.
Chia-I Wu32710d72014-08-20 16:05:22 +080084 */
Chia-I Wue24c3292014-08-21 14:05:23 +080085static inline void cmd_writer_add_reloc(struct intel_cmd *cmd,
86 struct intel_cmd_writer *writer,
87 XGL_INT offset, uint32_t val,
88 const struct intel_mem *mem,
89 uint16_t read_domains,
90 uint16_t write_domain)
Chia-I Wu343b1372014-08-20 16:39:20 +080091{
92 struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used];
93
Chia-I Wue24c3292014-08-21 14:05:23 +080094 assert(cmd->reloc_used < cmd->reloc_count);
95
96 reloc->writer = writer;
97 reloc->pos = writer->used + offset;
Chia-I Wu343b1372014-08-20 16:39:20 +080098 reloc->val = val;
99 reloc->mem = mem;
100 reloc->read_domains = read_domains;
101 reloc->write_domain = write_domain;
102
103 cmd->reloc_used++;
104}
105
106/**
Chia-I Wue24c3292014-08-21 14:05:23 +0800107 * Advance the writer position.
Chia-I Wu32710d72014-08-20 16:05:22 +0800108 */
Chia-I Wue24c3292014-08-21 14:05:23 +0800109static inline void cmd_writer_advance(struct intel_cmd *cmd,
110 struct intel_cmd_writer *writer,
111 XGL_UINT len)
Chia-I Wu32710d72014-08-20 16:05:22 +0800112{
Chia-I Wue24c3292014-08-21 14:05:23 +0800113 assert(writer->used + len <= writer->size);
114 writer->used += len;
Chia-I Wu32710d72014-08-20 16:05:22 +0800115}
116
117/**
Chia-I Wue24c3292014-08-21 14:05:23 +0800118 * Copy \p len DWords and advance.
Chia-I Wu32710d72014-08-20 16:05:22 +0800119 */
Chia-I Wue24c3292014-08-21 14:05:23 +0800120static inline void cmd_writer_copy(struct intel_cmd *cmd,
121 struct intel_cmd_writer *writer,
122 const uint32_t *vals, XGL_UINT len)
Chia-I Wu32710d72014-08-20 16:05:22 +0800123{
Chia-I Wue24c3292014-08-21 14:05:23 +0800124 assert(writer->used + len <= writer->size);
125 memcpy((uint32_t *) writer->ptr_opaque + writer->used,
Chia-I Wu343b1372014-08-20 16:39:20 +0800126 vals, sizeof(uint32_t) * len);
Chia-I Wue24c3292014-08-21 14:05:23 +0800127 writer->used += len;
Chia-I Wu343b1372014-08-20 16:39:20 +0800128}
129
130/**
131 * Patch the given \p pos.
132 */
Chia-I Wue24c3292014-08-21 14:05:23 +0800133static inline void cmd_writer_patch(struct intel_cmd *cmd,
134 struct intel_cmd_writer *writer,
135 XGL_UINT pos, uint32_t val)
Chia-I Wu343b1372014-08-20 16:39:20 +0800136{
Chia-I Wue24c3292014-08-21 14:05:23 +0800137 assert(pos < writer->used);
138 ((uint32_t *) writer->ptr_opaque)[pos] = val;
139}
140
141/**
142 * Reserve \p len DWords in the batch buffer for writing.
143 */
144static inline void cmd_batch_reserve(struct intel_cmd *cmd, XGL_UINT len)
145{
146 struct intel_cmd_writer *writer = &cmd->batch;
147
148 if (writer->used + len > writer->size)
149 cmd_writer_grow(cmd, writer);
150 assert(writer->used + len <= writer->size);
151}
152
153/**
154 * Write a DWord to the batch buffer and advance.
155 */
156static inline void cmd_batch_write(struct intel_cmd *cmd, uint32_t val)
157{
158 struct intel_cmd_writer *writer = &cmd->batch;
159
160 assert(writer->used < writer->size);
161 ((uint32_t *) writer->ptr_opaque)[writer->used++] = val;
162}
163
164/**
165 * Add a reloc for the batch buffer and advance.
166 */
167static inline void cmd_batch_reloc(struct intel_cmd *cmd,
168 uint32_t val, const struct intel_mem *mem,
169 uint16_t read_domains,
170 uint16_t write_domain)
171{
172 struct intel_cmd_writer *writer = &cmd->batch;
173
174 cmd_writer_add_reloc(cmd, writer, 0, val,
175 mem, read_domains, write_domain);
176 writer->used++;
177}
178
179/**
180 * End the batch buffer.
181 */
182static inline void cmd_batch_end(struct intel_cmd *cmd)
183{
184 if (cmd->batch.used & 1) {
185 cmd_batch_reserve(cmd, 1);
186 cmd_batch_write(cmd, GEN_MI_CMD(MI_BATCH_BUFFER_END));
187 } else {
188 cmd_batch_reserve(cmd, 2);
189 cmd_batch_write(cmd, GEN_MI_CMD(MI_BATCH_BUFFER_END));
190 cmd_batch_write(cmd, GEN_MI_CMD(MI_NOOP));
191 }
Chia-I Wu343b1372014-08-20 16:39:20 +0800192}
193
Chia-I Wu00a23b22014-08-20 15:28:08 +0800194#endif /* CMD_PRIV_H */