19a4e12a6SPhilippe Mathieu-Daudé /* 29a4e12a6SPhilippe Mathieu-Daudé * USB UHCI controller emulation 39a4e12a6SPhilippe Mathieu-Daudé * 49a4e12a6SPhilippe Mathieu-Daudé * Copyright (c) 2005 Fabrice Bellard 59a4e12a6SPhilippe Mathieu-Daudé * 69a4e12a6SPhilippe Mathieu-Daudé * Copyright (c) 2008 Max Krasnyansky 79a4e12a6SPhilippe Mathieu-Daudé * Magor rewrite of the UHCI data structures parser and frame processor 89a4e12a6SPhilippe Mathieu-Daudé * Support for fully async operation and multiple outstanding transactions 99a4e12a6SPhilippe Mathieu-Daudé * 109a4e12a6SPhilippe Mathieu-Daudé * Permission is hereby granted, free of charge, to any person obtaining a copy 119a4e12a6SPhilippe Mathieu-Daudé * of this software and associated documentation files (the "Software"), to deal 129a4e12a6SPhilippe Mathieu-Daudé * in the Software without restriction, including without limitation the rights 139a4e12a6SPhilippe Mathieu-Daudé * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 149a4e12a6SPhilippe Mathieu-Daudé * copies of the Software, and to permit persons to whom the Software is 159a4e12a6SPhilippe Mathieu-Daudé * furnished to do so, subject to the following conditions: 169a4e12a6SPhilippe Mathieu-Daudé * 179a4e12a6SPhilippe Mathieu-Daudé * The above copyright notice and this permission notice shall be included in 189a4e12a6SPhilippe Mathieu-Daudé * all copies or substantial portions of the Software. 199a4e12a6SPhilippe Mathieu-Daudé * 209a4e12a6SPhilippe Mathieu-Daudé * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 219a4e12a6SPhilippe Mathieu-Daudé * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 229a4e12a6SPhilippe Mathieu-Daudé * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 239a4e12a6SPhilippe Mathieu-Daudé * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 249a4e12a6SPhilippe Mathieu-Daudé * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 259a4e12a6SPhilippe Mathieu-Daudé * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 269a4e12a6SPhilippe Mathieu-Daudé * THE SOFTWARE. 279a4e12a6SPhilippe Mathieu-Daudé */ 289a4e12a6SPhilippe Mathieu-Daudé #ifndef HW_USB_HCD_UHCI_H 299a4e12a6SPhilippe Mathieu-Daudé #define HW_USB_HCD_UHCI_H 309a4e12a6SPhilippe Mathieu-Daudé 319a4e12a6SPhilippe Mathieu-Daudé #include "exec/memory.h" 329a4e12a6SPhilippe Mathieu-Daudé #include "qemu/timer.h" 33edf5ca5dSMarkus Armbruster #include "hw/pci/pci_device.h" 349a4e12a6SPhilippe Mathieu-Daudé #include "hw/usb.h" 35*27af7e00SGuenter Roeck #include "hw/sysbus.h" 369a4e12a6SPhilippe Mathieu-Daudé 379a4e12a6SPhilippe Mathieu-Daudé typedef struct UHCIQueue UHCIQueue; 389a4e12a6SPhilippe Mathieu-Daudé 39fe693e32SPhilippe Mathieu-Daudé #define UHCI_PORTS 2 409a4e12a6SPhilippe Mathieu-Daudé 419a4e12a6SPhilippe Mathieu-Daudé typedef struct UHCIPort { 429a4e12a6SPhilippe Mathieu-Daudé USBPort port; 439a4e12a6SPhilippe Mathieu-Daudé uint16_t ctrl; 449a4e12a6SPhilippe Mathieu-Daudé } UHCIPort; 459a4e12a6SPhilippe Mathieu-Daudé 46*27af7e00SGuenter Roeck typedef struct UHCIState UHCIState; 47*27af7e00SGuenter Roeck 48*27af7e00SGuenter Roeck struct UHCIState { 49*27af7e00SGuenter Roeck MemoryRegion mem; 50*27af7e00SGuenter Roeck AddressSpace *as; 51*27af7e00SGuenter Roeck void (*uhci_reset)(UHCIState *); 529a4e12a6SPhilippe Mathieu-Daudé USBBus bus; /* Note unused when we're a companion controller */ 539a4e12a6SPhilippe Mathieu-Daudé uint16_t cmd; /* cmd register */ 549a4e12a6SPhilippe Mathieu-Daudé uint16_t status; 559a4e12a6SPhilippe Mathieu-Daudé uint16_t intr; /* interrupt enable register */ 569a4e12a6SPhilippe Mathieu-Daudé uint16_t frnum; /* frame number */ 579a4e12a6SPhilippe Mathieu-Daudé uint32_t fl_base_addr; /* frame list base address */ 589a4e12a6SPhilippe Mathieu-Daudé uint8_t sof_timing; 599a4e12a6SPhilippe Mathieu-Daudé uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */ 609a4e12a6SPhilippe Mathieu-Daudé int64_t expire_time; 619a4e12a6SPhilippe Mathieu-Daudé QEMUTimer *frame_timer; 629a4e12a6SPhilippe Mathieu-Daudé QEMUBH *bh; 639a4e12a6SPhilippe Mathieu-Daudé uint32_t frame_bytes; 649a4e12a6SPhilippe Mathieu-Daudé uint32_t frame_bandwidth; 659a4e12a6SPhilippe Mathieu-Daudé bool completions_only; 66fe693e32SPhilippe Mathieu-Daudé UHCIPort ports[UHCI_PORTS]; 67e4f5b939SBALATON Zoltan qemu_irq irq; 689a4e12a6SPhilippe Mathieu-Daudé /* Interrupts that should be raised at the end of the current frame. */ 699a4e12a6SPhilippe Mathieu-Daudé uint32_t pending_int_mask; 709a4e12a6SPhilippe Mathieu-Daudé 719a4e12a6SPhilippe Mathieu-Daudé /* Active packets */ 729a4e12a6SPhilippe Mathieu-Daudé QTAILQ_HEAD(, UHCIQueue) queues; 739a4e12a6SPhilippe Mathieu-Daudé uint8_t num_ports_vmstate; 749a4e12a6SPhilippe Mathieu-Daudé 759a4e12a6SPhilippe Mathieu-Daudé /* Properties */ 769a4e12a6SPhilippe Mathieu-Daudé char *masterbus; 779a4e12a6SPhilippe Mathieu-Daudé uint32_t firstport; 789a4e12a6SPhilippe Mathieu-Daudé uint32_t maxframes; 79*27af7e00SGuenter Roeck }; 809a4e12a6SPhilippe Mathieu-Daudé 81*27af7e00SGuenter Roeck #define TYPE_UHCI "uhci-usb" 82*27af7e00SGuenter Roeck OBJECT_DECLARE_TYPE(UHCIState, UHCIDeviceClass, UHCI) 839a4e12a6SPhilippe Mathieu-Daudé 84*27af7e00SGuenter Roeck extern const VMStateDescription vmstate_uhci_state; 859a4e12a6SPhilippe Mathieu-Daudé 869a4e12a6SPhilippe Mathieu-Daudé void uhci_data_class_init(ObjectClass *klass, void *data); 879a4e12a6SPhilippe Mathieu-Daudé void usb_uhci_common_realize(PCIDevice *dev, Error **errp); 88*27af7e00SGuenter Roeck void usb_uhci_init(UHCIState *s, DeviceState *dev, Error **errp); 89*27af7e00SGuenter Roeck void uhci_state_reset(UHCIState *s); 90*27af7e00SGuenter Roeck void usb_uhci_exit(UHCIState *s); 919a4e12a6SPhilippe Mathieu-Daudé 92f0712099SBernhard Beschow #define TYPE_PIIX3_USB_UHCI "piix3-usb-uhci" 93f0712099SBernhard Beschow #define TYPE_PIIX4_USB_UHCI "piix4-usb-uhci" 94f0712099SBernhard Beschow #define TYPE_ICH9_USB_UHCI(fn) "ich9-usb-uhci" #fn 95f0712099SBernhard Beschow 969a4e12a6SPhilippe Mathieu-Daudé #endif 97