pintos/src/devices/usb_uhci.c File Reference

#include <round.h>
#include <stdio.h>
#include <string.h>
#include <kernel/bitmap.h>
#include "threads/pte.h"
#include "threads/malloc.h"
#include "threads/palloc.h"
#include "threads/synch.h"
#include "threads/interrupt.h"
#include "threads/thread.h"
#include "devices/pci.h"
#include "devices/usb.h"
#include "devices/timer.h"

Go to the source code of this file.

Data Structures

struct  frame_list_ptr
struct  td_token
struct  td_control
struct  tx_descriptor
struct  queue_head
struct  uhci_info
struct  usb_wait
struct  uhci_dev_info
struct  uhci_eop_info

Defines

#define UHCI_MAX_PORTS   8
#define FRAME_LIST_ENTRIES   1024
#define TD_ENTRIES   (4096/32)
#define QH_ENTRIES   (4096/16)
#define UHCI_REG_USBCMD   0x00
#define UHCI_REG_USBSTS   0x02
#define UHCI_REG_USBINTR   0x04
#define UHCI_REG_FRNUM   0x06
#define UHCI_REG_FLBASEADD   0x08
#define UHCI_REG_SOFMOD   0x0c
#define UHCI_REG_PORTSC1   0x10
#define UHCI_REG_PORTSC2   0x12
#define UHCI_REGSZ   0x20
#define UHCI_REG_LEGSUP   0xC0
#define USB_CMD_MAX_PACKET   (1 << 7)
#define USB_CMD_CONFIGURE   (1 << 6)
#define USB_CMD_FGR   (1 << 4)
#define USB_CMD_EGSM   (1 << 3)
#define USB_CMD_GRESET   (1 << 2)
#define USB_CMD_HCRESET   (1 << 1)
#define USB_CMD_RS   (1 << 0)
#define USB_STATUS_HALTED   (1 << 5)
#define USB_STATUS_PROCESSERR   (1 << 4)
#define USB_STATUS_HOSTERR   (1 << 3)
#define USB_STATUS_RESUME   (1 << 2)
#define USB_STATUS_INTERR   (1 << 1)
#define USB_STATUS_USBINT   (1 << 0)
#define USB_INTR_SHORT   (1 << 3)
#define USB_INTR_IOC   (1 << 2)
#define USB_INTR_RESUME   (1 << 1)
#define USB_INTR_TIMEOUT   (1 << 0)
#define USB_PORT_SUSPEND   (1 << 12)
#define USB_PORT_RESET   (1 << 9)
#define USB_PORT_LOWSPEED   (1 << 8)
#define USB_PORT_RESUMED   (1 << 6)
#define USB_PORT_CHANGE   (1 << 3)
#define USB_PORT_ENABLE   (1 << 2)
#define USB_PORT_CONNECTCHG   (1 << 1)
#define USB_PORT_CONNECTSTATUS   (1 << 0)
#define ptr_to_flp(x)   (((uintptr_t)x) >> 4)
#define flp_to_ptr(x)   (uintptr_t)(((uintptr_t)x) << 4)
#define TD_FL_ASYNC   1
#define TD_FL_USED   0x80000000
#define uhci_lock(x)   lock_acquire(&(x)->lock)
#define uhci_unlock(x)   lock_release(&(x)->lock)
#define dev_lock(x)   lock_acquire(&(x)->lock)
#define dev_unlock(x)   lock_release(&(x)->lock)
#define uhci_is_stopped(x)
#define uhci_port_enabled(x, y)   (pci_reg_read16((x)->io, (y)) & USB_PORT_ENABLE)
#define UHCI_PORT_TIMEOUT   1000

Functions

static int token_to_pid (int token)
static int uhci_tx_pkt (host_eop_info eop, int token, void *pkt, int min_sz, int max_sz, int *in_sz, bool wait)
static int uhci_detect_change (host_info)
static int uhci_tx_pkt_now (struct uhci_eop_info *ue, int token, void *pkt, int sz)
static int uhci_tx_pkt_wait (struct uhci_eop_info *ue, int token, void *pkt, int max_sz, int *in_sz)
static int uhci_tx_pkt_bulk (struct uhci_eop_info *ue, int token, void *buf, int sz, int *tx)
static int uhci_process_completed (struct uhci_info *ui)
static struct tx_descriptoruhci_acquire_td (struct uhci_info *)
static void uhci_release_td (struct uhci_info *, struct tx_descriptor *)
static void uhci_remove_qh (struct uhci_info *ui, struct queue_head *qh)
static void qh_free (struct uhci_info *ui, struct queue_head *qh)
static struct queue_headqh_alloc (struct uhci_info *ui)
static struct uhci_infouhci_create_info (struct pci_io *io)
static void uhci_destroy_info (struct uhci_info *ui) UNUSED
static host_eop_info uhci_create_eop (host_dev_info hd, int eop, int maxpkt)
static void uhci_remove_eop (host_eop_info hei)
static host_dev_info uhci_create_chan (host_info hi, int dev_addr, int ver)
static void uhci_destroy_chan (host_dev_info)
static void uhci_modify_chan (host_dev_info, int dev_addr, int ver)
static void uhci_set_toggle (host_eop_info, int toggle)
static struct tx_descriptortd_from_pool (struct uhci_info *ui, int idx)
static int check_and_flip_change (struct uhci_info *ui, int reg)
static void uhci_stop (struct uhci_info *ui)
static void uhci_run (struct uhci_info *ui)
static void uhci_stop_unlocked (struct uhci_info *ui)
static void uhci_run_unlocked (struct uhci_info *ui)
static void uhci_add_td_to_qh (struct queue_head *qh, struct tx_descriptor *td)
static void uhci_remove_error_td (struct tx_descriptor *td)
static void uhci_setup_td (struct tx_descriptor *td, int dev_addr, int token, int eop, void *pkt, int sz, int toggle, bool ls)
static int uhci_enable_port (struct uhci_info *ui, int port)
static void uhci_irq (void *uhci_data)
static void uhci_detect_ports (struct uhci_info *ui)
static int uhci_remove_stalled (struct uhci_info *ui)
static void uhci_stall_watchdog (struct uhci_info *ui) UNUSED
static void dump_all_qh (struct uhci_info *ui)
static void dump_qh (struct queue_head *qh)
static void dump_regs (struct uhci_info *ui)
void uhci_init (void)

Variables

static struct usb_host uhci_host


Define Documentation

#define dev_lock ( x   )     lock_acquire(&(x)->lock)

Definition at line 198 of file usb_uhci.c.

#define dev_unlock ( x   )     lock_release(&(x)->lock)

Definition at line 199 of file usb_uhci.c.

#define flp_to_ptr ( x   )     (uintptr_t)(((uintptr_t)x) << 4)

Definition at line 78 of file usb_uhci.c.

Referenced by dump_qh(), uhci_add_td_to_qh(), uhci_remove_error_td(), and uhci_remove_qh().

#define FRAME_LIST_ENTRIES   1024

Definition at line 25 of file usb_uhci.c.

Referenced by uhci_create_chan(), uhci_create_info(), and uhci_remove_qh().

#define ptr_to_flp ( x   )     (((uintptr_t)x) >> 4)

#define QH_ENTRIES   (4096/16)

Definition at line 27 of file usb_uhci.c.

Referenced by uhci_create_info().

#define TD_ENTRIES   (4096/32)

Definition at line 26 of file usb_uhci.c.

Referenced by td_from_pool(), uhci_create_info(), uhci_process_completed(), and uhci_release_td().

#define TD_FL_ASYNC   1

Definition at line 125 of file usb_uhci.c.

Referenced by uhci_process_completed(), and uhci_tx_pkt_now().

#define TD_FL_USED   0x80000000

Definition at line 126 of file usb_uhci.c.

Referenced by uhci_process_completed(), uhci_tx_pkt_now(), and uhci_tx_pkt_wait().

#define uhci_is_stopped ( x   ) 

Value:

Definition at line 244 of file usb_uhci.c.

Referenced by uhci_remove_qh(), uhci_stop_unlocked(), and uhci_tx_pkt_now().

#define uhci_lock ( x   )     lock_acquire(&(x)->lock)

#define UHCI_MAX_PORTS   8

3194302259845385 Universal Host Controller Interface driver TODO: Stall timeouts Better (any) root hub handling

Definition at line 23 of file usb_uhci.c.

Referenced by uhci_detect_ports().

#define uhci_port_enabled ( x,
 )     (pci_reg_read16((x)->io, (y)) & USB_PORT_ENABLE)

Definition at line 246 of file usb_uhci.c.

#define UHCI_PORT_TIMEOUT   1000

Definition at line 352 of file usb_uhci.c.

#define UHCI_REG_FLBASEADD   0x08

Definition at line 34 of file usb_uhci.c.

Referenced by uhci_init().

#define UHCI_REG_FRNUM   0x06

Definition at line 33 of file usb_uhci.c.

Referenced by uhci_init().

#define UHCI_REG_LEGSUP   0xC0

Definition at line 41 of file usb_uhci.c.

Referenced by uhci_init().

#define UHCI_REG_PORTSC1   0x10

Definition at line 36 of file usb_uhci.c.

Referenced by check_and_flip_change(), uhci_detect_ports(), uhci_enable_port(), and uhci_init().

#define UHCI_REG_PORTSC2   0x12

Definition at line 37 of file usb_uhci.c.

Referenced by uhci_init().

#define UHCI_REG_SOFMOD   0x0c

Definition at line 35 of file usb_uhci.c.

Referenced by uhci_init().

#define UHCI_REG_USBCMD   0x00

Definition at line 30 of file usb_uhci.c.

Referenced by uhci_init(), uhci_run_unlocked(), and uhci_stop_unlocked().

#define UHCI_REG_USBINTR   0x04

Definition at line 32 of file usb_uhci.c.

Referenced by uhci_init().

#define UHCI_REG_USBSTS   0x02

Definition at line 31 of file usb_uhci.c.

Referenced by uhci_irq().

#define UHCI_REGSZ   0x20

Definition at line 38 of file usb_uhci.c.

Referenced by uhci_init().

#define uhci_unlock ( x   )     lock_release(&(x)->lock)

#define USB_CMD_CONFIGURE   (1 << 6)

Definition at line 46 of file usb_uhci.c.

Referenced by uhci_init().

#define USB_CMD_EGSM   (1 << 3)

Definition at line 48 of file usb_uhci.c.

#define USB_CMD_FGR   (1 << 4)

Definition at line 47 of file usb_uhci.c.

#define USB_CMD_GRESET   (1 << 2)

Definition at line 49 of file usb_uhci.c.

#define USB_CMD_HCRESET   (1 << 1)

Definition at line 50 of file usb_uhci.c.

Referenced by uhci_init().

#define USB_CMD_MAX_PACKET   (1 << 7)

Definition at line 45 of file usb_uhci.c.

Referenced by uhci_init(), and uhci_run_unlocked().

#define USB_CMD_RS   (1 << 0)

Definition at line 51 of file usb_uhci.c.

Referenced by uhci_init(), uhci_run_unlocked(), and uhci_stop_unlocked().

#define USB_INTR_IOC   (1 << 2)

Definition at line 63 of file usb_uhci.c.

Referenced by uhci_init().

#define USB_INTR_RESUME   (1 << 1)

Definition at line 64 of file usb_uhci.c.

Referenced by uhci_init().

#define USB_INTR_SHORT   (1 << 3)

Definition at line 62 of file usb_uhci.c.

Referenced by uhci_init().

#define USB_INTR_TIMEOUT   (1 << 0)

Definition at line 65 of file usb_uhci.c.

Referenced by uhci_init().

#define USB_PORT_CHANGE   (1 << 3)

Definition at line 72 of file usb_uhci.c.

Referenced by check_and_flip_change(), and uhci_enable_port().

#define USB_PORT_CONNECTCHG   (1 << 1)

Definition at line 74 of file usb_uhci.c.

Referenced by uhci_enable_port().

#define USB_PORT_CONNECTSTATUS   (1 << 0)

Definition at line 75 of file usb_uhci.c.

Referenced by uhci_enable_port().

#define USB_PORT_ENABLE   (1 << 2)

Definition at line 73 of file usb_uhci.c.

Referenced by uhci_enable_port().

#define USB_PORT_LOWSPEED   (1 << 8)

Definition at line 70 of file usb_uhci.c.

#define USB_PORT_RESET   (1 << 9)

Definition at line 69 of file usb_uhci.c.

Referenced by uhci_enable_port().

#define USB_PORT_RESUMED   (1 << 6)

Definition at line 71 of file usb_uhci.c.

#define USB_PORT_SUSPEND   (1 << 12)

Definition at line 68 of file usb_uhci.c.

#define USB_STATUS_HALTED   (1 << 5)

Definition at line 54 of file usb_uhci.c.

#define USB_STATUS_HOSTERR   (1 << 3)

Definition at line 56 of file usb_uhci.c.

Referenced by uhci_irq().

#define USB_STATUS_INTERR   (1 << 1)

Definition at line 58 of file usb_uhci.c.

Referenced by uhci_irq().

#define USB_STATUS_PROCESSERR   (1 << 4)

Definition at line 55 of file usb_uhci.c.

Referenced by uhci_irq().

#define USB_STATUS_RESUME   (1 << 2)

Definition at line 57 of file usb_uhci.c.

#define USB_STATUS_USBINT   (1 << 0)

Definition at line 59 of file usb_uhci.c.

Referenced by uhci_irq().


Function Documentation

static int check_and_flip_change ( struct uhci_info ui,
int  reg 
) [static]

static void dump_all_qh ( struct uhci_info ui  )  [static]

static void dump_qh ( struct queue_head qh  )  [static]

Definition at line 1149 of file usb_uhci.c.

References flp_to_ptr, printf(), ptov(), queue_head::qelp, frame_list_ptr::terminate, and vtop().

Referenced by dump_all_qh().

static void dump_regs ( struct uhci_info ui  )  [static]

Definition at line 419 of file usb_uhci.c.

References uhci_info::io, name, pci_reg_read16(), pci_reg_read32(), and printf().

Referenced by uhci_irq().

static struct queue_head * qh_alloc ( struct uhci_info ui  )  [static, read]

static void qh_free ( struct uhci_info ui,
struct queue_head qh 
) [static]

static struct tx_descriptor * td_from_pool ( struct uhci_info ui,
int  idx 
) [static, read]

Definition at line 1163 of file usb_uhci.c.

References ASSERT, TD_ENTRIES, and uhci_info::td_pool.

Referenced by uhci_acquire_td(), and uhci_process_completed().

static int token_to_pid ( int  token  )  [static]

Definition at line 571 of file usb_uhci.c.

References PANIC, USB_PID_IN, USB_PID_OUT, USB_PID_SETUP, USB_TOKEN_IN, USB_TOKEN_OUT, and USB_TOKEN_SETUP.

Referenced by uhci_setup_td().

static struct tx_descriptor * uhci_acquire_td ( struct uhci_info ui  )  [static, read]

static void uhci_add_td_to_qh ( struct queue_head qh,
struct tx_descriptor td 
) [static]

static host_dev_info uhci_create_chan ( host_info  hi,
int  dev_addr,
int  ver 
) [static]

static host_eop_info uhci_create_eop ( host_dev_info  hd,
int  eop,
int  maxpkt 
) [static]

static struct uhci_info * uhci_create_info ( struct pci_io io  )  [static, read]

static void uhci_destroy_chan ( host_dev_info  hd  )  [static]

static void uhci_destroy_info ( struct uhci_info ui  )  [static]

static int uhci_detect_change ( host_info  hi  )  [static]

Definition at line 874 of file usb_uhci.c.

References check_and_flip_change(), uhci_info::num_ports, uhci_lock, and uhci_unlock.

static void uhci_detect_ports ( struct uhci_info ui  )  [static]

Definition at line 1170 of file usb_uhci.c.

References uhci_info::io, uhci_info::num_ports, pci_reg_read16(), UHCI_MAX_PORTS, and UHCI_REG_PORTSC1.

Referenced by uhci_init().

static int uhci_enable_port ( struct uhci_info ui,
int  port 
) [static]

void uhci_init ( void   ) 

static void uhci_irq ( void *  uhci_data  )  [static]

static void uhci_modify_chan ( host_dev_info  hd,
int  dev_addr,
int  ver 
) [static]

Definition at line 1113 of file usb_uhci.c.

References uhci_dev_info::dev_addr, uhci_dev_info::low_speed, and USB_VERSION_1_0.

static int uhci_process_completed ( struct uhci_info ui  )  [static]

static void uhci_release_td ( struct uhci_info ui,
struct tx_descriptor td 
) [static]

static void uhci_remove_eop ( host_eop_info  hei  )  [static]

Definition at line 1271 of file usb_uhci.c.

References free().

static void uhci_remove_error_td ( struct tx_descriptor td  )  [static]

static void uhci_remove_qh ( struct uhci_info ui,
struct queue_head qh 
) [static]

static int uhci_remove_stalled ( struct uhci_info ui  )  [static]

static void uhci_run ( struct uhci_info ui  )  [static]

Put UHCI into 'Run' State

Definition at line 1090 of file usb_uhci.c.

References ASSERT, uhci_info::lock, lock_held_by_current_thread(), and uhci_run_unlocked().

Referenced by uhci_create_chan(), uhci_destroy_chan(), uhci_stall_watchdog(), and uhci_tx_pkt_wait().

static void uhci_run_unlocked ( struct uhci_info ui  )  [static]

static void uhci_set_toggle ( host_eop_info  he,
int  toggle 
) [static]

Definition at line 1123 of file usb_uhci.c.

References uhci_eop_info::toggle.

static void uhci_setup_td ( struct tx_descriptor td,
int  dev_addr,
int  token,
int  eop,
void *  pkt,
int  sz,
int  toggle,
bool ls  UNUSED 
) [static]

static void uhci_stall_watchdog ( struct uhci_info ui  )  [static]

static void uhci_stop ( struct uhci_info ui  )  [static]

Put UHCI into stop state Wait until status register reflects setting

Definition at line 1047 of file usb_uhci.c.

References ASSERT, intr_get_level(), INTR_OFF, uhci_info::lock, lock_held_by_current_thread(), and uhci_stop_unlocked().

Referenced by uhci_create_chan(), uhci_destroy_chan(), uhci_stall_watchdog(), uhci_tx_pkt_now(), and uhci_tx_pkt_wait().

static void uhci_stop_unlocked ( struct uhci_info ui  )  [static]

static int uhci_tx_pkt ( host_eop_info  eop,
int  token,
void *  pkt,
int  min_sz,
int  max_sz,
int *  in_sz,
bool  wait 
) [static]

static int uhci_tx_pkt_bulk ( struct uhci_eop_info ue,
int  token,
void *  buf,
int  sz,
int *  tx 
) [static]

Definition at line 532 of file usb_uhci.c.

References uhci_eop_info::maxpkt, NULL, uhci_tx_pkt(), and USB_HOST_ERR_NONE.

Referenced by uhci_tx_pkt().

static int uhci_tx_pkt_now ( struct uhci_eop_info ue,
int  token,
void *  pkt,
int  sz 
) [static]

static int uhci_tx_pkt_wait ( struct uhci_eop_info ue,
int  token,
void *  pkt,
int  max_sz,
int *  in_sz 
) [static]


Variable Documentation

struct usb_host uhci_host [static]

Initial value:

 {
  .name = "UHCI",
  .tx_pkt = uhci_tx_pkt,
  .detect_change = uhci_detect_change,
  .create_dev_channel = uhci_create_chan,
  .remove_dev_channel = uhci_destroy_chan,
  .modify_dev_channel = uhci_modify_chan,
  .set_toggle = uhci_set_toggle,
  .create_eop = uhci_create_eop,
  .remove_eop = uhci_remove_eop
}

Definition at line 266 of file usb_uhci.c.


Generated on Mon Jan 10 16:43:58 2011 for Pintos by  doxygen 1.5.6