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 | /** @file ATA driver definitions.
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifndef __ATA_BD_H__
|
---|
36 | #define __ATA_BD_H__
|
---|
37 |
|
---|
38 | #include <sys/types.h>
|
---|
39 | #include <fibril_synch.h>
|
---|
40 | #include <str.h>
|
---|
41 |
|
---|
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 |
|
---|
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 |
|
---|
55 | enum ata_dev_type {
|
---|
56 | ata_reg_dev, /* Register device (no packet feature set support) */
|
---|
57 | ata_pkt_dev /* Packet device (supports packet feature set). */
|
---|
58 | };
|
---|
59 |
|
---|
60 | /** Register device block addressing mode. */
|
---|
61 | enum rd_addr_mode {
|
---|
62 | am_chs, /**< CHS block addressing */
|
---|
63 | am_lba28, /**< LBA-28 block addressing */
|
---|
64 | am_lba48 /**< LBA-48 block addressing */
|
---|
65 | };
|
---|
66 |
|
---|
67 | /** Block coordinates */
|
---|
68 | typedef struct {
|
---|
69 | enum rd_addr_mode amode;
|
---|
70 |
|
---|
71 | union {
|
---|
72 | /** CHS coordinates */
|
---|
73 | struct {
|
---|
74 | uint8_t sector;
|
---|
75 | uint8_t cyl_lo;
|
---|
76 | uint8_t cyl_hi;
|
---|
77 | };
|
---|
78 | /** LBA coordinates */
|
---|
79 | struct {
|
---|
80 | uint8_t c0;
|
---|
81 | uint8_t c1;
|
---|
82 | uint8_t c2;
|
---|
83 | uint8_t c3;
|
---|
84 | uint8_t c4;
|
---|
85 | uint8_t c5;
|
---|
86 | };
|
---|
87 | };
|
---|
88 |
|
---|
89 | /** Lower 4 bits for device/head register */
|
---|
90 | uint8_t h;
|
---|
91 | } block_coord_t;
|
---|
92 |
|
---|
93 | /** ATA device state structure. */
|
---|
94 | typedef struct {
|
---|
95 | bool present;
|
---|
96 |
|
---|
97 | /** Device type */
|
---|
98 | enum ata_dev_type dev_type;
|
---|
99 |
|
---|
100 | /** Addressing mode to use (if register device) */
|
---|
101 | enum rd_addr_mode amode;
|
---|
102 |
|
---|
103 | /*
|
---|
104 | * Geometry. Only valid if operating in CHS mode.
|
---|
105 | */
|
---|
106 | struct {
|
---|
107 | unsigned heads;
|
---|
108 | unsigned cylinders;
|
---|
109 | unsigned sectors;
|
---|
110 | } geom;
|
---|
111 |
|
---|
112 | uint64_t blocks;
|
---|
113 | size_t block_size;
|
---|
114 |
|
---|
115 | char model[STR_BOUNDS(40) + 1];
|
---|
116 |
|
---|
117 | fibril_mutex_t lock;
|
---|
118 | devmap_handle_t devmap_handle;
|
---|
119 | } disk_t;
|
---|
120 |
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | /** @}
|
---|
124 | */
|
---|