1030b1a8aSPatrick Venture #pragma once 2030b1a8aSPatrick Venture 3030b1a8aSPatrick Venture #include "internal/sys.hpp" 4*d6b337e6SPatrick Venture #include "io_interface.hpp" 5030b1a8aSPatrick Venture 6030b1a8aSPatrick Venture #include <cstdint> 7030b1a8aSPatrick Venture #include <string> 8030b1a8aSPatrick Venture 9030b1a8aSPatrick Venture namespace host_tool 10030b1a8aSPatrick Venture { 11030b1a8aSPatrick Venture 12030b1a8aSPatrick Venture class DevMemDevice : public HostIoInterface 13030b1a8aSPatrick Venture { 14030b1a8aSPatrick Venture public: DevMemDevice(const internal::Sys * sys=& internal::sys_impl)15030b1a8aSPatrick Venture explicit DevMemDevice(const internal::Sys* sys = &internal::sys_impl) : 16030b1a8aSPatrick Venture sys(sys) 179b37b095SPatrick Venture {} 18030b1a8aSPatrick Venture 1918bbe3c6SPatrick Venture ~DevMemDevice() = default; 20030b1a8aSPatrick Venture 21cbf47404SBrandon Kim /* Don't allow copying, assignment or move assignment, only moving. */ 22030b1a8aSPatrick Venture DevMemDevice(const DevMemDevice&) = delete; 23030b1a8aSPatrick Venture DevMemDevice& operator=(const DevMemDevice&) = delete; 24030b1a8aSPatrick Venture DevMemDevice(DevMemDevice&&) = default; 25cbf47404SBrandon Kim DevMemDevice& operator=(DevMemDevice&&) = delete; 26030b1a8aSPatrick Venture 27ac4ff973SPatrick Venture bool read(const std::size_t offset, const std::size_t length, 28ac4ff973SPatrick Venture void* const destination) override; 29ac4ff973SPatrick Venture 30030b1a8aSPatrick Venture bool write(const std::size_t offset, const std::size_t length, 31030b1a8aSPatrick Venture const void* const source) override; 32030b1a8aSPatrick Venture 33030b1a8aSPatrick Venture private: 34030b1a8aSPatrick Venture static const std::string devMemPath; 35030b1a8aSPatrick Venture int devMemFd = -1; 36030b1a8aSPatrick Venture void* devMemMapped = nullptr; 37030b1a8aSPatrick Venture const internal::Sys* sys; 38030b1a8aSPatrick Venture }; 39030b1a8aSPatrick Venture 40286cc6adSBrandon Kim class PpcMemDevice : public HostIoInterface 41286cc6adSBrandon Kim { 42286cc6adSBrandon Kim public: PpcMemDevice(const std::string & ppcMemPath,const internal::Sys * sys=& internal::sys_impl)43d8515a6cSRui Zhang explicit PpcMemDevice(const std::string& ppcMemPath, 44286cc6adSBrandon Kim const internal::Sys* sys = &internal::sys_impl) : 45286cc6adSBrandon Kim ppcMemPath(ppcMemPath), 46286cc6adSBrandon Kim sys(sys) 479b37b095SPatrick Venture {} 48286cc6adSBrandon Kim 49286cc6adSBrandon Kim ~PpcMemDevice() override; 50286cc6adSBrandon Kim 51286cc6adSBrandon Kim /* Don't allow copying or assignment, only moving. */ 52286cc6adSBrandon Kim PpcMemDevice(const PpcMemDevice&) = delete; 53286cc6adSBrandon Kim PpcMemDevice& operator=(const PpcMemDevice&) = delete; 54286cc6adSBrandon Kim PpcMemDevice(PpcMemDevice&&) = default; 55286cc6adSBrandon Kim PpcMemDevice& operator=(PpcMemDevice&&) = default; 56286cc6adSBrandon Kim 57286cc6adSBrandon Kim bool read(const std::size_t offset, const std::size_t length, 58286cc6adSBrandon Kim void* const destination) override; 59286cc6adSBrandon Kim 60286cc6adSBrandon Kim bool write(const std::size_t offset, const std::size_t length, 61286cc6adSBrandon Kim const void* const source) override; 62286cc6adSBrandon Kim 63286cc6adSBrandon Kim private: 64ea0e470fSPatrick Venture void close(); 65ea0e470fSPatrick Venture 66286cc6adSBrandon Kim int ppcMemFd = -1; 67286cc6adSBrandon Kim const std::string ppcMemPath; 68286cc6adSBrandon Kim const internal::Sys* sys; 69286cc6adSBrandon Kim }; 70286cc6adSBrandon Kim 71030b1a8aSPatrick Venture } // namespace host_tool 72