osint_usb.h 3.98 KB
#ifndef _OSINT_USB_H_
#define _OSINT_USB_H_

/*---------------------------------------------------------------------*
        Copyright (C) 2003 BroadOn Communications Corp.
        
        $RCSfile: osint_usb.h,v $
        $Revision: 1.13 $
        $Date: 2004/07/08 22:46:06 $
 *---------------------------------------------------------------------*/

#ifdef MIPSEB
#define BIG_ENDIAN 1
#endif
#include <PR/region.h>
#include <PR/os_usb.h>
#include <PR/bcp.h>
#include <assert.h>
#include <arcusb.h>

/***************************************
 *
 * Type definitions
 *
 */

/*
 * USB Manager Message
 */
typedef struct __OSBbUsbMesg_s {
	u8	um_type;
	union {
		struct {
			OSBbUsbInfo *umq_info;
			s32 umq_ninfo;
		} umq;
		struct {
			OSBbUsbInfo *umh_info;
			OSBbUsbHandle umh_handle;
		} umh;
		struct {
			OSBbUsbHandle umrw_handle;
			u8 *umrw_buffer;
			s32 umrw_len;
			u64 umrw_offset;
		} umrw;
	} u;
	s32	um_ret;
	OSMesgQueue *um_rq;	/* reply queue */
} __OSBbUsbMesg;

/*
 * State structure per controller
 */
typedef struct _usb_ctlr_state_s {
	int     ucs_mode;	/* current mode of controller */
	int     ucs_mask;	/* controls what modes controller can assume */
} _usb_ctlr_state_t;

/***************************************
 *
 * Macro definitions
 *
 */
#define USB_REG_ADDR(ctlr,u0reg)	(((ctlr)?USB1_BASE_REG:USB0_BASE_REG)+\
		((u0reg) - USB0_BASE_REG))
#define USB_BDT_BASE(ctlr)	((ctlr)?USB1_BDT_SRAM:USB0_BDT_SRAM)
#define USB_BDT_SIZE		512	/* bytes */

#define MIN(a,b) ((a) < (b) ? (a) : (b))

/*
 * Libultra doesn't seem to have any endianness munging support,
 * so we have to roll our own.  Try this in C first and see whether
 * it is worth rewriting in asm.
 */
#ifdef BIG_ENDIAN
#define swab32(in) (((in) & 0xff) << 24 | \
			((in) & 0xff00) << 8 | \
			((in) & 0xff0000) >> 8 | \
			(((in) >> 24) & 0xff))
#define swab16(in) ((((in) & 0xff) << 8) | (((in) & 0xff00) >> 8))
#else
#define swab32(in) (in)
#define swab16(in) (in)
#endif

/*
 * USB Subsystem parameters
 */
#define	OS_USB_MGR_STACKSIZE	0x2000
#define	OS_USB_TID_BASE		3141
#define	OS_USB_THREAD_PRI_HOST	230
#define	OS_USB_THREAD_PRI_DEV	232
#define	OS_USB_MAX_DRIVERS	4	/* host drivers present per system */
#define	OS_USB_MAX_DEVICES	4	/* per system */
#define	OS_USB_MAX_HANDLES	4	/* per system */
#define	OS_USB_MAX_PIPES	16	/* per device */
#define	OS_USB_MAX_ENDPTS	16	/* per device */
#define	OS_USB_SVC_CALLBACK_SIZE	512
#define	OS_USB_ENDPT_DESC_SIZE	(OS_USB_MAX_DEVICES * OS_USB_MAX_ENDPTS * sizeof (XD_STRUCT))
#define ECHO_DEV	(OS_USB_MAX_DEVICES - 1)

/*
 * USB manager message types
 */
#define OS_USB_MESG_INT0	0
#define OS_USB_MESG_INT1	1
#define OS_USB_MESG_QUERY	2
#define OS_USB_MESG_HANDLE	3
#define OS_USB_MESG_READ	4
#define OS_USB_MESG_WRITE	5

#define OS_USB_REPLY_MASK	0x80
#define OS_USB_REPLY_QUERY	(OS_USB_REPLY_MASK|OS_USB_MESG_QUERY)
#define OS_USB_REPLY_HANDLE	(OS_USB_REPLY_MASK|OS_USB_MESG_HANDLE)
#define OS_USB_REPLY_READ	(OS_USB_REPLY_MASK|OS_USB_MESG_READ)
#define OS_USB_REPLY_WRITE	(OS_USB_REPLY_MASK|OS_USB_MESG_WRITE)

#define	UCS_MODE_IDLE	OS_USB_TYPE_DISABLED
#define	UCS_MODE_HOST	OS_USB_TYPE_HOST
#define	UCS_MODE_DEVICE	OS_USB_TYPE_DEVICE

/***************************************
 *
 * Extern data declarations
 *
 */

extern OSMesgQueue     __osBbUsbCtlrQ[];
extern void *__usb_svc_callback_reg;
extern void *__usb_endpt_desc_reg;
extern _usb_host_handle     __osArcHostHandle[];
extern _usb_device_handle   __osArcDeviceHandle[];
extern _usb_ctlr_state_t    _usb_ctlr_state[];

/***************************************
 *
 * Extern function prototypes
 *
 */

extern s32 __usbHwInit();
extern s32 __usbDevInterrupt(s32);
extern void __usbInvalidateHandles(s32);
extern void _usb_bdt_copy_swab(HOST_BDT_STRUCT_PTR, HOST_BDT_STRUCT_PTR);
extern void __usb_splhigh(void);
extern void __usb_splx(void);

/*
 * Paper over the different declarations of BDT structs between Host and Device
 */
#define _usb_bdt_copy_swab_d(f, t) \
	_usb_bdt_copy_swab((HOST_BDT_STRUCT_PTR)(f), (HOST_BDT_STRUCT_PTR)(t));

#endif  /* _OSINT_USB_H_ */