diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2022-10-21 00:07:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 00:07:30 +0200 |
commit | a6628e8dba0432031a5bc470e5716c831128a357 (patch) | |
tree | 533eef88596325c5f14b3caf5350cb9a09265afa /src/core/hle/kernel/k_session_request.cpp | |
parent | Merge pull request #9099 from Docteh/undocked (diff) | |
parent | kernel: remove most SessionRequestManager handling from KServerSession (diff) | |
download | yuzu-a6628e8dba0432031a5bc470e5716c831128a357.tar yuzu-a6628e8dba0432031a5bc470e5716c831128a357.tar.gz yuzu-a6628e8dba0432031a5bc470e5716c831128a357.tar.bz2 yuzu-a6628e8dba0432031a5bc470e5716c831128a357.tar.lz yuzu-a6628e8dba0432031a5bc470e5716c831128a357.tar.xz yuzu-a6628e8dba0432031a5bc470e5716c831128a357.tar.zst yuzu-a6628e8dba0432031a5bc470e5716c831128a357.zip |
Diffstat (limited to 'src/core/hle/kernel/k_session_request.cpp')
-rw-r--r-- | src/core/hle/kernel/k_session_request.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_session_request.cpp b/src/core/hle/kernel/k_session_request.cpp new file mode 100644 index 000000000..520da6aa7 --- /dev/null +++ b/src/core/hle/kernel/k_session_request.cpp @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/kernel/k_page_buffer.h" +#include "core/hle/kernel/k_session_request.h" + +namespace Kernel { + +Result KSessionRequest::SessionMappings::PushMap(VAddr client, VAddr server, size_t size, + KMemoryState state, size_t index) { + // At most 15 buffers of each type (4-bit descriptor counts). + ASSERT(index < ((1ul << 4) - 1) * 3); + + // Get the mapping. + Mapping* mapping; + if (index < NumStaticMappings) { + mapping = &m_static_mappings[index]; + } else { + // Allocate a page for the extra mappings. + if (m_mappings == nullptr) { + KPageBuffer* page_buffer = KPageBuffer::Allocate(kernel); + R_UNLESS(page_buffer != nullptr, ResultOutOfMemory); + + m_mappings = reinterpret_cast<Mapping*>(page_buffer); + } + + mapping = &m_mappings[index - NumStaticMappings]; + } + + // Set the mapping. + mapping->Set(client, server, size, state); + + return ResultSuccess; +} + +Result KSessionRequest::SessionMappings::PushSend(VAddr client, VAddr server, size_t size, + KMemoryState state) { + ASSERT(m_num_recv == 0); + ASSERT(m_num_exch == 0); + return this->PushMap(client, server, size, state, m_num_send++); +} + +Result KSessionRequest::SessionMappings::PushReceive(VAddr client, VAddr server, size_t size, + KMemoryState state) { + ASSERT(m_num_exch == 0); + return this->PushMap(client, server, size, state, m_num_send + m_num_recv++); +} + +Result KSessionRequest::SessionMappings::PushExchange(VAddr client, VAddr server, size_t size, + KMemoryState state) { + return this->PushMap(client, server, size, state, m_num_send + m_num_recv + m_num_exch++); +} + +void KSessionRequest::SessionMappings::Finalize() { + if (m_mappings) { + KPageBuffer::Free(kernel, reinterpret_cast<KPageBuffer*>(m_mappings)); + m_mappings = nullptr; + } +} + +} // namespace Kernel |