Changeset 71b0d4d4 in mainline for uspace/srv/bd/ata_bd/ata_bd.c
- Timestamp:
- 2012-08-14T03:37:30Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b224a3e
- Parents:
- 2988aec7 (diff), 4802dd7 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
r2988aec7 r71b0d4d4 51 51 #include <libarch/ddi.h> 52 52 #include <ddi.h> 53 #include <ipc/bd.h>54 53 #include <async.h> 55 54 #include <as.h> 55 #include <bd_srv.h> 56 56 #include <fibril_synch.h> 57 57 #include <stdint.h> … … 98 98 99 99 /** Per-disk state. */ 100 static disk_t disk[MAX_DISKS];100 static disk_t ata_disk[MAX_DISKS]; 101 101 102 102 static void print_syntax(void); 103 103 static int ata_bd_init(void); 104 104 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *); 105 static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt, 106 void *buf); 107 static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt, 108 const void *buf); 105 106 static int ata_bd_open(bd_srv_t *); 107 static int ata_bd_close(bd_srv_t *); 108 static int ata_bd_read_blocks(bd_srv_t *, uint64_t ba, size_t cnt, void *buf, 109 size_t); 110 static int ata_bd_read_toc(bd_srv_t *, uint8_t session, void *buf, size_t); 111 static int ata_bd_write_blocks(bd_srv_t *, uint64_t ba, size_t cnt, 112 const void *buf, size_t); 113 static int ata_bd_get_block_size(bd_srv_t *, size_t *); 114 static int ata_bd_get_num_blocks(bd_srv_t *, aoff64_t *); 115 109 116 static int ata_rcmd_read(int disk_id, uint64_t ba, size_t cnt, 110 117 void *buf); … … 127 134 unsigned timeout); 128 135 136 static bd_ops_t ata_bd_ops = { 137 .open = ata_bd_open, 138 .close = ata_bd_close, 139 .read_blocks = ata_bd_read_blocks, 140 .read_toc = ata_bd_read_toc, 141 .write_blocks = ata_bd_write_blocks, 142 .get_block_size = ata_bd_get_block_size, 143 .get_num_blocks = ata_bd_get_num_blocks 144 }; 145 146 static disk_t *bd_srv_disk(bd_srv_t *bd) 147 { 148 return (disk_t *)bd->arg; 149 } 150 129 151 int main(int argc, char **argv) 130 152 { … … 161 183 fflush(stdout); 162 184 163 rc = disk_init(& disk[i], i);185 rc = disk_init(&ata_disk[i], i); 164 186 165 187 if (rc == EOK) { 166 disk_print_summary(& disk[i]);188 disk_print_summary(&ata_disk[i]); 167 189 } else { 168 190 printf("Not found.\n"); … … 174 196 for (i = 0; i < MAX_DISKS; i++) { 175 197 /* Skip unattached drives. */ 176 if ( disk[i].present == false)198 if (ata_disk[i].present == false) 177 199 continue; 178 200 179 201 snprintf(name, 16, "%s/ata%udisk%d", NAMESPACE, ctl_num, i); 180 rc = loc_service_register(name, & disk[i].service_id);202 rc = loc_service_register(name, &ata_disk[i].service_id); 181 203 if (rc != EOK) { 182 204 printf(NAME ": Unable to register device %s.\n", name); … … 217 239 case am_chs: 218 240 printf("CHS %u cylinders, %u heads, %u sectors", 219 d isk->geom.cylinders, disk->geom.heads,220 d isk->geom.sectors);241 d->geom.cylinders, d->geom.heads, 242 d->geom.sectors); 221 243 break; 222 244 case am_lba28: … … 273 295 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 274 296 { 275 void *fs_va = NULL;276 ipc_callid_t callid;277 ipc_call_t call;278 sysarg_t method;279 297 service_id_t dsid; 280 size_t comm_size; /**< Size of the communication area. */281 unsigned int flags;282 int retval;283 uint64_t ba;284 size_t cnt;285 298 int disk_id, i; 286 299 … … 291 304 disk_id = -1; 292 305 for (i = 0; i < MAX_DISKS; i++) 293 if ( disk[i].service_id == dsid)306 if (ata_disk[i].service_id == dsid) 294 307 disk_id = i; 295 308 296 if (disk_id < 0 || disk[disk_id].present == false) {309 if (disk_id < 0 || ata_disk[disk_id].present == false) { 297 310 async_answer_0(iid, EINVAL); 298 311 return; 299 312 } 300 313 301 /* Answer the IPC_M_CONNECT_ME_TO call. */ 302 async_answer_0(iid, EOK); 303 304 if (!async_share_out_receive(&callid, &comm_size, &flags)) { 305 async_answer_0(callid, EHANGUP); 306 return; 307 } 308 309 (void) async_share_out_finalize(callid, &fs_va); 310 if (fs_va == AS_MAP_FAILED) { 311 async_answer_0(callid, EHANGUP); 312 return; 313 } 314 315 while (true) { 316 callid = async_get_call(&call); 317 method = IPC_GET_IMETHOD(call); 318 319 if (!method) { 320 /* The other side has hung up. */ 321 async_answer_0(callid, EOK); 322 return; 323 } 324 325 switch (method) { 326 case BD_READ_BLOCKS: 327 ba = MERGE_LOUP32(IPC_GET_ARG1(call), 328 IPC_GET_ARG2(call)); 329 cnt = IPC_GET_ARG3(call); 330 if (cnt * disk[disk_id].block_size > comm_size) { 331 retval = ELIMIT; 332 break; 333 } 334 retval = ata_bd_read_blocks(disk_id, ba, cnt, fs_va); 335 break; 336 case BD_WRITE_BLOCKS: 337 ba = MERGE_LOUP32(IPC_GET_ARG1(call), 338 IPC_GET_ARG2(call)); 339 cnt = IPC_GET_ARG3(call); 340 if (cnt * disk[disk_id].block_size > comm_size) { 341 retval = ELIMIT; 342 break; 343 } 344 retval = ata_bd_write_blocks(disk_id, ba, cnt, fs_va); 345 break; 346 case BD_GET_BLOCK_SIZE: 347 async_answer_1(callid, EOK, disk[disk_id].block_size); 348 continue; 349 case BD_GET_NUM_BLOCKS: 350 async_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks), 351 UPPER32(disk[disk_id].blocks)); 352 continue; 353 case BD_READ_TOC: 354 cnt = IPC_GET_ARG1(call); 355 if (disk[disk_id].dev_type == ata_pkt_dev) 356 retval = ata_pcmd_read_toc(disk_id, cnt, fs_va, 357 disk[disk_id].block_size); 358 else 359 retval = EINVAL; 360 break; 361 default: 362 retval = EINVAL; 363 break; 364 } 365 async_answer_0(callid, retval); 366 } 314 bd_conn(iid, icall, &ata_disk[disk_id].bd); 367 315 } 368 316 … … 384 332 unsigned i; 385 333 334 d->disk_id = disk_id; 386 335 d->present = false; 387 336 fibril_mutex_initialize(&d->lock); 337 338 bd_srv_init(&d->bd); 339 d->bd.ops = &ata_bd_ops; 340 d->bd.arg = d; 388 341 389 342 /* Try identify command. */ … … 514 467 } 515 468 469 static int ata_bd_open(bd_srv_t *bd) 470 { 471 return EOK; 472 } 473 474 static int ata_bd_close(bd_srv_t *bd) 475 { 476 return EOK; 477 } 478 516 479 /** Read multiple blocks from the device. */ 517 static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt, 518 void *buf) { 519 480 static int ata_bd_read_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, 481 void *buf, size_t size) 482 { 483 disk_t *disk = bd_srv_disk(bd); 520 484 int rc; 521 485 486 if (size < cnt * disk->block_size) 487 return EINVAL; 488 522 489 while (cnt > 0) { 523 if (disk [disk_id].dev_type == ata_reg_dev)524 rc = ata_rcmd_read(disk _id, ba, 1, buf);490 if (disk->dev_type == ata_reg_dev) 491 rc = ata_rcmd_read(disk->disk_id, ba, 1, buf); 525 492 else 526 rc = ata_pcmd_read_12(disk _id, ba, 1, buf,527 disk [disk_id].block_size);493 rc = ata_pcmd_read_12(disk->disk_id, ba, 1, buf, 494 disk->block_size); 528 495 529 496 if (rc != EOK) … … 532 499 ++ba; 533 500 --cnt; 534 buf += disk[disk_id].block_size; 535 } 536 537 return EOK; 501 buf += disk->block_size; 502 } 503 504 return EOK; 505 } 506 507 /** Read TOC from device. */ 508 static int ata_bd_read_toc(bd_srv_t *bd, uint8_t session, void *buf, size_t size) 509 { 510 disk_t *disk = bd_srv_disk(bd); 511 512 return ata_pcmd_read_toc(disk->disk_id, session, buf, size); 538 513 } 539 514 540 515 /** Write multiple blocks to the device. */ 541 static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt, 542 const void *buf) { 543 516 static int ata_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, 517 const void *buf, size_t size) 518 { 519 disk_t *disk = bd_srv_disk(bd); 544 520 int rc; 545 521 546 if (disk [disk_id].dev_type != ata_reg_dev)522 if (disk->dev_type != ata_reg_dev) 547 523 return ENOTSUP; 548 524 525 if (size < cnt * disk->block_size) 526 return EINVAL; 527 549 528 while (cnt > 0) { 550 rc = ata_rcmd_write(disk _id, ba, 1, buf);529 rc = ata_rcmd_write(disk->disk_id, ba, 1, buf); 551 530 if (rc != EOK) 552 531 return rc; … … 554 533 ++ba; 555 534 --cnt; 556 buf += disk[disk_id].block_size; 557 } 558 535 buf += disk->block_size; 536 } 537 538 return EOK; 539 } 540 541 /** Get device block size. */ 542 static int ata_bd_get_block_size(bd_srv_t *bd, size_t *rbsize) 543 { 544 disk_t *disk = bd_srv_disk(bd); 545 546 *rbsize = disk->block_size; 547 return EOK; 548 } 549 550 /** Get device number of blocks. */ 551 static int ata_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 552 { 553 disk_t *disk = bd_srv_disk(bd); 554 555 *rnb = disk->blocks; 559 556 return EOK; 560 557 } … … 685 682 uint16_t val; 686 683 687 d = & disk[dev_idx];684 d = &ata_disk[dev_idx]; 688 685 fibril_mutex_lock(&d->lock); 689 686 … … 874 871 block_coord_t bc; 875 872 876 d = & disk[disk_id];873 d = &ata_disk[disk_id]; 877 874 878 875 /* Silence warning. */ … … 919 916 /* Read data from the device buffer. */ 920 917 921 for (i = 0; i < disk[disk_id].block_size / 2; i++) {918 for (i = 0; i < ata_disk[disk_id].block_size / 2; i++) { 922 919 data = pio_read_16(&cmd->data_port); 923 920 ((uint16_t *) buf)[i] = data; … … 950 947 block_coord_t bc; 951 948 952 d = & disk[disk_id];949 d = &ata_disk[disk_id]; 953 950 954 951 /* Silence warning. */ … … 995 992 /* Write data to the device buffer. */ 996 993 997 for (i = 0; i < d isk[disk_id].block_size / 2; i++) {994 for (i = 0; i < d->block_size / 2; i++) { 998 995 pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]); 999 996 }
Note:
See TracChangeset
for help on using the changeset viewer.