libdragon
Loading...
Searching...
No Matches
rspq.h
Go to the documentation of this file.
1
167#ifndef __LIBDRAGON_RSPQ_H
168#define __LIBDRAGON_RSPQ_H
169
170#include <stdint.h>
171#include <rsp.h>
172#include <debug.h>
173#include <n64sys.h>
174#include <pputils.h>
175
176#ifdef __cplusplus
177extern "C" {
178#endif
179
181#define RSPQ_MAX_COMMAND_SIZE 62
182
188#define RSPQ_MAX_SHORT_COMMAND_SIZE 16
189
201typedef struct rspq_block_s rspq_block_t;
202
222
233void rspq_init(void);
234
240void rspq_close(void);
241
242
275uint32_t rspq_overlay_register(rsp_ucode_t *overlay_ucode);
276
293void rspq_overlay_register_static(rsp_ucode_t *overlay_ucode, uint32_t overlay_id);
294
310void rspq_overlay_unregister(uint32_t overlay_id);
311
332void* rspq_overlay_get_state(rsp_ucode_t *overlay_ucode);
333
398#define rspq_write(ovl_id, cmd_id, ...) \
399 __PPCAT(_rspq_write, __HAS_VARARGS(__VA_ARGS__)) (ovl_id, cmd_id, ##__VA_ARGS__)
400
402
403// Helpers used to implement rspq_write
404#define _rspq_write_prolog() \
405 extern volatile uint32_t *rspq_cur_pointer, *rspq_cur_sentinel; \
406 extern void rspq_next_buffer(void); \
407 volatile uint32_t *ptr = rspq_cur_pointer+1; \
408 (void)ptr;
409
410#define _rspq_write_epilog() ({ \
411 if (__builtin_expect(rspq_cur_pointer > rspq_cur_sentinel, 0)) \
412 rspq_next_buffer(); \
413})
414
415#define _rspq_write_arg(arg) \
416 *ptr++ = (arg);
417
418#define _rspq_write0(ovl_id, cmd_id) ({ \
419 _rspq_write_prolog(); \
420 rspq_cur_pointer[0] = (ovl_id) + ((cmd_id)<<24); \
421 rspq_cur_pointer += 1; \
422 _rspq_write_epilog(); \
423})
424
425#define _rspq_write1(ovl_id, cmd_id, arg0, ...) ({ \
426 _Static_assert(__COUNT_VARARGS(__VA_ARGS__) <= RSPQ_MAX_SHORT_COMMAND_SIZE, "too many arguments to rspq_write, please use rspq_write_begin/arg/end instead"); \
427 _rspq_write_prolog(); \
428 __CALL_FOREACH(_rspq_write_arg, ##__VA_ARGS__); \
429 rspq_cur_pointer[0] = ((ovl_id) + ((cmd_id)<<24)) | (arg0); \
430 rspq_cur_pointer += 1 + __COUNT_VARARGS(__VA_ARGS__); \
431 _rspq_write_epilog(); \
432})
433
435
437typedef struct {
438 uint32_t first_word;
439 volatile uint32_t *pointer;
440 volatile uint32_t *first;
441 bool is_first;
443
476inline rspq_write_t rspq_write_begin(uint32_t ovl_id, uint32_t cmd_id, int size) {
477 extern volatile uint32_t *rspq_cur_pointer, *rspq_cur_sentinel;
478 extern void rspq_next_buffer(void);
479
480 assertf(size <= RSPQ_MAX_COMMAND_SIZE, "The maximum command size is %d!", RSPQ_MAX_COMMAND_SIZE);
481
482 if (__builtin_expect(rspq_cur_pointer > rspq_cur_sentinel - size, 0))
484
485 volatile uint32_t *cur = rspq_cur_pointer;
486 rspq_cur_pointer += size;
487
488 return (rspq_write_t){
489 .first_word = ovl_id + (cmd_id<<24),
490 .pointer = cur + 1,
491 .first = cur,
492 .is_first = 1
493 };
494}
495
517inline void rspq_write_arg(rspq_write_t *w, uint32_t value) {
518 if (w->is_first) {
519 w->first_word |= value;
520 w->is_first = 0;
521 } else {
522 *w->pointer++ = value;
523 }
524}
525
541 *w->first = w->first_word;
542 w->first = 0;
543 w->pointer = 0;
544}
545
602void rspq_flush(void);
603
617void rspq_wait(void);
618
639
654
667
668
686void rspq_block_begin(void);
687
704
722void rspq_block_run(rspq_block_t *block);
723
736void rspq_block_free(rspq_block_t *block);
737
774void rspq_highpri_begin(void);
775
786void rspq_highpri_end(void);
787
796void rspq_highpri_sync(void);
797
804void rspq_noop(void);
805
821void rspq_dma_to_rdram(void *rdram_addr, uint32_t dmem_addr, uint32_t len, bool is_async);
822
838void rspq_dma_to_dmem(uint32_t dmem_addr, void *rdram_addr, uint32_t len, bool is_async);
839
841__attribute__((deprecated("may not work anymore. use rspq_syncpoint_new/rspq_syncpoint_check instead")))
842void rspq_signal(uint32_t signal);
845#ifdef __cplusplus
846}
847#endif
848
849#endif
Debugging Support.
#define assertf(expr, msg,...)
assertf() is like assert() with an attached printf().
Definition debug.h:196
N64 System Interface.
Low-level RSP hardware library.
void rspq_next_buffer(void)
Switch to the next write buffer for the current RSP queue.
Definition rspq.c:947
volatile uint32_t * rspq_cur_pointer
Copy of the current write pointer (see rspq_ctx_t)
Definition rspq.c:315
volatile uint32_t * rspq_cur_sentinel
Copy of the current write sentinel (see rspq_ctx_t)
Definition rspq.c:316
uint32_t rspq_overlay_register(rsp_ucode_t *overlay_ucode)
Register a rspq overlay into the RSP queue engine.
Definition rspq.c:887
void rspq_write_end(rspq_write_t *w)
Finish enqueuing a command into the queue.
Definition rspq.h:540
volatile uint32_t * first
pointer to the first word of the command
Definition rspq.h:440
void rspq_flush(void)
Make sure that RSP starts executing up to the last written command.
Definition rspq.c:1027
uint32_t first_word
value that will be written as first word
Definition rspq.h:438
volatile uint32_t * pointer
current pointer into the RSP queue
Definition rspq.h:439
void rspq_overlay_unregister(uint32_t overlay_id)
Unregister a ucode overlay from the RSP queue engine.
Definition rspq.c:899
void * rspq_overlay_get_state(rsp_ucode_t *overlay_ucode)
Return a pointer to the overlay state (in RDRAM)
Definition rspq.c:708
void rspq_block_begin(void)
Begin creating a new block.
Definition rspq.c:1113
rspq_syncpoint_t rspq_syncpoint_new(void)
Create a syncpoint in the queue.
Definition rspq.c:1230
void rspq_highpri_sync(void)
Wait for the RSP to finish processing all high-priority queues.
Definition rspq.c:1100
#define RSPQ_MAX_COMMAND_SIZE
Maximum size of a command (in 32-bit words).
Definition rspq.h:181
rspq_write_t rspq_write_begin(uint32_t ovl_id, uint32_t cmd_id, int size)
Begin writing a new command into the RSP queue.
Definition rspq.h:476
void rspq_overlay_register_static(rsp_ucode_t *overlay_ucode, uint32_t overlay_id)
Register an overlay into the RSP queue engine assigning a static ID to it.
Definition rspq.c:892
int rspq_syncpoint_t
A syncpoint in the queue.
Definition rspq.h:221
rspq_block_t * rspq_block_end(void)
Finish creating a block.
Definition rspq.c:1132
bool is_first
true if we are waiting for the first argument word
Definition rspq.h:441
bool rspq_syncpoint_check(rspq_syncpoint_t sync_id)
Check whether a syncpoint was reached by RSP or not.
Definition rspq.c:1252
void rspq_block_free(rspq_block_t *block)
Free a block that is not needed any more.
Definition rspq.c:1152
void rspq_write_arg(rspq_write_t *w, uint32_t value)
Add one argument to the command being enqueued.
Definition rspq.h:517
void rspq_syncpoint_wait(rspq_syncpoint_t sync_id)
Wait until a syncpoint is reached by RSP.
Definition rspq.c:1258
void rspq_dma_to_dmem(uint32_t dmem_addr, void *rdram_addr, uint32_t len, bool is_async)
Enqueue a command to do a DMA transfer from RDRAM to DMEM.
Definition rspq.c:1309
void rspq_block_run(rspq_block_t *block)
Add to the RSP queue a command that runs a block.
Definition rspq.c:1188
void rspq_close(void)
Shut down the RSPQ library.
Definition rspq.c:673
void rspq_highpri_end(void)
Finish building the high-priority queue and close it.
Definition rspq.c:1084
void rspq_highpri_begin(void)
Start building a high-priority queue.
Definition rspq.c:1036
void rspq_noop(void)
Enqueue a no-op command in the queue.
Definition rspq.c:1225
void rspq_init(void)
Initialize the RSPQ library.
Definition rspq.c:584
void rspq_wait(void)
Wait until all commands in the queue have been executed by RSP.
Definition rspq.c:1278
void rspq_dma_to_rdram(void *rdram_addr, uint32_t dmem_addr, uint32_t len, bool is_async)
Enqueue a command to do a DMA transfer from DMEM to RDRAM.
Definition rspq.c:1304
A write cursor, returned by rspq_write_begin.
Definition rspq.h:437
A rspq block: pre-recorded array of commands.
Definition rspq_internal.h:161
RSP ucode definition.
Definition rsp.h:282