Changeset a830611 in mainline
- Timestamp:
- 2009-08-30T22:27:49Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 00b1d20e, cfa8738
- Parents:
- 1ee00b7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r1ee00b7 ra830611 75 75 dev_handle_t dev_handle; 76 76 int dev_phone; 77 fibril_mutex_t com _area_lock;78 void *com _area;79 size_t com _size;77 fibril_mutex_t comm_area_lock; 78 void *comm_area; 79 size_t comm_size; 80 80 void *bb_buf; 81 81 bn_t bb_addr; … … 105 105 106 106 static int devcon_add(dev_handle_t dev_handle, int dev_phone, size_t bsize, 107 void *com _area, size_t com_size)107 void *comm_area, size_t comm_size) 108 108 { 109 109 link_t *cur; 110 110 devcon_t *devcon; 111 111 112 if (com _size < bsize)112 if (comm_size < bsize) 113 113 return EINVAL; 114 114 … … 120 120 devcon->dev_handle = dev_handle; 121 121 devcon->dev_phone = dev_phone; 122 fibril_mutex_initialize(&devcon->com _area_lock);123 devcon->com _area = com_area;124 devcon->com _size = com_size;122 fibril_mutex_initialize(&devcon->comm_area_lock); 123 devcon->comm_area = comm_area; 124 devcon->comm_size = comm_size; 125 125 devcon->bb_buf = NULL; 126 126 devcon->bb_addr = 0; … … 149 149 } 150 150 151 int block_init(dev_handle_t dev_handle, size_t com _size)151 int block_init(dev_handle_t dev_handle, size_t comm_size) 152 152 { 153 153 int rc; 154 154 int dev_phone; 155 void *com _area;155 void *comm_area; 156 156 size_t bsize; 157 157 158 com _area = mmap(NULL, com_size, PROTO_READ | PROTO_WRITE,158 comm_area = mmap(NULL, comm_size, PROTO_READ | PROTO_WRITE, 159 159 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); 160 if (!com _area) {160 if (!comm_area) { 161 161 return ENOMEM; 162 162 } … … 164 164 dev_phone = devmap_device_connect(dev_handle, IPC_FLAG_BLOCKING); 165 165 if (dev_phone < 0) { 166 munmap(com _area, com_size);166 munmap(comm_area, comm_size); 167 167 return dev_phone; 168 168 } 169 169 170 rc = ipc_share_out_start(dev_phone, com _area,170 rc = ipc_share_out_start(dev_phone, comm_area, 171 171 AS_AREA_READ | AS_AREA_WRITE); 172 172 if (rc != EOK) { 173 munmap(com _area, com_size);173 munmap(comm_area, comm_size); 174 174 ipc_hangup(dev_phone); 175 175 return rc; … … 177 177 178 178 if (get_block_size(dev_phone, &bsize) != EOK) { 179 munmap(com _area, com_size);179 munmap(comm_area, comm_size); 180 180 ipc_hangup(dev_phone); 181 181 return rc; 182 182 } 183 183 184 rc = devcon_add(dev_handle, dev_phone, bsize, com _area, com_size);184 rc = devcon_add(dev_handle, dev_phone, bsize, comm_area, comm_size); 185 185 if (rc != EOK) { 186 munmap(com _area, com_size);186 munmap(comm_area, comm_size); 187 187 ipc_hangup(dev_phone); 188 188 return rc; … … 207 207 } 208 208 209 munmap(devcon->com _area, devcon->com_size);209 munmap(devcon->comm_area, devcon->comm_size); 210 210 ipc_hangup(devcon->dev_phone); 211 211 … … 227 227 return ENOMEM; 228 228 229 fibril_mutex_lock(&devcon->com _area_lock);229 fibril_mutex_lock(&devcon->comm_area_lock); 230 230 rc = read_blocks(devcon, 0, 1); 231 231 if (rc != EOK) { 232 fibril_mutex_unlock(&devcon->com _area_lock);232 fibril_mutex_unlock(&devcon->comm_area_lock); 233 233 free(bb_buf); 234 234 return rc; 235 235 } 236 memcpy(bb_buf, devcon->com _area, devcon->pblock_size);237 fibril_mutex_unlock(&devcon->com _area_lock);236 memcpy(bb_buf, devcon->comm_area, devcon->pblock_size); 237 fibril_mutex_unlock(&devcon->comm_area_lock); 238 238 239 239 devcon->bb_buf = bb_buf; … … 412 412 list_append(&b->free_link, &cache->free_head); 413 413 fibril_mutex_unlock(&cache->lock); 414 fibril_mutex_lock(&devcon->com _area_lock);415 memcpy(devcon->com _area, b->data, b->size);414 fibril_mutex_lock(&devcon->comm_area_lock); 415 memcpy(devcon->comm_area, b->data, b->size); 416 416 rc = write_blocks(devcon, b->boff, 1); 417 fibril_mutex_unlock(&devcon->com _area_lock);417 fibril_mutex_unlock(&devcon->comm_area_lock); 418 418 if (rc != EOK) { 419 419 /* … … 467 467 * the new contents from the device. 468 468 */ 469 fibril_mutex_lock(&devcon->com _area_lock);469 fibril_mutex_lock(&devcon->comm_area_lock); 470 470 rc = read_blocks(devcon, b->boff, 1); 471 memcpy(b->data, devcon->com _area, cache->lblock_size);472 fibril_mutex_unlock(&devcon->com _area_lock);471 memcpy(b->data, devcon->comm_area, cache->lblock_size); 472 fibril_mutex_unlock(&devcon->comm_area_lock); 473 473 if (rc != EOK) 474 474 b->toxic = true; … … 521 521 if (block->dirty && (block->refcnt == 1) && 522 522 (blocks_cached > CACHE_HI_WATERMARK || mode != CACHE_MODE_WB)) { 523 fibril_mutex_lock(&devcon->com _area_lock);524 memcpy(devcon->com _area, block->data, block->size);523 fibril_mutex_lock(&devcon->comm_area_lock); 524 memcpy(devcon->comm_area, block->data, block->size); 525 525 rc = write_blocks(devcon, block->boff, 1); 526 fibril_mutex_unlock(&devcon->com _area_lock);526 fibril_mutex_unlock(&devcon->comm_area_lock); 527 527 block->dirty = false; 528 528 } … … 612 612 block_size = devcon->pblock_size; 613 613 614 fibril_mutex_lock(&devcon->com _area_lock);614 fibril_mutex_lock(&devcon->comm_area_lock); 615 615 while (left > 0) { 616 616 size_t rd; … … 626 626 * destination buffer. 627 627 */ 628 memcpy(dst + offset, devcon->com _area + *bufpos, rd);628 memcpy(dst + offset, devcon->comm_area + *bufpos, rd); 629 629 offset += rd; 630 630 *bufpos += rd; … … 639 639 rc = read_blocks(devcon, *pos / block_size, 1); 640 640 if (rc != EOK) { 641 fibril_mutex_unlock(&devcon->com _area_lock);641 fibril_mutex_unlock(&devcon->comm_area_lock); 642 642 return rc; 643 643 } … … 647 647 } 648 648 } 649 fibril_mutex_unlock(&devcon->com _area_lock);649 fibril_mutex_unlock(&devcon->comm_area_lock); 650 650 651 651 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.