libdragon
Loading...
Searching...
No Matches
rspq.h
Go to the documentation of this file.
1
166#ifndef __LIBDRAGON_RSPQ_H
167#define __LIBDRAGON_RSPQ_H
168
169#include <stdint.h>
170#include <rsp.h>
171#include <debug.h>
172#include <n64sys.h>
173#include <pputils.h>
174
175#ifdef __cplusplus
176extern "C" {
177#endif
178
180#define RSPQ_MAX_COMMAND_SIZE 62
181
187#define RSPQ_MAX_SHORT_COMMAND_SIZE 16
188
200typedef struct rspq_block_s rspq_block_t;
201
221
232void rspq_init(void);
233
239void rspq_close(void);
240
241
274uint32_t rspq_overlay_register(rsp_ucode_t *overlay_ucode);
275
292void rspq_overlay_register_static(rsp_ucode_t *overlay_ucode, uint32_t overlay_id);
293
309void rspq_overlay_unregister(uint32_t overlay_id);
310
331void* rspq_overlay_get_state(rsp_ucode_t *overlay_ucode);
332
397#define rspq_write(ovl_id, cmd_id, ...) \
398 __PPCAT(_rspq_write, __HAS_VARARGS(__VA_ARGS__)) (ovl_id, cmd_id, ##__VA_ARGS__)
399
401
402// Helpers used to implement rspq_write
403#define _rspq_write_prolog() \
404 extern volatile uint32_t *rspq_cur_pointer, *rspq_cur_sentinel; \
405 extern void rspq_next_buffer(void); \
406 volatile uint32_t *ptr = rspq_cur_pointer+1; \
407 (void)ptr;
408
409#define _rspq_write_epilog() ({ \
410 if (__builtin_expect(rspq_cur_pointer > rspq_cur_sentinel, 0)) \
411 rspq_next_buffer(); \
412})
413
414#define _rspq_write_arg(arg) \
415 *ptr++ = (arg);
416
417#define _rspq_write0(ovl_id, cmd_id) ({ \
418 _rspq_write_prolog(); \
419 rspq_cur_pointer[0] = (ovl_id) + ((cmd_id)<<24); \
420 rspq_cur_pointer += 1; \
421 _rspq_write_epilog(); \
422})
423
424#define _rspq_write1(ovl_id, cmd_id, arg0, ...) ({ \
425 _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"); \
426 _rspq_write_prolog(); \
427 __CALL_FOREACH(_rspq_write_arg, ##__VA_ARGS__); \
428 rspq_cur_pointer[0] = ((ovl_id) + ((cmd_id)<<24)) | (arg0); \
429 rspq_cur_pointer += 1 + __COUNT_VARARGS(__VA_ARGS__); \
430 _rspq_write_epilog(); \
431})
432
434
436typedef struct {
437 uint32_t first_word;
438 volatile uint32_t *pointer;
439 volatile uint32_t *first;
440 bool is_first;
442
475inline rspq_write_t rspq_write_begin(uint32_t ovl_id, uint32_t cmd_id, int size) {
476 extern volatile uint32_t *rspq_cur_pointer, *rspq_cur_sentinel;
477 extern void rspq_next_buffer(void);
478
479 assertf(size <= RSPQ_MAX_COMMAND_SIZE, "The maximum command size is %d!", RSPQ_MAX_COMMAND_SIZE);
480
481 if (__builtin_expect(rspq_cur_pointer > rspq_cur_sentinel - size, 0))
483
484 volatile uint32_t *cur = rspq_cur_pointer;
485 rspq_cur_pointer += size;
486
487 return (rspq_write_t){
488 .first_word = ovl_id + (cmd_id<<24),
489 .pointer = cur + 1,
490 .first = cur,
491 .is_first = 1
492 };
493}
494
516inline void rspq_write_arg(rspq_write_t *w, uint32_t value) {
517 if (w->is_first) {
518 w->first_word |= value;
519 w->is_first = 0;
520 } else {
521 *w->pointer++ = value;
522 }
523}
524
540 *w->first = w->first_word;
541 w->first = 0;
542 w->pointer = 0;
543}
544
601void rspq_flush(void);
602
616void rspq_wait(void);
617
638
653
666
667
685void rspq_block_begin(void);
686
703
721void rspq_block_run(rspq_block_t *block);
722
735void rspq_block_free(rspq_block_t *block);
736
773void rspq_highpri_begin(void);
774
785void rspq_highpri_end(void);
786
795void rspq_highpri_sync(void);
796
803void rspq_noop(void);
804
820void rspq_dma_to_rdram(void *rdram_addr, uint32_t dmem_addr, uint32_t len, bool is_async);
821
837void rspq_dma_to_dmem(uint32_t dmem_addr, void *rdram_addr, uint32_t len, bool is_async);
838
840__attribute__((deprecated("may not work anymore. use rspq_syncpoint_new/rspq_syncpoint_check instead")))
841void rspq_signal(uint32_t signal);
844#ifdef __cplusplus
845}
846#endif
847
848#endif
Debugging Support.
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:946
volatile uint32_t * rspq_cur_pointer
Copy of the current write pointer (see rspq_ctx_t)
Definition rspq.c:314
volatile uint32_t * rspq_cur_sentinel
Copy of the current write sentinel (see rspq_ctx_t)
Definition rspq.c:315
uint32_t rspq_overlay_register(rsp_ucode_t *overlay_ucode)
Register a rspq overlay into the RSP queue engine.
Definition rspq.c:886
void rspq_write_end(rspq_write_t *w)
Finish enqueuing a command into the queue.
Definition rspq.h:539
volatile uint32_t * first
pointer to the first word of the command
Definition rspq.h:439
void rspq_flush(void)
Make sure that RSP starts executing up to the last written command.
Definition rspq.c:1026
uint32_t first_word
value that will be written as first word
Definition rspq.h:437
volatile uint32_t * pointer
current pointer into the RSP queue
Definition rspq.h:438
void rspq_overlay_unregister(uint32_t overlay_id)
Unregister a ucode overlay from the RSP queue engine.
Definition rspq.c:898
void * rspq_overlay_get_state(rsp_ucode_t *overlay_ucode)
Return a pointer to the overlay state (in RDRAM)
Definition rspq.c:707
void rspq_block_begin(void)
Begin creating a new block.
Definition rspq.c:1112
rspq_syncpoint_t rspq_syncpoint_new(void)
Create a syncpoint in the queue.
Definition rspq.c:1229
void rspq_highpri_sync(void)
Wait for the RSP to finish processing all high-priority queues.
Definition rspq.c:1099
#define RSPQ_MAX_COMMAND_SIZE
Maximum size of a command (in 32-bit words).
Definition rspq.h:180
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:475
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:891
int rspq_syncpoint_t
A syncpoint in the queue.
Definition rspq.h:220
rspq_block_t * rspq_block_end(void)
Finish creating a block.
Definition rspq.c:1131
bool is_first
true if we are waiting for the first argument word
Definition rspq.h:440
bool rspq_syncpoint_check(rspq_syncpoint_t sync_id)
Check whether a syncpoint was reached by RSP or not.
Definition rspq.c:1251
void rspq_block_free(rspq_block_t *block)
Free a block that is not needed any more.
Definition rspq.c:1151
void rspq_write_arg(rspq_write_t *w, uint32_t value)
Add one argument to the command being enqueued.
Definition rspq.h:516
void rspq_syncpoint_wait(rspq_syncpoint_t sync_id)
Wait until a syncpoint is reached by RSP.
Definition rspq.c:1257
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:1308
void rspq_block_run(rspq_block_t *block)
Add to the RSP queue a command that runs a block.
Definition rspq.c:1187
void rspq_close(void)
Shut down the RSPQ library.
Definition rspq.c:672
void rspq_highpri_end(void)
Finish building the high-priority queue and close it.
Definition rspq.c:1083
void rspq_highpri_begin(void)
Start building a high-priority queue.
Definition rspq.c:1035
void rspq_noop(void)
Enqueue a no-op command in the queue.
Definition rspq.c:1224
void rspq_init(void)
Initialize the RSPQ library.
Definition rspq.c:583
void rspq_wait(void)
Wait until all commands in the queue have been executed by RSP.
Definition rspq.c:1277
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:1303
A write cursor, returned by rspq_write_begin.
Definition rspq.h:436
A rspq block: pre-recorded array of commands.
Definition rspq_internal.h:160
RSP ucode definition.
Definition rsp.h:279