Changeset 243cb86 in mainline for uspace/lib
- Timestamp:
- 2010-12-12T10:50:19Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8365533
- Parents:
- 101ef25c (diff), ebb98c5 (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:
-
- 8 added
- 25 edited
-
block/libblock.c (modified) (17 diffs)
-
block/libblock.h (modified) (1 diff)
-
c/generic/adt/char_map.c (modified) (4 diffs)
-
c/generic/devman.c (modified) (1 diff)
-
c/include/adt/generic_field.h (modified) (2 diffs)
-
c/include/errno.h (modified) (1 diff)
-
c/include/ipc/dev_iface.h (modified) (1 diff)
-
c/include/ipc/vfs.h (modified) (2 diffs)
-
drv/generic/driver.c (modified) (1 diff)
-
drv/generic/remote_usbhc.c (modified) (9 diffs)
-
drv/include/driver.h (modified) (1 diff)
-
drv/include/usbhc_iface.h (modified) (2 diffs)
-
usb/Makefile (modified) (1 diff)
-
usb/include/usb/classes/hid.h (modified) (2 diffs)
-
usb/include/usb/classes/hidparser.h (added)
-
usb/include/usb/debug.h (added)
-
usb/include/usb/devreq.h (modified) (2 diffs)
-
usb/include/usb/hcd.h (added)
-
usb/include/usb/hcdhubd.h (modified) (4 diffs)
-
usb/include/usb/usb.h (modified) (1 diff)
-
usb/include/usb/usbdrv.h (modified) (4 diffs)
-
usb/src/addrkeep.c (added)
-
usb/src/debug.c (added)
-
usb/src/drvpsync.c (added)
-
usb/src/hcdhubd.c (modified) (7 diffs)
-
usb/src/hcdhubd_private.h (modified) (1 diff)
-
usb/src/hcdrv.c (modified) (3 diffs)
-
usb/src/hidparser.c (added)
-
usb/src/localdrv.c (modified) (1 diff)
-
usb/src/remotedrv.c (modified) (1 diff)
-
usb/src/usbdrv.c (modified) (3 diffs)
-
usb/src/usbdrvreq.c (added)
-
usbvirt/main.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r101ef25c r243cb86 66 66 fibril_mutex_t lock; 67 67 size_t lblock_size; /**< Logical block size. */ 68 unsigned blocks_cluster; /**< Physical blocks per block_t */ 68 69 unsigned block_count; /**< Total number of blocks. */ 69 70 unsigned blocks_cached; /**< Number of cached blocks. */ … … 90 91 static int get_block_size(int dev_phone, size_t *bsize); 91 92 static int get_num_blocks(int dev_phone, aoff64_t *nblocks); 93 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba); 92 94 93 95 static devcon_t *devcon_search(devmap_handle_t devmap_handle) … … 259 261 { 260 262 block_t *b = hash_table_get_instance(item, block_t, hash_link); 261 return b-> boff== *key;263 return b->lba == *key; 262 264 } 263 265 … … 292 294 cache->mode = mode; 293 295 294 /* No block size translation a.t.m. */ 295 assert(cache->lblock_size == devcon->pblock_size); 296 /* Allow 1:1 or small-to-large block size translation */ 297 if (cache->lblock_size % devcon->pblock_size != 0) 298 return ENOTSUP; 299 300 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 296 301 297 302 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1, … … 329 334 if (b->dirty) { 330 335 memcpy(devcon->comm_area, b->data, b->size); 331 rc = write_blocks(devcon, b-> boff, 1);336 rc = write_blocks(devcon, b->pba, cache->blocks_cluster); 332 337 if (rc != EOK) 333 338 return rc; 334 339 } 335 340 336 unsigned long key = b-> boff;341 unsigned long key = b->lba; 337 342 hash_table_remove(&cache->block_hash, &key, 1); 338 343 … … 375 380 * block pointer on success. 376 381 * @param devmap_handle Device handle of the block device. 377 * @param b off Block offset.382 * @param ba Block address (logical). 378 383 * @param flags If BLOCK_FLAGS_NOREAD is specified, block_get() 379 384 * will not read the contents of the block from the … … 382 387 * @return EOK on success or a negative error code. 383 388 */ 384 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t b off, int flags)389 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags) 385 390 { 386 391 devcon_t *devcon; … … 388 393 block_t *b; 389 394 link_t *l; 390 unsigned long key = b off;395 unsigned long key = ba; 391 396 int rc; 392 397 … … 465 470 fibril_mutex_lock(&devcon->comm_area_lock); 466 471 memcpy(devcon->comm_area, b->data, b->size); 467 rc = write_blocks(devcon, b->boff, 1); 472 rc = write_blocks(devcon, b->pba, 473 cache->blocks_cluster); 468 474 fibril_mutex_unlock(&devcon->comm_area_lock); 469 475 if (rc != EOK) { … … 495 501 */ 496 502 list_remove(&b->free_link); 497 temp_key = b-> boff;503 temp_key = b->lba; 498 504 hash_table_remove(&cache->block_hash, &temp_key, 1); 499 505 } … … 502 508 b->devmap_handle = devmap_handle; 503 509 b->size = cache->lblock_size; 504 b->boff = boff; 510 b->lba = ba; 511 b->pba = ba_ltop(devcon, b->lba); 505 512 hash_table_insert(&cache->block_hash, &key, &b->hash_link); 506 513 … … 519 526 */ 520 527 fibril_mutex_lock(&devcon->comm_area_lock); 521 rc = read_blocks(devcon, b-> boff, 1);528 rc = read_blocks(devcon, b->pba, cache->blocks_cluster); 522 529 memcpy(b->data, devcon->comm_area, cache->lblock_size); 523 530 fibril_mutex_unlock(&devcon->comm_area_lock); … … 580 587 fibril_mutex_lock(&devcon->comm_area_lock); 581 588 memcpy(devcon->comm_area, block->data, block->size); 582 rc = write_blocks(devcon, block-> boff, 1);589 rc = write_blocks(devcon, block->pba, cache->blocks_cluster); 583 590 fibril_mutex_unlock(&devcon->comm_area_lock); 584 591 block->dirty = false; … … 614 621 * Take the block out of the cache and free it. 615 622 */ 616 unsigned long key = block-> boff;623 unsigned long key = block->lba; 617 624 hash_table_remove(&cache->block_hash, &key, 1); 618 625 free(block); … … 712 719 * 713 720 * @param devmap_handle Device handle of the block device. 714 * @param ba Address of first block .721 * @param ba Address of first block (physical). 715 722 * @param cnt Number of blocks. 716 723 * @param src Buffer for storing the data. … … 740 747 * 741 748 * @param devmap_handle Device handle of the block device. 742 * @param ba Address of first block .749 * @param ba Address of first block (physical). 743 750 * @param cnt Number of blocks. 744 751 * @param src The data to be written. … … 879 886 } 880 887 888 /** Convert logical block address to physical block address. */ 889 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba) 890 { 891 assert(devcon->cache != NULL); 892 return lba * devcon->cache->blocks_cluster; 893 } 894 881 895 /** @} 882 896 */ -
uspace/lib/block/libblock.h
r101ef25c r243cb86 73 73 /** Handle of the device where the block resides. */ 74 74 devmap_handle_t devmap_handle; 75 /** Block offset on the block device. Counted in 'size'-byte blocks. */ 76 aoff64_t boff; 75 /** Logical block address */ 76 aoff64_t lba; 77 /** Physical block address */ 78 aoff64_t pba; 77 79 /** Size of the block. */ 78 80 size_t size; -
uspace/lib/c/generic/adt/char_map.c
r101ef25c r243cb86 90 90 } 91 91 92 map->items[map->next]->c = * identifier;93 ++ identifier;94 ++ map->next;95 if ((length > 1) || ((length == 0) && (*identifier))) {92 map->items[map->next]->c = *identifier; 93 identifier++; 94 map->next++; 95 if ((length > 1) || ((length == 0) && *identifier)) { 96 96 map->items[map->next - 1]->value = CHAR_MAP_NULL; 97 97 return char_map_add_item(map->items[map->next - 1], identifier, … … 142 142 const int value) 143 143 { 144 if (char_map_is_valid(map) && (identifier) && 145 ((length) || (*identifier))) { 144 if (char_map_is_valid(map) && identifier && (length || *identifier)) { 146 145 int index; 147 146 148 for (index = 0; index < map->next; ++ index) {147 for (index = 0; index < map->next; index++) { 149 148 if (map->items[index]->c != *identifier) 150 149 continue; 151 150 152 ++ identifier;153 if((length > 1) || ((length == 0) && (*identifier))) {151 identifier++; 152 if((length > 1) || ((length == 0) && *identifier)) { 154 153 return char_map_add(map->items[index], 155 154 identifier, length ? length - 1 : 0, value); … … 178 177 179 178 map->magic = 0; 180 for (index = 0; index < map->next; ++index)179 for (index = 0; index < map->next; index++) 181 180 char_map_destroy(map->items[index]); 182 181 … … 207 206 return NULL; 208 207 209 if (length || (*identifier)) {208 if (length || *identifier) { 210 209 int index; 211 210 212 for (index = 0; index < map->next; ++index) {211 for (index = 0; index < map->next; index++) { 213 212 if (map->items[index]->c == *identifier) { 214 ++identifier;213 identifier++; 215 214 if (length == 1) 216 215 return map->items[index]; -
uspace/lib/c/generic/devman.c
r101ef25c r243cb86 116 116 { 117 117 ipc_call_t answer; 118 a sync_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer);118 aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer); 119 119 int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id)); 120 return retval; 120 async_wait_for(req, NULL); 121 return retval; 121 122 } 122 123 -
uspace/lib/c/include/adt/generic_field.h
r101ef25c r243cb86 91 91 } \ 92 92 field->items[field->next] = value; \ 93 ++field->next; \93 field->next++; \ 94 94 field->items[field->next] = NULL; \ 95 95 return field->next - 1; \ … … 108 108 int index; \ 109 109 field->magic = 0; \ 110 for (index = 0; index < field->next; ++ index) { \110 for (index = 0; index < field->next; index++) { \ 111 111 if (field->items[index]) \ 112 112 free(field->items[index]); \ -
uspace/lib/c/include/errno.h
r101ef25c r243cb86 83 83 #define ENOTCONN (-10057) 84 84 85 /** The requested operation was not performed. 86 * Try again later. 87 */ 88 #define TRY_AGAIN (-11002) 85 /** The requested operation was not performed. Try again later. */ 86 #define EAGAIN (-11002) 89 87 90 88 /** No data. -
uspace/lib/c/include/ipc/dev_iface.h
r101ef25c r243cb86 54 54 DEV_IFACE_ID(DEV_FIRST_CUSTOM_METHOD_IDX) 55 55 56 /* 57 * The first argument is actually method (as the "real" method is used 58 * for indexing into interfaces. 59 */ 60 61 #define DEV_IPC_GET_ARG1(call) IPC_GET_ARG2((call)) 62 #define DEV_IPC_GET_ARG2(call) IPC_GET_ARG3((call)) 63 #define DEV_IPC_GET_ARG3(call) IPC_GET_ARG4((call)) 64 #define DEV_IPC_GET_ARG4(call) IPC_GET_ARG5((call)) 65 56 66 57 67 #endif -
uspace/lib/c/include/ipc/vfs.h
r101ef25c r243cb86 36 36 #define LIBC_IPC_VFS_H_ 37 37 38 #include <ipc/ipc.h> 38 39 #include <sys/types.h> 39 #include < ipc/ipc.h>40 #include <bool.h> 40 41 41 42 #define FS_NAME_MAXLEN 20 … … 55 56 /** Unique identifier of the fs. */ 56 57 char name[FS_NAME_MAXLEN + 1]; 58 bool concurrent_read_write; 59 bool write_retains_size; 57 60 } vfs_info_t; 58 61 -
uspace/lib/drv/generic/driver.c
r101ef25c r243cb86 381 381 } 382 382 383 /** Wrapper for child_device_register for devices with single match id. 384 * 385 * @param parent Parent device. 386 * @param child_name Child device name. 387 * @param child_match_id Child device match id. 388 * @param child_match_score Child device match score. 389 * @return Error code. 390 */ 391 int child_device_register_wrapper(device_t *parent, const char *child_name, 392 const char *child_match_id, int child_match_score, 393 devman_handle_t *child_handle) 394 { 395 device_t *child = NULL; 396 match_id_t *match_id = NULL; 397 int rc; 398 399 child = create_device(); 400 if (child == NULL) { 401 rc = ENOMEM; 402 goto failure; 403 } 404 405 child->name = child_name; 406 407 match_id = create_match_id(); 408 if (match_id == NULL) { 409 rc = ENOMEM; 410 goto failure; 411 } 412 413 match_id->id = child_match_id; 414 match_id->score = child_match_score; 415 add_match_id(&child->match_ids, match_id); 416 417 rc = child_device_register(child, parent); 418 if (EOK != rc) 419 goto failure; 420 421 if (child_handle != NULL) { 422 *child_handle = child->handle; 423 } 424 return EOK; 425 426 failure: 427 if (match_id != NULL) { 428 match_id->id = NULL; 429 delete_match_id(match_id); 430 } 431 432 if (child != NULL) { 433 child->name = NULL; 434 delete_device(child); 435 } 436 437 return rc; 438 } 439 383 440 int driver_main(driver_t *drv) 384 441 { -
uspace/lib/drv/generic/remote_usbhc.c
r101ef25c r243cb86 52 52 static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *); 53 53 static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 56 static void remote_usbhc_request_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 57 static void remote_usbhc_bind_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 58 static void remote_usbhc_release_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 59 //static void remote_usbhc(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 60 … … 57 62 static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = { 58 63 remote_usbhc_get_address, 64 59 65 remote_usbhc_get_buffer, 66 67 remote_usbhc_reserve_default_address, 68 remote_usbhc_release_default_address, 69 70 remote_usbhc_request_address, 71 remote_usbhc_bind_address, 72 remote_usbhc_release_address, 73 60 74 remote_usbhc_interrupt_out, 61 75 remote_usbhc_interrupt_in, 76 62 77 remote_usbhc_control_write_setup, 63 78 remote_usbhc_control_write_data, 64 79 remote_usbhc_control_write_status, 80 65 81 remote_usbhc_control_read_setup, 66 82 remote_usbhc_control_read_data, … … 92 108 } 93 109 94 devman_handle_t handle = IPC_GET_ARG1(*call);110 devman_handle_t handle = DEV_IPC_GET_ARG1(*call); 95 111 96 112 usb_address_t address; … … 106 122 ipc_callid_t callid, ipc_call_t *call) 107 123 { 108 ipcarg_t buffer_hash = IPC_GET_ARG1(*call);124 ipcarg_t buffer_hash = DEV_IPC_GET_ARG1(*call); 109 125 async_transaction_t * trans = (async_transaction_t *)buffer_hash; 110 126 if (trans == NULL) { … … 128 144 accepted_size = trans->size; 129 145 } 130 async_data_read_finalize(c allid, trans->buffer, accepted_size);146 async_data_read_finalize(cid, trans->buffer, accepted_size); 131 147 132 148 ipc_answer_1(callid, EOK, accepted_size); … … 134 150 free(trans->buffer); 135 151 free(trans); 152 } 153 154 void remote_usbhc_reserve_default_address(device_t *device, void *iface, 155 ipc_callid_t callid, ipc_call_t *call) 156 { 157 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 158 159 if (!usb_iface->reserve_default_address) { 160 ipc_answer_0(callid, ENOTSUP); 161 return; 162 } 163 164 int rc = usb_iface->reserve_default_address(device); 165 166 ipc_answer_0(callid, rc); 167 } 168 169 void remote_usbhc_release_default_address(device_t *device, void *iface, 170 ipc_callid_t callid, ipc_call_t *call) 171 { 172 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 173 174 if (!usb_iface->release_default_address) { 175 ipc_answer_0(callid, ENOTSUP); 176 return; 177 } 178 179 int rc = usb_iface->release_default_address(device); 180 181 ipc_answer_0(callid, rc); 182 } 183 184 void remote_usbhc_request_address(device_t *device, void *iface, 185 ipc_callid_t callid, ipc_call_t *call) 186 { 187 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 188 189 if (!usb_iface->request_address) { 190 ipc_answer_0(callid, ENOTSUP); 191 return; 192 } 193 194 usb_address_t address; 195 int rc = usb_iface->request_address(device, &address); 196 if (rc != EOK) { 197 ipc_answer_0(callid, rc); 198 } else { 199 ipc_answer_1(callid, EOK, (ipcarg_t) address); 200 } 201 } 202 203 void remote_usbhc_bind_address(device_t *device, void *iface, 204 ipc_callid_t callid, ipc_call_t *call) 205 { 206 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 207 208 if (!usb_iface->bind_address) { 209 ipc_answer_0(callid, ENOTSUP); 210 return; 211 } 212 213 usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call); 214 devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call); 215 216 int rc = usb_iface->bind_address(device, address, handle); 217 218 ipc_answer_0(callid, rc); 219 } 220 221 void remote_usbhc_release_address(device_t *device, void *iface, 222 ipc_callid_t callid, ipc_call_t *call) 223 { 224 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 225 226 if (!usb_iface->release_address) { 227 ipc_answer_0(callid, ENOTSUP); 228 return; 229 } 230 231 usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call); 232 233 int rc = usb_iface->release_address(device, address); 234 235 ipc_answer_0(callid, rc); 136 236 } 137 237 … … 175 275 } 176 276 177 size_t expected_len = IPC_GET_ARG3(*call);277 size_t expected_len = DEV_IPC_GET_ARG3(*call); 178 278 usb_target_t target = { 179 .address = IPC_GET_ARG1(*call),180 .endpoint = IPC_GET_ARG2(*call)279 .address = DEV_IPC_GET_ARG1(*call), 280 .endpoint = DEV_IPC_GET_ARG2(*call) 181 281 }; 182 282 … … 227 327 } 228 328 229 size_t len = IPC_GET_ARG3(*call);329 size_t len = DEV_IPC_GET_ARG3(*call); 230 330 usb_target_t target = { 231 .address = IPC_GET_ARG1(*call),232 .endpoint = IPC_GET_ARG2(*call)331 .address = DEV_IPC_GET_ARG1(*call), 332 .endpoint = DEV_IPC_GET_ARG2(*call) 233 333 }; 234 334 … … 284 384 285 385 usb_target_t target = { 286 .address = IPC_GET_ARG1(*call),287 .endpoint = IPC_GET_ARG2(*call)386 .address = DEV_IPC_GET_ARG1(*call), 387 .endpoint = DEV_IPC_GET_ARG2(*call) 288 388 }; 289 389 -
uspace/lib/drv/include/driver.h
r101ef25c r243cb86 199 199 200 200 int child_device_register(device_t *, device_t *); 201 int child_device_register_wrapper(device_t *, const char *, const char *, int, 202 devman_handle_t *); 201 203 202 204 -
uspace/lib/drv/include/usbhc_iface.h
r101ef25c r243cb86 111 111 112 112 113 /** Reserve usage of default address. 114 * This call informs the host controller that the caller will be 115 * using default USB address. It is duty of the HC driver to ensure 116 * that only single entity will have it reserved. 117 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS. 118 * The caller can start using the address after receiving EOK 119 * answer. 120 */ 121 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS, 122 123 /** Release usage of default address. 124 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS 125 */ 126 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS, 127 128 /** Asks for address assignment by host controller. 129 * Answer: 130 * - ELIMIT - host controller run out of address 131 * - EOK - address assigned 132 * Answer arguments: 133 * - assigned address 134 * 135 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS. 136 */ 137 IPC_M_USBHC_REQUEST_ADDRESS, 138 139 /** Bind USB address with devman handle. 140 * Parameters: 141 * - USB address 142 * - devman handle 143 * Answer: 144 * - EOK - address binded 145 * - ENOENT - address is not in use 146 */ 147 IPC_M_USBHC_BIND_ADDRESS, 148 149 /** Release address in use. 150 * Arguments: 151 * - address to be released 152 * Answer: 153 * - ENOENT - address not in use 154 * - EPERM - trying to release default USB address 155 */ 156 IPC_M_USBHC_RELEASE_ADDRESS, 157 158 113 159 /** Send interrupt data to device. 114 160 * See explanation at usb_iface_funcs_t (OUT transaction). … … 183 229 typedef struct { 184 230 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *); 231 232 int (*reserve_default_address)(device_t *); 233 int (*release_default_address)(device_t *); 234 int (*request_address)(device_t *, usb_address_t *); 235 int (*bind_address)(device_t *, usb_address_t, devman_handle_t); 236 int (*release_address)(device_t *, usb_address_t); 185 237 186 238 usbhc_iface_transfer_out_t interrupt_out; -
uspace/lib/usb/Makefile
r101ef25c r243cb86 33 33 34 34 SOURCES = \ 35 src/addrkeep.c \ 36 src/debug.c \ 37 src/drvpsync.c \ 35 38 src/hcdhubd.c \ 36 39 src/hcdrv.c \ 37 src/h ubdrv.c \40 src/hidparser.c \ 38 41 src/localdrv.c \ 39 42 src/remotedrv.c \ 40 43 src/usb.c \ 44 src/usbdrvreq.c \ 41 45 src/usbdrv.c 42 46 -
uspace/lib/usb/include/usb/classes/hid.h
r101ef25c r243cb86 38 38 #include <usb/usb.h> 39 39 #include <driver.h> 40 #include <usb/classes/hidparser.h> 40 41 41 42 /** USB/HID device requests. */ … … 66 67 usb_address_t address; 67 68 usb_endpoint_t default_ep; 69 usb_hid_report_parser_t *parser; 68 70 } usb_hid_dev_kbd_t; 69 71 -
uspace/lib/usb/include/usb/devreq.h
r101ef25c r243cb86 38 38 #include <ipc/ipc.h> 39 39 #include <async.h> 40 #include <usb/usb.h> 41 #include <usb/descriptor.h> 40 42 41 43 /** Standard device request. */ … … 83 85 } __attribute__ ((packed)) usb_device_request_setup_packet_t; 84 86 87 int usb_drv_req_set_address(int, usb_address_t, usb_address_t); 88 int usb_drv_req_get_device_descriptor(int, usb_address_t, 89 usb_standard_device_descriptor_t *); 90 int usb_drv_req_get_bare_configuration_descriptor(int, usb_address_t, int, 91 usb_standard_configuration_descriptor_t *); 92 int usb_drv_req_get_full_configuration_descriptor(int, usb_address_t, int, 93 void *, size_t, size_t *); 94 95 85 96 #endif 86 97 /** -
uspace/lib/usb/include/usb/hcdhubd.h
r101ef25c r243cb86 116 116 } usb_hcd_transfer_ops_t; 117 117 118 /** 119 * @brief structure holding information about free and used addresses 120 * 121 * This structure should not be used outside usb hcd driver. 122 * You better consider it to be 'private'. 123 */ 124 typedef struct { 125 /** lower bound included in the interval */ 126 usb_address_t lower_bound; 127 128 /** upper bound, excluded from the interval */ 129 usb_address_t upper_bound; 130 131 /** */ 132 link_t link; 133 }usb_address_list_t; 134 118 135 struct usb_hc_device { 119 136 /** Transfer operations. */ … … 131 148 /** List of hubs operating from this HC. */ 132 149 link_t hubs; 150 151 /** Structure with free and used addresses */ 152 link_t addresses; 133 153 134 154 /** Link to other driven HCs. */ … … 146 166 147 167 int usb_hcd_main(usb_hc_driver_t *); 148 int usb_hcd_add_root_hub(usb_hc_device_t *dev); 168 int usb_hcd_add_root_hub(device_t *dev); 169 170 /** 171 * find first not yet used address on this host controller and use it 172 * @param this_hcd 173 * @return number in the range of allowed usb addresses or 174 * a negative number if not succesful 175 */ 176 usb_address_t usb_use_free_address(usb_hc_device_t * this_hcd); 177 178 /** 179 * @brief free the address in the address space of this hcd. 180 * 181 * if address is not used, nothing happens 182 * @param this_hcd 183 * @param addr 184 */ 185 void usb_free_used_address(usb_hc_device_t * this_hcd, usb_address_t addr ); 149 186 150 187 … … 154 191 */ 155 192 193 device_t *usb_hc_connect(device_t *); 156 194 157 195 int usb_hc_async_interrupt_out(usb_hc_device_t *, usb_target_t, -
uspace/lib/usb/include/usb/usb.h
r101ef25c r243cb86 69 69 typedef int usb_address_t; 70 70 71 /** Default USB address. */ 72 #define USB_ADDRESS_DEFAULT 0 73 /** Maximum address number in USB 1.1. */ 74 #define USB11_ADDRESS_MAX 128 75 71 76 /** USB endpoint number type. 72 77 * Negative values could be used to indicate error. -
uspace/lib/usb/include/usb/usbdrv.h
r101ef25c r243cb86 36 36 #define LIBUSB_USBDRV_H_ 37 37 38 #include "usb.h"38 #include <usb/usb.h> 39 39 #include <driver.h> 40 #include <usb/devreq.h> 41 #include <usb/descriptor.h> 40 42 41 43 int usb_drv_hc_connect(device_t *, unsigned int); 44 45 int usb_drv_reserve_default_address(int); 46 int usb_drv_release_default_address(int); 47 usb_address_t usb_drv_request_address(int); 48 int usb_drv_bind_address(int, usb_address_t, devman_handle_t); 49 int usb_drv_release_address(int, usb_address_t); 42 50 43 51 usb_address_t usb_drv_get_my_address(int, device_t *); … … 48 56 void *, size_t, size_t *, usb_handle_t *); 49 57 58 int usb_drv_psync_interrupt_out(int, usb_target_t, void *, size_t); 59 int usb_drv_psync_interrupt_in(int, usb_target_t, void *, size_t, size_t *); 60 61 62 50 63 int usb_drv_async_control_write_setup(int, usb_target_t, 51 64 void *, size_t, usb_handle_t *); … … 54 67 int usb_drv_async_control_write_status(int, usb_target_t, 55 68 usb_handle_t *); 69 70 int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t); 71 int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t); 72 int usb_drv_psync_control_write_status(int, usb_target_t); 73 74 int usb_drv_psync_control_write(int, usb_target_t, 75 void *, size_t, void *, size_t); 76 56 77 57 78 int usb_drv_async_control_read_setup(int, usb_target_t, … … 62 83 usb_handle_t *); 63 84 85 int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t); 86 int usb_drv_psync_control_read_data(int, usb_target_t, void *, size_t, size_t *); 87 int usb_drv_psync_control_read_status(int, usb_target_t); 88 89 int usb_drv_psync_control_read(int, usb_target_t, 90 void *, size_t, void *, size_t, size_t *); 91 92 93 64 94 int usb_drv_async_wait_for(usb_handle_t); 95 65 96 66 97 #endif -
uspace/lib/usb/src/hcdhubd.c
r101ef25c r243cb86 51 51 */ 52 52 static int add_device(device_t *dev) { 53 bool is_hc = str_cmp(dev->name, USB_HUB_DEVICE_NAME) != 0; 54 printf("%s: add_device(name=\"%s\")\n", hc_driver->name, dev->name); 55 56 if (is_hc) { 57 /* 58 * We are the HC itself. 59 */ 60 return usb_add_hc_device(dev); 61 } else { 62 /* 63 * We are some (maybe deeply nested) hub. 64 * Thus, assign our own operations and explore already 65 * connected devices. 66 */ 67 return usb_add_hub_device(dev); 68 } 53 return ENOTSUP; 69 54 } 70 55 … … 105 90 * @return Error code. 106 91 */ 107 int usb_hcd_add_root_hub( usb_hc_device_t *dev)92 int usb_hcd_add_root_hub(device_t *dev) 108 93 { 109 94 char *id; 110 int rc = asprintf(&id, "usb&h c=%s&hub", hc_driver->name);95 int rc = asprintf(&id, "usb&hub"); 111 96 if (rc <= 0) { 112 97 return rc; 113 98 } 114 99 115 rc = usb_hc_add_child_device(dev ->generic, USB_HUB_DEVICE_NAME, id, true);100 rc = usb_hc_add_child_device(dev, USB_HUB_DEVICE_NAME, id, true); 116 101 if (rc != EOK) { 117 102 free(id); … … 129 114 130 115 /** Adds a child device fibril worker. */ 131 static int fibril_add_child_device(void *arg) 132 { 116 static int fibril_add_child_device(void *arg) { 133 117 struct child_device_info *child_info 134 = (struct child_device_info *) arg;118 = (struct child_device_info *) arg; 135 119 int rc; 136 120 … … 156 140 157 141 printf("%s: adding child device `%s' with match \"%s\"\n", 158 hc_driver->name, child->name, match_id->id);142 hc_driver->name, child->name, match_id->id); 159 143 rc = child_device_register(child, child_info->parent); 160 144 printf("%s: child device `%s' registration: %s\n", 161 hc_driver->name, child->name, str_error(rc));145 hc_driver->name, child->name, str_error(rc)); 162 146 163 147 if (rc != EOK) { … … 197 181 */ 198 182 int usb_hc_add_child_device(device_t *parent, const char *name, 199 const char *match_id, bool create_fibril) 200 { 183 const char *match_id, bool create_fibril) { 201 184 printf("%s: about to add child device `%s' (%s)\n", hc_driver->name, 202 name, match_id);185 name, match_id); 203 186 204 187 /* … … 209 192 210 193 struct child_device_info *child_info 211 = malloc(sizeof(struct child_device_info));194 = malloc(sizeof (struct child_device_info)); 212 195 213 196 child_info->parent = parent; … … 233 216 * @return USB device address or error code. 234 217 */ 235 usb_address_t usb_get_address_by_handle(devman_handle_t handle) 236 { 218 usb_address_t usb_get_address_by_handle(devman_handle_t handle) { 237 219 /* TODO: search list of attached devices. */ 238 220 return ENOENT; 239 221 } 240 222 223 usb_address_t usb_use_free_address(usb_hc_device_t * this_hcd) { 224 //is there free address? 225 link_t * addresses = &this_hcd->addresses; 226 if (list_empty(addresses)) return -1; 227 link_t * link_addr = addresses; 228 bool found = false; 229 usb_address_list_t * range = NULL; 230 while (!found) { 231 link_addr = link_addr->next; 232 if (link_addr == addresses) return -2; 233 range = list_get_instance(link_addr, 234 usb_address_list_t, link); 235 if (range->upper_bound - range->lower_bound > 0) { 236 found = true; 237 } 238 } 239 //now we have interval 240 int result = range->lower_bound; 241 ++(range->lower_bound); 242 if (range->upper_bound - range->lower_bound == 0) { 243 list_remove(&range->link); 244 free(range); 245 } 246 return result; 247 } 248 249 void usb_free_used_address(usb_hc_device_t * this_hcd, usb_address_t addr) { 250 //check range 251 if (addr < usb_lowest_address || addr > usb_highest_address) 252 return; 253 link_t * addresses = &this_hcd->addresses; 254 link_t * link_addr = addresses; 255 //find 'good' interval 256 usb_address_list_t * found_range = NULL; 257 bool found = false; 258 while (!found) { 259 link_addr = link_addr->next; 260 if (link_addr == addresses) { 261 found = true; 262 } else { 263 usb_address_list_t * range = list_get_instance(link_addr, 264 usb_address_list_t, link); 265 if ( (range->lower_bound - 1 == addr) || 266 (range->upper_bound == addr)) { 267 found = true; 268 found_range = range; 269 } 270 if (range->lower_bound - 1 > addr) { 271 found = true; 272 } 273 274 } 275 } 276 if (found_range == NULL) { 277 //no suitable range found 278 usb_address_list_t * result_range = 279 (usb_address_list_t*) malloc(sizeof (usb_address_list_t)); 280 result_range->lower_bound = addr; 281 result_range->upper_bound = addr + 1; 282 list_insert_before(&result_range->link, link_addr); 283 } else { 284 //we have good range 285 if (found_range->lower_bound - 1 == addr) { 286 --found_range->lower_bound; 287 } else { 288 //only one possible case 289 ++found_range->upper_bound; 290 if (found_range->link.next != addresses) { 291 usb_address_list_t * next_range = 292 list_get_instance( &found_range->link.next, 293 usb_address_list_t, link); 294 //check neighbour range 295 if (next_range->lower_bound == addr + 1) { 296 //join ranges 297 found_range->upper_bound = next_range->upper_bound; 298 list_remove(&next_range->link); 299 free(next_range); 300 } 301 } 302 } 303 } 304 305 } 306 241 307 /** 242 308 * @} -
uspace/lib/usb/src/hcdhubd_private.h
r101ef25c r243cb86 46 46 usb_address_t usb_get_address_by_handle(devman_handle_t); 47 47 int usb_add_hc_device(device_t *); 48 int usb_add_hub_device(device_t *); 48 49 /** lowest allowed usb address */ 50 extern int usb_lowest_address; 51 52 /** highest allowed usb address */ 53 extern int usb_highest_address; 54 55 /** 56 * @brief initialize address list of given hcd 57 * 58 * This function should be used only for hcd initialization. 59 * It creates interval list of free addresses, thus it is initialized as 60 * list with one interval with whole address space. Using an address shrinks 61 * the interval, freeing an address extends an interval or creates a 62 * new one. 63 * 64 * @param hcd 65 * @return 66 */ 67 void usb_create_address_list(usb_hc_device_t * hcd); 68 69 70 71 72 49 73 50 74 #endif -
uspace/lib/usb/src/hcdrv.c
r101ef25c r243cb86 47 47 LIST_INITIALIZE(hc_list); 48 48 49 /* Fake driver to have the name item initialized. */ 50 static usb_hc_driver_t hc_driver_fake = { 51 .name = "HCD", 52 }; 53 49 54 /** Our HC driver. */ 50 usb_hc_driver_t *hc_driver = NULL; 55 usb_hc_driver_t *hc_driver = &hc_driver_fake; 56 57 int usb_lowest_address = 1; 58 59 int usb_highest_address = 255; 51 60 52 61 static device_ops_t usb_device_ops = { 53 62 .interfaces[USBHC_DEV_IFACE] = &usbhc_interface 54 63 }; 64 65 66 void usb_create_address_list(usb_hc_device_t * hcd){ 67 list_initialize(&hcd->addresses); 68 usb_address_list_t * range = 69 (usb_address_list_t*)malloc(sizeof(usb_address_list_t)); 70 range->lower_bound = usb_lowest_address; 71 range->upper_bound = usb_highest_address + 1; 72 list_append(&range->link, &hcd->addresses); 73 } 55 74 56 75 static usb_hc_device_t *usb_hc_device_create(device_t *dev) { … … 59 78 list_initialize(&hc_dev->link); 60 79 list_initialize(&hc_dev->hubs); 80 usb_create_address_list(hc_dev); 61 81 list_initialize(&hc_dev->attached_devices); 62 82 hc_dev->transfer_ops = NULL; … … 71 91 int usb_add_hc_device(device_t *dev) 72 92 { 93 return ENOTSUP; 73 94 usb_hc_device_t *hc_dev = usb_hc_device_create(dev); 74 95 -
uspace/lib/usb/src/localdrv.c
r101ef25c r243cb86 39 39 #include <errno.h> 40 40 41 /** Find host controller when handled by current task. 42 * 43 * @param dev Device asking for connection. 44 * @return Device structure corresponding to parent host controller. 45 * @retval NULL Corresponding host controller not found. 46 */ 47 device_t *usb_hc_connect(device_t *dev) 48 { 49 /* 50 * FIXME: this will not work when some hub on the path is 51 * not driven by the same task. 52 */ 53 device_t *parent = dev; 54 while (parent->parent != NULL) { 55 parent = parent->parent; 56 } 57 58 if (dev == parent) { 59 printf("FIXME in %s:%d encountered!\n", __FILE__, __LINE__); 60 parent = NULL; 61 } 62 63 return parent; 64 } 65 41 66 /** Information about pending transaction on HC. */ 42 67 typedef struct { -
uspace/lib/usb/src/remotedrv.c
r101ef25c r243cb86 300 300 */ 301 301 static void remote_in_callback(usb_hc_device_t *hc, 302 usb_transaction_outcome_t outcome, size_t actual_size, void *arg)302 size_t actual_size, usb_transaction_outcome_t outcome, void *arg) 303 303 { 304 304 transfer_info_t *transfer = (transfer_info_t *) arg; -
uspace/lib/usb/src/usbdrv.c
r101ef25c r243cb86 55 55 /** Connect to host controller the device is physically attached to. 56 56 * 57 * @param handle Device handle.57 * @param dev Device asking for connection. 58 58 * @param flags Connection flags (blocking connection). 59 59 * @return Phone to corresponding HC or error code. … … 71 71 devman_handle_t handle; 72 72 73 rc = devman_device_get_handle("/v hc", &handle, 0);73 rc = devman_device_get_handle("/virt/usbhc", &handle, 0); 74 74 if (rc != EOK) { 75 75 return rc; … … 98 98 99 99 return (usb_address_t) address; 100 } 101 102 /** Tell HC to reserve default address. 103 * 104 * @param phone Open phone to host controller driver. 105 * @return Error code. 106 */ 107 int usb_drv_reserve_default_address(int phone) 108 { 109 return async_req_0_0(phone, IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS); 110 } 111 112 /** Tell HC to release default address. 113 * 114 * @param phone Open phone to host controller driver. 115 * @return Error code. 116 */ 117 int usb_drv_release_default_address(int phone) 118 { 119 return async_req_0_0(phone, IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS); 120 } 121 122 /** Ask HC for free address assignment. 123 * 124 * @param phone Open phone to host controller driver. 125 * @return Assigned USB address or negative error code. 126 */ 127 usb_address_t usb_drv_request_address(int phone) 128 { 129 ipcarg_t address; 130 int rc = async_req_0_1(phone, IPC_M_USBHC_REQUEST_ADDRESS, &address); 131 if (rc != EOK) { 132 return rc; 133 } else { 134 return (usb_address_t) address; 135 } 136 } 137 138 /** Inform HC about binding address with devman handle. 139 * 140 * @param phone Open phone to host controller driver. 141 * @param address Address to be binded. 142 * @param handle Devman handle of the device. 143 * @return Error code. 144 */ 145 int usb_drv_bind_address(int phone, usb_address_t address, 146 devman_handle_t handle) 147 { 148 int rc = async_req_2_0(phone, IPC_M_USBHC_BIND_ADDRESS, 149 address, handle); 150 151 return rc; 152 } 153 154 /** Inform HC about address release. 155 * 156 * @param phone Open phone to host controller driver. 157 * @param address Address to be released. 158 * @return Error code. 159 */ 160 int usb_drv_release_address(int phone, usb_address_t address) 161 { 162 return async_req_1_0(phone, IPC_M_USBHC_RELEASE_ADDRESS, address); 100 163 } 101 164 -
uspace/lib/usbvirt/main.c
r101ef25c r243cb86 183 183 } 184 184 185 /** Create necessary phones for com unication with virtual HCD.185 /** Create necessary phones for communication with virtual HCD. 186 186 * This function wraps following calls: 187 * -# open <code>/dev/devices/\\v hc for reading187 * -# open <code>/dev/devices/\\virt\\usbhc for reading 188 188 * -# access phone of file opened in previous step 189 189 * -# create callback through just opened phone … … 193 193 * @warning This function is wrapper for several actions and therefore 194 194 * it is not possible - in case of error - to determine at which point 195 * error occured. 196 * 197 * @param hcd_path HCD identification under devfs 198 * (without <code>/dev/usb/</code>). 195 * error occurred. 196 * 199 197 * @param dev Device to connect. 200 198 * @return EOK on success or error code from errno.h. … … 207 205 } 208 206 209 const char *vhc_path = "/v hc";207 const char *vhc_path = "/virt/usbhc"; 210 208 int rc; 211 209 devman_handle_t handle;
Note:
See TracChangeset
for help on using the changeset viewer.
