usb: make usb_packet_copy operate on combined packets
Likewise usb_packet_skip. Also usb_packet_size. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
e382d966d0
commit
6a98d1c0f9
1
hw/usb.h
1
hw/usb.h
@ -390,6 +390,7 @@ int usb_packet_map(USBPacket *p, QEMUSGList *sgl);
|
||||
void usb_packet_unmap(USBPacket *p, QEMUSGList *sgl);
|
||||
void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes);
|
||||
void usb_packet_skip(USBPacket *p, size_t bytes);
|
||||
size_t usb_packet_size(USBPacket *p);
|
||||
void usb_packet_cleanup(USBPacket *p);
|
||||
|
||||
static inline bool usb_packet_is_inflight(USBPacket *p)
|
||||
|
@ -570,15 +570,17 @@ void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len)
|
||||
|
||||
void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes)
|
||||
{
|
||||
QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov;
|
||||
|
||||
assert(p->actual_length >= 0);
|
||||
assert(p->actual_length + bytes <= p->iov.size);
|
||||
assert(p->actual_length + bytes <= iov->size);
|
||||
switch (p->pid) {
|
||||
case USB_TOKEN_SETUP:
|
||||
case USB_TOKEN_OUT:
|
||||
iov_to_buf(p->iov.iov, p->iov.niov, p->actual_length, ptr, bytes);
|
||||
iov_to_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
|
||||
break;
|
||||
case USB_TOKEN_IN:
|
||||
iov_from_buf(p->iov.iov, p->iov.niov, p->actual_length, ptr, bytes);
|
||||
iov_from_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: invalid pid: %x\n", __func__, p->pid);
|
||||
@ -589,14 +591,21 @@ 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(p->actual_length >= 0);
|
||||
assert(p->actual_length + bytes <= p->iov.size);
|
||||
assert(p->actual_length + bytes <= iov->size);
|
||||
if (p->pid == USB_TOKEN_IN) {
|
||||
iov_memset(p->iov.iov, p->iov.niov, p->actual_length, 0, bytes);
|
||||
iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes);
|
||||
}
|
||||
p->actual_length += bytes;
|
||||
}
|
||||
|
||||
size_t usb_packet_size(USBPacket *p)
|
||||
{
|
||||
return p->combined ? p->combined->iov.size : p->iov.size;
|
||||
}
|
||||
|
||||
void usb_packet_cleanup(USBPacket *p)
|
||||
{
|
||||
assert(!usb_packet_is_inflight(p));
|
||||
|
Loading…
Reference in New Issue
Block a user