KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
g2bus.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  g2bus.h
4  (c)2002 Dan Potter
5 
6 */
7 
8 /** \file dc/g2bus.h
9  \brief G2 bus memory interface.
10 
11  This file provides low-level support for accessing devices on the G2 bus in
12  the Dreamcast. The G2 bus contains the AICA, as well as the expansion port.
13  Generally, you won't be dealing with things at this level, but rather on the
14  level of the device you're actually interested in working with. Most of the
15  expansion port devices (the modem, bba, and lan adapter) all have their own
16  drivers that work off of this functionality.
17 
18  The G2 bus is notoroiously picky about a lot of things. You have to be
19  careful to use the right access size for whatever you're working with. Also
20  you can't be doing PIO and DMA at the same time. Finally, there's a FIFO to
21  contend with when you're doing PIO stuff as well. Generally, G2 is a pain in
22  the rear, so you really do want to be using the higher-level stuff related
23  to each device if at all possible!
24 
25  \author Dan Potter
26 */
27 
28 #ifndef __DC_G2BUS_H
29 #define __DC_G2BUS_H
30 
31 #include <sys/cdefs.h>
32 __BEGIN_DECLS
33 
34 #include <arch/types.h>
35 
36 /* DMA copy from SH-4 RAM to G2 bus (dir = 0) or the opposite;
37  length must be a multiple of 32,
38  and the source and destination addresses must be aligned on 32-byte
39  boundaries. If block is non-zero, this function won't return until
40  the transfer is complete. If callback is non-NULL, it will be called
41  upon completion (in an interrupt context!). Returns <0 on error.
42 
43  Known working combination :
44 
45  g2chn = 0, sh4chn = 3 --> mode = 5 (but many other value seems OK ?)
46  g2chn = 1, sh4chn = 1 --> mode = 0 (or 4 better ?)
47  g2chn = 1, sh4chn = 0 --> mode = 3
48 
49  It seems that g2chn is not important when choosing mode, so this mode parameter is probably
50  how we actually connect the sh4chn to the g2chn.
51 
52  Update : looks like there is a formula, mode = 3 + shchn
53 
54 */
55 
56 /* We use sh channel 3 here to avoid conflicts with the PVR. */
57 #define SPU_DMA_MODE 6 /* should we use 6 instead, so that the formula is 3+shchn ?
58 6 works too, so ... */
59 #define SPU_DMA_G2CHN 0
60 #define SPU_DMA_SHCHN 3
61 
62 /* For BBA : sh channel 1 (doesn't seem used) and g2 channel 1 to no conflict with SPU */
63 #define BBA_DMA_MODE 4
64 #define BBA_DMA_G2CHN 1
65 #define BBA_DMA_SHCHN 1
66 
67 /* For BBA2 : sh channel 0 (doesn't seem used) and g2 channel 2 to no conflict with SPU */
68 /* This is a second DMA channels used for the BBA, just for fun and see if we can initiate
69  two DMA transfers with the BBA concurently. */
70 #define BBA_DMA2_MODE 3
71 #define BBA_DMA2_G2CHN 2
72 #define BBA_DMA2_SHCHN 0
73 
74 typedef void (*g2_dma_callback_t)(ptr_t data);
75 int g2_dma_transfer(void *from, void * dest, uint32 length, int block,
76  g2_dma_callback_t callback, ptr_t cbdata,
77  uint32 dir, uint32 mode, uint32 g2chn, uint32 sh4chn);
78 
79 /** \brief Read one byte from G2.
80 
81  This function reads a single byte from the specified address, taking all
82  necessary precautions that are required for accessing G2.
83 
84  \param address The address in memory to read.
85  \return The byte read from the address specified.
86 */
87 uint8 g2_read_8(uint32 address);
88 
89 /** \brief Write a single byte to G2.
90 
91  This function writes one byte to the specified address, taking all the
92  necessary precautions to ensure your write actually succeeds.
93 
94  \param address The address in memory to write to.
95  \param value The value to write to that address.
96 */
97 void g2_write_8(uint32 address, uint8 value);
98 
99 /** \brief Read one 16-bit word from G2.
100 
101  This function reads a single word from the specified address, taking all
102  necessary precautions that are required for accessing G2.
103 
104  \param address The address in memory to read.
105  \return The word read from the address specified.
106 */
107 uint16 g2_read_16(uint32 address);
108 
109 /** \brief Write a 16-bit word to G2.
110 
111  This function writes one word to the specified address, taking all the
112  necessary precautions to ensure your write actually succeeds.
113 
114  \param address The address in memory to write to.
115  \param value The value to write to that address.
116 */
117 void g2_write_16(uint32 address, uint16 value);
118 
119 /** \brief Read one 32-bit dword from G2.
120 
121  This function reads a single dword from the specified address, taking all
122  necessary precautions that are required for accessing G2.
123 
124  \param address The address in memory to read.
125  \return The dword read from the address specified.
126 */
127 uint32 g2_read_32(uint32 address);
128 
129 /** \brief Write a 32-bit dword to G2.
130 
131  This function writes one dword to the specified address, taking all the
132  necessary precautions to ensure your write actually succeeds.
133 
134  \param address The address in memory to write to.
135  \param value The value to write to that address.
136 */
137 void g2_write_32(uint32 address, uint32 value);
138 
139 /** \brief Read a block of bytes from G2.
140 
141  This function acts as memcpy() for copying data from G2 to system memory. It
142  will take the necessary precautions before accessing G2 for you as well.
143 
144  \param output Pointer in system memory to write to.
145  \param address The address in G2-space to read from.
146  \param amt The number of bytes to read.
147 */
148 void g2_read_block_8(uint8 * output, uint32 address, int amt);
149 
150 /** \brief Write a block of bytes to G2.
151 
152  This function acts as memcpy() for copying data to G2 from system memory. It
153  will take the necessary precautions for accessing G2.
154 
155  \param input The pointer in system memory to read from.
156  \param address The address in G2-space to write to.
157  \param amt The number of bytes to write.
158 */
159 void g2_write_block_8(const uint8 * input, uint32 address, int amt);
160 
161 /** \brief Read a block of words from G2.
162 
163  This function acts as memcpy() for copying data from G2 to system memory,
164  but it copies 16 bits at a time. It will take the necessary precautions
165  before accessing G2 for you as well.
166 
167  \param output Pointer in system memory to write to.
168  \param address The address in G2-space to read from.
169  \param amt The number of words to read.
170 */
171 void g2_read_block_16(uint16 * output, uint32 address, int amt);
172 
173 /** \brief Write a block of words to G2.
174 
175  This function acts as memcpy() for copying data to G2 from system memory,
176  copying 16 bits at a time. It will take the necessary precautions for
177  accessing G2.
178 
179  \param input The pointer in system memory to read from.
180  \param address The address in G2-space to write to.
181  \param amt The number of words to write.
182 */
183 void g2_write_block_16(const uint16 * input, uint32 address, int amt);
184 
185 /** \brief Read a block of dwords from G2.
186 
187  This function acts as memcpy() for copying data from G2 to system memory,
188  but it copies 32 bits at a time. It will take the necessary precautions
189  before accessing G2 for you as well.
190 
191  \param output Pointer in system memory to write to.
192  \param address The address in G2-space to read from.
193  \param amt The number of dwords to read.
194 */
195 void g2_read_block_32(uint32 * output, uint32 address, int amt);
196 
197 /** \brief Write a block of dwords to G2.
198 
199  This function acts as memcpy() for copying data to G2 from system memory,
200  copying 32 bits at a time. It will take the necessary precautions for
201  accessing G2.
202 
203  \param input The pointer in system memory to read from.
204  \param address The address in G2-space to write to.
205  \param amt The number of dwords to write.
206 */
207 void g2_write_block_32(const uint32 * input, uint32 address, int amt);
208 
209 /** \brief Set a block of bytes to G2.
210 
211  This function acts as memset() for setting a block of bytes on G2. It will
212  take the necessary precautions for accessing G2.
213 
214  \param address The address in G2-space to write to.
215  \param c The byte to write.
216  \param amt The number of bytes to write.
217 */
218 void g2_memset_8(uint32 address, uint8 c, int amt);
219 
220 /** \brief Wait for the G2 write FIFO to empty.
221 
222  This function will spinwait until the G2 FIFO indicates that it has been
223  drained. The FIFO is 32 bytes in length, and thus when accessing AICA you
224  must do this at least for every 8 32-bit writes that you execute.
225 */
226 void g2_fifo_wait();
227 
228 __END_DECLS
229 
230 #endif /* __DC_G2BUS_H */
231 
Common integer types.
void g2_write_32(uint32 address, uint32 value)
Write a 32-bit dword to G2.
uint32 g2_read_32(uint32 address)
Read one 32-bit dword from G2.
int g2_dma_transfer(void *from, void *dest, uint32 length, int block, g2_dma_callback_t callback, ptr_t cbdata, uint32 dir, uint32 mode, uint32 g2chn, uint32 sh4chn)
uint8 g2_read_8(uint32 address)
Read one byte from G2.
void g2_write_block_16(const uint16 *input, uint32 address, int amt)
Write a block of words to G2.
void g2_fifo_wait()
Wait for the G2 write FIFO to empty.
void g2_read_block_16(uint16 *output, uint32 address, int amt)
Read a block of words from G2.
void g2_read_block_32(uint32 *output, uint32 address, int amt)
Read a block of dwords from G2.
void g2_write_8(uint32 address, uint8 value)
Write a single byte to G2.
uint16 g2_read_16(uint32 address)
Read one 16-bit word from G2.
void g2_read_block_8(uint8 *output, uint32 address, int amt)
Read a block of bytes from G2.
void g2_write_block_32(const uint32 *input, uint32 address, int amt)
Write a block of dwords to G2.
void g2_write_16(uint32 address, uint16 value)
Write a 16-bit word to G2.
unsigned short uint16
16-bit unsigned integer
Definition: types.h:29
uint32 ptr_t
Pointer arithmetic type.
Definition: types.h:47
void(* g2_dma_callback_t)(ptr_t data)
Definition: g2bus.h:74
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
void g2_memset_8(uint32 address, uint8 c, int amt)
Set a block of bytes to G2.
unsigned char uint8
8-bit unsigned integer
Definition: types.h:30
void g2_write_block_8(const uint8 *input, uint32 address, int amt)
Write a block of bytes to G2.