From beb438bb0bede8b8906a41f7a1ad7b010ec3ec60 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 15 Jan 2024 21:47:59 -0500 Subject: [PATCH] nvdrv: use static typing for SessionId, smmu Asid types --- src/core/device_memory_manager.h | 31 ++++++++++--------- src/core/device_memory_manager.inc | 28 ++++++++--------- src/core/hle/service/nvdrv/core/container.cpp | 31 +++++++++---------- src/core/hle/service/nvdrv/core/container.h | 17 ++++++---- .../hle/service/nvdrv/core/heap_mapper.cpp | 8 ++--- src/core/hle/service/nvdrv/core/heap_mapper.h | 7 +++-- src/core/hle/service/nvdrv/core/nvmap.cpp | 5 +-- src/core/hle/service/nvdrv/core/nvmap.h | 5 +-- src/core/hle/service/nvdrv/devices/nvdevice.h | 3 +- .../service/nvdrv/devices/nvdisp_disp0.cpp | 2 +- .../hle/service/nvdrv/devices/nvdisp_disp0.h | 2 +- .../service/nvdrv/devices/nvhost_as_gpu.cpp | 2 +- .../hle/service/nvdrv/devices/nvhost_as_gpu.h | 2 +- .../hle/service/nvdrv/devices/nvhost_ctrl.cpp | 2 +- .../hle/service/nvdrv/devices/nvhost_ctrl.h | 2 +- .../service/nvdrv/devices/nvhost_ctrl_gpu.cpp | 2 +- .../service/nvdrv/devices/nvhost_ctrl_gpu.h | 2 +- .../hle/service/nvdrv/devices/nvhost_gpu.cpp | 2 +- .../hle/service/nvdrv/devices/nvhost_gpu.h | 2 +- .../service/nvdrv/devices/nvhost_nvdec.cpp | 2 +- .../hle/service/nvdrv/devices/nvhost_nvdec.h | 2 +- .../nvdrv/devices/nvhost_nvdec_common.h | 2 +- .../service/nvdrv/devices/nvhost_nvjpg.cpp | 2 +- .../hle/service/nvdrv/devices/nvhost_nvjpg.h | 2 +- .../hle/service/nvdrv/devices/nvhost_vic.cpp | 2 +- .../hle/service/nvdrv/devices/nvhost_vic.h | 2 +- src/core/hle/service/nvdrv/devices/nvmap.cpp | 2 +- src/core/hle/service/nvdrv/devices/nvmap.h | 4 +-- src/core/hle/service/nvdrv/nvdrv.cpp | 2 +- src/core/hle/service/nvdrv/nvdrv.h | 2 +- src/core/hle/service/nvdrv/nvdrv_interface.h | 2 +- .../nvnflinger/fb_share_buffer_manager.h | 3 +- .../hle/service/nvnflinger/nvnflinger.cpp | 2 +- 33 files changed, 99 insertions(+), 87 deletions(-) diff --git a/src/core/device_memory_manager.h b/src/core/device_memory_manager.h index 6311e9ecee..ffeed46ccd 100644 --- a/src/core/device_memory_manager.h +++ b/src/core/device_memory_manager.h @@ -28,6 +28,10 @@ class Memory; template struct DeviceMemoryManagerAllocator; +struct Asid { + size_t id; +}; + template class DeviceMemoryManager { using DeviceInterface = typename Traits::DeviceInterface; @@ -43,15 +47,14 @@ public: void AllocateFixed(DAddr start, size_t size); void Free(DAddr start, size_t size); - void Map(DAddr address, VAddr virtual_address, size_t size, size_t process_id, - bool track = false); + void Map(DAddr address, VAddr virtual_address, size_t size, Asid asid, bool track = false); void Unmap(DAddr address, size_t size); - void TrackContinuityImpl(DAddr address, VAddr virtual_address, size_t size, size_t process_id); - void TrackContinuity(DAddr address, VAddr virtual_address, size_t size, size_t process_id) { + void TrackContinuityImpl(DAddr address, VAddr virtual_address, size_t size, Asid asid); + void TrackContinuity(DAddr address, VAddr virtual_address, size_t size, Asid asid) { std::scoped_lock lk(mapping_guard); - TrackContinuityImpl(address, virtual_address, size, process_id); + TrackContinuityImpl(address, virtual_address, size, asid); } // Write / Read @@ -105,8 +108,8 @@ public: void WriteBlock(DAddr address, const void* src_pointer, size_t size); void WriteBlockUnsafe(DAddr address, const void* src_pointer, size_t size); - size_t RegisterProcess(Memory::Memory* memory); - void UnregisterProcess(size_t id); + Asid RegisterProcess(Memory::Memory* memory); + void UnregisterProcess(Asid id); void UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta); @@ -163,17 +166,17 @@ private: static constexpr size_t guest_max_as_bits = 39; static constexpr size_t guest_as_size = 1ULL << guest_max_as_bits; static constexpr size_t guest_mask = guest_as_size - 1ULL; - static constexpr size_t process_id_start_bit = guest_max_as_bits; + static constexpr size_t asid_start_bit = guest_max_as_bits; - std::pair ExtractCPUBacking(size_t page_index) { + std::pair ExtractCPUBacking(size_t page_index) { auto content = cpu_backing_address[page_index]; const VAddr address = content & guest_mask; - const size_t process_id = static_cast(content >> process_id_start_bit); - return std::make_pair(process_id, address); + const Asid asid{static_cast(content >> asid_start_bit)}; + return std::make_pair(asid, address); } - void InsertCPUBacking(size_t page_index, VAddr address, size_t process_id) { - cpu_backing_address[page_index] = address | (process_id << process_id_start_bit); + void InsertCPUBacking(size_t page_index, VAddr address, Asid asid) { + cpu_backing_address[page_index] = address | (asid.id << asid_start_bit); } Common::VirtualBuffer cpu_backing_address; @@ -205,4 +208,4 @@ private: std::mutex mapping_guard; }; -} // namespace Core \ No newline at end of file +} // namespace Core diff --git a/src/core/device_memory_manager.inc b/src/core/device_memory_manager.inc index d7b4abacce..f6e4ad8742 100644 --- a/src/core/device_memory_manager.inc +++ b/src/core/device_memory_manager.inc @@ -215,8 +215,8 @@ void DeviceMemoryManager::Free(DAddr start, size_t size) { template void DeviceMemoryManager::Map(DAddr address, VAddr virtual_address, size_t size, - size_t process_id, bool track) { - Core::Memory::Memory* process_memory = registered_processes[process_id]; + Asid asid, bool track) { + Core::Memory::Memory* process_memory = registered_processes[asid.id]; size_t start_page_d = address >> Memory::YUZU_PAGEBITS; size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS; std::scoped_lock lk(mapping_guard); @@ -229,7 +229,7 @@ void DeviceMemoryManager::Map(DAddr address, VAddr virtual_address, size } auto phys_addr = static_cast(GetRawPhysicalAddr(ptr) >> Memory::YUZU_PAGEBITS) + 1U; compressed_physical_ptr[start_page_d + i] = phys_addr; - InsertCPUBacking(start_page_d + i, new_vaddress, process_id); + InsertCPUBacking(start_page_d + i, new_vaddress, asid); const u32 base_dev = compressed_device_addr[phys_addr - 1U]; const u32 new_dev = static_cast(start_page_d + i); if (base_dev == 0) [[likely]] { @@ -244,7 +244,7 @@ void DeviceMemoryManager::Map(DAddr address, VAddr virtual_address, size impl->multi_dev_address.Register(new_dev, start_id); } if (track) { - TrackContinuityImpl(address, virtual_address, size, process_id); + TrackContinuityImpl(address, virtual_address, size, asid); } } @@ -277,8 +277,8 @@ void DeviceMemoryManager::Unmap(DAddr address, size_t size) { } template void DeviceMemoryManager::TrackContinuityImpl(DAddr address, VAddr virtual_address, - size_t size, size_t process_id) { - Core::Memory::Memory* process_memory = registered_processes[process_id]; + size_t size, Asid asid) { + Core::Memory::Memory* process_memory = registered_processes[asid.id]; size_t start_page_d = address >> Memory::YUZU_PAGEBITS; size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS; uintptr_t last_ptr = 0; @@ -488,8 +488,8 @@ void DeviceMemoryManager::WriteBlockUnsafe(DAddr address, const void* sr } template -size_t DeviceMemoryManager::RegisterProcess(Memory::Memory* memory_device_inter) { - size_t new_id; +Asid DeviceMemoryManager::RegisterProcess(Memory::Memory* memory_device_inter) { + size_t new_id{}; if (!id_pool.empty()) { new_id = id_pool.front(); id_pool.pop_front(); @@ -498,13 +498,13 @@ size_t DeviceMemoryManager::RegisterProcess(Memory::Memory* memory_devic registered_processes.emplace_back(memory_device_inter); new_id = registered_processes.size() - 1U; } - return new_id; + return Asid{new_id}; } template -void DeviceMemoryManager::UnregisterProcess(size_t id) { - registered_processes[id] = nullptr; - id_pool.push_front(id); +void DeviceMemoryManager::UnregisterProcess(Asid asid) { + registered_processes[asid.id] = nullptr; + id_pool.push_front(asid.id); } template @@ -530,9 +530,9 @@ void DeviceMemoryManager::UpdatePagesCachedCount(DAddr addr, size_t size std::atomic_thread_fence(std::memory_order_acquire); const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE); size_t page = addr >> Memory::YUZU_PAGEBITS; - auto [process_id, base_vaddress] = ExtractCPUBacking(page); + auto [asid, base_vaddress] = ExtractCPUBacking(page); size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS; - auto* memory_device_inter = registered_processes[process_id]; + auto* memory_device_inter = registered_processes[asid.id]; for (; page != page_end; ++page) { std::atomic_uint8_t& count = cached_pages->at(page >> 3).Count(page); diff --git a/src/core/hle/service/nvdrv/core/container.cpp b/src/core/hle/service/nvdrv/core/container.cpp index d04b7f5ffa..b5fd98a9d9 100644 --- a/src/core/hle/service/nvdrv/core/container.cpp +++ b/src/core/hle/service/nvdrv/core/container.cpp @@ -16,9 +16,8 @@ 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(SessionId id_, Kernel::KProcess* process_, Core::Asid asid_) + : id{id_}, process{process_}, asid{asid_}, has_preallocated_area{}, mapper{}, is_active{} {} Session::~Session() = default; @@ -41,7 +40,7 @@ Container::Container(Tegra::Host1x::Host1x& host1x_) { Container::~Container() = default; -size_t Container::OpenSession(Kernel::KProcess* process) { +SessionId Container::OpenSession(Kernel::KProcess* process) { std::scoped_lock lk(impl->session_guard); for (auto& session : impl->sessions) { if (!session.is_active) { @@ -54,14 +53,14 @@ size_t Container::OpenSession(Kernel::KProcess* process) { size_t new_id{}; auto* memory_interface = &process->GetMemory(); auto& smmu = impl->host1x.MemoryManager(); - auto smmu_id = smmu.RegisterProcess(memory_interface); + auto asid = smmu.RegisterProcess(memory_interface); if (!impl->id_pool.empty()) { new_id = impl->id_pool.front(); impl->id_pool.pop_front(); - impl->sessions[new_id] = Session{new_id, process, smmu_id}; + impl->sessions[new_id] = Session{SessionId{new_id}, process, asid}; } else { new_id = impl->new_ids++; - impl->sessions.emplace_back(new_id, process, smmu_id); + impl->sessions.emplace_back(SessionId{new_id}, process, asid); } auto& session = impl->sessions[new_id]; session.is_active = true; @@ -100,18 +99,18 @@ size_t Container::OpenSession(Kernel::KProcess* process) { auto start_region = (region_size >> 15) >= 1024 ? smmu.Allocate(region_size) : 0; if (start_region != 0) { session.mapper = std::make_unique(region_start, start_region, region_size, - smmu_id, impl->host1x); - smmu.TrackContinuity(start_region, region_start, region_size, smmu_id); + asid, impl->host1x); + smmu.TrackContinuity(start_region, region_start, region_size, asid); session.has_preallocated_area = true; LOG_CRITICAL(Debug, "Preallocation created!"); } } - return new_id; + return SessionId{new_id}; } -void Container::CloseSession(size_t id) { +void Container::CloseSession(SessionId session_id) { std::scoped_lock lk(impl->session_guard); - auto& session = impl->sessions[id]; + auto& session = impl->sessions[session_id.id]; auto& smmu = impl->host1x.MemoryManager(); if (session.has_preallocated_area) { const DAddr region_start = session.mapper->GetRegionStart(); @@ -121,13 +120,13 @@ void Container::CloseSession(size_t id) { session.has_preallocated_area = false; } session.is_active = false; - smmu.UnregisterProcess(impl->sessions[id].smmu_id); - impl->id_pool.emplace_front(id); + smmu.UnregisterProcess(impl->sessions[session_id.id].asid); + impl->id_pool.emplace_front(session_id.id); } -Session* Container::GetSession(size_t id) { +Session* Container::GetSession(SessionId session_id) { std::atomic_thread_fence(std::memory_order_acquire); - return &impl->sessions[id]; + return &impl->sessions[session_id.id]; } NvMap& Container::GetNvMapFile() { diff --git a/src/core/hle/service/nvdrv/core/container.h b/src/core/hle/service/nvdrv/core/container.h index 4b84528446..b4d3938a8e 100644 --- a/src/core/hle/service/nvdrv/core/container.h +++ b/src/core/hle/service/nvdrv/core/container.h @@ -8,6 +8,7 @@ #include #include +#include "core/device_memory_manager.h" #include "core/hle/service/nvdrv/nvdata.h" namespace Kernel { @@ -26,8 +27,12 @@ class SyncpointManager; struct ContainerImpl; +struct SessionId { + size_t id; +}; + struct Session { - Session(size_t id_, Kernel::KProcess* process_, size_t smmu_id_); + Session(SessionId id_, Kernel::KProcess* process_, Core::Asid asid_); ~Session(); Session(const Session&) = delete; @@ -35,9 +40,9 @@ struct Session { Session(Session&&) = default; Session& operator=(Session&&) = default; - size_t id; + SessionId id; Kernel::KProcess* process; - size_t smmu_id; + Core::Asid asid; bool has_preallocated_area{}; std::unique_ptr mapper{}; bool is_active{}; @@ -48,10 +53,10 @@ public: explicit Container(Tegra::Host1x::Host1x& host1x); ~Container(); - size_t OpenSession(Kernel::KProcess* process); - void CloseSession(size_t id); + SessionId OpenSession(Kernel::KProcess* process); + void CloseSession(SessionId id); - Session* GetSession(size_t id); + Session* GetSession(SessionId id); NvMap& GetNvMapFile(); diff --git a/src/core/hle/service/nvdrv/core/heap_mapper.cpp b/src/core/hle/service/nvdrv/core/heap_mapper.cpp index c29191b921..096dc5deb5 100644 --- a/src/core/hle/service/nvdrv/core/heap_mapper.cpp +++ b/src/core/hle/service/nvdrv/core/heap_mapper.cpp @@ -109,9 +109,9 @@ struct HeapMapper::HeapMapperInternal { std::mutex guard; }; -HeapMapper::HeapMapper(VAddr start_vaddress, DAddr start_daddress, size_t size, size_t smmu_id, +HeapMapper::HeapMapper(VAddr start_vaddress, DAddr start_daddress, size_t size, Core::Asid asid, Tegra::Host1x::Host1x& host1x) - : m_vaddress{start_vaddress}, m_daddress{start_daddress}, m_size{size}, m_smmu_id{smmu_id} { + : m_vaddress{start_vaddress}, m_daddress{start_daddress}, m_size{size}, m_asid{asid} { m_internal = std::make_unique(host1x); } @@ -138,7 +138,7 @@ DAddr HeapMapper::Map(VAddr start, size_t size) { 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_asid); } } m_internal->mapping_overlaps += std::make_pair(interval, 1); @@ -172,4 +172,4 @@ void HeapMapper::Unmap(VAddr start, size_t size) { m_internal->base_set.clear(); } -} // namespace Service::Nvidia::NvCore \ No newline at end of file +} // namespace Service::Nvidia::NvCore diff --git a/src/core/hle/service/nvdrv/core/heap_mapper.h b/src/core/hle/service/nvdrv/core/heap_mapper.h index 8b23638b87..491a12e4f1 100644 --- a/src/core/hle/service/nvdrv/core/heap_mapper.h +++ b/src/core/hle/service/nvdrv/core/heap_mapper.h @@ -6,6 +6,7 @@ #include #include "common/common_types.h" +#include "core/device_memory_manager.h" namespace Tegra::Host1x { class Host1x; @@ -15,7 +16,7 @@ namespace Service::Nvidia::NvCore { class HeapMapper { public: - HeapMapper(VAddr start_vaddress, DAddr start_daddress, size_t size, size_t smmu_id, + HeapMapper(VAddr start_vaddress, DAddr start_daddress, size_t size, Core::Asid asid, Tegra::Host1x::Host1x& host1x); ~HeapMapper(); @@ -41,8 +42,8 @@ private: VAddr m_vaddress; DAddr m_daddress; size_t m_size; - size_t m_smmu_id; + Core::Asid m_asid; std::unique_ptr m_internal; }; -} // namespace Service::Nvidia::NvCore \ No newline at end of file +} // namespace Service::Nvidia::NvCore diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cpp index 6e59d4fe1f..1b59c6b15a 100644 --- a/src/core/hle/service/nvdrv/core/nvmap.cpp +++ b/src/core/hle/service/nvdrv/core/nvmap.cpp @@ -22,7 +22,8 @@ NvMap::Handle::Handle(u64 size_, Id id_) flags.raw = 0; } -NvResult NvMap::Handle::Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress, size_t pSessionId) { +NvResult NvMap::Handle::Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress, + NvCore::SessionId pSessionId) { std::scoped_lock lock(mutex); // Handles cannot be allocated twice if (allocated) { @@ -223,7 +224,7 @@ DAddr NvMap::PinHandle(NvMap::Handle::Id handle, bool low_area_pin) { } handle_description->d_address = address; - smmu.Map(address, vaddress, map_size, session->smmu_id, true); + smmu.Map(address, vaddress, map_size, session->asid, true); handle_description->in_heap = false; } } diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.h index aa5cd21ec0..d7f6958450 100644 --- a/src/core/hle/service/nvdrv/core/nvmap.h +++ b/src/core/hle/service/nvdrv/core/nvmap.h @@ -14,6 +14,7 @@ #include "common/bit_field.h" #include "common/common_types.h" +#include "core/hle/service/nvdrv/core/container.h" #include "core/hle/service/nvdrv/nvdata.h" namespace Tegra { @@ -71,7 +72,7 @@ public: u8 kind{}; //!< Used for memory compression bool allocated{}; //!< If the handle has been allocated with `Alloc` bool in_heap{}; - size_t session_id{}; + NvCore::SessionId 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 @@ -83,7 +84,7 @@ public: * if a 0 address is passed */ [[nodiscard]] NvResult Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress, - size_t pSessionId); + NvCore::SessionId pSessionId); /** * @brief Increases the dupe counter of the handle for the given session diff --git a/src/core/hle/service/nvdrv/devices/nvdevice.h b/src/core/hle/service/nvdrv/devices/nvdevice.h index ff91aabcbd..8adaddc60b 100644 --- a/src/core/hle/service/nvdrv/devices/nvdevice.h +++ b/src/core/hle/service/nvdrv/devices/nvdevice.h @@ -7,6 +7,7 @@ #include #include "common/common_types.h" +#include "core/hle/service/nvdrv/core/container.h" #include "core/hle/service/nvdrv/nvdata.h" namespace Core { @@ -62,7 +63,7 @@ public: * Called once a device is opened * @param fd The device fd */ - virtual void OnOpen(size_t session_id, DeviceFD fd) = 0; + virtual void OnOpen(NvCore::SessionId session_id, DeviceFD fd) = 0; /** * Called once a device is closed diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp index f1404b9dad..c1ebbd62d4 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp @@ -35,7 +35,7 @@ NvResult nvdisp_disp0::Ioctl3(DeviceFD fd, Ioctl command, std::span in return NvResult::NotImplemented; } -void nvdisp_disp0::OnOpen(size_t session_id, DeviceFD fd) {} +void nvdisp_disp0::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {} void nvdisp_disp0::OnClose(DeviceFD fd) {} void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, android::PixelFormat format, u32 width, diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h index 4e32ec1919..5f13a50a2b 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h @@ -32,7 +32,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; /// Performs a screen flip, drawing the buffer pointed to by the handle. diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 936b93bd95..e6646ba046 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -86,7 +86,7 @@ NvResult nvhost_as_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span i return NvResult::NotImplemented; } -void nvhost_as_gpu::OnOpen(size_t session_id, DeviceFD fd) {} +void nvhost_as_gpu::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {} void nvhost_as_gpu::OnClose(DeviceFD fd) {} NvResult nvhost_as_gpu::AllocAsEx(IoctlAllocAsEx& params) { diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index 7fd704bce2..7d0a999888 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h @@ -55,7 +55,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; Kernel::KEvent* QueryEvent(u32 event_id) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp index c4033cf1bb..250d01de3b 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp @@ -76,7 +76,7 @@ NvResult nvhost_ctrl::Ioctl3(DeviceFD fd, Ioctl command, std::span inp return NvResult::NotImplemented; } -void nvhost_ctrl::OnOpen(size_t session_id, DeviceFD fd) {} +void nvhost_ctrl::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {} void nvhost_ctrl::OnClose(DeviceFD fd) {} diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h index 84f419f16b..403f1a7462 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h @@ -32,7 +32,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; Kernel::KEvent* QueryEvent(u32 event_id) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp index 75276c37c9..ddd85678b2 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp @@ -82,7 +82,7 @@ NvResult nvhost_ctrl_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span return NvResult::NotImplemented; } -void nvhost_ctrl_gpu::OnOpen(size_t session_id, DeviceFD fd) {} +void nvhost_ctrl_gpu::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {} void nvhost_ctrl_gpu::OnClose(DeviceFD fd) {} NvResult nvhost_ctrl_gpu::GetCharacteristics1(IoctlCharacteristics& params) { diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h index 6147e37cc8..d2ab05b214 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h @@ -28,7 +28,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; Kernel::KEvent* QueryEvent(u32 event_id) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index 0929c71282..bf12d69a5d 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp @@ -120,7 +120,7 @@ NvResult nvhost_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span inpu return NvResult::NotImplemented; } -void nvhost_gpu::OnOpen(size_t session_id, DeviceFD fd) {} +void nvhost_gpu::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {} void nvhost_gpu::OnClose(DeviceFD fd) {} NvResult nvhost_gpu::SetNVMAPfd(IoctlSetNvmapFD& params) { diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h index f5a396c402..e34a978db0 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h @@ -47,7 +47,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; Kernel::KEvent* QueryEvent(u32 event_id) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp index 63228518ef..2c0ac2a46e 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp @@ -68,7 +68,7 @@ NvResult nvhost_nvdec::Ioctl3(DeviceFD fd, Ioctl command, std::span in return NvResult::NotImplemented; } -void nvhost_nvdec::OnOpen(size_t session_id, DeviceFD fd) { +void nvhost_nvdec::OnOpen(NvCore::SessionId session_id, DeviceFD fd) { LOG_INFO(Service_NVDRV, "NVDEC video stream started"); system.SetNVDECActive(true); sessions[fd] = session_id; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h index 1fb27b8147..627686757b 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h @@ -20,7 +20,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; }; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h index 718e0fecd2..900db81d27 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h @@ -127,7 +127,7 @@ protected: NvCore::NvMap& nvmap; NvCore::ChannelType channel_type; std::array device_syncpoints{}; - std::unordered_map sessions; + std::unordered_map sessions; }; }; // namespace Devices } // namespace Service::Nvidia diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp index 1c88b39abf..f87d53f12c 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp @@ -44,7 +44,7 @@ NvResult nvhost_nvjpg::Ioctl3(DeviceFD fd, Ioctl command, std::span in return NvResult::NotImplemented; } -void nvhost_nvjpg::OnOpen(size_t session_id, DeviceFD fd) {} +void nvhost_nvjpg::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {} void nvhost_nvjpg::OnClose(DeviceFD fd) {} NvResult nvhost_nvjpg::SetNVMAPfd(IoctlSetNvmapFD& params) { diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h index 3e33dffef8..def9c254d1 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h @@ -22,7 +22,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; private: diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp index a27bed29bb..263061f1da 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp @@ -68,7 +68,7 @@ NvResult nvhost_vic::Ioctl3(DeviceFD fd, Ioctl command, std::span inpu return NvResult::NotImplemented; } -void nvhost_vic::OnOpen(size_t session_id, DeviceFD fd) { +void nvhost_vic::OnOpen(NvCore::SessionId session_id, DeviceFD fd) { sessions[fd] = session_id; } diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.h b/src/core/hle/service/nvdrv/devices/nvhost_vic.h index d70df0f20d..0cc04354a0 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_vic.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.h @@ -19,7 +19,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; }; } // namespace Service::Nvidia::Devices diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index 08ee8ec249..da61a3bfeb 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp @@ -67,7 +67,7 @@ NvResult nvmap::Ioctl3(DeviceFD fd, Ioctl command, std::span input, st return NvResult::NotImplemented; } -void nvmap::OnOpen(size_t session_id, DeviceFD fd) { +void nvmap::OnOpen(NvCore::SessionId session_id, DeviceFD fd) { sessions[fd] = session_id; } void nvmap::OnClose(DeviceFD fd) { diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index ea5df2a9c5..d07d85f888 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h @@ -33,7 +33,7 @@ public: NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::span output, std::span inline_output) override; - void OnOpen(size_t session_id, DeviceFD fd) override; + void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override; void OnClose(DeviceFD fd) override; enum class HandleParameterType : u32_le { @@ -115,7 +115,7 @@ private: NvCore::Container& container; NvCore::NvMap& file; - std::unordered_map sessions; + std::unordered_map sessions; }; } // namespace Service::Nvidia::Devices diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index 5191341db7..5f093c0d4b 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -122,7 +122,7 @@ NvResult Module::VerifyFD(DeviceFD fd) const { return NvResult::Success; } -DeviceFD Module::Open(const std::string& device_name, size_t session_id) { +DeviceFD Module::Open(const std::string& device_name, NvCore::SessionId session_id) { auto it = builders.find(device_name); if (it == builders.end()) { LOG_ERROR(Service_NVDRV, "Trying to open unknown device {}", device_name); diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h index d7648fb155..c594f0e5e1 100644 --- a/src/core/hle/service/nvdrv/nvdrv.h +++ b/src/core/hle/service/nvdrv/nvdrv.h @@ -77,7 +77,7 @@ public: NvResult VerifyFD(DeviceFD fd) const; /// Opens a device node and returns a file descriptor to it. - DeviceFD Open(const std::string& device_name, size_t session_id); + DeviceFD Open(const std::string& device_name, NvCore::SessionId session_id); /// Sends an ioctl command to the specified file descriptor. NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::span output); diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.h b/src/core/hle/service/nvdrv/nvdrv_interface.h index e7237c881c..f2195ae1e1 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.h +++ b/src/core/hle/service/nvdrv/nvdrv_interface.h @@ -35,7 +35,7 @@ private: u64 pid{}; bool is_initialized{}; - size_t session_id{}; + NvCore::SessionId session_id{}; Common::ScratchBuffer output_buffer; Common::ScratchBuffer inline_output_buffer; }; diff --git a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h index d2ec7a9b9b..033bf4bbe3 100644 --- a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h +++ b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.h @@ -4,6 +4,7 @@ #pragma once #include "common/math_util.h" +#include "core/hle/service/nvdrv/core/container.h" #include "core/hle/service/nvdrv/nvdata.h" #include "core/hle/service/nvnflinger/nvnflinger.h" #include "core/hle/service/nvnflinger/ui/fence.h" @@ -55,7 +56,7 @@ private: u32 m_buffer_nvmap_handle = 0; SharedMemoryPoolLayout m_pool_layout = {}; Nvidia::DeviceFD m_nvmap_fd = {}; - size_t m_session_id = {}; + Nvidia::NvCore::SessionId m_session_id = {}; std::unique_ptr m_buffer_page_group; std::mutex m_guard; diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index e4b38ae0bc..423b9aef1f 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp @@ -126,7 +126,7 @@ void Nvnflinger::ShutdownLayers() { void Nvnflinger::SetNVDrvInstance(std::shared_ptr instance) { nvdrv = std::move(instance); - disp_fd = nvdrv->Open("/dev/nvdisp_disp0", 0); + disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {}); } std::optional Nvnflinger::OpenDisplay(std::string_view name) {