2 * Copyright © 2020 Google, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include "drm/freedreno_drmif.h"
32 #include "drm/freedreno_ringbuffer.h"
34 #include "registers/adreno_pm4.xml.h"
35 #include "registers/adreno_common.xml.h"
40 /* filled in by backend when shader is assembled: */
41 uint32_t local_size
[3];
43 uint32_t buf_sizes
[MAX_BUFS
]; /* size in dwords */
45 /* filled in by frontend before launching grid: */
46 struct fd_bo
*bufs
[MAX_BUFS
];
49 /* per-generation entry-points: */
51 struct kernel
*(*assemble
)(struct backend
*b
, FILE *in
);
52 void (*disassemble
)(struct kernel
*kernel
, FILE *out
);
53 void (*emit_grid
)(struct kernel
*kernel
, uint32_t grid
[3],
54 struct fd_submit
*submit
);
57 #define define_cast(_from, _to) \
58 static inline struct _to * \
59 to_ ## _to(struct _from *f) \
60 { return (struct _to *)f; }
62 struct backend
*a6xx_init(struct fd_device
*dev
, uint32_t gpu_id
);
69 BEGIN_RING(struct fd_ringbuffer
*ring
, uint32_t ndwords
)
71 if (ring
->cur
+ ndwords
> ring
->end
)
72 fd_ringbuffer_grow(ring
, ndwords
);
76 OUT_RING(struct fd_ringbuffer
*ring
, uint32_t data
)
78 fd_ringbuffer_emit(ring
, data
);
81 static inline unsigned
82 _odd_parity_bit(unsigned val
)
84 /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel
85 * note that we want odd parity so 0x6996 is inverted.
91 return (~0x6996 >> val
) & 1;
95 OUT_PKT4(struct fd_ringbuffer
*ring
, uint16_t regindx
, uint16_t cnt
)
97 BEGIN_RING(ring
, cnt
+1);
98 OUT_RING(ring
, CP_TYPE4_PKT
| cnt
|
99 (_odd_parity_bit(cnt
) << 7) |
100 ((regindx
& 0x3ffff) << 8) |
101 ((_odd_parity_bit(regindx
) << 27)));
105 OUT_PKT7(struct fd_ringbuffer
*ring
, uint8_t opcode
, uint16_t cnt
)
107 BEGIN_RING(ring
, cnt
+1);
108 OUT_RING(ring
, CP_TYPE7_PKT
| cnt
|
109 (_odd_parity_bit(cnt
) << 15) |
110 ((opcode
& 0x7f) << 16) |
111 ((_odd_parity_bit(opcode
) << 23)));
115 * NOTE: OUT_RELOC*() is 2 dwords (64b) on a5xx+
119 __out_reloc(struct fd_ringbuffer
*ring
, struct fd_bo
*bo
,
120 uint32_t offset
, uint64_t or, int32_t shift
, uint32_t flags
)
122 debug_assert(offset
< fd_bo_size(bo
));
123 fd_ringbuffer_reloc(ring
, &(struct fd_reloc
){
134 OUT_RELOC(struct fd_ringbuffer
*ring
, struct fd_bo
*bo
,
135 uint32_t offset
, uint64_t or, int32_t shift
)
137 __out_reloc(ring
, bo
, offset
, or, shift
, FD_RELOC_READ
);
141 OUT_RELOCW(struct fd_ringbuffer
*ring
, struct fd_bo
*bo
,
142 uint32_t offset
, uint64_t or, int32_t shift
)
144 __out_reloc(ring
, bo
, offset
, or, shift
, FD_RELOC_READ
| FD_RELOC_WRITE
);
148 OUT_RELOCD(struct fd_ringbuffer
*ring
, struct fd_bo
*bo
,
149 uint32_t offset
, uint64_t or, int32_t shift
)
151 __out_reloc(ring
, bo
, offset
, or, shift
, FD_RELOC_READ
| FD_RELOC_DUMP
);
155 OUT_RB(struct fd_ringbuffer
*ring
, struct fd_ringbuffer
*target
)
157 fd_ringbuffer_emit_reloc_ring_full(ring
, target
, 0);
160 /* for conditionally setting boolean flag(s): */
161 #define COND(bool, val) ((bool) ? (val) : 0)
163 #endif /* __MAIN_H__ */