summaryrefslogtreecommitdiff
path: root/Source/Kernel/Devices/ATA/ATAController.class.h
blob: 89176c96e8888100f053d9f9f1d420b206b87259 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef DEF_ATACONTROLLER_CLASS_H
#define DEF_ATACONTROLLER_CLASS_H

#include <Devices/Device.proto.h>
#include <Mutex.class.h>

#define ATA_BUS1_BASE 0x1F0
#define ATA_BUS2_BASE 0x170

#define ATA_PORT_DATA 0
#define ATA_PORT_FEATURES_ERROR 1
#define ATA_PORT_SECT_COUNT 2
#define ATA_PORT_PARTIAL1 3
#define ATA_PORT_PARTIAL2 4
#define ATA_PORT_PARTIAL3 5
#define ATA_PORT_DRIVE_SELECT 6
#define ATA_PORT_COMMAND 7

#define ATA_CMD_IDENTIFY 0xEC
#define ATA_CMD_READ 0x20
#define ATA_CMD_WRITE 0x30

class ATADrive;

class ATAController : public Device, public Mutex {
	friend class ATADrive;
	private:
	ATAController(u32int base, u8int number);

	u32int m_base;
	u8int m_number;

	ATADrive* m_drives[2];

	void writeWord(u16int port, u16int word) { Sys::outw(m_base + port, word); }
	void writeByte(u16int port, u8int byte) { Sys::outb(m_base + port, byte); }
	u8int readByte(u16int port) { return Sys::inb(m_base + port); }
	u16int readWord(u16int port) { return Sys::inw(m_base + port); }

	void identify(bool slave);	//Identifies a drive and adds it to m_drives

	public:
	static void detect();
	String getClass();
	String getName();
};

#endif