KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
pvr_dma.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/pvr/pvr_dma.h
4 Copyright (C) 2002 Megan Potter
5 Copyright (C) 2014 Lawrence Sebald
6 Copyright (C) 2023 Ruslan Rostovtsev
7 Copyright (C) 2024 Falco Girgis
8*/
9
10/** \file dc/pvr/pvr_dma.h
11 \brief API for utilizing the DMA with the PVR for rendering
12 \ingroup pvr_dma
13
14 \author Megan Potter
15 \author Roger Cattermole
16 \author Paul Boese
17 \author Brian Paul
18 \author Lawrence Sebald
19 \author Benoit Miller
20 \author Ruslan Rostovtsev
21 \author Falco Girgis
22
23 \todo
24 - Top level "Transfer" group
25 a. DMA
26 b. SQs
27*/
28
29#ifndef __DC_PVR_PVR_DMA_H
30#define __DC_PVR_PVR_DMA_H
31
32#include <stdint.h>
33#include <stdbool.h>
34
35#include <sys/cdefs.h>
36__BEGIN_DECLS
37
38/** \defgroup pvr_dma DMA
39 \brief PowerVR DMA driver
40 \ingroup pvr
41*/
42
43/** \brief Transfer modes with TA/PVR DMA and Store Queues
44 \ingroup pvr_dma
45*/
46typedef enum pvr_dma_type {
47 PVR_DMA_VRAM64, /**< Transfer to VRAM using TA bus */
48 PVR_DMA_VRAM32, /**< Transfer to VRAM using TA bus */
49 PVR_DMA_TA, /**< Transfer to the tile accelerator */
50 PVR_DMA_YUV, /**< Transfer to the YUV converter (TA) */
51 PVR_DMA_VRAM32_SB, /**< Transfer to/from VRAM using PVR i/f */
52 PVR_DMA_VRAM64_SB, /**< Transfer to/from VRAM using PVR i/f */
53 PVR_DMA_REGISTERS /**< \brief Transfer to/from PVR registers */
55
56/** \brief PVR DMA interrupt callback type.
57 \ingroup pvr_dma
58
59 Functions that act as callbacks when DMA completes should be of this type.
60 These functions will be called inside an interrupt context, so don't try to
61 use anything that might stall.
62
63 \param data User data passed in to the pvr_dma_transfer()
64 function.
65*/
66typedef void (*pvr_dma_callback_t)(void *data);
67
68/** \brief Perform a DMA transfer to the PVR RAM over 64-bit TA bus.
69 \ingroup pvr_dma
70
71 This function copies a block of data to the PVR or its memory via DMA. There
72 are all kinds of constraints that must be fulfilled to actually do this, so
73 make sure to read all the fine print with the parameter list.
74
75 If a callback is specified, it will be called in an interrupt context, so
76 keep that in mind in writing the callback.
77
78 \param src Where to copy from. Must be 32-byte aligned.
79 \param dest Where to copy to. Must be 32-byte aligned.
80 \param count The number of bytes to copy. Must be a multiple of
81 32.
82 \param type The type of DMA transfer to do (see list of modes).
83 \param block True if you want the function to block until the
84 DMA completes.
85 \param callback A function to call upon completion of the DMA.
86 \param cbdata Data to pass to the callback function.
87 \retval 0 On success.
88 \retval -1 On failure. Sets errno as appropriate.
89
90 \par Error Conditions:
91 \em EINPROGRESS - DMA already in progress \n
92 \em EFAULT - dest is not 32-byte aligned \n
93 \em EIO - I/O error
94*/
95int pvr_dma_transfer(const void *src, uintptr_t dest, size_t count,
96 pvr_dma_type_t type, bool block,
97 pvr_dma_callback_t callback, void *cbdata);
98
99
100/** \brief Load a texture using TA DMA.
101 \ingroup pvr_dma
102
103 This is essentially a convenience wrapper for pvr_dma_transfer(), so all
104 notes that apply to it also apply here.
105
106 \param src Where to copy from. Must be 32-byte aligned.
107 \param dest Where to copy to. Must be 32-byte aligned.
108 \param count The number of bytes to copy. Must be a multiple of
109 32.
110 \param block True if you want the function to block until the
111 DMA completes.
112 \param callback A function to call upon completion of the DMA.
113 \param cbdata Data to pass to the callback function.
114 \retval 0 On success.
115 \retval -1 On failure. Sets errno as appropriate.
116
117 \par Error Conditions:
118 \em EINPROGRESS - DMA already in progress \n
119 \em EFAULT - dest is not 32-byte aligned \n
120 \em EIO - I/O error
121*/
122int pvr_txr_load_dma(const void *src, pvr_ptr_t dest, size_t count, bool block,
123 pvr_dma_callback_t callback, void *cbdata);
124
125/** \brief Load vertex data to the TA using TA DMA.
126 \ingroup pvr_dma
127
128 This is essentially a convenience wrapper for pvr_dma_transfer(), so all
129 notes that apply to it also apply here.
130
131 \param src Where to copy from. Must be 32-byte aligned.
132 \param count The number of bytes to copy. Must be a multiple of
133 32.
134 \param block True if you want the function to block until the
135 DMA completes.
136 \param callback A function to call upon completion of the DMA.
137 \param cbdata Data to pass to the callback function.
138 \retval 0 On success.
139 \retval -1 On failure. Sets errno as appropriate.
140
141 \par Error Conditions:
142 \em EINPROGRESS - DMA already in progress \n
143 \em EFAULT - dest is not 32-byte aligned \n
144 \em EIO - I/O error
145 */
146int pvr_dma_load_ta(const void *src, size_t count, bool block,
147 pvr_dma_callback_t callback, void *cbdata);
148
149/** \brief Load yuv data to the YUV converter using TA DMA.
150 \ingroup pvr_dma
151
152 This is essentially a convenience wrapper for pvr_dma_transfer(), so all
153 notes that apply to it also apply here.
154
155 \param src Where to copy from. Must be 32-byte aligned.
156 \param count The number of bytes to copy. Must be a multiple of
157 32.
158 \param block True if you want the function to block until the
159 DMA completes.
160 \param callback A function to call upon completion of the DMA.
161 \param cbdata Data to pass to the callback function.
162 \retval 0 On success.
163 \retval -1 On failure. Sets errno as appropriate.
164
165 \par Error Conditions:
166 \em EINPROGRESS - DMA already in progress \n
167 \em EFAULT - dest is not 32-byte aligned \n
168 \em EIO - I/O error
169*/
170int pvr_dma_yuv_conv(const void *src, size_t count, bool block,
171 pvr_dma_callback_t callback, void *cbdata);
172
173/** \brief Is PVR DMA is inactive?
174 \ingroup pvr_dma
175 \return True if there is no PVR DMA active, thus a DMA
176 can begin or false if there is an active DMA.
177*/
178bool pvr_dma_ready(void);
179
180/** \brief Initialize TA/PVR DMA.
181 \ingroup pvr_dma
182 */
183void pvr_dma_init(void);
184
185/** \brief Shut down TA/PVR DMA.
186 \ingroup pvr_dma
187 */
189
190/** \brief Copy a block of memory to VRAM
191 \ingroup store_queues
192
193 This function is similar to sq_cpy(), but it has been
194 optimized for writing to a destination residing within VRAM.
195
196 \warning
197 This function cannot be used at the same time as a PVR DMA transfer.
198
199 The dest pointer must be at least 32-byte aligned and reside
200 in video memory, the src pointer must be at least 8-byte aligned,
201 and n must be a multiple of 32.
202
203 \param dest The address to copy to (32-byte aligned).
204 \param src The address to copy from (32-bit (8-byte) aligned).
205 \param n The number of bytes to copy (multiple of 32).
206 \param type The type of SQ/DMA transfer to do (see list of modes).
207 \return The original value of dest.
208
209 \sa pvr_sq_set32()
210*/
211void *pvr_sq_load(void *dest, const void *src,
212 size_t n, pvr_dma_type_t type);
213
214/** \brief Set a block of PVR memory to a 16-bit value.
215 \ingroup store_queues
216
217 This function is similar to sq_set16(), but it has been
218 optimized for writing to a destination residing within VRAM.
219
220 \warning
221 This function cannot be used at the same time as a PVR DMA transfer.
222
223 The dest pointer must be at least 32-byte aligned and reside in video
224 memory, n must be a multiple of 32 and only the low 16-bits are used
225 from c.
226
227 \param dest The address to begin setting at (32-byte aligned).
228 \param c The value to set (in the low 16-bits).
229 \param n The number of bytes to set (multiple of 32).
230 \param type The type of SQ/DMA transfer to do (see list of modes).
231 \return The original value of dest.
232
233 \sa pvr_sq_set32()
234*/
235void *pvr_sq_set16(void *dest, uint32_t c, size_t n, pvr_dma_type_t type);
236
237/** \brief Set a block of PVR memory to a 32-bit value.
238 \ingroup store_queues
239
240 This function is similar to sq_set32(), but it has been
241 optimized for writing to a destination residing within VRAM.
242
243 \warning
244 This function cannot be used at the same time as a PVR DMA transfer.
245
246 The dest pointer must be at least 32-byte aligned and reside in video
247 memory, n must be a multiple of 32.
248
249 \param dest The address to begin setting at (32-byte aligned).
250 \param c The value to set.
251 \param n The number of bytes to set (multiple of 32).
252 \param type The type of SQ/DMA transfer to do (see list of modes).
253 \return The original value of dest.
254
255 \sa pvr_sq_set16()
256*/
257void *pvr_sq_set32(void *dest, uint32_t c, size_t n, pvr_dma_type_t type);
258
259__END_DECLS
260
261#endif /* __DC_PVR_PVR_DMA_H */
int pvr_dma_yuv_conv(const void *src, size_t count, bool block, pvr_dma_callback_t callback, void *cbdata)
Load yuv data to the YUV converter using TA DMA.
void(* pvr_dma_callback_t)(void *data)
PVR DMA interrupt callback type.
Definition pvr_dma.h:66
int pvr_dma_transfer(const void *src, uintptr_t dest, size_t count, pvr_dma_type_t type, bool block, pvr_dma_callback_t callback, void *cbdata)
Perform a DMA transfer to the PVR RAM over 64-bit TA bus.
int pvr_txr_load_dma(const void *src, pvr_ptr_t dest, size_t count, bool block, pvr_dma_callback_t callback, void *cbdata)
Load a texture using TA DMA.
bool pvr_dma_ready(void)
Is PVR DMA is inactive?
pvr_dma_type_t
Transfer modes with TA/PVR DMA and Store Queues.
Definition pvr_dma.h:46
int pvr_dma_load_ta(const void *src, size_t count, bool block, pvr_dma_callback_t callback, void *cbdata)
Load vertex data to the TA using TA DMA.
void pvr_dma_init(void)
Initialize TA/PVR DMA.
void pvr_dma_shutdown(void)
Shut down TA/PVR DMA.
@ PVR_DMA_TA
Transfer to the tile accelerator.
Definition pvr_dma.h:49
@ PVR_DMA_VRAM32_SB
Transfer to/from VRAM using PVR i/f.
Definition pvr_dma.h:51
@ PVR_DMA_REGISTERS
Transfer to/from PVR registers.
Definition pvr_dma.h:53
@ PVR_DMA_VRAM32
Transfer to VRAM using TA bus.
Definition pvr_dma.h:48
@ PVR_DMA_YUV
Transfer to the YUV converter (TA)
Definition pvr_dma.h:50
@ PVR_DMA_VRAM64_SB
Transfer to/from VRAM using PVR i/f.
Definition pvr_dma.h:52
@ PVR_DMA_VRAM64
Transfer to VRAM using TA bus.
Definition pvr_dma.h:47
void * pvr_ptr_t
PVR texture memory pointer.
Definition pvr_mem.h:45
void * pvr_sq_set16(void *dest, uint32_t c, size_t n, pvr_dma_type_t type)
Set a block of PVR memory to a 16-bit value.
void * pvr_sq_set32(void *dest, uint32_t c, size_t n, pvr_dma_type_t type)
Set a block of PVR memory to a 32-bit value.
void * pvr_sq_load(void *dest, const void *src, size_t n, pvr_dma_type_t type)
Copy a block of memory to VRAM.