From d0845ccadeb360203693b13138c905446d273ee5 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 10 May 2023 17:09:13 +0600 Subject: [PATCH] usb: Infrastructure changes Make OHCI OwnershipChange work properly --- src/chipset/ali1543.c | 1 + src/chipset/ali6117.c | 1 - src/chipset/intel_piix.c | 1 + src/chipset/sis_5571.c | 1 + src/chipset/stpc.c | 1 + src/chipset/via_pipc.c | 1 + src/include/86box/usb.h | 96 ++++++++++++++++++++++++++++------------ src/usb.c | 4 +- 8 files changed, 76 insertions(+), 30 deletions(-) diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index 2e2f74305..26673edec 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/timer.h> diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 98451067a..796ca880f 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -30,7 +30,6 @@ #include <86box/pit.h> #include <86box/device.h> #include <86box/port_92.h> -#include <86box/usb.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/chipset.h> diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 470978611..f550d9503 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -23,6 +23,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index c158e2d63..a20f5fadd 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index 2e4b045f2..822f462ad 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/mem.h> diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index c2abc4465..067b733a2 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -26,6 +26,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index d94d8a137..455282f71 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -23,6 +23,7 @@ extern "C" { #endif typedef struct usb_t usb_t; +typedef struct usb_device_t usb_device_t; enum usb_pid { @@ -39,22 +40,6 @@ enum usb_errors USB_ERROR_UNDERRUN = 3 }; -/* USB endpoint device struct. Incomplete and unused. */ -typedef struct -{ - uint16_t vendor_id; - uint16_t device_id; - - /* General-purpose function for I/O. Non-zero value indicates error. */ - uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); - /* Device reset. */ - void (*device_reset)(void* priv); - /* Get address. */ - uint8_t (*device_get_address)(void* priv); - - void* priv; -} usb_device_t; - enum usb_bus_types { USB_BUS_OHCI = 0, @@ -107,6 +92,35 @@ typedef struct uint8_t bDescriptorType; } usb_desc_base_t; +typedef struct +{ + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} usb_desc_setup_t; + +typedef struct +{ + usb_desc_base_t base; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} usb_desc_endpoint_t; + +typedef struct +{ + usb_desc_base_t base; + + uint16_t bcdHID; + uint8_t bCountryCode; + uint8_t bNumDescriptors; + uint8_t bDescriptorType; + uint16_t wDescriptorLength; +} usb_desc_hid_t; + typedef struct { usb_desc_base_t base; @@ -123,16 +137,7 @@ typedef struct typedef struct { usb_desc_base_t base; - uint8_t bEndpointAddress; - uint8_t bmAttributes; - uint8_t wMaxPacketSize; - uint8_t bInterval; -} usb_desc_endpoint_t; - -typedef struct -{ - usb_desc_base_t base; - uint16_t bString[]; + char16_t bString[]; } usb_desc_string_t; typedef struct @@ -145,12 +150,47 @@ typedef struct uint8_t iConfiguration; uint8_t bmAttributes; uint8_t bMaxPower; - - usb_desc_interface_t interface_descs[]; } usb_desc_conf_t; +typedef struct +{ + usb_desc_base_t base; + + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} usb_desc_device_t; + #pragma pack(pop) +/* USB endpoint device struct. Incomplete and unused. */ +typedef struct usb_device_t +{ + usb_desc_device_t device_desc; + struct { + usb_desc_conf_t conf_desc; + usb_desc_base_t* other_descs[16]; + } conf_desc_items; + + /* General-purpose function for I/O. Non-zero value indicates error. */ + uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); + /* Device reset. */ + void (*device_reset)(void* priv); + /* Get address. */ + uint8_t (*device_get_address)(void* priv); + + void* priv; +} usb_device_t; + /* Global variables. */ extern const device_t usb_device; extern usb_t* usb_device_inst; diff --git a/src/usb.c b/src/usb.c index 894e0a864..5d661bd72 100644 --- a/src/usb.c +++ b/src/usb.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #define HAVE_STDARG_H #include <86box/86box.h> @@ -702,8 +703,9 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) /* bit OwnershipChangeRequest triggers an ownership change (SMM <-> OS) */ if (val & 0x08) { dev->ohci_mmio[OHCI_HcInterruptStatus].b[3] = 0x40; - if ((dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] & 0xc0) == 0xc0) + if ((dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] & 0x40) == 0x40) { smi_raise(); + } } /* bit HostControllerReset must be cleared for the controller to be seen as initialized */