Changes in / [293de44:160b75e] in mainline
- Files:
-
- 15 added
- 6 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r293de44 r160b75e 53 53 ./uspace/app/klog/klog 54 54 ./uspace/app/lsusb/lsusb 55 ./uspace/app/mkbd/mkbd56 55 ./uspace/app/mkfat/mkfat 57 56 ./uspace/app/netstart/netstart -
boot/Makefile.common
r293de44 r160b75e 157 157 $(USPACE_PATH)/app/usbinfo/usbinfo \ 158 158 $(USPACE_PATH)/app/vuhid/vuh \ 159 $(USPACE_PATH)/app/mkbd/mkbd \160 159 $(USPACE_PATH)/app/websrv/websrv 161 160 -
boot/arch/amd64/Makefile.inc
r293de44 r160b75e 49 49 usbflbk \ 50 50 usbhub \ 51 usbkbd \ 51 52 usbhid \ 52 53 usbmast \ -
kernel/generic/src/ipc/irq.c
r293de44 r160b75e 370 370 if (AS != irq->driver_as) \ 371 371 as_switch(AS, irq->driver_as); \ 372 printf("Copying data from address: %p.\n", va); \ 372 373 memcpy_from_uspace(&target, va, (sizeof(target))); \ 373 374 if (dstarg) \ … … 380 381 if (AS != irq->driver_as) \ 381 382 as_switch(AS, irq->driver_as); \ 383 printf("Writing data to address: %p.\n", va); \ 382 384 memcpy_to_uspace(va, &val, sizeof(val)); \ 383 385 } while (0) … … 455 457 uint32_t val; 456 458 CMD_MEM_READ(val); 459 printf("mem READ value: %x.\n", val); 457 460 break; 458 461 } -
uspace/Makefile
r293de44 r160b75e 59 59 app/websrv \ 60 60 app/sysinfo \ 61 app/mkbd \62 61 srv/clip \ 63 62 srv/devmap \ … … 123 122 drv/uhci-rhd \ 124 123 drv/usbflbk \ 124 drv/usbkbd \ 125 125 drv/usbhid \ 126 126 drv/usbhub \ … … 144 144 drv/uhci-rhd \ 145 145 drv/usbflbk \ 146 drv/usbkbd \ 146 147 drv/usbhid \ 147 148 drv/usbhub \ -
uspace/drv/ohci/batch.c
r293de44 r160b75e 44 44 #include "hw_struct/transfer_descriptor.h" 45 45 46 /** OHCI specific data required for USB transfer */47 46 typedef struct ohci_transfer_batch { 48 /** Endpoint descriptor of the target endpoint. */49 47 ed_t *ed; 50 /** List of TDs needed for the transfer */51 48 td_t **tds; 52 /** Number of TDs used by the transfer */53 49 size_t td_count; 54 /** Dummy TD to be left at the ED and used by the next transfer */55 50 size_t leave_td; 56 /** Data buffer, must be accessible byb the OHCI hw. */ 57 void *device_buffer; 51 char *device_buffer; 58 52 } ohci_transfer_batch_t; 59 /*----------------------------------------------------------------------------*/ 60 static void batch_control(usb_transfer_batch_t *instance, 61 usb_direction_t data_dir, usb_direction_t status_dir); 62 static void batch_data(usb_transfer_batch_t *instance); 63 /*----------------------------------------------------------------------------*/ 64 /** Safely destructs ohci_transfer_batch_t structure 65 * 66 * @param[in] ohci_batch Instance to destroy. 67 */ 53 68 54 static void ohci_transfer_batch_dispose(void *ohci_batch) 69 55 { … … 83 69 } 84 70 /*----------------------------------------------------------------------------*/ 85 /** Allocate memory initialize internal structures 86 * 87 * @param[in] fun DDF function to pass to callback. 88 * @param[in] ep Communication target 89 * @param[in] buffer Data source/destination. 90 * @param[in] buffer_size Size of the buffer. 91 * @param[in] setup_buffer Setup data source (if not NULL) 92 * @param[in] setup_size Size of setup_buffer (should be always 8) 93 * @param[in] func_in function to call on inbound transfer completion 94 * @param[in] func_out function to call on outbound transfer completion 95 * @param[in] arg additional parameter to func_in or func_out 96 * @return Valid pointer if all structures were successfully created, 97 * NULL otherwise. 98 * 99 * Allocates and initializes structures needed by the OHCI hw for the transfer. 100 */ 71 static void batch_control(usb_transfer_batch_t *instance, 72 usb_direction_t data_dir, usb_direction_t status_dir); 73 static void batch_data(usb_transfer_batch_t *instance); 74 /*----------------------------------------------------------------------------*/ 101 75 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, 102 char *buffer, size_t buffer_size, 103 const char *setup_buffer, size_t setup_size, 76 char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size, 104 77 usbhc_iface_transfer_in_callback_t func_in, 105 78 usbhc_iface_transfer_out_callback_t func_out, void *arg) … … 121 94 ohci_transfer_batch_dispose); 122 95 123 consthcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep);96 hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep); 124 97 assert(hcd_ep); 125 98 … … 130 103 data->td_count = 131 104 ((buffer_size + OHCI_TD_MAX_TRANSFER - 1) / OHCI_TD_MAX_TRANSFER); 132 /* Control transfer need Setup and Status stage */133 105 if (ep->transfer_type == USB_TRANSFER_CONTROL) { 134 106 data->td_count += 2; 135 107 } 136 108 137 /* We need an extra place for TDthat is currently assigned to hcd_ep*/109 /* we need one extra place for td that is currently assigned to hcd_ep*/ 138 110 data->tds = calloc(sizeof(td_t*), data->td_count + 1); 139 111 CHECK_NULL_DISPOSE_RETURN(data->tds, 140 112 "Failed to allocate transfer descriptors.\n"); 141 113 142 /* Add TD left over by the previous transfer */143 114 data->tds[0] = hcd_ep->td; 144 115 data->leave_td = 0; … … 152 123 data->ed = hcd_ep->ed; 153 124 154 /* NOTE: OHCI is capable of handling buffer that crosses page boundaries155 * it is, however, not capable of handling buffer that occupies more156 * than two pages (the first page is computed using start pointer, the157 * other using the end pointer) */158 125 if (setup_size + buffer_size > 0) { 159 126 data->device_buffer = malloc32(setup_size + buffer_size); … … 168 135 } 169 136 /*----------------------------------------------------------------------------*/ 170 /** Check batch TDs' status.171 *172 * @param[in] instance Batch structure to use.173 * @return False, if there is an active TD, true otherwise.174 *175 * Walk all TDs (usually there is just one). Stop with false if there is an176 * active TD. Stop with true if an error is found. Return true if the walk177 * completes with the last TD.178 */179 137 bool batch_is_complete(usb_transfer_batch_t *instance) 180 138 { … … 182 140 ohci_transfer_batch_t *data = instance->private_data; 183 141 assert(data); 142 size_t tds = data->td_count; 184 143 usb_log_debug("Batch(%p) checking %zu td(s) for completion.\n", 185 instance, data->td_count);144 instance, tds); 186 145 usb_log_debug("ED: %x:%x:%x:%x.\n", 187 146 data->ed->status, data->ed->td_head, data->ed->td_tail, … … 189 148 size_t i = 0; 190 149 instance->transfered_size = instance->buffer_size; 191 for (; i < data->td_count; ++i) {150 for (; i < tds; ++i) { 192 151 assert(data->tds[i] != NULL); 193 152 usb_log_debug("TD %zu: %x:%x:%x:%x.\n", i, … … 214 173 assert(hcd_ep); 215 174 hcd_ep->td = data->tds[i]; 216 assert(i > 0); 217 for (--i;i < data->td_count; ++i) 218 instance->transfered_size -= td_remain_size(data->tds[i]); 175 if (i > 0) 176 instance->transfered_size -= td_remain_size(data->tds[i - 1]); 219 177 220 178 /* Clear possible ED HALT */ 221 179 data->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG; 222 constuint32_t pa = addr_to_phys(hcd_ep->td);180 uint32_t pa = addr_to_phys(hcd_ep->td); 223 181 assert(pa == (data->ed->td_head & ED_TDHEAD_PTR_MASK)); 224 182 assert(pa == (data->ed->td_tail & ED_TDTAIL_PTR_MASK)); … … 227 185 } 228 186 /*----------------------------------------------------------------------------*/ 229 /** Starts execution of the TD list230 *231 * @param[in] instance Batch structure to use232 */233 187 void batch_commit(usb_transfer_batch_t *instance) 234 188 { … … 239 193 } 240 194 /*----------------------------------------------------------------------------*/ 241 /** Prepares control write transfer.242 *243 * @param[in] instance Batch structure to use.244 *245 * Uses generic control transfer using direction OUT(data stage) and246 * IN(status stage).247 */248 195 void batch_control_write(usb_transfer_batch_t *instance) 249 196 { … … 256 203 } 257 204 /*----------------------------------------------------------------------------*/ 258 /** Prepares control read transfer.259 *260 * @param[in] instance Batch structure to use.261 *262 * Uses generic control transfer using direction IN(data stage) and263 * OUT(status stage).264 */265 205 void batch_control_read(usb_transfer_batch_t *instance) 266 206 { … … 271 211 } 272 212 /*----------------------------------------------------------------------------*/ 273 /** Prepare interrupt in transfer.274 *275 * @param[in] instance Batch structure to use.276 *277 * Data transfer.278 */279 213 void batch_interrupt_in(usb_transfer_batch_t *instance) 280 214 { … … 285 219 } 286 220 /*----------------------------------------------------------------------------*/ 287 /** Prepare interrupt out transfer.288 *289 * @param[in] instance Batch structure to use.290 *291 * Data transfer.292 */293 221 void batch_interrupt_out(usb_transfer_batch_t *instance) 294 222 { … … 301 229 } 302 230 /*----------------------------------------------------------------------------*/ 303 /** Prepare bulk in transfer.304 *305 * @param[in] instance Batch structure to use.306 *307 * Data transfer.308 */309 231 void batch_bulk_in(usb_transfer_batch_t *instance) 310 232 { … … 315 237 } 316 238 /*----------------------------------------------------------------------------*/ 317 /** Prepare bulk out transfer.318 *319 * @param[in] instance Batch structure to use.320 *321 * Data transfer.322 */323 239 void batch_bulk_out(usb_transfer_batch_t *instance) 324 240 { … … 331 247 } 332 248 /*----------------------------------------------------------------------------*/ 333 /** Prepare generic control transfer 334 * 335 * @param[in] instance Batch structure to use. 336 * @param[in] data_dir Direction to use for data stage. 337 * @param[in] status_dir Direction to use for status stage. 338 * 339 * Setup stage with toggle 0 and direction BOTH(SETUP_PID) 340 * Data stage with alternating toggle and direction supplied by parameter. 341 * Status stage with toggle 1 and direction supplied by parameter. 342 */ 249 ed_t * batch_ed(usb_transfer_batch_t *instance) 250 { 251 assert(instance); 252 ohci_transfer_batch_t *data = instance->private_data; 253 assert(data); 254 return data->ed; 255 } 256 /*----------------------------------------------------------------------------*/ 343 257 void batch_control(usb_transfer_batch_t *instance, 344 258 usb_direction_t data_dir, usb_direction_t status_dir) … … 389 303 } 390 304 /*----------------------------------------------------------------------------*/ 391 /** Prepare generic data transfer392 *393 * @param[in] instance Batch structure to use.394 *395 * Direction is supplied by the associated ep and toggle is maintained by the396 * OHCI hw in ED.397 */398 305 void batch_data(usb_transfer_batch_t *instance) 399 306 { … … 409 316 char *buffer = instance->data_buffer; 410 317 while (remain_size > 0) { 411 const size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER412 ?OHCI_TD_MAX_TRANSFER : remain_size;318 size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ? 319 OHCI_TD_MAX_TRANSFER : remain_size; 413 320 414 321 td_init(data->tds[td_current], instance->ep->direction, -
uspace/drv/ohci/batch.h
r293de44 r160b75e 41 41 #include <usb/host/batch.h> 42 42 43 #include "hw_struct/endpoint_descriptor.h" 44 43 45 usb_transfer_batch_t * batch_get( 44 46 ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size, 45 c onst char *setup_buffer, size_t setup_size,47 char *setup_buffer, size_t setup_size, 46 48 usbhc_iface_transfer_in_callback_t func_in, 47 49 usbhc_iface_transfer_out_callback_t func_out, … … 63 65 64 66 void batch_bulk_out(usb_transfer_batch_t *instance); 67 68 ed_t * batch_ed(usb_transfer_batch_t *instance); 65 69 #endif 66 70 /** -
uspace/drv/ohci/endpoint_list.c
r293de44 r160b75e 34 34 #include <errno.h> 35 35 #include <usb/debug.h> 36 #include <arch/barrier.h>37 36 38 37 #include "endpoint_list.h" … … 44 43 * @return Error code 45 44 * 46 * Allocates memory for internal ed_t structure.45 * Allocates memory for internal qh_t structure. 47 46 */ 48 47 int endpoint_list_init(endpoint_list_t *instance, const char *name) … … 69 68 * @param[in] instance List to lead. 70 69 * @param[in] next List to append. 71 * 72 * Does not check whether this replaces an existing list. 70 * @return Error code 71 * 72 * Does not check whether this replaces an existing list . 73 73 */ 74 74 void endpoint_list_set_next(endpoint_list_t *instance, endpoint_list_t *next) … … 79 79 } 80 80 /*----------------------------------------------------------------------------*/ 81 /** Add endpoint to the list and queue. 82 * 83 * @param[in] instance List to use. 84 * @param[in] endpoint Endpoint to add. 81 /** Submit transfer endpoint to the list and queue. 82 * 83 * @param[in] instance List to use. 84 * @param[in] endpoint Transfer endpoint to submit. 85 * @return Error code 85 86 * 86 87 * The endpoint is added to the end of the list and queue. … … 98 99 /* Add to the hardware queue. */ 99 100 if (list_empty(&instance->endpoint_list)) { 100 /* There are no active EDs*/101 /* There is nothing scheduled */ 101 102 last_ed = instance->list_head; 102 103 } else { 103 /* There are active EDs, get the last one*/104 /* There is something scheduled */ 104 105 hcd_endpoint_t *last = list_get_instance( 105 106 instance->endpoint_list.prev, hcd_endpoint_t, link); 106 assert(last);107 107 last_ed = last->ed; 108 108 } 109 /* Keep link */109 /* keep link */ 110 110 hcd_ep->ed->next = last_ed->next; 111 /* Make sure ED is written to the memory */112 write_barrier();113 114 /* Add ed to the hw queue */115 111 ed_append_ed(last_ed, hcd_ep->ed); 116 /* Make sure ED is updated */ 117 write_barrier();118 119 /* Add to the swlist */112 113 asm volatile ("": : :"memory"); 114 115 /* Add to the driver list */ 120 116 list_append(&hcd_ep->link, &instance->endpoint_list); 121 117 … … 133 129 } 134 130 /*----------------------------------------------------------------------------*/ 135 /** Remove endpoint from the list and queue. 136 * 137 * @param[in] instance List to use. 138 * @param[in] endpoint Endpoint to remove. 131 #if 0 132 /** Create list for finished endpoints. 133 * 134 * @param[in] instance List to use. 135 * @param[in] done list to fill 136 */ 137 void endpoint_list_remove_finished(endpoint_list_t *instance, link_t *done) 138 { 139 assert(instance); 140 assert(done); 141 142 fibril_mutex_lock(&instance->guard); 143 usb_log_debug2("Checking list %s for completed endpointes(%d).\n", 144 instance->name, list_count(&instance->endpoint_list)); 145 link_t *current = instance->endpoint_list.next; 146 while (current != &instance->endpoint_list) { 147 link_t *next = current->next; 148 hcd_endpoint_t *endpoint = 149 list_get_instance(current, hcd_endpoint_t, link); 150 151 if (endpoint_is_complete(endpoint)) { 152 /* Save for post-processing */ 153 endpoint_list_remove_endpoint(instance, endpoint); 154 list_append(current, done); 155 } 156 current = next; 157 } 158 fibril_mutex_unlock(&instance->guard); 159 } 160 /*----------------------------------------------------------------------------*/ 161 /** Walk the list and abort all endpointes. 162 * 163 * @param[in] instance List to use. 164 */ 165 void endpoint_list_abort_all(endpoint_list_t *instance) 166 { 167 fibril_mutex_lock(&instance->guard); 168 while (!list_empty(&instance->endpoint_list)) { 169 link_t *current = instance->endpoint_list.next; 170 hcd_endpoint_t *endpoint = 171 list_get_instance(current, hcd_endpoint_t, link); 172 endpoint_list_remove_endpoint(instance, endpoint); 173 hcd_endpoint_finish_error(endpoint, EIO); 174 } 175 fibril_mutex_unlock(&instance->guard); 176 } 177 #endif 178 /*----------------------------------------------------------------------------*/ 179 /** Remove a transfer endpoint from the list and queue. 180 * 181 * @param[in] instance List to use. 182 * @param[in] endpoint Transfer endpoint to remove. 183 * @return Error code 184 * 185 * Does not lock the transfer list, caller is responsible for that. 139 186 */ 140 187 void endpoint_list_remove_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep) … … 165 212 assert((prev_ed->next & ED_NEXT_PTR_MASK) == addr_to_phys(hcd_ep->ed)); 166 213 prev_ed->next = hcd_ep->ed->next; 167 /* Make sure ED is updated */ 168 write_barrier(); 169 214 215 asm volatile ("": : :"memory"); 170 216 usb_log_debug("HCD EP(%p) removed (%s) from %s, next %x.\n", 171 217 hcd_ep, qpos, instance->name, hcd_ep->ed->next); -
uspace/drv/ohci/endpoint_list.h
r293de44 r160b75e 41 41 #include "utils/malloc32.h" 42 42 43 /** Structure maintains both OHCI queue and software list of active endpoints.*/44 43 typedef struct endpoint_list { 45 /** Guard against add/remove races */46 44 fibril_mutex_t guard; 47 /** OHCI hw structure at the beginning of the queue */48 45 ed_t *list_head; 49 /** Physical address of the first(dummy) ED */50 46 uint32_t list_head_pa; 51 /** Assigned name, provides nicer debug output */52 47 const char *name; 53 /** Sw list of all active EDs */54 48 link_t endpoint_list; 55 49 } endpoint_list_t; … … 59 53 * @param[in] instance Memory place to use. 60 54 * 61 * Frees memory of the internal ed_t structure.55 * Frees memory for internal qh_t structure. 62 56 */ 63 57 static inline void endpoint_list_fini(endpoint_list_t *instance) … … 68 62 69 63 int endpoint_list_init(endpoint_list_t *instance, const char *name); 64 70 65 void endpoint_list_set_next(endpoint_list_t *instance, endpoint_list_t *next); 66 71 67 void endpoint_list_add_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep); 68 72 69 void endpoint_list_remove_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep); 70 #if 0 71 void endpoint_list_remove_finished(endpoint_list_t *instance, link_t *done); 72 73 void endpoint_list_abort_all(endpoint_list_t *instance); 74 #endif 73 75 #endif 74 76 /** -
uspace/drv/ohci/hc.c
r293de44 r160b75e 51 51 static int hc_init_memory(hc_t *instance); 52 52 /*----------------------------------------------------------------------------*/ 53 /** Announce OHCI root hub to the DDF54 *55 * @param[in] instance OHCI driver intance56 * @param[in] hub_fun DDF fuction representing OHCI root hub57 * @return Error code58 */59 53 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun) 60 54 { … … 62 56 assert(hub_fun); 63 57 64 const usb_address_t hub_address = 58 int ret; 59 60 usb_address_t hub_address = 65 61 device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL); 66 62 if (hub_address <= 0) { 67 usb_log_error("Failed(%d) to get OHCI root hub address.\n", 68 hub_address); 63 usb_log_error("Failed to get OHCI root hub address.\n"); 69 64 return hub_address; 70 65 } … … 73 68 &instance->manager, hub_address, hub_fun->handle); 74 69 75 #define CHECK_RET_RELEASE(ret, message...) \ 76 if (ret != EOK) { \ 77 usb_log_error(message); \ 78 hc_remove_endpoint(instance, hub_address, 0, USB_DIRECTION_BOTH); \ 79 usb_device_keeper_release(&instance->manager, hub_address); \ 80 return ret; \ 81 } else (void)0 82 83 int ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL, 70 ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL, 84 71 USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH, 64, 0, 0); 85 CHECK_RET_RELEASE(ret, "Failed(%d) to add OHCI rh endpoint 0.\n", ret); 72 if (ret != EOK) { 73 usb_log_error("Failed to add OHCI rh endpoint 0.\n"); 74 usb_device_keeper_release(&instance->manager, hub_address); 75 return ret; 76 } 86 77 87 78 char *match_str = NULL; 88 79 /* DDF needs heap allocated string */ 89 80 ret = asprintf(&match_str, "usb&class=hub"); 90 ret = ret > 0 ? 0 : ret; 91 CHECK_RET_RELEASE(ret, "Failed(%d) to create match-id string.\n", ret); 81 if (ret < 0) { 82 usb_log_error( 83 "Failed(%d) to create root hub match-id string.\n", ret); 84 usb_device_keeper_release(&instance->manager, hub_address); 85 return ret; 86 } 92 87 93 88 ret = ddf_fun_add_match_id(hub_fun, match_str, 100); 94 CHECK_RET_RELEASE(ret, "Failed(%d) add root hub match-id.\n", ret); 95 89 if (ret != EOK) { 90 usb_log_error("Failed add root hub match-id.\n"); 91 } 96 92 ret = ddf_fun_bind(hub_fun); 97 CHECK_RET_RELEASE(ret, "Failed(%d) to bind root hub function.\n", ret); 98 99 return EOK; 100 #undef CHECK_RET_RELEASE 101 } 102 /*----------------------------------------------------------------------------*/ 103 /** Initialize OHCI hc driver structure 104 * 105 * @param[in] instance Memory place for the structure. 106 * @param[in] regs Address of the memory mapped I/O registers. 107 * @param[in] reg_size Size of the memory mapped area. 108 * @param[in] interrupts True if w interrupts should be used 109 * @return Error code 110 */ 93 return ret; 94 } 95 /*----------------------------------------------------------------------------*/ 111 96 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts) 112 97 { … … 136 121 #undef CHECK_RET_RETURN 137 122 123 124 // hc_init_hw(instance); 125 hc_gain_control(instance); 138 126 fibril_mutex_initialize(&instance->guard); 139 hc_gain_control(instance);140 127 141 128 rh_init(&instance->rh, instance->registers); … … 150 137 } 151 138 /*----------------------------------------------------------------------------*/ 152 /** Create end register endpoint structures153 *154 * @param[in] instance OHCI driver structure.155 * @param[in] address USB address of the device.156 * @param[in] endpoint USB endpoint number.157 * @param[in] speed Communication speeed of the device.158 * @param[in] type Endpoint's transfer type.159 * @param[in] direction Endpoint's direction.160 * @param[in] mps Maximum packet size the endpoint accepts.161 * @param[in] size Maximum allowed buffer size.162 * @param[in] interval Time between transfers(interrupt transfers only).163 * @return Error code164 */165 139 int hc_add_endpoint( 166 140 hc_t *instance, usb_address_t address, usb_endpoint_t endpoint, … … 220 194 } 221 195 /*----------------------------------------------------------------------------*/ 222 /** Dequeue and delete endpoint structures223 *224 * @param[in] instance OHCI hc driver structure.225 * @param[in] address USB address of the device.226 * @param[in] endpoint USB endpoint number.227 * @param[in] direction Direction of the endpoint.228 * @return Error code229 */230 196 int hc_remove_endpoint(hc_t *instance, usb_address_t address, 231 197 usb_endpoint_t endpoint, usb_direction_t direction) … … 278 244 } 279 245 /*----------------------------------------------------------------------------*/ 280 /** Get access to endpoint structures281 *282 * @param[in] instance OHCI hc driver structure.283 * @param[in] address USB address of the device.284 * @param[in] endpoint USB endpoint number.285 * @param[in] direction Direction of the endpoint.286 * @param[out] bw Reserved bandwidth.287 * @return Error code288 */289 246 endpoint_t * hc_get_endpoint(hc_t *instance, usb_address_t address, 290 247 usb_endpoint_t endpoint, usb_direction_t direction, size_t *bw) … … 298 255 } 299 256 /*----------------------------------------------------------------------------*/ 300 /** Add USB transfer to the schedule.301 *302 * @param[in] instance OHCI hc driver structure.303 * @param[in] batch Batch representing the transfer.304 * @return Error code.305 */306 257 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch) 307 258 { … … 310 261 assert(batch->ep); 311 262 312 /* Check for root hub communication */263 /* check for root hub communication */ 313 264 if (batch->ep->address == instance->rh.address) { 314 265 return rh_request(&instance->rh, batch); … … 318 269 list_append(&batch->link, &instance->pending_batches); 319 270 batch_commit(batch); 320 321 /* Control and bulk schedules need a kick to start working */ 322 switch (batch->ep->transfer_type) 323 { 271 switch (batch->ep->transfer_type) { 324 272 case USB_TRANSFER_CONTROL: 325 273 instance->registers->command_status |= CS_CLF; … … 331 279 break; 332 280 } 281 333 282 fibril_mutex_unlock(&instance->guard); 334 283 return EOK; 335 284 } 336 285 /*----------------------------------------------------------------------------*/ 337 /** Interrupt handling routine338 *339 * @param[in] instance OHCI hc driver structure.340 * @param[in] status Value of the status register at the time of interrupt.341 */342 286 void hc_interrupt(hc_t *instance, uint32_t status) 343 287 { … … 348 292 if (status & I_RHSC) 349 293 rh_interrupt(&instance->rh); 294 350 295 351 296 if (status & I_WDH) { … … 371 316 fibril_mutex_unlock(&instance->guard); 372 317 } 373 374 if (status & I_UE) { 375 hc_start_hw(instance); 376 } 377 378 } 379 /*----------------------------------------------------------------------------*/ 380 /** Check status register regularly 381 * 382 * @param[in] instance OHCI hc driver structure. 383 * @return Error code 384 */ 318 } 319 /*----------------------------------------------------------------------------*/ 385 320 int interrupt_emulator(hc_t *instance) 386 321 { … … 391 326 instance->registers->interrupt_status = status; 392 327 hc_interrupt(instance, status); 393 async_usleep( 10000);328 async_usleep(50000); 394 329 } 395 330 return EOK; 396 331 } 397 332 /*----------------------------------------------------------------------------*/ 398 /** Turn off any (BIOS)driver that might be in control of the device.399 *400 * @param[in] instance OHCI hc driver structure.401 */402 333 void hc_gain_control(hc_t *instance) 403 334 { … … 449 380 } 450 381 /*----------------------------------------------------------------------------*/ 451 /** OHCI hw initialization routine.452 *453 * @param[in] instance OHCI hc driver structure.454 */455 382 void hc_start_hw(hc_t *instance) 456 383 { … … 520 447 } 521 448 /*----------------------------------------------------------------------------*/ 522 /** Initialize schedule queues523 *524 * @param[in] instance OHCI hc driver structure525 * @return Error code526 */527 449 int hc_init_transfer_lists(hc_t *instance) 528 450 { 529 451 assert(instance); 452 530 453 #define SETUP_ENDPOINT_LIST(type) \ 531 454 do { \ … … 535 458 usb_log_error("Failed(%d) to setup %s endpoint list.\n", \ 536 459 ret, name); \ 537 endpoint_list_fini(&instance->lists[USB_TRANSFER_ISOCHRONOUS]); \460 endpoint_list_fini(&instance->lists[USB_TRANSFER_ISOCHRONOUS]); \ 538 461 endpoint_list_fini(&instance->lists[USB_TRANSFER_INTERRUPT]); \ 539 462 endpoint_list_fini(&instance->lists[USB_TRANSFER_CONTROL]); \ 540 463 endpoint_list_fini(&instance->lists[USB_TRANSFER_BULK]); \ 541 return ret; \542 464 } \ 543 465 } while (0) … … 554 476 } 555 477 /*----------------------------------------------------------------------------*/ 556 /** Initialize memory structures used by the OHCI hcd.557 *558 * @param[in] instance OHCI hc driver structure.559 * @return Error code.560 */561 478 int hc_init_memory(hc_t *instance) 562 479 { … … 585 502 /* Init interrupt code */ 586 503 instance->interrupt_code.cmds = instance->interrupt_commands; 587 instance->interrupt_code.cmdcount = OHCI_NEEDED_IRQ_COMMANDS;588 504 { 589 505 /* Read status register */ … … 605 521 instance->interrupt_commands[2].srcarg = 2; 606 522 607 /* Write -clean status register */523 /* Write clean status register */ 608 524 instance->interrupt_commands[3].cmd = CMD_MEM_WRITE_A_32; 609 525 instance->interrupt_commands[3].srcarg = 1; … … 613 529 /* Accept interrupt */ 614 530 instance->interrupt_commands[4].cmd = CMD_ACCEPT; 531 532 instance->interrupt_code.cmdcount = OHCI_NEEDED_IRQ_COMMANDS; 615 533 } 616 534 -
uspace/drv/ohci/hc.h
r293de44 r160b75e 53 53 #define OHCI_NEEDED_IRQ_COMMANDS 5 54 54 55 /** Main OHCI drier structure */56 55 typedef struct hc { 57 /** USB bus driver, devices and addresses */58 usb_device_keeper_t manager;59 /** USB bus driver, endpoints */60 usb_endpoint_manager_t ep_manager;61 62 /** Memory mapped I/O registers area */63 56 ohci_regs_t *registers; 64 /** Host controller communication area structure */65 57 hcca_t *hcca; 66 58 67 /** Transfer schedules */ 59 usb_address_t rh_address; 60 rh_t rh; 61 68 62 endpoint_list_t lists[4]; 69 /** List of active transfers */70 63 link_t pending_batches; 71 64 72 /** Fibril for periodic checks if interrupts can't be used */ 65 usb_device_keeper_t manager; 66 usb_endpoint_manager_t ep_manager; 73 67 fid_t interrupt_emulator; 74 75 /** Guards schedule and endpoint manipulation */76 68 fibril_mutex_t guard; 77 69 … … 81 73 /** Commands that form interrupt code */ 82 74 irq_cmd_t interrupt_commands[OHCI_NEEDED_IRQ_COMMANDS]; 83 84 /** USB hub emulation structure */85 rh_t rh;86 75 } hc_t; 87 76 88 77 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun); 78 89 79 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts); 80 90 81 void hc_start_hw(hc_t *instance); 91 82 … … 94 85 * @param[in] instance Host controller structure to use. 95 86 */ 96 static inline void hc_fini(hc_t *instance) 97 { /* TODO: implement*/ }; 87 static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ }; 98 88 99 89 int hc_add_endpoint(hc_t *instance, usb_address_t address, usb_endpoint_t ep, 100 90 usb_speed_t speed, usb_transfer_type_t type, usb_direction_t direction, 101 91 size_t max_packet_size, size_t size, unsigned interval); 92 102 93 int hc_remove_endpoint(hc_t *instance, usb_address_t address, 103 94 usb_endpoint_t endpoint, usb_direction_t direction); 95 104 96 endpoint_t * hc_get_endpoint(hc_t *instance, usb_address_t address, 105 97 usb_endpoint_t endpoint, usb_direction_t direction, size_t *bw); 106 98 107 99 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); 100 108 101 void hc_interrupt(hc_t *instance, uint32_t status); 109 102 … … 114 107 */ 115 108 static inline hc_t * fun_to_hc(ddf_fun_t *fun) 116 { return fun->driver_data; }109 { return (hc_t*)fun->driver_data; } 117 110 #endif 118 111 /** -
uspace/drv/ohci/hcd_endpoint.c
r293de44 r160b75e 35 35 #include "hcd_endpoint.h" 36 36 37 /** Callback to set toggle on ED.38 *39 * @param[in] hcd_ep hcd endpoint structure40 * @param[in] toggle new value of toggle bit41 */42 37 static void hcd_ep_toggle_set(void *hcd_ep, int toggle) 43 38 { … … 47 42 ed_toggle_set(instance->ed, toggle); 48 43 } 49 /*----------------------------------------------------------------------------*/50 /** Callback to get value of toggle bit.51 *52 * @param[in] hcd_ep hcd endpoint structure53 * @return Current value of toggle bit.54 */55 44 static int hcd_ep_toggle_get(void *hcd_ep) 56 45 { … … 60 49 return ed_toggle_get(instance->ed); 61 50 } 62 /*----------------------------------------------------------------------------*/ 63 /** Creates new hcd endpoint representation. 64 * 65 * @param[in] ep USBD endpoint structure 66 * @return pointer to a new hcd endpoint structure, NULL on failure. 67 */ 51 52 68 53 hcd_endpoint_t * hcd_endpoint_assign(endpoint_t *ep) 69 54 { … … 93 78 } 94 79 /*----------------------------------------------------------------------------*/ 95 /** Disposes assigned hcd endpoint structure 96 * 97 * @param[in] ep USBD endpoint structure 98 */ 80 hcd_endpoint_t * hcd_endpoint_get(endpoint_t *ep) 81 { 82 assert(ep); 83 return ep->hc_data.data; 84 } 85 /*----------------------------------------------------------------------------*/ 99 86 void hcd_endpoint_clear(endpoint_t *ep) 100 87 { -
uspace/drv/ohci/hcd_endpoint.h
r293de44 r160b75e 37 37 #include <assert.h> 38 38 #include <adt/list.h> 39 39 40 #include <usb/host/endpoint.h> 40 41 … … 42 43 #include "hw_struct/transfer_descriptor.h" 43 44 44 /** Connector structure linking ED to to prepared TD. */45 45 typedef struct hcd_endpoint { 46 /** OHCI endpoint descriptor */47 46 ed_t *ed; 48 /** Currently enqueued transfer descriptor */49 47 td_t *td; 50 /** Linked list used by driver software */51 48 link_t link; 52 49 } hcd_endpoint_t; 53 50 54 51 hcd_endpoint_t * hcd_endpoint_assign(endpoint_t *ep); 52 53 hcd_endpoint_t * hcd_endpoint_get(endpoint_t *ep); 54 55 55 void hcd_endpoint_clear(endpoint_t *ep); 56 57 /** Get and convert assigned hcd_endpoint_t structure58 * @param[in] ep USBD endpoint structure.59 * @return Pointer to assigned hcd endpoint structure60 */61 static inline hcd_endpoint_t * hcd_endpoint_get(endpoint_t *ep)62 {63 assert(ep);64 return ep->hc_data.data;65 }66 67 56 #endif 68 57 /** -
uspace/drv/ohci/hw_struct/transfer_descriptor.c
r293de44 r160b75e 44 44 assert(instance); 45 45 bzero(instance, sizeof(td_t)); 46 instance-> status = 046 instance-> status = 0 47 47 | ((dp[dir] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT) 48 48 | ((CC_NOACCESS2 & TD_STATUS_CC_MASK) << TD_STATUS_CC_SHIFT); -
uspace/drv/ohci/hw_struct/transfer_descriptor.h
r293de44 r160b75e 41 41 #include "completion_codes.h" 42 42 43 /* OHCI TDs can handle up to 8KB buffers, however, it can use max 2 pages. 44 * Using 4KB buffers guarantees the page count condition. 45 * (OHCI assumes 4KB pages) */ 46 #define OHCI_TD_MAX_TRANSFER (4 * 1024) 43 /* OHCI TDs can handle up to 8KB buffers */ 44 #define OHCI_TD_MAX_TRANSFER (8 * 1024) 47 45 48 46 typedef struct td { -
uspace/drv/ohci/ohci_regs.h
r293de44 r160b75e 36 36 #include <stdint.h> 37 37 38 /** OHCI memory mapped registers structure */ 39 typedef struct ohci_regs{38 typedef struct ohci_regs 39 { 40 40 const volatile uint32_t revision; 41 41 volatile uint32_t control; -
uspace/drv/uhci-hcd/batch.c
r293de44 r160b75e 45 45 #define DEFAULT_ERROR_COUNT 3 46 46 47 /** UHCI specific data required for USB transfer */48 47 typedef struct uhci_transfer_batch { 49 /** Queue head50 * This QH is used to maintain UHCI schedule structure and the element51 * pointer points to the first TD of this batch.52 */53 48 qh_t *qh; 54 /** List of TDs needed for the transfer */55 49 td_t *tds; 56 /** Number of TDs used by the transfer */50 void *device_buffer; 57 51 size_t td_count; 58 /** Data buffer, must be accessible by the UHCI hw */59 void *device_buffer;60 52 } uhci_transfer_batch_t; 61 53 /*----------------------------------------------------------------------------*/ 54 static void uhci_transfer_batch_dispose(void *uhci_batch) 55 { 56 uhci_transfer_batch_t *instance = uhci_batch; 57 assert(instance); 58 free32(instance->device_buffer); 59 free(instance); 60 } 61 /*----------------------------------------------------------------------------*/ 62 62 63 static void batch_control(usb_transfer_batch_t *instance, 63 64 usb_packet_id data_stage, usb_packet_id status_stage); 64 65 static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid); 65 /*----------------------------------------------------------------------------*/ 66 /** Safely destructs uhci_transfer_batch_t structure 67 * 68 * @param[in] uhci_batch Instance to destroy. 69 */ 70 static void uhci_transfer_batch_dispose(void *uhci_batch) 71 { 72 uhci_transfer_batch_t *instance = uhci_batch; 73 assert(instance); 74 free32(instance->device_buffer); 75 free(instance); 76 } 77 /*----------------------------------------------------------------------------*/ 66 78 67 /** Allocate memory and initialize internal data structure. 79 68 * … … 95 84 */ 96 85 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, 97 char *buffer, size_t buffer_size, 98 const char* setup_buffer, size_t setup_size, 86 char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size, 99 87 usbhc_iface_transfer_in_callback_t func_in, 100 88 usbhc_iface_transfer_out_callback_t func_out, void *arg) … … 185 173 instance->error = td_status(&data->tds[i]); 186 174 if (instance->error != EOK) { 187 usb_log_debug("Batch(%p) found error TD(%zu):%" 188 PRIx32 ".\n",instance, i, data->tds[i].status);175 usb_log_debug("Batch(%p) found error TD(%zu):%" PRIx32 ".\n", 176 instance, i, data->tds[i].status); 189 177 td_print_status(&data->tds[i]); 190 178 … … 409 397 /*----------------------------------------------------------------------------*/ 410 398 /** Provides access to QH data structure. 411 *412 399 * @param[in] instance Batch pointer to use. 413 400 * @return Pointer to the QH used by the batch. -
uspace/drv/uhci-hcd/batch.h
r293de44 r160b75e 45 45 usb_transfer_batch_t * batch_get( 46 46 ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size, 47 c onst char *setup_buffer, size_t setup_size,47 char *setup_buffer, size_t setup_size, 48 48 usbhc_iface_transfer_in_callback_t func_in, 49 49 usbhc_iface_transfer_out_callback_t func_out, … … 55 55 56 56 void batch_control_write(usb_transfer_batch_t *instance); 57 57 58 void batch_control_read(usb_transfer_batch_t *instance); 58 59 59 60 void batch_interrupt_in(usb_transfer_batch_t *instance); 61 60 62 void batch_interrupt_out(usb_transfer_batch_t *instance); 61 63 62 64 void batch_bulk_in(usb_transfer_batch_t *instance); 65 63 66 void batch_bulk_out(usb_transfer_batch_t *instance); 64 67 -
uspace/drv/uhci-hcd/hc.c
r293de44 r160b75e 57 57 static int hc_debug_checker(void *arg); 58 58 /*----------------------------------------------------------------------------*/ 59 /** Initialize UHCI hc driver structure59 /** Initialize UHCI hcd driver structure 60 60 * 61 61 * @param[in] instance Memory place to initialize. -
uspace/drv/uhci-hcd/hc.h
r293de44 r160b75e 95 95 #define UHCI_NEEDED_IRQ_COMMANDS 5 96 96 97 /* * Main UHCIdriver structure */97 /* Main HC driver structure */ 98 98 typedef struct hc { 99 99 /** USB bus driver, devices and addresses */ -
uspace/drv/uhci-hcd/transfer_list.c
r293de44 r160b75e 34 34 #include <errno.h> 35 35 #include <usb/debug.h> 36 #include <arch/barrier.h>37 36 38 37 #include "transfer_list.h" … … 72 71 * @param[in] instance Memory place to use. 73 72 * 74 * Frees memory of theinternal qh_t structure.73 * Frees memory for internal qh_t structure. 75 74 */ 76 75 void transfer_list_fini(transfer_list_t *instance) … … 127 126 assert((pa & LINK_POINTER_ADDRESS_MASK) == pa); 128 127 129 /* Make sure all data in the batch are written */130 write_barrier();131 132 128 /* keep link */ 133 129 batch_qh(batch)->next = last_qh->next; 134 130 qh_set_next_qh(last_qh, batch_qh(batch)); 135 131 136 /* Make sure the pointer is updated */ 137 write_barrier(); 132 asm volatile ("": : :"memory"); 138 133 139 134 /* Add to the driver list */ … … 227 222 == addr_to_phys(batch_qh(batch))); 228 223 prev_qh->next = batch_qh(batch)->next; 229 230 /* Make sure the pointer is updated */ 231 write_barrier(); 232 224 asm volatile ("": : :"memory"); 233 225 /* Remove from the batch list */ 234 226 list_remove(&batch->link); -
uspace/drv/uhci-hcd/transfer_list.h
r293de44 r160b75e 43 43 * of currently executed transfers 44 44 */ 45 typedef struct transfer_list { 45 typedef struct transfer_list 46 { 46 47 /** Guard against multiple add/remove races */ 47 48 fibril_mutex_t guard; -
uspace/drv/uhci-hcd/utils/malloc32.h
r293de44 r160b75e 74 74 if (size <= SLAB_ELEMENT_SIZE) 75 75 return slab_malloc_g(); 76 usb_log_warning("Requested %zu bytes, current allocator can't handle " 77 "that amount, pray that the standard malloc will suffice.", size); 76 assert(false); 78 77 return memalign(UHCI_STRCUTURES_ALIGNMENT, size); 79 78 } -
uspace/drv/uhci-rhd/port.c
r293de44 r160b75e 227 227 while (uhci_port_read_status(port) & STATUS_IN_RESET); 228 228 } 229 /* PIO delay, should not be longer than 3ms as the device might230 * enter suspend state. */231 229 udelay(10); 232 230 /* Enable the port. */ 233 231 uhci_port_set_enabled(port, true); 232 233 /* Reset recovery period, 234 * devices do not have to respond during this period 235 */ 236 async_usleep(10000); 234 237 return EOK; 235 238 } -
uspace/drv/usbhid/Makefile
r293de44 r160b75e 57 57 generic/hiddev.c \ 58 58 mouse/mousedev.c \ 59 multimedia/multimedia.c \60 multimedia/keymap.c \59 lgtch-ultrax/lgtch-ultrax.c \ 60 lgtch-ultrax/keymap.c \ 61 61 $(STOLEN_LAYOUT_SOURCES) 62 62 -
uspace/drv/usbhid/generic/hiddev.c
r293de44 r160b75e 162 162 /*----------------------------------------------------------------------------*/ 163 163 164 int usb_generic_hid_init(usb_hid_dev_t *hid_dev , void **data)164 int usb_generic_hid_init(usb_hid_dev_t *hid_dev) 165 165 { 166 166 if (hid_dev == NULL) { … … 173 173 /*----------------------------------------------------------------------------*/ 174 174 175 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data,175 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, 176 176 uint8_t *buffer, size_t buffer_size) 177 177 { -
uspace/drv/usbhid/generic/hiddev.h
r293de44 r160b75e 48 48 /*----------------------------------------------------------------------------*/ 49 49 50 int usb_generic_hid_init(struct usb_hid_dev *hid_dev , void **data);50 int usb_generic_hid_init(struct usb_hid_dev *hid_dev); 51 51 52 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data,52 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, 53 53 uint8_t *buffer, size_t buffer_size); 54 54 -
uspace/drv/usbhid/kbd/kbddev.c
r293de44 r160b75e 252 252 sysarg_t method = IPC_GET_IMETHOD(*icall); 253 253 254 usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data; 255 if (kbd_dev == NULL) { 254 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 255 256 if (hid_dev == NULL || hid_dev->data == NULL) { 256 257 usb_log_debug("default_connection_handler: " 257 258 "Missing parameter.\n"); … … 259 260 return; 260 261 } 262 263 assert(hid_dev != NULL); 264 assert(hid_dev->data != NULL); 265 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 261 266 262 267 if (method == IPC_M_CONNECT_TO_ME) { … … 308 313 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 309 314 hid_dev->report, NULL, kbd_dev->led_path, 310 USB_HID_PATH_COMPARE_ END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,315 USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY | USB_HID_PATH_COMPARE_END, 311 316 USB_HID_REPORT_TYPE_OUTPUT); 312 317 313 while (field != NULL) { 314 318 while (field != NULL) { 319 315 320 if ((field->usage == USB_HID_LED_NUM_LOCK) 316 321 && (kbd_dev->mods & KM_NUM_LOCK)){ … … 329 334 330 335 field = usb_hid_report_get_sibling(hid_dev->report, field, 331 kbd_dev->led_path, 332 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 333 USB_HID_REPORT_TYPE_OUTPUT); 336 kbd_dev->led_path, USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 337 | USB_HID_PATH_COMPARE_END, USB_HID_REPORT_TYPE_OUTPUT); 334 338 } 335 339 … … 658 662 * usb_hid_parse_report(). 659 663 */ 660 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev,664 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, 661 665 uint8_t *buffer, size_t actual_size) 662 666 { 663 667 assert(hid_dev->report != NULL); 664 668 assert(hid_dev != NULL); 665 assert(kbd_dev != NULL); 669 assert(hid_dev->data != NULL); 670 671 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 666 672 667 673 usb_log_debug("Calling usb_hid_parse_report() with " … … 768 774 /*----------------------------------------------------------------------------*/ 769 775 770 static int usb_kbd_create_function(usb_hid_dev_t *hid_dev , usb_kbd_t *kbd_dev)776 static int usb_kbd_create_function(usb_hid_dev_t *hid_dev) 771 777 { 772 778 assert(hid_dev != NULL); 773 779 assert(hid_dev->usb_dev != NULL); 774 assert(kbd_dev != NULL);775 780 776 781 /* Create the function exposed under /dev/devices. */ … … 787 792 * to the DDF function. 788 793 */ 789 fun->ops = & kbd_dev->ops;790 fun->driver_data = kbd_dev;794 fun->ops = &hid_dev->ops; 795 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 791 796 792 797 int rc = ddf_fun_bind(fun); … … 835 840 * @return Other value inherited from function usbhid_dev_init(). 836 841 */ 837 int usb_kbd_init(usb_hid_dev_t *hid_dev , void **data)842 int usb_kbd_init(usb_hid_dev_t *hid_dev) 838 843 { 839 844 usb_log_debug("Initializing HID/KBD structure...\n"); … … 860 865 usb_hid_report_path_set_report_id(path, 0); 861 866 862 kbd_dev->key_count = usb_hid_report_size( 863 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 867 kbd_dev->key_count = usb_hid_report_input_length( 868 hid_dev->report, path, 869 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 864 870 usb_hid_report_path_free(path); 865 871 … … 902 908 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 903 909 904 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 905 0, USB_HID_REPORT_TYPE_OUTPUT); 910 kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev->report, 911 kbd_dev->led_path, 912 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 906 913 907 914 usb_log_debug("Output report size (in items): %zu\n", … … 948 955 949 956 // save the KBD device structure into the HID device structure 950 //hid_dev->data = kbd_dev; 951 *data = kbd_dev; 957 hid_dev->data = kbd_dev; 952 958 953 959 // set handler for incoming calls 954 kbd_dev->ops.default_handler = default_connection_handler;960 hid_dev->ops.default_handler = default_connection_handler; 955 961 956 962 /* … … 977 983 978 984 usb_log_debug("Creating KBD function...\n"); 979 int rc = usb_kbd_create_function(hid_dev , kbd_dev);985 int rc = usb_kbd_create_function(hid_dev); 980 986 if (rc != EOK) { 981 987 usb_kbd_free(&kbd_dev); … … 988 994 /*----------------------------------------------------------------------------*/ 989 995 990 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data,991 uint8_t *buffer,size_t buffer_size)992 { 993 if (hid_dev == NULL || buffer == NULL || data == NULL) {996 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer, 997 size_t buffer_size) 998 { 999 if (hid_dev == NULL || buffer == NULL) { 994 1000 // do not continue polling (???) 995 1001 return false; 996 1002 } 997 1003 998 usb_kbd_t *kbd_dev = (usb_kbd_t *)data;999 assert(kbd_dev != NULL);1000 1001 1004 // TODO: add return value from this function 1002 usb_kbd_process_data(hid_dev, kbd_dev,buffer, buffer_size);1005 usb_kbd_process_data(hid_dev, buffer, buffer_size); 1003 1006 1004 1007 return true; … … 1063 1066 /*----------------------------------------------------------------------------*/ 1064 1067 1065 void usb_kbd_deinit(usb_hid_dev_t *hid_dev , void *data)1068 void usb_kbd_deinit(usb_hid_dev_t *hid_dev) 1066 1069 { 1067 1070 if (hid_dev == NULL) { … … 1069 1072 } 1070 1073 1071 if ( data != NULL) {1072 usb_kbd_t *kbd_dev = (usb_kbd_t *) data;1074 if (hid_dev->data != NULL) { 1075 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 1073 1076 if (usb_kbd_is_initialized(kbd_dev)) { 1074 1077 usb_kbd_mark_unusable(kbd_dev); 1075 1078 } else { 1076 1079 usb_kbd_free(&kbd_dev); 1080 hid_dev->data = NULL; 1077 1081 } 1078 1082 } -
uspace/drv/usbhid/kbd/kbddev.h
r293de44 r160b75e 83 83 int console_phone; 84 84 85 /** @todo What is this actually? */86 ddf_dev_ops_t ops;87 88 85 /** Information for auto-repeat of keys. */ 89 86 usb_kbd_repeat_t repeat; … … 120 117 /*----------------------------------------------------------------------------*/ 121 118 122 int usb_kbd_init(struct usb_hid_dev *hid_dev , void **data);119 int usb_kbd_init(struct usb_hid_dev *hid_dev); 123 120 124 bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, void *data,125 uint8_t *buffer,size_t buffer_size);121 bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer, 122 size_t buffer_size); 126 123 127 124 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev); … … 134 131 int type, unsigned int key); 135 132 136 void usb_kbd_deinit(struct usb_hid_dev *hid_dev , void *data);133 void usb_kbd_deinit(struct usb_hid_dev *hid_dev); 137 134 138 135 int usb_kbd_set_boot_protocol(struct usb_hid_dev *hid_dev); -
uspace/drv/usbhid/mouse/mousedev.c
r293de44 r160b75e 122 122 sysarg_t method = IPC_GET_IMETHOD(*icall); 123 123 124 usb_ mouse_t *mouse_dev = (usb_mouse_t *)fun->driver_data;125 126 if ( mouse_dev== NULL) {124 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 125 126 if (hid_dev == NULL || hid_dev->data == NULL) { 127 127 usb_log_debug("default_connection_handler: Missing " 128 128 "parameters.\n"); … … 131 131 } 132 132 133 usb_log_debug("default_connection_handler: fun->name: %s\n", 134 fun->name); 135 usb_log_debug("default_connection_handler: mouse_phone: %d, wheel " 136 "phone: %d\n", mouse_dev->mouse_phone, mouse_dev->wheel_phone); 133 assert(hid_dev != NULL); 134 assert(hid_dev->data != NULL); 135 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; 137 136 138 137 int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) … … 146 145 "phone to mouse already set.\n"); 147 146 async_answer_0(icallid, ELIMIT); 147 //async_answer_0(icallid, EOK); 148 148 return; 149 149 } 150 150 151 151 *phone = callback; 152 usb_log_debug("Console phone to mouse set ok (%d).\n", *phone);152 usb_log_debug("Console phone to mouse set ok (%d).\n", callback); 153 153 async_answer_0(icallid, EOK); 154 154 return; … … 224 224 /*----------------------------------------------------------------------------*/ 225 225 226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 227 usb_mouse_t *mouse_dev, uint8_t *buffer, 228 size_t buffer_size) 229 { 230 assert(mouse_dev != NULL); 226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer, 227 size_t buffer_size) 228 { 229 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; 231 230 232 231 usb_log_debug2("got buffer: %s.\n", … … 379 378 /*----------------------------------------------------------------------------*/ 380 379 381 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse) 382 { 383 assert(hid_dev != NULL); 384 assert(mouse != NULL); 385 380 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev) 381 { 386 382 /* Create the function exposed under /dev/devices. */ 387 383 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 393 389 } 394 390 395 fun->ops = &mouse->ops; 396 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data 391 /* 392 * Store the initialized HID device and HID ops 393 * to the DDF function. 394 */ 395 fun->ops = &hid_dev->ops; 396 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 397 397 398 398 int rc = ddf_fun_bind(fun); … … 431 431 * to the DDF function. 432 432 */ 433 fun->ops = & mouse->ops;434 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data433 fun->ops = &hid_dev->ops; 434 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 435 435 436 436 rc = ddf_fun_bind(fun); … … 458 458 /*----------------------------------------------------------------------------*/ 459 459 460 int usb_mouse_init(usb_hid_dev_t *hid_dev , void **data)460 int usb_mouse_init(usb_hid_dev_t *hid_dev) 461 461 { 462 462 usb_log_debug("Initializing HID/Mouse structure...\n"); … … 485 485 486 486 // save the Mouse device structure into the HID device structure 487 *data = mouse_dev;487 hid_dev->data = mouse_dev; 488 488 489 489 // set handler for incoming calls 490 // TODO: must be one for each subdriver!! 491 mouse_dev->ops.default_handler = default_connection_handler; 490 hid_dev->ops.default_handler = default_connection_handler; 492 491 493 492 // TODO: how to know if the device supports the request??? … … 495 494 // hid_dev->usb_dev->interface_no, IDLE_RATE); 496 495 497 int rc = usb_mouse_create_function(hid_dev , mouse_dev);496 int rc = usb_mouse_create_function(hid_dev); 498 497 if (rc != EOK) { 499 498 usb_mouse_free(&mouse_dev); … … 506 505 /*----------------------------------------------------------------------------*/ 507 506 508 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data,509 uint8_t *buffer,size_t buffer_size)507 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer, 508 size_t buffer_size) 510 509 { 511 510 usb_log_debug("usb_mouse_polling_callback()\n"); 512 511 usb_debug_str_buffer(buffer, buffer_size, 0); 513 512 514 if (hid_dev == NULL || data == NULL) {513 if (hid_dev == NULL) { 515 514 usb_log_error("Missing argument to the mouse polling callback." 516 515 "\n"); … … 518 517 } 519 518 520 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 521 522 return usb_mouse_process_report(hid_dev, mouse_dev, buffer, 523 buffer_size); 524 } 525 526 /*----------------------------------------------------------------------------*/ 527 528 void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data) 529 { 530 if (data != NULL) { 531 usb_mouse_free((usb_mouse_t **)&data); 532 } 519 if (hid_dev->data == NULL) { 520 usb_log_error("Wrong argument to the mouse polling callback." 521 "\n"); 522 return false; 523 } 524 525 return usb_mouse_process_report(hid_dev, buffer, buffer_size); 526 } 527 528 /*----------------------------------------------------------------------------*/ 529 530 void usb_mouse_deinit(usb_hid_dev_t *hid_dev) 531 { 532 usb_mouse_free((usb_mouse_t **)&hid_dev->data); 533 533 } 534 534 -
uspace/drv/usbhid/mouse/mousedev.h
r293de44 r160b75e 52 52 53 53 int32_t *buttons; 54 55 ddf_dev_ops_t ops;56 54 } usb_mouse_t; 57 55 … … 65 63 /*----------------------------------------------------------------------------*/ 66 64 67 int usb_mouse_init(struct usb_hid_dev *hid_dev , void **data);65 int usb_mouse_init(struct usb_hid_dev *hid_dev); 68 66 69 bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, void *data,70 uint8_t *buffer,size_t buffer_size);67 bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer, 68 size_t buffer_size); 71 69 72 void usb_mouse_deinit(struct usb_hid_dev *hid_dev , void *data);70 void usb_mouse_deinit(struct usb_hid_dev *hid_dev); 73 71 74 72 int usb_mouse_set_boot_protocol(struct usb_hid_dev *hid_dev); -
uspace/drv/usbhid/subdrivers.c
r293de44 r160b75e 38 38 #include <usb/hid/hidpath.h> 39 39 40 //#include "lgtch-ultrax/lgtch-ultrax.h" 41 #include "multimedia/multimedia.h" 40 #include "lgtch-ultrax/lgtch-ultrax.h" 42 41 #include "mouse/mousedev.h" 43 42 44 43 static usb_hid_subdriver_usage_t path_kbd[] = { 45 {USB_HIDUT_PAGE_GENERIC_DESKTOP, 46 USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 44 {USB_HIDUT_PAGE_KEYBOARD, 0}, 47 45 {0, 0} 48 46 }; 49 47 50 static usb_hid_subdriver_usage_t path_mouse [] = {51 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_ MOUSE},48 static usb_hid_subdriver_usage_t path_mouse2[] = { 49 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_X}, 52 50 {0, 0} 53 51 }; 54 52 55 static usb_hid_subdriver_usage_t multim_key_path[] = {56 { USB_HIDUT_PAGE_CONSUMER, USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL},53 static usb_hid_subdriver_usage_t lgtch_path[] = { 54 {0xc, 0}, 57 55 {0, 0} 58 56 }; … … 62 60 path_kbd, 63 61 -1, 64 USB_HID_PATH_COMPARE_BEGIN, 62 USB_HID_PATH_COMPARE_END 63 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 65 64 -1, 66 65 -1, … … 74 73 }, 75 74 { 76 multim_key_path,75 lgtch_path, 77 76 1, 78 USB_HID_PATH_COMPARE_BEGIN, 79 -1, 80 -1, 77 USB_HID_PATH_COMPARE_END 78 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 79 0x046d, 80 0xc30e, 81 81 { 82 .init = usb_ multimedia_init,83 .deinit = usb_ multimedia_deinit,84 .poll = usb_ multimedia_polling_callback,82 .init = usb_lgtch_init, 83 .deinit = usb_lgtch_deinit, 84 .poll = usb_lgtch_polling_callback, 85 85 .poll_end = NULL 86 86 } 87 87 }, 88 88 { 89 path_mouse ,89 path_mouse2, 90 90 -1, 91 USB_HID_PATH_COMPARE_BEGIN, 91 USB_HID_PATH_COMPARE_END 92 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 92 93 -1, 93 94 -1, … … 99 100 } 100 101 }, 101 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL , NULL}}102 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL}} 102 103 }; 103 104 -
uspace/drv/usbhid/usbhid.c
r293de44 r160b75e 203 203 204 204 usb_log_debug("Compare flags: %d\n", mapping->compare); 205 // size_t size = usb_hid_report_size(hid_dev->report, 0, 206 // USB_HID_REPORT_TYPE_INPUT); 207 size_t size = 0; 208 usb_hid_report_field_t *field = usb_hid_report_get_sibling (hid_dev->report, 209 NULL, usage_path, mapping->compare, USB_HID_REPORT_TYPE_INPUT); 210 while(field != NULL) { 211 size++; 212 field = usb_hid_report_get_sibling (hid_dev->report, 213 field, usage_path, mapping->compare, 214 USB_HID_REPORT_TYPE_INPUT); 215 } 216 205 size_t size = usb_hid_report_input_length(hid_dev->report, usage_path, 206 mapping->compare); 217 207 usb_log_debug("Size of the input report: %zuB\n", size); 208 218 209 usb_hid_report_path_free(usage_path); 219 210 … … 466 457 if (hid_dev->subdrivers[i].init != NULL) { 467 458 usb_log_debug("Initializing subdriver %d.\n",i); 468 rc = hid_dev->subdrivers[i].init(hid_dev, 469 &hid_dev->subdrivers[i].data); 459 rc = hid_dev->subdrivers[i].init(hid_dev); 470 460 if (rc != EOK) { 471 461 usb_log_warning("Failed to initialize" … … 532 522 for (i = 0; i < hid_dev->subdriver_count; ++i) { 533 523 if (hid_dev->subdrivers[i].poll != NULL 534 && hid_dev->subdrivers[i].poll(hid_dev, 535 hid_dev->subdrivers[i].data, buffer,buffer_size)) {524 && hid_dev->subdrivers[i].poll(hid_dev, buffer, 525 buffer_size)) { 536 526 cont = true; 537 527 } … … 556 546 for (i = 0; i < hid_dev->subdriver_count; ++i) { 557 547 if (hid_dev->subdrivers[i].poll_end != NULL) { 558 hid_dev->subdrivers[i].poll_end(hid_dev, 559 hid_dev->subdrivers[i].data, reason); 548 hid_dev->subdrivers[i].poll_end(hid_dev, reason); 560 549 } 561 550 } … … 638 627 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) { 639 628 if ((*hid_dev)->subdrivers[i].deinit != NULL) { 640 (*hid_dev)->subdrivers[i].deinit(*hid_dev, 641 (*hid_dev)->subdrivers[i].data); 629 (*hid_dev)->subdrivers[i].deinit(*hid_dev); 642 630 } 643 631 } -
uspace/drv/usbhid/usbhid.h
r293de44 r160b75e 48 48 struct usb_hid_dev; 49 49 50 typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *, void **data); 51 typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *, void *data); 52 typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, void *data, uint8_t *, 53 size_t); 54 typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, void *data, 55 bool reason); 50 typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *); 51 typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *); 52 typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, uint8_t *, size_t); 53 typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, bool reason); 56 54 57 55 // TODO: add function and class name?? … … 65 63 /** Function to be called when polling ends. */ 66 64 usb_hid_driver_poll_ended poll_end; 67 /** Arbitrary data needed by the subdriver. */68 void *data;69 65 } usb_hid_subdriver_t; 70 66 … … 76 72 /** Structure holding generic USB device information. */ 77 73 usb_device_t *usb_dev; 74 75 /** @todo What is this actually? */ 76 ddf_dev_ops_t ops; 78 77 79 78 /** Index of the polling pipe in usb_hid_endpoints array. */ … … 98 97 99 98 size_t input_report_size; 99 100 /** Arbitrary data (e.g. a special structure for handling keyboard). */ 101 void *data; 100 102 } usb_hid_dev_t; 101 103 -
uspace/lib/usbdev/src/hub.c
r293de44 r160b75e 41 41 #include <assert.h> 42 42 #include <usb/debug.h> 43 #include <time.h>44 43 45 44 /** How much time to wait between attempts to register endpoint 0:0. … … 219 218 220 219 int rc; 221 struct timeval start_time;222 223 rc = gettimeofday(&start_time, NULL);224 if (rc != EOK) {225 return rc;226 }227 220 228 221 rc = usb_hc_connection_open(&hc_conn); … … 271 264 } 272 265 } while (rc != EOK); 273 struct timeval end_time;274 275 rc = gettimeofday(&end_time, NULL);276 if (rc != EOK) {277 goto leave_release_default_address;278 }279 280 /* According to the USB spec part 9.1.2 host allows 100ms time for281 * the insertion process to complete. According to 7.1.7.1 this is the282 * time between attach detected and port reset. However, the setup done283 * above might use much of this time so we should only wait to fill284 * up the 100ms quota*/285 suseconds_t elapsed = tv_sub(&end_time, &start_time);286 if (elapsed < 100000) {287 async_usleep(100000 - elapsed);288 }289 266 290 267 /* … … 296 273 goto leave_release_default_address; 297 274 } 298 /* USB spec 7.1.7.1: The USB System Software guarantees a minimum of299 * 10ms for reset recovery. Device response to any bus transactions300 * addressed to the default device address during the reset recovery301 * time is undefined.302 */303 async_usleep(10000);304 275 305 276 rc = usb_pipe_probe_default_control(&ctrl_pipe); -
uspace/lib/usbhid/include/usb/hid/hid_report_items.h
r293de44 r160b75e 46 46 #define USB_HID_ITEM_IS_LONG(data) (data == 0xFE) 47 47 48 49 /**50 * Extended usage macros51 */52 #define USB_HID_IS_EXTENDED_USAGE(usage) ((usage & 0xFFFF0000) != 0)53 #define USB_HID_EXTENDED_USAGE_PAGE(usage) ((usage & 0xFFFF0000) >> 16)54 #define USB_HID_EXTENDED_USAGE(usage) (usage & 0xFFFF)55 48 56 49 /** -
uspace/lib/usbhid/include/usb/hid/hidparser.h
r293de44 r160b75e 51 51 size_t size, uint8_t *report_id); 52 52 53 /** */ 54 size_t usb_hid_report_input_length(const usb_hid_report_t *report, 55 usb_hid_report_path_t *path, int flags); 56 53 57 /* 54 58 * Output report parser functions … … 61 65 void usb_hid_report_output_free(uint8_t *output); 62 66 63 /** Returns size of report in items*/64 size_t usb_hid_report_ size(usb_hid_report_t *report, uint8_t report_id,65 usb_hid_report_type_t type);67 /** Returns size of output for given usage path */ 68 size_t usb_hid_report_output_size(usb_hid_report_t *report, 69 usb_hid_report_path_t *path, int flags); 66 70 67 71 /** Makes the output report buffer by translated given data */ -
uspace/lib/usbhid/include/usb/hid/hidtypes.h
r293de44 r160b75e 39 39 #include <adt/list.h> 40 40 41 #define USB_HID_MAX_USAGES 0xffff41 #define USB_HID_MAX_USAGES 20 42 42 43 43 #define USB_HID_UINT32_TO_INT32(x, size) ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1))) … … 92 92 int32_t physical_minimum; 93 93 int32_t physical_maximum; 94 int32_t usage_minimum;95 int32_t usage_maximum;94 uint32_t usage_minimum; 95 uint32_t usage_maximum; 96 96 uint32_t unit; 97 97 uint32_t unit_exponent; 98 99 uint32_t *usages; 100 size_t usages_count; 98 101 99 102 100 int32_t value; … … 123 121 124 122 /** */ 125 int32_t usage_minimum;126 /** */ 127 int32_t usage_maximum;123 uint32_t usage_minimum; 124 /** */ 125 uint32_t usage_maximum; 128 126 /** */ 129 127 int32_t logical_minimum; -
uspace/lib/usbhid/include/usb/hid/usages/core.h
r293de44 r160b75e 67 67 } usb_hidut_usage_generic_desktop_t; 68 68 69 typedef enum {70 USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL = 171 } usb_hidut_usage_consumer_t;72 73 69 74 70 #endif -
uspace/lib/usbhid/src/hiddescriptor.c
r293de44 r160b75e 64 64 { 65 65 /* find or append current collection path to the list */ 66 //link_t *path_it = report->collection_paths.next; 67 link_t *path_it = report->collection_paths.prev->next; 66 link_t *path_it = report->collection_paths.next; 68 67 usb_hid_report_path_t *path = NULL; 69 70 71 68 while(path_it != &report->collection_paths) { 72 69 path = list_get_instance(path_it, usb_hid_report_path_t, link); … … 119 116 int i; 120 117 121 uint32_t *usages; 122 int usages_used=0; 123 if(report_item->usages_count > 0){ 124 usages = malloc(sizeof(int32_t) * report_item->usages_count); 125 memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count); 126 } 127 else { 128 usages = NULL; 129 } 130 118 for(i=0; i<report_item->usages_count; i++){ 119 usb_log_debug("usages (%d) - %x\n", i, report_item->usages[i]); 120 } 121 131 122 usb_hid_report_path_t *path = report_item->usage_path; 132 123 for(i=0; i<report_item->count; i++){ … … 142 133 field->physical_maximum = report_item->physical_maximum; 143 134 144 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){ 145 /* 146 Store usage array. The Correct Usage Page and Usage is depending 147 on data in report and will be filled later 148 */ 149 field->usage = 0; 150 field->usage_page = 0; //report_item->usage_page; 151 152 field->usages_count = report_item->usages_count; 153 field->usages = usages; 154 usages_used = 1; 135 field->usage_minimum = report_item->usage_minimum; 136 field->usage_maximum = report_item->usage_maximum; 137 if(report_item->extended_usage_page != 0){ 138 field->usage_page = report_item->extended_usage_page; 155 139 } 156 140 else { 157 158 /* Fill the correct Usage and Usage Page */ 159 int32_t usage; 160 if(i < report_item->usages_count) { 141 field->usage_page = report_item->usage_page; 142 } 143 144 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 145 uint32_t usage; 146 if(i < report_item->usages_count){ 161 147 usage = report_item->usages[i]; 162 148 } … … 165 151 } 166 152 167 if(USB_HID_IS_EXTENDED_USAGE(usage)){ 168 field->usage = USB_HID_EXTENDED_USAGE(usage); 169 field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage); 153 154 if((usage & 0xFFFF0000) != 0){ 155 field->usage_page = (usage >> 16); 156 field->usage = (usage & 0xFFFF); 170 157 } 171 158 else { 172 // should not occur173 159 field->usage = usage; 174 field->usage_page = report_item->usage_page; 175 } 160 } 161 162 163 } 164 165 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) { 166 field->usage = report_item->usage_minimum + i; 176 167 } 177 168 … … 218 209 } 219 210 220 // free only when not used!!!221 if(usages && usages_used == 0) {222 free(usages);223 }224 211 225 212 return EOK; … … 463 450 464 451 case USB_HID_REPORT_TAG_COLLECTION: 465 466 452 // store collection atributes 467 453 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); … … 469 455 470 456 // set last item 471 usb_hid_report_set_last_item(usage_path, 472 USB_HID_TAG_CLASS_GLOBAL, 473 USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1])); 474 usb_hid_report_set_last_item(usage_path, 475 USB_HID_TAG_CLASS_LOCAL, 476 USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1])); 457 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page); 458 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]); 477 459 478 460 // append the new one which will be set by common … … 569 551 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 570 552 { 571 int32_t extended_usage;572 573 553 switch(tag) { 574 554 case USB_HID_REPORT_TAG_USAGE: … … 580 560 report_item->in_delimiter = INSIDE_DELIMITER_SET; 581 561 case OUTSIDE_DELIMITER_SET: 582 extended_usage = ((report_item->usage_page) << 16); 583 extended_usage += usb_hid_report_tag_data_uint32(data,item_size); 584 report_item->usages[report_item->usages_count] = extended_usage; 562 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 585 563 report_item->usages_count++; 586 564 break; 587 565 } 588 566 break; 589 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 567 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 590 568 if (item_size == 3) { 591 569 // usage extended usages … … 599 577 case USB_HID_REPORT_TAG_USAGE_MAXIMUM: 600 578 if (item_size == 3) { 601 602 if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) {603 return EINVAL;604 }605 606 579 // usage extended usages 607 580 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; … … 611 584 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size); 612 585 } 613 614 // vlozit zaznamy do pole usages615 int32_t i;616 for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) {617 if(report_item->extended_usage_page) {618 report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i;619 }620 else {621 622 report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i;623 }624 }625 report_item->extended_usage_page = 0;626 627 586 break; 628 587 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: … … 704 663 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum); 705 664 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum); 706 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);707 665 708 666 usb_log_debug("\t\tVALUE: %X\n", report_item->value); … … 710 668 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page); 711 669 712 usb_hid_print_usage_path(report_item->collection_path);670 //usb_hid_print_usage_path(report_item->collection_path); 713 671 714 672 usb_log_debug("\n"); … … 742 700 usb_hid_descriptor_print_list(&report_des->report_items); 743 701 744 /* 702 745 703 link_t *path_it = report->collection_paths.next; 746 704 while(path_it != &report->collection_paths) { … … 748 706 path_it = path_it->next; 749 707 } 750 */708 751 709 report_it = report_it->next; 752 710 } -
uspace/lib/usbhid/src/hidparser.c
r293de44 r160b75e 69 69 70 70 71 /** Returns size of report of specified report id and type in items72 *73 * @param parser Opaque report parser structure74 * @param report_id75 * @param type76 * @return Number of items in specified report77 */78 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,79 usb_hid_report_type_t type)80 {81 usb_hid_report_description_t *report_des;82 83 if(report == NULL) {84 return 0;85 }86 87 report_des = usb_hid_report_find_description (report, report_id, type);88 if(report_des == NULL){89 return 0;90 }91 else {92 return report_des->item_length;93 }94 }95 71 96 72 … … 111 87 usb_hid_report_description_t *report_des; 112 88 usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT; 113 89 114 90 if(report == NULL) { 115 91 return EINVAL; … … 138 114 // array 139 115 item->value = usb_hid_translate_data(item, data); 140 141 item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]); 142 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]); 143 144 usb_hid_report_set_last_item (item->collection_path, 145 USB_HID_TAG_CLASS_GLOBAL, 146 item->usage_page); 147 usb_hid_report_set_last_item (item->collection_path, 148 USB_HID_TAG_CLASS_LOCAL, 149 item->usage); 150 116 item->usage = (item->value - item->physical_minimum) + item->usage_minimum; 151 117 } 152 118 else { … … 157 123 list_item = list_item->next; 158 124 } 159 125 160 126 return EOK; 161 127 … … 240 206 } 241 207 208 /** 209 * Returns number of items in input report which are accessible by given usage path 210 * 211 * @param parser Opaque report descriptor structure 212 * @param path Usage path specification 213 * @param flags Usage path comparison flags 214 * @return Number of items in input report 215 */ 216 size_t usb_hid_report_input_length(const usb_hid_report_t *report, 217 usb_hid_report_path_t *path, int flags) 218 { 219 220 size_t ret = 0; 221 222 if(report == NULL) { 223 return 0; 224 } 225 226 usb_hid_report_description_t *report_des; 227 report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_INPUT); 228 if(report_des == NULL) { 229 return 0; 230 } 231 232 link_t *field_it = report_des->report_items.next; 233 usb_hid_report_field_t *field; 234 while(field_it != &report_des->report_items) { 235 236 field = list_get_instance(field_it, usb_hid_report_field_t, link); 237 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) { 238 239 usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage); 240 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) { 241 ret++; 242 } 243 usb_hid_report_remove_last_item (field->collection_path); 244 } 245 246 field_it = field_it->next; 247 } 248 249 return ret; 250 } 251 242 252 /*** OUTPUT API **/ 243 253 … … 294 304 } 295 305 306 /** Returns size of output for given usage path 307 * 308 * @param parser Opaque report parser structure 309 * @param path Usage path specified which items will be thought for the output 310 * @param flags Flags of usage path structure comparison 311 * @return Number of items matching the given usage path 312 */ 313 size_t usb_hid_report_output_size(usb_hid_report_t *report, 314 usb_hid_report_path_t *path, int flags) 315 { 316 size_t ret = 0; 317 usb_hid_report_description_t *report_des; 318 319 if(report == NULL) { 320 return 0; 321 } 322 323 report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_OUTPUT); 324 if(report_des == NULL){ 325 return 0; 326 } 327 328 link_t *field_it = report_des->report_items.next; 329 usb_hid_report_field_t *field; 330 while(field_it != &report_des->report_items) { 331 332 field = list_get_instance(field_it, usb_hid_report_field_t, link); 333 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0){ 334 usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage); 335 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) { 336 ret++; 337 } 338 usb_hid_report_remove_last_item (field->collection_path); 339 } 340 341 field_it = field_it->next; 342 } 343 344 return ret; 345 346 } 347 296 348 /** Makes the output report buffer for data given in the report structure 297 349 * … … 333 385 report_item = list_get_instance(item, usb_hid_report_field_t, link); 334 386 335 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value); 336 337 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 387 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 338 388 339 // array340 value = usb_hid_translate_data_reverse(report_item, report_item->value);341 offset = report_item->offset;342 length = report_item->size;343 }344 else {345 // variable item346 value = usb_hid_translate_data_reverse(report_item, report_item->value);347 offset = report_item->offset;348 length = report_item->size;349 }350 351 usb_log_debug("\ttranslated value: %x\n", value);352 353 if((offset/8) == ((offset+length-1)/8)) {354 // je to v jednom bytu355 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {356 break; // TODO ErrorCode 357 }358 size_t shift = 8 - offset%8 - length; 359 value = value << shift;360 value = value & (((1 << length)-1) << shift);389 // array 390 value = usb_hid_translate_data_reverse(report_item, report_item->value); 391 offset = report_item->offset; 392 length = report_item->size; 393 } 394 else { 395 // variable item 396 value = usb_hid_translate_data_reverse(report_item, report_item->value); 397 offset = report_item->offset; 398 length = report_item->size; 399 } 400 401 if((offset/8) == ((offset+length-1)/8)) { 402 // je to v jednom bytu 403 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 404 break; // TODO ErrorCode 405 } 406 407 size_t shift = 8 - offset%8 - length; 408 409 value = value << shift; 410 value = value & (((1 << length)-1) << shift); 361 411 362 uint8_t mask = 0; 363 mask = 0xff - (((1 << length) - 1) << shift); 364 buffer[offset/8] = (buffer[offset/8] & mask) | value; 365 } 366 else { 367 int i = 0; 368 uint8_t mask = 0; 369 for(i = (offset/8); i <= ((offset+length-1)/8); i++) { 370 if(i == (offset/8)) { 371 tmp_value = value; 372 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 373 tmp_value = tmp_value << (offset%8); 374 375 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 376 buffer[i] = (buffer[i] & mask) | tmp_value; 412 uint8_t mask = 0; 413 mask = 0xff - (((1 << length) - 1) << shift); 414 buffer[offset/8] = (buffer[offset/8] & mask) | value; 415 } 416 else { 417 int i = 0; 418 uint8_t mask = 0; 419 for(i = (offset/8); i <= ((offset+length-1)/8); i++) { 420 if(i == (offset/8)) { 421 tmp_value = value; 422 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 423 tmp_value = tmp_value << (offset%8); 424 425 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 426 buffer[i] = (buffer[i] & mask) | tmp_value; 427 } 428 else if (i == ((offset + length -1)/8)) { 429 430 value = value >> (length - ((offset + length) % 8)); 431 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 432 433 mask = (1 << (length - ((offset + length) % 8))) - 1; 434 buffer[i] = (buffer[i] & mask) | value; 435 } 436 else { 437 buffer[i] = value & (0xFF << i); 438 } 377 439 } 378 else if (i == ((offset + length -1)/8)) { 379 380 value = value >> (length - ((offset + length) % 8)); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 382 383 mask = (1 << (length - ((offset + length) % 8))) - 1; 384 buffer[i] = (buffer[i] & mask) | value; 385 } 386 else { 387 buffer[i] = value & (0xFF << i); 388 } 389 } 390 } 440 } 441 391 442 392 443 // reset value … … 421 472 } 422 473 423 // variable item 424 if(item->physical_maximum == item->physical_minimum){ 425 resolution = 1; 474 475 if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) { 476 477 // variable item 478 if(item->physical_maximum == item->physical_minimum){ 479 resolution = 1; 480 } 481 else { 482 resolution = (item->logical_maximum - item->logical_minimum) / 483 ((item->physical_maximum - item->physical_minimum) * 484 (usb_pow(10,(item->unit_exponent)))); 485 } 486 487 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 426 488 } 427 489 else { 428 resolution = (item->logical_maximum - item->logical_minimum) / 429 ((item->physical_maximum - item->physical_minimum) * 430 (usb_pow(10,(item->unit_exponent)))); 431 } 432 433 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 434 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret); 435 490 // bitmapa 491 if(value == 0) { 492 ret = 0; 493 } 494 else { 495 size_t bitmap_idx = (value - item->usage_minimum); 496 ret = 1 << bitmap_idx; 497 } 498 } 499 436 500 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ 437 501 return USB_HID_INT32_TO_UINT32(ret, item->size); 438 502 } 439 return (int32_t) 0 +ret;503 return (int32_t)ret; 440 504 } 441 505 -
uspace/lib/usbhid/src/hidpath.c
r293de44 r160b75e 42 42 43 43 44 #define USB_HID_SAME_USAGE(usage1, usage2) ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0))45 #define USB_HID_SAME_USAGE_PAGE(page1, page2) ((page1 == page2) || (page1 == 0) || (page2 == 0))46 47 44 /** 48 45 * Appends one item (couple of usage_path and usage) into the usage path … … 206 203 while(report_link != &report_path->head) { 207 204 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 208 if( USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){205 if(report_item->usage_page == path_item->usage_page){ 209 206 if(only_page == 0){ 210 if( USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) {207 if(report_item->usage == path_item->usage) { 211 208 return EOK; 212 209 } … … 245 242 link); 246 243 247 if( !USB_HID_SAME_USAGE_PAGE(report_item->usage_page,path_item->usage_page) ||244 if((report_item->usage_page != path_item->usage_page) || 248 245 ((only_page == 0) && 249 !USB_HID_SAME_USAGE(report_item->usage,path_item->usage))) {246 (report_item->usage != path_item->usage))) { 250 247 251 248 return 1; … … 285 282 usb_hid_report_usage_path_t, 286 283 link); 287 288 if( !USB_HID_SAME_USAGE_PAGE(report_item->usage_page,path_item->usage_page) ||284 285 if((report_item->usage_page != path_item->usage_page) || 289 286 ((only_page == 0) && 290 !USB_HID_SAME_USAGE(report_item->usage,path_item->usage))) {291 287 (report_item->usage != path_item->usage))) { 288 return 1; 292 289 } else { 293 290 report_link = report_link->prev; -
uspace/lib/usbhost/src/device_keeper.c
r293de44 r160b75e 158 158 } 159 159 160 /** Find devman handle assigned to USB address. 161 * Intentionally refuse to find handle of default address. 160 /** Find devman handled assigned to USB address. 162 161 * 163 162 * @param[in] instance Device keeper structure to use. … … 171 170 assert(instance); 172 171 fibril_mutex_lock(&instance->guard); 173 if ((address < =0) || (address >= USB_ADDRESS_COUNT)) {172 if ((address < 0) || (address >= USB_ADDRESS_COUNT)) { 174 173 fibril_mutex_unlock(&instance->guard); 175 174 return false;
Note:
See TracChangeset
for help on using the changeset viewer.