device_memory.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/common_types.h"
  6. #include "common/virtual_buffer.h"
  7. namespace Core {
  8. namespace DramMemoryMap {
  9. enum : u64 {
  10. Base = 0x80000000ULL,
  11. Size = 0x100000000ULL,
  12. End = Base + Size,
  13. KernelReserveBase = Base + 0x60000,
  14. SlabHeapBase = KernelReserveBase + 0x85000,
  15. SlapHeapSize = 0xa21000,
  16. SlabHeapEnd = SlabHeapBase + SlapHeapSize,
  17. };
  18. }; // namespace DramMemoryMap
  19. class DeviceMemory : NonCopyable {
  20. public:
  21. explicit DeviceMemory();
  22. ~DeviceMemory();
  23. template <typename T>
  24. PAddr GetPhysicalAddr(const T* ptr) const {
  25. return (reinterpret_cast<uintptr_t>(ptr) - reinterpret_cast<uintptr_t>(buffer.data())) +
  26. DramMemoryMap::Base;
  27. }
  28. u8* GetPointer(PAddr addr) {
  29. return buffer.data() + (addr - DramMemoryMap::Base);
  30. }
  31. const u8* GetPointer(PAddr addr) const {
  32. return buffer.data() + (addr - DramMemoryMap::Base);
  33. }
  34. private:
  35. Common::VirtualBuffer<u8> buffer;
  36. };
  37. } // namespace Core