blob: 1c1c2e20b3f18c23a0c08a3e129579ba7f499d18 [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 Wu00a23b22014-08-20 15:28:08 +080035void cmd_grow(struct intel_cmd *cmd);
36
Chia-I Wu32710d72014-08-20 16:05:22 +080037/**
38 * Reserve \p len DWords for writing.
39 */
40static inline void cmd_reserve(struct intel_cmd *cmd, XGL_UINT len)
41{
42 if (cmd->used + len > cmd->size)
43 cmd_grow(cmd);
44 assert(cmd->used + len <= cmd->size);
45}
46
47/**
48 * Return a pointer of \p len DWords for writing.
49 */
50static inline uint32_t *cmd_ptr(struct intel_cmd *cmd, XGL_UINT len)
51{
52 cmd_reserve(cmd, len);
53 return &((uint32_t *) cmd->ptr_opaque)[cmd->used];
54}
55
56/**
Chia-I Wu343b1372014-08-20 16:39:20 +080057 * Add a reloc for the value at \p offset.
58 */
59static inline void cmd_add_reloc(struct intel_cmd *cmd, XGL_INT offset,
60 uint32_t val, struct intel_mem *mem,
61 uint16_t read_domains, uint16_t write_domain)
62{
63 struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used];
64
65 reloc->pos = cmd->used + offset;
66 reloc->val = val;
67 reloc->mem = mem;
68 reloc->read_domains = read_domains;
69 reloc->write_domain = write_domain;
70
71 cmd->reloc_used++;
72}
73
74/**
Chia-I Wu32710d72014-08-20 16:05:22 +080075 * Advance without writing.
76 */
77static inline void cmd_advance(struct intel_cmd *cmd, XGL_UINT len)
78{
79 assert(cmd->used + len <= cmd->size);
80 cmd->used += len;
81}
82
83/**
Chia-I Wu32710d72014-08-20 16:05:22 +080084 * Write a DWord and advance.
85 */
86static inline void cmd_write(struct intel_cmd *cmd, uint32_t val)
87{
88 assert(cmd->used < cmd->size);
89 ((uint32_t *) cmd->ptr_opaque)[cmd->used++] = val;
90}
91
Chia-I Wu343b1372014-08-20 16:39:20 +080092/**
93 * Write \p len DWords and advance.
94 */
95static inline void cmd_write_n(struct intel_cmd *cmd,
96 const uint32_t *vals, XGL_UINT len)
97{
98 assert(cmd->used + len <= cmd->size);
99 memcpy((uint32_t *) cmd->ptr_opaque + cmd->used,
100 vals, sizeof(uint32_t) * len);
101 cmd->used += len;
102}
103
104/**
105 * Write a reloc and advance.
106 */
107static inline void cmd_write_r(struct intel_cmd *cmd, uint32_t val,
108 struct intel_mem *mem,
109 uint16_t read_domains, uint16_t write_domain)
110{
111 cmd_add_reloc(cmd, 0, val, mem, read_domains, write_domain);
112 cmd->used++;
113}
114
115/**
116 * Patch the given \p pos.
117 */
118static inline void cmd_patch(struct intel_cmd *cmd,
119 XGL_UINT pos, uint32_t val)
120{
121 assert(pos < cmd->used);
122 ((uint32_t *) cmd->ptr_opaque)[pos] = val;
123}
124
Chia-I Wu00a23b22014-08-20 15:28:08 +0800125#endif /* CMD_PRIV_H */