xref: /openbmc/qemu/hw/usb/hcd-ohci.h (revision 4713720a)
134d97308SThomas Huth /*
234d97308SThomas Huth  * QEMU USB OHCI Emulation
334d97308SThomas Huth  * Copyright (c) 2004 Gianni Tedesco
434d97308SThomas Huth  * Copyright (c) 2006 CodeSourcery
534d97308SThomas Huth  * Copyright (c) 2006 Openedhand Ltd.
634d97308SThomas Huth  *
734d97308SThomas Huth  * This library is free software; you can redistribute it and/or
834d97308SThomas Huth  * modify it under the terms of the GNU Lesser General Public
934d97308SThomas Huth  * License as published by the Free Software Foundation; either
1034d97308SThomas Huth  * version 2.1 of the License, or (at your option) any later version.
1134d97308SThomas Huth  *
1234d97308SThomas Huth  * This library is distributed in the hope that it will be useful,
1334d97308SThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1434d97308SThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1534d97308SThomas Huth  * Lesser General Public License for more details.
1634d97308SThomas Huth  *
1734d97308SThomas Huth  * You should have received a copy of the GNU Lesser General Public
1834d97308SThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
1934d97308SThomas Huth  */
2034d97308SThomas Huth 
2134d97308SThomas Huth #ifndef HCD_OHCI_H
2234d97308SThomas Huth #define HCD_OHCI_H
2334d97308SThomas Huth 
24d9b934f2SPhilippe Mathieu-Daudé #include "hw/sysbus.h"
2534d97308SThomas Huth #include "sysemu/dma.h"
26fbec359eSGuenter Roeck #include "hw/usb.h"
27db1015e9SEduardo Habkost #include "qom/object.h"
2834d97308SThomas Huth 
2934d97308SThomas Huth /* Number of Downstream Ports on the root hub: */
3034d97308SThomas Huth #define OHCI_MAX_PORTS 15
3134d97308SThomas Huth 
3234d97308SThomas Huth typedef struct OHCIPort {
3334d97308SThomas Huth     USBPort port;
3434d97308SThomas Huth     uint32_t ctrl;
3534d97308SThomas Huth } OHCIPort;
3634d97308SThomas Huth 
37*4713720aSPhilippe Mathieu-Daudé typedef struct OHCIState OHCIState;
38*4713720aSPhilippe Mathieu-Daudé 
39*4713720aSPhilippe Mathieu-Daudé struct OHCIState {
4034d97308SThomas Huth     USBBus bus;
4134d97308SThomas Huth     qemu_irq irq;
4234d97308SThomas Huth     MemoryRegion mem;
4334d97308SThomas Huth     AddressSpace *as;
4434d97308SThomas Huth     uint32_t num_ports;
4534d97308SThomas Huth     const char *name;
4634d97308SThomas Huth 
4734d97308SThomas Huth     QEMUTimer *eof_timer;
4834d97308SThomas Huth     int64_t sof_time;
4934d97308SThomas Huth 
5034d97308SThomas Huth     /* OHCI state */
5134d97308SThomas Huth     /* Control partition */
5234d97308SThomas Huth     uint32_t ctl, status;
5334d97308SThomas Huth     uint32_t intr_status;
5434d97308SThomas Huth     uint32_t intr;
5534d97308SThomas Huth 
5634d97308SThomas Huth     /* memory pointer partition */
5734d97308SThomas Huth     uint32_t hcca;
5834d97308SThomas Huth     uint32_t ctrl_head, ctrl_cur;
5934d97308SThomas Huth     uint32_t bulk_head, bulk_cur;
6034d97308SThomas Huth     uint32_t per_cur;
6134d97308SThomas Huth     uint32_t done;
6234d97308SThomas Huth     int32_t done_count;
6334d97308SThomas Huth 
6434d97308SThomas Huth     /* Frame counter partition */
6534d97308SThomas Huth     uint16_t fsmps;
6634d97308SThomas Huth     uint8_t fit;
6734d97308SThomas Huth     uint16_t fi;
6834d97308SThomas Huth     uint8_t frt;
6934d97308SThomas Huth     uint16_t frame_number;
7034d97308SThomas Huth     uint16_t padding;
7134d97308SThomas Huth     uint32_t pstart;
7234d97308SThomas Huth     uint32_t lst;
7334d97308SThomas Huth 
7434d97308SThomas Huth     /* Root Hub partition */
7534d97308SThomas Huth     uint32_t rhdesc_a, rhdesc_b;
7634d97308SThomas Huth     uint32_t rhstatus;
7734d97308SThomas Huth     OHCIPort rhport[OHCI_MAX_PORTS];
7834d97308SThomas Huth 
7934d97308SThomas Huth     /* PXA27x Non-OHCI events */
8034d97308SThomas Huth     uint32_t hstatus;
8134d97308SThomas Huth     uint32_t hmask;
8234d97308SThomas Huth     uint32_t hreset;
8334d97308SThomas Huth     uint32_t htest;
8434d97308SThomas Huth 
8534d97308SThomas Huth     /* SM501 local memory offset */
8634d97308SThomas Huth     dma_addr_t localmem_base;
8734d97308SThomas Huth 
8834d97308SThomas Huth     /* Active packets.  */
8934d97308SThomas Huth     uint32_t old_ctl;
9034d97308SThomas Huth     USBPacket usb_packet;
9134d97308SThomas Huth     uint8_t usb_buf[8192];
9234d97308SThomas Huth     uint32_t async_td;
9334d97308SThomas Huth     bool async_complete;
9434d97308SThomas Huth 
95*4713720aSPhilippe Mathieu-Daudé     void (*ohci_die)(OHCIState *ohci);
96*4713720aSPhilippe Mathieu-Daudé };
9734d97308SThomas Huth 
98fbec359eSGuenter Roeck #define TYPE_SYSBUS_OHCI "sysbus-ohci"
998063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(OHCISysBusState, SYSBUS_OHCI)
100fbec359eSGuenter Roeck 
101db1015e9SEduardo Habkost struct OHCISysBusState {
102fbec359eSGuenter Roeck     /*< private >*/
103fbec359eSGuenter Roeck     SysBusDevice parent_obj;
104fbec359eSGuenter Roeck     /*< public >*/
105fbec359eSGuenter Roeck 
106fbec359eSGuenter Roeck     OHCIState ohci;
107fbec359eSGuenter Roeck     char *masterbus;
108fbec359eSGuenter Roeck     uint32_t num_ports;
109fbec359eSGuenter Roeck     uint32_t firstport;
110fbec359eSGuenter Roeck     dma_addr_t dma_offset;
111db1015e9SEduardo Habkost };
112fbec359eSGuenter Roeck 
11334d97308SThomas Huth extern const VMStateDescription vmstate_ohci_state;
11434d97308SThomas Huth 
11534d97308SThomas Huth void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports,
11634d97308SThomas Huth                    dma_addr_t localmem_base, char *masterbus,
11734d97308SThomas Huth                    uint32_t firstport, AddressSpace *as,
118*4713720aSPhilippe Mathieu-Daudé                    void (*ohci_die_fn)(OHCIState *), Error **errp);
11934d97308SThomas Huth void ohci_bus_stop(OHCIState *ohci);
12034d97308SThomas Huth void ohci_stop_endpoints(OHCIState *ohci);
12134d97308SThomas Huth void ohci_hard_reset(OHCIState *ohci);
12234d97308SThomas Huth void ohci_sysbus_die(struct OHCIState *ohci);
12334d97308SThomas Huth 
12434d97308SThomas Huth #endif
125