2003-01-28 19:58:10 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-04-06 13:30:26 +04:00
|
|
|
// $Id: usb_uhci.h,v 1.12 2009-04-06 09:30:26 vruppert Exp $
|
2003-01-28 19:58:10 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-01-18 16:11:27 +03:00
|
|
|
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
|
2003-01-28 19:58:10 +03:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-01-28 19:58:10 +03:00
|
|
|
|
2009-01-19 12:48:12 +03:00
|
|
|
#ifndef BX_IODEV_USB_UHCI_H
|
|
|
|
#define BX_IODEV_USB_UHCI_H
|
2006-03-07 21:16:41 +03:00
|
|
|
|
2009-01-19 12:48:12 +03:00
|
|
|
#if BX_USE_USB_UHCI_SMF
|
|
|
|
# define BX_UHCI_THIS theUSB_UHCI->
|
|
|
|
# define BX_UHCI_THIS_PTR theUSB_UHCI
|
2003-01-28 19:58:10 +03:00
|
|
|
#else
|
2009-01-19 12:48:12 +03:00
|
|
|
# define BX_UHCI_THIS this->
|
|
|
|
# define BX_UHCI_THIS_PTR this
|
2003-01-28 19:58:10 +03:00
|
|
|
#endif
|
|
|
|
|
2009-03-15 15:54:59 +03:00
|
|
|
// defined in bochs.h: UHCI supports 2 ports per root hub
|
2003-01-28 19:58:10 +03:00
|
|
|
|
2004-12-11 11:35:33 +03:00
|
|
|
typedef struct {
|
2004-07-12 00:38:48 +04:00
|
|
|
Bit32u base_ioaddr;
|
2003-01-28 19:58:10 +03:00
|
|
|
int timer_index;
|
|
|
|
|
|
|
|
// Registers
|
|
|
|
// Base + 0x00 Command register
|
|
|
|
// Base + 0x02 Status register
|
|
|
|
// Base + 0x04 Interrupt Enable register
|
|
|
|
// Base + 0x06 Frame Number register
|
|
|
|
// Base + 0x08 Frame Base Register (32-bit)
|
|
|
|
// Base + 0x0C Start of Frame Modify register
|
|
|
|
// Base + 0x0D
|
|
|
|
// Base + 0x0E
|
|
|
|
// Base + 0x0F
|
|
|
|
// Base + 0x10 Eight(?) 16-bit ports (one for each port on hub)
|
|
|
|
|
|
|
|
// Bit reps of registers above
|
|
|
|
// Command Register
|
|
|
|
// Bits 15-8 are reserved
|
|
|
|
// Bit 7 = Maximum packet size
|
|
|
|
// Bit 6 = Host Controller has been configured (set by software)
|
|
|
|
// Bit 5 = software debug mode
|
|
|
|
// Bit 4 = force global resume
|
|
|
|
// Bit 3 = enter global suspend mode
|
|
|
|
// Bit 2 = global reset
|
|
|
|
// Bit 1 = host controller reset
|
|
|
|
// Bit 0 = run/stop schedule
|
|
|
|
struct {
|
|
|
|
bx_bool max_packet_size; //(bit 7) 0 = 32 bytes, 1 = 64 bytes
|
|
|
|
bx_bool configured; //(bit 6)
|
|
|
|
bx_bool debug; //(bit 5)
|
|
|
|
bx_bool resume; //(bit 4)
|
|
|
|
bx_bool suspend; //(bit 3)
|
|
|
|
bx_bool reset; //(bit 2)
|
|
|
|
bx_bool host_reset; //(bit 1)
|
|
|
|
bx_bool schedule; //(bit 0) 0 = Stop, 1 = Run
|
|
|
|
} usb_command;
|
|
|
|
|
|
|
|
// Status Register
|
|
|
|
// Bits 15-6 are reserved
|
|
|
|
// Bit 5 = Host controller halted
|
|
|
|
// Bit 4 = Host controller process error
|
|
|
|
// Bit 3 = PCI Bus error
|
|
|
|
// Bit 2 = resume received
|
|
|
|
// Bit 1 = USB error interrupt
|
|
|
|
// Bit 0 = USB interrupt
|
|
|
|
struct {
|
|
|
|
bx_bool host_halted; //(bit 5)
|
|
|
|
bx_bool host_error; //(bit 4)
|
|
|
|
bx_bool pci_error; //(bit 3)
|
|
|
|
bx_bool resume; //(bit 2)
|
|
|
|
bx_bool error_interrupt; //(bit 1)
|
|
|
|
bx_bool interrupt; //(bit 0)
|
|
|
|
} usb_status;
|
|
|
|
|
|
|
|
// Interrupt Enable Register
|
|
|
|
// Bits 15-4 are reserved
|
|
|
|
// Bit 3 = enable short packet interrupts
|
|
|
|
// Bit 2 = enable interrupt On Complete
|
|
|
|
// Bit 1 = enable resume
|
|
|
|
// Bit 0 = enable timeout/crc
|
|
|
|
struct {
|
|
|
|
bx_bool short_packet; //(bit 3)
|
|
|
|
bx_bool on_complete; //(bit 2)
|
|
|
|
bx_bool resume; //(bit 1)
|
|
|
|
bx_bool timeout_crc; //(bit 0)
|
|
|
|
} usb_enable;
|
|
|
|
|
|
|
|
// Frame Number Register
|
|
|
|
// Bits 15-11 are reserved
|
|
|
|
// Bits 10-0 Frame List Current Index/Frame Number
|
|
|
|
struct {
|
|
|
|
Bit16u frame_num;
|
|
|
|
} usb_frame_num;
|
|
|
|
|
|
|
|
// Frame List Base Address Register
|
|
|
|
// Bits 31-12 Base
|
|
|
|
// Bits 11-0 *must* be zeros when written to
|
|
|
|
struct {
|
|
|
|
Bit32u frame_base;
|
|
|
|
} usb_frame_base;
|
|
|
|
|
|
|
|
// Start of Frame Modify Register
|
|
|
|
// Bit 7 reserved
|
|
|
|
// Bits 6-0 SOF timing value (default 64)
|
|
|
|
// SOF cycle time equals 11936+timing value
|
|
|
|
struct {
|
|
|
|
Bit8u sof_timing;
|
|
|
|
} usb_sof;
|
|
|
|
|
|
|
|
// Port Register (0-1)
|
|
|
|
// Bits 15-13 are reserved
|
|
|
|
// Bit 12 suspend port
|
|
|
|
// Bit 11-10 are reserved
|
|
|
|
// Bit 9 port in reset state
|
|
|
|
// Bit 8 low-speed device is attached (read-only)
|
|
|
|
// Bit 7 reserved
|
|
|
|
// Bit 6 resume detected (read-only)
|
|
|
|
// Bit 5 line-status D+ (read-only)
|
|
|
|
// Bit 4 line-status D- (read-only)
|
|
|
|
// Bit 3 port enabled/disable status has changed
|
|
|
|
// (write 1 to this bit to clear it)
|
|
|
|
// Bit 2 port is enabled
|
|
|
|
// Bit 1 connect status has changed
|
|
|
|
// (write 1 to this bit to clear it)
|
|
|
|
// Bit 0 current connect status (read-only)
|
|
|
|
// Can only write in WORD sizes (Read in byte sizes???)
|
|
|
|
struct {
|
2004-12-19 12:59:40 +03:00
|
|
|
// our data
|
2009-01-19 12:48:12 +03:00
|
|
|
usb_device_c *device; // device connected to this port
|
2004-12-19 12:59:40 +03:00
|
|
|
|
|
|
|
// bit reps of actual port
|
2003-01-28 19:58:10 +03:00
|
|
|
bx_bool suspend;
|
|
|
|
bx_bool reset;
|
|
|
|
bx_bool low_speed;
|
|
|
|
bx_bool resume;
|
|
|
|
bx_bool line_dminus;
|
2004-12-11 11:35:33 +03:00
|
|
|
bx_bool line_dplus;
|
2003-01-28 19:58:10 +03:00
|
|
|
bx_bool able_changed;
|
|
|
|
bx_bool enabled;
|
|
|
|
bx_bool connect_changed;
|
|
|
|
bx_bool status;
|
2009-03-15 15:54:59 +03:00
|
|
|
} usb_port[BX_N_USB_UHCI_PORTS];
|
2003-01-28 19:58:10 +03:00
|
|
|
|
|
|
|
Bit8u pci_conf[256];
|
2004-12-11 11:35:33 +03:00
|
|
|
Bit8u devfunc;
|
|
|
|
|
2009-04-06 13:30:26 +04:00
|
|
|
int statusbar_id; // ID of the status LEDs
|
|
|
|
int iolight_counter;
|
|
|
|
int iolight_timer_index;
|
2009-01-19 12:48:12 +03:00
|
|
|
} bx_usb_uhci_t;
|
2003-01-28 19:58:10 +03:00
|
|
|
|
2004-12-11 11:35:33 +03:00
|
|
|
#pragma pack (push, 1)
|
|
|
|
struct TD {
|
|
|
|
Bit32u dword0;
|
|
|
|
Bit32u dword1;
|
|
|
|
Bit32u dword2;
|
|
|
|
Bit32u dword3;
|
|
|
|
Bit32u resv[4];
|
|
|
|
};
|
|
|
|
#pragma pack (pop)
|
2003-01-28 19:58:10 +03:00
|
|
|
|
2004-12-11 11:35:33 +03:00
|
|
|
#define HC_HORZ 0x80
|
|
|
|
#define HC_VERT 0x81
|
|
|
|
struct HCSTACK {
|
|
|
|
Bit32u next;
|
|
|
|
Bit8u d; // if queue, denotes VERT or HORZ
|
|
|
|
bx_bool q;
|
|
|
|
bx_bool t;
|
|
|
|
};
|
|
|
|
|
2009-03-03 21:29:51 +03:00
|
|
|
class bx_usb_uhci_c : public bx_devmodel_c, public bx_pci_device_stub_c {
|
2003-01-28 19:58:10 +03:00
|
|
|
public:
|
2009-01-19 12:48:12 +03:00
|
|
|
bx_usb_uhci_c();
|
|
|
|
virtual ~bx_usb_uhci_c();
|
2006-03-07 21:16:41 +03:00
|
|
|
virtual void init(void);
|
|
|
|
virtual void reset(unsigned);
|
2006-05-27 19:54:49 +04:00
|
|
|
virtual void register_state(void);
|
|
|
|
virtual void after_restore_state(void);
|
|
|
|
virtual Bit32u pci_read_handler(Bit8u address, unsigned io_len);
|
|
|
|
virtual void pci_write_handler(Bit8u address, Bit32u value, unsigned io_len);
|
2006-03-08 00:11:20 +03:00
|
|
|
|
2009-01-05 00:46:20 +03:00
|
|
|
static const char *usb_param_handler(bx_param_string_c *param, int set,
|
|
|
|
const char *oldval, const char *val, int maxlen);
|
2003-01-28 19:58:10 +03:00
|
|
|
|
|
|
|
private:
|
2009-01-19 12:48:12 +03:00
|
|
|
bx_usb_uhci_t hub;
|
|
|
|
Bit8u global_reset;
|
|
|
|
bx_bool busy;
|
|
|
|
Bit8u *device_buffer;
|
2004-12-11 11:35:33 +03:00
|
|
|
|
2007-03-14 21:05:46 +03:00
|
|
|
USBPacket usb_packet;
|
2005-01-14 21:28:47 +03:00
|
|
|
|
2009-01-19 16:13:32 +03:00
|
|
|
static void set_irq_level(bx_bool level);
|
2009-01-19 12:48:12 +03:00
|
|
|
|
2006-09-24 14:10:21 +04:00
|
|
|
static void init_device(Bit8u port, const char *devname);
|
2009-02-27 01:46:37 +03:00
|
|
|
static void remove_device(Bit8u port);
|
2009-03-05 22:12:23 +03:00
|
|
|
static int broadcast_packet(USBPacket *p);
|
2006-03-07 21:16:41 +03:00
|
|
|
static void usb_set_connect_status(Bit8u port, int type, bx_bool connected);
|
2004-12-16 22:05:01 +03:00
|
|
|
|
2003-01-28 19:58:10 +03:00
|
|
|
static void usb_timer_handler(void *);
|
|
|
|
void usb_timer(void);
|
2005-11-05 15:57:18 +03:00
|
|
|
bx_bool DoTransfer(Bit32u address, Bit32u queue_num, struct TD *);
|
2004-12-11 11:35:33 +03:00
|
|
|
void set_status(struct TD *td, bx_bool stalled, bx_bool data_buffer_error, bx_bool babble,
|
|
|
|
bx_bool nak, bx_bool crc_time_out, bx_bool bitstuff_error, Bit16u act_len);
|
2003-01-28 19:58:10 +03:00
|
|
|
|
|
|
|
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
|
|
|
|
static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
|
2009-01-19 12:48:12 +03:00
|
|
|
#if !BX_USE_USB_UHCI_SMF
|
2003-01-28 19:58:10 +03:00
|
|
|
Bit32u read(Bit32u address, unsigned io_len);
|
|
|
|
void write(Bit32u address, Bit32u value, unsigned io_len);
|
|
|
|
#endif
|
2009-04-06 13:30:26 +04:00
|
|
|
|
|
|
|
static void iolight_timer_handler(void *);
|
|
|
|
void iolight_timer(void);
|
|
|
|
|
2003-01-28 19:58:10 +03:00
|
|
|
};
|
2004-12-16 22:05:01 +03:00
|
|
|
|
2006-03-07 21:16:41 +03:00
|
|
|
#endif
|