Changeset 643b983 in mainline
- Timestamp:
- 2011-01-21T18:14:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bae9e76
- Parents:
- 9600516
- Location:
- uspace/drv/uhci
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci/callback.h
r9600516 r643b983 35 35 #define DRV_UHCI_CALLBACK_H 36 36 37 #include <mem.h> 37 38 #include <usbhc_iface.h> 39 40 #include "debug.h" 41 #include "translating_malloc.h" 38 42 39 43 typedef struct callback 40 44 { 41 union { 42 usbhc_iface_transfer_in_callback_t callback_in; 43 usbhc_iface_transfer_out_callback_t callback_out; 44 }; 45 void* buffer; 45 usbhc_iface_transfer_in_callback_t callback_in; 46 usbhc_iface_transfer_out_callback_t callback_out; 47 void *old_buffer; 48 void *new_buffer; 49 void *arg; 50 size_t buffer_size; 51 device_t *dev; 46 52 } callback_t; 47 53 54 55 static inline int callback_init(callback_t *instance, device_t *dev, 56 void *buffer, size_t size, usbhc_iface_transfer_in_callback_t func_in, 57 usbhc_iface_transfer_out_callback_t func_out, void *arg) 58 { 59 assert(instance); 60 assert(func_in == NULL || func_out == NULL); 61 instance->new_buffer = trans_malloc(size); 62 if (!instance->new_buffer) { 63 uhci_print_error("Failed to allocate device acessible buffer.\n"); 64 return ENOMEM; 65 } 66 67 if (func_out) 68 memcpy(instance->new_buffer, buffer, size); 69 70 instance->callback_out = func_out; 71 instance->callback_in = func_in; 72 instance->old_buffer = buffer; 73 instance->buffer_size = size; 74 instance->dev = dev; 75 return EOK; 76 } 77 #define callback_in_init(instance, dev, buffer, size, func, arg) \ 78 callback_init(instance, dev, buffer, size, func, NULL, arg) 79 80 #define callback_out_init(instance, dev, buffer, size, func, arg) \ 81 callback_init(instance, dev, buffer, size, func, NULL, arg) 82 83 static inline void callback_fini(callback_t *instance) 84 { 85 assert(instance); 86 if (instance->new_buffer) 87 trans_free(instance->new_buffer); 88 } 48 89 #endif 49 90 /** -
uspace/drv/uhci/transfer_list.h
r9600516 r643b983 70 70 assert(instance); 71 71 if (instance->queue_head) 72 free(instance->queue_head);72 trans_free(instance->queue_head); 73 73 } 74 74 -
uspace/drv/uhci/uhci.c
r9600516 r643b983 68 68 } 69 69 /*----------------------------------------------------------------------------*/ 70 int init_tranfer_lists(transfer_list_t transfers[])71 {72 //TODO:refactor73 int ret;74 ret = transfer_list_init(&transfers[USB_TRANSFER_BULK], NULL);75 if (ret != EOK) {76 uhci_print_error("Failed to inititalize bulk queue.\n");77 return ret;78 }79 80 ret = transfer_list_init(81 &transfers[USB_TRANSFER_CONTROL], &transfers[USB_TRANSFER_BULK]);82 if (ret != EOK) {83 uhci_print_error("Failed to inititalize control queue.\n");84 transfer_list_fini(&transfers[USB_TRANSFER_BULK]);85 return ret;86 }87 88 ret = transfer_list_init(89 &transfers[USB_TRANSFER_INTERRUPT], &transfers[USB_TRANSFER_CONTROL]);90 if (ret != EOK) {91 uhci_print_error("Failed to interrupt control queue.\n");92 transfer_list_fini(&transfers[USB_TRANSFER_CONTROL]);93 transfer_list_fini(&transfers[USB_TRANSFER_BULK]);94 return ret;95 }96 97 return EOK;98 }99 /*----------------------------------------------------------------------------*/100 70 int uhci_in( 101 71 device_t *dev, … … 110 80 usb_str_transfer_type(transfer_type), 111 81 size); 82 if (size >= 1024) 83 return ENOTSUP; 112 84 113 callback( dev, USB_OUTCOME_OK, size, arg ); 85 callback_t *job = malloc(sizeof(callback_t)); 86 if (job == NULL) { 87 uhci_print_error("Failed to allocate callback structure.\n"); 88 return ENOMEM; 89 } 90 91 #define CHECK_RET_FREE_JOB(r, message) \ 92 if (r != EOK) { \ 93 uhci_print_error(message); \ 94 callback_fini(job); \ 95 trans_free(job); \ 96 return r; \ 97 } else (void) 0 98 99 int ret = callback_in_init(job, dev, buffer, size, callback, arg); 100 CHECK_RET_FREE_JOB(ret, "Failed to initialize callback structure.\n"); 101 102 transfer_descriptor_t *td = trans_malloc(sizeof(transfer_descriptor_t)); 103 ret = (td == NULL) ? ENOMEM : EOK; 104 CHECK_RET_FREE_JOB(ret, "Failed to allocate tranfer descriptor.\n"); 105 106 transfer_descriptor_init(td, 3, size, false, target, USB_PID_IN); 107 108 109 // TODO: add to list 110 // callback(dev, USB_OUTCOME_OK, size, arg); 114 111 115 112 return EOK; … … 152 149 } 153 150 /*----------------------------------------------------------------------------*/ 151 int init_tranfer_lists(transfer_list_t transfers[]) 152 { 153 //TODO:refactor 154 transfers[USB_TRANSFER_ISOCHRONOUS].first = NULL; 155 transfers[USB_TRANSFER_ISOCHRONOUS].last = NULL; 156 int ret; 157 ret = transfer_list_init(&transfers[USB_TRANSFER_BULK], NULL); 158 if (ret != EOK) { 159 uhci_print_error("Failed to inititalize bulk queue.\n"); 160 return ret; 161 } 162 163 ret = transfer_list_init( 164 &transfers[USB_TRANSFER_CONTROL], &transfers[USB_TRANSFER_BULK]); 165 if (ret != EOK) { 166 uhci_print_error("Failed to inititalize control queue.\n"); 167 transfer_list_fini(&transfers[USB_TRANSFER_BULK]); 168 return ret; 169 } 170 171 ret = transfer_list_init( 172 &transfers[USB_TRANSFER_INTERRUPT], &transfers[USB_TRANSFER_CONTROL]); 173 if (ret != EOK) { 174 uhci_print_error("Failed to interrupt control queue.\n"); 175 transfer_list_fini(&transfers[USB_TRANSFER_CONTROL]); 176 transfer_list_fini(&transfers[USB_TRANSFER_BULK]); 177 return ret; 178 } 179 180 return EOK; 181 } -
uspace/drv/uhci/uhci_struct/transfer_descriptor.h
r9600516 r643b983 35 35 #define DRV_UHCI_TRANSFER_DESCRIPTOR_H 36 36 37 #include <mem.h> 38 #include <usb/usb.h> 37 39 #include "callback.h" 38 40 … … 70 72 char :1; /* reserved */ 71 73 uint8_t toggle:1; 72 uint8_t end _point:4;74 uint8_t endpoint:4; 73 75 uint8_t address:7; 74 76 uint8_t pid; … … 85 87 } __attribute__((packed)) transfer_descriptor_t; 86 88 89 static inline int transfer_descriptor_init(transfer_descriptor_t *instance, 90 int error_count, size_t size, bool isochronous, usb_target_t target, 91 int pid) 92 { 93 assert(instance); 94 bzero(instance, sizeof(transfer_descriptor_t)); 95 96 instance->depth = 1; 97 instance->terminate = 1; 98 99 assert(error_count < 4); 100 instance->error_count = error_count; 101 instance->status.active = 1; 102 103 assert(size < 1024); 104 instance->maxlen = size; 105 106 instance->address = target.address; 107 instance->endpoint = target.endpoint; 108 109 instance->pid = pid; 110 111 return EOK; 112 } 113 87 114 #endif 88 115 /**
Note:
See TracChangeset
for help on using the changeset viewer.