USB: initial merge relatively complete, linking issues left

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-11-02 19:21:45 +01:00 committed by refractionpcsx2
parent eb4089657e
commit d33eff635b
20 changed files with 61 additions and 81 deletions

View File

@ -78,16 +78,6 @@ Config::Config(): Log(0)
memset(&WheelType, 0, sizeof(WheelType));
}
void __Log(const char *fmt, ...) {
va_list list;
if (!conf.Log ||!usbLog) return;
va_start(list, fmt);
vfprintf(usbLog, fmt, list);
va_end(list);
}
//Simpler to reset and reattach after USBclose/USBopen
void Reset()
{

View File

@ -35,9 +35,9 @@ std::string GetSelectedAPI(const std::pair<int, std::string>& pair)
bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, TSTDSTRING& value)
{
CIniKey *key;
auto sect = ciniFile.GetSection(section);
if (sect && (key = sect->GetKey(param))) {
value = key->GetValue();
auto sect = ciniFile.GetSection(str_to_wstr(section));
if (sect && (key = sect->GetKey(str_to_wstr(param)))) {
value = wstr_to_str(key->GetValue());
return true;
}
return false;
@ -46,8 +46,8 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC
bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, int32_t& value)
{
CIniKey *key;
auto sect = ciniFile.GetSection(section);
if (sect && (key = sect->GetKey(param))) {
auto sect = ciniFile.GetSection(str_to_wstr(section));
if (sect && (key = sect->GetKey(str_to_wstr(param)))) {
try {
value = std::stoi(key->GetValue());
return true;
@ -61,19 +61,19 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC
bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, const TSTDSTRING& value)
{
ciniFile.SetKeyValue(section, param, value);
ciniFile.SetKeyValue(str_to_wstr(section), str_to_wstr(param), str_to_wstr(value));
return true;
}
bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, int32_t value)
{
ciniFile.SetKeyValue(section, param, TSTDTOSTRING(value));
ciniFile.SetKeyValue(str_to_wstr(section), str_to_wstr(param), str_to_wstr(TSTDTOSTRING(value)));
return true;
}
void SaveConfig() {
SaveSetting(_T("MAIN"), _T("log"), conf.Log);
SaveSetting("MAIN", "log", conf.Log);
SaveSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, conf.Port[0]);
SaveSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, conf.Port[1]);
@ -86,15 +86,15 @@ void SaveConfig() {
SaveSetting(nullptr, k.first.first, k.first.second, N_DEVICE_API, k.second);
}
bool ret = ciniFile.Save(IniPath);
ciniFile.Save(str_to_wstr(IniPath));
OSDebugOut(_T("ciniFile.Save: %d [%s]\n"), ret, IniPath.c_str());
}
void LoadConfig() {
std::cerr << "USB load config\n" << std::endl;
ciniFile.Load(IniPath);
ciniFile.Load(str_to_wstr(IniPath));
LoadSetting(_T("MAIN"), _T("log"), conf.Log);
LoadSetting("MAIN", "log", conf.Log);
LoadSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, conf.Port[0]);
LoadSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, conf.Port[1]);
@ -133,7 +133,7 @@ void LoadConfig() {
void ClearSection(const TCHAR* section)
{
auto s = ciniFile.GetSection(section);
auto s = ciniFile.GetSection(str_to_wstr(section));
if (s) {
s->RemoveAllKeys();
}

View File

@ -23,7 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "osdebugout.h"
#include "../osdebugout.h"
#include "../platcompat.h"
#include "vl.h"
#include "iov.h"
//#include "trace.h"
@ -39,7 +40,7 @@ void usb_pick_speed(USBPort *port)
USBDevice *udev = port->dev;
int i;
for (i = 0; i < ARRAY_SIZE(speeds); i++) {
for (i = 0; i < (int)ARRAY_SIZE(speeds); i++) {
if ((udev->speedmask & (1 << speeds[i])) &&
(port->speedmask & (1 << speeds[i]))) {
udev->speed = speeds[i];
@ -138,7 +139,7 @@ static void do_token_setup(USBDevice *s, USBPacket *p)
s->setup_index = 0;
p->actual_length = 0;
s->setup_len = (s->setup_buf[7] << 8) | s->setup_buf[6];
if (s->setup_len > sizeof(s->data_buf)) {
if (s->setup_len > (int32_t)sizeof(s->data_buf)) {
fprintf(stderr,
"usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
s->setup_len, sizeof(s->data_buf));
@ -200,7 +201,7 @@ static void do_token_in(USBDevice *s, USBPacket *p)
case SETUP_STATE_DATA:
if (s->setup_buf[0] & USB_DIR_IN) {
int len = s->setup_len - s->setup_index;
if (len > p->iov.size) {
if ((size_t)len > p->iov.size) {
len = p->iov.size;
}
usb_packet_copy(p, s->data_buf + s->setup_index, len);
@ -236,7 +237,7 @@ static void do_token_out(USBDevice *s, USBPacket *p)
case SETUP_STATE_DATA:
if (!(s->setup_buf[0] & USB_DIR_IN)) {
int len = s->setup_len - s->setup_index;
if (len > p->iov.size) {
if ((size_t)len > p->iov.size) {
len = p->iov.size;
}
usb_packet_copy(p, s->data_buf + s->setup_index, len);
@ -271,7 +272,7 @@ static void do_parameter(USBDevice *s, USBPacket *p)
value = (s->setup_buf[3] << 8) | s->setup_buf[2];
index = (s->setup_buf[5] << 8) | s->setup_buf[4];
if (s->setup_len > sizeof(s->data_buf)) {
if (s->setup_len > (int32_t)sizeof(s->data_buf)) {
fprintf(stderr,
"usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
s->setup_len, sizeof(s->data_buf));
@ -450,7 +451,7 @@ void usb_packet_complete_one(USBDevice *dev, USBPacket *p)
assert(p->status != USB_RET_ASYNC && p->status != USB_RET_NAK);
if (p->status != USB_RET_SUCCESS ||
(p->short_not_ok && (p->actual_length < p->iov.size))) {
(p->short_not_ok && ((size_t)p->actual_length < p->iov.size))) {
ep->halted = true;
}
usb_packet_set_state(p, USB_PACKET_COMPLETE);
@ -527,14 +528,9 @@ static const char *usb_packet_state_name(USBPacketState state)
void usb_packet_check_state(USBPacket *p, USBPacketState expected)
{
USBDevice *dev;
USBBus *bus;
if (p->state == expected) {
return;
}
dev = p->ep->dev;
bus = dev->bus; //usb_bus_from_device(dev);
//trace_usb_packet_state_fault(bus->busnr, dev->port->path, p->ep->nr, p,
// usb_packet_state_name(p->state),
// usb_packet_state_name(expected));

View File

@ -1,7 +1,7 @@
#include "vl.h"
#include "desc.h"
#include "glib.h"
#include "osdebugout.h"
#include "../osdebugout.h"
//#include "trace.h"
/* ------------------------------------------------------------------ */
@ -128,7 +128,6 @@ int usb_desc_iface_group(const USBDescIfaceAssoc& iad, int flags,
uint8_t *dest, size_t len)
{
int pos = 0;
int i = 0;
/* handle interface association descriptor */
uint8_t bLength = 0x08;
@ -209,7 +208,7 @@ int usb_desc_endpoint(const USBDescEndpoint& ep, int flags,
uint8_t superlen = (flags & USB_DESC_FLAG_SUPER) ? 0x06 : 0;
USBDescriptor *d = (USBDescriptor *)dest;
if (len < bLength + extralen + superlen) {
if (len < (size_t)(bLength + extralen + superlen)) {
return -1;
}
@ -251,7 +250,7 @@ int usb_desc_other(const USBDescOther& desc, uint8_t *dest, size_t len)
{
int bLength = desc.length ? desc.length : desc.data[0];
if (len < bLength) {
if (len < (size_t)bLength) {
return -1;
}
@ -389,7 +388,6 @@ int usb_desc_parse_config (const uint8_t *data, int len, USBDescDevice& dev)
{
int pos = 0;
USBDescIface *iface = nullptr;
USBDescIfaceAssoc *ifaceAssoc = nullptr;
USBDescConfig *config = nullptr;
USBDescriptor *d;
@ -668,7 +666,7 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
dest[0] = bLength;
dest[1] = USB_DT_STRING;
i = 0; pos = 2;
while (pos+1 < bLength && pos+1 < len) {
while (pos+1 < bLength && (size_t)(pos+1) < len) {
dest[pos++] = str[i++];
dest[pos++] = 0;
}
@ -744,7 +742,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,
}
if (ret > 0) {
if (ret > len) {
if ((size_t)ret > len) {
ret = len;
}
memcpy(dest, buf, ret);
@ -757,11 +755,9 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,
int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
bool msos = (dev->flags & (1 << USB_DEV_FLAG_MSOS_DESC_IN_USE));
const USBDesc *desc = usb_device_get_usb_desc(dev);
assert(usb_device_get_usb_desc(dev) != NULL);
int ret = -1;
assert(desc != NULL);
switch(request) {
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
dev->addr = value;

View File

@ -2,7 +2,12 @@
#define GLIB_H
#include <cstddef>
#include <cstdint>
#include "gmem-size.h"
#ifdef __M_X86_64
#define G_MAXSIZE G_MAXUINT64
#else
#define G_MAXSIZE G_MAXUINT32
#endif
#define G_MAXUINT64 0xffffffffffffffffUL
#define G_MAXUINT32 ((uint32_t)0xffffffff)
@ -28,4 +33,4 @@ void* my_g_realloc_n (void* mem,
#define my_g_new(struct_type, n_structs) my_G_NEW (struct_type, n_structs, malloc)
#define my_g_renew(struct_type, mem, n_structs) my_G_RENEW (struct_type, mem, n_structs, realloc)
#endif
#endif

View File

@ -24,7 +24,7 @@
*/
#include "hid.h"
#include "input-keymap.h"
#include "osdebugout.h"
#include "../osdebugout.h"
#define HID_USAGE_ERROR_ROLLOVER 0x01
#define HID_USAGE_POSTFAIL 0x02
@ -283,6 +283,7 @@ static void hid_keyboard_process_keycode(HIDState *hs)
}
/* fall through to process Ctrl_L */
//case 0xe1 ... 0xe7:
[[fallthrough]];
case 0xe1:
case 0xe2:
case 0xe3:
@ -341,7 +342,7 @@ static void hid_keyboard_process_keycode(HIDState *hs)
}
}
if (i < 0) {
if (hs->kbd.keys < sizeof(hs->kbd.key)) {
if (hs->kbd.keys < (int32_t)sizeof(hs->kbd.key)) {
hs->kbd.key[hs->kbd.keys++] = hid_code;
}
}

View File

@ -379,12 +379,10 @@ size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,
void qemu_iovec_discard_back(QEMUIOVector *qiov, size_t bytes)
{
size_t total;
unsigned int niov = qiov->niov;
assert(qiov->size >= bytes);
total = iov_discard_back(qiov->iov, &niov, bytes);
assert(total == bytes);
assert(iov_discard_back(qiov->iov, &niov, bytes) == bytes);
qiov->niov = niov;
qiov->size -= bytes;

View File

@ -537,5 +537,9 @@ typedef KeyIndexA KeyIndex;
typedef SecIndexA SecIndex;
#endif
std::wstring str_to_wstr(const std::string& arg);
std::string wstr_to_str(const std::wstring& arg);
#endif

View File

@ -1,7 +1,7 @@
#include "ringbuffer.h"
#include <cstring>
#include <cassert>
#include "osdebugout.h"
#include "../osdebugout.h"
#if 0
#define DPRINTF OSDebugOut
@ -152,8 +152,6 @@ size_t RingBuffer::peek_read() const
void RingBuffer::write(size_t bytes)
{
size_t before = m_end;
//assert( bytes <= m_capacity - size() );
// push m_begin forward if m_end overlaps it
@ -175,7 +173,6 @@ void RingBuffer::read(size_t bytes)
{
assert( bytes <= size() );
size_t before = m_begin;
m_overrun = false;
if ((m_begin < m_end && m_begin + bytes > m_end) ||
m_begin + bytes > m_end + m_capacity)

View File

@ -74,12 +74,14 @@ public:
{
return std::chrono::duration_cast<ms>(hrc::now()-mLastWrite).count();
}
private:
bool m_overrun;
size_t m_begin, m_end, m_capacity;
size_t m_capacity;
char *m_data;
size_t m_begin;
bool m_overrun;
size_t m_end;
hrc::time_point mLastWrite = hrc::time_point(ns(0));
};
#endif

View File

@ -421,9 +421,7 @@ static void eyetoy_handle_data(USBDevice *dev, USBPacket *p)
EYETOYState *s = (EYETOYState *)dev;
static const int max_ep_size = 896;
uint8_t data[max_ep_size];
int ret = 0;
uint8_t devep = p->ep->nr;
size_t len = p->iov.size;
switch(p->pid) {
case USB_TOKEN_IN:
@ -578,8 +576,6 @@ int EyeToyWebCamDevice::Configure(int port, const std::string& api, void *data)
int EyeToyWebCamDevice::Freeze(int mode, USBDevice *dev, void *data)
{
EYETOYState *s = (EYETOYState *)dev;
/*switch (mode)
{
case FREEZE_LOAD:

View File

@ -26,7 +26,7 @@
#include "hidproxy.h"
#include "../qemu-usb/desc.h"
#include "usb-hid.h"
#include "osdebugout.h"
#include "../osdebugout.h"
#define CONTAINER_OF(p, type, field) ((type*) ((char*)p - ((ptrdiff_t)&((type*)0)->field)))
@ -720,4 +720,4 @@ int HIDMouseDevice::Freeze(int mode, USBDevice *dev, void *data)
return HIDKbdDevice::Freeze(mode, dev, data);
}
} //namespace
} //namespace

View File

@ -658,7 +658,6 @@ static int usb_audio_ep_control(HeadsetState *s, uint8_t attrib,
int length, uint8_t *data)
{
uint8_t cs = cscn >> 8;
uint8_t cn = cscn - 1; /* -1 for the non-present master control */
uint32_t aid = ATTRIB_ID(cs, attrib, ep);
int ret = USB_RET_STALL;
@ -902,7 +901,6 @@ static void headset_handle_data(USBDevice *dev, USBPacket *p)
}
break;
default:
fail:
p->status = USB_RET_STALL;
break;
}
@ -1068,4 +1066,4 @@ int HeadsetDevice::Freeze(int mode, USBDevice *dev, void *data)
return -1;
}
}
}

View File

@ -235,7 +235,6 @@ USBDevice* LogitechMicDevice::CreateDevice(int port)
return nullptr;
SINGSTARMICMINIState *s = (SINGSTARMICMINIState *)dev;
const USBDescDevice *full = s->desc.full;
s->desc = {};
s->desc_dev = {};
@ -256,4 +255,4 @@ fail:
return nullptr;
}
}
}

View File

@ -694,8 +694,8 @@ static void singstar_mic_handle_data(USBDevice *dev, USBPacket *p)
case USB_TOKEN_OUT:
printf("token out ep: %d\n", devep);
OSDebugOut(TEXT("token out ep: %d len: %d\n"), devep, p->actual_length);
[[fallthrough]];
default:
fail:
p->status = USB_RET_STALL;
break;
}
@ -861,4 +861,4 @@ int SingstarDevice::Freeze(int mode, USBDevice *dev, void *data)
return -1;
}
}
}

View File

@ -780,7 +780,6 @@ static void usb_msd_handle_control(USBDevice *dev, USBPacket *p, int request, in
p->actual_length = 1;
break;
default:
fail:
p->status = USB_RET_STALL;
break;
}
@ -801,8 +800,6 @@ static void usb_msd_cancel_io(USBDevice *dev, USBPacket *p)
static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
{
MSDState *s = (MSDState *)dev;
int ret = 0;
size_t file_ret = 0;
struct usb_msd_cbw cbw;
uint8_t devep = p->ep->nr;
@ -877,7 +874,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
}
}
}
if (p->actual_length < p->iov.size) {
if ((size_t)p->actual_length < p->iov.size) {
DPRINTF("Deferring packet %p [wait data-out]\n", p);
s->packet = p;
p->status = USB_RET_ASYNC;
@ -955,7 +952,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
}
}
if (p->actual_length < p->iov.size) {
if ((size_t)p->actual_length < p->iov.size) {
DPRINTF("Deferring packet %p [wait data-in]\n", p);
s->packet = p;
p->status = USB_RET_ASYNC;
@ -1049,7 +1046,6 @@ const char* MsdDevice::TypeName()
int MsdDevice::Freeze(int mode, USBDevice *dev, void *data)
{
uint32_t fat32_serial = 0;
MSDState *s = (MSDState *)dev;
MSDState::freeze *tmp;
@ -1085,4 +1081,4 @@ int MsdDevice::Freeze(int mode, USBDevice *dev, void *data)
}
#undef DPRINTF
} //namespace
} //namespace

View File

@ -1,6 +1,6 @@
#include "usb-pad.h"
#include "lg/lg_ff.h"
#include "osdebugout.h"
#include "../osdebugout.h"
namespace usb_pad {
@ -266,4 +266,4 @@ void Pad::ParseFFData(const ff_data *ffdata, bool isDFP)
}
}
} //namespace
} //namespace

View File

@ -164,7 +164,7 @@ static void pad_handle_data(USBDevice *dev, USBPacket *p)
if (devep == 1 && s->pad) {
ret = s->pad->TokenIn(data, p->iov.size);
if (ret > 0)
usb_packet_copy (p, data, MIN(ret, sizeof(data)));
usb_packet_copy (p, data, MIN(ret, (int)sizeof(data)));
else
p->status = ret;
} else {

View File

@ -22,6 +22,7 @@
#include "FW.h"
#include "SPU2/spu2.h"
#include "DEV9/DEV9.h"
#include "USB/USB.h"
#include "ps2/pgif.h"
#include "Mdec.h"

View File

@ -21,6 +21,7 @@
#include "CDVD/CdRom.h"
#include "SPU2/spu2.h"
#include "DEV9/DEV9.h"
#include "USB/USB.h"
#include "ps2/pgif.h"
#include "Mdec.h"