Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/drivers/usb/uhci.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef _UHCI_H_
0019 #define _UHCI_H_
0020 
0021 #include <types.h>
0022 #include <arch/i386.h>
0023 #include <drivers/pci/pci.h>
0024 #include <drivers/usb/usb.h>
0025 
0026 #define NUM_FRM_PTRS 1024
0027 
0028 #define UHCI_PID_OUT             0xE1
0029 #define UHCI_PID_IN              0x69
0030 #define UHCI_PID_SETUP           0x2D
0031 
0032 #define UHCI_MAX_LEN      0x4FF
0033 
0034 #define GET_USB_BASE(bus, dev, func)    pci_config_rd16(bus, dev, func, 0x20) & 0xFFE0
0035 #define GET_USB_RELNUM(bus, dev, func)    pci_config_rd8(bus, dev, func, 0x60)
0036 #define DISABLE_LEGACY(bus, dev, func)    pci_config_wr16(bus, dev, func, 0xC0, 0x8f00)
0037 #define SET_LEGACY(bus, dev, func, leg)    pci_config_wr16(bus, dev, func, 0xC0, leg);
0038 #define GET_LEGACY(bus, dev, func)    pci_config_rd16(bus, dev, func, 0xC0)
0039 #define GET_PCICMD(bus, dev, func)    pci_config_rd16(bus, dev, func, 0x04)
0040 #define SET_PCICMD(bus, dev, func, cmd)    pci_config_wr16(bus, dev, func, 0x04, cmd)
0041 #define GET_PCISTS(bus, dev, func)    pci_config_rd16(bus, dev, func, 0x06)
0042 
0043 #define GET_USBCMD(usb_base)    inw(usb_base + 0x00)
0044 #define SET_USBCMD(usb_base, cmd)    outw(cmd, usb_base + 0x00)
0045 #define GET_USBSTS(usb_base)    inw(usb_base + 0x02)
0046 #define SET_USBSTS(usb_base, sts)    outw(sts, usb_base + 0x02)
0047 #define SET_FRBASEADD(usb_base, frbase)    outl(frbase, usb_base + 0x08)
0048 #define GET_FRBASEADD(usb_base)    inl(usb_base + 0x08)
0049 #define SET_SOFMOD(usb_base, sofmod)    outb(sofmod, usb_base + 0x0C)
0050 #define SET_FRNUM(usb_base, frnum)    outw(frnum, usb_base + 0x06)
0051 #define GET_FRNUM(usb_base)    inw(usb_base + 0x06)
0052 #define SET_PORTSC0(usb_base, sc)    outw(sc, usb_base + 0x10)
0053 #define SET_PORTSC1(usb_base, sc)    outw(sc, usb_base + 0x12)
0054 #define GET_PORTSC0(usb_base)    inw(usb_base + 0x10)
0055 #define GET_PORTSC1(usb_base)    inw(usb_base + 0x12)
0056 #define SET_USBINTR(usb_base, intr)    outw(intr, usb_base + 0x04)
0057 #define GET_USBINTR(usb_base)    inw(usb_base + 0x04)
0058 
0059 #define TD_POOL_SIZE 200
0060 #define QH_POOL_SIZE 16
0061 #define TYPE_TD 0
0062 #define TYPE_QH 1
0063 #define DIR_IN  0
0064 #define DIR_OUT 1
0065 
0066 /*
0067  * frm_lst_ptr : UHCI Frame List Pointer
0068  *
0069  * Reference :
0070  *     Universal Host Controller Interface (UHCI) Design Guide
0071  *     Revision 1.1, page 20, Intel
0072  */
0073 typedef uint32_t frm_lst_ptr;
0074 
0075 /*
0076  * UHCI_TD : UHCI Transfer Descriptor
0077  *
0078  * Fields  :
0079  *     link_ptr        TD Link Pointer
0080  *     ctl_status      TD Control and Status
0081  *     token           TD Token
0082  *     buf_ptr         TD Buffer Pointer
0083  *
0084  * Reference :
0085  *     Universal Host Controller Interface (UHCI) Design Guide
0086  *     Revision 1.1, Page 21, Intel
0087  */
0088 typedef struct
0089 {
0090   uint32_t link_ptr;
0091 
0092   union {
0093     uint32_t raw2;
0094     struct {
0095       uint32_t act_len:11;
0096       uint32_t reserve0:5;
0097       uint32_t status:8;
0098       uint32_t ioc:1;
0099       uint32_t iso:1;
0100       uint32_t ls:1;
0101       uint32_t c_err:2;
0102       uint32_t spd:1;
0103       uint32_t reserve1:2;
0104     };
0105   };
0106 
0107   union {
0108     uint32_t raw3;
0109     struct {
0110       uint32_t pid:8;
0111       uint32_t addr:7;
0112       uint32_t endp:4;
0113       uint32_t toggle:1;
0114       uint32_t reserve2:1;
0115       uint32_t max_len:11;
0116     };
0117   };
0118 
0119   uint32_t buf_ptr;
0120 
0121   /* Use reserved word for buf_ptr virt addr */
0122   addr_t buf_vptr;
0123   /* Call back funtion pointer of this TD */
0124   void (*call_back)(addr_t);
0125 
0126   /* --??-- This is problem for 64-bit */
0127   /* Reserved for software */
0128   uint32_t reserve[2];
0129 } UHCI_TD;
0130 
0131 /*
0132  * UHCI_QH : UHCI Queue Head
0133  *
0134  * Fields  :
0135  *     qh_ptr        Queue Head Link Pointer
0136  *     qe_ptr        Queue Element Link Pointer
0137  *
0138  * Reference :
0139  *     Universal Host Controller Interface (UHCI) Design Guide
0140  *     Revision 1.1, Page 25, Intel
0141  */
0142 typedef struct
0143 {
0144   uint32_t qh_ptr;
0145   uint32_t qe_ptr;
0146   uint32_t padding[2];          // QH must be aligned on 16-byte boundary
0147 } UHCI_QH;
0148 
0149 extern bool uhci_init (void);
0150 extern int uhci_reset (void);
0151 extern int port_reset (uint8_t);
0152 extern int uhci_isochronous_transfer (uint8_t, uint8_t, addr_t, int, int *,
0153                                       uint16_t, uint8_t, void (*) (addr_t));
0154 extern int uhci_control_transfer (uint8_t, addr_t, int, addr_t, int, int);
0155 extern int uhci_bulk_transfer (uint8_t, uint8_t, addr_t, int, 
0156                                int, uint8_t, uint32_t *);
0157 extern int uhci_get_descriptor (uint8_t, uint16_t, uint16_t, uint16_t,
0158                                 uint16_t, addr_t, uint8_t);
0159 extern int uhci_set_address (uint8_t, uint8_t, uint8_t);
0160 extern int uhci_get_configuration (uint8_t, uint8_t);
0161 extern int uhci_set_configuration (uint8_t, uint8_t, uint8_t);
0162 extern int uhci_get_interface (uint8_t, uint16_t, uint8_t);
0163 extern int uhci_set_interface (uint8_t, uint16_t, uint16_t, uint8_t);
0164 extern sint uhci_get_string (uint8_t address, uint16_t index, uint16_t lang,
0165                              uint16_t length, void *buffer, uint8_t pktsize);
0166 extern sint uhci_interp_string (USB_STR_DESC *string, uint16_t length,
0167                                 uint16_t lang, uint8 *output, uint16_t out_len);
0168 
0169 
0170 
0171 #endif
0172 
0173 /*
0174  * Local Variables:
0175  * indent-tabs-mode: nil
0176  * mode: C
0177  * c-file-style: "gnu"
0178  * c-basic-offset: 2
0179  * End:
0180  */
0181 
0182 /* vi: set et sw=2 sts=2: */