19#include "irx_imports.h"
25#define OHCI_REG_BASE 0xBF801600
28#define dbg_printf(a...) printf("usbd: " a)
30#define dbg_printf(a...) (void)0
33#define READ_UINT16(a) (((u8 *)a)[0] | (((u8 *)a)[1] << 8))
47 int m_maxIsoTransfDesc;
49 int m_maxStaticDescSize;
52 int m_allocatedSize_unused;
69typedef void (*TimerCallback)(
void *arg);
70typedef void (*InternCallback)(
struct _ioRequest *arg);
77 TimerCallback m_callbackProc;
92 InternCallback m_callbackProc;
94 u32 m_transferedBytes;
96 void *m_userCallbackArg;
99 void *m_userCallbackProc;
100 sceUsbdDoneCallback m_userCallbackProcRegular;
101 sceUsbdMultiIsochronousDoneCallback m_userCallbackProcMultiIsochronous;
116 u8 m_functionAddress;
117 u8 m_isLowSpeedDevice;
119 u32 m_magicPowerValue;
120 struct _device *m_childListStart;
121 struct _device *m_childListEnd;
123 u32 m_attachedToPortNo;
124 void *m_privDataField;
128 void *m_staticDeviceDescPtr;
129 void *m_staticDeviceDescEndPtr;
130 u32 m_fetchDescriptorCounter;
140 struct _hcTd *m_next;
170 struct _hcEd *m_next;
186 u32 m_isochronLastFrameNum;
189 u8 m_schedulingIndex;
192 u8 m_packetSizeForScheduling;
199 u32 m_curAllocatedCount;
209 u32 m_numChildDevices;
211 u32 m_hubStatusCounter;
213 u16 m_hubStatusChange;
214 u32 m_portStatusChange;
215 u8 m_statusChangeInfo[8];
222 volatile u16 FrameNumber;
225 volatile u8 reserved[116];
231 volatile u32 HcRevision;
232 volatile u32 HcControl;
233 volatile u32 HcCommandStatus;
234 volatile u32 HcInterruptStatus;
235 volatile u32 HcInterruptEnable;
236 volatile u32 HcInterruptDisable;
237 volatile HcCA *HcHCCA;
243 volatile u32 HcDoneHead;
244 volatile u32 HcFmInterval;
245 volatile u32 HcFmRemaining;
246 volatile u32 HcFmNumber;
247 volatile u32 HcPeriodicStart;
248 volatile u32 HcLsThreshold;
249 volatile u32 HcRhDescriptorA;
250 volatile u32 HcRhDescriptorB;
251 volatile u32 HcRhStatus;
252 volatile u32 HcRhPortStatus[2];
258 volatile HcCA *m_hcHCCA;
260 struct _hcEd *m_hcEdBuf;
262 struct _hcTd *m_freeHcTdList;
263 struct _hcTd *m_hcTdBuf;
264 struct _hcTd *m_hcTdBufEnd;
277 struct _device *m_deviceTreeBuf;
278 struct _device *m_freeDeviceListStart;
279 struct _device *m_freeDeviceListEnd;
288 u32 m_interruptBandwidthSchedulingValues[32];
290 int m_interruptCounters[9];
295 struct _device *m_deviceTreeRoot;
321#define TYPE_CONTROL 0x3F
322#define TYPE_BULK 0x40
323#define TYPE_ISOCHRON 0x41
325#define DEVICE_NOTCONNECTED 1
326#define DEVICE_CONNECTED 3
327#define DEVICE_RESETDELAYED 4
328#define DEVICE_RESETPENDING 5
329#define DEVICE_RESETCOMPLETE 6
330#define DEVICE_FETCHINGDESCRIPTOR 7
331#define DEVICE_READY 8
333#define PORT_CONNECTION 0
335#define PORT_SUSPEND 2
336#define PORT_OVER_CURRENT 3
339#define PORT_LOW_SPEED 9
341#define C_HUB_LOCAL_POWER 0
342#define C_HUB_OVER_CURRENT 1
344#define C_PORT_CONNECTION 16
345#define C_PORT_ENABLE 17
346#define C_PORT_SUSPEND 18
347#define C_PORT_OVER_CURRENT 19
348#define C_PORT_RESET 20
350#define BIT(x) (((u32)1) << (x))
352#define C_PORT_FLAGS \
353 (BIT(C_PORT_CONNECTION) | BIT(C_PORT_ENABLE) | BIT(C_PORT_SUSPEND) | BIT(C_PORT_OVER_CURRENT) | BIT(C_PORT_RESET))
355#define HCED_DIR_OUT BIT(11)
356#define HCED_DIR_IN BIT(12)
357#define HCED_SPEED BIT(13)
358#define HCED_SKIP BIT(14)
359#define HCED_ISOC BIT(15)
360#define HCED_DIR_MASK (HCED_DIR_OUT | HCED_DIR_IN)
362#define ED_HALTED(a) ((u32)((a).m_tdHead) & 1)
363#define ED_SKIPPED(a) ((u32)((a).m_hcArea.stru.m_hcArea) & HCED_SKIP)
365#define TD_HCAREA(CC, T, DI, DP, R) (u32)((((CC) << 12) | ((T) << 8) | ((DI) << 5) | ((DP) << 3) | ((R) << 2)))
371#define OHCI_INT_SO BIT(0)
372#define OHCI_INT_WDH BIT(1)
373#define OHCI_INT_SF BIT(2)
374#define OHCI_INT_RD BIT(3)
375#define OHCI_INT_UE BIT(4)
376#define OHCI_INT_FNO BIT(5)
377#define OHCI_INT_RHSC BIT(6)
378#define OHCI_INT_OC BIT(30)
379#define OHCI_INT_MIE BIT(31)
381#define OHCI_COM_HCR BIT(0)
382#define OHCI_COM_CLF BIT(1)
383#define OHCI_COM_BLF BIT(2)
385#define OHCI_CTR_CBSR (3 << 0)
386#define OHCI_CTR_PLE BIT(2)
387#define OHCI_CTR_IE BIT(3)
388#define OHCI_CTR_CLE BIT(4)
389#define OHCI_CTR_BLE BIT(5)
390#define OHCI_CTR_USB_RESET (0 << 6)
391#define OHCI_CTR_USB_RESUME (1 << 6)
392#define OHCI_CTR_USB_OPERATIONAL (2 << 6)
393#define OHCI_CTR_USB_SUSPEND (3 << 6)
397extern int initHubDriver(
void);
398extern void deinitHubDriver(
void);
416extern int addTimerCallback(
UsbdTimerCbStruct_t *arg, TimerCallback func,
void *cbArg,
int delay);
418extern void handleTimerList(
void);
428extern void usbdRebootInner(
void);
431extern void handleRhsc(
void);
434extern void processDoneQueue_GenTd(
UsbdHcTD_t *arg);
438extern void hcdProcessIntr(
void);
439extern void PostIntrEnableFunction(
void);
440extern int initHcdStructs(
void);
441extern void deinitHcd(
void);
444extern void *AllocSysMemoryWrap(
int size);
445extern int FreeSysMemoryWrap(
void *ptr);
446extern int usbdLock(
void);
447extern int usbdUnlock(
void);
450extern void usbdReboot(
int ac);
457extern int callUsbDriverFunc(
int (*func)(
int devId),
int devId,
void *gpSeg);
458extern int doRegisterDriver(
sceUsbdLddOps *drv,
void *drvGpSeg);
459extern int doRegisterAutoLoader(
sceUsbdLddOps *drv,
void *drvGpSeg);
461extern int doUnregisterAutoLoader(
void);
464extern void *doGetDeviceStaticDescriptor(
int devId,
void *data, u8 type);
465extern int doGetDeviceLocation(
UsbdDevice_t *dev, u8 *path);
469extern int doControlTransfer(
481extern int usbdInitInner(
void);