device_memory.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/assert.h"
  6. #include "common/common_funcs.h"
  7. #include "common/virtual_buffer.h"
  8. namespace Core {
  9. class System;
  10. namespace DramMemoryMap {
  11. enum : u64 {
  12. Base = 0x80000000ULL,
  13. Size = 0x100000000ULL,
  14. End = Base + Size,
  15. KernelReserveBase = Base + 0x60000,
  16. SlabHeapBase = KernelReserveBase + 0x85000,
  17. SlapHeapSize = 0xa21000,
  18. SlabHeapEnd = SlabHeapBase + SlapHeapSize,
  19. };
  20. }; // namespace DramMemoryMap
  21. class DeviceMemory : NonCopyable {
  22. public:
  23. explicit DeviceMemory(Core::System& system);
  24. ~DeviceMemory();
  25. template <typename T>
  26. PAddr GetPhysicalAddr(const T* ptr) const {
  27. return (reinterpret_cast<uintptr_t>(ptr) - reinterpret_cast<uintptr_t>(buffer.data())) +
  28. DramMemoryMap::Base;
  29. }
  30. u8* GetPointer(PAddr addr) {
  31. return buffer.data() + (addr - DramMemoryMap::Base);
  32. }
  33. const u8* GetPointer(PAddr addr) const {
  34. return buffer.data() + (addr - DramMemoryMap::Base);
  35. }
  36. private:
  37. Common::VirtualBuffer<u8> buffer;
  38. Core::System& system;
  39. };
  40. } // namespace Core