blob: 7301e5f5a8eec2abe7903c50c13c89d55fb4ddea [file] [log] [blame]
Patrick Venture030b1a82019-01-18 08:33:02 -08001#pragma once
2
3#include "internal/sys.hpp"
Patrick Ventured6b337e2021-04-16 14:37:57 -07004#include "io_interface.hpp"
Patrick Venture030b1a82019-01-18 08:33:02 -08005
6#include <cstdint>
7#include <string>
8
9namespace host_tool
10{
11
Patrick Venture030b1a82019-01-18 08:33:02 -080012class DevMemDevice : public HostIoInterface
13{
14 public:
15 explicit DevMemDevice(const internal::Sys* sys = &internal::sys_impl) :
16 sys(sys)
Patrick Venture9b37b092020-05-28 20:58:57 -070017 {}
Patrick Venture030b1a82019-01-18 08:33:02 -080018
Patrick Venture18bbe3c2019-05-14 11:40:57 -070019 ~DevMemDevice() = default;
Patrick Venture030b1a82019-01-18 08:33:02 -080020
Brandon Kimcbf47402019-11-26 17:27:47 -080021 /* Don't allow copying, assignment or move assignment, only moving. */
Patrick Venture030b1a82019-01-18 08:33:02 -080022 DevMemDevice(const DevMemDevice&) = delete;
23 DevMemDevice& operator=(const DevMemDevice&) = delete;
24 DevMemDevice(DevMemDevice&&) = default;
Brandon Kimcbf47402019-11-26 17:27:47 -080025 DevMemDevice& operator=(DevMemDevice&&) = delete;
Patrick Venture030b1a82019-01-18 08:33:02 -080026
Patrick Ventureac4ff972019-05-03 17:35:00 -070027 bool read(const std::size_t offset, const std::size_t length,
28 void* const destination) override;
29
Patrick Venture030b1a82019-01-18 08:33:02 -080030 bool write(const std::size_t offset, const std::size_t length,
31 const void* const source) override;
32
33 private:
34 static const std::string devMemPath;
Patrick Venture030b1a82019-01-18 08:33:02 -080035 int devMemFd = -1;
36 void* devMemMapped = nullptr;
37 const internal::Sys* sys;
38};
39
Brandon Kim286cc6a2019-11-05 16:39:47 -080040class PpcMemDevice : public HostIoInterface
41{
42 public:
Rui Zhangd8515a62020-03-24 16:46:44 -070043 explicit PpcMemDevice(const std::string& ppcMemPath,
Brandon Kim286cc6a2019-11-05 16:39:47 -080044 const internal::Sys* sys = &internal::sys_impl) :
Patrick Williams42a44c22024-08-16 15:21:32 -040045 ppcMemPath(ppcMemPath), sys(sys)
Patrick Venture9b37b092020-05-28 20:58:57 -070046 {}
Brandon Kim286cc6a2019-11-05 16:39:47 -080047
48 ~PpcMemDevice() override;
49
50 /* Don't allow copying or assignment, only moving. */
51 PpcMemDevice(const PpcMemDevice&) = delete;
52 PpcMemDevice& operator=(const PpcMemDevice&) = delete;
53 PpcMemDevice(PpcMemDevice&&) = default;
54 PpcMemDevice& operator=(PpcMemDevice&&) = default;
55
56 bool read(const std::size_t offset, const std::size_t length,
57 void* const destination) override;
58
59 bool write(const std::size_t offset, const std::size_t length,
60 const void* const source) override;
61
62 private:
Patrick Ventureea0e4702020-10-05 12:22:59 -070063 void close();
64
Brandon Kim286cc6a2019-11-05 16:39:47 -080065 int ppcMemFd = -1;
66 const std::string ppcMemPath;
67 const internal::Sys* sys;
68};
69
Patrick Venture030b1a82019-01-18 08:33:02 -080070} // namespace host_tool