pf2: implement open/close disk

This commit is contained in:
Michael Scire
2020-11-25 23:51:49 -08:00
parent 4466a74e40
commit 75f006b002
7 changed files with 220 additions and 14 deletions

View File

@@ -22,4 +22,7 @@ namespace ams::prfile2::pdm {
pdm::Error Initialize(u32 config, void *param);
pdm::Error OpenDisk(InitDisk *init_disk_table, HandleType *out);
pdm::Error CloseDisk(HandleType handle);
}

View File

@@ -15,6 +15,7 @@
*/
#pragma once
#include <vapours/prfile2/prfile2_build_config.hpp>
#include <vapours/prfile2/prfile2_handle.hpp>
#include <vapours/prfile2/pdm/prfile2_pdm_types.hpp>
namespace ams::prfile2::pdm {
@@ -41,14 +42,14 @@ namespace ams::prfile2::pdm {
};
struct FunctionTable {
pdm::Error (*initialize)(Disk *);
pdm::Error (*finalize)(Disk *);
pdm::Error (*mount)(Disk *);
pdm::Error (*unmount)(Disk *);
pdm::Error (*format)(Disk *, const u8 *);
pdm::Error (*physical_read)(Disk *disk, u8 *dst, u32 block, u32 count, u32 *num_read);
pdm::Error (*physical_write)(Disk *disk, const u8 *src, u32 block, u32 count, u32 *num_read);
pdm::Error (*get_disk_info)(Disk *disk, DiskInfo *out);
pdm::Error (*initialize)(HandleType disk_handle);
pdm::Error (*finalize)(HandleType disk_handle);
pdm::Error (*mount)(HandleType disk_handle);
pdm::Error (*unmount)(HandleType disk_handle);
pdm::Error (*format)(HandleType disk_handle, const u8 *);
pdm::Error (*physical_read)(HandleType disk_handle, u8 *dst, u32 block, u32 count, u32 *num_read);
pdm::Error (*physical_write)(HandleType disk_handle, const u8 *src, u32 block, u32 count, u32 *num_read);
pdm::Error (*get_disk_info)(HandleType disk_handle, DiskInfo *out);
};
struct DiskTable {

View File

@@ -34,12 +34,34 @@ namespace ams::prfile2::pdm {
volatile NonBlockingProtocolType nbc;
volatile NonBlockingProtocolType nbc_detect;
volatile NonBlockingProtocolType nbc_req;
template<size_t Ix>
constexpr ALWAYS_INLINE bool GetStatusBit() const {
constexpr u32 Mask = (1u << Ix);
return (this->status & Mask) != 0;
}
template<size_t Ix>
constexpr ALWAYS_INLINE void SetStatusBit(bool en) {
constexpr u32 Mask = (1u << Ix);
if (en) {
this->status |= Mask;
} else {
this->status &= ~Mask;
}
}
constexpr bool IsOpen() const { return this->GetStatusBit<0>(); }
constexpr void SetOpen(bool en) { this->SetStatusBit<0>(en); }
constexpr bool IsLocked() const { return this->GetStatusBit<1>(); }
constexpr void SetLocked(bool en) { this->SetStatusBit<1>(en); }
};
namespace disk {
pdm::Error OpenDisk(InitDisk *init_disk_table, Disk **out);
pdm::Error CloseDisk(Disk *disk);
pdm::Error OpenDisk(InitDisk *init_disk_table, HandleType *out);
pdm::Error CloseDisk(HandleType handle);
/* ... */

View File

@@ -40,6 +40,21 @@ namespace ams::prfile2 {
return val;
};
constexpr ALWAYS_INLINE u8 GetHandleId(HandleType handle) {
return handle.Get<HandleField::Id>();
}
constexpr ALWAYS_INLINE u16 GetHandleSignature(HandleType handle) {
return handle.Get<HandleField::Signature>();
}
constexpr inline const HandleType InvalidHandle = {};
constexpr ALWAYS_INLINE bool IsInvalidHandle(HandleType handle) {
return handle.value == 0;
}
static_assert(IsInvalidHandle(InvalidHandle));
constexpr ALWAYS_INLINE HandleType ConstructDiskHandle(u8 id, u16 signature) { return ConstructHandle(id, HandleKind_Disk, signature); }
constexpr ALWAYS_INLINE HandleType ConstructPartitionHandle(u8 id, u16 signature) { return ConstructHandle(id, HandleKind_Partition, signature); }