[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 |
|
---|
[4802dd7] | 38 | #include <bd_srv.h>
|
---|
[4f5caea] | 39 | #include <sys/types.h>
|
---|
[1e4cada] | 40 | #include <fibril_synch.h>
|
---|
[19f857a] | 41 | #include <str.h>
|
---|
[4f5caea] | 42 |
|
---|
[e092dc5] | 43 | /** Base addresses for ATA I/O blocks. */
|
---|
| 44 | typedef struct {
|
---|
| 45 | uintptr_t cmd; /**< Command block base address. */
|
---|
| 46 | uintptr_t ctl; /**< Control block base address. */
|
---|
| 47 | } ata_base_t;
|
---|
| 48 |
|
---|
[31de325] | 49 | /** Timeout definitions. Unit is 10 ms. */
|
---|
| 50 | enum ata_timeout {
|
---|
| 51 | TIMEOUT_PROBE = 100, /* 1 s */
|
---|
| 52 | TIMEOUT_BSY = 100, /* 1 s */
|
---|
| 53 | TIMEOUT_DRDY = 1000 /* 10 s */
|
---|
| 54 | };
|
---|
| 55 |
|
---|
[7a56e33e] | 56 | enum ata_dev_type {
|
---|
| 57 | ata_reg_dev, /* Register device (no packet feature set support) */
|
---|
| 58 | ata_pkt_dev /* Packet device (supports packet feature set). */
|
---|
| 59 | };
|
---|
| 60 |
|
---|
| 61 | /** Register device block addressing mode. */
|
---|
| 62 | enum rd_addr_mode {
|
---|
[a1f48f6] | 63 | am_chs, /**< CHS block addressing */
|
---|
| 64 | am_lba28, /**< LBA-28 block addressing */
|
---|
| 65 | am_lba48 /**< LBA-48 block addressing */
|
---|
[a99cf073] | 66 | };
|
---|
| 67 |
|
---|
[5048be7] | 68 | /** Block coordinates */
|
---|
| 69 | typedef struct {
|
---|
[7a56e33e] | 70 | enum rd_addr_mode amode;
|
---|
[5048be7] | 71 |
|
---|
| 72 | union {
|
---|
| 73 | /** CHS coordinates */
|
---|
| 74 | struct {
|
---|
| 75 | uint8_t sector;
|
---|
| 76 | uint8_t cyl_lo;
|
---|
| 77 | uint8_t cyl_hi;
|
---|
| 78 | };
|
---|
| 79 | /** LBA coordinates */
|
---|
| 80 | struct {
|
---|
| 81 | uint8_t c0;
|
---|
| 82 | uint8_t c1;
|
---|
| 83 | uint8_t c2;
|
---|
| 84 | uint8_t c3;
|
---|
| 85 | uint8_t c4;
|
---|
| 86 | uint8_t c5;
|
---|
| 87 | };
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | /** Lower 4 bits for device/head register */
|
---|
| 91 | uint8_t h;
|
---|
| 92 | } block_coord_t;
|
---|
| 93 |
|
---|
[e092dc5] | 94 | /** ATA device state structure. */
|
---|
[4f5caea] | 95 | typedef struct {
|
---|
| 96 | bool present;
|
---|
[7a56e33e] | 97 |
|
---|
| 98 | /** Device type */
|
---|
| 99 | enum ata_dev_type dev_type;
|
---|
| 100 |
|
---|
| 101 | /** Addressing mode to use (if register device) */
|
---|
| 102 | enum rd_addr_mode amode;
|
---|
[a99cf073] | 103 |
|
---|
| 104 | /*
|
---|
| 105 | * Geometry. Only valid if operating in CHS mode.
|
---|
| 106 | */
|
---|
| 107 | struct {
|
---|
| 108 | unsigned heads;
|
---|
| 109 | unsigned cylinders;
|
---|
| 110 | unsigned sectors;
|
---|
| 111 | } geom;
|
---|
| 112 |
|
---|
[4f5caea] | 113 | uint64_t blocks;
|
---|
[0d247f5] | 114 | size_t block_size;
|
---|
[12956e57] | 115 |
|
---|
[0e6dce8] | 116 | char model[STR_BOUNDS(40) + 1];
|
---|
| 117 |
|
---|
[12956e57] | 118 | fibril_mutex_t lock;
|
---|
[15f3c3f] | 119 | service_id_t service_id;
|
---|
[4802dd7] | 120 | int disk_id;
|
---|
[135486d] | 121 | bd_srvs_t bds;
|
---|
[4f5caea] | 122 | } disk_t;
|
---|
| 123 |
|
---|
| 124 | #endif
|
---|
| 125 |
|
---|
| 126 | /** @}
|
---|
| 127 | */
|
---|