KallistiOS git master
Independent SDK for the Sega Dreamcast
|
Driver for accessing the devices on the G2 Bus More...
Files | |
file | g2bus.h |
G2 bus memory interface. | |
Data Structures | |
struct | g2_ctx_t |
G2 context. More... | |
Macros | |
#define | G2_DMA_TO_G2 0 |
G2Bus DMA direction. | |
#define | G2_DMA_TO_SH4 1 |
Typedefs | |
typedef void(* | g2_dma_callback_t) (void *data) |
G2Bus DMA interrupt callback type. | |
Functions | |
int | g2_dma_transfer (void *sh4, void *g2bus, size_t length, uint32_t block, g2_dma_callback_t callback, void *cbdata, uint32_t dir, uint32_t mode, uint32_t g2chn, uint32_t sh4chn) |
Perform a DMA transfer between SH-4 RAM and G2 Bus. | |
int | g2_dma_init (void) |
Initialize DMA support. | |
void | g2_dma_shutdown (void) |
Shutdown DMA support. | |
static g2_ctx_t | g2_lock (void) |
Disable IRQs and G2 DMA. | |
static void | g2_unlock (g2_ctx_t ctx) |
Enable IRQs and G2 DMA. | |
uint8_t | g2_read_8 (uintptr_t address) |
Read one byte from G2. | |
void | g2_write_8 (uintptr_t address, uint8_t value) |
Write a single byte to G2. | |
uint16 | g2_read_16 (uintptr_t address) |
Read one 16-bit word from G2. | |
void | g2_write_16 (uintptr_t address, uint16_t value) |
Write a 16-bit word to G2. | |
uint32_t | g2_read_32 (uintptr_t address) |
Read one 32-bit dword from G2. | |
void | g2_write_32 (uintptr_t address, uint32_t value) |
Write a 32-bit dword to G2. | |
void | g2_read_block_8 (uint8_t *output, uintptr_t address, size_t amt) |
Read a block of bytes from G2. | |
void | g2_write_block_8 (const uint8_t *input, uintptr_t address, size_t amt) |
Write a block of bytes to G2. | |
void | g2_read_block_16 (uint16_t *output, uintptr_t address, size_t amt) |
Read a block of words from G2. | |
void | g2_write_block_16 (const uint16_t *input, uintptr_t address, size_t amt) |
Write a block of words to G2. | |
void | g2_read_block_32 (uint32_t *output, uintptr_t address, size_t amt) |
Read a block of dwords from G2. | |
void | g2_write_block_32 (const uint32_t *input, uintptr_t address, size_t amt) |
Write a block of dwords to G2. | |
void | g2_memset_8 (uintptr_t address, uint8_t c, size_t amt) |
Set a block of bytes to G2. | |
void | g2_fifo_wait (void) |
Wait for the G2 write FIFO to empty. | |
List of G2 Bus channels | |
AICA (SPU) is channel 0, BBA uses channel 1. CH2_DMA_G2CHN and CH3_DMA_G2CHN are not currently tied to any specific device.
In the current implementation, *_DMA_MODE should always be set to zero (representing CPU_TRIGGER). There is also no involvement of SH4-DMA with G2-DMA; therefore, the *_DMA_SHCHN values have been deprecated. | |
#define | G2_DMA_CHAN_SPU 0 |
AICA: G2 channel 0. | |
#define | G2_DMA_CHAN_BBA 1 |
BBA: G2 channel 1. | |
#define | G2_DMA_CHAN_CH2 2 |
CH2: G2 channel 2. | |
#define | G2_DMA_CHAN_CH3 3 |
CH3: G2 channel 3. | |
Driver for accessing the devices on the G2 Bus
#define G2_DMA_CHAN_BBA 1 |
BBA: G2 channel 1.
#define G2_DMA_CHAN_CH2 2 |
CH2: G2 channel 2.
#define G2_DMA_CHAN_CH3 3 |
CH3: G2 channel 3.
#define G2_DMA_CHAN_SPU 0 |
AICA: G2 channel 0.
#define G2_DMA_TO_G2 0 |
G2Bus DMA direction.
The direction you want the data to go. SH4 to AICA, BBA, etc use SH4TOG2BUS, otherwise G2BUSTOSH4.
#define G2_DMA_TO_SH4 1 |
typedef void(* g2_dma_callback_t) (void *data) |
G2Bus DMA interrupt callback type.
Functions that act as callbacks when G2-DMA completes should be of this type. These functions will be called inside an interrupt context, so don't try to use anything that might stall.
data | User data passed in to the g2_dma_transfer() function. |
int g2_dma_init | ( | void | ) |
Initialize DMA support.
This function sets up the DMA support for transfers to/from the G2 Bus.
0 | On success (no error conditions defined). |
void g2_dma_shutdown | ( | void | ) |
Shutdown DMA support.
int g2_dma_transfer | ( | void * | sh4, |
void * | g2bus, | ||
size_t | length, | ||
uint32_t | block, | ||
g2_dma_callback_t | callback, | ||
void * | cbdata, | ||
uint32_t | dir, | ||
uint32_t | mode, | ||
uint32_t | g2chn, | ||
uint32_t | sh4chn ) |
Perform a DMA transfer between SH-4 RAM and G2 Bus.
This function copies a block of data between SH-4 RAM and G2 Bus via DMA. You specify the direction of the copy (SH4TOG2BUS/G2BUSTOSH4). There are all kinds of constraints that must be fulfilled to actually do this, so make sure to read all the fine print with the parameter list.
If a callback is specified, it will be called in an interrupt context, so keep that in mind in writing the callback.
sh4 | Where to copy from/to. Must be 32-byte aligned. |
g2bus | Where to copy from/to. Must be 32-byte aligned. |
length | The number of bytes to copy. Must be a multiple of 32. |
block | Non-zero if you want the function to block until the DMA completes. |
callback | A function to call upon completion of the DMA. |
cbdata | Data to pass to the callback function. |
dir | SH4TOG2BUS or G2BUSTOSH4. |
mode | Ignored; for compatibility only. |
g2chn | See g2b_channels. |
sh4chn | Ignored; for compatibility only. |
0 | On success. |
-1 | On failure. Sets errno as appropriate. |
void g2_fifo_wait | ( | void | ) |
Wait for the G2 write FIFO to empty.
This function will spinwait until the G2 FIFO indicates that it has been drained. The FIFO is 32 bytes in length, and thus when accessing AICA you must do this at least for every 8 32-bit writes that you execute.
|
inlinestatic |
Disable IRQs and G2 DMA.
This function makes the following g2_read_*()/g2_write_*() functions atomic by disabling IRQs and G2 DMA and storing their states. Pass the context created by this function to g2_unlock() to re-enable IRQs and G2 DMA.
References FIFO_G2, FIFO_SH4, FIFO_STATUS, irq_disable(), and g2_ctx_t::irq_state.
void g2_memset_8 | ( | uintptr_t | address, |
uint8_t | c, | ||
size_t | amt ) |
Set a block of bytes to G2.
This function acts as memset() for setting a block of bytes on G2. It will take the necessary precautions for accessing G2.
address | The address in G2-space to write to. |
c | The byte to write. |
amt | The number of bytes to write. |
uint16 g2_read_16 | ( | uintptr_t | address | ) |
Read one 16-bit word from G2.
This function reads a single word from the specified address, taking all necessary precautions that are required for accessing G2.
address | The address in memory to read. |
uint32_t g2_read_32 | ( | uintptr_t | address | ) |
Read one 32-bit dword from G2.
This function reads a single dword from the specified address, taking all necessary precautions that are required for accessing G2.
address | The address in memory to read. |
uint8_t g2_read_8 | ( | uintptr_t | address | ) |
Read one byte from G2.
This function reads a single byte from the specified address, taking all necessary precautions that are required for accessing G2.
address | The address in memory to read. |
void g2_read_block_16 | ( | uint16_t * | output, |
uintptr_t | address, | ||
size_t | amt ) |
Read a block of words from G2.
This function acts as memcpy() for copying data from G2 to system memory, but it copies 16 bits at a time. It will take the necessary precautions before accessing G2 for you as well.
output | Pointer in system memory to write to. |
address | The address in G2-space to read from. |
amt | The number of words to read. |
void g2_read_block_32 | ( | uint32_t * | output, |
uintptr_t | address, | ||
size_t | amt ) |
Read a block of dwords from G2.
This function acts as memcpy() for copying data from G2 to system memory, but it copies 32 bits at a time. It will take the necessary precautions before accessing G2 for you as well.
output | Pointer in system memory to write to. |
address | The address in G2-space to read from. |
amt | The number of dwords to read. |
void g2_read_block_8 | ( | uint8_t * | output, |
uintptr_t | address, | ||
size_t | amt ) |
Read a block of bytes from G2.
This function acts as memcpy() for copying data from G2 to system memory. It will take the necessary precautions before accessing G2 for you as well.
output | Pointer in system memory to write to. |
address | The address in G2-space to read from. |
amt | The number of bytes to read. |
|
inlinestatic |
Enable IRQs and G2 DMA.
This function restores the IRQ and G2 DMA states using the context value generated by g2_lock().
ctx | The context containing IRQ and G2 DMA states. |
References irq_restore(), and g2_ctx_t::irq_state.
void g2_write_16 | ( | uintptr_t | address, |
uint16_t | value ) |
Write a 16-bit word to G2.
This function writes one word to the specified address, taking all the necessary precautions to ensure your write actually succeeds.
address | The address in memory to write to. |
value | The value to write to that address. |
void g2_write_32 | ( | uintptr_t | address, |
uint32_t | value ) |
Write a 32-bit dword to G2.
This function writes one dword to the specified address, taking all the necessary precautions to ensure your write actually succeeds.
address | The address in memory to write to. |
value | The value to write to that address. |
void g2_write_8 | ( | uintptr_t | address, |
uint8_t | value ) |
Write a single byte to G2.
This function writes one byte to the specified address, taking all the necessary precautions to ensure your write actually succeeds.
address | The address in memory to write to. |
value | The value to write to that address. |
void g2_write_block_16 | ( | const uint16_t * | input, |
uintptr_t | address, | ||
size_t | amt ) |
Write a block of words to G2.
This function acts as memcpy() for copying data to G2 from system memory, copying 16 bits at a time. It will take the necessary precautions for accessing G2.
input | The pointer in system memory to read from. |
address | The address in G2-space to write to. |
amt | The number of words to write. |
void g2_write_block_32 | ( | const uint32_t * | input, |
uintptr_t | address, | ||
size_t | amt ) |
Write a block of dwords to G2.
This function acts as memcpy() for copying data to G2 from system memory, copying 32 bits at a time. It will take the necessary precautions for accessing G2.
input | The pointer in system memory to read from. |
address | The address in G2-space to write to. |
amt | The number of dwords to write. |
void g2_write_block_8 | ( | const uint8_t * | input, |
uintptr_t | address, | ||
size_t | amt ) |
Write a block of bytes to G2.
This function acts as memcpy() for copying data to G2 from system memory. It will take the necessary precautions for accessing G2.
input | The pointer in system memory to read from. |
address | The address in G2-space to write to. |
amt | The number of bytes to write. |