diff options
Diffstat (limited to 'dev/kernel/HALKit/AMD64/Storage')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 45 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc | 13 |
2 files changed, 37 insertions, 21 deletions
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index fd138513..1591fa56 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -55,11 +55,11 @@ using namespace Kernel; STATIC PCI::Device kSATADev; STATIC HbaMemRef kSATAHba; -STATIC Lba kSATASectorCount = 0UL; -STATIC UInt16 kSATAIndex = 0U; -STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"}; -STATIC UInt16 kSATAPortsImplemented = 0U; -STATIC ALIGN(4096) UInt8 kIdentifyData[kAHCISectorSize] = {0}; +STATIC Lba kSATASectorCount = 0UL; +STATIC UInt16 kSATAIndex = 0U; +STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"}; +STATIC UInt16 kSATAPortsImplemented = 0U; +STATIC ALIGN(kib_cast(4)) UInt8 kIdentifyData[kAHCISectorSize] = {0}; template <BOOL Write, BOOL CommandOrCTRL, BOOL Identify> STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz, @@ -153,6 +153,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz VoidPtr ptr = Kernel::rtl_dma_alloc(size_buffer, 4096); + if (Write) { + Kernel::rt_copy_memory(buffer, ptr, size_buffer); + } + // Build the PRDT SizeT bytes_remaining = size_buffer; SizeT prdt_index = 0; @@ -160,8 +164,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz while (bytes_remaining > 0 && prdt_index < 8) { SizeT chunk_size = bytes_remaining; - if (chunk_size > 8 * 1024) // AHCI recommends ~8 KiB per PRDT - chunk_size = 8 * 1024; + + if (chunk_size > kib_cast(32)) chunk_size = kib_cast(32); command_table->Prdt[prdt_index].Dba = (UInt32) (buffer_phys & 0xFFFFFFFF); command_table->Prdt[prdt_index].Dbau = (UInt32) (buffer_phys >> 32); @@ -170,12 +174,16 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz buffer_phys += chunk_size; bytes_remaining -= chunk_size; + ++prdt_index; } + command_table->Prdt[prdt_index - 1].Ie = YES; + if (bytes_remaining > 0) { kout << "Warning: AHCI PRDT overflow, cannot map full buffer.\r"; err_global_get() = kErrorDisk; + return; } @@ -197,9 +205,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz h2d_fis->Lba4 = (lba >> 32) & 0xFF; h2d_fis->Lba5 = (lba >> 40) & 0xFF; + h2d_fis->Device = 0; + if (Identify) { - h2d_fis->Device = 0; // DO NOT set LBAMODE flag - h2d_fis->CountLow = 1; // IDENTIFY always transfers 1 sector + h2d_fis->CountLow = 1; h2d_fis->CountHigh = 0; } else { h2d_fis->Device = kSATALBAMode; @@ -220,12 +229,15 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz if (kSATAHba->Is & kHBAErrTaskFile) { kout << "AHCI Task File Error during I/O.\r"; - + rtl_dma_free(size_buffer); err_global_get() = kErrorDiskIsCorrupted; return; } else { + rtl_dma_flush(ptr, size_buffer); rt_copy_memory(ptr, buffer, size_buffer); + rtl_dma_flush(ptr, size_buffer); + rtl_dma_free(size_buffer); err_global_get() = kErrorSuccess; @@ -289,11 +301,11 @@ STATIC Bool drv_init_command_structures_ahci() { UIntPtr clb_phys = HAL::hal_get_phys_address(clb_mem); - kSATAHba->Ports[kSATAIndex].Clb = (UInt32)(clb_phys & 0xFFFFFFFF); - kSATAHba->Ports[kSATAIndex].Clbu = (UInt32)(clb_phys >> 32); + kSATAHba->Ports[kSATAIndex].Clb = (UInt32) (clb_phys & 0xFFFFFFFF); + kSATAHba->Ports[kSATAIndex].Clbu = (UInt32) (clb_phys >> 32); // Clear it - rt_set_memory(clb_mem, 0, 4096); + rt_set_memory(clb_mem, 0, kib_cast(4)); // For each command slot (up to 32) volatile HbaCmdHeader* header = (volatile HbaCmdHeader*) clb_mem; @@ -302,15 +314,15 @@ STATIC Bool drv_init_command_structures_ahci() { // Allocate 4KiB for Command Table VoidPtr ct_mem = Kernel::rtl_dma_alloc(4096, 128); if (!ct_mem) { - kout << "Failed to allocate CTB memory for slot " << hex_number(i); + (Void)(kout << "Failed to allocate CTB memory for slot " << hex_number(i)); kout << "!\r"; return NO; } UIntPtr ct_phys = HAL::hal_get_phys_address(ct_mem); - header[i].Ctba = (UInt32)(ct_phys & 0xFFFFFFFF); - header[i].Ctbau = (UInt32)(ct_phys >> 32); + header[i].Ctba = (UInt32) (ct_phys & 0xFFFFFFFF); + header[i].Ctbau = (UInt32) (ct_phys >> 32); // Clear the command table rt_set_memory((VoidPtr) ct_mem, 0, 4096); @@ -319,7 +331,6 @@ STATIC Bool drv_init_command_structures_ahci() { return YES; } - /// @brief Initializes an AHCI disk. /// @param pi the amount of ports that have been detected. /// @param atapi reference value, tells whether we should detect ATAPI instead of SATA. diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc index a7361778..ca3e9ee4 100644 --- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc @@ -28,11 +28,11 @@ using namespace Kernel::HAL; /// BUGS: 0 -STATIC Boolean kATADetected = false; -STATIC Int32 kATADeviceType = kATADeviceCount; -STATIC UInt16 kATAIdentifyData[kATADataLen] = {0}; +STATIC Boolean kATADetected = false; +STATIC Int32 kATADeviceType ATTRIBUTE(unused) = kATADeviceCount; +STATIC UInt16 kATAIdentifyData[kATADataLen] = {0}; STATIC Kernel::PCI::Device kATADevice; -STATIC Char kATADiskModel[50] = {"GENERIC DMA"}; +STATIC Char kATADiskModel[50] ATTRIBUTE(unused) = {"GENERIC DMA"}; Boolean drv_std_wait_io(UInt16 IO) { for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS); @@ -60,6 +60,11 @@ Void drv_std_select(UInt16 Bus) { } Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { + NE_UNUSED(Bus); + NE_UNUSED(Drive); + NE_UNUSED(OutBus); + NE_UNUSED(OutMaster); + PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController); for (SizeT device_index = 0; device_index < NE_BUS_COUNT; ++device_index) { |
