blob: 52b44fd9534026fb8fc4782e73277bf5377f098b [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/**
57 * Advance without writing.
58 */
59static inline void cmd_advance(struct intel_cmd *cmd, XGL_UINT len)
60{
61 assert(cmd->used + len <= cmd->size);
62 cmd->used += len;
63}
64
65/**
66 * Write \p len DWords and advance.
67 */
68static inline void cmd_writen(struct intel_cmd *cmd,
69 const uint32_t *vals, XGL_UINT len)
70{
71 assert(cmd->used + len <= cmd->size);
72 memcpy((uint32_t *) cmd->ptr_opaque + cmd->used,
73 vals, sizeof(uint32_t) * len);
74 cmd->used += len;
75}
76
77/**
78 * Write a DWord and advance.
79 */
80static inline void cmd_write(struct intel_cmd *cmd, uint32_t val)
81{
82 assert(cmd->used < cmd->size);
83 ((uint32_t *) cmd->ptr_opaque)[cmd->used++] = val;
84}
85
Chia-I Wu00a23b22014-08-20 15:28:08 +080086#endif /* CMD_PRIV_H */