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