feat: Ahci, ACPI shutdown
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <Drivers/Net/E1000.hpp>
|
||||
#include <Drivers/Net/E1000E.hpp>
|
||||
#include <Drivers/Graphics/IntelGPU.hpp>
|
||||
#include <Drivers/Storage/Ahci.hpp>
|
||||
#include <Pci/Pci.hpp>
|
||||
|
||||
#include "Syscall.hpp"
|
||||
@@ -128,7 +129,30 @@ namespace Montauk {
|
||||
}
|
||||
}
|
||||
|
||||
// PCI devices (category 7)
|
||||
// Storage (category 7)
|
||||
if (Drivers::Storage::Ahci::IsInitialized()) {
|
||||
for (int port = 0; port < 32 && count < maxCount; port++) {
|
||||
auto* info = Drivers::Storage::Ahci::GetPortInfo(port);
|
||||
if (!info) continue;
|
||||
uint64_t sectors = info->SectorCount;
|
||||
uint64_t sizeMB = (sectors * 512) / (1024 * 1024);
|
||||
uint64_t sizeGB = sizeMB / 1024;
|
||||
char detail[48];
|
||||
int p = 0;
|
||||
if (sizeGB > 0) {
|
||||
p = dl_append_dec(detail, p, (int)sizeGB, 48);
|
||||
p = dl_append(detail, p, " GiB, SATA port ", 48);
|
||||
} else {
|
||||
p = dl_append_dec(detail, p, (int)sizeMB, 48);
|
||||
p = dl_append(detail, p, " MiB, SATA port ", 48);
|
||||
}
|
||||
p = dl_append_dec(detail, p, port, 48);
|
||||
add(7, info->Model, detail);
|
||||
buf[count - 1]._pad[0] = (uint8_t)port; // stash port index
|
||||
}
|
||||
}
|
||||
|
||||
// PCI devices (category 8)
|
||||
auto& pciDevs = Pci::GetDevices();
|
||||
for (int i = 0; i < (int)pciDevs.size() && count < maxCount; i++) {
|
||||
auto& d = pciDevs[i];
|
||||
@@ -144,9 +168,37 @@ namespace Montauk {
|
||||
p = dl_append_hex(detail, p, d.VendorId, 4, 48);
|
||||
p = dl_append(detail, p, ":", 48);
|
||||
p = dl_append_hex(detail, p, d.DeviceId, 4, 48);
|
||||
add(7, className, detail);
|
||||
add(8, className, detail);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int Sys_DiskInfo(DiskInfo* buf, int port) {
|
||||
if (buf == nullptr) return -1;
|
||||
if (!Drivers::Storage::Ahci::IsInitialized()) return -1;
|
||||
|
||||
auto* info = Drivers::Storage::Ahci::GetPortInfo(port);
|
||||
if (!info) return -1;
|
||||
|
||||
buf->port = info->PortIndex;
|
||||
buf->type = (uint8_t)info->Type;
|
||||
buf->sataGen = (uint8_t)info->SataGen;
|
||||
buf->sectorCount = info->SectorCount;
|
||||
buf->sectorSizeLog = info->SectorSizeLog;
|
||||
buf->sectorSizePhys = info->SectorSizePhys;
|
||||
buf->rpm = info->Rpm;
|
||||
buf->ncqDepth = info->NcqDepth;
|
||||
buf->supportsLba48 = info->SupportsLba48 ? 1 : 0;
|
||||
buf->supportsNcq = info->SupportsNcq ? 1 : 0;
|
||||
buf->supportsTrim = info->SupportsTrim ? 1 : 0;
|
||||
buf->supportsSmart = info->SupportsSmart ? 1 : 0;
|
||||
buf->supportsWriteCache = info->SupportsWriteCache ? 1 : 0;
|
||||
buf->supportsReadAhead = info->SupportsReadAhead ? 1 : 0;
|
||||
dl_strcpy(buf->model, info->Model, 41);
|
||||
dl_strcpy(buf->serial, info->Serial, 21);
|
||||
dl_strcpy(buf->firmware, info->Firmware, 9);
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <cstdint>
|
||||
#include <Efi/UEFI.hpp>
|
||||
#include <Memory/Paging.hpp>
|
||||
#include <ACPI/AcpiShutdown.hpp>
|
||||
|
||||
namespace Montauk {
|
||||
|
||||
@@ -25,13 +26,18 @@ namespace Montauk {
|
||||
}
|
||||
|
||||
static void Sys_Shutdown() {
|
||||
/* Primary: ACPI S5 shutdown via PM1 control registers */
|
||||
if (Hal::AcpiShutdown::IsAvailable()) {
|
||||
Hal::AcpiShutdown::Shutdown();
|
||||
}
|
||||
|
||||
/* Fallback: EFI ResetSystem */
|
||||
if (Efi::g_ResetSystem) {
|
||||
/* Switch to kernel PML4 which has identity-mapped UEFI runtime regions */
|
||||
Memory::VMM::LoadCR3(Memory::VMM::g_paging->PML4);
|
||||
Efi::g_ResetSystem(Efi::EfiResetShutdown, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
/* No fallback for shutdown; halt the CPU */
|
||||
/* Last resort: halt the CPU */
|
||||
asm volatile("cli; hlt");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@@ -209,6 +209,8 @@ namespace Montauk {
|
||||
}
|
||||
case SYS_DEVLIST:
|
||||
return (int64_t)Sys_DevList((DevInfo*)frame->arg1, (int)frame->arg2);
|
||||
case SYS_DISKINFO:
|
||||
return (int64_t)Sys_DiskInfo((DiskInfo*)frame->arg1, (int)frame->arg2);
|
||||
case SYS_WINSETSCALE:
|
||||
return (int64_t)Sys_WinSetScale((int)frame->arg1);
|
||||
case SYS_WINGETSCALE:
|
||||
|
||||
@@ -132,6 +132,7 @@ namespace Montauk {
|
||||
|
||||
/* Device.hpp */
|
||||
static constexpr uint64_t SYS_DEVLIST = 63;
|
||||
static constexpr uint64_t SYS_DISKINFO = 69;
|
||||
|
||||
/* MemInfo.hpp */
|
||||
static constexpr uint64_t SYS_MEMSTATS = 67;
|
||||
@@ -224,12 +225,35 @@ namespace Montauk {
|
||||
};
|
||||
|
||||
struct DevInfo {
|
||||
uint8_t category; // 0=CPU, 1=Interrupt, 2=Timer, 3=Input, 4=USB, 5=Network, 6=Display, 7=PCI
|
||||
uint8_t category; // 0=CPU, 1=Interrupt, 2=Timer, 3=Input, 4=USB, 5=Network, 6=Display, 7=Storage, 8=PCI
|
||||
uint8_t _pad[3];
|
||||
char name[48];
|
||||
char detail[48];
|
||||
};
|
||||
|
||||
struct DiskInfo {
|
||||
uint8_t port; // AHCI port index
|
||||
uint8_t type; // 0=none, 1=SATA, 2=SATAPI
|
||||
uint8_t sataGen; // SATA gen (1/2/3)
|
||||
uint8_t _pad0;
|
||||
uint64_t sectorCount; // Total user-addressable sectors
|
||||
uint16_t sectorSizeLog; // Logical sector size (bytes)
|
||||
uint16_t sectorSizePhys; // Physical sector size (bytes)
|
||||
uint16_t rpm; // 0=unknown, 1=SSD, else RPM
|
||||
uint16_t ncqDepth; // 0 if no NCQ
|
||||
uint8_t supportsLba48;
|
||||
uint8_t supportsNcq;
|
||||
uint8_t supportsTrim;
|
||||
uint8_t supportsSmart;
|
||||
uint8_t supportsWriteCache;
|
||||
uint8_t supportsReadAhead;
|
||||
uint8_t _pad1[2];
|
||||
char model[41];
|
||||
char serial[21];
|
||||
char firmware[9];
|
||||
char _pad2[1];
|
||||
};
|
||||
|
||||
struct ProcInfo {
|
||||
int32_t pid;
|
||||
int32_t parentPid;
|
||||
|
||||
Reference in New Issue
Block a user