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 
222 typedef struct IdentifyData
223 {
226  u8 serial[20];
229  u8 model[40];
243 }
245 
249 typedef struct ATADrive
250 {
253 
256 }
257 ATADrive;
258 
262 class ATAController : public Device
263 {
264  public:
265 
271  ATAController(const u32 inode);
272 
278  virtual FileSystem::Result initialize();
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 */
IdentifyData::reserved6
u16 reserved6[2]
Definition: ATAController.h:241
ATAController::interrupt
virtual FileSystem::Result interrupt(const Size vector)
Process ATA interrupts.
Definition: ATAController.cpp:153
Device.h
IdentifyData
struct IdentifyData IdentifyData
IDENTIFY data presentation.
IdentifyData::reserved1
u16 reserved1[9]
Definition: ATAController.h:225
IdentifyData::model
u8 model[40]
Definition: ATAController.h:229
IdentifyData::sectors48
u64 sectors48
Definition: ATAController.h:240
ATAController::initialize
virtual FileSystem::Result initialize()
Configures the ATA controller.
Definition: ATAController.cpp:47
ATADrive
struct ATADrive ATADrive
Represents a Drive on the ATA bus.
IdentifyData::reserved2
u16 reserved2[3]
Definition: ATAController.h:227
ARMIO
Input/Output operations specific to the ARM architecture.
Definition: ARMIO.h:39
ATAController::ATAController
ATAController(const u32 inode)
Constructor.
Definition: ATAController.cpp:41
IdentifyData::reserved4
u16 reserved4[18]
Definition: ATAController.h:235
ATAController
AT Attachment (ATA) Host Controller Device.
Definition: ATAController.h:262
IdentifyData::maxTransfer
u16 maxTransfer
Definition: ATAController.h:230
ATAController::pollReady
void pollReady(bool noData=false)
Polls the Regular Status register.
Definition: ATAController.cpp:159
Device
Abstract device class interface.
Definition: Device.h:35
IdentifyData::serial
u8 serial[20]
Definition: ATAController.h:226
ATADrive
Represents a Drive on the ATA bus.
Definition: ATAController.h:249
IdentifyData::minorRevision
u16 minorRevision
Definition: ATAController.h:237
IdentifyData::type
u16 type
Definition: ATAController.h:224
u64
unsigned long long u64
Unsigned 64-bit number.
Definition: Types.h:50
IdentifyData::firmware
u8 firmware[8]
Definition: ATAController.h:228
IdentifyData::sectorSize
u16 sectorSize
Definition: ATAController.h:242
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
IdentifyData::majorRevision
u16 majorRevision
Definition: ATAController.h:236
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
ATADrive::sectors
Size sectors
Number of sectors.
Definition: ATAController.h:255
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
ATAController::drives
List< ATADrive * > drives
Drives detected on the ATA bus.
Definition: ATAController.h:315
ATAController::m_io
Arch::IO m_io
Port I/O object.
Definition: ATAController.h:318
IdentifyData::sectors28
u32 sectors28
Definition: ATAController.h:234
IdentifyData::reserved5
u16 reserved5[12]
Definition: ATAController.h:239
IdentifyData::capabilities
u16 capabilities[2]
Definition: ATAController.h:232
ATADrive::identity
IdentifyData identity
Bytes returned from IDENTIFY.
Definition: ATAController.h:252
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
IdentifyData::reserved3
u16 reserved3[8]
Definition: ATAController.h:233
ATAController::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from a drive attached to the ATA controller.
Definition: ATAController.cpp:101
List< ATADrive * >
IdentifyData
IDENTIFY data presentation.
Definition: ATAController.h:222
IdentifyData::supported
u16 supported[6]
Definition: ATAController.h:238
IdentifyData::trustedFeatures
u16 trustedFeatures
Definition: ATAController.h:231
List.h