* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+
#include "qemu/osdep.h"
#include "qapi/error.h"
-#include "qemu-common.h"
+#include "qemu/timer.h"
#include "trace.h"
+#include "hw/qdev-properties.h"
#include "hw/usb.h"
+#include "migration/vmstate.h"
#include "desc.h"
#include "qemu/error-report.h"
+#include "qemu/module.h"
+#include "qom/object.h"
#define MAX_PORTS 8
uint16_t wPortChange;
} USBHubPort;
-typedef struct USBHubState {
+struct USBHubState {
USBDevice dev;
USBEndpoint *intr;
uint32_t num_ports;
+ bool port_power;
+ QEMUTimer *port_timer;
USBHubPort ports[MAX_PORTS];
-} USBHubState;
+};
+typedef struct USBHubState USBHubState;
#define TYPE_USB_HUB "usb-hub"
#define USB_HUB(obj) OBJECT_CHECK(USBHubState, (obj), TYPE_USB_HUB)
return notify;
}
+static void usb_hub_port_update_timer(void *opaque)
+{
+ USBHubState *s = opaque;
+ bool notify = false;
+ int i;
+
+ for (i = 0; i < s->num_ports; i++) {
+ notify |= usb_hub_port_update(&s->ports[i]);
+ }
+ if (notify) {
+ usb_wakeup(s->intr, 0);
+ }
+}
+
static void usb_hub_attach(USBPort *port1)
{
USBHubState *s = port1->opaque;
usb_wakeup(s->intr, 0);
break;
case PORT_POWER:
+ if (s->port_power) {
+ int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ usb_hub_port_set(port, PORT_STAT_POWER);
+ timer_mod(s->port_timer, now + 5000000); /* 5 ms */
+ }
break;
default:
goto fail;
case PORT_C_RESET:
port->wPortChange &= ~PORT_STAT_C_RESET;
break;
+ case PORT_POWER:
+ if (s->port_power) {
+ usb_hub_port_clear(port, PORT_STAT_POWER);
+ usb_hub_port_clear(port, PORT_STAT_CONNECTION);
+ usb_hub_port_clear(port, PORT_STAT_ENABLE);
+ usb_hub_port_clear(port, PORT_STAT_SUSPEND);
+ port->wPortChange = 0;
+ }
default:
goto fail;
}
sizeof(qemu_hub_hub_descriptor));
data[2] = s->num_ports;
+ if (s->port_power) {
+ data[3] &= ~0x03;
+ data[3] |= 0x01;
+ }
+
/* fill DeviceRemovable bits */
limit = DIV_ROUND_UP(s->num_ports + 1, 8) + 7;
for (n = 7; n < limit; n++) {
}
}
-static void usb_hub_unrealize(USBDevice *dev, Error **errp)
+static void usb_hub_unrealize(USBDevice *dev)
{
USBHubState *s = (USBHubState *)dev;
int i;
usb_unregister_port(usb_bus_from_device(dev),
&s->ports[i].port);
}
+
+ timer_del(s->port_timer);
+ timer_free(s->port_timer);
}
static USBPortOps usb_hub_port_ops = {
usb_desc_create_serial(dev);
usb_desc_init(dev);
+ s->port_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
+ usb_hub_port_update_timer, s);
s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
for (i = 0; i < s->num_ports; i++) {
port = &s->ports[i];
}
};
+static bool usb_hub_port_timer_needed(void *opaque)
+{
+ USBHubState *s = opaque;
+
+ return s->port_power;
+}
+
+static const VMStateDescription vmstate_usb_hub_port_timer = {
+ .name = "usb-hub/port-timer",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .needed = usb_hub_port_timer_needed,
+ .fields = (VMStateField[]) {
+ VMSTATE_TIMER_PTR(port_timer, USBHubState),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
static const VMStateDescription vmstate_usb_hub = {
.name = "usb-hub",
.version_id = 1,
VMSTATE_STRUCT_ARRAY(ports, USBHubState, MAX_PORTS, 0,
vmstate_usb_hub_port, USBHubPort),
VMSTATE_END_OF_LIST()
+ },
+ .subsections = (const VMStateDescription * []) {
+ &vmstate_usb_hub_port_timer,
+ NULL
}
};
static Property usb_hub_properties[] = {
DEFINE_PROP_UINT32("ports", USBHubState, num_ports, 8),
+ DEFINE_PROP_BOOL("port-power", USBHubState, port_power, false),
DEFINE_PROP_END_OF_LIST(),
};
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
dc->fw_name = "hub";
dc->vmsd = &vmstate_usb_hub;
- dc->props = usb_hub_properties;
+ device_class_set_props(dc, usb_hub_properties);
}
static const TypeInfo hub_info = {