diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-08 14:00:04 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-08 14:00:04 +0200 |
| commit | 6dfe91e2f6d91011c57e0dd0858a7907f35bb71b (patch) | |
| tree | 41fe2cfb13c3c1e451212321eabbd723671dc6a4 /dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | |
| parent | 2ac97283d813414973f83d177280aafa7fbaa66f (diff) | |
dev: Urgent patches regarding memory management.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 68a5b051..41aabca2 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -147,6 +147,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz return; } + if (size_buffer > mib_cast(4) || + sector_sz > kAHCISectorSize) + return; + if (!Write) { // Zero-memory the buffer field. @@ -167,9 +171,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz command_header->Cfl = sizeof(FisRegH2D) / sizeof(UInt32); command_header->Write = Write; - command_header->Prdtl = (UInt16)((size_buffer + kMaxPRDSize - 1) / kMaxPRDSize); + command_header->Prdtl = 1; - volatile HbaCmdTbl* command_table = (volatile HbaCmdTbl*)((VoidPtr)((UInt64)command_header->Ctba)); + auto ctba_phys = ((UInt64)command_header->Ctbau << 32) | command_header->Ctba; + auto command_table = reinterpret_cast<volatile HbaCmdTbl*>(ctba_phys); rt_set_memory((HbaCmdTbl*)command_table, 0, sizeof(HbaCmdTbl) + (command_header->Prdtl - 1) * sizeof(HbaPrdtEntry)); @@ -177,23 +182,11 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz UIntPtr buffer_phys = HAL::hal_get_phys_address(buffer); SizeT bytes_remaining = size_buffer; - SizeT prdt_count = command_header->Prdtl; - - for (UInt16 i = 0; i < prdt_count; ++i) - { - UInt32 chunk = bytes_remaining / prdt_count; - - if (chunk == 0) - break; - - command_table->Prdt[i].Dba = (UInt32)(buffer_phys & 0xFFFFFFFF); - command_table->Prdt[i].Dbau = (UInt32)(buffer_phys >> 32); - command_table->Prdt[i].Dbc = chunk - 1; - command_table->Prdt[i].Ie = 1; - buffer_phys += chunk; - bytes_remaining -= chunk; - } + command_table->Prdt[0].Dba = (UInt32)(buffer_phys & 0xFFFFFFFF); + command_table->Prdt[0].Dbau = (UInt32)(buffer_phys >> 32); + command_table->Prdt[0].Dbc = bytes_remaining - 1; + command_table->Prdt[0].Ie = 1; volatile FisRegH2D* h2d_fis = (volatile FisRegH2D*)(&command_table->Cfis[0]); @@ -214,29 +207,12 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz h2d_fis->CountLow = (size_buffer)&0xFF; h2d_fis->CountHigh = (size_buffer >> 8) & 0xFF; - while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)) - { - ; - } - kSATAHba->Ports[kSATAIndex].Ci = (1 << slot); - while (YES) + for (Int32 i = 0; i < 1000000; ++i) { if (!(kSATAHba->Ports[kSATAIndex].Ci & (1 << slot))) break; - - if (kSATAHba->Is & kHBAErrTaskFile) - { - err_global_get() = kErrorDiskIsCorrupted; - return; - } - } - - /// we should wait again, just in case. - while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)) - { - ; } if (kSATAHba->Is & kHBAErrTaskFile) @@ -454,7 +430,7 @@ namespace Kernel UInt16 sk_init_ahci_device(BOOL atapi) { UInt16 pi = 0; - + if (drv_std_init_ahci(pi, atapi)) kSATAPortsImplemented = pi; |
