Core: Clang format and other small issues.

This commit is contained in:
Fernando Sahmkow 2023-12-31 20:55:15 +01:00 committed by Liam
parent b0bca0f8b0
commit 590d9b7e1d
40 changed files with 152 additions and 106 deletions

View file

@ -16,6 +16,12 @@
namespace Service::Nvidia::NvCore {
Session::Session(size_t id_, Kernel::KProcess* process_, size_t smmu_id_)
: id{id_}, process{process_}, smmu_id{smmu_id_},
has_preallocated_area{}, mapper{}, is_active{} {}
Session::~Session() = default;
struct ContainerImpl {
explicit ContainerImpl(Container& core, Tegra::Host1x::Host1x& host1x_)
: host1x{host1x_}, file{core, host1x_}, manager{host1x_}, device_file_data{} {}
@ -54,8 +60,8 @@ size_t Container::OpenSession(Kernel::KProcess* process) {
impl->id_pool.pop_front();
impl->sessions[new_id] = Session{new_id, process, smmu_id};
} else {
impl->sessions.emplace_back(new_id, process, smmu_id);
new_id = impl->new_ids++;
impl->sessions.emplace_back(new_id, process, smmu_id);
}
auto& session = impl->sessions[new_id];
session.is_active = true;

View file

@ -27,6 +27,14 @@ class SyncpointManager;
struct ContainerImpl;
struct Session {
Session(size_t id_, Kernel::KProcess* process_, size_t smmu_id_);
~Session();
Session(const Session&) = delete;
Session& operator=(const Session&) = delete;
Session(Session&&) = default;
Session& operator=(Session&&) = default;
size_t id;
Kernel::KProcess* process;
size_t smmu_id;

View file

@ -124,10 +124,11 @@ DAddr HeapMapper::Map(VAddr start, size_t size) {
m_internal->base_set.clear();
const IntervalType interval{start, start + size};
m_internal->base_set.insert(interval);
m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size, [this](VAddr start_addr, VAddr end_addr, int){
const IntervalType other{start_addr, end_addr};
m_internal->base_set.subtract(other);
});
m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size,
[this](VAddr start_addr, VAddr end_addr, int) {
const IntervalType other{start_addr, end_addr};
m_internal->base_set.subtract(other);
});
if (!m_internal->base_set.empty()) {
auto it = m_internal->base_set.begin();
auto end_it = m_internal->base_set.end();
@ -136,7 +137,8 @@ DAddr HeapMapper::Map(VAddr start, size_t size) {
const VAddr inter_addr = it->lower();
const size_t offset = inter_addr - m_vaddress;
const size_t sub_size = inter_addr_end - inter_addr;
m_internal->device_memory.Map(m_daddress + offset, m_vaddress + offset, sub_size, m_smmu_id);
m_internal->device_memory.Map(m_daddress + offset, m_vaddress + offset, sub_size,
m_smmu_id);
}
}
m_internal->mapping_overlaps += std::make_pair(interval, 1);
@ -147,12 +149,13 @@ DAddr HeapMapper::Map(VAddr start, size_t size) {
void HeapMapper::Unmap(VAddr start, size_t size) {
std::scoped_lock lk(m_internal->guard);
m_internal->base_set.clear();
m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size, [this](VAddr start_addr, VAddr end_addr, int value) {
if (value <= 1) {
const IntervalType other{start_addr, end_addr};
m_internal->base_set.insert(other);
}
});
m_internal->ForEachInOverlapCounter(m_internal->mapping_overlaps, start, size,
[this](VAddr start_addr, VAddr end_addr, int value) {
if (value <= 1) {
const IntervalType other{start_addr, end_addr};
m_internal->base_set.insert(other);
}
});
if (!m_internal->base_set.empty()) {
auto it = m_internal->base_set.begin();
auto end_it = m_internal->base_set.end();

View file

@ -13,8 +13,8 @@
#include "core/memory.h"
#include "video_core/host1x/host1x.h"
using Core::Memory::YUZU_PAGESIZE;
constexpr size_t BIG_PAGE_SIZE = YUZU_PAGESIZE * 16;
namespace Service::Nvidia::NvCore {
NvMap::Handle::Handle(u64 size_, Id id_)
@ -96,8 +96,9 @@ void NvMap::UnmapHandle(Handle& handle_description) {
const size_t map_size = handle_description.aligned_size;
if (!handle_description.in_heap) {
auto& smmu = host1x.MemoryManager();
size_t aligned_up = Common::AlignUp(map_size, BIG_PAGE_SIZE);
smmu.Unmap(handle_description.d_address, map_size);
smmu.Free(handle_description.d_address, static_cast<size_t>(map_size));
smmu.Free(handle_description.d_address, static_cast<size_t>(aligned_up));
handle_description.d_address = 0;
return;
}
@ -206,7 +207,8 @@ DAddr NvMap::PinHandle(NvMap::Handle::Id handle, bool low_area_pin) {
handle_description->d_address = session->mapper->Map(vaddress, map_size);
handle_description->in_heap = true;
} else {
while ((address = smmu.Allocate(map_size)) == 0) {
size_t aligned_up = Common::AlignUp(map_size, BIG_PAGE_SIZE);
while ((address = smmu.Allocate(aligned_up)) == 0) {
// Free handles until the allocation succeeds
std::scoped_lock queueLock(unmap_queue_lock);
if (auto freeHandleDesc{unmap_queue.front()}) {

View file

@ -63,8 +63,8 @@ public:
} flags{};
static_assert(sizeof(Flags) == sizeof(u32));
VAddr address{}; //!< The memory location in the guest's AS that this handle corresponds to,
//!< this can also be in the nvdrv tmem
VAddr address{}; //!< The memory location in the guest's AS that this handle corresponds to,
//!< this can also be in the nvdrv tmem
bool is_shared_mem_mapped{}; //!< If this nvmap has been mapped with the MapSharedMem IPC
//!< call
@ -73,8 +73,8 @@ public:
bool in_heap{};
size_t session_id{};
DAddr d_address{}; //!< The memory location in the device's AS that this handle corresponds to,
//!< this can also be in the nvdrv tmem
DAddr d_address{}; //!< The memory location in the device's AS that this handle corresponds
//!< to, this can also be in the nvdrv tmem
Handle(u64 size, Id id);
@ -82,7 +82,8 @@ public:
* @brief Sets up the handle with the given memory config, can allocate memory from the tmem
* if a 0 address is passed
*/
[[nodiscard]] NvResult Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress, size_t pSessionId);
[[nodiscard]] NvResult Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress,
size_t pSessionId);
/**
* @brief Increases the dupe counter of the handle for the given session

View file

@ -4,8 +4,8 @@
#pragma once
#include <deque>
#include <vector>
#include <unordered_map>
#include <vector>
#include "common/common_types.h"
#include "common/swap.h"

View file

@ -69,7 +69,7 @@ NvResult nvhost_vic::Ioctl3(DeviceFD fd, Ioctl command, std::span<const u8> inpu
}
void nvhost_vic::OnOpen(size_t session_id, DeviceFD fd) {
sessions[fd] = session_id;
sessions[fd] = session_id;
}
void nvhost_vic::OnClose(DeviceFD fd) {

View file

@ -123,8 +123,8 @@ NvResult nvmap::IocAlloc(IocAllocParams& params, DeviceFD fd) {
return NvResult::InsufficientMemory;
}
const auto result =
handle_description->Alloc(params.flags, params.align, params.kind, params.address, sessions[fd]);
const auto result = handle_description->Alloc(params.flags, params.align, params.kind,
params.address, sessions[fd]);
if (result != NvResult::Success) {
LOG_CRITICAL(Service_NVDRV, "Object failed to allocate, handle={:08X}", params.handle);
return result;