From e76166d6d0bb18316911cc98defb7cfd5a9ed99b Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Tue, 28 Jun 2022 19:59:45 -0700 Subject: [PATCH] Skeleton the sdmmc api --- src/LibHac/Fs/Sdmmc.cs | 1 + src/LibHac/FsSrv/Impl/DeviceOperator.cs | 1 + src/LibHac/FsSrv/Storage/MmcService.cs | 1 + src/LibHac/Sdmmc/Common.cs | 152 ++++++++++++++++++++++++ src/LibHac/Sdmmc/GcAsic.cs | 53 +++++++++ src/LibHac/Sdmmc/Mmc.cs | 57 +++++++++ src/LibHac/Sdmmc/SdCard.cs | 87 ++++++++++++++ src/LibHac/Sdmmc/SdmmcEnums.cs | 34 ------ 8 files changed, 352 insertions(+), 34 deletions(-) create mode 100644 src/LibHac/Fs/Sdmmc.cs create mode 100644 src/LibHac/Sdmmc/Common.cs create mode 100644 src/LibHac/Sdmmc/GcAsic.cs create mode 100644 src/LibHac/Sdmmc/Mmc.cs create mode 100644 src/LibHac/Sdmmc/SdCard.cs delete mode 100644 src/LibHac/Sdmmc/SdmmcEnums.cs diff --git a/src/LibHac/Fs/Sdmmc.cs b/src/LibHac/Fs/Sdmmc.cs new file mode 100644 index 00000000..77721970 --- /dev/null +++ b/src/LibHac/Fs/Sdmmc.cs @@ -0,0 +1 @@ +global using SdmmcHandle = System.UInt32; \ No newline at end of file diff --git a/src/LibHac/FsSrv/Impl/DeviceOperator.cs b/src/LibHac/FsSrv/Impl/DeviceOperator.cs index d74a22c5..e07506ed 100644 --- a/src/LibHac/FsSrv/Impl/DeviceOperator.cs +++ b/src/LibHac/FsSrv/Impl/DeviceOperator.cs @@ -10,6 +10,7 @@ using LibHac.Gc; using LibHac.Sdmmc; using LibHac.Sf; using LibHac.Util; +using MmcPartition = LibHac.Fs.MmcPartition; namespace LibHac.FsSrv.Impl; diff --git a/src/LibHac/FsSrv/Storage/MmcService.cs b/src/LibHac/FsSrv/Storage/MmcService.cs index b67c4b22..71557ba5 100644 --- a/src/LibHac/FsSrv/Storage/MmcService.cs +++ b/src/LibHac/FsSrv/Storage/MmcService.cs @@ -8,6 +8,7 @@ using LibHac.Sdmmc; using LibHac.SdmmcSrv; using LibHac.Sf; using IStorageSf = LibHac.FsSrv.Sf.IStorage; +using MmcPartition = LibHac.Fs.MmcPartition; namespace LibHac.FsSrv.Storage; diff --git a/src/LibHac/Sdmmc/Common.cs b/src/LibHac/Sdmmc/Common.cs new file mode 100644 index 00000000..4ee2b2e1 --- /dev/null +++ b/src/LibHac/Sdmmc/Common.cs @@ -0,0 +1,152 @@ +using System; + +namespace LibHac.Sdmmc; + +public enum BusPower +{ + // ReSharper disable InconsistentNaming + PowerOff = 0, + Power1_8V = 1, + Power3_3V = 2, + // ReSharper restore InconsistentNaming +} +public enum BusWidth +{ + Width1Bit = 0, + Width4Bit = 1, + Width8Bit = 2, +} + +public enum SpeedMode +{ + MmcIdentification = 0, + MmcLegacySpeed = 1, + MmcHighSpeed = 2, + MmcHs200 = 3, + MmcHs400 = 4, + SdCardIdentification = 5, + SdCardDefaultSpeed = 6, + SdCardHighSpeed = 7, + SdCardSdr12 = 8, + SdCardSdr25 = 9, + SdCardSdr50 = 10, + SdCardSdr104 = 11, + SdCardDdr50 = 12, + GcAsicFpgaSpeed = 13, + GcAsicSpeed = 14 +} + +public enum Port +{ + Mmc0 = 0, + SdCard0 = 1, + GcAsic0 = 2 +} + +public struct ErrorInfo +{ + public uint NumActivationFailures; + public uint NumActivationErrorCorrections; + public uint NumReadWriteFailures; + public uint NumReadWriteErrorCorrections; +} + +public delegate void DeviceDetectionEventCallback(object args); + +public partial class SdmmcApi +{ + public const int SectorSize = 0x200; + + public const int DeviceCidSize = 0x10; + public const int DeviceCsdSize = 0x10; + + public void SwitchToPcvClockResetControl() + { + throw new NotImplementedException(); + } + + public void Initialize(Port port) + { + throw new NotImplementedException(); + } + + public void Finalize(Port port) + { + throw new NotImplementedException(); + } + + public void ChangeCheckTransferInterval(Port port, uint ms) + { + throw new NotImplementedException(); + } + + public void SetDefaultCheckTransferInterval(Port port) + { + throw new NotImplementedException(); + } + + public Result Activate(Port port) + { + throw new NotImplementedException(); + } + + public void Deactivate(Port port) + { + throw new NotImplementedException(); + } + + public Result Read(Span destination, Port port, uint sectorIndex, uint sectorCount) + { + throw new NotImplementedException(); + } + + public Result Write(Port port, uint sectorIndex, uint sectorCount, ReadOnlySpan source) + { + throw new NotImplementedException(); + } + + public Result CheckConnection(out SpeedMode outSpeedMode, out BusWidth outBusWidth, Port port) + { + throw new NotImplementedException(); + } + + public Result GetDeviceSpeedMode(out SpeedMode outSpeedMode, Port port) + { + throw new NotImplementedException(); + } + + public Result GetDeviceMemoryCapacity(out uint outNumSectors, Port port) + { + throw new NotImplementedException(); + } + + public Result GetDeviceStatus(out uint outDeviceStatus, Port port) + { + throw new NotImplementedException(); + } + + public Result GetDeviceCid(Span outBuffer, Port port) + { + throw new NotImplementedException(); + } + + public Result GetDeviceCsd(Span outBuffer, Port port) + { + throw new NotImplementedException(); + } + + public void GetAndClearErrorInfo(out ErrorInfo outErrorInfo, out int outLogSize, Span outLogBuffer, Port port) + { + throw new NotImplementedException(); + } + + public void RegisterDeviceVirtualAddress(Port port, Memory buffer, ulong bufferDeviceVirtualAddress) + { + throw new NotImplementedException(); + } + + public void UnregisterDeviceVirtualAddress(Port port, Memory buffer, ulong bufferDeviceVirtualAddress) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/LibHac/Sdmmc/GcAsic.cs b/src/LibHac/Sdmmc/GcAsic.cs new file mode 100644 index 00000000..eb467590 --- /dev/null +++ b/src/LibHac/Sdmmc/GcAsic.cs @@ -0,0 +1,53 @@ +using System; + +namespace LibHac.Sdmmc; + +public partial class SdmmcApi +{ + public const int GcAsicOperationSize = 0x40; + + public void PutGcAsicToSleep(Port port) + { + throw new NotImplementedException(); + } + + public Result AwakenGcAsic(Port port) + { + throw new NotImplementedException(); + } + + public Result WriteGcAsicOperation(Port port, ReadOnlySpan operationBuffer) + { + throw new NotImplementedException(); + } + + public Result FinishGcAsicOperation(Port port) + { + throw new NotImplementedException(); + } + + public Result AbortGcAsicOperation(Port port) + { + throw new NotImplementedException(); + } + + public Result SleepGcAsic(Port port) + { + throw new NotImplementedException(); + } + + public Result UpdateGcAsicKey(Port port) + { + throw new NotImplementedException(); + } + + public void SignalGcRemovedEvent(Port port) + { + throw new NotImplementedException(); + } + + public void ClearGcRemovedEvent(Port port) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/LibHac/Sdmmc/Mmc.cs b/src/LibHac/Sdmmc/Mmc.cs new file mode 100644 index 00000000..39e5d06a --- /dev/null +++ b/src/LibHac/Sdmmc/Mmc.cs @@ -0,0 +1,57 @@ +using System; + +namespace LibHac.Sdmmc; + +public enum MmcPartition +{ + UserData = 0, + BootPartition1 = 1, + BootPartition2 = 2, + Unknown = 3 +} + +public partial class SdmmcApi +{ + public const int MmcExtendedCsdSize = 0x200; + public const int MmcWorkBufferSize = MmcExtendedCsdSize; + + public void SetMmcWorkBuffer(Port port, Memory workBuffer) + { + throw new NotImplementedException(); + } + + public void PutMmcToSleep(Port port) + { + throw new NotImplementedException(); + } + + public void AwakenMmc(Port port) + { + throw new NotImplementedException(); + } + + public Result SelectMmcPartition(Port port, MmcPartition mmcPartition) + { + throw new NotImplementedException(); + } + + public Result EraseMmc(Port port) + { + throw new NotImplementedException(); + } + + public Result GetMmcBootPartitionCapacity(out uint outNumSectors, Port port) + { + throw new NotImplementedException(); + } + + public Result GetMmcExtendedCsd(Span outBuffer, Port port) + { + throw new NotImplementedException(); + } + + public Result CheckMmcConnection(out SpeedMode outSpeedMode, out BusWidth outBusWidth, Port port) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/LibHac/Sdmmc/SdCard.cs b/src/LibHac/Sdmmc/SdCard.cs new file mode 100644 index 00000000..b2dfabcb --- /dev/null +++ b/src/LibHac/Sdmmc/SdCard.cs @@ -0,0 +1,87 @@ +using System; + +namespace LibHac.Sdmmc; + +public enum SdCardSwitchFunction +{ + CheckSupportedFunction = 0, + CheckDefault = 1, + CheckHighSpeed = 2, + CheckSdr50 = 3, + CheckSdr104 = 4, + CheckDdr50 = 5 +}; + +public partial class SdmmcApi +{ + public const int SdCardScrSize = 8; + public const int SdCardSwitchFunctionStatusSize = 0x40; + public const int SdCardSdStatusSize = 0x40; + + public const int SdCardWorkBufferSize = SdCardSdStatusSize; + + public void SetSdCardWorkBuffer(Port port, Memory workBuffer) + { + throw new NotImplementedException(); + } + + public void PutSdCardToSleep(Port port) + { + throw new NotImplementedException(); + } + + public void AwakenSdCard(Port port) + { + throw new NotImplementedException(); + } + + public Result GetSdCardProtectedAreaCapacity(out uint outNumSectors, Port port) + { + throw new NotImplementedException(); + } + + public Result GetSdCardScr(Span outBuffer, Port port) + { + throw new NotImplementedException(); + } + + public Result GetSdCardSwitchFunctionStatus(Span outBuffer, Port port, SdCardSwitchFunction switchFunction) + { + throw new NotImplementedException(); + } + + public Result GetSdCardCurrentConsumption(out ushort outCurrentConsumption, Port port, SpeedMode speedMode) + { + throw new NotImplementedException(); + } + + public Result GetSdCardSdStatus(Span outBuffer, Port port) + { + throw new NotImplementedException(); + } + + public Result CheckSdCardConnection(out SpeedMode outSpeedMode, out BusWidth outBusWidth, Port port) + { + throw new NotImplementedException(); + } + + public void RegisterSdCardDetectionEventCallback(Port port, DeviceDetectionEventCallback callback, object args) + { + throw new NotImplementedException(); + } + + public void UnregisterSdCardDetectionEventCallback(Port port) + { + throw new NotImplementedException(); + } + + public bool IsSdCardInserted(Port port) + { + throw new NotImplementedException(); + } + + public bool IsSdCardRemoved(Port port) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/LibHac/Sdmmc/SdmmcEnums.cs b/src/LibHac/Sdmmc/SdmmcEnums.cs deleted file mode 100644 index 113246d9..00000000 --- a/src/LibHac/Sdmmc/SdmmcEnums.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace LibHac.Sdmmc; - -public enum BusWidth -{ - Width1Bit = 0, - Width4Bit = 1, - Width8Bit = 2, -} - -public enum SpeedMode -{ - MmcIdentification = 0, - MmcLegacySpeed = 1, - MmcHighSpeed = 2, - MmcHs200 = 3, - MmcHs400 = 4, - SdCardIdentification = 5, - SdCardDefaultSpeed = 6, - SdCardHighSpeed = 7, - SdCardSdr12 = 8, - SdCardSdr25 = 9, - SdCardSdr50 = 10, - SdCardSdr104 = 11, - SdCardDdr50 = 12, - GcAsicFpgaSpeed = 13, - GcAsicSpeed = 14 -} - -public enum Port -{ - Mmc0 = 0, - SdCard0 = 1, - GcAsic0 = 2 -} \ No newline at end of file