[4f5caea] | 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 | */
|
---|
[d770deb] | 32 | /** @file ATA driver definitions.
|
---|
[4f5caea] | 33 | */
|
---|
| 34 |
|
---|
| 35 | #ifndef __ATA_BD_H__
|
---|
| 36 | #define __ATA_BD_H__
|
---|
| 37 |
|
---|
| 38 | #include <sys/types.h>
|
---|
[1e4cada] | 39 | #include <fibril_synch.h>
|
---|
[19f857a] | 40 | #include <str.h>
|
---|
[4f5caea] | 41 |
|
---|
[e092dc5] | 42 | /** Base addresses for ATA I/O blocks. */
|
---|
| 43 | typedef struct {
|
---|
| 44 | uintptr_t cmd; /**< Command block base address. */
|
---|
| 45 | uintptr_t ctl; /**< Control block base address. */
|
---|
| 46 | } ata_base_t;
|
---|
| 47 |
|
---|
[31de325] | 48 | /** Timeout definitions. Unit is 10 ms. */
|
---|
| 49 | enum ata_timeout {
|
---|
| 50 | TIMEOUT_PROBE = 100, /* 1 s */
|
---|
| 51 | TIMEOUT_BSY = 100, /* 1 s */
|
---|
| 52 | TIMEOUT_DRDY = 1000 /* 10 s */
|
---|
| 53 | };
|
---|
| 54 |
|
---|
[a99cf073] | 55 | /** Block addressing mode. */
|
---|
| 56 | enum addr_mode {
|
---|
[a1f48f6] | 57 | am_chs, /**< CHS block addressing */
|
---|
| 58 | am_lba28, /**< LBA-28 block addressing */
|
---|
| 59 | am_lba48 /**< LBA-48 block addressing */
|
---|
[a99cf073] | 60 | };
|
---|
| 61 |
|
---|
[5048be7] | 62 | /** Block coordinates */
|
---|
| 63 | typedef struct {
|
---|
| 64 | /** Addressing mode used */
|
---|
| 65 | enum addr_mode amode;
|
---|
| 66 |
|
---|
| 67 | union {
|
---|
| 68 | /** CHS coordinates */
|
---|
| 69 | struct {
|
---|
| 70 | uint8_t sector;
|
---|
| 71 | uint8_t cyl_lo;
|
---|
| 72 | uint8_t cyl_hi;
|
---|
| 73 | };
|
---|
| 74 | /** LBA coordinates */
|
---|
| 75 | struct {
|
---|
| 76 | uint8_t c0;
|
---|
| 77 | uint8_t c1;
|
---|
| 78 | uint8_t c2;
|
---|
| 79 | uint8_t c3;
|
---|
| 80 | uint8_t c4;
|
---|
| 81 | uint8_t c5;
|
---|
| 82 | };
|
---|
| 83 | };
|
---|
| 84 |
|
---|
| 85 | /** Lower 4 bits for device/head register */
|
---|
| 86 | uint8_t h;
|
---|
| 87 | } block_coord_t;
|
---|
| 88 |
|
---|
[e092dc5] | 89 | /** ATA device state structure. */
|
---|
[4f5caea] | 90 | typedef struct {
|
---|
| 91 | bool present;
|
---|
[a99cf073] | 92 | enum addr_mode amode;
|
---|
| 93 |
|
---|
| 94 | /*
|
---|
| 95 | * Geometry. Only valid if operating in CHS mode.
|
---|
| 96 | */
|
---|
| 97 | struct {
|
---|
| 98 | unsigned heads;
|
---|
| 99 | unsigned cylinders;
|
---|
| 100 | unsigned sectors;
|
---|
| 101 | } geom;
|
---|
| 102 |
|
---|
[4f5caea] | 103 | uint64_t blocks;
|
---|
[12956e57] | 104 |
|
---|
[0e6dce8] | 105 | char model[STR_BOUNDS(40) + 1];
|
---|
| 106 |
|
---|
[12956e57] | 107 | fibril_mutex_t lock;
|
---|
[991f645] | 108 | devmap_handle_t devmap_handle;
|
---|
[4f5caea] | 109 | } disk_t;
|
---|
| 110 |
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | /** @}
|
---|
| 114 | */
|
---|