From 9182775637bee46ce04fd69cb62b1cc296cabfbb Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 23 Dec 2022 02:11:32 -0500 Subject: [PATCH] Fix KUSB enough to compile, move KUSB defines to KernelA.HH. --- src/Kernel/KUSB.ZC | 223 ++++++++++++++++++++---------------------- src/Kernel/KernelA.HH | 56 +++++++++++ 2 files changed, 162 insertions(+), 117 deletions(-) diff --git a/src/Kernel/KUSB.ZC b/src/Kernel/KUSB.ZC index b7058bee..1acbd05c 100644 --- a/src/Kernel/KUSB.ZC +++ b/src/Kernel/KUSB.ZC @@ -1,117 +1,106 @@ - -#define USBP_CMD 0x00 -#define USBP_STS 0x02 -#define USBP_INTR 0x04 -#define USBP_FRNUM 0x06 -#define USBP_FRBASEADD 0x08 -#define USBP_SOFMOD 0x0C -#define USBP_PORTSC0 0x10 -#define USBP_PORTSC1 0x12 -#define USB_NUM 16 - -class CUSBTD //Not implemented -{ - U32 td[4]; -}; - -class CUSB //Not implemented -{ - U8 num, //USB dev num - bus, dev, fun; - U16 ports, pad; - U32 *frame_lst; -}; - -//USB Pkt ID's -#define PID_OUT 0xE1 -#define PID_IN 0x69 -#define PID_SOF 0xA5 -#define PID_SETUP 0x2D -#define PID_DATA0 0xC3 -#define PID_DATA1 0x4B -#define PID_DATA2 0x87 -#define PID_MDATA 0x0F -#define PID_ACK 0xD2 -#define PID_NAK 0x5A -#define PID_STALL 0x1E -#define PID_NYET 0x96 -#define PID_PRE 0x3C -#define PID_ERR 0x3C -#define PID_SPLIT 0x78 -#define PID_PING 0xB4 - -//USB Std Rqsts -#define RQ_GET_STAT 0x0 -#define RQ_CLR_FEAT 0x1 -#define RQ_SET_FEAT 0x3 -#define RQ_SET_ADDR 0x5 -#define RQ_SET_DESC 0x7 -#define RQ_GET_CFG 0x8 -#define RQ_SET_CFG 0x9 -#define RQ_GET_INTERFACE 0xA -#define RQ_SET_INTERFACE 0xB -#define RQ_SYNC_FRAME 0xC - -I64 sys_num_usb = 0; -CUSB sys_usb_devs[USB_NUM]; -MemSet(sys_usb_devs, 0, USB_NUM * sizeof(CUSB)); - -U0 USBInitOne(I64 b, I64 d, I64 f) -{ - CUSB *u; - if (sys_num_usb < USB_NUM && PCIReadU16(b, d, f, 0) == 0x8086) - { - u = &sys_usb_devs[sys_num_usb++]; - u->num = sys_num_usb; - u->bus = b; - u->dev = d; - u->fun = f; - u->ports = PCIReadU32(b, d, f, 0x20) & ~0x1F; - } -} - -U0 USBEndAll() -{ - sys_num_usb = 0; -} - -U0 USBInitAll() //This is only valid for my ICH10 dev -{ - if (sys_num_usb) - USBEndAll; - USBInitOne(0, 29, 0); - USBInitOne(0, 29, 1); - USBInitOne(0, 29, 2); - USBInitOne(0, 29, 3); - USBInitOne(0, 26, 0); - USBInitOne(0, 26, 1); - USBInitOne(0, 26, 2); -} - -CUSBTD *USBAllocTD() -{ - return MAllocAligned(sizeof(CUSBTD), 0x10, dev.uncached_heap); -} - -U0 USBFreeTD(CUSBTD *tmptd) -{ - Free(tmptd); -} - -U32 *USBAllocFrameLst(I64 usb_num, I64 size) -{ - //aligned to 0x1000 - CUSB *u; - if (0 <= usb_num < sys_num_usb) - { - u = &sys_usb_devs[usb_num]; - Free(u->frame_lst); - u->frame_lst = MAllocAligned(size * sizeof(U32), 0x1000, dev.uncached_heap); - OutU16(u->ports + USBP_CMD, 0); //Stop - OutU16(u->ports + USBP_FRNUM, 0); - OutU32(u->ports + USBP_FRBASEADD, u->frame_lst); - return u->frame_lst; - } - - return NULL; -} + +#define USBP_CMD 0x00 +#define USBP_STS 0x02 +#define USBP_INTR 0x04 +#define USBP_FRNUM 0x06 +#define USBP_FRBASEADD 0x08 +#define USBP_SOFMOD 0x0C +#define USBP_PORTSC0 0x10 +#define USBP_PORTSC1 0x12 +#define USB_NUM 16 + +//USB Pkt ID's +#define PID_OUT 0xE1 +#define PID_IN 0x69 +#define PID_SOF 0xA5 +#define PID_SETUP 0x2D +#define PID_DATA0 0xC3 +#define PID_DATA1 0x4B +#define PID_DATA2 0x87 +#define PID_MDATA 0x0F +#define PID_ACK 0xD2 +#define PID_NAK 0x5A +#define PID_STALL 0x1E +#define PID_NYET 0x96 +#define PID_PRE 0x3C +#define PID_ERR 0x3C +#define PID_SPLIT 0x78 +#define PID_PING 0xB4 + +//USB Std Rqsts +#define RQ_GET_STAT 0x0 +#define RQ_CLR_FEAT 0x1 +#define RQ_SET_FEAT 0x3 +#define RQ_SET_ADDR 0x5 +#define RQ_SET_DESC 0x7 +#define RQ_GET_CFG 0x8 +#define RQ_SET_CFG 0x9 +#define RQ_GET_INTERFACE 0xA +#define RQ_SET_INTERFACE 0xB +#define RQ_SYNC_FRAME 0xC + +I64 sys_num_usb = 0; +CUSB sys_usb_devs[USB_NUM]; +MemSet(sys_usb_devs, 0, USB_NUM * sizeof(CUSB)); + +U0 USBInitOne(I64 b, I64 d, I64 f) +{ + CUSB *u; + if (sys_num_usb < USB_NUM && PCIReadU16(b, d, f, 0) == 0x8086) + { + u = &sys_usb_devs[sys_num_usb++]; + u->num = sys_num_usb; + u->bus = b; + u->dev = d; + u->fun = f; + u->ports = PCIReadU32(b, d, f, 0x20) & ~0x1F; + } +} + +U0 USBEndAll() +{ + sys_num_usb = 0; +} + +U0 USBInitAll() //This is only valid for my ICH10 dev +{ + if (sys_num_usb) + USBEndAll; + USBInitOne(0, 29, 0); + USBInitOne(0, 29, 1); + USBInitOne(0, 29, 2); + USBInitOne(0, 29, 3); + USBInitOne(0, 26, 0); + USBInitOne(0, 26, 1); + USBInitOne(0, 26, 2); +} + +CUSBTD *USBAllocTD() +{ +// return MAllocAligned(sizeof(CUSBTD), 0x10, dev.uncached_heap); + return MAllocAligned(sizeof(CUSBTD), 0x10, dev.uncached_alias + sys_task->code_heap); +} + +U0 USBFreeTD(CUSBTD *tmptd) +{ + Free(tmptd); +} + +U32 *USBAllocFrameLst(I64 usb_num, I64 size) +{ + //aligned to 0x1000 + CUSB *u; + if (0 <= usb_num < sys_num_usb) + { + u = &sys_usb_devs[usb_num]; + Free(u->frame_lst); +// u->frame_lst = MAllocAligned(size * sizeof(U32), 0x1000, dev.uncached_heap); + u->frame_lst = MAllocAligned(size * sizeof(U32), 0x1000, dev.uncached_alias + sys_task->code_heap); + OutU16(u->ports + USBP_CMD, 0); //Stop + OutU16(u->ports + USBP_FRNUM, 0); + OutU32(u->ports + USBP_FRBASEADD, u->frame_lst); + return u->frame_lst; + } + + return NULL; +} diff --git a/src/Kernel/KernelA.HH b/src/Kernel/KernelA.HH index 2f22b54f..8a1f7d29 100755 --- a/src/Kernel/KernelA.HH +++ b/src/Kernel/KernelA.HH @@ -3016,6 +3016,62 @@ class CAtapiModeWriteList #define ATAR0_CMD 7 #define ATAR1_CTRL 2 +#help_index "Devices;USB" +class CUSBTD //Not implemented +{ + U32 td[4]; +}; + +class CUSB //Not implemented +{ + U8 num, //USB dev num + bus, dev, fun; + U16 ports, pad; + U32 *frame_lst; +}; + +#define USBP_CMD 0x00 +#define USBP_STS 0x02 +#define USBP_INTR 0x04 +#define USBP_FRNUM 0x06 +#define USBP_FRBASEADD 0x08 +#define USBP_SOFMOD 0x0C +#define USBP_PORTSC0 0x10 +#define USBP_PORTSC1 0x12 +#define USB_NUM 16 + +//USB Pkt ID's +#define PID_OUT 0xE1 +#define PID_IN 0x69 +#define PID_SOF 0xA5 +#define PID_SETUP 0x2D +#define PID_DATA0 0xC3 +#define PID_DATA1 0x4B +#define PID_DATA2 0x87 +#define PID_MDATA 0x0F +#define PID_ACK 0xD2 +#define PID_NAK 0x5A +#define PID_STALL 0x1E +#define PID_NYET 0x96 +#define PID_PRE 0x3C +#define PID_ERR 0x3C +#define PID_SPLIT 0x78 +#define PID_PING 0xB4 + +//USB Std Rqsts +#define RQ_GET_STAT 0x0 +#define RQ_CLR_FEAT 0x1 +#define RQ_SET_FEAT 0x3 +#define RQ_SET_ADDR 0x5 +#define RQ_SET_DESC 0x7 +#define RQ_GET_CFG 0x8 +#define RQ_SET_CFG 0x9 +#define RQ_GET_INTERFACE 0xA +#define RQ_SET_INTERFACE 0xB +#define RQ_SYNC_FRAME 0xC + + + #help_index "File/FileNames" #define FILEMASK_JIT "*.ZC*;*.HH*" #define FILEMASK_AOT "*.ZC*;*.HH*;*.PRJ*"