k_session_request.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/hle/kernel/k_page_buffer.h"
  4. #include "core/hle/kernel/k_session_request.h"
  5. namespace Kernel {
  6. Result KSessionRequest::SessionMappings::PushMap(VAddr client, VAddr server, size_t size,
  7. KMemoryState state, size_t index) {
  8. // At most 15 buffers of each type (4-bit descriptor counts).
  9. ASSERT(index < ((1ul << 4) - 1) * 3);
  10. // Get the mapping.
  11. Mapping* mapping;
  12. if (index < NumStaticMappings) {
  13. mapping = &m_static_mappings[index];
  14. } else {
  15. // Allocate a page for the extra mappings.
  16. if (m_mappings == nullptr) {
  17. KPageBuffer* page_buffer = KPageBuffer::Allocate(kernel);
  18. R_UNLESS(page_buffer != nullptr, ResultOutOfMemory);
  19. m_mappings = reinterpret_cast<Mapping*>(page_buffer);
  20. }
  21. mapping = &m_mappings[index - NumStaticMappings];
  22. }
  23. // Set the mapping.
  24. mapping->Set(client, server, size, state);
  25. return ResultSuccess;
  26. }
  27. Result KSessionRequest::SessionMappings::PushSend(VAddr client, VAddr server, size_t size,
  28. KMemoryState state) {
  29. ASSERT(m_num_recv == 0);
  30. ASSERT(m_num_exch == 0);
  31. return this->PushMap(client, server, size, state, m_num_send++);
  32. }
  33. Result KSessionRequest::SessionMappings::PushReceive(VAddr client, VAddr server, size_t size,
  34. KMemoryState state) {
  35. ASSERT(m_num_exch == 0);
  36. return this->PushMap(client, server, size, state, m_num_send + m_num_recv++);
  37. }
  38. Result KSessionRequest::SessionMappings::PushExchange(VAddr client, VAddr server, size_t size,
  39. KMemoryState state) {
  40. return this->PushMap(client, server, size, state, m_num_send + m_num_recv + m_num_exch++);
  41. }
  42. void KSessionRequest::SessionMappings::Finalize() {
  43. if (m_mappings) {
  44. KPageBuffer::Free(kernel, reinterpret_cast<KPageBuffer*>(m_mappings));
  45. m_mappings = nullptr;
  46. }
  47. }
  48. } // namespace Kernel