source: rtems/cpukit/libblock/include/rtems/ata_internal.h @ ef142d7

4.104.114.84.9
Last change on this file since ef142d7 was ef142d7, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 28, 2002 at 2:00:43 PM

2002-10-28 Eugeny S. Mints <Eugeny.Mints@…>

  • Added ATA support.
  • include/rtems/blkdev.h: Added last IO status.
  • include/rtems/ata.h, include/rtems/ata_internal.h, include/rtems/ide_part_table.h, src/ata.c, src/ide_part_table.c: New files.
  • Property mode set to 100644
File size: 11.7 KB
Line 
1/*
2 * ata_internal.h
3 *
4 * ATA RTEMS driver internal header file
5 *
6 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
7 * Authors: Eugeny S. Mints     <Eugeny.Mints@oktet.ru>
8 *          Alexandra Kossovsky <sasha@oktet.ru>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.OARcorp.com/rtems/license.html.
13 *
14 * $Id$
15 *
16 */
17#ifndef __ATA_INTERNAL_H__
18#define __ATA_INTERNAL_H__
19
20#include <rtems.h>
21#include <sys/types.h>
22#include <rtems/libio.h>
23#include <stdlib.h>
24
25#include <rtems/blkdev.h>
26#include <rtems/diskdevs.h>
27
28/*
29 * Conversion from and to little-endian byte order. (no-op on i386/i486)
30 *
31 * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
32 * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
33 */
34#if (CPU_BIG_ENDIAN == TRUE)
35#    define CF_LE_W(v) CPU_swap_u16(v)
36#    define CF_LE_L(v) CPU_swap_u32(v)
37#    define CT_LE_W(v) CPU_swap_u16(v)
38#    define CT_LE_L(v) CPU_swap_u32(v)
39#else
40#    define CF_LE_W(v) (v)
41#    define CF_LE_L(v) (v)
42#    define CT_LE_W(v) (v)
43#    define CT_LE_L(v) (v)
44#endif
45
46#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
47#define ATA_UNDEFINED_VALUE   (-1)
48
49/* Sector size for all ATA devices */
50#define ATA_SECTOR_SIZE                 512
51
52
53#define ATA_MAX_CMD_REG_OFFSET          8
54
55/* ATA modes */
56#define ATA_MODES_PIO3    0x001
57#define ATA_MODES_PIO4    0x002
58
59#define ATA_MODES_PIO     0x003
60
61#define ATA_MODES_DMA0    0x004
62#define ATA_MODES_DMA1    0x008
63#define ATA_MODES_DMA2    0x010
64
65#define ATA_MODES_UDMA0   0x020
66#define ATA_MODES_UDMA1   0x040
67#define ATA_MODES_UDMA2   0x080
68#define ATA_MODES_UDMA3   0x100
69#define ATA_MODES_UDMA4   0x200
70#define ATA_MODES_UDMA5   0x400
71
72#define ATA_MODES_UDMA    0x7e0
73#define ATA_MODES_DMA     0x7fc
74
75
76/* ATA Commands */
77
78/* Types of ATA commands */
79#define ATA_COMMAND_TYPE_NON_DATA   0
80#define ATA_COMMAND_TYPE_PIO_IN     1
81#define ATA_COMMAND_TYPE_PIO_OUT    2
82#define ATA_COMMAND_TYPE_DMA        3
83
84/* ATA commands opcodes */
85/*
86 * Commands present in both ATA-2 and ATA-4 specs.
87 * Some commands have two values in ATA-2,
88 * in such case value from ATA-4 used.
89 * Some commands have slightly different names in these specifications,
90 * so names from ATA-4 are used.
91 */
92#define ATA_COMMAND_NOP                          0x00
93#define ATA_COMMAND_READ_SECTORS                 0x20
94#define ATA_COMMAND_WRITE_SECTORS                0x30
95#define ATA_COMMAND_READ_VERIFY_SECTORS          0x40
96#define ATA_COMMAND_SEEK                         0x70 /* or 0x7. */
97#define ATA_COMMAND_EXECUTE_DEVICE_DIAGNOSTIC    0x90
98#define ATA_COMMAND_INITIALIZE_DEVICE_PARAMETERS 0x91
99#define ATA_COMMAND_DOWNLOAD_MICROCODE           0x92
100#define ATA_COMMAND_READ_MULTIPLE                0xc4
101#define ATA_COMMAND_WRITE_MULTIPLE               0xc5
102#define ATA_COMMAND_SET_MULTIPLE_MODE            0xc6
103#define ATA_COMMAND_READ_DMA                     0xc8
104#define ATA_COMMAND_WRITE_DMA                    0xca
105#define ATA_COMMAND_STANDBY_IMMEDIATE            0xe0 /* or 0x94 */
106#define ATA_COMMAND_IDLE_IMMEDIATE               0xe1 /* or 0x95 */
107#define ATA_COMMAND_STANDBY                      0xe2 /* or 0x96 */
108#define ATA_COMMAND_IDLE                         0xe3 /* or 0x97 */
109#define ATA_COMMAND_READ_BUFFER                  0xe4
110#define ATA_COMMAND_CHECK_POWER_MODE             0xe5 /* or 0x98 in ATA-2 */
111#define ATA_COMMAND_SLEEP                        0xe6 /* or 0x99 */
112#define ATA_COMMAND_WRITE_BUFFER                 0xe8
113#define ATA_COMMAND_IDENTIFY_DEVICE              0xec
114#define ATA_COMMAND_SET_FEATURES                 0xef
115
116/* Commands present in both ATA-2 and ATA-4 specs: removable media */
117#define ATA_COMMAND_MEDIA_LOCK                   0xde
118#define ATA_COMMAND_MEDIA_UNLOCK                 0xdf
119#define ATA_COMMAND_MEDIA_EJECT                  0xed
120
121
122/* Commands present in ATA-2, but not in ATA-4 (not used) */
123#define ATA_COMMAND_RECALIBRATE                  0x10 /* or 0x1. */
124#define ATA_COMMAND_READ_SECTOR_NON_RETRY        0x21
125#define ATA_COMMAND_READ_LONG_RETRY              0x22
126#define ATA_COMMAND_READ_LONG_NON_RETRY          0x23
127#define ATA_COMMAND_WRITE_SECTOR_NON_RETRY       0x31
128#define ATA_COMMAND_WRITE_LONG_RETRY             0x32
129#define ATA_COMMAND_WRITE_LONG_NON_RETRY         0x33
130#define ATA_COMMAND_WRITE_VERIFY                 0x3c
131#define ATA_COMMAND_READ_VERIFY_SECTOR_NON_RETRY 0x41
132#define ATA_COMMAND_FORMAT_TRACK                 0x50
133#define ATA_COMMAND_READ_DMA_NON_RETRY           0xc9
134#define ATA_COMMAND_WRITE_DMA_NON_RETRY          0xcb
135#define ATA_COMMAND_ACKNOWLEGE_MEDIA_CHANGE      0xdb
136#define ATA_COMMAND_BOOT_POST_BOOT               0xdc
137#define ATA_COMMAND_BOOT_PRE_BOOT                0xdd
138#define ATA_COMMAND_WRITE_SAME                   0xe9
139
140/* Commands from ATA-4 specification: CFA feature set */
141#define ATA_COMMAND_CFA_REQUEST_EXTENDED_ERROR_CODE  0x03
142#define ATA_COMMAND_CFA_WRITE_SECTORS_WITHOUT_ERASE  0x38
143#define ATA_COMMAND_CFA_TRANSLATE_SECTOR             0x87
144#define ATA_COMMAND_CFA_ERASE_SECTORS                0xc0
145#define ATA_COMMAND_CFA_WRITE_MULTIPLE_WITHOUT_ERASE 0xcd
146
147/* Commands from ATA-4 specification: commands to use with PACKET command */
148#define ATA_COMMAND_DEVICE_RESET                 0x08
149#define ATA_COMMAND_PACKET                       0xa0
150#define ATA_COMMAND_IDENTIFY_PACKET_DEVICE       0xa1
151#define ATA_COMMAND_SERVICE                      0xa2
152
153/* Commands from ATA-4 specification: SECURITY commands */
154#define ATA_COMMAND_SECURITY_SET_PASSWORD        0xf1
155#define ATA_COMMAND_SECURITY_UNLOCK              0xf2
156#define ATA_COMMAND_SECURITY_ERASE_PREPARE       0xf3
157#define ATA_COMMAND_SECURITY_ERASE_UNIT          0xf4
158#define ATA_COMMAND_SECURITY_FREEZE_LOCK         0xf5
159#define ATA_COMMAND_SECURITY_DISABLE_PASSWORD    0xf6
160
161/* Commands from ATA-4 specification: other commands */
162#define ATA_COMMAND_SMART                        0xb0
163#define ATA_COMMAND_READ_DMA_QUEUED              0xc7
164#define ATA_COMMAND_WRITE_DMA_QUEUED             0xcc
165#define ATA_COMMAND_GET_MEDIA_STATUS             0xda
166#define ATA_COMMAND_FLUSH_CACHE                  0xe7
167#define ATA_COMMAND_READ_NATIVE_MAX_ADDRESS      0xf8
168#define ATA_COMMAND_SET_MAX_ADDRESS              0xf9
169
170#define ATA_REGISTERS_VALUE(reg)    (1 << (reg))
171
172/* ATA IDENTIFY DEVICE command words and bits */
173#define ATA_IDENT_WORD_RW_MULT                   47
174#define ATA_IDENT_WORD_CAPABILITIES              49
175#define ATA_IDENT_WORD_FIELD_VALIDITY            53
176#define ATA_IDENT_WORD_NUM_OF_CURR_LOG_CLNDS     54
177#define ATA_IDENT_WORD_NUM_OF_CURR_LOG_HEADS     55
178#define ATA_IDENT_WORD_NUM_OF_CURR_LOG_SECS      56
179#define ATA_IDENT_WORD_MULT_SECS                 59
180#define ATA_IDENT_WORD_NUM_OF_USR_SECS0          60
181#define ATA_IDENT_WORD_NUM_OF_USR_SECS1          61
182#define ATA_IDENT_WORD_PIO_SPPRTD                64
183
184#define ATA_IDENT_BIT_VALID                      0x02
185
186/*
187 * It is OR for all ATA_REGISTERS_VALUE(reg), where reg is neccessary
188 * for setting block position
189 */
190#define ATA_REGISTERS_POSITION       0xfc
191
192#define ATA_MINOR_NUM_RESERVED_PER_ATA_DEVICE     64
193
194#define ATA_MAX_RTEMS_INT_VEC_NUMBER              255
195
196#define ATA_MAX_NAME_LENGTH                       10
197
198/* diagnostic codes */
199#define ATA_DEV0_PASSED_DEV1_PASSED_OR_NOT_PRSNT  0x01
200#define ATA_DEV0_PASSED_DEV1_FAILED               0x81
201#define ATA_DEV1_PASSED_DEV0_FAILED               0x80
202
203/*
204 * Obtain ata device parameters by controller minor number and device number
205 */
206#define ATA_DEV_INFO(controller_minor, dev) \
207    ata_ide_ctrls[controller_minor].device[dev]
208
209/* ATA RTEMS driver internal data stuctures */
210
211/* Command block registers */
212typedef struct ata_registers_s {
213    unsigned16 regs[8];  /* command block registers */
214    unsigned16 to_read;  /* mask: which ata registers should be read */
215    unsigned16 to_write; /* mask: which ata registers should be written */
216} ata_registers_t;
217
218/* ATA request */
219typedef struct ata_req_s {
220    Chain_Node        link;   /* link in requests chain */
221    char              type;   /* request type */
222    ata_registers_t   regs;   /* ATA command */
223    rtems_unsigned32  cnt;    /* Number of sectors to be exchanged */
224    rtems_unsigned32  cbuf;   /* number of current buffer from breq in use */
225    rtems_unsigned32  pos;    /* current position in 'cbuf' */
226    blkdev_request   *breq;   /* blkdev_request which corresponds to the
227                               * ata request
228                               */
229    rtems_id          sema;   /* semaphore which is used if synchronous
230                               * processing of the ata request is required
231                               */
232    rtems_status_code status; /* status of ata request processing */
233    int               error;  /* device error code */
234} ata_req_t;
235
236/* call callback provided by block device request if it is defined */
237#define ATA_EXEC_CALLBACK(areq, status, error) \
238    do {\
239        if (((areq)->breq != NULL) && ((areq)->breq->req_done != NULL)) \
240            (areq)->breq->req_done((areq)->breq->done_arg, status, error); \
241    } while (0)
242
243/* ATA RTEMS driver events types */
244typedef enum ata_msg_type_s {
245    ATA_MSG_GEN_EVT = 1,     /* general event */
246    ATA_MSG_SUCCESS_EVT,     /* success event */
247    ATA_MSG_ERROR_EVT,       /* error event */
248    ATA_MSG_PROCESS_NEXT_EVT /* process next request event */
249} ata_msg_type_t;
250
251/* ATA RTEMS driver message */
252typedef struct ata_queue_msg_s {
253    ata_msg_type_t            type;       /* message type */
254    rtems_device_minor_number ctrl_minor; /* IDE controller minor number */
255    int                       error;      /* error code */
256} ata_queue_msg_t;
257
258/* macros for messages processing */
259#define ATA_FILL_MSG(msg, evt_type, ctrl, err)\
260    do {\
261        msg.type = evt_type;\
262        msg.ctrl_minor = ctrl;\
263        msg.error = err;\
264    } while (0)
265
266#define ATA_SEND_EVT(msg, type, ctrl, err)\
267    do {\
268        rtems_status_code rc;\
269        ATA_FILL_MSG(msg, type, ctrl, err);\
270        rc = rtems_message_queue_send(ata_queue_id, &msg,\
271                                      sizeof(ata_queue_msg_t));\
272        if (rc != RTEMS_SUCCESSFUL)\
273            rtems_fatal_error_occurred(RTEMS_INTERNAL_ERROR);\
274    } while (0)
275
276/*
277 * Array of such structures is indexed by interrupt vecotrs and used for
278 * mapping of IDE controllers and interrupt vectors
279 */
280typedef struct ata_int_st_s {
281    Chain_Node                link;
282    rtems_device_minor_number ctrl_minor;
283} ata_int_st_t;
284
285/*
286 * Mapping of rtems ATA devices to the following pairs:
287 * (IDE controller number served the device, device number on the controller)
288 */
289typedef struct ata_ide_dev_s {
290    int ctrl_minor;/* minor number of IDE controller served rtems ATA device */
291    int device;    /* device number on IDE controller (0 or 1) */
292} ata_ide_dev_t;
293
294/*
295 * ATA device description
296 */
297typedef struct ata_dev_s {
298    signed8     present;     /* 1 -- present, 0 -- not present, */
299                             /* -1 -- non-initialized */
300    unsigned16  cylinders;
301    unsigned16  heads;
302    unsigned16  sectors;
303    unsigned32  lba_sectors;  /* for small disk */
304                              /* == cylinders * heads * sectors */
305
306    unsigned8   lba_avaible;  /* 0 - CHS mode, 1 - LBA mode */
307
308    unsigned8   max_multiple; /* 0 if READ/WRITE MULTIPLE is unsupported */
309    unsigned8   current_multiple;
310
311    unsigned8   modes_avaible; /* OR of values for this modes */
312    unsigned8   mode_active;
313} ata_dev_t;
314
315/*
316 * This structure describes controller state, devices configuration on the
317 * controller and chain of ATA requests to the controller. Array of such
318 * structures is indexed by controller minor number
319 */
320typedef struct ata_ide_ctrl_s {
321    rtems_boolean present;   /* controller state */
322    ata_dev_t     device[2]; /* ata diveces description */
323    Chain_Control reqs;      /* requests chain */
324} ata_ide_ctrl_t;
325
326#endif /* __ATA_INTERNAL_H__ */
327
328 
Note: See TracBrowser for help on using the repository browser.