device_memory.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/host_memory.h"
  5. #include "common/typed_address.h"
  6. namespace Core {
  7. namespace DramMemoryMap {
  8. enum : u64 {
  9. Base = 0x80000000ULL,
  10. KernelReserveBase = Base + 0x60000,
  11. SlabHeapBase = KernelReserveBase + 0x85000,
  12. };
  13. }; // namespace DramMemoryMap
  14. class DeviceMemory {
  15. public:
  16. explicit DeviceMemory();
  17. ~DeviceMemory();
  18. DeviceMemory& operator=(const DeviceMemory&) = delete;
  19. DeviceMemory(const DeviceMemory&) = delete;
  20. template <typename T>
  21. Common::PhysicalAddress GetPhysicalAddr(const T* ptr) const {
  22. return (reinterpret_cast<uintptr_t>(ptr) -
  23. reinterpret_cast<uintptr_t>(buffer.BackingBasePointer())) +
  24. DramMemoryMap::Base;
  25. }
  26. template <typename T>
  27. T* GetPointer(Common::PhysicalAddress addr) {
  28. return reinterpret_cast<T*>(buffer.BackingBasePointer() +
  29. (GetInteger(addr) - DramMemoryMap::Base));
  30. }
  31. template <typename T>
  32. const T* GetPointer(Common::PhysicalAddress addr) const {
  33. return reinterpret_cast<T*>(buffer.BackingBasePointer() +
  34. (GetInteger(addr) - DramMemoryMap::Base));
  35. }
  36. Common::HostMemory buffer;
  37. };
  38. } // namespace Core