mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-15 01:26:34 +00:00
kern: add toggleable support for 40-bit physaddr caps
This commit is contained in:
parent
ff1760fac1
commit
d562bb841d
3 changed files with 28 additions and 5 deletions
|
@ -39,3 +39,12 @@
|
||||||
/* However, as of (10/16/2021) KAutoObject has an unused class member */
|
/* However, as of (10/16/2021) KAutoObject has an unused class member */
|
||||||
/* of the right side, and so this does not actually cost any space. */
|
/* of the right side, and so this does not actually cost any space. */
|
||||||
#define MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST
|
#define MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST
|
||||||
|
|
||||||
|
/* NOTE: This uses currently-reserved bits inside the MapRange capability */
|
||||||
|
/* in order to support large physical addresses (40-bit instead of 36). */
|
||||||
|
/* This is toggleable in order to disable it if N ever uses those bits. */
|
||||||
|
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
|
||||||
|
//#define MESOSPHERE_ENABLE_LARGE_PHYSICAL_ADDRESS_CAPABILITIES
|
||||||
|
#else
|
||||||
|
#define MESOSPHERE_ENABLE_LARGE_PHYSICAL_ADDRESS_CAPABILITIES
|
||||||
|
#endif
|
|
@ -82,7 +82,11 @@ namespace ams::kern {
|
||||||
DEFINE_FIELD(Index, Mask, 3);
|
DEFINE_FIELD(Index, Mask, 3);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(MESOSPHERE_ENABLE_LARGE_PHYSICAL_ADDRESS_CAPABILITIES)
|
||||||
|
static constexpr u64 PhysicalMapAllowedMask = (1ul << 40) - 1;
|
||||||
|
#else
|
||||||
static constexpr u64 PhysicalMapAllowedMask = (1ul << 36) - 1;
|
static constexpr u64 PhysicalMapAllowedMask = (1ul << 36) - 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct MapRange {
|
struct MapRange {
|
||||||
using IdBits = Field<0, CapabilityId<CapabilityType::MapRange> + 1>;
|
using IdBits = Field<0, CapabilityId<CapabilityType::MapRange> + 1>;
|
||||||
|
@ -94,9 +98,15 @@ namespace ams::kern {
|
||||||
struct MapRangeSize {
|
struct MapRangeSize {
|
||||||
using IdBits = Field<0, CapabilityId<CapabilityType::MapRange> + 1>;
|
using IdBits = Field<0, CapabilityId<CapabilityType::MapRange> + 1>;
|
||||||
|
|
||||||
DEFINE_FIELD(Pages, IdBits, 20);
|
DEFINE_FIELD(Pages, IdBits, 20);
|
||||||
|
|
||||||
|
#if defined(MESOSPHERE_ENABLE_LARGE_PHYSICAL_ADDRESS_CAPABILITIES)
|
||||||
|
DEFINE_FIELD(AddressHigh, Pages, 4);
|
||||||
|
DEFINE_FIELD(Normal, AddressHigh, 1, bool);
|
||||||
|
#else
|
||||||
DEFINE_FIELD(Reserved, Pages, 4);
|
DEFINE_FIELD(Reserved, Pages, 4);
|
||||||
DEFINE_FIELD(Normal, Reserved, 1, bool);
|
DEFINE_FIELD(Normal, Reserved, 1, bool);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MapIoPage {
|
struct MapIoPage {
|
||||||
|
|
|
@ -117,11 +117,15 @@ namespace ams::kern {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KCapabilities::MapRange(const util::BitPack32 cap, const util::BitPack32 size_cap, KProcessPageTable *page_table) {
|
Result KCapabilities::MapRange(const util::BitPack32 cap, const util::BitPack32 size_cap, KProcessPageTable *page_table) {
|
||||||
|
/* Get/validate address/size */
|
||||||
|
#if defined(MESOSPHERE_ENABLE_LARGE_PHYSICAL_ADDRESS_CAPABILITIES)
|
||||||
|
const u64 phys_addr = static_cast<u64>(cap.Get<MapRange::Address>() | (size_cap.Get<MapRangeSize::AddressHigh>() << MapRange::Address::Count)) * PageSize;
|
||||||
|
#else
|
||||||
|
const u64 phys_addr = static_cast<u64>(cap.Get<MapRange::Address>()) * PageSize;
|
||||||
|
|
||||||
/* Validate reserved bits are unused. */
|
/* Validate reserved bits are unused. */
|
||||||
R_UNLESS(size_cap.Get<MapRangeSize::Reserved>() == 0, svc::ResultOutOfRange());
|
R_UNLESS(size_cap.Get<MapRangeSize::Reserved>() == 0, svc::ResultOutOfRange());
|
||||||
|
#endif
|
||||||
/* Get/validate address/size */
|
|
||||||
const u64 phys_addr = cap.Get<MapRange::Address>() * PageSize;
|
|
||||||
const size_t num_pages = size_cap.Get<MapRangeSize::Pages>();
|
const size_t num_pages = size_cap.Get<MapRangeSize::Pages>();
|
||||||
const size_t size = num_pages * PageSize;
|
const size_t size = num_pages * PageSize;
|
||||||
R_UNLESS(phys_addr == GetInteger(KPhysicalAddress(phys_addr)), svc::ResultInvalidAddress());
|
R_UNLESS(phys_addr == GetInteger(KPhysicalAddress(phys_addr)), svc::ResultInvalidAddress());
|
||||||
|
|
Loading…
Reference in a new issue