FreeNOS
ATAController.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __SERVER_ATA_ATACONTROLLER_H
19#define __SERVER_ATA_ATACONTROLLER_H
20
21#include <FreeNOS/User.h>
22#include <List.h>
23#include <Device.h>
24
39#define ATA_BASE_CMD0 0x1f0
40
42#define ATA_BASE_CMD1 0x170
43
45#define ATA_BASE_CTL0 0x3f6
46
48#define ATA_BASE_CTL1 0x376
49
64#define ATA_REG_DATA 0
65
70#define ATA_REG_ERROR 1
71
76#define ATA_REG_COUNT 2
77
82#define ATA_REG_ADDR0 3
83
87#define ATA_REG_ADDR1 4
88
92#define ATA_REG_ADDR2 5
93
97#define ATA_REG_SELECT 6
98
103#define ATA_REG_CMD 7
104
110#define ATA_REG_STATUS 7
111
125#define ATA_STATUS_ERROR 0x01
126
131#define ATA_STATUS_DATA 0x08
132
138#define ATA_STATUS_BUSY 0x80
139
154#define ATA_REG_RESET 0x4
155
160#define ATA_REG_INTR 0x2
161
172#define ATA_SEL_MASTER 0xa0
173
175#define ATA_SEL_MASTER_28 0xe0
176
178#define ATA_SEL_MASTER_48 0x40
179
190#define ATA_CMD_IDENTIFY 0xec
191
193#define ATA_CMD_READ 0x20
194
206#define IDENTIFY_TEXT_SWAP(field,size) \
207 \
208 ({ \
209 u8 tmp; \
210 \
211 for (int i = 0; i < (size); i+=2) \
212 { \
213 tmp = (field)[i]; \
214 (field)[i] = (field)[i+1]; \
215 (field)[i+1] = tmp; \
216 } \
217 })
218
245
249typedef struct ATADrive
250{
253
256}
258
262class ATAController : public Device
263{
264 public:
265
271 ATAController(const u32 inode);
272
279
290 virtual FileSystem::Result read(IOBuffer & buffer,
291 Size & size,
292 const Size offset);
293
301 virtual FileSystem::Result interrupt(const Size vector);
302
303 private:
304
310 void pollReady(bool noData = false);
311
312 private:
313
316
319};
320
326#endif /* __SERVER_ATA_ATACONTROLLER_H */
Input/Output operations specific to the ARM architecture.
Definition ARMIO.h:40
AT Attachment (ATA) Host Controller Device.
Arch::IO m_io
Port I/O object.
virtual FileSystem::Result initialize()
Configures the ATA controller.
List< ATADrive * > drives
Drives detected on the ATA bus.
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from a drive attached to the ATA controller.
virtual FileSystem::Result interrupt(const Size vector)
Process ATA interrupts.
void pollReady(bool noData=false)
Polls the Regular Status register.
Abstract device class interface.
Definition Device.h:36
Abstract Input/Output buffer.
Definition IOBuffer.h:38
Simple linked list template class.
Definition List.h:37
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned short u16
Unsigned 16-bit number.
Definition Types.h:56
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
Represents a Drive on the ATA bus.
IdentifyData identity
Bytes returned from IDENTIFY.
Size sectors
Number of sectors.
IDENTIFY data presentation.
u16 reserved5[12]
u16 reserved4[18]
u16 capabilities[2]