Changeset 0e6dce8 in mainline
- Timestamp:
- 2009-08-22T13:58:10Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b94334f
- Parents:
- a71c158
- Location:
- uspace/srv/bd/ata_bd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
ra71c158 r0e6dce8 50 50 #include <as.h> 51 51 #include <fibril_sync.h> 52 #include <string.h> 52 53 #include <devmap.h> 53 54 #include <sys/types.h> … … 85 86 static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 86 87 const void *buf); 87 static int drive_identify(int drive_id, disk_t *d); 88 static int disk_init(disk_t *d, int disk_id); 89 static int drive_identify(int drive_id, void *buf); 88 90 static int wait_status(unsigned set, unsigned n_reset, uint8_t *pstatus, 89 91 unsigned timeout); … … 106 108 fflush(stdout); 107 109 108 rc = d rive_identify(i, &disk[i]);110 rc = disk_init(&disk[i], i); 109 111 110 112 if (rc == EOK) { 111 printf("%u cylinders, %u heads, %u sectors\n", 112 disk[i].cylinders, disk[i].heads, disk[i].sectors); 113 printf("%s: %u cylinders, %u heads, %u sectors.\n", 114 disk[i].model, disk[i].cylinders, disk[i].heads, 115 disk[i].sectors); 113 116 } else { 114 117 printf("Not found.\n"); … … 251 254 } 252 255 256 /** Initialize a disk. 257 * 258 * Probes for a disk, determines its parameters and initializes 259 * the disk structure. 260 */ 261 static int disk_init(disk_t *d, int disk_id) 262 { 263 uint16_t buf[256]; 264 uint8_t model[40]; 265 uint16_t w; 266 uint8_t c; 267 size_t pos, len; 268 int rc; 269 int i; 270 271 rc = drive_identify(disk_id, buf); 272 if (rc != EOK) { 273 d->present = false; 274 return rc; 275 } 276 277 d->cylinders = buf[1]; 278 d->heads = buf[3]; 279 d->sectors = buf[6]; 280 281 d->blocks = d->cylinders * d->heads * d->sectors; 282 283 /* 284 * Convert model name to string representation. 285 */ 286 for (i = 0; i < 20; i++) { 287 w = buf[27 + i]; 288 model[2 * i] = w >> 8; 289 model[2 * i + 1] = w & 0x00ff; 290 } 291 292 len = 40; 293 while (len > 0 && model[len - 1] == 0x20) 294 --len; 295 296 pos = 0; 297 for (i = 0; i < len; ++i) { 298 c = model[i]; 299 if (c >= 0x80) c = '?'; 300 301 chr_encode(c, d->model, &pos, 40); 302 } 303 d->model[pos] = '\0'; 304 305 d->present = true; 306 fibril_mutex_initialize(&d->lock); 307 308 return EOK; 309 } 310 253 311 /** Transfer a logical block from/to the device. 254 312 * … … 294 352 /** Issue IDENTIFY command. 295 353 * 296 * This is used to detect whether an ATA device is present and if so,297 * to determine its parameters. The parameters are written to @a d.354 * Reads @c identify data into the provided buffer. This is used to detect 355 * whether an ATA device is present and if so, to determine its parameters. 298 356 * 299 357 * @param disk_id Device ID, 0 or 1. 300 * @param d Device structure to store parameters in.301 */ 302 static int drive_identify(int disk_id, disk_t *d)358 * @param buf Pointer to a 512-byte buffer. 359 */ 360 static int drive_identify(int disk_id, void *buf) 303 361 { 304 362 uint16_t data; … … 308 366 309 367 drv_head = ((disk_id != 0) ? DHR_DRV : 0); 310 d->present = false;311 368 312 369 if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) … … 330 387 331 388 if ((status & SR_DRQ) != 0) { 332 // for (i = 0; i < block_size / 2; i++) {333 // data = pio_read_16(&cmd->data_port);334 // ((uint16_t *) buf)[i] = data;335 // }336 337 389 for (i = 0; i < block_size / 2; i++) { 338 390 data = pio_read_16(&cmd->data_port); 339 340 switch (i) { 341 case 1: d->cylinders = data; break; 342 case 3: d->heads = data; break; 343 case 6: d->sectors = data; break; 344 } 391 ((uint16_t *) buf)[i] = data; 345 392 } 346 393 } … … 348 395 if ((status & SR_ERR) != 0) 349 396 return EIO; 350 351 d->blocks = d->cylinders * d->heads * d->sectors;352 353 d->present = true;354 fibril_mutex_initialize(&d->lock);355 397 356 398 return EOK; -
uspace/srv/bd/ata_bd/ata_bd.h
ra71c158 r0e6dce8 38 38 #include <sys/types.h> 39 39 #include <fibril_sync.h> 40 #include <string.h> 40 41 41 42 enum { … … 149 150 uint64_t blocks; 150 151 152 char model[STR_BOUNDS(40) + 1]; 153 151 154 fibril_mutex_t lock; 152 155 dev_handle_t dev_handle;
Note:
See TracChangeset
for help on using the changeset viewer.