1 | @c |
---|
2 | @c COPYRIGHT (c) 1988-2002. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter ATA Driver |
---|
10 | |
---|
11 | @section Terms |
---|
12 | |
---|
13 | ATA device - physical device attached to an IDE controller |
---|
14 | |
---|
15 | @section Introduction |
---|
16 | |
---|
17 | ATA driver provides generic interface to an ATA device. ATA driver is |
---|
18 | hardware independant implementation of ATA standart defined in working draft |
---|
19 | "AT Attachment Interface with Extentions (ATA-2)" X3T10/0948D revision 4c, |
---|
20 | March 18, 1996. ATA Driver based on IDE Controller Driver and may be used for |
---|
21 | computer systems with single IDE controller and with multiple as well. Although |
---|
22 | current implementation has several restrictions detailed below ATA driver |
---|
23 | architecture allows easily extend the driver. Current restrictions are: |
---|
24 | |
---|
25 | @itemize @bullet |
---|
26 | @item Only mandatory (see draft p.29) and two optional (READ/WRITE MULTIPLE) |
---|
27 | commands are implemented |
---|
28 | @item Only PIO mode is supported but both poll and interrupt driven |
---|
29 | @end itemize |
---|
30 | |
---|
31 | The reference implementation for ATA driver can be found in |
---|
32 | @code{c/src/exec/libblock/src/ata.c}. |
---|
33 | |
---|
34 | @section Initialization |
---|
35 | |
---|
36 | The @code{ata_initialize} routine is responsible for ATA driver |
---|
37 | initialization. The main goal of the initialization is to detect and |
---|
38 | register in the system all ATA devices attached to IDE controllers |
---|
39 | successfully initialized by the IDE Controller driver. |
---|
40 | |
---|
41 | In the implementation of the driver, the following actions are performed: |
---|
42 | |
---|
43 | @example |
---|
44 | @group |
---|
45 | rtems_device_driver ata_initialize( |
---|
46 | rtems_device_major_number major, |
---|
47 | rtems_device_minor_number minor, |
---|
48 | void *arg |
---|
49 | ) |
---|
50 | @{ |
---|
51 | initialize internal ATA driver data structure |
---|
52 | |
---|
53 | for each IDE controller successfully initialized by the IDE Controller |
---|
54 | driver |
---|
55 | if the controller is interuupt driven |
---|
56 | set up interrupt handler |
---|
57 | |
---|
58 | obtain information about ATA devices attached to the controller |
---|
59 | with help of EXECUTE DEVICE DIAGNOSTIC command |
---|
60 | |
---|
61 | for each ATA device detected on the controller |
---|
62 | obtain device parameters with help of DEVICE IDENTIFY command |
---|
63 | |
---|
64 | register new ATA device as new block device in the system |
---|
65 | @} |
---|
66 | @end group |
---|
67 | @end example |
---|
68 | |
---|
69 | Special processing of ATA commands is required because of absence of |
---|
70 | multitasking enviroment during the driver initialization. |
---|
71 | |
---|
72 | Detected ATA devices are registered in the system as physical block devices |
---|
73 | (see libblock library description). Device names are formed based on IDE |
---|
74 | controller minor number device is attached to and device number on the |
---|
75 | controller (0 - Master, 1 - Slave). In current implementation 64 minor |
---|
76 | numbers are reserved for each ATA device which allows to support up to 63 |
---|
77 | logical partitions per device. |
---|
78 | |
---|
79 | @example |
---|
80 | @group |
---|
81 | controller minor device number device name ata device minor |
---|
82 | 0 0 hda 0 |
---|
83 | 0 1 hdb 64 |
---|
84 | 1 0 hdc 128 |
---|
85 | 1 1 hdd 172 |
---|
86 | ... ... ... |
---|
87 | @end group |
---|
88 | @end example |
---|
89 | |
---|
90 | @section ATA Driver Architecture |
---|
91 | |
---|
92 | @subsection ATA Driver Main Internal Data Structures |
---|
93 | |
---|
94 | ATA driver works with ATA requests. ATA request is described by the |
---|
95 | following structure: |
---|
96 | |
---|
97 | @example |
---|
98 | @group |
---|
99 | /* ATA request */ |
---|
100 | typedef struct ata_req_s @{ |
---|
101 | Chain_Node link; /* link in requests chain */ |
---|
102 | char type; /* request type */ |
---|
103 | ata_registers_t regs; /* ATA command */ |
---|
104 | rtems_unsigned32 cnt; /* Number of sectors to be exchanged */ |
---|
105 | rtems_unsigned32 cbuf; /* number of current buffer from breq in use */ |
---|
106 | rtems_unsigned32 pos; /* current position in 'cbuf' */ |
---|
107 | blkdev_request *breq; /* blkdev_request which corresponds to the |
---|
108 | * ata request |
---|
109 | */ |
---|
110 | rtems_id sema; /* semaphore which is used if synchronous |
---|
111 | * processing of the ata request is required |
---|
112 | */ |
---|
113 | rtems_status_code status; /* status of ata request processing */ |
---|
114 | int error; /* error code */ |
---|
115 | @} ata_req_t; |
---|
116 | @end group |
---|
117 | @end example |
---|
118 | |
---|
119 | ATA driver supports separate ATA requests queues for each IDE |
---|
120 | controller (one queue per controller). The following structure contains |
---|
121 | inforamtion about controller's queue and devices attached to the controller: |
---|
122 | |
---|
123 | @example |
---|
124 | @group |
---|
125 | /* |
---|
126 | * This structure describes controller state, devices configuration on the |
---|
127 | * controller and chain of ATA requests to the controller. |
---|
128 | */ |
---|
129 | typedef struct ata_ide_ctrl_s @{ |
---|
130 | rtems_boolean present; /* controller state */ |
---|
131 | ata_dev_t device[2]; /* ata diveces description */ |
---|
132 | Chain_Control reqs; /* requests chain */ |
---|
133 | @} ata_ide_ctrl_t; |
---|
134 | @end group |
---|
135 | @end example |
---|
136 | |
---|
137 | Driver uses array of the structures indexed by the controllers minor |
---|
138 | number. |
---|
139 | |
---|
140 | The following struture allows to map an ATA device to the pair (IDE |
---|
141 | controller minor number device is attached to, device number |
---|
142 | on the controller): |
---|
143 | |
---|
144 | @example |
---|
145 | @group |
---|
146 | /* |
---|
147 | * Mapping of rtems ATA devices to the following pairs: |
---|
148 | * (IDE controller number served the device, device number on the controller) |
---|
149 | */ |
---|
150 | typedef struct ata_ide_dev_s @{ |
---|
151 | int ctrl_minor;/* minor number of IDE controller serves rtems ATA device */ |
---|
152 | int device; /* device number on IDE controller (0 or 1) */ |
---|
153 | @} ata_ide_dev_t; |
---|
154 | @end group |
---|
155 | @end example |
---|
156 | |
---|
157 | Driver uses array of the structures indexed by the ATA devices minor |
---|
158 | number. |
---|
159 | |
---|
160 | ATA driver defines the following internal events: |
---|
161 | |
---|
162 | @example |
---|
163 | @group |
---|
164 | /* ATA driver events */ |
---|
165 | typedef enum ata_msg_type_s @{ |
---|
166 | ATA_MSG_GEN_EVT = 1, /* general event */ |
---|
167 | ATA_MSG_SUCCESS_EVT, /* success event */ |
---|
168 | ATA_MSG_ERROR_EVT, /* error event */ |
---|
169 | ATA_MSG_PROCESS_NEXT_EVT /* process next ata request event */ |
---|
170 | @} ata_msg_type_t; |
---|
171 | @end group |
---|
172 | @end example |
---|
173 | |
---|
174 | @subsection Brief ATA Driver Core Overview |
---|
175 | |
---|
176 | All ATA driver functionality is available via ATA driver ioctl. Current |
---|
177 | implementation supports only two ioctls: BLKIO_REQUEST and |
---|
178 | ATAIO_SET_MULTIPLE_MODE. Each ATA driver ioctl() call generates an |
---|
179 | ATA request which is appended to the apropriate controller queue depending |
---|
180 | on ATA device the request belongs to. If appended request is single request in |
---|
181 | the controller's queue then ATA driver event is generated. |
---|
182 | |
---|
183 | ATA driver task which manages queue of ATA driver events is core of ATA |
---|
184 | driver. In current driver version queue of ATA driver events implemented |
---|
185 | as RTEMS message queue. Each message contains event type, IDE controller |
---|
186 | minor number on which event happaned and error if an error occured. Events |
---|
187 | may be generated either by ATA driver ioctl call or by ATA driver task itself. |
---|
188 | Each time ATA driver task receives an event it gets controller minor number |
---|
189 | from event, takes first ATA request from controller queue and processes it |
---|
190 | depending on request and event types. An ATA request processing may also |
---|
191 | includes sending of several events. If ATA request processing is finished |
---|
192 | the ATA request is removed from the controller queue. Note, that in current |
---|
193 | implementation maximum one event per controller may be queued at any moment |
---|
194 | of the time. |
---|
195 | |
---|
196 | (This part seems not very clear, hope I rewrite it soon) |
---|
197 | |
---|
198 | |
---|
199 | |
---|