summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-06 02:51:58 +0200
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-06 02:51:58 +0200
commitef604f691e2e3a6f710c96d0270cd9e2a223f08d (patch)
treec0320f8384d2f6ff24c56fb26cfdfeff8dd01bd3 /Private/HALKit
parente47a33d7d4f70c54a27e96df437e6d9ac4e829cf (diff)
Kernel: Worked on driver support, add standard disk calls.
Bootloader: Fix formatting. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/HALKit')
-rw-r--r--Private/HALKit/AMD64/PCI/Iterator.cxx6
-rw-r--r--Private/HALKit/AMD64/Storage/AHCI.cxx43
-rw-r--r--Private/HALKit/AMD64/Storage/ATA-DMA.cxx4
-rw-r--r--Private/HALKit/AMD64/Storage/ATA-PIO.cxx22
4 files changed, 58 insertions, 17 deletions
diff --git a/Private/HALKit/AMD64/PCI/Iterator.cxx b/Private/HALKit/AMD64/PCI/Iterator.cxx
index eb3f7b13..151d8780 100644
--- a/Private/HALKit/AMD64/PCI/Iterator.cxx
+++ b/Private/HALKit/AMD64/PCI/Iterator.cxx
@@ -12,9 +12,9 @@
namespace NewOS::PCI {
Iterator::Iterator(const Types::PciDeviceKind &type) {
// probe devices.
- for (int bus = 0; bus < ME_BUS_COUNT; ++bus) {
- for (int device = 0; device < ME_DEVICE_COUNT; ++device) {
- for (int function = 0; function < ME_FUNCTION_COUNT; ++function) {
+ for (int bus = 0; bus < NEWOS_BUS_COUNT; ++bus) {
+ for (int device = 0; device < NEWOS_DEVICE_COUNT; ++device) {
+ for (int function = 0; function < NEWOS_FUNCTION_COUNT; ++function) {
Device dev(bus, device, function, 0);
if (dev.Class() == (UChar)type) {
diff --git a/Private/HALKit/AMD64/Storage/AHCI.cxx b/Private/HALKit/AMD64/Storage/AHCI.cxx
index 25318212..35308582 100644
--- a/Private/HALKit/AMD64/Storage/AHCI.cxx
+++ b/Private/HALKit/AMD64/Storage/AHCI.cxx
@@ -15,4 +15,45 @@
*
*/
-#include <Builtins/AHCI/Defines.hxx> \ No newline at end of file
+#include <Builtins/AHCI/Defines.hxx>
+#include <KernelKit/PCI/Iterator.hpp>
+
+#ifdef __AHCI__
+enum { kSATAProgIfAHCI = 0x01, kSATASubClass = 0x06 };
+
+static NewOS::PCI::Device kAhciDevice;
+
+/// @brief Initializes an AHCI disk.
+/// @param PortsImplemented the amount of port that have been detected.
+/// @return
+NewOS::Boolean drv_std_init(NewOS::UInt16& PortsImplemented) {
+ using namespace NewOS;
+
+ PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController);
+ for (SizeT devIndex = 0; devIndex < NEWOS_BUS_COUNT; ++devIndex) {
+ if (iterator[devIndex].Leak().Subclass() == kSATASubClass &&
+ iterator[devIndex].Leak().ProgIf() == kSATAProgIfAHCI) {
+ iterator[devIndex].Leak().EnableMmio();
+ kAhciDevice = iterator[devIndex].Leak();
+
+ kcout << "NewKernel: Found AHCI controller.\r\n";
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+NewOS::Boolean drv_std_detected(NewOS::Void) {
+ return kAhciDevice.DeviceId() != 0xFFFF;
+}
+
+NewOS::Void drv_std_read(NewOS::UInt64 Lba, NewOS::UInt16 IO,
+ NewOS::UInt8 Master, NewOS::Char* Buf,
+ NewOS::SizeT SectorSz, NewOS::SizeT Size) {}
+
+NewOS::Void drv_std_write(NewOS::UInt64 Lba, NewOS::UInt16 IO,
+ NewOS::UInt8 Master, NewOS::Char* Buf,
+ NewOS::SizeT SectorSz, NewOS::SizeT Size) {}
+#endif // __AHCI__ \ No newline at end of file
diff --git a/Private/HALKit/AMD64/Storage/ATA-DMA.cxx b/Private/HALKit/AMD64/Storage/ATA-DMA.cxx
index 4189e467..d3e90f67 100644
--- a/Private/HALKit/AMD64/Storage/ATA-DMA.cxx
+++ b/Private/HALKit/AMD64/Storage/ATA-DMA.cxx
@@ -27,11 +27,11 @@ EXTERN_C Int32 kPRDTTransferStatus;
#ifdef __ATA_DMA__
#ifdef __ATA_PIO__
-# error You can't have both PIO and DMA enabled!
+# error You cant have both PIO and DMA enabled!
#endif /* ifdef __ATA_PIO__ */
#ifdef __AHCI__
-# error You can't have both ATA and AHCI enabled!
+# error You cant have both ATA and AHCI enabled!
#endif /* ifdef __AHCI__ */
#endif /* ifdef __ATA_DMA__ */
diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
index 2344cd86..0ff3591e 100644
--- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
+++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
@@ -31,7 +31,7 @@ static Boolean kATADetected = false;
static Int32 kATADeviceType = kATADeviceCount;
static Char kATAData[kATADataLen] = {0};
-Boolean drv_ata_wait_io(UInt16 IO) {
+Boolean drv_std_wait_io(UInt16 IO) {
for (int i = 0; i < 4; i++) In8(IO + ATA_REG_STATUS);
ATAWaitForIO_Retry:
@@ -49,20 +49,20 @@ ATAWaitForIO_Retry2:
return true;
}
-Void drv_ata_select(UInt16 Bus) {
+Void drv_std_select(UInt16 Bus) {
if (Bus == ATA_PRIMARY_IO)
Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL);
else
Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL);
}
-Boolean drv_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus,
+Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus,
UInt8& OutMaster) {
- if (drv_ata_detected()) return false;
+ if (drv_std_detected()) return false;
UInt16 IO = Bus;
- drv_ata_select(IO);
+ drv_std_select(IO);
// Bus init, NEIN bit.
Out8(IO + ATA_REG_NEIN, 1);
@@ -86,7 +86,7 @@ ATAInit_Retry:
/// fetch serial info
/// model, speed, number of sectors...
- drv_ata_wait_io(IO);
+ drv_std_wait_io(IO);
for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) {
kATAData[indexData] = In16(IO + ATA_REG_DATA);
@@ -130,7 +130,7 @@ ATAInit_Retry:
return true;
}
-Void drv_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
+Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
SizeT SectorSz, SizeT Size) {
UInt8 Command = (!Master ? 0xE0 : 0xF0);
@@ -144,7 +144,7 @@ Void drv_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
- drv_ata_wait_io(IO);
+ drv_std_wait_io(IO);
for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
WideChar chr = In16(IO + ATA_REG_DATA);
@@ -153,7 +153,7 @@ Void drv_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
}
}
-Void drv_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
+Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
SizeT SectorSz, SizeT Size) {
UInt8 Command = (!Master ? 0xE0 : 0xF0);
@@ -167,7 +167,7 @@ Void drv_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
- drv_ata_wait_io(IO);
+ drv_std_wait_io(IO);
for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
Out16(IO + ATA_REG_DATA, Buf[IndexOff]);
@@ -176,6 +176,6 @@ Void drv_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
}
/// @check is ATA detected?
-Boolean drv_ata_detected(Void) { return kATADetected; }
+Boolean drv_std_detected(Void) { return kATADetected; }
#endif /* ifdef __ATA_PIO__ */ \ No newline at end of file