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