blob: c4f2efbaa7a32a18ffbf77cfdac0c657003d8cb5 [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 Wu32710d72014-08-20 16:05:22 +080028#include "dev.h"
29#include "gpu.h"
Chia-I Wu00a23b22014-08-20 15:28:08 +080030#include "cmd.h"
31
Chia-I Wu32710d72014-08-20 16:05:22 +080032#define CMD_ASSERT(cmd, min_gen, max_gen) \
33 INTEL_GPU_ASSERT((cmd)->dev->gpu, (min_gen), (max_gen))
34
Chia-I Wu958d1b72014-08-21 11:28:11 +080035struct intel_cmd_reloc {
36 XGL_UINT pos;
37
38 uint32_t val;
39 const struct intel_mem *mem;
40
41 /*
42 * With application state tracking promised by XGL, we should be able to
43 * set
44 *
45 * I915_EXEC_NO_RELOC
46 * I915_EXEC_HANDLE_LUT
47 * I915_EXEC_IS_PINNED
48 *
49 * once we figure them out.
50 */
51 uint16_t read_domains;
52 uint16_t write_domain;
53};
54
Chia-I Wu9f039862014-08-20 15:39:56 +080055static inline int cmd_gen(const struct intel_cmd *cmd)
56{
57 return intel_gpu_gen(cmd->dev->gpu);
58}
59
Chia-I Wu00a23b22014-08-20 15:28:08 +080060void cmd_grow(struct intel_cmd *cmd);
61
Chia-I Wu32710d72014-08-20 16:05:22 +080062/**
63 * Reserve \p len DWords for writing.
64 */
65static inline void cmd_reserve(struct intel_cmd *cmd, XGL_UINT len)
66{
67 if (cmd->used + len > cmd->size)
68 cmd_grow(cmd);
69 assert(cmd->used + len <= cmd->size);
70}
71
72/**
73 * Return a pointer of \p len DWords for writing.
74 */
75static inline uint32_t *cmd_ptr(struct intel_cmd *cmd, XGL_UINT len)
76{
77 cmd_reserve(cmd, len);
78 return &((uint32_t *) cmd->ptr_opaque)[cmd->used];
79}
80
81/**
Chia-I Wu343b1372014-08-20 16:39:20 +080082 * Add a reloc for the value at \p offset.
83 */
84static inline void cmd_add_reloc(struct intel_cmd *cmd, XGL_INT offset,
Chia-I Wu958d1b72014-08-21 11:28:11 +080085 uint32_t val, const struct intel_mem *mem,
Chia-I Wu343b1372014-08-20 16:39:20 +080086 uint16_t read_domains, uint16_t write_domain)
87{
88 struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used];
89
90 reloc->pos = cmd->used + offset;
91 reloc->val = val;
92 reloc->mem = mem;
93 reloc->read_domains = read_domains;
94 reloc->write_domain = write_domain;
95
96 cmd->reloc_used++;
97}
98
99/**
Chia-I Wu32710d72014-08-20 16:05:22 +0800100 * Advance without writing.
101 */
102static inline void cmd_advance(struct intel_cmd *cmd, XGL_UINT len)
103{
104 assert(cmd->used + len <= cmd->size);
105 cmd->used += len;
106}
107
108/**
Chia-I Wu32710d72014-08-20 16:05:22 +0800109 * Write a DWord and advance.
110 */
111static inline void cmd_write(struct intel_cmd *cmd, uint32_t val)
112{
113 assert(cmd->used < cmd->size);
114 ((uint32_t *) cmd->ptr_opaque)[cmd->used++] = val;
115}
116
Chia-I Wu343b1372014-08-20 16:39:20 +0800117/**
118 * Write \p len DWords and advance.
119 */
120static inline void cmd_write_n(struct intel_cmd *cmd,
121 const uint32_t *vals, XGL_UINT len)
122{
123 assert(cmd->used + len <= cmd->size);
124 memcpy((uint32_t *) cmd->ptr_opaque + cmd->used,
125 vals, sizeof(uint32_t) * len);
126 cmd->used += len;
127}
128
129/**
130 * Write a reloc and advance.
131 */
132static inline void cmd_write_r(struct intel_cmd *cmd, uint32_t val,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800133 const struct intel_mem *mem,
Chia-I Wu343b1372014-08-20 16:39:20 +0800134 uint16_t read_domains, uint16_t write_domain)
135{
136 cmd_add_reloc(cmd, 0, val, mem, read_domains, write_domain);
137 cmd->used++;
138}
139
140/**
141 * Patch the given \p pos.
142 */
143static inline void cmd_patch(struct intel_cmd *cmd,
144 XGL_UINT pos, uint32_t val)
145{
146 assert(pos < cmd->used);
147 ((uint32_t *) cmd->ptr_opaque)[pos] = val;
148}
149
Chia-I Wu00a23b22014-08-20 15:28:08 +0800150#endif /* CMD_PRIV_H */