mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-31 06:48:22 -04:00
dd: implement DeviceAddressSpaceType api
This commit is contained in:
parent
708f5bf1fb
commit
4d1c4f1677
15 changed files with 626 additions and 52 deletions
|
@ -16,5 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "dd/dd_io_mappings.hpp"
|
||||
#include "dd/dd_process_handle.hpp"
|
||||
#include <stratosphere/dd/dd_types.hpp>
|
||||
#include <stratosphere/dd/dd_device_address_space.hpp>
|
||||
#include <stratosphere/dd/dd_io_mappings.hpp>
|
||||
#include <stratosphere/dd/dd_process_handle.hpp>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
#include <stratosphere/dd/dd_device_address_space_common.hpp>
|
||||
#include <stratosphere/dd/dd_device_address_space_types.hpp>
|
||||
#include <stratosphere/dd/dd_device_address_space_api.hpp>
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/dd/dd_types.hpp>
|
||||
#include <stratosphere/dd/dd_device_address_space_common.hpp>
|
||||
#include <stratosphere/dd/dd_device_address_space_types.hpp>
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
Result CreateDeviceAddressSpace(DeviceAddressSpaceType *das, u64 address, u64 size);
|
||||
Result CreateDeviceAddressSpace(DeviceAddressSpaceType *das, u64 size);
|
||||
void DestroyDeviceAddressSpace(DeviceAddressSpaceType *das);
|
||||
|
||||
void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, Handle handle, bool managed);
|
||||
|
||||
Handle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das);
|
||||
|
||||
Result MapDeviceAddressSpaceAligned(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm);
|
||||
Result MapDeviceAddressSpaceNotAligned(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm);
|
||||
void UnmapDeviceAddressSpace(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address);
|
||||
|
||||
void InitializeDeviceAddressSpaceMapInfo(DeviceAddressSpaceMapInfo *info, DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm);
|
||||
|
||||
Result MapNextDeviceAddressSpaceRegion(size_t *out_mapped_size, DeviceAddressSpaceMapInfo *info);
|
||||
void UnmapDeviceAddressSpaceRegion(DeviceAddressSpaceMapInfo *info);
|
||||
|
||||
u64 GetMappedProcessAddress(DeviceAddressSpaceMapInfo *info);
|
||||
DeviceVirtualAddress GetMappedDeviceVirtualAddress(DeviceAddressSpaceMapInfo *info);
|
||||
size_t GetMappedSize(DeviceAddressSpaceMapInfo *info);
|
||||
|
||||
Result AttachDeviceAddressSpace(DeviceAddressSpaceType *das, DeviceName device_name);
|
||||
void DetachDeviceAddressSpace(DeviceAddressSpaceType *das, DeviceName device_name);
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/dd/dd_types.hpp>
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
using DeviceName = ::ams::svc::DeviceName;
|
||||
|
||||
constexpr inline u64 DeviceAddressSpaceMemoryRegionAlignment = 4_KB;
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/dd/dd_types.hpp>
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
using DeviceVirtualAddress = u64;
|
||||
|
||||
using DeviceAddressSpaceHandle = ::Handle;
|
||||
|
||||
struct DeviceAddressSpaceType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
DeviceAddressSpaceHandle device_handle;
|
||||
u8 state;
|
||||
bool is_handle_managed;
|
||||
};
|
||||
static_assert(std::is_trivial<DeviceAddressSpaceType>::value);
|
||||
|
||||
struct DeviceAddressSpaceMapInfo {
|
||||
size_t last_mapped_size;
|
||||
size_t size;
|
||||
u64 process_address;
|
||||
DeviceVirtualAddress device_start_address;
|
||||
DeviceVirtualAddress device_end_address;
|
||||
ProcessHandle process_handle;
|
||||
MemoryPermission device_permission;
|
||||
DeviceAddressSpaceType *device_address_space;
|
||||
};
|
||||
static_assert(std::is_trivial<DeviceAddressSpaceMapInfo>::value);
|
||||
|
||||
}
|
|
@ -19,10 +19,6 @@
|
|||
|
||||
namespace ams::dd {
|
||||
|
||||
u32 ReadRegister(dd::PhysicalAddress phys_addr);
|
||||
void WriteRegister(dd::PhysicalAddress phys_addr, u32 value);
|
||||
u32 ReadWriteRegister(dd::PhysicalAddress phys_addr, u32 value, u32 mask);
|
||||
|
||||
/* Convenience Helper. */
|
||||
inline uintptr_t GetIoMapping(dd::PhysicalAddress phys_addr, size_t size) {
|
||||
const uintptr_t io_mapping = dd::QueryIoMapping(phys_addr, size);
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/dd/dd_types.hpp>
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
::Handle GetCurrentProcessHandle();
|
||||
ProcessHandle GetCurrentProcessHandle();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/dd/dd_types.hpp>
|
||||
|
||||
namespace ams::dd {
|
||||
|
||||
using ProcessHandle = ::Handle;
|
||||
|
||||
enum MemoryPermission {
|
||||
MemoryPermission_None = 0,
|
||||
MemoryPermission_ReadOnly = (1u << 0),
|
||||
MemoryPermission_WriteOnly = (1u << 1),
|
||||
|
||||
MemoryPermission_ReadWrite = MemoryPermission_ReadOnly | MemoryPermission_WriteOnly,
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue