1 #ifndef CYGONCE_IDE_DISK_H
2 #define CYGONCE_IDE_DISK_H
3 //==========================================================================
7 // IDE polled mode disk driver defines
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Red Hat, Inc.
14 // Copyright (C) 2004 eCosCentric, Ltd.
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
48 //####DESCRIPTIONEND####
50 //==========================================================================
52 // IDE Register Indices
53 #define IDE_REG_DATA 0
54 #define IDE_REG_ERROR 1
55 #define IDE_REG_FEATURES 1
56 #define IDE_REG_COUNT 2
57 #define IDE_REG_REASON 2 // ATAPI
58 #define IDE_REG_LBALOW 3
59 #define IDE_REG_LBAMID 4
60 #define IDE_REG_LBAHI 5
61 #define IDE_REG_DEVICE 6
62 #define IDE_REG_STATUS 7
63 #define IDE_REG_COMMAND 7
65 #define IDE_STAT_BSY 0x80
66 #define IDE_STAT_DRDY 0x40
67 #define IDE_STAT_SERVICE 0x10
68 #define IDE_STAT_DRQ 0x08
69 #define IDE_STAT_CORR 0x04
70 #define IDE_STAT_ERR 0x01
72 #define IDE_REASON_REL 0x04
73 #define IDE_REASON_IO 0x02
74 #define IDE_REASON_COD 0x01
77 #define IDE_DEV_PRESENT 1 // Device is present
78 #define IDE_DEV_PACKET 2 // Supports packet interface
79 #define IDE_DEV_ADDR48 3 // Supports 48bit addressing
81 typedef struct ide_identify_data_t_ {
82 cyg_uint16 general_conf; // 00 : general configuration
83 cyg_uint16 num_cylinders; // 01 : number of cylinders (default CHS trans)
84 cyg_uint16 reserved0; // 02 : reserved
85 cyg_uint16 num_heads; // 03 : number of heads (default CHS trans)
86 cyg_uint16 num_ub_per_track; // 04 : number of unformatted bytes per track
87 cyg_uint16 num_ub_per_sector; // 05 : number of unformatted bytes per sector
88 cyg_uint16 num_sectors; // 06 : number of sectors per track (default CHS trans)
89 cyg_uint16 num_card_sectors[2]; // 07-08 : number of sectors per card
90 cyg_uint16 reserved1; // 09 : reserved
91 cyg_uint16 serial[10]; // 10-19 : serial number (string)
92 cyg_uint16 buffer_type; // 20 : buffer type (dual ported)
93 cyg_uint16 buffer_size; // 21 : buffer size in 512 increments
94 cyg_uint16 num_ECC_bytes; // 22 : number of ECC bytes passed on R/W Long cmds
95 cyg_uint16 firmware_rev[4]; // 23-26 : firmware revision (string)
96 cyg_uint16 model_num[20]; // 27-46 : model number (string)
97 cyg_uint16 rw_mult_support; // 47 : max number of sectors on R/W multiple cmds
98 cyg_uint16 reserved2; // 48 : reserved
99 cyg_uint16 capabilities; // 49 : LBA, DMA, IORDY support indicator
100 cyg_uint16 reserved3; // 50 : reserved
101 cyg_uint16 pio_xferc_timing; // 51 : PIO data transfer cycle timing mode
102 cyg_uint16 dma_xferc_timing; // 52 : single word DMA data transfer cycle timing mode
103 cyg_uint16 cur_field_validity; // 53 : words 54-58 validity (0 == not valid)
104 cyg_uint16 cur_cylinders; // 54 : number of current cylinders
105 cyg_uint16 cur_heads; // 55 : number of current heads
106 cyg_uint16 cur_spt; // 56 : number of current sectors per track
107 cyg_uint16 cur_capacity[2]; // 57-58 : current capacity in sectors
108 cyg_uint16 mult_sectors; // 59 : multiple sector setting
109 cyg_uint16 lba_total_sectors[2]; // 60-61 : total sectors in LBA mode
110 cyg_uint16 sw_dma; // 62 : single word DMA support
111 cyg_uint16 mw_dma; // 63 : multi word DMA support
112 cyg_uint16 apio_modes; // 64 : advanced PIO transfer mode supported
113 cyg_uint16 min_dma_timing; // 65 : minimum multiword DMA transfer cycle
114 cyg_uint16 rec_dma_timing; // 66 : recommended multiword DMA cycle
115 cyg_uint16 min_pio_timing; // 67 : min PIO transfer time without flow control
116 cyg_uint16 min_pio_iordy_timing; // 68 : min PIO transfer time with IORDY flow control
117 // cyg_uint16 reserved4[187]; // 69-255: reserved
118 } ide_identify_data_t;
121 typedef struct ide_disk_info_t_ {
126 // ----------------------------------------------------------------------------
128 static cyg_bool ide_disk_init(struct cyg_devtab_entry *tab);
130 static Cyg_ErrNo ide_disk_read(disk_channel *chan,
133 cyg_uint32 block_num);
136 static Cyg_ErrNo ide_disk_write(disk_channel *chan,
139 cyg_uint32 block_num);
141 static Cyg_ErrNo ide_disk_get_config(disk_channel *chan,
146 static Cyg_ErrNo ide_disk_set_config(disk_channel *chan,
151 static Cyg_ErrNo ide_disk_lookup(struct cyg_devtab_entry **tab,
152 struct cyg_devtab_entry *sub_tab,
155 static DISK_FUNS(ide_disk_funs,
162 // ----------------------------------------------------------------------------
164 #define IDE_DISK_INSTANCE(_number_,_port_,_chan_,_mbr_supp_,_name_) \
165 static ide_disk_info_t ide_disk_info##_number_ = { \
166 port: (cyg_uint8) _port_, \
167 chan: (cyg_uint8) _chan_ \
169 DISK_CHANNEL(ide_disk_channel##_number_, \
171 ide_disk_info##_number_, \
175 BLOCK_DEVTAB_ENTRY(ide_disk_io##_number_, \
178 &cyg_io_disk_devio, \
181 &ide_disk_channel##_number_ \
184 // ----------------------------------------------------------------------------
186 #endif // CYGONCE_IDE_DISK_H