37 #include <sys/cdefs.h>
41 #include <sys/queue.h>
49 #define MAPLE_DMA_DEBUG 0
58 #define MAPLE_IRQ_DEBUG 0
67 #define MAPLE_BASE 0xa05f6c00
68 #define MAPLE_DMAADDR (MAPLE_BASE+0x04)
69 #define MAPLE_RESET2 (MAPLE_BASE+0x10)
70 #define MAPLE_ENABLE (MAPLE_BASE+0x14)
71 #define MAPLE_STATE (MAPLE_BASE+0x18)
72 #define MAPLE_SPEED (MAPLE_BASE+0x80)
73 #define MAPLE_RESET1 (MAPLE_BASE+0x8c)
83 #define MAPLE_RESET2_MAGIC 0
84 #define MAPLE_ENABLE_ENABLED 1
85 #define MAPLE_ENABLE_DISABLED 0
86 #define MAPLE_STATE_IDLE 0
87 #define MAPLE_STATE_DMA 1
88 #define MAPLE_SPEED_2MBPS 0
89 #define MAPLE_SPEED_TIMEOUT(n) ((n) << 16)
90 #define MAPLE_RESET1_MAGIC 0x6155404f
100 #define MAPLE_RESPONSE_FILEERR -5
101 #define MAPLE_RESPONSE_AGAIN -4
102 #define MAPLE_RESPONSE_BADCMD -3
103 #define MAPLE_RESPONSE_BADFUNC -2
104 #define MAPLE_RESPONSE_NONE -1
105 #define MAPLE_COMMAND_DEVINFO 1
106 #define MAPLE_COMMAND_ALLINFO 2
107 #define MAPLE_COMMAND_RESET 3
108 #define MAPLE_COMMAND_KILL 4
109 #define MAPLE_RESPONSE_DEVINFO 5
110 #define MAPLE_RESPONSE_ALLINFO 6
111 #define MAPLE_RESPONSE_OK 7
112 #define MAPLE_RESPONSE_DATATRF 8
113 #define MAPLE_COMMAND_GETCOND 9
114 #define MAPLE_COMMAND_GETMINFO 10
115 #define MAPLE_COMMAND_BREAD 11
116 #define MAPLE_COMMAND_BWRITE 12
117 #define MAPLE_COMMAND_BSYNC 13
118 #define MAPLE_COMMAND_SETCOND 14
119 #define MAPLE_COMMAND_MICCONTROL 15
120 #define MAPLE_COMMAND_CAMCONTROL 17
135 #define MAPLE_FUNC_PURUPURU 0x00010000
136 #define MAPLE_FUNC_MOUSE 0x00020000
137 #define MAPLE_FUNC_CAMERA 0x00080000
138 #define MAPLE_FUNC_CONTROLLER 0x01000000
139 #define MAPLE_FUNC_MEMCARD 0x02000000
140 #define MAPLE_FUNC_LCD 0x04000000
141 #define MAPLE_FUNC_CLOCK 0x08000000
142 #define MAPLE_FUNC_MICROPHONE 0x10000000
143 #define MAPLE_FUNC_ARGUN 0x20000000
144 #define MAPLE_FUNC_KEYBOARD 0x40000000
145 #define MAPLE_FUNC_LIGHTGUN 0x80000000
191 #define MAPLE_FRAME_VACANT 0
192 #define MAPLE_FRAME_UNSENT 1
193 #define MAPLE_FRAME_SENT 2
194 #define MAPLE_FRAME_RESPONDED 3
253 #define MAPLE_PORT_COUNT 4
254 #define MAPLE_UNIT_COUNT 6
364 #define MAPLE_DMA_SIZE 16384
369 #define maple_read(A) ( *((vuint32*)(A)) )
372 #define maple_write(A, V) ( *((vuint32*)(A)) = (V) )
379 #define MAPLE_EFAIL -1
380 #define MAPLE_EAGAIN -2
381 #define MAPLE_EINVALID -3
382 #define MAPLE_ENOTSUPP -4
383 #define MAPLE_ETIMEOUT -5
487 void maple_sentinel_setup(
void * buffer,
int bufsize);
494 void maple_sentinel_verify(
const char * bufname,
void * buffer,
int bufsize);
689 #define MAPLE_FOREACH_BEGIN(TYPE, VARTYPE, VAR) \
691 maple_device_t * __dev; \
696 while ( (__dev = maple_enum_type(__i, TYPE)) ) { \
697 VAR = (VARTYPE *)maple_dev_status(__dev); \
705 #define MAPLE_FOREACH_END() \
uint8 connector_direction
?
Definition: maple.h:208
Internal representation of a Maple port.
Definition: maple.h:263
volatile int dma_in_progress
Is a DMA running now?
Definition: maple.h:345
void * send_buf
The data which will be sent (if any)
Definition: maple.h:174
volatile int vbl_cntr
VBlank interrupt counter.
Definition: maple.h:339
struct maple_device maple_device_t
One maple device.
char product_license[60]
License statement.
Definition: maple.h:210
int maple_frame_lock(maple_frame_t *frame)
Lock a frame so that someone else can't use it in the mean time.
void maple_raddr(uint8 addr, int *port, int *unit)
Decompose a "maple address" into a port, unit pair.
volatile int state
Has this frame been sent / responded to?
Definition: maple.h:171
uint32 function_data[3]
Additional data per function.
Definition: maple.h:206
LIST_ENTRY(maple_driver) drv_list
Driver list handle. NOT A FUNCTION!
int maple_driver_attach(maple_frame_t *det)
Attach a maple device to a driver, if possible.
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
void * maple_dev_status(maple_device_t *dev)
Get the status struct for the requested maple device.
struct maple_device * dev
Does this belong to a device?
Definition: maple.h:177
Maple frame to be queued for transport.
Definition: maple.h:163
int maple_driver_reg(maple_driver_t *driver)
Register a maple device driver.
volatile int queued
Are we on the queue?
Definition: maple.h:172
uint8 area_code
Region code.
Definition: maple.h:207
void maple_shutdown()
Shutdown Maple.
char product_name[30]
Name of device.
Definition: maple.h:209
struct maple_frame_queue frame_queue
Maple frame submission queue. Do not manipulate directly!
Definition: maple.h:330
int maple_driver_detach(int p, int u)
Detach an attached maple device.
int maple_init()
Initialize Maple.
One maple device.
Definition: maple.h:237
int port
Maple bus port connected to.
Definition: maple.h:240
maple_port_t ports[MAPLE_PORT_COUNT]
Maple device info structure.
Definition: maple.h:333
int detect_unit_next
Next unit which will be auto-detected.
Definition: maple.h:351
uint8 src_addr
Source address.
Definition: maple.h:225
A maple device driver.
Definition: maple.h:278
void maple_dma_irq_hnd(uint32 code)
Called after a Maple DMA send / receive pair completes.
struct maple_response maple_response_t
Maple response frame structure.
int dst_port
Destination port.
Definition: maple.h:168
void maple_dma_start()
Start a Maple DMA.
#define MAPLE_UNIT_COUNT
Max number of units per port.
Definition: maple.h:254
int dev_mask
Device-present mask for unit 0's.
Definition: maple.h:245
#define MAPLE_PORT_COUNT
Number of ports on the bus.
Definition: maple.h:253
uint8 data[0]
Data (if any)
Definition: maple.h:227
void maple_bus_enable()
Enable the Maple bus.
Maple device info structure.
Definition: maple.h:204
void maple_frame_unlock(maple_frame_t *frame)
Unlock a frame.
void maple_queue_flush()
Send all queued frames.
int maple_dev_valid(int p, int u)
Determine if a given device is valid.
int unit
Unit number, off of the port.
Definition: maple.h:241
void maple_vbl_irq_hnd(uint32 code)
Called on every VBL (~60fps).
const char * maple_perror(int response)
Return a string representing the maple response code.
maple_frame_t frame
One rx/tx frame.
Definition: maple.h:246
void(* periodic)(struct maple_driver *drv)
Periodic polling callback.
Definition: maple.h:294
unsigned short uint16
16-bit unsigned integer
Definition: types.h:29
maple_state_t maple_state
Global state info.
struct maple_frame maple_frame_t
Maple frame to be queued for transport.
int maple_driver_unreg(maple_driver_t *driver)
Unregister a maple device driver.
void(* callback)(struct maple_frame *)
Response callback.
Definition: maple.h:179
maple_devinfo_t info
Device info struct.
Definition: maple.h:242
uint8 * recv_buf
Points into recv_buf_arr, but 32-byte aligned.
Definition: maple.h:175
void maple_frame_init(maple_frame_t *frame)
Initialize a new frame to prepare it to be placed on the queue.
Maple response frame structure.
Definition: maple.h:222
uint8 recv_buf_arr[1024+32]
Response receive area.
Definition: maple.h:184
void maple_bus_disable()
Disable the Maple bus.
uint32 functions
One or more MAPLE_FUNCs ORed together.
Definition: maple.h:282
uint32 functions
Function codes supported.
Definition: maple.h:205
maple_device_t units[MAPLE_UNIT_COUNT]
Pointers to active units.
Definition: maple.h:265
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
uint8 dst_addr
Destination address.
Definition: maple.h:224
int cmd
Command (see Maple commands and responses)
Definition: maple.h:167
int length
Data transfer length in 32-bit words.
Definition: maple.h:170
int vbl_handle
Our vblank handler handle.
Definition: maple.h:357
uint16 max_power
Power consumption (max)
Definition: maple.h:212
void(* detach)(struct maple_driver *drv, maple_device_t *dev)
Device detached callback.
Definition: maple.h:315
int8 response
Response.
Definition: maple.h:223
struct maple_devinfo maple_devinfo_t
Maple device info structure.
volatile int status_valid
Have we got our first status update?
Definition: maple.h:249
int maple_queue_frame(maple_frame_t *frame)
Submit a frame for queueing.
int detect_port_next
Next port that will be auto-detected.
Definition: maple.h:348
int dst_unit
Destination unit.
Definition: maple.h:169
unsigned char uint8
8-bit unsigned integer
Definition: types.h:30
uint8 data_len
Data length (in 32-bit words)
Definition: maple.h:226
uint16 standby_power
Power consumption (standby)
Definition: maple.h:211
const char * name
The driver name.
Definition: maple.h:283
void maple_dma_stop()
Stop a Maple DMA.
int maple_driver_foreach(maple_driver_t *drv, int(*callback)(maple_device_t *))
For each device which the given driver controls, call the callback.
void maple_wait_scan()
Wait for the initial bus scan to complete.
uint8 * dma_buffer
DMA send buffer.
Definition: maple.h:342
struct maple_driver_list driver_list
Maple device driver list. Do not manipulate directly!
Definition: maple.h:327
int maple_dma_in_progress()
Is a Maple DMA in progress?
int port
Port ID.
Definition: maple.h:264
Maple state structure.
Definition: maple.h:325
const char * maple_pcaps(uint32 functions)
Return a string with the capabilities of a given function code.
uint8 maple_addr(int port, int unit)
Return a "maple address" for a port, unit pair.
maple_device_t * maple_enum_type_ex(int n, uint32 func, uint32 cap)
Return the Nth device that is of the requested type and supports the list of capabilities given...
int maple_queue_remove(maple_frame_t *frame)
Remove a used frame from the queue.
struct maple_driver * drv
Driver which handles this device.
Definition: maple.h:247
maple_device_t * maple_enum_dev(int p, int u)
Get a raw device info struct for the given device.
volatile int detect_wrapped
Did the detect wrap?
Definition: maple.h:354
maple_device_t * maple_enum_type(int n, uint32 func)
Get the Nth device of the requested type (where N is zero-indexed).
TAILQ_ENTRY(maple_frame) frameq
Send queue handle. NOT A FUNCTION!
char int8
8-bit signed integer
Definition: types.h:34
int valid
Is this a valid device?
Definition: maple.h:239
int(* attach)(struct maple_driver *drv, maple_device_t *dev)
Device attached callback.
Definition: maple.h:305
uint8 status[1024]
Status buffer (for pollable devices)
Definition: maple.h:250
struct maple_driver maple_driver_t
A maple device driver.
void maple_dma_addr(void *ptr)
Set the Maple DMA address.
struct maple_state_str maple_state_t
Maple state structure.
volatile int dma_cntr
DMA interrupt counter.
Definition: maple.h:336
int maple_enum_count()
Return the number of connected devices.
struct maple_port maple_port_t
Internal representation of a Maple port.