summaryrefslogtreecommitdiff
path: root/Source/Kernel/Devices
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-29 17:06:47 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-29 17:06:47 +0100
commit32ffa508b6ee9c9b36e3a054d218ee90caea4c8b (patch)
tree4136164e7fb52005d57782c9ae70da89eca85807 /Source/Kernel/Devices
parent2be9def10e048b3245bb14e9fb57324c11c527d6 (diff)
downloadMelon-32ffa508b6ee9c9b36e3a054d218ee90caea4c8b.tar.gz
Melon-32ffa508b6ee9c9b36e3a054d218ee90caea4c8b.zip
make qemu-hdd now works great
Diffstat (limited to 'Source/Kernel/Devices')
-rw-r--r--Source/Kernel/Devices/ATA/ATAController.class.cpp4
-rw-r--r--Source/Kernel/Devices/ATA/ATAController.class.h3
-rw-r--r--Source/Kernel/Devices/ATA/ATADrive.class.cpp4
3 files changed, 9 insertions, 2 deletions
diff --git a/Source/Kernel/Devices/ATA/ATAController.class.cpp b/Source/Kernel/Devices/ATA/ATAController.class.cpp
index 69a18a4..d8073d0 100644
--- a/Source/Kernel/Devices/ATA/ATAController.class.cpp
+++ b/Source/Kernel/Devices/ATA/ATAController.class.cpp
@@ -27,14 +27,16 @@ void ATAController::detect() {
}
}
-ATAController::ATAController(u32int base, u8int number) {
+ATAController::ATAController(u32int base, u8int number) : Mutex(MUTEX_TRUE) {
m_base = base; m_number = number;
m_drives[0] = NULL; m_drives[1] = NULL;
identify(false); //Identify master device
identify(true); //Identify slave device
+ unlock();
}
void ATAController::identify(bool slave) {
+ if (!locked()) return;
if (m_drives[(slave ? 1 : 0)] != NULL) return;
writeByte(ATA_PORT_DRIVE_SELECT, (slave ? 0xB0 : 0xA0));
writeByte(ATA_PORT_COMMAND, ATA_CMD_IDENTIFY);
diff --git a/Source/Kernel/Devices/ATA/ATAController.class.h b/Source/Kernel/Devices/ATA/ATAController.class.h
index a12b835..89176c9 100644
--- a/Source/Kernel/Devices/ATA/ATAController.class.h
+++ b/Source/Kernel/Devices/ATA/ATAController.class.h
@@ -2,6 +2,7 @@
#define DEF_ATACONTROLLER_CLASS_H
#include <Devices/Device.proto.h>
+#include <Mutex.class.h>
#define ATA_BUS1_BASE 0x1F0
#define ATA_BUS2_BASE 0x170
@@ -21,7 +22,7 @@
class ATADrive;
-class ATAController : public Device {
+class ATAController : public Device, public Mutex {
friend class ATADrive;
private:
ATAController(u32int base, u8int number);
diff --git a/Source/Kernel/Devices/ATA/ATADrive.class.cpp b/Source/Kernel/Devices/ATA/ATADrive.class.cpp
index d9cc4a7..247e798 100644
--- a/Source/Kernel/Devices/ATA/ATADrive.class.cpp
+++ b/Source/Kernel/Devices/ATA/ATADrive.class.cpp
@@ -37,6 +37,7 @@ void ATADrive::cmdCommon(u32int numblock, u32int count) {
bool ATADrive::readBlocks(u64int start, u32int count, u8int* data) {
if (start + count >= m_blockCount) return false;
+ m_ctrlr->waitLock();
cmdCommon(start, count);
m_ctrlr->writeByte(ATA_PORT_COMMAND, ATA_CMD_READ);
@@ -47,6 +48,7 @@ bool ATADrive::readBlocks(u64int start, u32int count, u8int* data) {
data[idx * 2] = (u8int)tmpword;
data[idx * 2 + 1] = (u8int)(tmpword >> 8);
}
+ m_ctrlr->unlock();
return true;
}
@@ -54,6 +56,7 @@ bool ATADrive::writeBlocks(u64int start, u32int count, u8int* data) {
if (start + count >= m_blockCount) return false;
if (readOnly()) return false;
+ m_ctrlr->waitLock();
cmdCommon(start, count);
m_ctrlr->writeByte(ATA_PORT_COMMAND, ATA_CMD_WRITE);
@@ -63,6 +66,7 @@ bool ATADrive::writeBlocks(u64int start, u32int count, u8int* data) {
u16int tmpword = (data[idx * 2]) | (data[idx * 2 + 1] << 8);
m_ctrlr->writeByte(ATA_PORT_DATA, tmpword);
}
+ m_ctrlr->unlock();
return true;
}