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 | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 28 | #include "dev.h" |
| 29 | #include "gpu.h" |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 30 | #include "cmd.h" |
| 31 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 32 | #define CMD_ASSERT(cmd, min_gen, max_gen) \ |
| 33 | INTEL_GPU_ASSERT((cmd)->dev->gpu, (min_gen), (max_gen)) |
| 34 | |
Chia-I Wu | 9f03986 | 2014-08-20 15:39:56 +0800 | [diff] [blame^] | 35 | static inline int cmd_gen(const struct intel_cmd *cmd) |
| 36 | { |
| 37 | return intel_gpu_gen(cmd->dev->gpu); |
| 38 | } |
| 39 | |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 40 | void cmd_grow(struct intel_cmd *cmd); |
| 41 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 42 | /** |
| 43 | * Reserve \p len DWords for writing. |
| 44 | */ |
| 45 | static inline void cmd_reserve(struct intel_cmd *cmd, XGL_UINT len) |
| 46 | { |
| 47 | if (cmd->used + len > cmd->size) |
| 48 | cmd_grow(cmd); |
| 49 | assert(cmd->used + len <= cmd->size); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Return a pointer of \p len DWords for writing. |
| 54 | */ |
| 55 | static inline uint32_t *cmd_ptr(struct intel_cmd *cmd, XGL_UINT len) |
| 56 | { |
| 57 | cmd_reserve(cmd, len); |
| 58 | return &((uint32_t *) cmd->ptr_opaque)[cmd->used]; |
| 59 | } |
| 60 | |
| 61 | /** |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 62 | * Add a reloc for the value at \p offset. |
| 63 | */ |
| 64 | static inline void cmd_add_reloc(struct intel_cmd *cmd, XGL_INT offset, |
| 65 | uint32_t val, struct intel_mem *mem, |
| 66 | uint16_t read_domains, uint16_t write_domain) |
| 67 | { |
| 68 | struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used]; |
| 69 | |
| 70 | reloc->pos = cmd->used + offset; |
| 71 | reloc->val = val; |
| 72 | reloc->mem = mem; |
| 73 | reloc->read_domains = read_domains; |
| 74 | reloc->write_domain = write_domain; |
| 75 | |
| 76 | cmd->reloc_used++; |
| 77 | } |
| 78 | |
| 79 | /** |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 80 | * Advance without writing. |
| 81 | */ |
| 82 | static inline void cmd_advance(struct intel_cmd *cmd, XGL_UINT len) |
| 83 | { |
| 84 | assert(cmd->used + len <= cmd->size); |
| 85 | cmd->used += len; |
| 86 | } |
| 87 | |
| 88 | /** |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 89 | * Write a DWord and advance. |
| 90 | */ |
| 91 | static inline void cmd_write(struct intel_cmd *cmd, uint32_t val) |
| 92 | { |
| 93 | assert(cmd->used < cmd->size); |
| 94 | ((uint32_t *) cmd->ptr_opaque)[cmd->used++] = val; |
| 95 | } |
| 96 | |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 97 | /** |
| 98 | * Write \p len DWords and advance. |
| 99 | */ |
| 100 | static inline void cmd_write_n(struct intel_cmd *cmd, |
| 101 | const uint32_t *vals, XGL_UINT len) |
| 102 | { |
| 103 | assert(cmd->used + len <= cmd->size); |
| 104 | memcpy((uint32_t *) cmd->ptr_opaque + cmd->used, |
| 105 | vals, sizeof(uint32_t) * len); |
| 106 | cmd->used += len; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Write a reloc and advance. |
| 111 | */ |
| 112 | static inline void cmd_write_r(struct intel_cmd *cmd, uint32_t val, |
| 113 | struct intel_mem *mem, |
| 114 | uint16_t read_domains, uint16_t write_domain) |
| 115 | { |
| 116 | cmd_add_reloc(cmd, 0, val, mem, read_domains, write_domain); |
| 117 | cmd->used++; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Patch the given \p pos. |
| 122 | */ |
| 123 | static inline void cmd_patch(struct intel_cmd *cmd, |
| 124 | XGL_UINT pos, uint32_t val) |
| 125 | { |
| 126 | assert(pos < cmd->used); |
| 127 | ((uint32_t *) cmd->ptr_opaque)[pos] = val; |
| 128 | } |
| 129 | |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 130 | #endif /* CMD_PRIV_H */ |