2021-07-17 18:28:04 +02:00
|
|
|
// SPDX-License-Identifier: MIT OR MPL-2.0
|
|
|
|
// Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
2020-03-27 20:36:02 +01:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
#include <services/nvdrv/devices/deserialisation/deserialisation.h>
|
|
|
|
#include <services/nvdrv/core/nvmap.h>
|
2020-03-26 15:33:19 +01:00
|
|
|
#include "nvmap.h"
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2020-03-24 21:17:31 +01:00
|
|
|
namespace skyline::service::nvdrv::device {
|
2021-07-17 18:28:04 +02:00
|
|
|
NvMap::NvMap(const DeviceState &state, Core &core, const SessionContext &ctx) : NvDevice(state, core, ctx) {}
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
PosixResult NvMap::Create(In<u32> size, Out<NvMapCore::Handle::Id> handle) {
|
|
|
|
auto h{core.nvMap.CreateHandle(util::AlignUp(size, PAGE_SIZE))};
|
|
|
|
if (h) {
|
|
|
|
(*h)->origSize = size; // Orig size is the unaligned size
|
|
|
|
handle = (*h)->id;
|
2021-07-17 23:23:26 +02:00
|
|
|
state.logger->Debug("handle: {}, size: 0x{:X}", (*h)->id, size);
|
2021-07-17 18:28:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
PosixResult NvMap::FromId(In<NvMapCore::Handle::Id> id, Out<NvMapCore::Handle::Id> handle) {
|
2021-09-18 14:16:41 +02:00
|
|
|
state.logger->Debug("id: {}", id);
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
// Handles and IDs are always the same value in nvmap however IDs can be used globally given the right permissions.
|
|
|
|
// Since we don't plan on ever supporting multiprocess we can skip implementing handle refs and so this function
|
|
|
|
// just does simple validation and passes through the handle id.
|
|
|
|
if (!id) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
2020-04-22 19:02:27 +02:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
auto h{core.nvMap.GetHandle(id)};
|
|
|
|
if (!h) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
2020-04-22 19:02:27 +02:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
return h->Duplicate(ctx.internalSession);
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
}
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
PosixResult NvMap::Alloc(In<NvMapCore::Handle::Id> handle, In<u32> heapMask, In<NvMapCore::Handle::Flags> flags, InOut<u32> align, In<u8> kind, In<u64> address) {
|
2021-09-18 14:16:41 +02:00
|
|
|
state.logger->Debug("handle: {}, flags: ( mapUncached: {}, keepUncachedAfterFree: {} ), align: 0x{:X}, kind: {}, address: 0x{:X}", handle, flags.mapUncached, flags.keepUncachedAfterFree, align, kind, address);
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
if (!handle) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
2020-04-22 19:02:27 +02:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
if (!std::ispow2(align)) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
// Force page size alignment at a minimum
|
|
|
|
if (align < PAGE_SIZE) [[unlikely]]
|
|
|
|
align = PAGE_SIZE;
|
|
|
|
|
|
|
|
auto h{core.nvMap.GetHandle(handle)};
|
|
|
|
if (!h) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
|
|
|
|
|
|
|
return h->Alloc(flags, align, kind, address);
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
}
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
PosixResult NvMap::Free(In<NvMapCore::Handle::Id> handle, Out<u64> address, Out<u32> size, Out<NvMapCore::Handle::Flags> flags) {
|
2021-09-18 14:16:41 +02:00
|
|
|
state.logger->Debug("handle: {}", handle);
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
if (!handle) [[unlikely]]
|
|
|
|
return PosixResult::Success;
|
|
|
|
|
|
|
|
if (auto freeInfo{core.nvMap.FreeHandle(handle, ctx.internalSession)}) {
|
|
|
|
address = freeInfo->address;
|
|
|
|
size = static_cast<u32>(freeInfo->size);
|
|
|
|
flags = NvMapCore::Handle::Flags{ .mapUncached = freeInfo->wasUncached };
|
2021-09-18 14:16:41 +02:00
|
|
|
} else {
|
|
|
|
state.logger->Debug("Handle not freed");
|
2020-09-19 16:45:17 +02:00
|
|
|
}
|
2021-07-17 18:28:04 +02:00
|
|
|
|
|
|
|
return PosixResult::Success;
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
}
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
PosixResult NvMap::Param(In<NvMapCore::Handle::Id> handle, In<HandleParameterType> param, Out<u32> result) {
|
2021-09-18 14:16:41 +02:00
|
|
|
state.logger->Debug("handle: {}, param: {}", handle, param);
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
if (!handle)
|
|
|
|
return PosixResult::InvalidArgument;
|
|
|
|
|
|
|
|
auto h{core.nvMap.GetHandle(handle)};
|
|
|
|
if (!h) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case HandleParameterType::Size:
|
|
|
|
result = h->origSize;
|
|
|
|
return PosixResult::Success;
|
|
|
|
case HandleParameterType::Alignment:
|
|
|
|
result = h->align;
|
|
|
|
return PosixResult::Success;
|
|
|
|
case HandleParameterType::Base:
|
|
|
|
result = -static_cast<i32>(PosixResult::InvalidArgument);
|
|
|
|
return PosixResult::Success;
|
|
|
|
case HandleParameterType::Heap:
|
|
|
|
if (h->allocated)
|
|
|
|
result = 0x40000000;
|
|
|
|
else
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
return PosixResult::Success;
|
|
|
|
case HandleParameterType::Kind:
|
|
|
|
result = h->kind;
|
|
|
|
return PosixResult::Success;
|
|
|
|
case HandleParameterType::IsSharedMemMapped:
|
|
|
|
result = h->isSharedMemMapped;
|
|
|
|
return PosixResult::Success;
|
|
|
|
default:
|
|
|
|
return PosixResult::InvalidArgument;
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
PosixResult NvMap::GetId(Out<NvMapCore::Handle::Id> id, In<NvMapCore::Handle::Id> handle) {
|
2021-09-18 14:16:41 +02:00
|
|
|
state.logger->Debug("handle: {}", handle);
|
|
|
|
|
2021-07-17 18:28:04 +02:00
|
|
|
// See the comment in FromId for extra info on this function
|
|
|
|
if (!handle) [[unlikely]]
|
|
|
|
return PosixResult::InvalidArgument;
|
|
|
|
|
|
|
|
auto h{core.nvMap.GetHandle(handle)};
|
|
|
|
if (!h) [[unlikely]]
|
|
|
|
return PosixResult::NotPermitted; // This will always return EPERM irrespective of if the handle exists or not
|
|
|
|
|
|
|
|
id = h->id;
|
|
|
|
return PosixResult::Success;
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
}
|
2021-07-17 18:28:04 +02:00
|
|
|
|
2021-08-14 21:42:11 +02:00
|
|
|
#include "deserialisation/macro_def.inc"
|
2021-07-17 18:28:04 +02:00
|
|
|
static constexpr u32 NvMapMagic{1};
|
|
|
|
|
|
|
|
IOCTL_HANDLER_FUNC(NvMap, ({
|
|
|
|
IOCTL_CASE_ARGS(INOUT, SIZE(0x8), MAGIC(NvMapMagic), FUNC(0x1),
|
|
|
|
Create, ARGS(In<u32>, Out<NvMapCore::Handle::Id>))
|
|
|
|
IOCTL_CASE_ARGS(INOUT, SIZE(0x8), MAGIC(NvMapMagic), FUNC(0x3),
|
|
|
|
FromId, ARGS(In<NvMapCore::Handle::Id>, Out<NvMapCore::Handle::Id>))
|
|
|
|
IOCTL_CASE_ARGS(INOUT, SIZE(0x20), MAGIC(NvMapMagic), FUNC(0x4),
|
|
|
|
Alloc, ARGS(In<NvMapCore::Handle::Id>, In<u32>, In<NvMapCore::Handle::Flags>, InOut<u32>, In<u8>, Pad<u8, 0x7>, In<u64>))
|
|
|
|
IOCTL_CASE_ARGS(INOUT, SIZE(0x18), MAGIC(NvMapMagic), FUNC(0x5),
|
|
|
|
Free, ARGS(In<NvMapCore::Handle::Id>, Pad<u32>, Out<u64>, Out<u32>, Out<NvMapCore::Handle::Flags>))
|
|
|
|
IOCTL_CASE_ARGS(INOUT, SIZE(0xC), MAGIC(NvMapMagic), FUNC(0x9),
|
|
|
|
Param, ARGS(In<NvMapCore::Handle::Id>, In<HandleParameterType>, Out<u32>))
|
|
|
|
IOCTL_CASE_ARGS(INOUT, SIZE(0x8), MAGIC(NvMapMagic), FUNC(0xE),
|
|
|
|
GetId, ARGS(Out<NvMapCore::Handle::Id>, In<NvMapCore::Handle::Id>))
|
|
|
|
}))
|
2021-08-14 21:42:11 +02:00
|
|
|
#include "deserialisation/macro_undef.inc"
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
}
|
2021-07-17 18:28:04 +02:00
|
|
|
|