00001 /* 00002 * Copyright (c) 2011 Jan Vesely 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00035 #ifndef DRV_UHCI_HC_H 00036 #define DRV_UHCI_HC_H 00037 00038 #include <fibril.h> 00039 #include <ddi.h> 00040 00041 #include <usb/host/device_keeper.h> 00042 #include <usb/host/usb_endpoint_manager.h> 00043 #include <usb/host/batch.h> 00044 00045 #include "transfer_list.h" 00046 00048 typedef struct uhci_regs { 00050 uint16_t usbcmd; 00051 #define UHCI_CMD_MAX_PACKET (1 << 7) 00052 #define UHCI_CMD_CONFIGURE (1 << 6) 00053 #define UHCI_CMD_DEBUG (1 << 5) 00054 #define UHCI_CMD_FORCE_GLOBAL_RESUME (1 << 4) 00055 #define UHCI_CMD_FORCE_GLOBAL_SUSPEND (1 << 3) 00056 #define UHCI_CMD_GLOBAL_RESET (1 << 2) 00057 #define UHCI_CMD_HCRESET (1 << 1) 00058 #define UHCI_CMD_RUN_STOP (1 << 0) 00059 00061 uint16_t usbsts; 00062 #define UHCI_STATUS_HALTED (1 << 5) 00063 #define UHCI_STATUS_PROCESS_ERROR (1 << 4) 00064 #define UHCI_STATUS_SYSTEM_ERROR (1 << 3) 00065 #define UHCI_STATUS_RESUME (1 << 2) 00066 #define UHCI_STATUS_ERROR_INTERRUPT (1 << 1) 00067 #define UHCI_STATUS_INTERRUPT (1 << 0) 00068 #define UHCI_STATUS_NM_INTERRUPTS \ 00069 (UHCI_STATUS_PROCESS_ERROR | UHCI_STATUS_SYSTEM_ERROR) 00070 00072 uint16_t usbintr; 00073 #define UHCI_INTR_SHORT_PACKET (1 << 3) 00074 #define UHCI_INTR_COMPLETE (1 << 2) 00075 #define UHCI_INTR_RESUME (1 << 1) 00076 #define UHCI_INTR_CRC (1 << 0) 00077 00079 uint16_t frnum; 00080 00082 uint32_t flbaseadd; 00083 00085 uint8_t sofmod; 00086 } regs_t; 00087 00088 #define UHCI_FRAME_LIST_COUNT 1024 00089 #define UHCI_INT_EMULATOR_TIMEOUT 10000 00090 #define UHCI_DEBUGER_TIMEOUT 5000000 00091 #define UHCI_ALLOWED_HW_FAIL 5 00092 #define UHCI_NEEDED_IRQ_COMMANDS 5 00093 00095 typedef struct hc { 00097 usb_device_keeper_t manager; 00099 usb_endpoint_manager_t ep_manager; 00100 00102 regs_t *registers; 00103 00105 link_pointer_t *frame_list; 00106 00108 transfer_list_t transfers_interrupt; 00110 transfer_list_t transfers_control_slow; 00112 transfer_list_t transfers_bulk_full; 00114 transfer_list_t transfers_control_full; 00115 00117 transfer_list_t *transfers[2][4]; 00118 00120 irq_code_t interrupt_code; 00121 00123 irq_cmd_t interrupt_commands[UHCI_NEEDED_IRQ_COMMANDS]; 00124 00126 fid_t interrupt_emulator; 00127 00129 bool hw_interrupts; 00130 00132 unsigned hw_failures; 00133 } hc_t; 00134 00135 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts); 00136 00137 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); 00138 00139 void hc_interrupt(hc_t *instance, uint16_t status); 00140 00145 static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ }; 00146 00152 static inline hc_t * fun_to_hc(ddf_fun_t *fun) 00153 { 00154 assert(fun); 00155 return fun->driver_data; 00156 } 00157 #endif 00158