Rev 4530 | Rev 4546 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4530 | Rev 4531 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Jiri Svoboda |
2 | * Copyright (c) 2009 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup bd |
29 | /** @addtogroup bd |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #ifndef __ATA_BD_H__ |
35 | #ifndef __ATA_BD_H__ |
36 | #define __ATA_BD_H__ |
36 | #define __ATA_BD_H__ |
37 | 37 | ||
38 | #include <sys/types.h> |
38 | #include <sys/types.h> |
39 | 39 | ||
40 | enum { |
40 | enum { |
41 | CTL_READ_START = 0, |
41 | CTL_READ_START = 0, |
42 | CTL_WRITE_START = 1, |
42 | CTL_WRITE_START = 1, |
43 | }; |
43 | }; |
44 | 44 | ||
45 | enum { |
45 | enum { |
46 | STATUS_FAILURE = 0 |
46 | STATUS_FAILURE = 0 |
47 | }; |
47 | }; |
48 | 48 | ||
49 | enum { |
49 | enum { |
50 | MAX_DISKS = 2 |
50 | MAX_DISKS = 2 |
51 | }; |
51 | }; |
52 | 52 | ||
53 | typedef union { |
53 | typedef union { |
54 | /* Read */ |
54 | /* Read */ |
55 | struct { |
55 | struct { |
56 | uint8_t data_port; |
56 | uint8_t data_port; |
57 | uint8_t error; |
57 | uint8_t error; |
58 | uint8_t sector_count; |
58 | uint8_t sector_count; |
59 | uint8_t sector_number; |
59 | uint8_t sector_number; |
60 | uint8_t cylinder_low; |
60 | uint8_t cylinder_low; |
61 | uint8_t cylinder_high; |
61 | uint8_t cylinder_high; |
62 | uint8_t drive_head; |
62 | uint8_t drive_head; |
63 | uint8_t status; |
63 | uint8_t status; |
64 | }; |
64 | }; |
65 | 65 | ||
66 | /* Write */ |
66 | /* Write */ |
67 | struct { |
67 | struct { |
68 | uint8_t pad0[7]; |
68 | uint8_t pad0[7]; |
69 | uint8_t command; |
69 | uint8_t command; |
70 | }; |
70 | }; |
71 | } ata_cmd_t; |
71 | } ata_cmd_t; |
72 | 72 | ||
73 | typedef union { |
73 | typedef union { |
74 | /* Read */ |
74 | /* Read */ |
75 | struct { |
75 | struct { |
76 | uint8_t pad0[6]; |
76 | uint8_t pad0[6]; |
77 | uint8_t alt_status; |
77 | uint8_t alt_status; |
78 | uint8_t drive_address; |
78 | uint8_t drive_address; |
79 | }; |
79 | }; |
80 | 80 | ||
81 | /* Write */ |
81 | /* Write */ |
82 | struct { |
82 | struct { |
83 | uint8_t pad1[6]; |
83 | uint8_t pad1[6]; |
84 | uint8_t device_control; |
84 | uint8_t device_control; |
85 | uint8_t pad2; |
85 | uint8_t pad2; |
86 | }; |
86 | }; |
87 | } ata_ctl_t; |
87 | } ata_ctl_t; |
88 | 88 | ||
89 | enum devctl_bits { |
89 | enum devctl_bits { |
90 | DCR_SRST = 0x04, /**< Software Reset */ |
90 | DCR_SRST = 0x04, /**< Software Reset */ |
91 | DCR_nIEN = 0x02 /**< Interrupt Enable (negated) */ |
91 | DCR_nIEN = 0x02 /**< Interrupt Enable (negated) */ |
92 | }; |
92 | }; |
93 | 93 | ||
94 | enum status_bits { |
94 | enum status_bits { |
95 | SR_BSY = 0x80, /**< Busy */ |
95 | SR_BSY = 0x80, /**< Busy */ |
96 | SR_DRDY = 0x40, /**< Drive Ready */ |
96 | SR_DRDY = 0x40, /**< Drive Ready */ |
97 | SR_DWF = 0x20, /**< Drive Write Fault */ |
97 | SR_DWF = 0x20, /**< Drive Write Fault */ |
98 | SR_DSC = 0x10, /**< Drive Seek Complete */ |
98 | SR_DSC = 0x10, /**< Drive Seek Complete */ |
99 | SR_DRQ = 0x08, /**< Data Request */ |
99 | SR_DRQ = 0x08, /**< Data Request */ |
100 | SR_CORR = 0x04, /**< Corrected Data */ |
100 | SR_CORR = 0x04, /**< Corrected Data */ |
101 | SR_IDX = 0x02, /**< Index */ |
101 | SR_IDX = 0x02, /**< Index */ |
102 | SR_ERR = 0x01 /**< Error */ |
102 | SR_ERR = 0x01 /**< Error */ |
103 | }; |
103 | }; |
104 | 104 | ||
105 | enum drive_head_bits { |
105 | enum drive_head_bits { |
106 | DHR_DRV = 0x10 |
106 | DHR_DRV = 0x10 |
107 | }; |
107 | }; |
108 | 108 | ||
109 | enum error_bits { |
109 | enum error_bits { |
110 | ER_BBK = 0x80, /**< Bad Block Detected */ |
110 | ER_BBK = 0x80, /**< Bad Block Detected */ |
111 | ER_UNC = 0x40, /**< Uncorrectable Data Error */ |
111 | ER_UNC = 0x40, /**< Uncorrectable Data Error */ |
112 | ER_MC = 0x20, /**< Media Changed */ |
112 | ER_MC = 0x20, /**< Media Changed */ |
113 | ER_IDNF = 0x10, /**< ID Not Found */ |
113 | ER_IDNF = 0x10, /**< ID Not Found */ |
114 | ER_MCR = 0x08, /**< Media Change Request */ |
114 | ER_MCR = 0x08, /**< Media Change Request */ |
115 | ER_ABRT = 0x04, /**< Aborted Command */ |
115 | ER_ABRT = 0x04, /**< Aborted Command */ |
116 | ER_TK0NF = 0x02, /**< Track 0 Not Found */ |
116 | ER_TK0NF = 0x02, /**< Track 0 Not Found */ |
117 | ER_AMNF = 0x01 /**< Address Mark Not Found */ |
117 | ER_AMNF = 0x01 /**< Address Mark Not Found */ |
118 | }; |
118 | }; |
119 | 119 | ||
- | 120 | enum ata_command { |
|
- | 121 | CMD_IDENTIFY_DRIVE = 0xEC, |
|
- | 122 | CMD_READ_SECTORS = 0x20, |
|
- | 123 | CMD_WRITE_SECTORS = 0x30 |
|
- | 124 | }; |
|
- | 125 | ||
120 | typedef struct { |
126 | typedef struct { |
121 | bool present; |
127 | bool present; |
122 | unsigned heads; |
128 | unsigned heads; |
123 | unsigned cylinders; |
129 | unsigned cylinders; |
124 | unsigned sectors; |
130 | unsigned sectors; |
125 | uint64_t blocks; |
131 | uint64_t blocks; |
126 | } disk_t; |
132 | } disk_t; |
127 | 133 | ||
128 | #endif |
134 | #endif |
129 | 135 | ||
130 | /** @} |
136 | /** @} |
131 | */ |
137 | */ |
132 | 138 |