source: mainline/uspace/srv/bd/ata_bd/ata_bd.c@ 273b958

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 273b958 was 7e752b2, checked in by Martin Decky <martin@…>, 15 years ago
  • correct printf() formatting strings and corresponding arguments
  • minor cstyle changes and other small fixes
  • Property mode set to 100644
File size: 17.6 KB
Line 
1/*
2 * Copyright (c) 2009 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup bd
30 * @{
31 */
32
33/**
34 * @file
35 * @brief ATA disk driver
36 *
37 * This driver supports CHS, 28-bit and 48-bit LBA addressing. It only uses
38 * PIO transfers. There is no support DMA, the PACKET feature set or any other
39 * fancy features such as S.M.A.R.T, removable devices, etc.
40 *
41 * This driver is based on the ATA-1, ATA-2, ATA-3 and ATA/ATAPI-4 through 7
42 * standards, as published by the ANSI, NCITS and INCITS standards bodies,
43 * which are freely available. This driver contains no vendor-specific
44 * code at this moment.
45 *
46 * The driver services a single controller which can have up to two disks
47 * attached.
48 */
49
50#include <stdio.h>
51#include <libarch/ddi.h>
52#include <ddi.h>
53#include <ipc/ipc.h>
54#include <ipc/bd.h>
55#include <async.h>
56#include <as.h>
57#include <fibril_synch.h>
58#include <str.h>
59#include <devmap.h>
60#include <sys/types.h>
61#include <inttypes.h>
62#include <errno.h>
63#include <bool.h>
64#include <task.h>
65#include <macros.h>
66
67#include "ata_bd.h"
68
69#define NAME "ata_bd"
70#define NAMESPACE "bd"
71
72/** Physical block size. Should be always 512. */
73static const size_t block_size = 512;
74
75/** Size of the communication area. */
76static size_t comm_size;
77
78/** I/O base address of the command registers. */
79static uintptr_t cmd_physical = 0x1f0;
80/** I/O base address of the control registers. */
81static uintptr_t ctl_physical = 0x170;
82
83static ata_cmd_t *cmd;
84static ata_ctl_t *ctl;
85
86/** Per-disk state. */
87static disk_t disk[MAX_DISKS];
88
89static int ata_bd_init(void);
90static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
91static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt,
92 void *buf);
93static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt,
94 const void *buf);
95static int ata_bd_read_block(int disk_id, uint64_t ba, size_t cnt,
96 void *buf);
97static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
98 const void *buf);
99static int disk_init(disk_t *d, int disk_id);
100static int drive_identify(int drive_id, void *buf);
101static void disk_print_summary(disk_t *d);
102static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc);
103static void coord_sc_program(const block_coord_t *bc, uint16_t scnt);
104static int wait_status(unsigned set, unsigned n_reset, uint8_t *pstatus,
105 unsigned timeout);
106
107int main(int argc, char **argv)
108{
109 char name[16];
110 int i, rc;
111 int n_disks;
112
113 printf(NAME ": ATA disk driver\n");
114
115 printf("I/O address %p/%p\n", (void *) ctl_physical,
116 (void *) cmd_physical);
117
118 if (ata_bd_init() != EOK)
119 return -1;
120
121 for (i = 0; i < MAX_DISKS; i++) {
122 printf("Identify drive %d... ", i);
123 fflush(stdout);
124
125 rc = disk_init(&disk[i], i);
126
127 if (rc == EOK) {
128 disk_print_summary(&disk[i]);
129 } else {
130 printf("Not found.\n");
131 }
132 }
133
134 n_disks = 0;
135
136 for (i = 0; i < MAX_DISKS; i++) {
137 /* Skip unattached drives. */
138 if (disk[i].present == false)
139 continue;
140
141 snprintf(name, 16, "%s/disk%d", NAMESPACE, i);
142 rc = devmap_device_register(name, &disk[i].devmap_handle);
143 if (rc != EOK) {
144 devmap_hangup_phone(DEVMAP_DRIVER);
145 printf(NAME ": Unable to register device %s.\n", name);
146 return rc;
147 }
148 ++n_disks;
149 }
150
151 if (n_disks == 0) {
152 printf("No disks detected.\n");
153 return -1;
154 }
155
156 printf(NAME ": Accepting connections\n");
157 task_retval(0);
158 async_manager();
159
160 /* Not reached */
161 return 0;
162}
163
164/** Print one-line device summary. */
165static void disk_print_summary(disk_t *d)
166{
167 uint64_t mbytes;
168
169 printf("%s: ", d->model);
170
171 switch (d->amode) {
172 case am_chs:
173 printf("CHS %u cylinders, %u heads, %u sectors",
174 disk->geom.cylinders, disk->geom.heads, disk->geom.sectors);
175 break;
176 case am_lba28:
177 printf("LBA-28");
178 break;
179 case am_lba48:
180 printf("LBA-48");
181 break;
182 }
183
184 printf(" %" PRIu64 " blocks", d->blocks);
185
186 mbytes = d->blocks / (2 * 1024);
187 if (mbytes > 0)
188 printf(" %" PRIu64 " MB.", mbytes);
189
190 printf("\n");
191}
192
193/** Register driver and enable device I/O. */
194static int ata_bd_init(void)
195{
196 void *vaddr;
197 int rc;
198
199 rc = devmap_driver_register(NAME, ata_bd_connection);
200 if (rc < 0) {
201 printf(NAME ": Unable to register driver.\n");
202 return rc;
203 }
204
205 rc = pio_enable((void *) cmd_physical, sizeof(ata_cmd_t), &vaddr);
206 if (rc != EOK) {
207 printf(NAME ": Could not initialize device I/O space.\n");
208 return rc;
209 }
210
211 cmd = vaddr;
212
213 rc = pio_enable((void *) ctl_physical, sizeof(ata_ctl_t), &vaddr);
214 if (rc != EOK) {
215 printf(NAME ": Could not initialize device I/O space.\n");
216 return rc;
217 }
218
219 ctl = vaddr;
220
221
222 return EOK;
223}
224
225/** Block device connection handler */
226static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall)
227{
228 void *fs_va = NULL;
229 ipc_callid_t callid;
230 ipc_call_t call;
231 ipcarg_t method;
232 devmap_handle_t dh;
233 int flags;
234 int retval;
235 uint64_t ba;
236 size_t cnt;
237 int disk_id, i;
238
239 /* Get the device handle. */
240 dh = IPC_GET_ARG1(*icall);
241
242 /* Determine which disk device is the client connecting to. */
243 disk_id = -1;
244 for (i = 0; i < MAX_DISKS; i++)
245 if (disk[i].devmap_handle == dh)
246 disk_id = i;
247
248 if (disk_id < 0 || disk[disk_id].present == false) {
249 ipc_answer_0(iid, EINVAL);
250 return;
251 }
252
253 /* Answer the IPC_M_CONNECT_ME_TO call. */
254 ipc_answer_0(iid, EOK);
255
256 if (!async_share_out_receive(&callid, &comm_size, &flags)) {
257 ipc_answer_0(callid, EHANGUP);
258 return;
259 }
260
261 fs_va = as_get_mappable_page(comm_size);
262 if (fs_va == NULL) {
263 ipc_answer_0(callid, EHANGUP);
264 return;
265 }
266
267 (void) async_share_out_finalize(callid, fs_va);
268
269 while (1) {
270 callid = async_get_call(&call);
271 method = IPC_GET_METHOD(call);
272 switch (method) {
273 case IPC_M_PHONE_HUNGUP:
274 /* The other side has hung up. */
275 ipc_answer_0(callid, EOK);
276 return;
277 case BD_READ_BLOCKS:
278 ba = MERGE_LOUP32(IPC_GET_ARG1(call),
279 IPC_GET_ARG2(call));
280 cnt = IPC_GET_ARG3(call);
281 if (cnt * block_size > comm_size) {
282 retval = ELIMIT;
283 break;
284 }
285 retval = ata_bd_read_blocks(disk_id, ba, cnt, fs_va);
286 break;
287 case BD_WRITE_BLOCKS:
288 ba = MERGE_LOUP32(IPC_GET_ARG1(call),
289 IPC_GET_ARG2(call));
290 cnt = IPC_GET_ARG3(call);
291 if (cnt * block_size > comm_size) {
292 retval = ELIMIT;
293 break;
294 }
295 retval = ata_bd_write_blocks(disk_id, ba, cnt, fs_va);
296 break;
297 case BD_GET_BLOCK_SIZE:
298 ipc_answer_1(callid, EOK, block_size);
299 continue;
300 case BD_GET_NUM_BLOCKS:
301 ipc_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),
302 UPPER32(disk[disk_id].blocks));
303 continue;
304 default:
305 retval = EINVAL;
306 break;
307 }
308 ipc_answer_0(callid, retval);
309 }
310}
311
312/** Initialize a disk.
313 *
314 * Probes for a disk, determines its parameters and initializes
315 * the disk structure.
316 */
317static int disk_init(disk_t *d, int disk_id)
318{
319 identify_data_t idata;
320 uint8_t model[40];
321 uint16_t w;
322 uint8_t c;
323 size_t pos, len;
324 int rc;
325 unsigned i;
326
327 rc = drive_identify(disk_id, &idata);
328 if (rc != EOK) {
329 d->present = false;
330 return rc;
331 }
332
333 if ((idata.caps & cap_lba) == 0) {
334 /* Device only supports CHS addressing. */
335 d->amode = am_chs;
336
337 d->geom.cylinders = idata.cylinders;
338 d->geom.heads = idata.heads;
339 d->geom.sectors = idata.sectors;
340
341 d->blocks = d->geom.cylinders * d->geom.heads * d->geom.sectors;
342 } else if ((idata.cmd_set1 & cs1_addr48) == 0) {
343 /* Device only supports LBA-28 addressing. */
344 d->amode = am_lba28;
345
346 d->geom.cylinders = 0;
347 d->geom.heads = 0;
348 d->geom.sectors = 0;
349
350 d->blocks =
351 (uint32_t) idata.total_lba28_0 |
352 ((uint32_t) idata.total_lba28_1 << 16);
353 } else {
354 /* Device supports LBA-48 addressing. */
355 d->amode = am_lba48;
356
357 d->geom.cylinders = 0;
358 d->geom.heads = 0;
359 d->geom.sectors = 0;
360
361 d->blocks =
362 (uint64_t) idata.total_lba48_0 |
363 ((uint64_t) idata.total_lba48_1 << 16) |
364 ((uint64_t) idata.total_lba48_2 << 32) |
365 ((uint64_t) idata.total_lba48_3 << 48);
366 }
367
368 /*
369 * Convert model name to string representation.
370 */
371 for (i = 0; i < 20; i++) {
372 w = idata.model_name[i];
373 model[2 * i] = w >> 8;
374 model[2 * i + 1] = w & 0x00ff;
375 }
376
377 len = 40;
378 while (len > 0 && model[len - 1] == 0x20)
379 --len;
380
381 pos = 0;
382 for (i = 0; i < len; ++i) {
383 c = model[i];
384 if (c >= 0x80) c = '?';
385
386 chr_encode(c, d->model, &pos, 40);
387 }
388 d->model[pos] = '\0';
389
390 d->present = true;
391 fibril_mutex_initialize(&d->lock);
392
393 return EOK;
394}
395
396/** Read multiple blocks from the device. */
397static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt,
398 void *buf) {
399
400 int rc;
401
402 while (cnt > 0) {
403 rc = ata_bd_read_block(disk_id, ba, 1, buf);
404 if (rc != EOK)
405 return rc;
406
407 ++ba;
408 --cnt;
409 buf += block_size;
410 }
411
412 return EOK;
413}
414
415/** Write multiple blocks to the device. */
416static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt,
417 const void *buf) {
418
419 int rc;
420
421 while (cnt > 0) {
422 rc = ata_bd_write_block(disk_id, ba, 1, buf);
423 if (rc != EOK)
424 return rc;
425
426 ++ba;
427 --cnt;
428 buf += block_size;
429 }
430
431 return EOK;
432}
433
434/** Issue IDENTIFY command.
435 *
436 * Reads @c identify data into the provided buffer. This is used to detect
437 * whether an ATA device is present and if so, to determine its parameters.
438 *
439 * @param disk_id Device ID, 0 or 1.
440 * @param buf Pointer to a 512-byte buffer.
441 */
442static int drive_identify(int disk_id, void *buf)
443{
444 uint16_t data;
445 uint8_t status;
446 uint8_t drv_head;
447 size_t i;
448
449 drv_head = ((disk_id != 0) ? DHR_DRV : 0);
450
451 if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
452 return EIO;
453
454 pio_write_8(&cmd->drive_head, drv_head);
455
456 /*
457 * This is where we would most likely expect a non-existing device to
458 * show up by not setting SR_DRDY.
459 */
460 if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
461 return EIO;
462
463 pio_write_8(&cmd->command, CMD_IDENTIFY_DRIVE);
464
465 if (wait_status(0, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK)
466 return EIO;
467
468 /* Read data from the disk buffer. */
469
470 if ((status & SR_DRQ) != 0) {
471 for (i = 0; i < block_size / 2; i++) {
472 data = pio_read_16(&cmd->data_port);
473 ((uint16_t *) buf)[i] = data;
474 }
475 }
476
477 if ((status & SR_ERR) != 0)
478 return EIO;
479
480 return EOK;
481}
482
483/** Read a physical from the device.
484 *
485 * @param disk_id Device index (0 or 1)
486 * @param ba Address the first block.
487 * @param cnt Number of blocks to transfer.
488 * @param buf Buffer for holding the data.
489 *
490 * @return EOK on success, EIO on error.
491 */
492static int ata_bd_read_block(int disk_id, uint64_t ba, size_t blk_cnt,
493 void *buf)
494{
495 size_t i;
496 uint16_t data;
497 uint8_t status;
498 uint8_t drv_head;
499 disk_t *d;
500 block_coord_t bc;
501
502 d = &disk[disk_id];
503
504 /* Silence warning. */
505 memset(&bc, 0, sizeof(bc));
506
507 /* Compute block coordinates. */
508 if (coord_calc(d, ba, &bc) != EOK)
509 return EINVAL;
510
511 /* New value for Drive/Head register */
512 drv_head =
513 ((disk_id != 0) ? DHR_DRV : 0) |
514 ((d->amode != am_chs) ? DHR_LBA : 0) |
515 (bc.h & 0x0f);
516
517 fibril_mutex_lock(&d->lock);
518
519 /* Program a Read Sectors operation. */
520
521 if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) {
522 fibril_mutex_unlock(&d->lock);
523 return EIO;
524 }
525
526 pio_write_8(&cmd->drive_head, drv_head);
527
528 if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) {
529 fibril_mutex_unlock(&d->lock);
530 return EIO;
531 }
532
533 /* Program block coordinates into the device. */
534 coord_sc_program(&bc, 1);
535
536 pio_write_8(&cmd->command, d->amode == am_lba48 ?
537 CMD_READ_SECTORS_EXT : CMD_READ_SECTORS);
538
539 if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {
540 fibril_mutex_unlock(&d->lock);
541 return EIO;
542 }
543
544 if ((status & SR_DRQ) != 0) {
545 /* Read data from the device buffer. */
546
547 for (i = 0; i < block_size / 2; i++) {
548 data = pio_read_16(&cmd->data_port);
549 ((uint16_t *) buf)[i] = data;
550 }
551 }
552
553 if ((status & SR_ERR) != 0)
554 return EIO;
555
556 fibril_mutex_unlock(&d->lock);
557 return EOK;
558}
559
560/** Write a physical block to the device.
561 *
562 * @param disk_id Device index (0 or 1)
563 * @param ba Address of the first block.
564 * @param cnt Number of blocks to transfer.
565 * @param buf Buffer holding the data to write.
566 *
567 * @return EOK on success, EIO on error.
568 */
569static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
570 const void *buf)
571{
572 size_t i;
573 uint8_t status;
574 uint8_t drv_head;
575 disk_t *d;
576 block_coord_t bc;
577
578 d = &disk[disk_id];
579
580 /* Silence warning. */
581 memset(&bc, 0, sizeof(bc));
582
583 /* Compute block coordinates. */
584 if (coord_calc(d, ba, &bc) != EOK)
585 return EINVAL;
586
587 /* New value for Drive/Head register */
588 drv_head =
589 ((disk_id != 0) ? DHR_DRV : 0) |
590 ((d->amode != am_chs) ? DHR_LBA : 0) |
591 (bc.h & 0x0f);
592
593 fibril_mutex_lock(&d->lock);
594
595 /* Program a Write Sectors operation. */
596
597 if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) {
598 fibril_mutex_unlock(&d->lock);
599 return EIO;
600 }
601
602 pio_write_8(&cmd->drive_head, drv_head);
603
604 if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) {
605 fibril_mutex_unlock(&d->lock);
606 return EIO;
607 }
608
609 /* Program block coordinates into the device. */
610 coord_sc_program(&bc, 1);
611
612 pio_write_8(&cmd->command, d->amode == am_lba48 ?
613 CMD_WRITE_SECTORS_EXT : CMD_WRITE_SECTORS);
614
615 if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {
616 fibril_mutex_unlock(&d->lock);
617 return EIO;
618 }
619
620 if ((status & SR_DRQ) != 0) {
621 /* Write data to the device buffer. */
622
623 for (i = 0; i < block_size / 2; i++) {
624 pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]);
625 }
626 }
627
628 fibril_mutex_unlock(&d->lock);
629
630 if (status & SR_ERR)
631 return EIO;
632
633 return EOK;
634}
635
636/** Calculate block coordinates.
637 *
638 * Calculates block coordinates in the best coordinate system supported
639 * by the device. These can be later programmed into the device using
640 * @c coord_sc_program().
641 *
642 * @return EOK on success or EINVAL if block index is past end of device.
643 */
644static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc)
645{
646 uint64_t c;
647 uint64_t idx;
648
649 /* Check device bounds. */
650 if (ba >= d->blocks)
651 return EINVAL;
652
653 bc->amode = d->amode;
654
655 switch (d->amode) {
656 case am_chs:
657 /* Compute CHS coordinates. */
658 c = ba / (d->geom.heads * d->geom.sectors);
659 idx = ba % (d->geom.heads * d->geom.sectors);
660
661 bc->cyl_lo = c & 0xff;
662 bc->cyl_hi = (c >> 8) & 0xff;
663 bc->h = (idx / d->geom.sectors) & 0x0f;
664 bc->sector = (1 + (idx % d->geom.sectors)) & 0xff;
665 break;
666
667 case am_lba28:
668 /* Compute LBA-28 coordinates. */
669 bc->c0 = ba & 0xff; /* bits 0-7 */
670 bc->c1 = (ba >> 8) & 0xff; /* bits 8-15 */
671 bc->c2 = (ba >> 16) & 0xff; /* bits 16-23 */
672 bc->h = (ba >> 24) & 0x0f; /* bits 24-27 */
673 break;
674
675 case am_lba48:
676 /* Compute LBA-48 coordinates. */
677 bc->c0 = ba & 0xff; /* bits 0-7 */
678 bc->c1 = (ba >> 8) & 0xff; /* bits 8-15 */
679 bc->c2 = (ba >> 16) & 0xff; /* bits 16-23 */
680 bc->c3 = (ba >> 24) & 0xff; /* bits 24-31 */
681 bc->c4 = (ba >> 32) & 0xff; /* bits 32-39 */
682 bc->c5 = (ba >> 40) & 0xff; /* bits 40-47 */
683 bc->h = 0;
684 break;
685 }
686
687 return EOK;
688}
689
690/** Program block coordinates and sector count into ATA registers.
691 *
692 * Note that bc->h must be programmed separately into the device/head register.
693 */
694static void coord_sc_program(const block_coord_t *bc, uint16_t scnt)
695{
696 if (bc->amode == am_lba48) {
697 /* Write high-order bits. */
698 pio_write_8(&cmd->sector_count, scnt >> 8);
699 pio_write_8(&cmd->sector_number, bc->c3);
700 pio_write_8(&cmd->cylinder_low, bc->c4);
701 pio_write_8(&cmd->cylinder_high, bc->c5);
702 }
703
704 /* Write low-order bits. */
705 pio_write_8(&cmd->sector_count, scnt & 0x00ff);
706 pio_write_8(&cmd->sector_number, bc->c0);
707 pio_write_8(&cmd->cylinder_low, bc->c1);
708 pio_write_8(&cmd->cylinder_high, bc->c2);
709}
710
711/** Wait until some status bits are set and some are reset.
712 *
713 * Example: wait_status(SR_DRDY, ~SR_BSY) waits for SR_DRDY to become
714 * set and SR_BSY to become reset.
715 *
716 * @param set Combination if bits which must be all set.
717 * @param n_reset Negated combination of bits which must be all reset.
718 * @param pstatus Pointer where to store last read status or NULL.
719 * @param timeout Timeout in 10ms units.
720 *
721 * @return EOK on success, EIO on timeout.
722 */
723static int wait_status(unsigned set, unsigned n_reset, uint8_t *pstatus,
724 unsigned timeout)
725{
726 uint8_t status;
727 int cnt;
728
729 status = pio_read_8(&cmd->status);
730
731 /*
732 * This is crude, yet simple. First try with 1us delays
733 * (most likely the device will respond very fast). If not,
734 * start trying every 10 ms.
735 */
736
737 cnt = 100;
738 while ((status & ~n_reset) != 0 || (status & set) != set) {
739 async_usleep(1);
740 --cnt;
741 if (cnt <= 0) break;
742
743 status = pio_read_8(&cmd->status);
744 }
745
746 cnt = timeout;
747 while ((status & ~n_reset) != 0 || (status & set) != set) {
748 async_usleep(10000);
749 --cnt;
750 if (cnt <= 0) break;
751
752 status = pio_read_8(&cmd->status);
753 }
754
755 if (pstatus)
756 *pstatus = status;
757
758 if (cnt == 0)
759 return EIO;
760
761 return EOK;
762}
763
764/**
765 * @}
766 */
Note: See TracBrowser for help on using the repository browser.