mirror of https://github.com/PCSX2/pcsx2.git
USB: Remove IO vector for packets
It was unnecessary as our packets were always contiguous, and also GPL instead of LGPL.
This commit is contained in:
parent
fc14b8f0da
commit
7cbede9190
|
@ -450,7 +450,6 @@ set(pcsx2USBSources
|
|||
USB/qemu-usb/desc.cpp
|
||||
USB/qemu-usb/hid.cpp
|
||||
USB/qemu-usb/input-keymap-qcode-to-qnum.cpp
|
||||
USB/qemu-usb/iov.cpp
|
||||
USB/qemu-usb/usb-ohci.cpp
|
||||
USB/shared/ringbuffer.cpp
|
||||
USB/usb-eyetoy/jo_mpeg.cpp
|
||||
|
@ -476,7 +475,6 @@ set(pcsx2USBHeaders
|
|||
USB/qemu-usb/desc.h
|
||||
USB/qemu-usb/hid.h
|
||||
USB/qemu-usb/input-keymap.h
|
||||
USB/qemu-usb/iov.h
|
||||
USB/qemu-usb/queue.h
|
||||
USB/qemu-usb/qusb.h
|
||||
USB/readerwriterqueue/atomicops.h
|
||||
|
|
|
@ -300,7 +300,6 @@ void USB::DoPacketState(USBPacket* p, StateWrapper& sw, const std::array<bool, 2
|
|||
|
||||
s32 dev_index = -1;
|
||||
s32 ep_index = -1;
|
||||
u32 p_iov_size = 0;
|
||||
bool queued = false;
|
||||
if (sw.IsWriting())
|
||||
{
|
||||
|
@ -332,14 +331,12 @@ void USB::DoPacketState(USBPacket* p, StateWrapper& sw, const std::array<bool, 2
|
|||
}
|
||||
if (dev_index < 0 || ep_index < 0)
|
||||
Console.Error("Failed to save USB packet from unknown endpoint");
|
||||
else
|
||||
p_iov_size = p->iov.size;
|
||||
}
|
||||
}
|
||||
|
||||
sw.Do(&dev_index);
|
||||
sw.Do(&ep_index);
|
||||
sw.Do(&p_iov_size);
|
||||
sw.Do(&p->buffer_size);
|
||||
sw.Do(&queued);
|
||||
|
||||
sw.Do(&p->pid);
|
||||
|
@ -354,7 +351,6 @@ void USB::DoPacketState(USBPacket* p, StateWrapper& sw, const std::array<bool, 2
|
|||
|
||||
if (sw.IsReading())
|
||||
{
|
||||
qemu_iovec_reset(&p->iov);
|
||||
p->ep = nullptr;
|
||||
|
||||
if (dev_index >= 0 && ep_index >= 0 && valid_devices[static_cast<u32>(dev_index)])
|
||||
|
@ -362,8 +358,7 @@ void USB::DoPacketState(USBPacket* p, StateWrapper& sw, const std::array<bool, 2
|
|||
USBDevice* dev = s_usb_device[static_cast<u32>(dev_index)];
|
||||
pxAssert(dev);
|
||||
|
||||
if (p_iov_size > 0)
|
||||
qemu_iovec_add(&p->iov, s_qemu_ohci->usb_buf, p_iov_size);
|
||||
p->buffer_ptr = (p->buffer_size > 0) ? s_qemu_ohci->usb_buf : nullptr;
|
||||
|
||||
if (ep_index == 0)
|
||||
p->ep = &dev->ep_ctl;
|
||||
|
@ -375,6 +370,11 @@ void USB::DoPacketState(USBPacket* p, StateWrapper& sw, const std::array<bool, 2
|
|||
if (p->ep && queued)
|
||||
QTAILQ_INSERT_TAIL(&p->ep->queue, p, queue);
|
||||
}
|
||||
else
|
||||
{
|
||||
p->buffer_ptr = nullptr;
|
||||
p->buffer_size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "USB/qemu-usb/qusb.h"
|
||||
#include "USB/qemu-usb/iov.h"
|
||||
#include <utility>
|
||||
|
||||
void usb_pick_speed(USBPort* port)
|
||||
|
@ -133,13 +132,13 @@ static void do_token_setup(USBDevice* s, USBPacket* p)
|
|||
{
|
||||
int request, value, index;
|
||||
|
||||
if (p->iov.size != 8)
|
||||
if (p->buffer_size != 8)
|
||||
{
|
||||
p->status = USB_RET_STALL;
|
||||
return;
|
||||
}
|
||||
|
||||
usb_packet_copy(p, s->setup_buf, p->iov.size);
|
||||
usb_packet_copy(p, s->setup_buf, p->buffer_size);
|
||||
s->setup_index = 0;
|
||||
p->actual_length = 0;
|
||||
s->setup_len = (s->setup_buf[7] << 8) | s->setup_buf[6];
|
||||
|
@ -216,9 +215,9 @@ static void do_token_in(USBDevice* s, USBPacket* p)
|
|||
if (s->setup_buf[0] & USB_DIR_IN)
|
||||
{
|
||||
int len = s->setup_len - s->setup_index;
|
||||
if ((size_t)len > p->iov.size)
|
||||
if ((size_t)len > p->buffer_size)
|
||||
{
|
||||
len = p->iov.size;
|
||||
len = p->buffer_size;
|
||||
}
|
||||
usb_packet_copy(p, s->data_buf + s->setup_index, len);
|
||||
s->setup_index += len;
|
||||
|
@ -259,9 +258,9 @@ static void do_token_out(USBDevice* s, USBPacket* p)
|
|||
if (!(s->setup_buf[0] & USB_DIR_IN))
|
||||
{
|
||||
int len = s->setup_len - s->setup_index;
|
||||
if ((size_t)len > p->iov.size)
|
||||
if ((size_t)len > p->buffer_size)
|
||||
{
|
||||
len = p->iov.size;
|
||||
len = p->buffer_size;
|
||||
}
|
||||
usb_packet_copy(p, s->data_buf + s->setup_index, len);
|
||||
s->setup_index += len;
|
||||
|
@ -504,7 +503,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 && ((size_t)p->actual_length < p->iov.size)))
|
||||
(p->short_not_ok && ((size_t)p->actual_length < p->buffer_size)))
|
||||
{
|
||||
ep->halted = true;
|
||||
}
|
||||
|
@ -564,11 +563,6 @@ void usb_cancel_packet(USBPacket* p)
|
|||
}
|
||||
|
||||
|
||||
void usb_packet_init(USBPacket* p)
|
||||
{
|
||||
qemu_iovec_init(&p->iov);
|
||||
}
|
||||
|
||||
static const char* usb_packet_state_name(USBPacketState state)
|
||||
{
|
||||
static const char* name[] = {
|
||||
|
@ -619,7 +613,6 @@ void usb_packet_setup(USBPacket* p, int pid,
|
|||
uint64_t id, bool short_not_ok, bool int_req)
|
||||
{
|
||||
assert(!usb_packet_is_inflight(p));
|
||||
assert(p->iov.iov != NULL);
|
||||
p->id = id;
|
||||
p->pid = pid;
|
||||
p->ep = ep;
|
||||
|
@ -629,31 +622,31 @@ void usb_packet_setup(USBPacket* p, int pid,
|
|||
p->parameter = 0;
|
||||
p->short_not_ok = short_not_ok;
|
||||
p->int_req = int_req;
|
||||
p->combined = NULL;
|
||||
qemu_iovec_reset(&p->iov);
|
||||
p->buffer_ptr = NULL;
|
||||
p->buffer_size = 0;
|
||||
usb_packet_set_state(p, USB_PACKET_SETUP);
|
||||
}
|
||||
|
||||
void usb_packet_addbuf(USBPacket* p, void* ptr, size_t len)
|
||||
{
|
||||
qemu_iovec_add(&p->iov, ptr, len);
|
||||
assert(!p->buffer_ptr);
|
||||
p->buffer_ptr = static_cast<uint8_t*>(ptr);
|
||||
p->buffer_size = static_cast<unsigned int>(len);
|
||||
}
|
||||
|
||||
void usb_packet_copy(USBPacket* p, void* ptr, size_t bytes)
|
||||
{
|
||||
QEMUIOVector* iov = p->combined ? &p->combined->iov : &p->iov;
|
||||
|
||||
assert(bytes <= INT_MAX);
|
||||
assert(p->actual_length >= 0);
|
||||
assert(p->actual_length + bytes <= iov->size);
|
||||
assert(p->actual_length + bytes <= p->buffer_size);
|
||||
switch (p->pid)
|
||||
{
|
||||
case USB_TOKEN_SETUP:
|
||||
case USB_TOKEN_OUT:
|
||||
iov_to_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
|
||||
std::memcpy(ptr, p->buffer_ptr, bytes);
|
||||
break;
|
||||
case USB_TOKEN_IN:
|
||||
iov_from_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
|
||||
std::memcpy(p->buffer_ptr, ptr, bytes);
|
||||
break;
|
||||
default:
|
||||
Console.Warning("%s: invalid pid: %x\n", __func__, p->pid);
|
||||
|
@ -664,27 +657,26 @@ void usb_packet_copy(USBPacket* p, void* ptr, size_t bytes)
|
|||
|
||||
void usb_packet_skip(USBPacket* p, size_t bytes)
|
||||
{
|
||||
QEMUIOVector* iov = p->combined ? &p->combined->iov : &p->iov;
|
||||
|
||||
assert(bytes <= INT_MAX);
|
||||
assert(p->actual_length >= 0);
|
||||
assert(p->actual_length + bytes <= iov->size);
|
||||
assert(p->actual_length + bytes <= p->buffer_size);
|
||||
if (p->pid == USB_TOKEN_IN)
|
||||
{
|
||||
iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes);
|
||||
std::memset(p->buffer_ptr, 0, bytes);
|
||||
}
|
||||
p->actual_length += bytes;
|
||||
}
|
||||
|
||||
size_t usb_packet_size(USBPacket* p)
|
||||
{
|
||||
return p->combined ? p->combined->iov.size : p->iov.size;
|
||||
return p->buffer_size;
|
||||
}
|
||||
|
||||
void usb_packet_cleanup(USBPacket* p)
|
||||
{
|
||||
assert(!usb_packet_is_inflight(p));
|
||||
qemu_iovec_destroy(&p->iov);
|
||||
p->buffer_ptr = nullptr;
|
||||
p->buffer_size = 0;
|
||||
}
|
||||
|
||||
void usb_ep_reset(USBDevice* dev)
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Helpers for getting linearized buffers from iov / filling buffers into iovs
|
||||
*
|
||||
* Copyright IBM, Corp. 2007, 2008
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* Author(s):
|
||||
* Anthony Liguori <aliguori@us.ibm.com>
|
||||
* Amit Shah <amit.shah@redhat.com>
|
||||
* Michael Tokarev <mjt@tls.msk.ru>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
||||
* the COPYING file in the top-level directory.
|
||||
*
|
||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
||||
* GNU GPL, version 2 or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "USB/qemu-usb/iov.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
// TODO(Stenzek): Rewrite this stuff to LGPL.
|
||||
|
||||
size_t iov_from_buf(const struct usb_iovec* iov, unsigned int iov_cnt,
|
||||
size_t offset, const void* buf, size_t bytes)
|
||||
{
|
||||
size_t done;
|
||||
unsigned int i;
|
||||
for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++)
|
||||
{
|
||||
if (offset < iov[i].iov_len)
|
||||
{
|
||||
size_t len = std::min(iov[i].iov_len - offset, bytes - done);
|
||||
memcpy((char*)iov[i].iov_base + offset, (char*)buf + done, len);
|
||||
done += len;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset -= iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
assert(offset == 0);
|
||||
return done;
|
||||
}
|
||||
|
||||
size_t iov_to_buf(const struct usb_iovec* iov, const unsigned int iov_cnt,
|
||||
size_t offset, void* buf, size_t bytes)
|
||||
{
|
||||
size_t done;
|
||||
unsigned int i;
|
||||
for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++)
|
||||
{
|
||||
if (offset < iov[i].iov_len)
|
||||
{
|
||||
size_t len = std::min(iov[i].iov_len - offset, bytes - done);
|
||||
memcpy((char*)buf + done, (char*)iov[i].iov_base + offset, len);
|
||||
done += len;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset -= iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
assert(offset == 0);
|
||||
return done;
|
||||
}
|
||||
|
||||
size_t iov_memset(const struct usb_iovec* iov, const unsigned int iov_cnt,
|
||||
size_t offset, int fillc, size_t bytes)
|
||||
{
|
||||
size_t done;
|
||||
unsigned int i;
|
||||
for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++)
|
||||
{
|
||||
if (offset < iov[i].iov_len)
|
||||
{
|
||||
size_t len = std::min(iov[i].iov_len - offset, bytes - done);
|
||||
memset((char*)iov[i].iov_base + offset, fillc, len);
|
||||
done += len;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset -= iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
assert(offset == 0);
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
/* io vectors */
|
||||
|
||||
void qemu_iovec_init(QEMUIOVector* qiov)
|
||||
{
|
||||
qiov->iov = (struct usb_iovec*)std::malloc(sizeof(usb_iovec));
|
||||
qiov->niov = 0;
|
||||
qiov->nalloc = 1;
|
||||
qiov->size = 0;
|
||||
}
|
||||
|
||||
void qemu_iovec_add(QEMUIOVector* qiov, void* base, size_t len)
|
||||
{
|
||||
assert(qiov->nalloc != -1);
|
||||
|
||||
if (qiov->niov == qiov->nalloc)
|
||||
{
|
||||
qiov->nalloc = 2 * qiov->nalloc + 1;
|
||||
qiov->iov = (struct usb_iovec*)std::realloc(qiov->iov, sizeof(usb_iovec) * qiov->nalloc);
|
||||
}
|
||||
qiov->iov[qiov->niov].iov_base = base;
|
||||
qiov->iov[qiov->niov].iov_len = len;
|
||||
qiov->size += len;
|
||||
++qiov->niov;
|
||||
}
|
||||
|
||||
void qemu_iovec_destroy(QEMUIOVector* qiov)
|
||||
{
|
||||
assert(qiov->nalloc != -1);
|
||||
|
||||
qemu_iovec_reset(qiov);
|
||||
std::free(qiov->iov);
|
||||
qiov->nalloc = 0;
|
||||
qiov->iov = NULL;
|
||||
}
|
||||
|
||||
void qemu_iovec_reset(QEMUIOVector* qiov)
|
||||
{
|
||||
assert(qiov->nalloc != -1);
|
||||
|
||||
qiov->niov = 0;
|
||||
qiov->size = 0;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Helpers for using (partial) iovecs.
|
||||
*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* Author(s):
|
||||
* Amit Shah <amit.shah@redhat.com>
|
||||
* Michael Tokarev <mjt@tls.msk.ru>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
||||
* the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct usb_iovec
|
||||
{
|
||||
void* iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy from single continuous buffer to scatter-gather vector of buffers
|
||||
* (iovec) and back like memcpy() between two continuous memory regions.
|
||||
* Data in single continuous buffer starting at address `buf' and
|
||||
* `bytes' bytes long will be copied to/from an iovec `iov' with
|
||||
* `iov_cnt' number of elements, starting at byte position `offset'
|
||||
* within the iovec. If the iovec does not contain enough space,
|
||||
* only part of data will be copied, up to the end of the iovec.
|
||||
* Number of bytes actually copied will be returned, which is
|
||||
* min(bytes, iov_size(iov)-offset)
|
||||
* `Offset' must point to the inside of iovec.
|
||||
* It is okay to use very large value for `bytes' since we're
|
||||
* limited by the size of the iovec anyway, provided that the
|
||||
* buffer pointed to by buf has enough space. One possible
|
||||
* such "large" value is -1 (sinice size_t is unsigned),
|
||||
* so specifying `-1' as `bytes' means 'up to the end of iovec'.
|
||||
*/
|
||||
size_t iov_from_buf(const struct usb_iovec* iov, unsigned int iov_cnt,
|
||||
size_t offset, const void* buf, size_t bytes);
|
||||
size_t iov_to_buf(const struct usb_iovec* iov, const unsigned int iov_cnt,
|
||||
size_t offset, void* buf, size_t bytes);
|
||||
|
||||
/**
|
||||
* Set data bytes pointed out by iovec `iov' of size `iov_cnt' elements,
|
||||
* starting at byte offset `start', to value `fillc', repeating it
|
||||
* `bytes' number of times. `Offset' must point to the inside of iovec.
|
||||
* If `bytes' is large enough, only last bytes portion of iovec,
|
||||
* up to the end of it, will be filled with the specified value.
|
||||
* Function return actual number of bytes processed, which is
|
||||
* min(size, iov_size(iov) - offset).
|
||||
* Again, it is okay to use large value for `bytes' to mean "up to the end".
|
||||
*/
|
||||
size_t iov_memset(const struct usb_iovec* iov, const unsigned int iov_cnt,
|
||||
size_t offset, int fillc, size_t bytes);
|
||||
|
||||
typedef struct QEMUIOVector
|
||||
{
|
||||
struct usb_iovec* iov;
|
||||
int niov;
|
||||
int nalloc;
|
||||
size_t size;
|
||||
} QEMUIOVector;
|
||||
|
||||
void qemu_iovec_init(QEMUIOVector* qiov);
|
||||
void qemu_iovec_add(QEMUIOVector* qiov, void* base, size_t len);
|
||||
void qemu_iovec_destroy(QEMUIOVector* qiov);
|
||||
void qemu_iovec_reset(QEMUIOVector* qiov);
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
#include "USB/qemu-usb/iov.h"
|
||||
#include "USB/qemu-usb/queue.h"
|
||||
|
||||
#define USB_TOKEN_SETUP 0x2d
|
||||
|
@ -268,7 +267,6 @@ typedef struct USBBusOps USBBusOps;
|
|||
typedef struct USBPort USBPort;
|
||||
typedef struct USBDevice USBDevice;
|
||||
typedef struct USBPacket USBPacket;
|
||||
typedef struct USBCombinedPacket USBCombinedPacket;
|
||||
typedef struct USBEndpoint USBEndpoint;
|
||||
|
||||
typedef struct USBDesc USBDesc;
|
||||
|
@ -482,7 +480,8 @@ struct USBPacket
|
|||
uint64_t id;
|
||||
USBEndpoint* ep;
|
||||
unsigned int stream;
|
||||
QEMUIOVector iov;
|
||||
unsigned int buffer_size;
|
||||
uint8_t* buffer_ptr;
|
||||
uint64_t parameter; /* control transfers */
|
||||
bool short_not_ok;
|
||||
bool int_req;
|
||||
|
@ -490,22 +489,12 @@ struct USBPacket
|
|||
int actual_length; /* Number of bytes actually transferred */
|
||||
/* Internal use by the USB layer. */
|
||||
USBPacketState state;
|
||||
USBCombinedPacket* combined;
|
||||
QTAILQ_ENTRY(USBPacket)
|
||||
queue;
|
||||
QTAILQ_ENTRY(USBPacket)
|
||||
combined_entry;
|
||||
};
|
||||
|
||||
struct USBCombinedPacket
|
||||
{
|
||||
USBPacket* first;
|
||||
QTAILQ_HEAD(packets_head, USBPacket)
|
||||
packets;
|
||||
QEMUIOVector iov;
|
||||
};
|
||||
|
||||
void usb_packet_init(USBPacket* p);
|
||||
void usb_packet_set_state(USBPacket* p, USBPacketState state);
|
||||
void usb_packet_check_state(USBPacket* p, USBPacketState expected);
|
||||
void usb_packet_setup(USBPacket* p, int pid,
|
||||
|
|
|
@ -1731,12 +1731,12 @@ OHCIState* ohci_create(uint32_t base, int ports)
|
|||
{
|
||||
OHCIState* ohci = (OHCIState*)malloc(sizeof(OHCIState));
|
||||
if (!ohci)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
int i;
|
||||
|
||||
const int ticks_per_sec = usb_get_ticks_per_second();
|
||||
|
||||
memset(ohci, 0, sizeof(OHCIState));
|
||||
std::memset(ohci, 0, sizeof(OHCIState));
|
||||
|
||||
ohci->mem_base = base;
|
||||
|
||||
|
@ -1761,7 +1761,7 @@ OHCIState* ohci_create(uint32_t base, int ports)
|
|||
ohci->num_ports = ports;
|
||||
for (i = 0; i < ports; i++)
|
||||
{
|
||||
memset(&(ohci->rhport[i].port), 0, sizeof(USBPort));
|
||||
std::memset(&(ohci->rhport[i].port), 0, sizeof(USBPort));
|
||||
ohci->rhport[i].port.opaque = ohci;
|
||||
ohci->rhport[i].port.index = i;
|
||||
ohci->rhport[i].port.speedmask = USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL;
|
||||
|
@ -1769,7 +1769,5 @@ OHCIState* ohci_create(uint32_t base, int ports)
|
|||
}
|
||||
|
||||
ohci_hard_reset(ohci);
|
||||
usb_packet_init(&ohci->usb_packet);
|
||||
|
||||
return ohci;
|
||||
}
|
||||
|
|
|
@ -342,8 +342,8 @@ namespace usb_eyetoy
|
|||
{
|
||||
// get audio
|
||||
//Console.Warning("get audio %d\n", len);
|
||||
memset(data, 0, p->iov.size);
|
||||
usb_packet_copy(p, data, p->iov.size);
|
||||
memset(data, 0, p->buffer_size);
|
||||
usb_packet_copy(p, data, p->buffer_size);
|
||||
}
|
||||
break;
|
||||
case USB_TOKEN_OUT:
|
||||
|
|
|
@ -775,7 +775,7 @@ namespace usb_hid
|
|||
{
|
||||
UsbHIDState* us = USB_CONTAINER_OF(dev, UsbHIDState, dev);
|
||||
HIDState* hs = &us->hid;
|
||||
std::vector<uint8_t> buf(p->iov.size);
|
||||
uint8_t buf[16];
|
||||
size_t len = 0;
|
||||
|
||||
switch (p->pid)
|
||||
|
@ -795,13 +795,13 @@ namespace usb_hid
|
|||
hid_set_next_idle(hs);
|
||||
if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET)
|
||||
{
|
||||
len = hid_pointer_poll(hs, buf.data(), p->iov.size);
|
||||
len = hid_pointer_poll(hs, buf, p->buffer_size);
|
||||
}
|
||||
else if (hs->kind == HID_KEYBOARD)
|
||||
{
|
||||
len = hid_keyboard_poll(hs, buf.data(), p->iov.size);
|
||||
len = hid_keyboard_poll(hs, buf, p->buffer_size);
|
||||
}
|
||||
usb_packet_copy(p, buf.data(), len);
|
||||
usb_packet_copy(p, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -766,20 +766,11 @@ namespace usb_mic
|
|||
|
||||
uint32_t outChns = 1; //s->dev.altsetting[2] == 1 ? 2 : 1;
|
||||
uint32_t inChns = s->audsrc->GetChannels();
|
||||
int16_t* dst = nullptr;
|
||||
std::vector<int16_t> dst_alloc(0); //TODO
|
||||
size_t len = p->iov.size;
|
||||
int16_t* dst = (int16_t*)p->buffer_ptr;
|
||||
size_t len = p->buffer_size;
|
||||
//Divide 'len' bytes between n channels of 16 bits
|
||||
uint32_t maxFrames = len / (outChns * sizeof(int16_t)), frames = 0;
|
||||
|
||||
if (p->iov.niov == 1)
|
||||
dst = (int16_t*)p->iov.iov[0].iov_base;
|
||||
else
|
||||
{
|
||||
dst_alloc.resize(len / sizeof(int16_t));
|
||||
dst = dst_alloc.data();
|
||||
}
|
||||
|
||||
if (s->audsrc->GetFrames(&frames))
|
||||
{
|
||||
frames = std::min(frames, maxFrames);
|
||||
|
@ -811,12 +802,7 @@ namespace usb_mic
|
|||
fwrite(data, sizeof(short), ret * outChns, file);
|
||||
#endif
|
||||
ret = ret * outChns * sizeof(int16_t);
|
||||
if (p->iov.niov > 1)
|
||||
{
|
||||
usb_packet_copy(p, dst_alloc.data(), ret);
|
||||
}
|
||||
else
|
||||
p->actual_length = ret;
|
||||
p->actual_length = ret;
|
||||
}
|
||||
break;
|
||||
case USB_TOKEN_OUT:
|
||||
|
@ -828,21 +814,10 @@ namespace usb_mic
|
|||
{
|
||||
uint32_t inChns = s->dev.altsetting[1] == 1 ? 2 : 1;
|
||||
uint32_t outChns = s->audsink->GetChannels();
|
||||
size_t len = p->iov.size;
|
||||
int16_t* src = (int16_t*)p->buffer_ptr;
|
||||
size_t len = p->buffer_size;
|
||||
//Divide 'len' bytes between n channels of 16 bits
|
||||
uint32_t frames = len / (inChns * sizeof(int16_t));
|
||||
int16_t* src = nullptr;
|
||||
std::vector<int16_t> src_alloc(0);
|
||||
|
||||
if (p->iov.niov == 1)
|
||||
src = (int16_t*)p->iov.iov[0].iov_base;
|
||||
else
|
||||
{
|
||||
//Copy iov data into continuous space
|
||||
src_alloc.resize(len / sizeof(int16_t));
|
||||
src = src_alloc.data();
|
||||
usb_packet_copy(p, src, len);
|
||||
}
|
||||
|
||||
s->out_buffer.resize(frames * outChns); //TODO move to AudioDevice for less data copying
|
||||
|
||||
|
|
|
@ -571,25 +571,16 @@ namespace usb_mic
|
|||
int outChns = s->f.intf == 1 ? 1 : 2;
|
||||
uint32_t frames, out_frames[2] = {0}, chn;
|
||||
int16_t *src1, *src2;
|
||||
int16_t* dst = nullptr;
|
||||
std::vector<int16_t> dst_alloc(0); //TODO
|
||||
size_t len = p->iov.size;
|
||||
int16_t* dst = (int16_t*)p->buffer_ptr;
|
||||
size_t len = p->buffer_size;
|
||||
|
||||
// send only 1ms (bInterval) of samples
|
||||
if (s->f.srate[0] == 48000 || s->f.srate[0] == 8000)
|
||||
len = std::min(p->iov.size, outChns * sizeof(int16_t) * s->f.srate[0] / 1000);
|
||||
len = std::min<u32>(p->buffer_size, outChns * sizeof(int16_t) * s->f.srate[0] / 1000);
|
||||
|
||||
//Divide 'len' bytes between 2 channels of 16 bits
|
||||
uint32_t max_frames = len / (outChns * sizeof(uint16_t));
|
||||
|
||||
if (p->iov.niov == 1)
|
||||
dst = (int16_t*)p->iov.iov[0].iov_base;
|
||||
else
|
||||
{
|
||||
dst_alloc.resize(len / sizeof(int16_t));
|
||||
dst = dst_alloc.data();
|
||||
}
|
||||
|
||||
memset(dst, 0, len);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
|
@ -678,12 +669,7 @@ namespace usb_mic
|
|||
}
|
||||
|
||||
ret = ret * outChns * sizeof(int16_t);
|
||||
if (p->iov.niov > 1)
|
||||
{
|
||||
usb_packet_copy(p, dst_alloc.data(), ret);
|
||||
}
|
||||
else
|
||||
p->actual_length = ret;
|
||||
p->actual_length = ret;
|
||||
|
||||
#if 0 //defined(_DEBUG) && _MSC_VER > 1800
|
||||
if (!file)
|
||||
|
|
|
@ -456,7 +456,7 @@ namespace usb_msd
|
|||
size_t len;
|
||||
|
||||
assert(s->f.csw.sig == cpu_to_le32(0x53425355));
|
||||
len = std::min(sizeof(s->f.csw), p->iov.size);
|
||||
len = std::min<size_t>(sizeof(s->f.csw), p->buffer_size);
|
||||
usb_packet_copy(p, &s->f.csw, len);
|
||||
memset(&s->f.csw, 0, sizeof(s->f.csw));
|
||||
}
|
||||
|
@ -518,7 +518,7 @@ namespace usb_msd
|
|||
{
|
||||
if (s->f.data_len)
|
||||
{
|
||||
int len = (p->iov.size - p->actual_length);
|
||||
int len = (p->buffer_size - p->actual_length);
|
||||
usb_packet_skip(p, len);
|
||||
s->f.data_len -= len;
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ namespace usb_msd
|
|||
static void usb_msd_copy_data(MSDState* s, USBPacket* p)
|
||||
{
|
||||
size_t len, file_ret;
|
||||
len = p->iov.size - p->actual_length;
|
||||
len = p->buffer_size - p->actual_length;
|
||||
//if (len > s->scsi_len)
|
||||
// len = s->scsi_len;
|
||||
|
||||
|
@ -562,7 +562,7 @@ namespace usb_msd
|
|||
}
|
||||
break;
|
||||
case USB_MSDM_DATAIN:
|
||||
if ((file_ret = fread(s->f.buf, 1, p->iov.size, s->file)) < p->iov.size)
|
||||
if ((file_ret = fread(s->f.buf, 1, p->buffer_size, s->file)) < p->buffer_size)
|
||||
{
|
||||
s->f.result = COMMAND_FAILED;
|
||||
set_sense(s, SENSE_CODE(UNRECOVERED_READ_ERROR));
|
||||
|
@ -789,7 +789,7 @@ namespace usb_msd
|
|||
switch (s->f.mode)
|
||||
{
|
||||
case USB_MSDM_CBW:
|
||||
if (p->iov.size != 31)
|
||||
if (p->buffer_size != 31)
|
||||
{
|
||||
Console.Warning("usb-msd: Bad CBW size\n");
|
||||
goto fail;
|
||||
|
@ -829,12 +829,12 @@ namespace usb_msd
|
|||
|
||||
case USB_MSDM_DATAOUT:
|
||||
//TODO check if CBW still falls into here on write error a.k.a s->f.mode is set wrong
|
||||
if (p->iov.size > s->f.data_len)
|
||||
if (p->buffer_size > s->f.data_len)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (p->iov.size == 0) //TODO send status?
|
||||
if (p->buffer_size == 0) //TODO send status?
|
||||
goto send_csw;
|
||||
|
||||
//if (s->scsi_len)
|
||||
|
@ -843,7 +843,7 @@ namespace usb_msd
|
|||
}
|
||||
if (le32_to_cpu(s->f.csw.residue))
|
||||
{
|
||||
int len = p->iov.size - p->actual_length;
|
||||
int len = p->buffer_size - p->actual_length;
|
||||
if (len)
|
||||
{
|
||||
usb_packet_skip(p, len);
|
||||
|
@ -854,7 +854,7 @@ namespace usb_msd
|
|||
}
|
||||
}
|
||||
}
|
||||
if ((size_t)p->actual_length < p->iov.size)
|
||||
if ((size_t)p->actual_length < p->buffer_size)
|
||||
{
|
||||
s->packet = p;
|
||||
p->status = USB_RET_ASYNC;
|
||||
|
@ -876,7 +876,7 @@ namespace usb_msd
|
|||
switch (s->f.mode)
|
||||
{
|
||||
case USB_MSDM_DATAOUT:
|
||||
if (s->f.data_len != 0 || p->iov.size < 13)
|
||||
if (s->f.data_len != 0 || p->buffer_size < 13)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -887,7 +887,7 @@ namespace usb_msd
|
|||
|
||||
case USB_MSDM_CSW:
|
||||
send_csw:
|
||||
if (p->iov.size < 13)
|
||||
if (p->buffer_size < 13)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -910,7 +910,7 @@ namespace usb_msd
|
|||
|
||||
case USB_MSDM_DATAIN:
|
||||
//if (len == 13) goto send_csw;
|
||||
if (p->iov.size > s->f.data_len)
|
||||
if (p->buffer_size > s->f.data_len)
|
||||
{
|
||||
//len = s->f.data_len;
|
||||
s->f.result = COMMAND_FAILED;
|
||||
|
@ -924,7 +924,7 @@ namespace usb_msd
|
|||
}
|
||||
if (le32_to_cpu(s->f.csw.residue))
|
||||
{
|
||||
int len = p->iov.size - p->actual_length;
|
||||
int len = p->buffer_size - p->actual_length;
|
||||
if (len)
|
||||
{
|
||||
usb_packet_skip(p, len);
|
||||
|
@ -936,7 +936,7 @@ namespace usb_msd
|
|||
}
|
||||
}
|
||||
|
||||
if ((size_t)p->actual_length < p->iov.size)
|
||||
if ((size_t)p->actual_length < p->buffer_size)
|
||||
{
|
||||
s->packet = p;
|
||||
p->status = USB_RET_ASYNC;
|
||||
|
|
|
@ -587,20 +587,16 @@ namespace usb_pad
|
|||
static void pad_handle_data(USBDevice* dev, USBPacket* p)
|
||||
{
|
||||
PadState* s = USB_CONTAINER_OF(dev, PadState, dev);
|
||||
uint8_t data[64];
|
||||
|
||||
int ret = 0;
|
||||
uint8_t devep = p->ep->nr;
|
||||
|
||||
switch (p->pid)
|
||||
{
|
||||
case USB_TOKEN_IN:
|
||||
if (devep == 1)
|
||||
if (p->ep->nr == 1)
|
||||
{
|
||||
ret = s->TokenIn(data, p->iov.size);
|
||||
int ret = s->TokenIn(p->buffer_ptr, p->buffer_size);
|
||||
|
||||
if (ret > 0)
|
||||
usb_packet_copy(p, data, std::min(ret, (int)sizeof(data)));
|
||||
p->actual_length += std::min<u32>(static_cast<u32>(ret), p->buffer_size);
|
||||
else
|
||||
p->status = ret;
|
||||
}
|
||||
|
@ -610,11 +606,10 @@ namespace usb_pad
|
|||
}
|
||||
break;
|
||||
case USB_TOKEN_OUT:
|
||||
usb_packet_copy(p, data, std::min(p->iov.size, sizeof(data)));
|
||||
/*Console.Warning("usb-pad: data token out len=0x%X %X,%X,%X,%X,%X,%X,%X,%X\n",len,
|
||||
data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);*/
|
||||
//Console.Warning("usb-pad: data token out len=0x%X\n",len);
|
||||
ret = s->TokenOut(data, p->iov.size);
|
||||
s->TokenOut(p->buffer_ptr, p->buffer_size);
|
||||
break;
|
||||
default:
|
||||
fail:
|
||||
|
|
|
@ -247,7 +247,6 @@ namespace usb_pad
|
|||
SeamicState* s = USB_CONTAINER_OF(dev, SeamicState, dev);
|
||||
uint8_t data[64];
|
||||
|
||||
int ret = 0;
|
||||
uint8_t devep = p->ep->nr;
|
||||
|
||||
switch (p->pid)
|
||||
|
@ -259,7 +258,7 @@ namespace usb_pad
|
|||
}
|
||||
else if (devep == 2)
|
||||
{
|
||||
ret = s->TokenIn(data, p->iov.size);
|
||||
const int ret = s->TokenIn(data, p->buffer_size);
|
||||
if (ret > 0)
|
||||
usb_packet_copy(p, data, std::min((size_t)ret, sizeof(data)));
|
||||
else
|
||||
|
@ -271,8 +270,8 @@ namespace usb_pad
|
|||
}
|
||||
break;
|
||||
case USB_TOKEN_OUT:
|
||||
usb_packet_copy(p, data, std::min(p->iov.size, sizeof(data)));
|
||||
ret = s->TokenOut(data, p->iov.size);
|
||||
usb_packet_copy(p, data, p->buffer_size);
|
||||
s->TokenOut(data, p->buffer_size);
|
||||
break;
|
||||
default:
|
||||
fail:
|
||||
|
|
|
@ -218,7 +218,7 @@ namespace usb_printer
|
|||
switch (p->pid)
|
||||
{
|
||||
case USB_TOKEN_OUT:
|
||||
s->last_command_size = p->iov.size;
|
||||
s->last_command_size = p->buffer_size;
|
||||
usb_packet_copy(p, s->last_command, s->last_command_size);
|
||||
|
||||
if (s->cmd_state == 0 && s->last_command_size > 5)
|
||||
|
|
|
@ -341,7 +341,6 @@
|
|||
<ClCompile Include="USB\qemu-usb\desc.cpp" />
|
||||
<ClCompile Include="USB\qemu-usb\hid.cpp" />
|
||||
<ClCompile Include="USB\qemu-usb\input-keymap-qcode-to-qnum.cpp" />
|
||||
<ClCompile Include="USB\qemu-usb\iov.cpp" />
|
||||
<ClCompile Include="USB\qemu-usb\usb-ohci.cpp" />
|
||||
<ClCompile Include="USB\shared\ringbuffer.cpp" />
|
||||
<ClCompile Include="USB\usb-eyetoy\cam-windows.cpp" />
|
||||
|
@ -695,7 +694,6 @@
|
|||
<ClInclude Include="USB\qemu-usb\desc.h" />
|
||||
<ClInclude Include="USB\qemu-usb\hid.h" />
|
||||
<ClInclude Include="USB\qemu-usb\input-keymap.h" />
|
||||
<ClInclude Include="USB\qemu-usb\iov.h" />
|
||||
<ClInclude Include="USB\qemu-usb\queue.h" />
|
||||
<ClInclude Include="USB\qemu-usb\qusb.h" />
|
||||
<ClInclude Include="USB\qemu-usb\USBinternal.h" />
|
||||
|
|
|
@ -1353,9 +1353,6 @@
|
|||
<ClCompile Include="USB\qemu-usb\input-keymap-qcode-to-qnum.cpp">
|
||||
<Filter>System\Ps2\USB\qemu-usb</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="USB\qemu-usb\iov.cpp">
|
||||
<Filter>System\Ps2\USB\qemu-usb</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="USB\qemu-usb\usb-ohci.cpp">
|
||||
<Filter>System\Ps2\USB\qemu-usb</Filter>
|
||||
</ClCompile>
|
||||
|
@ -2306,9 +2303,6 @@
|
|||
<ClInclude Include="USB\USB.h">
|
||||
<Filter>System\Ps2\USB</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="USB\qemu-usb\iov.h">
|
||||
<Filter>System\Ps2\USB\qemu-usb</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="USB\qemu-usb\queue.h">
|
||||
<Filter>System\Ps2\USB\qemu-usb</Filter>
|
||||
</ClInclude>
|
||||
|
|
Loading…
Reference in New Issue