2005-11-05 15:22:28 +01:00
|
|
|
/*
|
|
|
|
* USB UHCI controller emulation
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2005-11-05 15:22:28 +01:00
|
|
|
* Copyright (c) 2005 Fabrice Bellard
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2008-08-21 21:30:31 +02:00
|
|
|
* Copyright (c) 2008 Max Krasnyansky
|
|
|
|
* Magor rewrite of the UHCI data structures parser and frame processor
|
|
|
|
* Support for fully async operation and multiple outstanding transactions
|
|
|
|
*
|
2005-11-05 15:22:28 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-05-23 16:35:07 +02:00
|
|
|
|
2016-01-26 19:17:12 +01:00
|
|
|
#include "qemu/osdep.h"
|
2012-03-07 14:55:18 +01:00
|
|
|
#include "hw/usb.h"
|
2014-05-08 10:58:44 +02:00
|
|
|
#include "hw/usb/uhci-regs.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2012-12-12 13:24:50 +01:00
|
|
|
#include "hw/pci/pci.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/timer.h"
|
|
|
|
#include "qemu/iov.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/dma.h"
|
2012-03-08 13:12:38 +01:00
|
|
|
#include "trace.h"
|
2013-08-21 17:02:47 +02:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2005-11-05 15:22:28 +01:00
|
|
|
|
|
|
|
#define FRAME_TIMER_FREQ 1000
|
|
|
|
|
2012-01-26 13:57:40 +01:00
|
|
|
#define FRAME_MAX_LOOPS 256
|
2005-11-05 15:22:28 +01:00
|
|
|
|
2012-12-14 14:35:35 +01:00
|
|
|
/* Must be large enough to handle 10 frame delay for initial isoc requests */
|
|
|
|
#define QH_VALID 32
|
|
|
|
|
2012-12-14 14:35:36 +01:00
|
|
|
#define MAX_FRAMES_PER_TICK (QH_VALID / 2)
|
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
#define NB_PORTS 2
|
|
|
|
|
2012-03-09 11:09:49 +01:00
|
|
|
enum {
|
2012-03-09 11:11:46 +01:00
|
|
|
TD_RESULT_STOP_FRAME = 10,
|
|
|
|
TD_RESULT_COMPLETE,
|
|
|
|
TD_RESULT_NEXT_QH,
|
2012-03-09 11:15:41 +01:00
|
|
|
TD_RESULT_ASYNC_START,
|
|
|
|
TD_RESULT_ASYNC_CONT,
|
2012-03-09 11:09:49 +01:00
|
|
|
};
|
|
|
|
|
2010-12-15 10:26:15 +01:00
|
|
|
typedef struct UHCIState UHCIState;
|
2012-01-27 14:17:06 +01:00
|
|
|
typedef struct UHCIAsync UHCIAsync;
|
|
|
|
typedef struct UHCIQueue UHCIQueue;
|
2012-10-25 16:22:57 +02:00
|
|
|
typedef struct UHCIInfo UHCIInfo;
|
2012-10-26 14:56:19 +02:00
|
|
|
typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass;
|
2012-10-25 16:22:57 +02:00
|
|
|
|
|
|
|
struct UHCIInfo {
|
|
|
|
const char *name;
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint8_t revision;
|
2012-10-26 14:56:19 +02:00
|
|
|
uint8_t irq_pin;
|
2015-02-17 14:28:05 +01:00
|
|
|
void (*realize)(PCIDevice *dev, Error **errp);
|
2012-10-25 16:22:57 +02:00
|
|
|
bool unplug;
|
|
|
|
};
|
2010-12-15 10:26:15 +01:00
|
|
|
|
2012-10-26 14:56:19 +02:00
|
|
|
struct UHCIPCIDeviceClass {
|
|
|
|
PCIDeviceClass parent_class;
|
|
|
|
UHCIInfo info;
|
|
|
|
};
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
/*
|
|
|
|
* Pending async transaction.
|
|
|
|
* 'packet' must be the first field because completion
|
|
|
|
* handler does "(UHCIAsync *) pkt" cast.
|
|
|
|
*/
|
2012-01-27 14:17:06 +01:00
|
|
|
|
|
|
|
struct UHCIAsync {
|
2008-08-21 21:30:31 +02:00
|
|
|
USBPacket packet;
|
2013-05-06 10:48:57 +02:00
|
|
|
uint8_t static_buf[64]; /* 64 bytes is enough, except for isoc packets */
|
|
|
|
uint8_t *buf;
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIQueue *queue;
|
2010-12-14 18:19:47 +01:00
|
|
|
QTAILQ_ENTRY(UHCIAsync) next;
|
2012-10-24 18:31:10 +02:00
|
|
|
uint32_t td_addr;
|
2008-08-21 21:30:31 +02:00
|
|
|
uint8_t done;
|
2012-01-27 14:17:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UHCIQueue {
|
2012-10-24 18:31:15 +02:00
|
|
|
uint32_t qh_addr;
|
2012-01-27 14:17:06 +01:00
|
|
|
uint32_t token;
|
|
|
|
UHCIState *uhci;
|
2012-10-24 18:31:13 +02:00
|
|
|
USBEndpoint *ep;
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_ENTRY(UHCIQueue) next;
|
2018-12-06 13:10:34 +01:00
|
|
|
QTAILQ_HEAD(, UHCIAsync) asyncs;
|
2012-01-27 14:17:06 +01:00
|
|
|
int8_t valid;
|
|
|
|
};
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
typedef struct UHCIPort {
|
|
|
|
USBPort port;
|
|
|
|
uint16_t ctrl;
|
|
|
|
} UHCIPort;
|
|
|
|
|
2010-12-15 10:26:15 +01:00
|
|
|
struct UHCIState {
|
2005-11-05 15:22:28 +01:00
|
|
|
PCIDevice dev;
|
2011-08-08 15:09:24 +02:00
|
|
|
MemoryRegion io_bar;
|
2011-06-24 17:44:53 +02:00
|
|
|
USBBus bus; /* Note unused when we're a companion controller */
|
2005-11-05 15:22:28 +01:00
|
|
|
uint16_t cmd; /* cmd register */
|
|
|
|
uint16_t status;
|
|
|
|
uint16_t intr; /* interrupt enable register */
|
|
|
|
uint16_t frnum; /* frame number */
|
|
|
|
uint32_t fl_base_addr; /* frame list base address */
|
|
|
|
uint8_t sof_timing;
|
|
|
|
uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */
|
2010-02-03 16:49:39 +01:00
|
|
|
int64_t expire_time;
|
2005-11-05 15:22:28 +01:00
|
|
|
QEMUTimer *frame_timer;
|
2012-05-11 09:33:07 +02:00
|
|
|
QEMUBH *bh;
|
2012-05-11 09:18:05 +02:00
|
|
|
uint32_t frame_bytes;
|
2012-05-11 10:02:53 +02:00
|
|
|
uint32_t frame_bandwidth;
|
2012-11-17 12:11:49 +01:00
|
|
|
bool completions_only;
|
2005-11-05 15:22:28 +01:00
|
|
|
UHCIPort ports[NB_PORTS];
|
2006-08-12 03:04:27 +02:00
|
|
|
|
|
|
|
/* Interrupts that should be raised at the end of the current frame. */
|
|
|
|
uint32_t pending_int_mask;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
/* Active packets */
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_HEAD(, UHCIQueue) queues;
|
2009-10-14 12:21:50 +02:00
|
|
|
uint8_t num_ports_vmstate;
|
2011-06-24 17:44:53 +02:00
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
char *masterbus;
|
|
|
|
uint32_t firstport;
|
2012-12-14 14:35:37 +01:00
|
|
|
uint32_t maxframes;
|
2010-12-15 10:26:15 +01:00
|
|
|
};
|
2005-11-05 15:22:28 +01:00
|
|
|
|
|
|
|
typedef struct UHCI_TD {
|
|
|
|
uint32_t link;
|
|
|
|
uint32_t ctrl; /* see TD_CTRL_xxx */
|
|
|
|
uint32_t token;
|
|
|
|
uint32_t buffer;
|
|
|
|
} UHCI_TD;
|
|
|
|
|
|
|
|
typedef struct UHCI_QH {
|
|
|
|
uint32_t link;
|
|
|
|
uint32_t el_link;
|
|
|
|
} UHCI_QH;
|
|
|
|
|
2012-10-24 18:31:09 +02:00
|
|
|
static void uhci_async_cancel(UHCIAsync *async);
|
2012-10-24 18:31:13 +02:00
|
|
|
static void uhci_queue_fill(UHCIQueue *q, UHCI_TD *td);
|
2013-06-26 17:05:06 +02:00
|
|
|
static void uhci_resume(void *opaque);
|
2012-10-24 18:31:09 +02:00
|
|
|
|
2015-05-06 14:55:23 +02:00
|
|
|
#define TYPE_UHCI "pci-uhci-usb"
|
2020-08-31 23:07:33 +02:00
|
|
|
DECLARE_INSTANCE_CHECKER(UHCIState, UHCI,
|
|
|
|
TYPE_UHCI)
|
2015-05-06 14:55:23 +02:00
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
static inline int32_t uhci_queue_token(UHCI_TD *td)
|
|
|
|
{
|
2012-10-24 18:31:20 +02:00
|
|
|
if ((td->token & (0xf << 15)) == 0) {
|
|
|
|
/* ctrl ep, cover ep and dev, not pid! */
|
|
|
|
return td->token & 0x7ff00;
|
|
|
|
} else {
|
|
|
|
/* covers ep, dev, pid -> identifies the endpoint */
|
|
|
|
return td->token & 0x7ffff;
|
|
|
|
}
|
2012-01-27 14:17:06 +01:00
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:15 +02:00
|
|
|
static UHCIQueue *uhci_queue_new(UHCIState *s, uint32_t qh_addr, UHCI_TD *td,
|
|
|
|
USBEndpoint *ep)
|
2012-01-27 14:17:06 +01:00
|
|
|
{
|
|
|
|
UHCIQueue *queue;
|
|
|
|
|
|
|
|
queue = g_new0(UHCIQueue, 1);
|
|
|
|
queue->uhci = s;
|
2012-10-24 18:31:15 +02:00
|
|
|
queue->qh_addr = qh_addr;
|
|
|
|
queue->token = uhci_queue_token(td);
|
2012-10-24 18:31:13 +02:00
|
|
|
queue->ep = ep;
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_INIT(&queue->asyncs);
|
|
|
|
QTAILQ_INSERT_HEAD(&s->queues, queue, next);
|
2012-12-14 14:35:35 +01:00
|
|
|
queue->valid = QH_VALID;
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_queue_add(queue->token);
|
2012-01-27 14:17:06 +01:00
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:15 +02:00
|
|
|
static void uhci_queue_free(UHCIQueue *queue, const char *reason)
|
2012-01-27 14:17:06 +01:00
|
|
|
{
|
|
|
|
UHCIState *s = queue->uhci;
|
2012-10-24 18:31:09 +02:00
|
|
|
UHCIAsync *async;
|
|
|
|
|
|
|
|
while (!QTAILQ_EMPTY(&queue->asyncs)) {
|
|
|
|
async = QTAILQ_FIRST(&queue->asyncs);
|
|
|
|
uhci_async_cancel(async);
|
|
|
|
}
|
2012-12-14 14:35:40 +01:00
|
|
|
usb_device_ep_stopped(queue->ep->dev, queue->ep);
|
2012-01-27 14:17:06 +01:00
|
|
|
|
2012-10-24 18:31:15 +02:00
|
|
|
trace_usb_uhci_queue_del(queue->token, reason);
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_REMOVE(&s->queues, queue, next);
|
|
|
|
g_free(queue);
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:15 +02:00
|
|
|
static UHCIQueue *uhci_queue_find(UHCIState *s, UHCI_TD *td)
|
|
|
|
{
|
|
|
|
uint32_t token = uhci_queue_token(td);
|
|
|
|
UHCIQueue *queue;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(queue, &s->queues, next) {
|
|
|
|
if (queue->token == token) {
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool uhci_queue_verify(UHCIQueue *queue, uint32_t qh_addr, UHCI_TD *td,
|
|
|
|
uint32_t td_addr, bool queuing)
|
|
|
|
{
|
|
|
|
UHCIAsync *first = QTAILQ_FIRST(&queue->asyncs);
|
2014-02-05 14:54:14 +01:00
|
|
|
uint32_t queue_token_addr = (queue->token >> 8) & 0x7f;
|
2012-10-24 18:31:15 +02:00
|
|
|
|
|
|
|
return queue->qh_addr == qh_addr &&
|
|
|
|
queue->token == uhci_queue_token(td) &&
|
2014-02-05 14:54:14 +01:00
|
|
|
queue_token_addr == queue->ep->dev->addr &&
|
2012-10-24 18:31:15 +02:00
|
|
|
(queuing || !(td->ctrl & TD_CTRL_ACTIVE) || first == NULL ||
|
|
|
|
first->td_addr == td_addr);
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:10 +02:00
|
|
|
static UHCIAsync *uhci_async_alloc(UHCIQueue *queue, uint32_t td_addr)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-01-27 14:17:59 +01:00
|
|
|
UHCIAsync *async = g_new0(UHCIAsync, 1);
|
2009-02-05 23:06:05 +01:00
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
async->queue = queue;
|
2012-10-24 18:31:10 +02:00
|
|
|
async->td_addr = td_addr;
|
2011-07-12 15:22:25 +02:00
|
|
|
usb_packet_init(&async->packet);
|
2012-10-24 18:31:10 +02:00
|
|
|
trace_usb_uhci_packet_add(async->queue->token, async->td_addr);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
return async;
|
|
|
|
}
|
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
static void uhci_async_free(UHCIAsync *async)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-10-24 18:31:10 +02:00
|
|
|
trace_usb_uhci_packet_del(async->queue->token, async->td_addr);
|
2011-07-12 15:22:25 +02:00
|
|
|
usb_packet_cleanup(&async->packet);
|
2013-05-06 10:48:57 +02:00
|
|
|
if (async->buf != async->static_buf) {
|
|
|
|
g_free(async->buf);
|
|
|
|
}
|
2011-08-21 05:09:37 +02:00
|
|
|
g_free(async);
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
static void uhci_async_link(UHCIAsync *async)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIQueue *queue = async->queue;
|
|
|
|
QTAILQ_INSERT_TAIL(&queue->asyncs, async, next);
|
2012-10-24 18:31:10 +02:00
|
|
|
trace_usb_uhci_packet_link_async(async->queue->token, async->td_addr);
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
static void uhci_async_unlink(UHCIAsync *async)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIQueue *queue = async->queue;
|
|
|
|
QTAILQ_REMOVE(&queue->asyncs, async, next);
|
2012-10-24 18:31:10 +02:00
|
|
|
trace_usb_uhci_packet_unlink_async(async->queue->token, async->td_addr);
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
static void uhci_async_cancel(UHCIAsync *async)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-10-24 18:31:06 +02:00
|
|
|
uhci_async_unlink(async);
|
2012-10-24 18:31:10 +02:00
|
|
|
trace_usb_uhci_packet_cancel(async->queue->token, async->td_addr,
|
|
|
|
async->done);
|
2008-08-21 21:30:31 +02:00
|
|
|
if (!async->done)
|
|
|
|
usb_cancel_packet(&async->packet);
|
2012-01-27 14:17:06 +01:00
|
|
|
uhci_async_free(async);
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark all outstanding async packets as invalid.
|
|
|
|
* This is used for canceling them when TDs are removed by the HCD.
|
|
|
|
*/
|
2012-01-27 14:17:06 +01:00
|
|
|
static void uhci_async_validate_begin(UHCIState *s)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIQueue *queue;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_FOREACH(queue, &s->queues, next) {
|
|
|
|
queue->valid--;
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel async packets that are no longer valid
|
|
|
|
*/
|
|
|
|
static void uhci_async_validate_end(UHCIState *s)
|
|
|
|
{
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIQueue *queue, *n;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_FOREACH_SAFE(queue, &s->queues, next, n) {
|
2012-10-24 18:31:09 +02:00
|
|
|
if (!queue->valid) {
|
2012-10-24 18:31:15 +02:00
|
|
|
uhci_queue_free(queue, "validate-end");
|
2012-01-27 14:17:06 +01:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-23 17:37:12 +02:00
|
|
|
static void uhci_async_cancel_device(UHCIState *s, USBDevice *dev)
|
|
|
|
{
|
2012-10-24 18:31:14 +02:00
|
|
|
UHCIQueue *queue, *n;
|
2011-05-23 17:37:12 +02:00
|
|
|
|
2012-10-24 18:31:14 +02:00
|
|
|
QTAILQ_FOREACH_SAFE(queue, &s->queues, next, n) {
|
|
|
|
if (queue->ep->dev == dev) {
|
|
|
|
uhci_queue_free(queue, "cancel-device");
|
2011-05-23 17:37:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
static void uhci_async_cancel_all(UHCIState *s)
|
|
|
|
{
|
2012-06-15 09:39:50 +02:00
|
|
|
UHCIQueue *queue, *nq;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-06-15 09:39:50 +02:00
|
|
|
QTAILQ_FOREACH_SAFE(queue, &s->queues, next, nq) {
|
2012-10-24 18:31:15 +02:00
|
|
|
uhci_queue_free(queue, "cancel-all");
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:16 +02:00
|
|
|
static UHCIAsync *uhci_async_find_td(UHCIState *s, uint32_t td_addr)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIQueue *queue;
|
2010-12-14 18:19:47 +01:00
|
|
|
UHCIAsync *async;
|
2008-08-22 11:23:06 +02:00
|
|
|
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_FOREACH(queue, &s->queues, next) {
|
2012-10-24 18:31:16 +02:00
|
|
|
QTAILQ_FOREACH(async, &queue->asyncs, next) {
|
|
|
|
if (async->td_addr == td_addr) {
|
|
|
|
return async;
|
|
|
|
}
|
2012-01-27 14:17:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
static void uhci_update_irq(UHCIState *s)
|
|
|
|
{
|
|
|
|
int level;
|
|
|
|
if (((s->status2 & 1) && (s->intr & (1 << 2))) ||
|
|
|
|
((s->status2 & 2) && (s->intr & (1 << 3))) ||
|
|
|
|
((s->status & UHCI_STS_USBERR) && (s->intr & (1 << 0))) ||
|
|
|
|
((s->status & UHCI_STS_RD) && (s->intr & (1 << 1))) ||
|
|
|
|
(s->status & UHCI_STS_HSERR) ||
|
|
|
|
(s->status & UHCI_STS_HCPERR)) {
|
|
|
|
level = 1;
|
|
|
|
} else {
|
|
|
|
level = 0;
|
|
|
|
}
|
2013-10-07 09:36:39 +02:00
|
|
|
pci_set_irq(&s->dev, level);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 10:33:46 +01:00
|
|
|
static void uhci_reset(DeviceState *dev)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
2015-03-18 10:33:46 +01:00
|
|
|
PCIDevice *d = PCI_DEVICE(dev);
|
2015-05-06 14:55:23 +02:00
|
|
|
UHCIState *s = UHCI(d);
|
2005-11-05 15:22:28 +01:00
|
|
|
uint8_t *pci_conf;
|
|
|
|
int i;
|
|
|
|
UHCIPort *port;
|
|
|
|
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_reset();
|
2008-08-21 21:33:09 +02:00
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
pci_conf = s->dev.config;
|
|
|
|
|
|
|
|
pci_conf[0x6a] = 0x01; /* usb clock */
|
|
|
|
pci_conf[0x6b] = 0x00;
|
|
|
|
s->cmd = 0;
|
2015-05-07 09:24:00 +02:00
|
|
|
s->status = UHCI_STS_HCHALTED;
|
2005-11-05 15:22:28 +01:00
|
|
|
s->status2 = 0;
|
|
|
|
s->intr = 0;
|
|
|
|
s->fl_base_addr = 0;
|
|
|
|
s->sof_timing = 64;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
for(i = 0; i < NB_PORTS; i++) {
|
|
|
|
port = &s->ports[i];
|
|
|
|
port->ctrl = 0x0080;
|
2011-09-01 13:56:37 +02:00
|
|
|
if (port->port.dev && port->port.dev->attached) {
|
2012-01-06 15:23:10 +01:00
|
|
|
usb_port_reset(&port->port);
|
2010-12-01 11:27:05 +01:00
|
|
|
}
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
uhci_async_cancel_all(s);
|
2012-05-11 09:33:07 +02:00
|
|
|
qemu_bh_cancel(s->bh);
|
2012-04-20 15:13:24 +02:00
|
|
|
uhci_update_irq(s);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:49:30 +02:00
|
|
|
static const VMStateDescription vmstate_uhci_port = {
|
|
|
|
.name = "uhci port",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 13:31:26 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2009-10-14 12:49:30 +02:00
|
|
|
VMSTATE_UINT16(ctrl, UHCIPort),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-10 12:51:07 +02:00
|
|
|
static int uhci_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
UHCIState *s = opaque;
|
|
|
|
|
|
|
|
if (version_id < 2) {
|
2013-08-21 17:03:08 +02:00
|
|
|
s->expire_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
2016-03-21 17:02:30 +01:00
|
|
|
(NANOSECONDS_PER_SECOND / FRAME_TIMER_FREQ);
|
2012-07-10 12:51:07 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:49:30 +02:00
|
|
|
static const VMStateDescription vmstate_uhci = {
|
|
|
|
.name = "uhci",
|
2012-12-14 14:35:34 +01:00
|
|
|
.version_id = 3,
|
2009-10-14 12:49:30 +02:00
|
|
|
.minimum_version_id = 1,
|
2012-07-10 12:51:07 +02:00
|
|
|
.post_load = uhci_post_load,
|
2014-04-16 13:31:26 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2009-10-14 12:49:30 +02:00
|
|
|
VMSTATE_PCI_DEVICE(dev, UHCIState),
|
2017-06-23 16:48:23 +02:00
|
|
|
VMSTATE_UINT8_EQUAL(num_ports_vmstate, UHCIState, NULL),
|
2009-10-14 12:49:30 +02:00
|
|
|
VMSTATE_STRUCT_ARRAY(ports, UHCIState, NB_PORTS, 1,
|
|
|
|
vmstate_uhci_port, UHCIPort),
|
|
|
|
VMSTATE_UINT16(cmd, UHCIState),
|
|
|
|
VMSTATE_UINT16(status, UHCIState),
|
|
|
|
VMSTATE_UINT16(intr, UHCIState),
|
|
|
|
VMSTATE_UINT16(frnum, UHCIState),
|
|
|
|
VMSTATE_UINT32(fl_base_addr, UHCIState),
|
|
|
|
VMSTATE_UINT8(sof_timing, UHCIState),
|
|
|
|
VMSTATE_UINT8(status2, UHCIState),
|
2015-01-08 10:18:59 +01:00
|
|
|
VMSTATE_TIMER_PTR(frame_timer, UHCIState),
|
2010-06-01 06:26:20 +02:00
|
|
|
VMSTATE_INT64_V(expire_time, UHCIState, 2),
|
2012-12-14 14:35:34 +01:00
|
|
|
VMSTATE_UINT32_V(pending_int_mask, UHCIState, 3),
|
2009-10-14 12:49:30 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2007-10-05 00:47:34 +02:00
|
|
|
|
2013-01-03 12:29:41 +01:00
|
|
|
static void uhci_port_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
|
|
|
UHCIState *s = opaque;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_mmio_writew(addr, val);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
switch(addr) {
|
|
|
|
case 0x00:
|
|
|
|
if ((val & UHCI_CMD_RS) && !(s->cmd & UHCI_CMD_RS)) {
|
|
|
|
/* start frame processing */
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_schedule_start();
|
2013-08-21 17:03:08 +02:00
|
|
|
s->expire_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
2016-03-21 17:02:30 +01:00
|
|
|
(NANOSECONDS_PER_SECOND / FRAME_TIMER_FREQ);
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->frame_timer, s->expire_time);
|
2006-04-24 23:38:50 +02:00
|
|
|
s->status &= ~UHCI_STS_HCHALTED;
|
2006-04-25 23:01:19 +02:00
|
|
|
} else if (!(val & UHCI_CMD_RS)) {
|
2006-04-24 23:38:50 +02:00
|
|
|
s->status |= UHCI_STS_HCHALTED;
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
if (val & UHCI_CMD_GRESET) {
|
|
|
|
UHCIPort *port;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* send reset on the USB bus */
|
|
|
|
for(i = 0; i < NB_PORTS; i++) {
|
|
|
|
port = &s->ports[i];
|
2012-01-06 15:23:10 +01:00
|
|
|
usb_device_reset(port->port.dev);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2015-03-18 10:33:46 +01:00
|
|
|
uhci_reset(DEVICE(s));
|
2005-11-05 15:22:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-11-19 18:43:37 +01:00
|
|
|
if (val & UHCI_CMD_HCRESET) {
|
2015-03-18 10:33:46 +01:00
|
|
|
uhci_reset(DEVICE(s));
|
2005-11-05 15:22:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->cmd = val;
|
2013-06-26 17:05:06 +02:00
|
|
|
if (val & UHCI_CMD_EGSM) {
|
|
|
|
if ((s->ports[0].ctrl & UHCI_PORT_RD) ||
|
|
|
|
(s->ports[1].ctrl & UHCI_PORT_RD)) {
|
|
|
|
uhci_resume(s);
|
|
|
|
}
|
|
|
|
}
|
2005-11-05 15:22:28 +01:00
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
s->status &= ~val;
|
|
|
|
/* XXX: the chip spec is not coherent, so we add a hidden
|
|
|
|
register to distinguish between IOC and SPD */
|
|
|
|
if (val & UHCI_STS_USBINT)
|
|
|
|
s->status2 = 0;
|
|
|
|
uhci_update_irq(s);
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
s->intr = val;
|
|
|
|
uhci_update_irq(s);
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
if (s->status & UHCI_STS_HCHALTED)
|
|
|
|
s->frnum = val & 0x7ff;
|
|
|
|
break;
|
2013-01-03 12:29:41 +01:00
|
|
|
case 0x08:
|
|
|
|
s->fl_base_addr &= 0xffff0000;
|
|
|
|
s->fl_base_addr |= val & ~0xfff;
|
|
|
|
break;
|
|
|
|
case 0x0a:
|
|
|
|
s->fl_base_addr &= 0x0000ffff;
|
|
|
|
s->fl_base_addr |= (val << 16);
|
|
|
|
break;
|
|
|
|
case 0x0c:
|
|
|
|
s->sof_timing = val & 0xff;
|
|
|
|
break;
|
2005-11-05 15:22:28 +01:00
|
|
|
case 0x10 ... 0x1f:
|
|
|
|
{
|
|
|
|
UHCIPort *port;
|
|
|
|
USBDevice *dev;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = (addr >> 1) & 7;
|
|
|
|
if (n >= NB_PORTS)
|
|
|
|
return;
|
|
|
|
port = &s->ports[n];
|
2005-11-06 17:13:29 +01:00
|
|
|
dev = port->port.dev;
|
2011-09-01 13:56:37 +02:00
|
|
|
if (dev && dev->attached) {
|
2005-11-05 15:22:28 +01:00
|
|
|
/* port reset */
|
2007-09-16 23:08:06 +02:00
|
|
|
if ( (val & UHCI_PORT_RESET) &&
|
2005-11-05 15:22:28 +01:00
|
|
|
!(port->ctrl & UHCI_PORT_RESET) ) {
|
2012-01-06 15:23:10 +01:00
|
|
|
usb_device_reset(dev);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-01 11:47:40 +01:00
|
|
|
port->ctrl &= UHCI_PORT_READ_ONLY;
|
2012-11-17 12:11:50 +01:00
|
|
|
/* enabled may only be set if a device is connected */
|
|
|
|
if (!(port->ctrl & UHCI_PORT_CCS)) {
|
|
|
|
val &= ~UHCI_PORT_EN;
|
|
|
|
}
|
2010-12-01 11:47:40 +01:00
|
|
|
port->ctrl |= (val & ~UHCI_PORT_READ_ONLY);
|
2005-11-05 15:22:28 +01:00
|
|
|
/* some bits are reset when a '1' is written to them */
|
2010-12-01 11:47:40 +01:00
|
|
|
port->ctrl &= ~(val & UHCI_PORT_WRITE_CLEAR);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:29:41 +01:00
|
|
|
static uint64_t uhci_port_read(void *opaque, hwaddr addr, unsigned size)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
|
|
|
UHCIState *s = opaque;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
switch(addr) {
|
|
|
|
case 0x00:
|
|
|
|
val = s->cmd;
|
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
val = s->status;
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
val = s->intr;
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
val = s->frnum;
|
|
|
|
break;
|
2013-01-03 12:29:41 +01:00
|
|
|
case 0x08:
|
|
|
|
val = s->fl_base_addr & 0xffff;
|
|
|
|
break;
|
|
|
|
case 0x0a:
|
|
|
|
val = (s->fl_base_addr >> 16) & 0xffff;
|
|
|
|
break;
|
|
|
|
case 0x0c:
|
|
|
|
val = s->sof_timing;
|
|
|
|
break;
|
2005-11-05 15:22:28 +01:00
|
|
|
case 0x10 ... 0x1f:
|
|
|
|
{
|
|
|
|
UHCIPort *port;
|
|
|
|
int n;
|
|
|
|
n = (addr >> 1) & 7;
|
2007-09-16 23:08:06 +02:00
|
|
|
if (n >= NB_PORTS)
|
2005-11-05 15:22:28 +01:00
|
|
|
goto read_default;
|
|
|
|
port = &s->ports[n];
|
|
|
|
val = port->ctrl;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
read_default:
|
|
|
|
val = 0xff7f; /* disabled port */
|
|
|
|
break;
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_mmio_readw(addr, val);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2007-02-22 21:21:33 +01:00
|
|
|
/* signal resume if controller suspended */
|
|
|
|
static void uhci_resume (void *opaque)
|
|
|
|
{
|
|
|
|
UHCIState *s = (UHCIState *)opaque;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (s->cmd & UHCI_CMD_EGSM) {
|
|
|
|
s->cmd |= UHCI_CMD_FGR;
|
|
|
|
s->status |= UHCI_STS_RD;
|
|
|
|
uhci_update_irq(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-01 11:27:05 +01:00
|
|
|
static void uhci_attach(USBPort *port1)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
|
|
|
UHCIState *s = port1->opaque;
|
|
|
|
UHCIPort *port = &s->ports[port1->index];
|
|
|
|
|
2010-12-01 11:27:05 +01:00
|
|
|
/* set connect status */
|
|
|
|
port->ctrl |= UHCI_PORT_CCS | UHCI_PORT_CSC;
|
2006-05-22 19:17:06 +02:00
|
|
|
|
2010-12-01 11:27:05 +01:00
|
|
|
/* update speed */
|
|
|
|
if (port->port.dev->speed == USB_SPEED_LOW) {
|
|
|
|
port->ctrl |= UHCI_PORT_LSDA;
|
2005-11-05 15:22:28 +01:00
|
|
|
} else {
|
2010-12-01 11:27:05 +01:00
|
|
|
port->ctrl &= ~UHCI_PORT_LSDA;
|
|
|
|
}
|
2007-02-22 21:21:33 +01:00
|
|
|
|
2010-12-01 11:27:05 +01:00
|
|
|
uhci_resume(s);
|
|
|
|
}
|
2007-02-22 21:21:33 +01:00
|
|
|
|
2010-12-01 11:27:05 +01:00
|
|
|
static void uhci_detach(USBPort *port1)
|
|
|
|
{
|
|
|
|
UHCIState *s = port1->opaque;
|
|
|
|
UHCIPort *port = &s->ports[port1->index];
|
|
|
|
|
2011-06-24 12:31:11 +02:00
|
|
|
uhci_async_cancel_device(s, port1->dev);
|
|
|
|
|
2010-12-01 11:27:05 +01:00
|
|
|
/* set connect status */
|
|
|
|
if (port->ctrl & UHCI_PORT_CCS) {
|
|
|
|
port->ctrl &= ~UHCI_PORT_CCS;
|
|
|
|
port->ctrl |= UHCI_PORT_CSC;
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2010-12-01 11:27:05 +01:00
|
|
|
/* disable port */
|
|
|
|
if (port->ctrl & UHCI_PORT_EN) {
|
|
|
|
port->ctrl &= ~UHCI_PORT_EN;
|
|
|
|
port->ctrl |= UHCI_PORT_ENC;
|
|
|
|
}
|
|
|
|
|
|
|
|
uhci_resume(s);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
|
2011-06-24 12:31:11 +02:00
|
|
|
static void uhci_child_detach(USBPort *port1, USBDevice *child)
|
|
|
|
{
|
|
|
|
UHCIState *s = port1->opaque;
|
|
|
|
|
|
|
|
uhci_async_cancel_device(s, child);
|
|
|
|
}
|
|
|
|
|
2011-06-21 11:52:28 +02:00
|
|
|
static void uhci_wakeup(USBPort *port1)
|
2010-12-01 11:47:40 +01:00
|
|
|
{
|
2011-06-21 11:52:28 +02:00
|
|
|
UHCIState *s = port1->opaque;
|
|
|
|
UHCIPort *port = &s->ports[port1->index];
|
2010-12-01 11:47:40 +01:00
|
|
|
|
|
|
|
if (port->ctrl & UHCI_PORT_SUSPEND && !(port->ctrl & UHCI_PORT_RD)) {
|
|
|
|
port->ctrl |= UHCI_PORT_RD;
|
|
|
|
uhci_resume(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 17:34:24 +01:00
|
|
|
static USBDevice *uhci_find_device(UHCIState *s, uint8_t addr)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
2012-01-10 17:34:24 +01:00
|
|
|
USBDevice *dev;
|
|
|
|
int i;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-10 17:34:24 +01:00
|
|
|
for (i = 0; i < NB_PORTS; i++) {
|
2008-08-21 21:30:31 +02:00
|
|
|
UHCIPort *port = &s->ports[i];
|
2012-01-10 17:34:24 +01:00
|
|
|
if (!(port->ctrl & UHCI_PORT_EN)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dev = usb_find_device(&port->port, addr);
|
|
|
|
if (dev != NULL) {
|
|
|
|
return dev;
|
2011-09-01 13:56:37 +02:00
|
|
|
}
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2012-01-10 17:34:24 +01:00
|
|
|
return NULL;
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:11 +02:00
|
|
|
static void uhci_read_td(UHCIState *s, UHCI_TD *td, uint32_t link)
|
|
|
|
{
|
|
|
|
pci_dma_read(&s->dev, link & ~0xf, td, sizeof(*td));
|
|
|
|
le32_to_cpus(&td->link);
|
|
|
|
le32_to_cpus(&td->ctrl);
|
|
|
|
le32_to_cpus(&td->token);
|
|
|
|
le32_to_cpus(&td->buffer);
|
|
|
|
}
|
|
|
|
|
2012-10-31 12:54:36 +01:00
|
|
|
static int uhci_handle_td_error(UHCIState *s, UHCI_TD *td, uint32_t td_addr,
|
|
|
|
int status, uint32_t *int_mask)
|
|
|
|
{
|
|
|
|
uint32_t queue_token = uhci_queue_token(td);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case USB_RET_NAK:
|
|
|
|
td->ctrl |= TD_CTRL_NAK;
|
|
|
|
return TD_RESULT_NEXT_QH;
|
|
|
|
|
|
|
|
case USB_RET_STALL:
|
|
|
|
td->ctrl |= TD_CTRL_STALL;
|
|
|
|
trace_usb_uhci_packet_complete_stall(queue_token, td_addr);
|
|
|
|
ret = TD_RESULT_NEXT_QH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_RET_BABBLE:
|
|
|
|
td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL;
|
|
|
|
/* frame interrupted */
|
|
|
|
trace_usb_uhci_packet_complete_babble(queue_token, td_addr);
|
|
|
|
ret = TD_RESULT_STOP_FRAME;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_RET_IOERROR:
|
|
|
|
case USB_RET_NODEV:
|
|
|
|
default:
|
|
|
|
td->ctrl |= TD_CTRL_TIMEOUT;
|
|
|
|
td->ctrl &= ~(3 << TD_CTRL_ERROR_SHIFT);
|
|
|
|
trace_usb_uhci_packet_complete_error(queue_token, td_addr);
|
|
|
|
ret = TD_RESULT_NEXT_QH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
td->ctrl &= ~TD_CTRL_ACTIVE;
|
|
|
|
s->status |= UHCI_STS_USBERR;
|
|
|
|
if (td->ctrl & TD_CTRL_IOC) {
|
|
|
|
*int_mask |= 0x01;
|
|
|
|
}
|
|
|
|
uhci_update_irq(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
static int uhci_complete_td(UHCIState *s, UHCI_TD *td, UHCIAsync *async, uint32_t *int_mask)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
int len = 0, max_len;
|
2005-11-05 15:22:28 +01:00
|
|
|
uint8_t pid;
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
max_len = ((td->token >> 21) + 1) & 0x7ff;
|
|
|
|
pid = td->token & 0xff;
|
|
|
|
|
|
|
|
if (td->ctrl & TD_CTRL_IOS)
|
|
|
|
td->ctrl &= ~TD_CTRL_ACTIVE;
|
2005-11-05 15:22:28 +01:00
|
|
|
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
if (async->packet.status != USB_RET_SUCCESS) {
|
|
|
|
return uhci_handle_td_error(s, td, async->td_addr,
|
|
|
|
async->packet.status, int_mask);
|
2012-10-31 12:54:36 +01:00
|
|
|
}
|
2007-10-05 00:47:34 +02:00
|
|
|
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
len = async->packet.actual_length;
|
2008-08-21 21:30:31 +02:00
|
|
|
td->ctrl = (td->ctrl & ~0x7ff) | ((len - 1) & 0x7ff);
|
|
|
|
|
|
|
|
/* The NAK bit may have been set by a previous frame, so clear it
|
|
|
|
here. The docs are somewhat unclear, but win2k relies on this
|
|
|
|
behavior. */
|
|
|
|
td->ctrl &= ~(TD_CTRL_ACTIVE | TD_CTRL_NAK);
|
2010-04-04 22:48:31 +02:00
|
|
|
if (td->ctrl & TD_CTRL_IOC)
|
|
|
|
*int_mask |= 0x01;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
if (pid == USB_TOKEN_IN) {
|
2013-05-06 10:48:57 +02:00
|
|
|
pci_dma_write(&s->dev, td->buffer, async->buf, len);
|
2008-08-21 21:30:31 +02:00
|
|
|
if ((td->ctrl & TD_CTRL_SPD) && len < max_len) {
|
2005-11-05 15:22:28 +01:00
|
|
|
*int_mask |= 0x02;
|
|
|
|
/* short packet: do not update QH */
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_packet_complete_shortxfer(async->queue->token,
|
2012-10-24 18:31:10 +02:00
|
|
|
async->td_addr);
|
2012-03-09 11:09:49 +01:00
|
|
|
return TD_RESULT_NEXT_QH;
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* success */
|
2012-10-24 18:31:10 +02:00
|
|
|
trace_usb_uhci_packet_complete_success(async->queue->token,
|
|
|
|
async->td_addr);
|
2012-03-09 11:09:49 +01:00
|
|
|
return TD_RESULT_COMPLETE;
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:15 +02:00
|
|
|
static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,
|
2012-10-24 18:31:12 +02:00
|
|
|
UHCI_TD *td, uint32_t td_addr, uint32_t *int_mask)
|
2008-08-21 21:30:31 +02:00
|
|
|
{
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
int ret, max_len;
|
2012-10-24 18:14:09 +02:00
|
|
|
bool spd;
|
2012-10-24 18:31:12 +02:00
|
|
|
bool queuing = (q != NULL);
|
2012-10-24 18:31:13 +02:00
|
|
|
uint8_t pid = td->token & 0xff;
|
2016-02-19 08:33:58 +01:00
|
|
|
UHCIAsync *async;
|
|
|
|
|
|
|
|
async = uhci_async_find_td(s, td_addr);
|
2012-10-24 18:31:16 +02:00
|
|
|
if (async) {
|
|
|
|
if (uhci_queue_verify(async->queue, qh_addr, td, td_addr, queuing)) {
|
|
|
|
assert(q == NULL || q == async->queue);
|
|
|
|
q = async->queue;
|
|
|
|
} else {
|
|
|
|
uhci_queue_free(async->queue, "guest re-used pending td");
|
|
|
|
async = NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-10-24 18:31:15 +02:00
|
|
|
if (q == NULL) {
|
|
|
|
q = uhci_queue_find(s, td);
|
|
|
|
if (q && !uhci_queue_verify(q, qh_addr, td, td_addr, queuing)) {
|
|
|
|
uhci_queue_free(q, "guest re-used qh");
|
|
|
|
q = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:18 +02:00
|
|
|
if (q) {
|
2012-12-14 14:35:35 +01:00
|
|
|
q->valid = QH_VALID;
|
2012-10-24 18:31:18 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
/* Is active ? */
|
2012-10-10 15:50:36 +02:00
|
|
|
if (!(td->ctrl & TD_CTRL_ACTIVE)) {
|
2012-10-24 18:31:17 +02:00
|
|
|
if (async) {
|
|
|
|
/* Guest marked a pending td non-active, cancel the queue */
|
|
|
|
uhci_queue_free(async->queue, "pending td non-active");
|
|
|
|
}
|
2012-10-10 15:50:36 +02:00
|
|
|
/*
|
|
|
|
* ehci11d spec page 22: "Even if the Active bit in the TD is already
|
|
|
|
* cleared when the TD is fetched ... an IOC interrupt is generated"
|
|
|
|
*/
|
|
|
|
if (td->ctrl & TD_CTRL_IOC) {
|
|
|
|
*int_mask |= 0x01;
|
|
|
|
}
|
2012-03-09 11:09:49 +01:00
|
|
|
return TD_RESULT_NEXT_QH;
|
2012-10-10 15:50:36 +02:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2016-04-22 12:44:53 +02:00
|
|
|
switch (pid) {
|
|
|
|
case USB_TOKEN_OUT:
|
|
|
|
case USB_TOKEN_SETUP:
|
|
|
|
case USB_TOKEN_IN:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* invalid pid : frame interrupted */
|
|
|
|
s->status |= UHCI_STS_HCPERR;
|
|
|
|
s->cmd &= ~UHCI_CMD_RS;
|
|
|
|
uhci_update_irq(s);
|
|
|
|
return TD_RESULT_STOP_FRAME;
|
|
|
|
}
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
if (async) {
|
2012-03-29 16:02:20 +02:00
|
|
|
if (queuing) {
|
|
|
|
/* we are busy filling the queue, we are not prepared
|
|
|
|
to consume completed packages then, just leave them
|
|
|
|
in async state */
|
|
|
|
return TD_RESULT_ASYNC_CONT;
|
|
|
|
}
|
2012-10-24 18:31:19 +02:00
|
|
|
if (!async->done) {
|
|
|
|
UHCI_TD last_td;
|
2018-12-06 13:10:34 +01:00
|
|
|
UHCIAsync *last = QTAILQ_LAST(&async->queue->asyncs);
|
2012-10-24 18:31:19 +02:00
|
|
|
/*
|
|
|
|
* While we are waiting for the current td to complete, the guest
|
|
|
|
* may have added more tds to the queue. Note we re-read the td
|
|
|
|
* rather then caching it, as we want to see guest made changes!
|
|
|
|
*/
|
|
|
|
uhci_read_td(s, &last_td, last->td_addr);
|
|
|
|
uhci_queue_fill(async->queue, &last_td);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-10-24 18:31:19 +02:00
|
|
|
return TD_RESULT_ASYNC_CONT;
|
|
|
|
}
|
2012-01-27 14:17:06 +01:00
|
|
|
uhci_async_unlink(async);
|
2008-08-21 21:30:31 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-11-17 12:11:49 +01:00
|
|
|
if (s->completions_only) {
|
|
|
|
return TD_RESULT_ASYNC_CONT;
|
|
|
|
}
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
/* Allocate new packet */
|
2012-10-24 18:31:12 +02:00
|
|
|
if (q == NULL) {
|
2019-02-06 14:36:53 +01:00
|
|
|
USBDevice *dev;
|
|
|
|
USBEndpoint *ep;
|
2012-10-31 12:54:37 +01:00
|
|
|
|
2019-02-06 14:36:53 +01:00
|
|
|
dev = uhci_find_device(s, (td->token >> 8) & 0x7f);
|
|
|
|
if (dev == NULL) {
|
2012-10-31 12:54:37 +01:00
|
|
|
return uhci_handle_td_error(s, td, td_addr, USB_RET_NODEV,
|
|
|
|
int_mask);
|
|
|
|
}
|
2019-02-06 14:36:53 +01:00
|
|
|
ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf);
|
2012-10-24 18:31:15 +02:00
|
|
|
q = uhci_queue_new(s, qh_addr, td, ep);
|
2012-10-24 18:31:12 +02:00
|
|
|
}
|
|
|
|
async = uhci_async_alloc(q, td_addr);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
max_len = ((td->token >> 21) + 1) & 0x7ff;
|
2012-10-24 18:14:09 +02:00
|
|
|
spd = (pid == USB_TOKEN_IN && (td->ctrl & TD_CTRL_SPD) != 0);
|
2013-01-29 12:44:35 +01:00
|
|
|
usb_packet_setup(&async->packet, pid, q->ep, 0, td_addr, spd,
|
2012-10-24 18:14:10 +02:00
|
|
|
(td->ctrl & TD_CTRL_IOC) != 0);
|
2013-05-06 10:48:57 +02:00
|
|
|
if (max_len <= sizeof(async->static_buf)) {
|
|
|
|
async->buf = async->static_buf;
|
|
|
|
} else {
|
|
|
|
async->buf = g_malloc(max_len);
|
|
|
|
}
|
|
|
|
usb_packet_addbuf(&async->packet, async->buf, max_len);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
switch(pid) {
|
|
|
|
case USB_TOKEN_OUT:
|
|
|
|
case USB_TOKEN_SETUP:
|
2013-05-06 10:48:57 +02:00
|
|
|
pci_dma_read(&s->dev, td->buffer, async->buf, max_len);
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
usb_handle_packet(q->ep->dev, &async->packet);
|
|
|
|
if (async->packet.status == USB_RET_SUCCESS) {
|
|
|
|
async->packet.actual_length = max_len;
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_TOKEN_IN:
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
usb_handle_packet(q->ep->dev, &async->packet);
|
2008-08-21 21:30:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-02-19 08:33:58 +01:00
|
|
|
abort(); /* Never to execute */
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
|
|
|
|
if (async->packet.status == USB_RET_ASYNC) {
|
2012-01-27 14:17:06 +01:00
|
|
|
uhci_async_link(async);
|
2012-10-24 18:31:12 +02:00
|
|
|
if (!queuing) {
|
2012-10-24 18:31:13 +02:00
|
|
|
uhci_queue_fill(q, td);
|
2012-10-24 18:31:12 +02:00
|
|
|
}
|
2012-03-09 11:15:41 +01:00
|
|
|
return TD_RESULT_ASYNC_START;
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
ret = uhci_complete_td(s, td, async, int_mask);
|
2012-01-27 14:17:06 +01:00
|
|
|
uhci_async_free(async);
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
return ret;
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
2011-06-21 11:52:28 +02:00
|
|
|
static void uhci_async_complete(USBPort *port, USBPacket *packet)
|
2006-08-12 03:04:27 +02:00
|
|
|
{
|
2010-12-15 10:26:15 +01:00
|
|
|
UHCIAsync *async = container_of(packet, UHCIAsync, packet);
|
2012-01-27 14:17:06 +01:00
|
|
|
UHCIState *s = async->queue->uhci;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be larger
then maxpacketsize, it is possible for the result of a single packet
to be both having transferred some data as well as the transfer to have
an error.
An example would be an input transfer from a bulk endpoint successfully
receiving 1 or more maxpacketsize packets from the device, followed
by a packet signalling halt.
While already touching all the devices and controllers handle_packet /
handle_data / handle_control code, also change the return type of
these functions to void, solely storing the status in the packet. To
make the code paths for regular versus async packet handling more
uniform.
This patch unfortunately is somewhat invasive, since makeing the qemu
usb core deal with this requires changes everywhere. This patch only
prepares the usb core for this, all the hcd / device changes are done
in such a way that there are no functional changes.
This patch has been tested with uhci and ehci hcds, together with usb-audio,
usb-hid and usb-storage devices, as well as with usb-redir redirection
with a wide variety of real devices.
Note that there is usually no need to directly set packet->actual_length
form devices handle_data callback, as that is done by usb_packet_copy()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-11-01 17:15:01 +01:00
|
|
|
if (packet->status == USB_RET_REMOVE_FROM_QUEUE) {
|
2012-10-24 18:14:08 +02:00
|
|
|
uhci_async_cancel(async);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:05 +02:00
|
|
|
async->done = 1;
|
2012-11-17 12:11:49 +01:00
|
|
|
/* Force processing of this packet *now*, needed for migration */
|
|
|
|
s->completions_only = true;
|
|
|
|
qemu_bh_schedule(s->bh);
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int is_valid(uint32_t link)
|
|
|
|
{
|
|
|
|
return (link & 1) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_qh(uint32_t link)
|
|
|
|
{
|
|
|
|
return (link & 2) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depth_first(uint32_t link)
|
|
|
|
{
|
|
|
|
return (link & 4) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* QH DB used for detecting QH loops */
|
|
|
|
#define UHCI_MAX_QUEUES 128
|
|
|
|
typedef struct {
|
|
|
|
uint32_t addr[UHCI_MAX_QUEUES];
|
|
|
|
int count;
|
|
|
|
} QhDb;
|
|
|
|
|
|
|
|
static void qhdb_reset(QhDb *db)
|
|
|
|
{
|
|
|
|
db->count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add QH to DB. Returns 1 if already present or DB is full. */
|
|
|
|
static int qhdb_insert(QhDb *db, uint32_t addr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < db->count; i++)
|
|
|
|
if (db->addr[i] == addr)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (db->count >= UHCI_MAX_QUEUES)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
db->addr[db->count++] = addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-24 18:31:13 +02:00
|
|
|
static void uhci_queue_fill(UHCIQueue *q, UHCI_TD *td)
|
2012-01-27 17:27:31 +01:00
|
|
|
{
|
|
|
|
uint32_t int_mask = 0;
|
|
|
|
uint32_t plink = td->link;
|
|
|
|
UHCI_TD ptd;
|
|
|
|
int ret;
|
|
|
|
|
2012-10-24 18:14:09 +02:00
|
|
|
while (is_valid(plink)) {
|
2012-10-24 18:31:12 +02:00
|
|
|
uhci_read_td(q->uhci, &ptd, plink);
|
2012-01-27 17:27:31 +01:00
|
|
|
if (!(ptd.ctrl & TD_CTRL_ACTIVE)) {
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 18:31:12 +02:00
|
|
|
if (uhci_queue_token(&ptd) != q->token) {
|
2012-01-27 17:27:31 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token);
|
2012-10-24 18:31:15 +02:00
|
|
|
ret = uhci_handle_td(q->uhci, q, q->qh_addr, &ptd, plink, &int_mask);
|
2012-03-21 18:25:25 +01:00
|
|
|
if (ret == TD_RESULT_ASYNC_CONT) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-09 11:15:41 +01:00
|
|
|
assert(ret == TD_RESULT_ASYNC_START);
|
2012-01-27 17:27:31 +01:00
|
|
|
assert(int_mask == 0);
|
|
|
|
plink = ptd.link;
|
|
|
|
}
|
2012-10-24 18:31:13 +02:00
|
|
|
usb_device_flush_ep_queue(q->ep->dev, q->ep);
|
2012-01-27 17:27:31 +01:00
|
|
|
}
|
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
static void uhci_process_frame(UHCIState *s)
|
|
|
|
{
|
|
|
|
uint32_t frame_addr, link, old_td_ctrl, val, int_mask;
|
2012-05-11 09:18:05 +02:00
|
|
|
uint32_t curr_qh, td_count = 0;
|
2008-08-21 21:30:31 +02:00
|
|
|
int cnt, ret;
|
2006-08-12 03:04:27 +02:00
|
|
|
UHCI_TD td;
|
2008-08-21 21:30:31 +02:00
|
|
|
UHCI_QH qh;
|
|
|
|
QhDb qhdb;
|
2006-08-12 03:04:27 +02:00
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2);
|
|
|
|
|
2011-11-04 02:03:38 +01:00
|
|
|
pci_dma_read(&s->dev, frame_addr, &link, 4);
|
2008-08-21 21:30:31 +02:00
|
|
|
le32_to_cpus(&link);
|
2007-10-05 00:47:34 +02:00
|
|
|
|
2008-08-21 21:30:31 +02:00
|
|
|
int_mask = 0;
|
|
|
|
curr_qh = 0;
|
|
|
|
|
|
|
|
qhdb_reset(&qhdb);
|
|
|
|
|
|
|
|
for (cnt = FRAME_MAX_LOOPS; is_valid(link) && cnt; cnt--) {
|
2012-11-17 12:11:49 +01:00
|
|
|
if (!s->completions_only && s->frame_bytes >= s->frame_bandwidth) {
|
2012-05-11 09:18:05 +02:00
|
|
|
/* We've reached the usb 1.1 bandwidth, which is
|
|
|
|
1280 bytes/frame, stop processing */
|
|
|
|
trace_usb_uhci_frame_stop_bandwidth();
|
|
|
|
break;
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
if (is_qh(link)) {
|
|
|
|
/* QH */
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_qh_load(link & ~0xf);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
if (qhdb_insert(&qhdb, link)) {
|
|
|
|
/*
|
|
|
|
* We're going in circles. Which is not a bug because
|
2012-01-26 13:57:40 +01:00
|
|
|
* HCD is allowed to do that as part of the BW management.
|
|
|
|
*
|
2012-05-11 09:18:05 +02:00
|
|
|
* Stop processing here if no transaction has been done
|
|
|
|
* since we've been here last time.
|
2008-08-21 21:30:31 +02:00
|
|
|
*/
|
2012-01-26 13:57:40 +01:00
|
|
|
if (td_count == 0) {
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_frame_loop_stop_idle();
|
2012-01-26 13:57:40 +01:00
|
|
|
break;
|
|
|
|
} else {
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_frame_loop_continue();
|
2012-01-26 13:57:40 +01:00
|
|
|
td_count = 0;
|
|
|
|
qhdb_reset(&qhdb);
|
|
|
|
qhdb_insert(&qhdb, link);
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
2011-11-04 02:03:38 +01:00
|
|
|
pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh));
|
2008-08-21 21:30:31 +02:00
|
|
|
le32_to_cpus(&qh.link);
|
|
|
|
le32_to_cpus(&qh.el_link);
|
|
|
|
|
|
|
|
if (!is_valid(qh.el_link)) {
|
|
|
|
/* QH w/o elements */
|
|
|
|
curr_qh = 0;
|
|
|
|
link = qh.link;
|
|
|
|
} else {
|
|
|
|
/* QH with elements */
|
2018-12-13 23:37:36 +01:00
|
|
|
curr_qh = link;
|
|
|
|
link = qh.el_link;
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TD */
|
2012-10-24 18:31:11 +02:00
|
|
|
uhci_read_td(s, &td, link);
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
old_td_ctrl = td.ctrl;
|
2012-10-24 18:31:15 +02:00
|
|
|
ret = uhci_handle_td(s, NULL, curr_qh, &td, link, &int_mask);
|
2007-10-05 00:47:34 +02:00
|
|
|
if (old_td_ctrl != td.ctrl) {
|
2008-08-21 21:30:31 +02:00
|
|
|
/* update the status bits of the TD */
|
2007-10-05 00:47:34 +02:00
|
|
|
val = cpu_to_le32(td.ctrl);
|
2011-11-04 02:03:38 +01:00
|
|
|
pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val));
|
2007-10-05 00:47:34 +02:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-27 16:38:42 +01:00
|
|
|
switch (ret) {
|
2012-03-09 11:09:49 +01:00
|
|
|
case TD_RESULT_STOP_FRAME: /* interrupted frame */
|
2012-01-27 16:38:42 +01:00
|
|
|
goto out;
|
2007-10-05 00:47:34 +02:00
|
|
|
|
2012-03-09 11:09:49 +01:00
|
|
|
case TD_RESULT_NEXT_QH:
|
2012-03-09 11:15:41 +01:00
|
|
|
case TD_RESULT_ASYNC_CONT:
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf);
|
2008-08-21 21:30:31 +02:00
|
|
|
link = curr_qh ? qh.link : td.link;
|
|
|
|
continue;
|
|
|
|
|
2012-03-09 11:15:41 +01:00
|
|
|
case TD_RESULT_ASYNC_START:
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf);
|
2012-01-27 16:38:42 +01:00
|
|
|
link = curr_qh ? qh.link : td.link;
|
|
|
|
continue;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-03-09 11:09:49 +01:00
|
|
|
case TD_RESULT_COMPLETE:
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf);
|
2012-01-27 16:38:42 +01:00
|
|
|
link = td.link;
|
|
|
|
td_count++;
|
2012-05-11 09:18:05 +02:00
|
|
|
s->frame_bytes += (td.ctrl & 0x7ff) + 1;
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-27 16:38:42 +01:00
|
|
|
if (curr_qh) {
|
|
|
|
/* update QH element link */
|
|
|
|
qh.el_link = link;
|
|
|
|
val = cpu_to_le32(qh.el_link);
|
|
|
|
pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val));
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-27 16:38:42 +01:00
|
|
|
if (!depth_first(link)) {
|
|
|
|
/* done with this QH */
|
|
|
|
curr_qh = 0;
|
|
|
|
link = qh.link;
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
}
|
2012-01-27 16:38:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(!"unknown return code");
|
2006-08-12 03:04:27 +02:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
|
|
|
/* go to the next entry */
|
2006-08-12 03:04:27 +02:00
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-01-27 16:38:42 +01:00
|
|
|
out:
|
2010-02-03 16:49:39 +01:00
|
|
|
s->pending_int_mask |= int_mask;
|
2006-08-12 03:04:27 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 09:33:07 +02:00
|
|
|
static void uhci_bh(void *opaque)
|
|
|
|
{
|
|
|
|
UHCIState *s = opaque;
|
|
|
|
uhci_process_frame(s);
|
|
|
|
}
|
|
|
|
|
2005-11-05 15:22:28 +01:00
|
|
|
static void uhci_frame_timer(void *opaque)
|
|
|
|
{
|
|
|
|
UHCIState *s = opaque;
|
2012-12-14 14:35:36 +01:00
|
|
|
uint64_t t_now, t_last_run;
|
|
|
|
int i, frames;
|
2016-03-21 17:02:30 +01:00
|
|
|
const uint64_t frame_t = NANOSECONDS_PER_SECOND / FRAME_TIMER_FREQ;
|
2010-02-03 16:49:39 +01:00
|
|
|
|
2012-11-17 12:11:49 +01:00
|
|
|
s->completions_only = false;
|
2012-05-11 09:33:07 +02:00
|
|
|
qemu_bh_cancel(s->bh);
|
2005-11-05 15:22:28 +01:00
|
|
|
|
|
|
|
if (!(s->cmd & UHCI_CMD_RS)) {
|
2008-08-21 21:30:31 +02:00
|
|
|
/* Full stop */
|
2012-03-08 13:12:38 +01:00
|
|
|
trace_usb_uhci_schedule_stop();
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_del(s->frame_timer);
|
2012-03-08 13:37:52 +01:00
|
|
|
uhci_async_cancel_all(s);
|
2006-04-24 23:38:50 +02:00
|
|
|
/* set hchalted bit in status - UHCI11D 2.1.2 */
|
|
|
|
s->status |= UHCI_STS_HCHALTED;
|
2005-11-05 15:22:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-12-14 14:35:36 +01:00
|
|
|
/* We still store expire_time in our state, for migration */
|
|
|
|
t_last_run = s->expire_time - frame_t;
|
2013-08-21 17:03:08 +02:00
|
|
|
t_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
2008-08-21 21:30:31 +02:00
|
|
|
|
2012-12-14 14:35:36 +01:00
|
|
|
/* Process up to MAX_FRAMES_PER_TICK frames */
|
|
|
|
frames = (t_now - t_last_run) / frame_t;
|
2012-12-14 14:35:37 +01:00
|
|
|
if (frames > s->maxframes) {
|
|
|
|
int skipped = frames - s->maxframes;
|
|
|
|
s->expire_time += skipped * frame_t;
|
|
|
|
s->frnum = (s->frnum + skipped) & 0x7ff;
|
|
|
|
frames -= skipped;
|
|
|
|
}
|
2012-12-14 14:35:36 +01:00
|
|
|
if (frames > MAX_FRAMES_PER_TICK) {
|
|
|
|
frames = MAX_FRAMES_PER_TICK;
|
|
|
|
}
|
2007-10-05 00:47:34 +02:00
|
|
|
|
2012-12-14 14:35:36 +01:00
|
|
|
for (i = 0; i < frames; i++) {
|
|
|
|
s->frame_bytes = 0;
|
|
|
|
trace_usb_uhci_frame_start(s->frnum);
|
|
|
|
uhci_async_validate_begin(s);
|
|
|
|
uhci_process_frame(s);
|
|
|
|
uhci_async_validate_end(s);
|
|
|
|
/* The spec says frnum is the frame currently being processed, and
|
|
|
|
* the guest must look at frnum - 1 on interrupt, so inc frnum now */
|
|
|
|
s->frnum = (s->frnum + 1) & 0x7ff;
|
|
|
|
s->expire_time += frame_t;
|
|
|
|
}
|
2012-12-14 14:35:33 +01:00
|
|
|
|
2012-12-14 14:35:36 +01:00
|
|
|
/* Complete the previous frame(s) */
|
2012-12-14 14:35:33 +01:00
|
|
|
if (s->pending_int_mask) {
|
|
|
|
s->status2 |= s->pending_int_mask;
|
|
|
|
s->status |= UHCI_STS_USBINT;
|
|
|
|
uhci_update_irq(s);
|
|
|
|
}
|
|
|
|
s->pending_int_mask = 0;
|
|
|
|
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->frame_timer, t_now + frame_t);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
|
|
|
|
2011-08-08 15:09:24 +02:00
|
|
|
static const MemoryRegionOps uhci_ioport_ops = {
|
2013-01-03 12:29:41 +01:00
|
|
|
.read = uhci_port_read,
|
|
|
|
.write = uhci_port_write,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.impl.min_access_size = 2,
|
|
|
|
.impl.max_access_size = 2,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-08 15:09:24 +02:00
|
|
|
};
|
2005-11-05 15:22:28 +01:00
|
|
|
|
2010-12-01 11:08:44 +01:00
|
|
|
static USBPortOps uhci_port_ops = {
|
|
|
|
.attach = uhci_attach,
|
2010-12-01 11:27:05 +01:00
|
|
|
.detach = uhci_detach,
|
2011-06-24 12:31:11 +02:00
|
|
|
.child_detach = uhci_child_detach,
|
2010-12-01 11:47:40 +01:00
|
|
|
.wakeup = uhci_wakeup,
|
2010-12-16 17:03:44 +01:00
|
|
|
.complete = uhci_async_complete,
|
2010-12-01 11:08:44 +01:00
|
|
|
};
|
|
|
|
|
2011-05-23 17:37:12 +02:00
|
|
|
static USBBusOps uhci_bus_ops = {
|
|
|
|
};
|
|
|
|
|
2015-02-17 14:28:05 +01:00
|
|
|
static void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
|
2005-11-05 15:22:28 +01:00
|
|
|
{
|
2015-02-17 14:28:02 +01:00
|
|
|
Error *err = NULL;
|
2012-05-25 12:53:47 +02:00
|
|
|
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
|
2012-10-26 14:56:19 +02:00
|
|
|
UHCIPCIDeviceClass *u = container_of(pc, UHCIPCIDeviceClass, parent_class);
|
2015-05-06 14:55:23 +02:00
|
|
|
UHCIState *s = UHCI(dev);
|
2009-08-31 14:24:02 +02:00
|
|
|
uint8_t *pci_conf = s->dev.config;
|
2005-11-05 15:22:28 +01:00
|
|
|
int i;
|
|
|
|
|
2009-12-10 18:25:03 +01:00
|
|
|
pci_conf[PCI_CLASS_PROG] = 0x00;
|
|
|
|
/* TODO: reset value should be 0. */
|
2011-06-02 03:18:47 +02:00
|
|
|
pci_conf[USB_SBRN] = USB_RELEASE_1; // release number
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2013-10-07 09:36:39 +02:00
|
|
|
pci_config_set_interrupt_pin(pci_conf, u->info.irq_pin + 1);
|
2012-05-25 12:53:47 +02:00
|
|
|
|
2011-06-24 17:44:53 +02:00
|
|
|
if (s->masterbus) {
|
|
|
|
USBPort *ports[NB_PORTS];
|
|
|
|
for(i = 0; i < NB_PORTS; i++) {
|
|
|
|
ports[i] = &s->ports[i].port;
|
|
|
|
}
|
2015-02-17 14:28:02 +01:00
|
|
|
usb_register_companion(s->masterbus, ports, NB_PORTS,
|
|
|
|
s->firstport, s, &uhci_port_ops,
|
|
|
|
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
|
|
|
|
&err);
|
|
|
|
if (err) {
|
2015-02-17 14:28:05 +01:00
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2011-06-24 17:44:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-23 20:32:04 +02:00
|
|
|
usb_bus_new(&s->bus, sizeof(s->bus), &uhci_bus_ops, DEVICE(dev));
|
2011-06-24 17:44:53 +02:00
|
|
|
for (i = 0; i < NB_PORTS; i++) {
|
|
|
|
usb_register_port(&s->bus, &s->ports[i].port, s, i, &uhci_port_ops,
|
|
|
|
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
|
|
|
|
}
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2012-05-11 09:33:07 +02:00
|
|
|
s->bh = qemu_bh_new(uhci_bh, s);
|
2013-08-21 17:03:08 +02:00
|
|
|
s->frame_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, uhci_frame_timer, s);
|
2009-10-14 12:21:50 +02:00
|
|
|
s->num_ports_vmstate = NB_PORTS;
|
2012-01-27 14:17:06 +01:00
|
|
|
QTAILQ_INIT(&s->queues);
|
2005-11-05 15:22:28 +01:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->io_bar, OBJECT(s), &uhci_ioport_ops, s,
|
|
|
|
"uhci", 0x20);
|
|
|
|
|
2006-03-11 19:03:38 +01:00
|
|
|
/* Use region 4 for consistency with real hardware. BSD guests seem
|
|
|
|
to rely on this. */
|
2011-08-08 15:09:31 +02:00
|
|
|
pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar);
|
2005-11-05 15:22:28 +01:00
|
|
|
}
|
2007-06-06 18:26:14 +02:00
|
|
|
|
2015-02-17 14:28:05 +01:00
|
|
|
static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
|
2010-06-29 04:50:09 +02:00
|
|
|
{
|
2015-05-06 14:55:23 +02:00
|
|
|
UHCIState *s = UHCI(dev);
|
2010-06-29 04:50:09 +02:00
|
|
|
uint8_t *pci_conf = s->dev.config;
|
|
|
|
|
|
|
|
/* USB misc control 1/2 */
|
|
|
|
pci_set_long(pci_conf + 0x40,0x00001000);
|
|
|
|
/* PM capability */
|
|
|
|
pci_set_long(pci_conf + 0x80,0x00020001);
|
|
|
|
/* USB legacy support */
|
|
|
|
pci_set_long(pci_conf + 0xc0,0x00002000);
|
|
|
|
|
2015-02-17 14:28:05 +01:00
|
|
|
usb_uhci_common_realize(dev, errp);
|
2010-06-29 04:50:09 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 10:31:49 +02:00
|
|
|
static void usb_uhci_exit(PCIDevice *dev)
|
|
|
|
{
|
2015-05-06 14:55:23 +02:00
|
|
|
UHCIState *s = UHCI(dev);
|
2014-06-04 10:31:49 +02:00
|
|
|
|
2014-06-04 10:31:55 +02:00
|
|
|
trace_usb_uhci_exit();
|
|
|
|
|
2014-06-04 10:31:49 +02:00
|
|
|
if (s->frame_timer) {
|
|
|
|
timer_del(s->frame_timer);
|
|
|
|
timer_free(s->frame_timer);
|
|
|
|
s->frame_timer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->bh) {
|
|
|
|
qemu_bh_delete(s->bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
uhci_async_cancel_all(s);
|
|
|
|
|
|
|
|
if (!s->masterbus) {
|
|
|
|
usb_bus_release(&s->bus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-29 14:13:11 +02:00
|
|
|
static Property uhci_properties_companion[] = {
|
2011-07-01 09:48:49 +02:00
|
|
|
DEFINE_PROP_STRING("masterbus", UHCIState, masterbus),
|
|
|
|
DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0),
|
2012-05-11 10:02:53 +02:00
|
|
|
DEFINE_PROP_UINT32("bandwidth", UHCIState, frame_bandwidth, 1280),
|
2012-12-14 14:35:37 +01:00
|
|
|
DEFINE_PROP_UINT32("maxframes", UHCIState, maxframes, 128),
|
2011-07-01 09:48:49 +02:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
2014-08-29 14:13:11 +02:00
|
|
|
static Property uhci_properties_standalone[] = {
|
|
|
|
DEFINE_PROP_UINT32("bandwidth", UHCIState, frame_bandwidth, 1280),
|
|
|
|
DEFINE_PROP_UINT32("maxframes", UHCIState, maxframes, 128),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
2011-07-01 09:48:49 +02:00
|
|
|
|
2012-10-25 16:22:57 +02:00
|
|
|
static void uhci_class_init(ObjectClass *klass, void *data)
|
2011-12-04 19:22:06 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:22:06 +01:00
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
2015-05-06 14:55:23 +02:00
|
|
|
|
|
|
|
k->class_id = PCI_CLASS_SERIAL_USB;
|
|
|
|
dc->vmsd = &vmstate_uhci;
|
|
|
|
dc->reset = uhci_reset;
|
|
|
|
set_bit(DEVICE_CATEGORY_USB, dc->categories);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo uhci_pci_type_info = {
|
|
|
|
.name = TYPE_UHCI,
|
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(UHCIState),
|
|
|
|
.class_size = sizeof(UHCIPCIDeviceClass),
|
|
|
|
.abstract = true,
|
|
|
|
.class_init = uhci_class_init,
|
2017-09-27 21:56:34 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2015-05-06 14:55:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void uhci_data_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-10-26 14:56:19 +02:00
|
|
|
UHCIPCIDeviceClass *u = container_of(k, UHCIPCIDeviceClass, parent_class);
|
2012-10-25 16:22:57 +02:00
|
|
|
UHCIInfo *info = data;
|
|
|
|
|
2015-02-17 14:28:05 +01:00
|
|
|
k->realize = info->realize ? info->realize : usb_uhci_common_realize;
|
2014-06-04 10:31:49 +02:00
|
|
|
k->exit = info->unplug ? usb_uhci_exit : NULL;
|
2012-10-25 16:22:57 +02:00
|
|
|
k->vendor_id = info->vendor_id;
|
|
|
|
k->device_id = info->device_id;
|
|
|
|
k->revision = info->revision;
|
2014-08-29 14:13:11 +02:00
|
|
|
if (!info->unplug) {
|
|
|
|
/* uhci controllers in companion setups can't be hotplugged */
|
|
|
|
dc->hotpluggable = false;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, uhci_properties_companion);
|
2014-08-29 14:13:11 +02:00
|
|
|
} else {
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, uhci_properties_standalone);
|
2014-08-29 14:13:11 +02:00
|
|
|
}
|
2012-10-26 14:56:19 +02:00
|
|
|
u->info = *info;
|
2011-12-04 19:22:06 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 16:22:57 +02:00
|
|
|
static UHCIInfo uhci_info[] = {
|
|
|
|
{
|
|
|
|
.name = "piix3-usb-uhci",
|
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82371SB_2,
|
|
|
|
.revision = 0x01,
|
2012-10-26 14:56:19 +02:00
|
|
|
.irq_pin = 3,
|
2012-10-25 16:22:57 +02:00
|
|
|
.unplug = true,
|
|
|
|
},{
|
|
|
|
.name = "piix4-usb-uhci",
|
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82371AB_2,
|
|
|
|
.revision = 0x01,
|
2012-10-26 14:56:19 +02:00
|
|
|
.irq_pin = 3,
|
2012-10-25 16:22:57 +02:00
|
|
|
.unplug = true,
|
|
|
|
},{
|
|
|
|
.name = "vt82c686b-usb-uhci",
|
|
|
|
.vendor_id = PCI_VENDOR_ID_VIA,
|
|
|
|
.device_id = PCI_DEVICE_ID_VIA_UHCI,
|
|
|
|
.revision = 0x01,
|
2012-10-26 14:56:19 +02:00
|
|
|
.irq_pin = 3,
|
2015-02-17 14:28:05 +01:00
|
|
|
.realize = usb_uhci_vt82c686b_realize,
|
2012-10-25 16:22:57 +02:00
|
|
|
.unplug = true,
|
|
|
|
},{
|
2012-10-30 09:57:28 +01:00
|
|
|
.name = "ich9-usb-uhci1", /* 00:1d.0 */
|
2012-10-25 16:22:57 +02:00
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1,
|
|
|
|
.revision = 0x03,
|
2012-10-26 14:56:19 +02:00
|
|
|
.irq_pin = 0,
|
2012-10-25 16:22:57 +02:00
|
|
|
.unplug = false,
|
|
|
|
},{
|
2012-10-30 09:57:28 +01:00
|
|
|
.name = "ich9-usb-uhci2", /* 00:1d.1 */
|
2012-10-25 16:22:57 +02:00
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2,
|
|
|
|
.revision = 0x03,
|
2012-10-26 14:56:19 +02:00
|
|
|
.irq_pin = 1,
|
2012-10-25 16:22:57 +02:00
|
|
|
.unplug = false,
|
|
|
|
},{
|
2012-10-30 09:57:28 +01:00
|
|
|
.name = "ich9-usb-uhci3", /* 00:1d.2 */
|
2012-10-25 16:22:57 +02:00
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3,
|
|
|
|
.revision = 0x03,
|
2012-10-26 14:56:19 +02:00
|
|
|
.irq_pin = 2,
|
2012-10-25 16:22:57 +02:00
|
|
|
.unplug = false,
|
2012-10-30 09:57:28 +01:00
|
|
|
},{
|
|
|
|
.name = "ich9-usb-uhci4", /* 00:1a.0 */
|
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI4,
|
|
|
|
.revision = 0x03,
|
|
|
|
.irq_pin = 0,
|
|
|
|
.unplug = false,
|
|
|
|
},{
|
|
|
|
.name = "ich9-usb-uhci5", /* 00:1a.1 */
|
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI5,
|
|
|
|
.revision = 0x03,
|
|
|
|
.irq_pin = 1,
|
|
|
|
.unplug = false,
|
|
|
|
},{
|
|
|
|
.name = "ich9-usb-uhci6", /* 00:1a.2 */
|
|
|
|
.vendor_id = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI6,
|
|
|
|
.revision = 0x03,
|
|
|
|
.irq_pin = 2,
|
|
|
|
.unplug = false,
|
2012-10-25 16:22:57 +02:00
|
|
|
}
|
2009-08-31 14:24:02 +02:00
|
|
|
};
|
2007-06-06 18:26:14 +02:00
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void uhci_register_types(void)
|
2009-08-31 14:24:02 +02:00
|
|
|
{
|
2012-10-25 16:22:57 +02:00
|
|
|
TypeInfo uhci_type_info = {
|
2015-05-06 14:55:23 +02:00
|
|
|
.parent = TYPE_UHCI,
|
|
|
|
.class_init = uhci_data_class_init,
|
2012-10-25 16:22:57 +02:00
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
2015-05-06 14:55:23 +02:00
|
|
|
type_register_static(&uhci_pci_type_info);
|
|
|
|
|
2012-10-25 16:22:57 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(uhci_info); i++) {
|
|
|
|
uhci_type_info.name = uhci_info[i].name;
|
|
|
|
uhci_type_info.class_data = uhci_info + i;
|
|
|
|
type_register(&uhci_type_info);
|
|
|
|
}
|
2009-08-31 14:24:02 +02:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(uhci_register_types)
|