Changeset d8b275d in mainline for uspace/lib
- Timestamp:
- 2011-04-14T08:24:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5e07e2b5
- Parents:
- 3f2af64 (diff), 34e8bab (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/lib
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/mips32/include/atomic.h
r3f2af64 rd8b275d 70 70 " sc %0, %1\n" 71 71 " beq %0, %4, 1b\n" /* if the atomic operation failed, try again */ 72 /* nop */ /* nop is inserted automatically by compiler */73 72 " nop\n" 74 73 : "=&r" (tmp), -
uspace/lib/c/generic/adt/measured_strings.c
r3f2af64 rd8b275d 74 74 new->length = length; 75 75 new->value = ((uint8_t *) new) + sizeof(measured_string_t); 76 / / append terminating zero explicitly - to be safe76 /* Append terminating zero explicitly - to be safe */ 77 77 memcpy(new->value, string, new->length); 78 78 new->value[new->length] = '\0'; -
uspace/lib/c/generic/async.c
r3f2af64 rd8b275d 1586 1586 * @param dst Address of the beginning of the destination buffer. 1587 1587 * @param size Size of the destination buffer. 1588 * @param flags Flags to control the data transfer. 1588 1589 * 1589 1590 * @return Zero on success or a negative error code from errno.h. 1590 1591 * 1591 1592 */ 1592 int async_data_read_start(int phoneid, void *dst, size_t size) 1593 { 1594 return async_req_2_0(phoneid, IPC_M_DATA_READ, (sysarg_t) dst, 1595 (sysarg_t) size); 1593 int 1594 async_data_read_start_generic(int phoneid, void *dst, size_t size, int flags) 1595 { 1596 return async_req_3_0(phoneid, IPC_M_DATA_READ, (sysarg_t) dst, 1597 (sysarg_t) size, (sysarg_t) flags); 1596 1598 } 1597 1599 … … 1683 1685 * @param src Address of the beginning of the source buffer. 1684 1686 * @param size Size of the source buffer. 1687 * @param flags Flags to control the data transfer. 1685 1688 * 1686 1689 * @return Zero on success or a negative error code from errno.h. 1687 1690 * 1688 1691 */ 1689 int async_data_write_start(int phoneid, const void *src, size_t size) 1690 { 1691 return async_req_2_0(phoneid, IPC_M_DATA_WRITE, (sysarg_t) src, 1692 (sysarg_t) size); 1692 int 1693 async_data_write_start_generic(int phoneid, const void *src, size_t size, 1694 int flags) 1695 { 1696 return async_req_3_0(phoneid, IPC_M_DATA_WRITE, (sysarg_t) src, 1697 (sysarg_t) size, (sysarg_t) flags); 1693 1698 } 1694 1699 -
uspace/lib/c/generic/vfs/vfs.c
r3f2af64 rd8b275d 378 378 379 379 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 380 rc = async_data_read_start(vfs_phone, (void *)buf, nbyte); 380 rc = async_data_read_start_generic(vfs_phone, (void *) buf, nbyte, 381 IPC_XF_RESTRICT); 381 382 if (rc != EOK) { 382 383 vfs_exchange_end(vfs_phone); … … 407 408 408 409 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 409 rc = async_data_write_start(vfs_phone, (void *)buf, nbyte); 410 rc = async_data_write_start_generic(vfs_phone, (void *) buf, nbyte, 411 IPC_XF_RESTRICT); 410 412 if (rc != EOK) { 411 413 vfs_exchange_end(vfs_phone); -
uspace/lib/c/include/async.h
r3f2af64 rd8b275d 341 341 342 342 extern aid_t async_data_read(int, void *, size_t, ipc_call_t *); 343 extern int async_data_read_start(int, void *, size_t); 343 #define async_data_read_start(p, buf, len) \ 344 async_data_read_start_generic((p), (buf), (len), IPC_XF_NONE) 345 346 extern int async_data_read_start_generic(int, void *, size_t, int); 344 347 extern bool async_data_read_receive(ipc_callid_t *, size_t *); 345 348 extern int async_data_read_finalize(ipc_callid_t, const void *, size_t); … … 380 383 (arg4), (answer)) 381 384 382 extern int async_data_write_start(int, const void *, size_t); 385 #define async_data_write_start(p, buf, len) \ 386 async_data_write_start_generic((p), (buf), (len), IPC_XF_NONE) 387 388 extern int async_data_write_start_generic(int, const void *, size_t, int); 383 389 extern bool async_data_write_receive(ipc_callid_t *, size_t *); 384 390 extern int async_data_write_finalize(ipc_callid_t, void *, size_t); -
uspace/lib/drv/generic/driver.c
r3f2af64 rd8b275d 47 47 #include <stdlib.h> 48 48 #include <str.h> 49 #include <str_error.h> 49 50 #include <ctype.h> 50 51 #include <errno.h> … … 402 403 get_remote_method(rem_iface, iface_method_idx); 403 404 if (iface_method_ptr == NULL) { 404 / / the interface has not such method405 /* The interface has not such method */ 405 406 printf("%s: driver_connection_gen error - " 406 407 "invalid interface method.", driver->name); … … 655 656 int ddf_driver_main(driver_t *drv) 656 657 { 658 int rc; 659 657 660 /* 658 661 * Remember the driver structure - driver_ops will be called by generic … … 668 671 669 672 /* 670 * Register driver by device manager with generic handler for incoming671 * connections.673 * Register driver with device manager using generic handler for 674 * incoming connections. 672 675 */ 673 devman_driver_register(driver->name, driver_connection); 674 676 rc = devman_driver_register(driver->name, driver_connection); 677 if (rc != EOK) { 678 printf("Error: Failed to register driver with device manager " 679 "(%s).\n", (rc == EEXISTS) ? "driver already started" : 680 str_error(rc)); 681 682 return 1; 683 } 684 685 /* Return success from the task since server has started. */ 686 rc = task_retval(0); 687 if (rc != EOK) 688 return 1; 689 675 690 async_manager(); 676 691 -
uspace/lib/net/generic/generic.c
r3f2af64 rd8b275d 106 106 return EBADMEM; 107 107 108 / / request the address108 /* Request the address */ 109 109 message_id = async_send_1(phone, (sysarg_t) message, 110 110 (sysarg_t) device_id, NULL); … … 112 112 async_wait_for(message_id, &result); 113 113 114 / / if not successful114 /* If not successful */ 115 115 if ((string == EOK) && (result != EOK)) { 116 / / clear the data116 /* Clear the data */ 117 117 free(*address); 118 118 free(*data); … … 242 242 return EBADMEM; 243 243 244 / / request the translation244 /* Request the translation */ 245 245 message_id = async_send_3(phone, (sysarg_t) message, 246 246 (sysarg_t) device_id, (sysarg_t) count, (sysarg_t) service, NULL); … … 249 249 async_wait_for(message_id, &result); 250 250 251 / / if not successful251 /* If not successful */ 252 252 if ((string == EOK) && (result != EOK)) { 253 / / clear the data253 /* Clear the data */ 254 254 free(*translation); 255 255 free(*data); -
uspace/lib/net/generic/net_checksum.c
r3f2af64 rd8b275d 52 52 uint16_t compact_checksum(uint32_t sum) 53 53 { 54 / / shorten to the 16 bits54 /* Shorten to the 16 bits */ 55 55 while (sum >> 16) 56 56 sum = (sum & 0xffff) + (sum >> 16); … … 72 72 size_t index; 73 73 74 / / sum all the 16 bit fields74 /* Sum all the 16 bit fields */ 75 75 for (index = 0; index + 1 < length; index += 2) 76 76 seed += (data[index] << 8) + data[index + 1]; 77 77 78 / / last odd byte with zero padding78 /* Last odd byte with zero padding */ 79 79 if (index + 1 == length) 80 80 seed += data[index] << 8; … … 94 94 size_t index; 95 95 96 / / process full bytes96 /* Process full bytes */ 97 97 while (length >= 8) { 98 / / add the data98 /* Add the data */ 99 99 seed ^= (*data) << 24; 100 100 101 / / for each added bit101 /* For each added bit */ 102 102 for (index = 0; index < 8; ++index) { 103 / / if the first bit is set103 /* If the first bit is set */ 104 104 if (seed & 0x80000000) { 105 / / shift and divide the checksum105 /* Shift and divide the checksum */ 106 106 seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE); 107 107 } else { 108 / / shift otherwise108 /* Shift otherwise */ 109 109 seed <<= 1; 110 110 } 111 111 } 112 112 113 / / move to the next byte113 /* Move to the next byte */ 114 114 ++data; 115 115 length -= 8; 116 116 } 117 117 118 / / process the odd bits118 /* Process the odd bits */ 119 119 if (length > 0) { 120 / / add the data with zero padding120 /* Add the data with zero padding */ 121 121 seed ^= ((*data) & (0xff << (8 - length))) << 24; 122 122 123 / / for each added bit123 /* For each added bit */ 124 124 for (index = 0; index < length; ++index) { 125 / / if the first bit is set125 /* If the first bit is set */ 126 126 if (seed & 0x80000000) { 127 / / shift and divide the checksum127 /* Shift and divide the checksum */ 128 128 seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE); 129 129 } else { 130 / / shift otherwise130 /* Shift otherwise */ 131 131 seed <<= 1; 132 132 } … … 148 148 size_t index; 149 149 150 / / process full bytes150 /* Process full bytes */ 151 151 while (length >= 8) { 152 / / add the data152 /* Add the data */ 153 153 seed ^= (*data); 154 154 155 / / for each added bit155 /* For each added bit */ 156 156 for (index = 0; index < 8; ++index) { 157 / / if the last bit is set157 /* If the last bit is set */ 158 158 if (seed & 1) { 159 / / shift and divide the checksum159 /* Shift and divide the checksum */ 160 160 seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE); 161 161 } else { 162 / / shift otherwise162 /* Shift otherwise */ 163 163 seed >>= 1; 164 164 } 165 165 } 166 166 167 / / move to the next byte167 /* Move to the next byte */ 168 168 ++data; 169 169 length -= 8; 170 170 } 171 171 172 / / process the odd bits172 /* Process the odd bits */ 173 173 if (length > 0) { 174 / / add the data with zero padding174 /* Add the data with zero padding */ 175 175 seed ^= (*data) >> (8 - length); 176 176 177 177 for (index = 0; index < length; ++index) { 178 / / if the last bit is set178 /* If the last bit is set */ 179 179 if (seed & 1) { 180 / / shift and divide the checksum180 /* Shift and divide the checksum */ 181 181 seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE); 182 182 } else { 183 / / shift otherwise183 /* Shift otherwise */ 184 184 seed >>= 1; 185 185 } … … 198 198 uint16_t flip_checksum(uint16_t checksum) 199 199 { 200 / / flip, zero is returned as 0xFFFF (not flipped)200 /* Flip, zero is returned as 0xFFFF (not flipped) */ 201 201 checksum = ~checksum; 202 202 return checksum ? checksum : IP_CHECKSUM_ZERO; … … 216 216 uint16_t ip_checksum(uint8_t *data, size_t length) 217 217 { 218 / / compute, compact and flip the data checksum218 /* Compute, compact and flip the data checksum */ 219 219 return flip_checksum(compact_checksum(compute_checksum(0, data, 220 220 length))); -
uspace/lib/net/generic/packet_client.c
r3f2af64 rd8b275d 267 267 return NULL; 268 268 269 / / get a new packet269 /* Get a new packet */ 270 270 copy = packet_get_4_remote(phone, PACKET_DATA_LENGTH(packet), 271 271 PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, … … 274 274 return NULL; 275 275 276 / / get addresses276 /* Get addresses */ 277 277 addrlen = packet_get_addr(packet, &src, &dest); 278 / / copy data278 /* Copy data */ 279 279 if ((packet_copy_data(copy, packet_get_data(packet), 280 280 PACKET_DATA_LENGTH(packet)) == EOK) && 281 / / copy addresses if present281 /* Copy addresses if present */ 282 282 ((addrlen <= 0) || 283 283 (packet_set_addr(copy, src, dest, addrlen) == EOK))) { -
uspace/lib/net/il/ip_client.c
r3f2af64 rd8b275d 124 124 125 125 // TODO IPv6 126 /* case AF_INET6: 126 #if 0 127 case AF_INET6: 127 128 if (addrlen != sizeof(struct sockaddr_in6)) 128 129 return EINVAL; … … 130 131 address_in6 = (struct sockaddr_in6 *) addr; 131 132 return EOK; 132 */ 133 #endif 133 134 134 135 default: … … 159 160 size_t padding; 160 161 161 // compute the padding if IP options are set 162 // multiple of 4 bytes 162 /* 163 * Compute the padding if IP options are set 164 * multiple of 4 bytes 165 */ 163 166 padding = ipopt_length % 4; 164 167 if (padding) { … … 167 170 } 168 171 169 / / prefix the header172 /* Prefix the header */ 170 173 data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding); 171 174 if (!data) 172 175 return ENOMEM; 173 176 174 / / add the padding177 /* Add the padding */ 175 178 while (padding--) 176 179 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP; 177 180 178 / / set the header181 /* Set the header */ 179 182 header = (ip_header_t *) data; 180 183 header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + -
uspace/lib/net/tl/icmp_client.c
r3f2af64 rd8b275d 81 81 *mtu = header->un.frag.mtu; 82 82 83 / / remove debug dump83 /* Remove debug dump */ 84 84 #ifdef CONFIG_DEBUG 85 85 printf("ICMP error %d (%d) in packet %d\n", header->type, header->code, -
uspace/lib/net/tl/socket_core.c
r3f2af64 rd8b275d 91 91 int packet_id; 92 92 93 / / if bound93 /* If bound */ 94 94 if (socket->port) { 95 / / release the port95 /* Release the port */ 96 96 socket_port_release(global_sockets, socket); 97 97 } 98 98 99 / / release all received packets99 /* Release all received packets */ 100 100 while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0) 101 101 pq_release_remote(packet_phone, packet_id); … … 166 166 int rc; 167 167 168 / / create a wrapper168 /* Create a wrapper */ 169 169 socket_ref = malloc(sizeof(*socket_ref)); 170 170 if (!socket_ref) … … 172 172 173 173 *socket_ref = socket; 174 / / add the wrapper174 /* Add the wrapper */ 175 175 rc = socket_port_map_add(&socket_port->map, key, key_length, 176 176 socket_ref); … … 206 206 int rc; 207 207 208 / / create a wrapper208 /* Create a wrapper */ 209 209 socket_port = malloc(sizeof(*socket_port)); 210 210 if (!socket_port) … … 221 221 goto fail; 222 222 223 / / register the incomming port223 /* Register the incoming port */ 224 224 rc = socket_ports_add(global_sockets, port, socket_port); 225 225 if (rc < 0) … … 277 277 278 278 address_in = (struct sockaddr_in *) addr; 279 / / find the socket279 /* Find the socket */ 280 280 socket = socket_cores_find(local_sockets, socket_id); 281 281 if (!socket) 282 282 return ENOTSOCK; 283 283 284 / / bind a free port?284 /* Bind a free port? */ 285 285 if (address_in->sin_port <= 0) 286 286 return socket_bind_free_port(global_sockets, socket, 287 287 free_ports_start, free_ports_end, last_used_port); 288 288 289 / / try to find the port289 /* Try to find the port */ 290 290 socket_port = socket_ports_find(global_sockets, 291 291 ntohs(address_in->sin_port)); 292 292 if (socket_port) { 293 / / already used293 /* Already used */ 294 294 return EADDRINUSE; 295 295 } 296 296 297 / / if bound297 /* If bound */ 298 298 if (socket->port) { 299 / / release the port299 /* Release the port */ 300 300 socket_port_release(global_sockets, socket); 301 301 } … … 333 333 int index; 334 334 335 / / from the last used one335 /* From the last used one */ 336 336 index = last_used_port; 337 337 … … 339 339 ++index; 340 340 341 / / til the range end341 /* Till the range end */ 342 342 if (index >= free_ports_end) { 343 / / start from the range beginning343 /* Start from the range beginning */ 344 344 index = free_ports_start - 1; 345 345 do { 346 346 ++index; 347 / / til the last used one347 /* Till the last used one */ 348 348 if (index >= last_used_port) { 349 / / none found349 /* None found */ 350 350 return ENOTCONN; 351 351 } 352 352 } while (socket_ports_find(global_sockets, index)); 353 353 354 / / found, break immediately354 /* Found, break immediately */ 355 355 break; 356 356 } … … 376 376 377 377 count = 0; 378 // socket_id = socket_globals.last_id; 378 #if 0 379 socket_id = socket_globals.last_id; 380 #endif 379 381 do { 380 382 if (count < SOCKET_ID_TRIES) { … … 384 386 socket_id = 1; 385 387 ++count; 386 / / only this branch for last_id388 /* Only this branch for last_id */ 387 389 } else { 388 390 if (socket_id < INT_MAX) { 389 391 ++ socket_id; 390 /* } else if(socket_globals.last_id) { 391 * socket_globals.last_id = 0; 392 * socket_id = 1; 393 */ } else { 392 #if 0 393 } else if(socket_globals.last_id) { 394 socket_globals.last_id = 0; 395 socket_id = 1; 396 #endif 397 } else { 394 398 return ELIMIT; 395 399 } … … 425 429 return EINVAL; 426 430 427 / / store the socket431 /* Store the socket */ 428 432 if (*socket_id <= 0) { 429 433 positive = (*socket_id == 0); … … 441 445 return ENOMEM; 442 446 443 / / initialize447 /* Initialize */ 444 448 socket->phone = app_phone; 445 449 socket->port = -1; … … 493 497 int accepted_id; 494 498 495 / / find the socket499 /* Find the socket */ 496 500 socket = socket_cores_find(local_sockets, socket_id); 497 501 if (!socket) 498 502 return ENOTSOCK; 499 503 500 / / destroy all accepted sockets504 /* Destroy all accepted sockets */ 501 505 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 502 506 socket_destroy(packet_phone, accepted_id, local_sockets, … … 535 539 next_packet = pq_next(packet); 536 540 if (!next_packet) { 537 / / write all if only one fragment541 /* Write all if only one fragment */ 538 542 rc = data_reply(packet_get_data(packet), 539 543 packet_get_data_length(packet)); 540 544 if (rc != EOK) 541 545 return rc; 542 / / store the total length546 /* Store the total length */ 543 547 *length = packet_get_data_length(packet); 544 548 } else { 545 / / count the packet fragments549 /* Count the packet fragments */ 546 550 fragments = 1; 547 551 next_packet = pq_next(packet); … … 549 553 ++fragments; 550 554 551 / / compute and store the fragment lengths555 /* Compute and store the fragment lengths */ 552 556 lengths = (size_t *) malloc(sizeof(size_t) * fragments + 553 557 sizeof(size_t)); … … 565 569 } 566 570 567 / / write the fragment lengths571 /* Write the fragment lengths */ 568 572 rc = data_reply(lengths, sizeof(int) * (fragments + 1)); 569 573 if (rc != EOK) { … … 573 577 next_packet = packet; 574 578 575 / / write the fragments579 /* Write the fragments */ 576 580 for (index = 0; index < fragments; ++index) { 577 581 rc = data_reply(packet_get_data(next_packet), … … 584 588 } 585 589 586 / / store the total length590 /* Store the total length */ 587 591 *length = lengths[fragments]; 588 592 free(lengths); … … 636 640 return; 637 641 638 / / find ports642 /* Find ports */ 639 643 socket_port = socket_ports_find(global_sockets, socket->port); 640 644 if (socket_port) { 641 / / find the socket645 /* Find the socket */ 642 646 socket_ref = socket_port_map_find(&socket_port->map, 643 647 socket->key, socket->key_length); … … 646 650 --socket_port->count; 647 651 648 / / release if empty652 /* Release if empty */ 649 653 if (socket_port->count <= 0) { 650 / / destroy the map654 /* Destroy the map */ 651 655 socket_port_map_destroy(&socket_port->map, free); 652 / / release the port656 /* Release the port */ 653 657 socket_ports_exclude(global_sockets, 654 658 socket->port, free); 655 659 } else { 656 / / remove660 /* Remove */ 657 661 socket_port_map_exclude(&socket_port->map, 658 662 socket->key, socket->key_length, free); … … 685 689 int rc; 686 690 687 / / find ports691 /* Find ports */ 688 692 socket_port = socket_ports_find(global_sockets, port); 689 693 if (!socket_port) 690 694 return ENOENT; 691 695 692 / / add the socket696 /* Add the socket */ 693 697 rc = socket_port_add_core(socket_port, socket, key, key_length); 694 698 if (rc != EOK) -
uspace/lib/net/tl/tl_common.c
r3f2af64 rd8b275d 255 255 int length; 256 256 257 / / detach the first packet and release the others257 /* Detach the first packet and release the others */ 258 258 next = pq_detach(packet); 259 259 if (next) … … 262 262 length = packet_get_addr(packet, &src, NULL); 263 263 if ((length > 0) && (!error) && (icmp_phone >= 0) && 264 // set both addresses to the source one (avoids the source address 265 // deletion before setting the destination one) 264 /* 265 * Set both addresses to the source one (avoids the source address 266 * deletion before setting the destination one) 267 */ 266 268 (packet_set_addr(packet, src, src, (size_t) length) == EOK)) { 267 269 return EOK; … … 299 301 return EINVAL; 300 302 301 / / get the data length303 /* Get the data length */ 302 304 if (!async_data_write_receive(&callid, &length)) 303 305 return EINVAL; 304 306 305 / / get a new packet307 /* Get a new packet */ 306 308 *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, 307 309 prefix + dimension->prefix, dimension->suffix); … … 309 311 return ENOMEM; 310 312 311 / / allocate space in the packet313 /* Allocate space in the packet */ 312 314 data = packet_suffix(*packet, length); 313 315 if (!data) { … … 316 318 } 317 319 318 / / read the data into the packet320 /* Read the data into the packet */ 319 321 rc = async_data_write_finalize(callid, data, length); 320 322 if (rc != EOK) { … … 323 325 } 324 326 325 / / set the packet destination address327 /* Set the packet destination address */ 326 328 rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen); 327 329 if (rc != EOK) { -
uspace/lib/packet/generic/packet_server.c
r3f2af64 rd8b275d 112 112 size_t max_content, size_t max_suffix) 113 113 { 114 / / clear the packet content114 /* Clear the packet content */ 115 115 bzero(((void *) packet) + sizeof(packet_t), 116 116 packet->length - sizeof(packet_t)); 117 117 118 / / clear the packet header118 /* Clear the packet header */ 119 119 packet->order = 0; 120 120 packet->metric = 0; … … 151 151 assert(fibril_mutex_is_locked(&ps_globals.lock)); 152 152 153 / / already locked153 /* Already locked */ 154 154 packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE, 155 155 MAP_SHARED | MAP_ANONYMOUS, 0, 0); -
uspace/lib/softint/generic/multiplication.c
r3f2af64 rd8b275d 109 109 * result does not fit in signed one */ 110 110 if (SOFTINT_CHECK_OF && ((t2 < t1) || (t2 & (1ull << 63)))) { 111 / / error, overflow111 /* Error, overflow */ 112 112 return (neg ? INT64_MIN : INT64_MAX); 113 113 } -
uspace/lib/usb/include/usb/host/batch.h
r3f2af64 rd8b275d 43 43 typedef struct usb_transfer_batch usb_transfer_batch_t; 44 44 struct usb_transfer_batch { 45 endpoint_t *ep; 45 46 link_t link; 46 usb_target_t target;47 usb_transfer_type_t transfer_type;48 usb_speed_t speed;49 usb_direction_t direction;50 47 usbhc_iface_transfer_in_callback_t callback_in; 51 48 usbhc_iface_transfer_out_callback_t callback_out; 49 void *arg; 52 50 char *buffer; 53 char * transport_buffer;51 char *data_buffer; 54 52 size_t buffer_size; 55 53 char *setup_buffer; 56 54 size_t setup_size; 57 size_t max_packet_size;58 55 size_t transfered_size; 59 56 void (*next_step)(usb_transfer_batch_t *); 60 57 int error; 61 58 ddf_fun_t *fun; 62 void *arg;63 endpoint_t *ep;64 59 void *private_data; 60 void (*private_data_dtor)(void *p_data); 65 61 }; 66 62 67 63 void usb_transfer_batch_init( 68 64 usb_transfer_batch_t *instance, 69 usb_target_t target, 70 usb_transfer_type_t transfer_type, 71 usb_speed_t speed, 72 size_t max_packet_size, 65 endpoint_t *ep, 73 66 char *buffer, 74 char * transport_buffer,67 char *data_buffer, 75 68 size_t buffer_size, 76 69 char *setup_buffer, … … 80 73 void *arg, 81 74 ddf_fun_t *fun, 82 endpoint_t *ep,83 void *private_data75 void *private_data, 76 void (*private_data_dtor)(void *p_data) 84 77 ); 85 78 86 static inline usb_transfer_batch_t *usb_transfer_batch_from_link(link_t *l) 87 { 88 assert(l); 89 return list_get_instance(l, usb_transfer_batch_t, link); 90 } 91 92 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance); 93 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance); 79 void usb_transfer_batch_call_in_and_dispose(usb_transfer_batch_t *instance); 80 void usb_transfer_batch_call_out_and_dispose(usb_transfer_batch_t *instance); 94 81 void usb_transfer_batch_finish(usb_transfer_batch_t *instance); 82 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance); 95 83 96 84 static inline void usb_transfer_batch_finish_error( … … 102 90 } 103 91 92 static inline usb_transfer_batch_t *usb_transfer_batch_from_link(link_t *l) 93 { 94 assert(l); 95 return list_get_instance(l, usb_transfer_batch_t, link); 96 } 97 104 98 #endif 105 99 /** -
uspace/lib/usb/include/usb/host/device_keeper.h
r3f2af64 rd8b275d 54 54 usb_speed_t speed; 55 55 bool occupied; 56 link_t endpoints;57 uint16_t control_used;58 56 devman_handle_t handle; 59 57 }; … … 65 63 struct usb_device_info devices[USB_ADDRESS_COUNT]; 66 64 fibril_mutex_t guard; 67 fibril_condvar_t change;68 65 usb_address_t last_address; 69 66 } usb_device_keeper_t; 70 67 71 68 void usb_device_keeper_init(usb_device_keeper_t *instance); 72 73 void usb_device_keeper_reserve_default_address(74 usb_device_keeper_t *instance, usb_speed_t speed);75 76 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance);77 78 void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,79 usb_target_t target, const uint8_t *setup_data);80 69 81 70 usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance, -
uspace/lib/usb/include/usb/host/endpoint.h
r3f2af64 rd8b275d 54 54 fibril_condvar_t avail; 55 55 volatile bool active; 56 struct { 57 void *data; 58 int (*toggle_get)(void *); 59 void (*toggle_set)(void *, int); 60 } hc_data; 56 61 } endpoint_t; 57 62 … … 61 66 62 67 void endpoint_destroy(endpoint_t *instance); 68 69 void endpoint_set_hc_data(endpoint_t *instance, 70 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)); 71 72 void endpoint_clear_hc_data(endpoint_t *instance); 63 73 64 74 void endpoint_use(endpoint_t *instance); -
uspace/lib/usb/include/usb/host/usb_endpoint_manager.h
r3f2af64 rd8b275d 66 66 endpoint_t *ep, size_t data_size); 67 67 68 int usb_endpoint_manager_register_ep_wait(usb_endpoint_manager_t *instance,69 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,70 void *data, void (*data_remove_callback)(void* data, void* arg), void *arg,71 size_t bw);72 73 68 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance, 74 69 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); … … 80 75 void usb_endpoint_manager_reset_if_need( 81 76 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data); 77 78 static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance, 79 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 80 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size, 81 size_t data_size) 82 { 83 endpoint_t *ep = malloc(sizeof(endpoint_t)); 84 if (ep == NULL) 85 return ENOMEM; 86 87 int ret = endpoint_init(ep, address, endpoint, direction, type, speed, 88 max_packet_size); 89 if (ret != EOK) { 90 free(ep); 91 return ret; 92 } 93 94 ret = usb_endpoint_manager_register_ep(instance, ep, data_size); 95 if (ret != EOK) { 96 endpoint_destroy(ep); 97 return ret; 98 } 99 return EOK; 100 } 82 101 #endif 83 102 /** -
uspace/lib/usb/src/hidparser.c
r3f2af64 rd8b275d 900 900 item->usage_page = usage_page; 901 901 902 usb_log_debug("Appending usage %d, usage page %d\n", usage, usage_page); 903 902 904 list_append (&usage_path->link, &item->link); 903 905 usage_path->depth++; -
uspace/lib/usb/src/host/batch.c
r3f2af64 rd8b275d 39 39 #include <usb/host/batch.h> 40 40 41 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance); 42 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance); 43 41 44 void usb_transfer_batch_init( 42 45 usb_transfer_batch_t *instance, 43 usb_target_t target, 44 usb_transfer_type_t transfer_type, 45 usb_speed_t speed, 46 size_t max_packet_size, 46 endpoint_t *ep, 47 47 char *buffer, 48 char * transport_buffer,48 char *data_buffer, 49 49 size_t buffer_size, 50 50 char *setup_buffer, … … 54 54 void *arg, 55 55 ddf_fun_t *fun, 56 endpoint_t *ep,57 void *private_data56 void *private_data, 57 void (*private_data_dtor)(void *p_data) 58 58 ) 59 59 { 60 60 assert(instance); 61 61 link_initialize(&instance->link); 62 instance->target = target; 63 instance->transfer_type = transfer_type; 64 instance->speed = speed; 65 instance->direction = ep->direction; 62 instance->ep = ep; 66 63 instance->callback_in = func_in; 67 64 instance->callback_out = func_out; 68 65 instance->arg = arg; 69 66 instance->buffer = buffer; 70 instance-> transport_buffer = transport_buffer;67 instance->data_buffer = data_buffer; 71 68 instance->buffer_size = buffer_size; 72 69 instance->setup_buffer = setup_buffer; 73 70 instance->setup_size = setup_size; 74 instance->max_packet_size = max_packet_size;75 71 instance->fun = fun; 76 72 instance->private_data = private_data; 73 instance->private_data_dtor = private_data_dtor; 77 74 instance->transfered_size = 0; 78 75 instance->next_step = NULL; 79 76 instance->error = EOK; 80 instance->ep = ep;81 77 endpoint_use(instance->ep); 78 } 79 /*----------------------------------------------------------------------------*/ 80 /** Helper function, calls callback and correctly destroys batch structure. 81 * 82 * @param[in] instance Batch structure to use. 83 */ 84 void usb_transfer_batch_call_in_and_dispose(usb_transfer_batch_t *instance) 85 { 86 assert(instance); 87 usb_transfer_batch_call_in(instance); 88 usb_transfer_batch_dispose(instance); 89 } 90 /*----------------------------------------------------------------------------*/ 91 /** Helper function calls callback and correctly destroys batch structure. 92 * 93 * @param[in] instance Batch structure to use. 94 */ 95 void usb_transfer_batch_call_out_and_dispose(usb_transfer_batch_t *instance) 96 { 97 assert(instance); 98 usb_transfer_batch_call_out(instance); 99 usb_transfer_batch_dispose(instance); 82 100 } 83 101 /*----------------------------------------------------------------------------*/ … … 105 123 assert(instance); 106 124 assert(instance->callback_in); 125 assert(instance->ep); 107 126 108 127 /* We are data in, we need data */ 109 memcpy(instance->buffer, instance->transport_buffer, 110 instance->buffer_size); 128 memcpy(instance->buffer, instance->data_buffer, instance->buffer_size); 111 129 112 130 usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n", 113 instance, 114 instance->target.address, instance->target.endpoint, 115 usb_str_speed(instance->speed), 116 usb_str_transfer_type_short(instance->transfer_type), 117 instance->transfered_size, 118 str_error(instance->error), instance->error); 131 instance, instance->ep->address, instance->ep->endpoint, 132 usb_str_speed(instance->ep->speed), 133 usb_str_transfer_type_short(instance->ep->transfer_type), 134 instance->transfered_size, str_error(instance->error), instance->error); 119 135 120 136 instance->callback_in(instance->fun, instance->error, … … 132 148 133 149 usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n", 134 instance, 135 instance->target.address, instance->target.endpoint, 136 usb_str_speed(instance->speed), 137 usb_str_transfer_type_short(instance->transfer_type), 150 instance, instance->ep->address, instance->ep->endpoint, 151 usb_str_speed(instance->ep->speed), 152 usb_str_transfer_type_short(instance->ep->transfer_type), 138 153 str_error(instance->error), instance->error); 139 154 … … 141 156 instance->error, instance->arg); 142 157 } 158 /*----------------------------------------------------------------------------*/ 159 /** Correctly dispose all used data structures. 160 * 161 * @param[in] instance Batch structure to use. 162 */ 163 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance) 164 { 165 assert(instance); 166 usb_log_debug("Batch(%p) disposing.\n", instance); 167 if (instance->private_data) { 168 assert(instance->private_data_dtor); 169 instance->private_data_dtor(instance->private_data); 170 } 171 free(instance); 172 } 143 173 /** 144 174 * @} -
uspace/lib/usb/src/host/device_keeper.c
r3f2af64 rd8b275d 48 48 { 49 49 assert(instance); 50 fibril_mutex_initialize(&instance->guard);51 fibril_condvar_initialize(&instance->change);52 instance->last_address = 0;53 50 unsigned i = 0; 54 51 for (; i < USB_ADDRESS_COUNT; ++i) { … … 60 57 // (it is needed to allow smooth registration at default address) 61 58 instance->devices[0].occupied = true; 59 instance->last_address = 0; 60 fibril_mutex_initialize(&instance->guard); 62 61 } 63 /*----------------------------------------------------------------------------*/64 /** Attempt to obtain address 0, blocks.65 *66 * @param[in] instance Device keeper structure to use.67 * @param[in] speed Speed of the device requesting default address.68 */69 void usb_device_keeper_reserve_default_address(70 usb_device_keeper_t *instance, usb_speed_t speed)71 {72 assert(instance);73 fibril_mutex_lock(&instance->guard);74 while (instance->devices[USB_ADDRESS_DEFAULT].occupied) {75 fibril_condvar_wait(&instance->change, &instance->guard);76 }77 instance->devices[USB_ADDRESS_DEFAULT].occupied = true;78 instance->devices[USB_ADDRESS_DEFAULT].speed = speed;79 fibril_mutex_unlock(&instance->guard);80 }81 /*----------------------------------------------------------------------------*/82 /** Attempt to obtain address 0, blocks.83 *84 * @param[in] instance Device keeper structure to use.85 * @param[in] speed Speed of the device requesting default address.86 */87 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance)88 {89 assert(instance);90 fibril_mutex_lock(&instance->guard);91 instance->devices[USB_ADDRESS_DEFAULT].occupied = false;92 fibril_mutex_unlock(&instance->guard);93 fibril_condvar_signal(&instance->change);94 }95 /*----------------------------------------------------------------------------*/96 62 /*----------------------------------------------------------------------------*/ 97 63 /** Get a free USB address … … 120 86 assert(new_address != USB_ADDRESS_DEFAULT); 121 87 assert(instance->devices[new_address].occupied == false); 88 122 89 instance->devices[new_address].occupied = true; 123 90 instance->devices[new_address].speed = speed; 124 91 instance->last_address = new_address; 92 125 93 fibril_mutex_unlock(&instance->guard); 126 94 return new_address; … … 138 106 assert(instance); 139 107 fibril_mutex_lock(&instance->guard); 108 140 109 assert(address > 0); 141 110 assert(address <= USB11_ADDRESS_MAX); 142 111 assert(instance->devices[address].occupied); 112 143 113 instance->devices[address].handle = handle; 144 114 fibril_mutex_unlock(&instance->guard); … … 159 129 fibril_mutex_lock(&instance->guard); 160 130 assert(instance->devices[address].occupied); 131 161 132 instance->devices[address].occupied = false; 162 133 fibril_mutex_unlock(&instance->guard); … … 177 148 while (address <= USB11_ADDRESS_MAX) { 178 149 if (instance->devices[address].handle == handle) { 150 assert(instance->devices[address].occupied); 179 151 fibril_mutex_unlock(&instance->guard); 180 152 return address; … … 198 170 assert(address >= 0); 199 171 assert(address <= USB11_ADDRESS_MAX); 172 200 173 return instance->devices[address].speed; 201 174 } -
uspace/lib/usb/src/host/endpoint.c
r3f2af64 rd8b275d 53 53 fibril_mutex_initialize(&instance->guard); 54 54 fibril_condvar_initialize(&instance->avail); 55 endpoint_clear_hc_data(instance); 55 56 return EOK; 56 57 } … … 61 62 assert(!instance->active); 62 63 free(instance); 64 } 65 /*----------------------------------------------------------------------------*/ 66 void endpoint_set_hc_data(endpoint_t *instance, 67 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 68 { 69 assert(instance); 70 instance->hc_data.data = data; 71 instance->hc_data.toggle_get = toggle_get; 72 instance->hc_data.toggle_set = toggle_set; 73 } 74 /*----------------------------------------------------------------------------*/ 75 void endpoint_clear_hc_data(endpoint_t *instance) 76 { 77 assert(instance); 78 instance->hc_data.data = NULL; 79 instance->hc_data.toggle_get = NULL; 80 instance->hc_data.toggle_set = NULL; 63 81 } 64 82 /*----------------------------------------------------------------------------*/ … … 85 103 { 86 104 assert(instance); 105 if (instance->hc_data.toggle_get) 106 instance->toggle = 107 instance->hc_data.toggle_get(instance->hc_data.data); 87 108 return (int)instance->toggle; 88 109 } … … 92 113 assert(instance); 93 114 assert(toggle == 0 || toggle == 1); 115 if (instance->hc_data.toggle_set) 116 instance->hc_data.toggle_set(instance->hc_data.data, toggle); 94 117 instance->toggle = toggle; 95 118 } … … 99 122 assert(instance); 100 123 if (instance->address == target.address && 101 instance->endpoint == target.endpoint)124 (instance->endpoint == target.endpoint || target.endpoint == 0)) 102 125 instance->toggle = 0; 103 126 } -
uspace/lib/usb/src/host/usb_endpoint_manager.c
r3f2af64 rd8b275d 211 211 212 212 node_t *node = hash_table_get_instance(item, node_t, link); 213 if (node->ep->active) 214 return EBUSY; 215 213 216 instance->free_bw += node->bw; 214 217 hash_table_remove(&instance->ep_table, key, MAX_KEYS);
Note:
See TracChangeset
for help on using the changeset viewer.