blob: 892541845c98898efa6104b194f61390ac75ee4e [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) :
45 ppcMemPath(ppcMemPath),
46 sys(sys)
Patrick Venture9b37b092020-05-28 20:58:57 -070047 {}
Brandon Kim286cc6a2019-11-05 16:39:47 -080048
49 ~PpcMemDevice() override;
50
51 /* Don't allow copying or assignment, only moving. */
52 PpcMemDevice(const PpcMemDevice&) = delete;
53 PpcMemDevice& operator=(const PpcMemDevice&) = delete;
54 PpcMemDevice(PpcMemDevice&&) = default;
55 PpcMemDevice& operator=(PpcMemDevice&&) = default;
56
57 bool read(const std::size_t offset, const std::size_t length,
58 void* const destination) override;
59
60 bool write(const std::size_t offset, const std::size_t length,
61 const void* const source) override;
62
63 private:
Patrick Ventureea0e4702020-10-05 12:22:59 -070064 void close();
65
Brandon Kim286cc6a2019-11-05 16:39:47 -080066 int ppcMemFd = -1;
67 const std::string ppcMemPath;
68 const internal::Sys* sys;
69};
70
Patrick Venture030b1a82019-01-18 08:33:02 -080071} // namespace host_tool