Changeset 2ab6875 in mainline
- Timestamp:
- 2011-03-07T11:18:21Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bcaefe3
- Parents:
- 4b4e163
- Location:
- uspace/drv/uhci-hcd
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
r4b4e163 r2ab6875 69 69 assert(func_in != NULL || func_out != NULL); 70 70 71 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \ 72 if (ptr == NULL) { \ 73 usb_log_error(message); \ 74 if (instance) { \ 75 batch_dispose(instance); \ 76 } \ 77 return NULL; \ 78 } else (void)0 79 71 80 batch_t *instance = malloc(sizeof(batch_t)); 72 if (instance == NULL) { 73 usb_log_error("Failed to allocate batch instance.\n"); 74 return NULL; 75 } 76 77 instance->qh = queue_head_get(); 78 if (instance->qh == NULL) { 79 usb_log_error("Failed to allocate queue head.\n"); 80 free(instance); 81 return NULL; 82 } 81 CHECK_NULL_DISPOSE_RETURN(instance, 82 "Failed to allocate batch instance.\n"); 83 bzero(instance, sizeof(batch_t)); 84 85 instance->qh = malloc32(sizeof(queue_head_t)); 86 CHECK_NULL_DISPOSE_RETURN(instance->qh, 87 "Failed to allocate batch queue head.\n"); 88 queue_head_init(instance->qh); 83 89 84 90 instance->packets = (size + max_packet_size - 1) / max_packet_size; … … 88 94 89 95 instance->tds = malloc32(sizeof(td_t) * instance->packets); 90 if (instance->tds == NULL) { 91 usb_log_error("Failed to allocate transfer descriptors.\n"); 92 queue_head_dispose(instance->qh); 93 free(instance); 94 return NULL; 95 } 96 CHECK_NULL_DISPOSE_RETURN( 97 instance->tds, "Failed to allocate transfer descriptors.\n"); 96 98 bzero(instance->tds, sizeof(td_t) * instance->packets); 97 99 98 100 const size_t transport_size = max_packet_size * instance->packets; 99 101 100 instance->transport_buffer = 101 (size > 0) ? malloc32(transport_size) : NULL; 102 103 if ((size > 0) && (instance->transport_buffer == NULL)) { 104 usb_log_error("Failed to allocate device accessible buffer.\n"); 105 queue_head_dispose(instance->qh); 106 free32(instance->tds); 107 free(instance); 108 return NULL; 109 } 110 111 instance->setup_buffer = setup_buffer ? malloc32(setup_size) : NULL; 112 if ((setup_size > 0) && (instance->setup_buffer == NULL)) { 113 usb_log_error("Failed to allocate device accessible setup buffer.\n"); 114 queue_head_dispose(instance->qh); 115 free32(instance->tds); 116 free32(instance->transport_buffer); 117 free(instance); 118 return NULL; 119 } 120 if (instance->setup_buffer) { 102 if (size > 0) { 103 instance->transport_buffer = malloc32(transport_size); 104 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer, 105 "Failed to allocate device accessible buffer.\n"); 106 } 107 108 if (setup_size > 0) { 109 instance->setup_buffer = malloc32(setup_size); 110 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer, 111 "Failed to allocate device accessible setup buffer.\n"); 121 112 memcpy(instance->setup_buffer, setup_buffer, setup_size); 122 113 } 123 114 115 116 link_initialize(&instance->link); 117 124 118 instance->max_packet_size = max_packet_size; 125 126 link_initialize(&instance->link);127 128 119 instance->target = target; 129 120 instance->transfer_type = transfer_type; 130 131 if (func_out)132 instance->callback_out = func_out;133 if (func_in)134 instance->callback_in = func_in;135 136 121 instance->buffer = buffer; 137 122 instance->buffer_size = size; … … 142 127 instance->manager = manager; 143 128 144 queue_head_element_td(instance->qh, addr_to_phys(instance->tds)); 129 if (func_out) 130 instance->callback_out = func_out; 131 if (func_in) 132 instance->callback_in = func_in; 133 134 queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds)); 135 145 136 usb_log_debug("Batch(%p) %d:%d memory structures ready.\n", 146 137 instance, target.address, target.endpoint); -
uspace/drv/uhci-hcd/transfer_list.c
r4b4e163 r2ab6875 43 43 instance->next = NULL; 44 44 instance->name = name; 45 instance->queue_head = queue_head_get();45 instance->queue_head = malloc32(sizeof(queue_head_t)); 46 46 if (!instance->queue_head) { 47 47 usb_log_error("Failed to allocate queue head.\n"); 48 48 return ENOMEM; 49 49 } 50 instance->queue_head_pa = (uintptr_t)addr_to_phys(instance->queue_head); 50 queue_head_init(instance->queue_head); 51 instance->queue_head_pa = addr_to_phys(instance->queue_head); 51 52 52 53 queue_head_init(instance->queue_head); -
uspace/drv/uhci-hcd/transfer_list.h
r4b4e163 r2ab6875 58 58 { 59 59 assert(instance); 60 queue_head_dispose(instance->queue_head);60 free32(instance->queue_head); 61 61 } 62 62 void transfer_list_remove_finished(transfer_list_t *instance); -
uspace/drv/uhci-hcd/uhci_struct/queue_head.h
r4b4e163 r2ab6875 71 71 } 72 72 73 static inline void queue_head_ element_td(queue_head_t *instance, uint32_t pa)73 static inline void queue_head_set_element_td(queue_head_t *instance, uint32_t pa) 74 74 { 75 75 if (pa) { … … 78 78 } 79 79 80 static inline queue_head_t * queue_head_get() {81 queue_head_t *ret = malloc32(sizeof(queue_head_t));82 if (ret)83 queue_head_init(ret);84 return ret;85 }86 87 static inline void queue_head_dispose(queue_head_t *head)88 { free32(head); }89 90 91 80 #endif 92 81 /**
Note:
See TracChangeset
for help on using the changeset viewer.