Changeset 063ead6f in mainline
- Timestamp:
- 2011-02-20T21:37:20Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 41e645c, da7c0a9
- Parents:
- c20da9f (diff), 423e8c81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
rc20da9f r063ead6f 49 49 #include <ipc/devman.h> 50 50 #include <ipc/dev_iface.h> 51 #include <ipc/irc.h> 52 #include <ipc/ns.h> 53 #include <ipc/services.h> 54 #include <sysinfo.h> 51 55 #include <ops/hw_res.h> 52 56 #include <device/hw_res.h> … … 72 76 static bool pciintel_enable_child_interrupt(device_t *dev) 73 77 { 74 /* TODO */ 75 76 return false; 78 /* This is an old ugly way, copied from ne2000 driver */ 79 assert(dev); 80 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 81 82 sysarg_t apic; 83 sysarg_t i8259; 84 int irc_phone = -1; 85 int irc_service = 0; 86 87 if ((sysinfo_get_value("apic", &apic) == EOK) && (apic)) { 88 irc_service = SERVICE_APIC; 89 } else if ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)) { 90 irc_service = SERVICE_I8259; 91 } 92 93 if (irc_service) { 94 while (irc_phone < 0) 95 irc_phone = service_connect_blocking(irc_service, 0, 0); 96 } else { 97 return false; 98 } 99 100 size_t i; 101 for (i = 0; i < dev_data->hw_resources.count; i++) { 102 if (dev_data->hw_resources.resources[i].type == INTERRUPT) { 103 int irq = dev_data->hw_resources.resources[i].res.interrupt.irq; 104 async_msg_1(irc_phone, IRC_ENABLE_INTERRUPT, irq); 105 } 106 } 107 108 async_hangup(irc_phone); 109 return true; 77 110 } 78 111 -
uspace/drv/uhci-hcd/batch.c
rc20da9f r063ead6f 141 141 usb_log_debug("Checking(%p) %d packet for completion.\n", 142 142 instance, instance->packets); 143 /* This is just an ugly trick to support the old API */144 143 instance->transfered_size = 0; 145 144 size_t i = 0; … … 157 156 transfer_descriptor_actual_size(&instance->tds[i]); 158 157 } 158 /* This is just an ugly trick to support the old API */ 159 159 instance->transfered_size -= instance->setup_size; 160 160 return true; … … 191 191 0, 1, false, instance->target, USB_PID_IN, NULL, NULL); 192 192 193 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 194 193 195 instance->next_step = batch_call_out_and_dispose; 194 196 batch_schedule(instance); … … 221 223 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 222 224 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL); 225 226 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 223 227 224 228 instance->next_step = batch_call_in_and_dispose; … … 244 248 } 245 249 250 instance->tds[i - 1].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 251 246 252 instance->next_step = batch_call_in_and_dispose; 247 253 batch_schedule(instance); … … 268 274 } 269 275 276 instance->tds[i - 1].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 277 270 278 instance->next_step = batch_call_out_and_dispose; 271 279 batch_schedule(instance); -
uspace/drv/uhci-hcd/main.c
rc20da9f r063ead6f 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <usb/ddfiface.h> 37 #include <device/hw_res.h> 36 38 37 39 #include <errno.h> … … 46 48 #define NAME "uhci-hcd" 47 49 48 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 49 { 50 /* This shall be called only for the UHCI itself. */ 51 assert(dev->parent == NULL); 52 53 *handle = dev->handle; 54 return EOK; 55 } 50 static int uhci_add_device(device_t *device); 56 51 57 52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle, … … 75 70 } 76 71 72 77 73 static usb_iface_t hc_usb_iface = { 78 .get_hc_handle = usb_iface_get_hc_handle ,74 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, 79 75 .get_address = usb_iface_get_address 80 76 }; 81 77 /*----------------------------------------------------------------------------*/ 82 78 static device_ops_t uhci_ops = { 83 79 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 84 80 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 85 81 }; 82 /*----------------------------------------------------------------------------*/ 83 static driver_ops_t uhci_driver_ops = { 84 .add_device = uhci_add_device, 85 }; 86 /*----------------------------------------------------------------------------*/ 87 static driver_t uhci_driver = { 88 .name = NAME, 89 .driver_ops = &uhci_driver_ops 90 }; 91 /*----------------------------------------------------------------------------*/ 92 static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call) 93 { 94 assert(device); 95 uhci_t *hc = dev_to_uhci(device); 96 uint16_t status = IPC_GET_ARG1(*call); 97 assert(hc); 98 uhci_interrupt(hc, status); 99 } 100 /*----------------------------------------------------------------------------*/ 101 #define CHECK_RET_RETURN(ret, message...) \ 102 if (ret != EOK) { \ 103 usb_log_error(message); \ 104 return ret; \ 105 } 86 106 87 107 static int uhci_add_device(device_t *device) … … 96 116 int irq; 97 117 98 int r c = pci_get_my_registers(device,99 &io_reg_base, &io_reg_size, &irq);118 int ret = 119 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 100 120 101 if (rc != EOK) { 102 usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n", 103 rc, device->handle); 104 return rc; 105 } 106 121 CHECK_RET_RETURN(ret, 122 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 107 123 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", 108 124 io_reg_base, io_reg_size, irq); 109 125 126 ret = pci_enable_interrupts(device); 127 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 128 110 129 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 111 if (!uhci_hc) { 112 usb_log_error("Failed to allocaete memory for uhci hcd driver.\n"); 113 return ENOMEM; 130 ret = (uhci_hc != NULL) ? EOK : ENOMEM; 131 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n"); 132 133 ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size); 134 if (ret != EOK) { 135 usb_log_error("Failed to init uhci-hcd.\n"); 136 free(uhci_hc); 137 return ret; 114 138 } 115 139 116 int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size); 140 ret = register_interrupt_handler(device, irq, irq_handler, 141 &uhci_hc->interrupt_code); 117 142 if (ret != EOK) { 118 usb_log_error("Failed to init uhci-hcd.\n"); 143 usb_log_error("Failed to register interrupt handler.\n"); 144 uhci_fini(uhci_hc); 145 free(uhci_hc); 119 146 return ret; 120 147 } 148 121 149 device_t *rh; 122 150 ret = setup_root_hub(&rh, device); 123 124 151 if (ret != EOK) { 125 152 usb_log_error("Failed to setup uhci root hub.\n"); 126 /* TODO: destroy uhci here */ 153 uhci_fini(uhci_hc); 154 free(uhci_hc); 127 155 return ret; 128 156 } … … 131 159 if (ret != EOK) { 132 160 usb_log_error("Failed to register root hub.\n"); 133 /* TODO: destroy uhci here */ 161 uhci_fini(uhci_hc); 162 free(uhci_hc); 163 free(rh); 134 164 return ret; 135 165 } 136 166 137 167 device->driver_data = uhci_hc; 138 139 168 return EOK; 140 169 } 141 142 static driver_ops_t uhci_driver_ops = { 143 .add_device = uhci_add_device, 144 }; 145 146 static driver_t uhci_driver = { 147 .name = NAME, 148 .driver_ops = &uhci_driver_ops 149 }; 150 170 /*----------------------------------------------------------------------------*/ 151 171 int main(int argc, char *argv[]) 152 172 { 153 /* 154 * Do some global initializations. 155 */ 156 sleep(5); 157 usb_log_enable(USB_LOG_LEVEL_INFO, NAME); 173 sleep(3); 174 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 158 175 159 176 return driver_main(&uhci_driver); -
uspace/drv/uhci-hcd/pci.c
rc20da9f r063ead6f 121 121 return rc; 122 122 } 123 123 /*----------------------------------------------------------------------------*/ 124 int pci_enable_interrupts(device_t *device) 125 { 126 int parent_phone = devman_parent_device_connect(device->handle, 127 IPC_FLAG_BLOCKING); 128 bool enabled = hw_res_enable_interrupt(parent_phone); 129 return enabled ? EOK : EIO; 130 } 124 131 /** 125 132 * @} -
uspace/drv/uhci-hcd/pci.h
rc20da9f r063ead6f 39 39 40 40 int pci_get_my_registers(device_t *, uintptr_t *, size_t *, int *); 41 int pci_enable_interrupts(device_t *device); 41 42 42 43 #endif -
uspace/drv/uhci-hcd/transfer_list.c
rc20da9f r063ead6f 111 111 /* I'm the first one here */ 112 112 if (batch->link.prev == &instance->batch_list) { 113 usb_log_debug("Removing tracer%p was first, next element %x.\n",113 usb_log_debug("Removing batch %p was first, next element %x.\n", 114 114 batch, batch->qh->next_queue); 115 115 instance->queue_head->element = batch->qh->next_queue; 116 116 } else { 117 usb_log_debug("Removing tracer%p was NOT first, next element %x.\n",117 usb_log_debug("Removing batch %p was NOT first, next element %x.\n", 118 118 batch, batch->qh->next_queue); 119 119 batch_t *prev = list_get_instance(batch->link.prev, batch_t, link); -
uspace/drv/uhci-hcd/uhci-hcd.ma
rc20da9f r063ead6f 1 1 10 pci/ven=8086&dev=7020 2 2 10 pci/ven=8086&dev=7112 -
uspace/drv/uhci-hcd/uhci.c
rc20da9f r063ead6f 39 39 40 40 #include "uhci.h" 41 static irq_cmd_t uhci_cmds[] = { 42 { 43 .cmd = CMD_PIO_READ_16, 44 .addr = (void*)0xc022, 45 .dstarg = 1 46 }, 47 { 48 .cmd = CMD_PIO_WRITE_16, 49 .addr = (void*)0xc022, 50 .value = 0x1f 51 }, 52 { 53 .cmd = CMD_ACCEPT 54 } 55 }; 41 56 42 57 static int uhci_init_transfer_lists(uhci_t *instance); 43 static int uhci_clean_finished(void *arg); 58 static int uhci_init_mem_structures(uhci_t *instance); 59 static void uhci_init_hw(uhci_t *instance); 60 61 static int uhci_interrupt_emulator(void *arg); 44 62 static int uhci_debug_checker(void *arg); 63 45 64 static bool allowed_usb_packet( 46 65 bool low_speed, usb_transfer_type_t, size_t size); 47 66 48 int uhci_init(uhci_t *instance, void *regs, size_t reg_size) 49 { 50 #define CHECK_RET_RETURN(message...) \ 67 #define CHECK_RET_RETURN(ret, message...) \ 51 68 if (ret != EOK) { \ 52 69 usb_log_error(message); \ … … 54 71 } else (void) 0 55 72 56 /* init address keeper(libusb) */ 57 usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX); 58 usb_log_debug("Initialized address manager.\n");73 int uhci_init(uhci_t *instance, void *regs, size_t reg_size) 74 { 75 assert(reg_size >= sizeof(regs_t)); 59 76 60 77 /* allow access to hc control registers */ 61 78 regs_t *io; 62 assert(reg_size >= sizeof(regs_t));63 79 int ret = pio_enable(regs, reg_size, (void**)&io); 64 CHECK_RET_RETURN( "Failed to gain access to registers at %p.\n", io);80 CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io); 65 81 instance->registers = io; 66 82 usb_log_debug("Device registers accessible.\n"); 67 83 84 ret = uhci_init_mem_structures(instance); 85 CHECK_RET_RETURN(ret, "Failed to initialize memory structures.\n"); 86 87 uhci_init_hw(instance); 88 89 instance->cleaner = fibril_create(uhci_interrupt_emulator, instance); 90 // fibril_add_ready(instance->cleaner); 91 92 instance->debug_checker = fibril_create(uhci_debug_checker, instance); 93 fibril_add_ready(instance->debug_checker); 94 95 return EOK; 96 } 97 /*----------------------------------------------------------------------------*/ 98 void uhci_init_hw(uhci_t *instance) 99 { 100 101 /* set framelist pointer */ 102 const uint32_t pa = addr_to_phys(instance->frame_list); 103 pio_write_32(&instance->registers->flbaseadd, pa); 104 105 /* enable all interrupts, but resume interrupt */ 106 pio_write_16(&instance->registers->usbintr, 107 UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET); 108 109 /* Start the hc with large(64B) packet FSBR */ 110 pio_write_16(&instance->registers->usbcmd, 111 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE); 112 usb_log_debug("Started UHCI HC.\n"); 113 } 114 /*----------------------------------------------------------------------------*/ 115 int uhci_init_mem_structures(uhci_t *instance) 116 { 117 assert(instance); 118 119 /* init interrupt code */ 120 irq_cmd_t *interrupt_commands = malloc(sizeof(uhci_cmds)); 121 if (interrupt_commands == NULL) { 122 return ENOMEM; 123 } 124 memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds)); 125 interrupt_commands[0].addr = (void*)&instance->registers->usbsts; 126 interrupt_commands[1].addr = (void*)&instance->registers->usbsts; 127 instance->interrupt_code.cmds = interrupt_commands; 128 instance->interrupt_code.cmdcount = 129 sizeof(uhci_cmds) / sizeof(irq_cmd_t); 130 68 131 /* init transfer lists */ 69 ret = uhci_init_transfer_lists(instance); 70 CHECK_RET_RETURN("Failed to initialize transfer lists.\n"); 71 usb_log_debug("Transfer lists initialized.\n"); 72 73 74 usb_log_debug("Initializing frame list.\n"); 132 int ret = uhci_init_transfer_lists(instance); 133 CHECK_RET_RETURN(ret, "Failed to initialize transfer lists.\n"); 134 usb_log_debug("Initialized transfer lists.\n"); 135 136 /* frame list initialization */ 75 137 instance->frame_list = get_page(); 76 138 ret = instance ? EOK : ENOMEM; 77 CHECK_RET_RETURN("Failed to get frame list page.\n"); 139 CHECK_RET_RETURN(ret, "Failed to get frame list page.\n"); 140 usb_log_debug("Initialized frame list.\n"); 78 141 79 142 /* initialize all frames to point to the first queue head */ … … 86 149 } 87 150 88 const uintptr_t pa = (uintptr_t)addr_to_phys(instance->frame_list); 89 pio_write_32(&instance->registers->flbaseadd, (uint32_t)pa); 90 91 list_initialize(&instance->batch_list); 92 fibril_mutex_initialize(&instance->batch_list_mutex); 93 94 instance->cleaner = fibril_create(uhci_clean_finished, instance); 95 fibril_add_ready(instance->cleaner); 96 97 instance->debug_checker = fibril_create(uhci_debug_checker, instance); 98 fibril_add_ready(instance->debug_checker); 99 100 /* Start the hc with large(64B) packet FSBR */ 101 pio_write_16(&instance->registers->usbcmd, 102 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET); 103 usb_log_debug("Started UHCI HC.\n"); 104 105 uint16_t cmd = pio_read_16(&instance->registers->usbcmd); 106 cmd |= UHCI_CMD_DEBUG; 107 pio_write_16(&instance->registers->usbcmd, cmd); 151 /* init address keeper(libusb) */ 152 usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX); 153 usb_log_debug("Initialized address manager.\n"); 108 154 109 155 return EOK; … … 114 160 assert(instance); 115 161 116 /* initialize */162 /* initialize TODO: check errors */ 117 163 int ret; 118 164 ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL"); … … 146 192 instance->transfers[1][USB_TRANSFER_CONTROL] = 147 193 &instance->transfers_control_slow; 148 instance->transfers[0][USB_TRANSFER_ CONTROL] =149 &instance->transfers_ control_full;194 instance->transfers[0][USB_TRANSFER_BULK] = 195 &instance->transfers_bulk_full; 150 196 151 197 return EOK; … … 174 220 } 175 221 /*----------------------------------------------------------------------------*/ 176 int uhci_clean_finished(void* arg) 177 { 178 usb_log_debug("Started cleaning fibril.\n"); 222 void uhci_interrupt(uhci_t *instance, uint16_t status) 223 { 224 assert(instance); 225 if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0) 226 return; 227 usb_log_debug("UHCI interrupt: %X.\n", status); 228 transfer_list_check(&instance->transfers_interrupt); 229 transfer_list_check(&instance->transfers_control_slow); 230 transfer_list_check(&instance->transfers_control_full); 231 transfer_list_check(&instance->transfers_bulk_full); 232 } 233 /*----------------------------------------------------------------------------*/ 234 int uhci_interrupt_emulator(void* arg) 235 { 236 usb_log_debug("Started interrupt emulator.\n"); 179 237 uhci_t *instance = (uhci_t*)arg; 180 238 assert(instance); 181 239 182 240 while(1) { 183 transfer_list_check(&instance->transfers_interrupt); 184 transfer_list_check(&instance->transfers_control_slow); 185 transfer_list_check(&instance->transfers_control_full); 186 transfer_list_check(&instance->transfers_bulk_full); 241 uint16_t status = pio_read_16(&instance->registers->usbsts); 242 uhci_interrupt(instance, status); 187 243 async_usleep(UHCI_CLEANER_TIMEOUT); 188 244 } … … 195 251 assert(instance); 196 252 while (1) { 197 uint16_t cmd = pio_read_16(&instance->registers->usbcmd); 198 uint16_t sts = pio_read_16(&instance->registers->usbsts); 199 usb_log_debug("Command register: %X Status register: %X\n", cmd, sts); 253 const uint16_t cmd = pio_read_16(&instance->registers->usbcmd); 254 const uint16_t sts = pio_read_16(&instance->registers->usbsts); 255 const uint16_t intr = pio_read_16(&instance->registers->usbintr); 256 usb_log_debug("Command: %X Status: %X Interrupts: %x\n", 257 cmd, sts, intr); 200 258 201 259 uintptr_t frame_list = pio_read_32(&instance->registers->flbaseadd); 202 if (frame_list != (uintptr_t)addr_to_phys(instance->frame_list)) {260 if (frame_list != addr_to_phys(instance->frame_list)) { 203 261 usb_log_debug("Framelist address: %p vs. %p.\n", 204 262 frame_list, addr_to_phys(instance->frame_list)); -
uspace/drv/uhci-hcd/uhci.h
rc20da9f r063ead6f 66 66 67 67 uint16_t usbintr; 68 #define UHCI_INTR_SHORT_PACKET (1 << 3) 69 #define UHCI_INTR_COMPLETE (1 << 2) 70 #define UHCI_INTR_RESUME (1 << 1) 71 #define UHCI_INTR_CRC (1 << 0) 72 68 73 uint16_t frnum; 69 74 uint32_t flbaseadd; … … 81 86 link_pointer_t *frame_list; 82 87 83 link_t batch_list;84 fibril_mutex_t batch_list_mutex;85 86 88 transfer_list_t transfers_bulk_full; 87 89 transfer_list_t transfers_control_full; … … 90 92 91 93 transfer_list_t *transfers[2][4]; 94 95 irq_code_t interrupt_code; 92 96 93 97 fid_t cleaner; … … 98 102 int uhci_init(uhci_t *instance, void *regs, size_t reg_size); 99 103 100 int uhci_fini(uhci_t *device); 101 102 int uhci_transfer( 103 uhci_t *instance, 104 device_t *dev, 105 usb_target_t target, 106 usb_transfer_type_t transfer_type, 107 bool toggle, 108 usb_packet_id pid, 109 bool low_speed, 110 void *buffer, size_t size, 111 usbhc_iface_transfer_out_callback_t callback_out, 112 usbhc_iface_transfer_in_callback_t callback_in, 113 void *arg ); 104 static inline void uhci_fini(uhci_t *instance) {}; 114 105 115 106 int uhci_schedule(uhci_t *instance, batch_t *batch); 116 107 108 void uhci_interrupt(uhci_t *instance, uint16_t status); 109 117 110 static inline uhci_t * dev_to_uhci(device_t *dev) 118 111 { return (uhci_t*)dev->driver_data; } 112 119 113 120 114 #endif
Note:
See TracChangeset
for help on using the changeset viewer.