Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +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 | |
| 25 | #ifndef CMD_PRIV_H |
| 26 | #define CMD_PRIV_H |
| 27 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 28 | #include "genhw/genhw.h" |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 29 | #include "dev.h" |
| 30 | #include "gpu.h" |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 31 | #include "cmd.h" |
| 32 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 33 | #define CMD_ASSERT(cmd, min_gen, max_gen) \ |
| 34 | INTEL_GPU_ASSERT((cmd)->dev->gpu, (min_gen), (max_gen)) |
| 35 | |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 36 | struct intel_cmd_reloc { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 37 | struct intel_cmd_writer *writer; |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 38 | 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 Wu | 9f03986 | 2014-08-20 15:39:56 +0800 | [diff] [blame] | 57 | static inline int cmd_gen(const struct intel_cmd *cmd) |
| 58 | { |
| 59 | return intel_gpu_gen(cmd->dev->gpu); |
| 60 | } |
| 61 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 62 | void cmd_writer_grow(struct intel_cmd *cmd, |
| 63 | struct intel_cmd_writer *writer); |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 64 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 65 | /** |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 66 | * Reserve \p len DWords and return a pointer to the reserved region for |
| 67 | * writing. |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 68 | */ |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 69 | static inline uint32_t *cmd_writer_ptr(struct intel_cmd *cmd, |
| 70 | struct intel_cmd_writer *writer, |
| 71 | XGL_UINT len) |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 72 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 73 | 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 Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 82 | * Add a reloc for the value at \p offset, relative to the current writer |
| 83 | * position. |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 84 | */ |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 85 | static 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 Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 91 | { |
| 92 | struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used]; |
| 93 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 94 | assert(cmd->reloc_used < cmd->reloc_count); |
| 95 | |
| 96 | reloc->writer = writer; |
| 97 | reloc->pos = writer->used + offset; |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 98 | 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 Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 107 | * Advance the writer position. |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 108 | */ |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 109 | static inline void cmd_writer_advance(struct intel_cmd *cmd, |
| 110 | struct intel_cmd_writer *writer, |
| 111 | XGL_UINT len) |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 112 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 113 | assert(writer->used + len <= writer->size); |
| 114 | writer->used += len; |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 118 | * Copy \p len DWords and advance. |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 119 | */ |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 120 | static 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 Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 123 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 124 | assert(writer->used + len <= writer->size); |
| 125 | memcpy((uint32_t *) writer->ptr_opaque + writer->used, |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 126 | vals, sizeof(uint32_t) * len); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 127 | writer->used += len; |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Patch the given \p pos. |
| 132 | */ |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 133 | static inline void cmd_writer_patch(struct intel_cmd *cmd, |
| 134 | struct intel_cmd_writer *writer, |
| 135 | XGL_UINT pos, uint32_t val) |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 136 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame^] | 137 | 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 | */ |
| 144 | static 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 | */ |
| 156 | static 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 | */ |
| 167 | static 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 | */ |
| 182 | static 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 Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 192 | } |
| 193 | |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 194 | #endif /* CMD_PRIV_H */ |