summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-23 18:20:04 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-23 18:20:04 +0200
commitbac8c9a8306e1582ef24ba68a412a29674c97775 (patch)
tree956155581fdb44fb6c82673a5f71a00cc6f4c89c /dev/ZKA/HALKit
parent73e0c81b5c8325db7aaec773fcc657f3ef50b0b8 (diff)
[IMP/WIP] AHCI disk driver for kernel DLL.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/HALKit')
-rw-r--r--dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx2
-rw-r--r--dev/ZKA/HALKit/AMD64/PCI/Device.cxx47
-rw-r--r--dev/ZKA/HALKit/AMD64/PCI/Iterator.cxx8
-rw-r--r--dev/ZKA/HALKit/AMD64/Processor.hxx2
-rw-r--r--dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx44
-rw-r--r--dev/ZKA/HALKit/POWER/HalHart.cxx4
6 files changed, 80 insertions, 27 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx
index 27706784..87dd1d24 100644
--- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx
@@ -11,7 +11,7 @@
#ifdef __ZKA_AMD64__
#include <HALKit/AMD64/HalPageAlloc.hxx>
-#elif defined(__NEWOS_ARM64__)
+#elif defined(__ZKA_ARM64__)
#include <HALKit/ARM64/HalPageAlloc.hxx>
#endif
diff --git a/dev/ZKA/HALKit/AMD64/PCI/Device.cxx b/dev/ZKA/HALKit/AMD64/PCI/Device.cxx
index 214a640a..bc6ba2bb 100644
--- a/dev/ZKA/HALKit/AMD64/PCI/Device.cxx
+++ b/dev/ZKA/HALKit/AMD64/PCI/Device.cxx
@@ -7,7 +7,7 @@
#include <ArchKit/ArchKit.hxx>
#include <KernelKit/PCI/Device.hxx>
-Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
+Kernel::UInt ZKA_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
{
Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
@@ -19,7 +19,7 @@ Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShor
return Kernel::HAL::In32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData);
}
-void NewOSPCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
+void ZKA_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
{
Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
@@ -29,34 +29,40 @@ void NewOSPCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort d
target);
}
+#define PCI_BAR_IO 0x01
+#define PCI_BAR_LOWMEM 0x02
+#define PCI_BAR_64 0x04
+#define PCI_BAR_PREFETCH 0x08
+
namespace Kernel::PCI
{
- Device::Device(UShort bus, UShort device, UShort func, UShort bar)
+ Device::Device(UShort bus, UShort device, UShort func, UInt32 bar)
: fBus(bus), fDevice(device), fFunction(func), fBar(bar)
{
+ // get bar 0
+ auto bar_zero = 0x10 + bar * sizeof(UInt32);
+ fBar = this->Read(bar_zero, 4);
}
- Device::~Device()
- {
- }
+ Device::~Device() = default;
UInt Device::Read(UInt bar, Size sz)
{
- NewOSPCISetCfgTarget(bar, fBus, fDevice, fFunction);
+ ZKA_PCISetCfgTarget(bar, fBus, fDevice, fFunction);
if (sz == 4)
- return HAL::In32((UShort)PciConfigKind::ConfigData + (fBar & 3));
+ return HAL::In32((UShort)PciConfigKind::ConfigData + (bar & 3));
if (sz == 2)
- return HAL::In16((UShort)PciConfigKind::ConfigData + (fBar & 3));
+ return HAL::In16((UShort)PciConfigKind::ConfigData + (bar & 3));
if (sz == 1)
- return HAL::In8((UShort)PciConfigKind::ConfigData + (fBar & 3));
+ return HAL::In8((UShort)PciConfigKind::ConfigData + (bar & 3));
return 0xFFFF;
}
void Device::Write(UInt bar, UIntPtr data, Size sz)
{
- NewOSPCISetCfgTarget(bar, fBus, fDevice, fFunction);
+ ZKA_PCISetCfgTarget(bar, fBus, fDevice, fFunction);
if (sz == 4)
HAL::Out32((UShort)PciConfigKind::ConfigData + (fBar & 3), (UInt)data);
@@ -68,37 +74,37 @@ namespace Kernel::PCI
UShort Device::DeviceId()
{
- return (UShort)(NewOSPCIReadRaw(0x0 >> 16, fBus, fDevice, fFunction));
+ return (UShort)(ZKA_PCIReadRaw(0x0 >> 16, fBus, fDevice, fFunction));
}
UShort Device::VendorId()
{
- return (UShort)(NewOSPCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
+ return (UShort)(ZKA_PCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
}
UShort Device::InterfaceId()
{
- return (UShort)(NewOSPCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
+ return (UShort)(ZKA_PCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
}
UChar Device::Class()
{
- return (UChar)(NewOSPCIReadRaw(0x08, fBus, fDevice, fFunction) >> 24);
+ return (UChar)(ZKA_PCIReadRaw(0x08, fBus, fDevice, fFunction) >> 24);
}
UChar Device::Subclass()
{
- return (UChar)(NewOSPCIReadRaw(0x08, fBus, fDevice, fFunction) >> 16);
+ return (UChar)(ZKA_PCIReadRaw(0x08, fBus, fDevice, fFunction) >> 16);
}
UChar Device::ProgIf()
{
- return (UChar)(NewOSPCIReadRaw(0x08, fBus, fDevice, fFunction) >> 8);
+ return (UChar)(ZKA_PCIReadRaw(0x08, fBus, fDevice, fFunction) >> 8);
}
UChar Device::HeaderType()
{
- return (UChar)(NewOSPCIReadRaw(0xC, fBus, fDevice, fFunction) >> 16);
+ return (UChar)(ZKA_PCIReadRaw(0xC, fBus, fDevice, fFunction) >> 16);
}
void Device::EnableMmio()
@@ -113,6 +119,11 @@ namespace Kernel::PCI
Write(0x04, enable, sizeof(UShort));
}
+ UInt32 Device::Bar()
+ {
+ return fBar;
+ }
+
UShort Device::Vendor()
{
UShort vendor = VendorId();
diff --git a/dev/ZKA/HALKit/AMD64/PCI/Iterator.cxx b/dev/ZKA/HALKit/AMD64/PCI/Iterator.cxx
index 47b16462..20a94115 100644
--- a/dev/ZKA/HALKit/AMD64/PCI/Iterator.cxx
+++ b/dev/ZKA/HALKit/AMD64/PCI/Iterator.cxx
@@ -15,13 +15,13 @@ namespace Kernel::PCI
Iterator::Iterator(const Types::PciDeviceKind& type)
{
// probe devices.
- for (int bus = 0; bus < NEWOS_BUS_COUNT; ++bus)
+ for (int bus = 0; bus < ZKA_BUS_COUNT; ++bus)
{
- for (int device = 0; device < NEWOS_DEVICE_COUNT; ++device)
+ for (int device = 0; device < ZKA_DEVICE_COUNT; ++device)
{
- for (int function = 0; function < NEWOS_FUNCTION_COUNT; ++function)
+ for (int function = 0; function < ZKA_FUNCTION_COUNT; ++function)
{
- Device dev(bus, device, function, 0);
+ Device dev(bus, device, function, type == Types::PciDeviceKind::MassStorageController ? 5 : 1);
if (dev.Class() == (UChar)type)
{
diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx
index b6ae0ab3..d1bda9ef 100644
--- a/dev/ZKA/HALKit/AMD64/Processor.hxx
+++ b/dev/ZKA/HALKit/AMD64/Processor.hxx
@@ -317,7 +317,7 @@ namespace Kernel::HAL
~APICController() = default;
- NEWOS_COPY_DEFAULT(APICController);
+ ZKA_COPY_DEFAULT(APICController);
public:
UInt32 Read(UInt32 reg) noexcept;
diff --git a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx
index 0974c240..e8742cdc 100644
--- a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx
+++ b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx
@@ -26,6 +26,7 @@ enum
};
static Kernel::PCI::Device kAhciDevice;
+static HbaPort* kAhciPort = nullptr;
/// @brief Initializes an AHCI disk.
/// @param PortsImplemented the amount of port that have been detected.
@@ -35,7 +36,8 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented)
using namespace Kernel;
PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController);
- for (SizeT devIndex = 0; devIndex < NEWOS_BUS_COUNT; ++devIndex)
+
+ for (SizeT devIndex = 0; devIndex < ZKA_BUS_COUNT; ++devIndex)
{
if (iterator[devIndex].Leak().Subclass() == kSATASubClass &&
iterator[devIndex].Leak().ProgIf() == kSATAProgIfAHCI)
@@ -43,6 +45,33 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented)
iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device.
kAhciDevice = iterator[devIndex].Leak(); /// and then leak the reference.
+ HbaMem* mem_ahci = (HbaMem*)kAhciDevice.Bar();
+
+ UInt32 pi = mem_ahci->Pi;
+ Int32 i = 0;
+
+ const auto cMaxAhciDevices = 32;
+ const auto cAhciSig = 0x00000101;
+ const auto cAhciPresent = 0x03;
+
+ while (i < cMaxAhciDevices)
+ {
+ if (pi & 1 &&
+ (mem_ahci->Ports[i].Ssts & 0x0F) == cAhciPresent &&
+ ((mem_ahci->Ports[i].Ssts >> 8) & 0x0F) == 1)
+ {
+ kcout << "newoskrnl: Port is implemented.\r";
+
+ if (mem_ahci->Ports[i].Sig == cAhciSig)
+ {
+ kcout << "newoskrnl: device is SATA.\r";
+ }
+ }
+
+ pi >>= 1;
+ i++;
+ }
+
kcout << "newoskrnl: [PCI] Found AHCI controller.\r";
return true;
@@ -64,4 +93,17 @@ Kernel::Void drv_std_read(Kernel::UInt64 Lba, Kernel::Char* Buf, Kernel::SizeT S
Kernel::Void drv_std_write(Kernel::UInt64 Lba, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size)
{
}
+/***
+ @brief Getter, gets the number of sectors inside the drive.
+*/
+Kernel::SizeT drv_std_get_sector_count()
+{
+ return 0;
+}
+
+/// @brief Get the drive size.
+Kernel::SizeT drv_std_get_drv_size()
+{
+ return 0;
+}
#endif // __AHCI__
diff --git a/dev/ZKA/HALKit/POWER/HalHart.cxx b/dev/ZKA/HALKit/POWER/HalHart.cxx
index 8327b8e0..ce27ddad 100644
--- a/dev/ZKA/HALKit/POWER/HalHart.cxx
+++ b/dev/ZKA/HALKit/POWER/HalHart.cxx
@@ -14,12 +14,12 @@ using namespace Kernel;
/// wakes up thread from hang.
void mp_wakeup_thread(HAL::StackFramePtr stack)
{
- NEWOS_UNUSED(stack);
+ ZKA_UNUSED(stack);
}
/// @brief makes thread sleep.
/// hooks and hangs thread to prevent code from executing.
void mp_hang_thread(HAL::StackFramePtr stack)
{
- NEWOS_UNUSED(stack);
+ ZKA_UNUSED(stack);
}