source: rtems/c/src/libchip/ide/ata_internal.h @ 7357f566

4.104.115
Last change on this file since 7357f566 was 7357f566, checked in by Chris Johns <chrisj@…>, on Oct 8, 2009 at 7:25:15 AM

2009-10-08 Chris Johns <chrisj@…>

  • libchip/ide/ata.c, c/src/libchip/ide/ata_internal.h: Remove the multiblock support from the ATA driver. Multiblock at the disk level should not be a global policy as a disk may have more than one partition with different block sizes. An IDE driver could decide to use the feature with DMA but this a driver specific design choice. Fixed bugs relating to variable block sizes and large block transfer.
  • c/src/libchip/ide/ide_controller.c, c/src/libchip/ide/ide_ctrl_cfg.h, c/src/libchip/ide/ide_ctrl_io.h: Changed the block size to 32bits so blocks of 64K or bigger can be transfered in a single driver call.
  • Property mode set to 100644
File size: 11.1 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.rtems.com/license/LICENSE.
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
56/* ATA Commands */
57
58/* Types of ATA commands */
59#define ATA_COMMAND_TYPE_NON_DATA   0
60#define ATA_COMMAND_TYPE_PIO_IN     1
61#define ATA_COMMAND_TYPE_PIO_OUT    2
62#define ATA_COMMAND_TYPE_DMA        3
63
64/* ATA commands opcodes */
65/*
66 * Commands present in both ATA-2 and ATA-4 specs.
67 * Some commands have two values in ATA-2,
68 * in such case value from ATA-4 used.
69 * Some commands have slightly different names in these specifications,
70 * so names from ATA-4 are used.
71 */
72#define ATA_COMMAND_NOP                          0x00
73#define ATA_COMMAND_READ_SECTORS                 0x20
74#define ATA_COMMAND_WRITE_SECTORS                0x30
75#define ATA_COMMAND_READ_VERIFY_SECTORS          0x40
76#define ATA_COMMAND_SEEK                         0x70 /* or 0x7. */
77#define ATA_COMMAND_EXECUTE_DEVICE_DIAGNOSTIC    0x90
78#define ATA_COMMAND_INITIALIZE_DEVICE_PARAMETERS 0x91
79#define ATA_COMMAND_DOWNLOAD_MICROCODE           0x92
80#define ATA_COMMAND_READ_MULTIPLE                0xc4
81#define ATA_COMMAND_WRITE_MULTIPLE               0xc5
82#define ATA_COMMAND_SET_MULTIPLE_MODE            0xc6
83#define ATA_COMMAND_READ_DMA                     0xc8
84#define ATA_COMMAND_WRITE_DMA                    0xca
85#define ATA_COMMAND_STANDBY_IMMEDIATE            0xe0 /* or 0x94 */
86#define ATA_COMMAND_IDLE_IMMEDIATE               0xe1 /* or 0x95 */
87#define ATA_COMMAND_STANDBY                      0xe2 /* or 0x96 */
88#define ATA_COMMAND_IDLE                         0xe3 /* or 0x97 */
89#define ATA_COMMAND_READ_BUFFER                  0xe4
90#define ATA_COMMAND_CHECK_POWER_MODE             0xe5 /* or 0x98 in ATA-2 */
91#define ATA_COMMAND_SLEEP                        0xe6 /* or 0x99 */
92#define ATA_COMMAND_WRITE_BUFFER                 0xe8
93#define ATA_COMMAND_IDENTIFY_DEVICE              0xec
94#define ATA_COMMAND_SET_FEATURES                 0xef
95
96/* Commands present in both ATA-2 and ATA-4 specs: removable media */
97#define ATA_COMMAND_MEDIA_LOCK                   0xde
98#define ATA_COMMAND_MEDIA_UNLOCK                 0xdf
99#define ATA_COMMAND_MEDIA_EJECT                  0xed
100
101
102/* Commands present in ATA-2, but not in ATA-4 (not used) */
103#define ATA_COMMAND_RECALIBRATE                  0x10 /* or 0x1. */
104#define ATA_COMMAND_READ_SECTOR_NON_RETRY        0x21
105#define ATA_COMMAND_READ_LONG_RETRY              0x22
106#define ATA_COMMAND_READ_LONG_NON_RETRY          0x23
107#define ATA_COMMAND_WRITE_SECTOR_NON_RETRY       0x31
108#define ATA_COMMAND_WRITE_LONG_RETRY             0x32
109#define ATA_COMMAND_WRITE_LONG_NON_RETRY         0x33
110#define ATA_COMMAND_WRITE_VERIFY                 0x3c
111#define ATA_COMMAND_READ_VERIFY_SECTOR_NON_RETRY 0x41
112#define ATA_COMMAND_FORMAT_TRACK                 0x50
113#define ATA_COMMAND_READ_DMA_NON_RETRY           0xc9
114#define ATA_COMMAND_WRITE_DMA_NON_RETRY          0xcb
115#define ATA_COMMAND_ACKNOWLEGE_MEDIA_CHANGE      0xdb
116#define ATA_COMMAND_BOOT_POST_BOOT               0xdc
117#define ATA_COMMAND_BOOT_PRE_BOOT                0xdd
118#define ATA_COMMAND_WRITE_SAME                   0xe9
119
120/* Commands from ATA-4 specification: CFA feature set */
121#define ATA_COMMAND_CFA_REQUEST_EXTENDED_ERROR_CODE  0x03
122#define ATA_COMMAND_CFA_WRITE_SECTORS_WITHOUT_ERASE  0x38
123#define ATA_COMMAND_CFA_TRANSLATE_SECTOR             0x87
124#define ATA_COMMAND_CFA_ERASE_SECTORS                0xc0
125#define ATA_COMMAND_CFA_WRITE_MULTIPLE_WITHOUT_ERASE 0xcd
126
127/* Commands from ATA-4 specification: commands to use with PACKET command */
128#define ATA_COMMAND_DEVICE_RESET                 0x08
129#define ATA_COMMAND_PACKET                       0xa0
130#define ATA_COMMAND_IDENTIFY_PACKET_DEVICE       0xa1
131#define ATA_COMMAND_SERVICE                      0xa2
132
133/* Commands from ATA-4 specification: SECURITY commands */
134#define ATA_COMMAND_SECURITY_SET_PASSWORD        0xf1
135#define ATA_COMMAND_SECURITY_UNLOCK              0xf2
136#define ATA_COMMAND_SECURITY_ERASE_PREPARE       0xf3
137#define ATA_COMMAND_SECURITY_ERASE_UNIT          0xf4
138#define ATA_COMMAND_SECURITY_FREEZE_LOCK         0xf5
139#define ATA_COMMAND_SECURITY_DISABLE_PASSWORD    0xf6
140
141/* Commands from ATA-4 specification: other commands */
142#define ATA_COMMAND_SMART                        0xb0
143#define ATA_COMMAND_READ_DMA_QUEUED              0xc7
144#define ATA_COMMAND_WRITE_DMA_QUEUED             0xcc
145#define ATA_COMMAND_GET_MEDIA_STATUS             0xda
146#define ATA_COMMAND_FLUSH_CACHE                  0xe7
147#define ATA_COMMAND_READ_NATIVE_MAX_ADDRESS      0xf8
148#define ATA_COMMAND_SET_MAX_ADDRESS              0xf9
149
150#define ATA_REGISTERS_VALUE(reg)    (1 << (reg))
151
152/* ATA IDENTIFY DEVICE command words and bits */
153#define ATA_IDENT_WORD_RW_MULT                   47
154#define ATA_IDENT_WORD_CAPABILITIES              49
155#define ATA_IDENT_WORD_FIELD_VALIDITY            53
156#define ATA_IDENT_WORD_NUM_OF_CURR_LOG_CLNDS     54
157#define ATA_IDENT_WORD_NUM_OF_CURR_LOG_HEADS     55
158#define ATA_IDENT_WORD_NUM_OF_CURR_LOG_SECS      56
159#define ATA_IDENT_WORD_MULT_SECS                 59
160#define ATA_IDENT_WORD_NUM_OF_USR_SECS0          60
161#define ATA_IDENT_WORD_NUM_OF_USR_SECS1          61
162#define ATA_IDENT_WORD_PIO_SPPRTD                64
163
164#define ATA_IDENT_BIT_VALID                      0x02
165
166/*
167 * It is OR for all ATA_REGISTERS_VALUE(reg), where reg is neccessary
168 * for setting block position
169 */
170#define ATA_REGISTERS_POSITION       0xfc
171
172#define ATA_MINOR_NUM_RESERVED_PER_ATA_DEVICE     64
173
174#define ATA_MAX_RTEMS_INT_VEC_NUMBER              255
175
176#define ATA_MAX_NAME_LENGTH                       10
177
178/* diagnostic codes */
179#define ATA_DEV0_PASSED_DEV1_PASSED_OR_NOT_PRSNT  0x01
180#define ATA_DEV0_PASSED_DEV1_FAILED               0x81
181#define ATA_DEV1_PASSED_DEV0_FAILED               0x80
182
183/*
184 * Obtain ata device parameters by controller minor number and device number
185 */
186#define ATA_DEV_INFO(controller_minor, dev) \
187    ata_ide_ctrls[controller_minor].device[dev]
188
189/* ATA RTEMS driver internal data stuctures */
190
191/* Command block registers */
192typedef struct ata_registers_s {
193    uint16_t   regs[8];  /* command block registers */
194    uint16_t   to_read;  /* mask: which ata registers should be read */
195    uint16_t   to_write; /* mask: which ata registers should be written */
196} ata_registers_t;
197
198/* ATA request */
199typedef struct ata_req_s {
200    rtems_chain_node  link;   /* link in requests chain */
201    char              type;   /* request type */
202    ata_registers_t   regs;   /* ATA command */
203    uint32_t    cnt;    /* Number of sectors to be exchanged */
204    uint32_t    cbuf;   /* number of current buffer from breq in use */
205    uint32_t    pos;    /* current position in 'cbuf' */
206    rtems_blkdev_request *breq;   /* blkdev_request which corresponds to the
207                               * ata request
208                               */
209    rtems_id          sema;   /* semaphore which is used if synchronous
210                               * processing of the ata request is required
211                               */
212    rtems_status_code status; /* status of ata request processing */
213    int               error;  /* device error code */
214} ata_req_t;
215
216/* call callback provided by block device request if it is defined */
217#define ATA_EXEC_CALLBACK(areq, status, error) \
218    do {\
219        if (((areq)->breq != NULL) && ((areq)->breq->req_done != NULL)) \
220            (areq)->breq->req_done((areq)->breq->done_arg, status, error); \
221    } while (0)
222
223/* ATA RTEMS driver events types */
224typedef enum ata_msg_type_s {
225    ATA_MSG_GEN_EVT = 1,     /* general event */
226    ATA_MSG_SUCCESS_EVT,     /* success event */
227    ATA_MSG_ERROR_EVT,       /* error event */
228    ATA_MSG_PROCESS_NEXT_EVT /* process next request event */
229} ata_msg_type_t;
230
231/* ATA RTEMS driver message */
232typedef struct ata_queue_msg_s {
233    ata_msg_type_t            type;       /* message type */
234    rtems_device_minor_number ctrl_minor; /* IDE controller minor number */
235    int                       error;      /* error code */
236} ata_queue_msg_t;
237
238/* macros for messages processing */
239#define ATA_FILL_MSG(msg, evt_type, ctrl, err)\
240    do {\
241        msg.type = evt_type;\
242        msg.ctrl_minor = ctrl;\
243        msg.error = err;\
244    } while (0)
245
246#define ATA_SEND_EVT(msg, type, ctrl, err)\
247    do {\
248        rtems_status_code rc;\
249        ATA_FILL_MSG(msg, type, ctrl, err);\
250        rc = rtems_message_queue_send(ata_queue_id, &msg,\
251                                      sizeof(ata_queue_msg_t));\
252        if (rc != RTEMS_SUCCESSFUL)\
253            rtems_fatal_error_occurred(RTEMS_INTERNAL_ERROR);\
254    } while (0)
255
256/*
257 * Array of such structures is indexed by interrupt vecotrs and used for
258 * mapping of IDE controllers and interrupt vectors
259 */
260typedef struct ata_int_st_s {
261    rtems_chain_node          link;
262    rtems_device_minor_number ctrl_minor;
263} ata_int_st_t;
264
265/*
266 * Mapping of rtems ATA devices to the following pairs:
267 * (IDE controller number served the device, device number on the controller)
268 */
269typedef struct ata_ide_dev_s {
270    int ctrl_minor;/* minor number of IDE controller served rtems ATA device */
271    int device;    /* device number on IDE controller (0 or 1) */
272} ata_ide_dev_t;
273
274/*
275 * ATA device description
276 */
277typedef struct ata_dev_s {
278    int8_t      present;     /* 1 -- present, 0 -- not present, */
279                             /* -1 -- non-initialized */
280    uint16_t    cylinders;
281    uint16_t    heads;
282    uint16_t    sectors;
283    uint32_t    lba_sectors;  /* for small disk */
284                              /* == cylinders * heads * sectors */
285
286    uint8_t     lba_avaible;  /* 0 - CHS mode, 1 - LBA mode */
287
288    uint16_t  modes_available; /* OR of values for this modes */
289    uint16_t  mode_active;
290} ata_dev_t;
291
292/*
293 * This structure describes controller state, devices configuration on the
294 * controller and chain of ATA requests to the controller. Array of such
295 * structures is indexed by controller minor number
296 */
297typedef struct ata_ide_ctrl_s {
298    bool          present;   /* controller state */
299    ata_dev_t     device[2]; /* ata diveces description */
300    rtems_chain_control reqs; /* requests chain */
301} ata_ide_ctrl_t;
302
303#endif /* __ATA_INTERNAL_H__ */
Note: See TracBrowser for help on using the repository browser.