summaryrefslogtreecommitdiff
path: root/Source/Kernel/Devices/ATA/ATAController.class.cpp
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-29 16:22:01 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-29 16:22:01 +0100
commit41874c455c755f00ca73c2e2ee5ab8c4b0dbe61e (patch)
tree95986807bde312286c28297059873a6c66b72566 /Source/Kernel/Devices/ATA/ATAController.class.cpp
parenta913d4c2cb4daf10c0eac4d548fccb26b2a9f099 (diff)
downloadMelon-41874c455c755f00ca73c2e2ee5ab8c4b0dbe61e.tar.gz
Melon-41874c455c755f00ca73c2e2ee5ab8c4b0dbe61e.zip
Reading from HDD is now possible !
Diffstat (limited to 'Source/Kernel/Devices/ATA/ATAController.class.cpp')
-rw-r--r--Source/Kernel/Devices/ATA/ATAController.class.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/Source/Kernel/Devices/ATA/ATAController.class.cpp b/Source/Kernel/Devices/ATA/ATAController.class.cpp
new file mode 100644
index 0000000..69a18a4
--- /dev/null
+++ b/Source/Kernel/Devices/ATA/ATAController.class.cpp
@@ -0,0 +1,53 @@
+#include "ATADrive.class.h"
+
+#include <DeviceManager/Dev.ns.h>
+#include <VFS/Part.ns.h>
+
+String ATAController::getClass() {
+ return "controller.ata";
+}
+
+String ATAController::getName() {
+ return String("ATA controller #") + String::number(m_number);
+}
+
+void ATAController::detect() {
+ ATAController *c[2];
+ c[0] = new ATAController(ATA_BUS1_BASE, 0);
+ c[1] = new ATAController(ATA_BUS2_BASE, 1);
+ Dev::registerDevice(c[0]); Dev::registerDevice(c[1]);
+ for (u32int d = 0; d < 2; d++) {
+ for (u32int r = 0; r < 2; r++) {
+ ATADrive* drv = c[d]->m_drives[r];
+ if (drv != 0) {
+ Dev::registerDevice(drv);
+ Part::registerDevice(drv);
+ }
+ }
+ }
+}
+
+ATAController::ATAController(u32int base, u8int number) {
+ m_base = base; m_number = number;
+ m_drives[0] = NULL; m_drives[1] = NULL;
+ identify(false); //Identify master device
+ identify(true); //Identify slave device
+}
+
+void ATAController::identify(bool slave) {
+ if (m_drives[(slave ? 1 : 0)] != NULL) return;
+ writeByte(ATA_PORT_DRIVE_SELECT, (slave ? 0xB0 : 0xA0));
+ writeByte(ATA_PORT_COMMAND, ATA_CMD_IDENTIFY);
+ u8int ret = readByte(ATA_PORT_COMMAND);
+ if (ret == 0) return; //Drive does not exist
+ while ((ret & 0x88) != 0x08 and (ret & 1) != 1) {
+ ret = readByte(ATA_PORT_COMMAND);
+ }
+ if ((ret & 1) == 1) return; //Error while IDENTIFY
+ u16int data[256];
+ for (u32int i = 0; i < 256; i++) data[i] = readWord(ATA_PORT_DATA);
+ u32int blocks = (data[61] << 16) | data[60];
+ if (blocks != 0) { //Drive supports LBA28
+ m_drives[(slave ? 1 : 0)] = new ATADrive(this, slave, blocks, data);
+ }
+}