Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "internal/sys.hpp" |
Patrick Venture | d6b337e | 2021-04-16 14:37:57 -0700 | [diff] [blame] | 4 | #include "io_interface.hpp" |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 5 | |
| 6 | #include <cstdint> |
| 7 | #include <string> |
| 8 | |
| 9 | namespace host_tool |
| 10 | { |
| 11 | |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 12 | class DevMemDevice : public HostIoInterface |
| 13 | { |
| 14 | public: |
| 15 | explicit DevMemDevice(const internal::Sys* sys = &internal::sys_impl) : |
| 16 | sys(sys) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 17 | {} |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 18 | |
Patrick Venture | 18bbe3c | 2019-05-14 11:40:57 -0700 | [diff] [blame] | 19 | ~DevMemDevice() = default; |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 20 | |
Brandon Kim | cbf4740 | 2019-11-26 17:27:47 -0800 | [diff] [blame] | 21 | /* Don't allow copying, assignment or move assignment, only moving. */ |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 22 | DevMemDevice(const DevMemDevice&) = delete; |
| 23 | DevMemDevice& operator=(const DevMemDevice&) = delete; |
| 24 | DevMemDevice(DevMemDevice&&) = default; |
Brandon Kim | cbf4740 | 2019-11-26 17:27:47 -0800 | [diff] [blame] | 25 | DevMemDevice& operator=(DevMemDevice&&) = delete; |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 26 | |
Patrick Venture | ac4ff97 | 2019-05-03 17:35:00 -0700 | [diff] [blame] | 27 | bool read(const std::size_t offset, const std::size_t length, |
| 28 | void* const destination) override; |
| 29 | |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 30 | 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 Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 35 | int devMemFd = -1; |
| 36 | void* devMemMapped = nullptr; |
| 37 | const internal::Sys* sys; |
| 38 | }; |
| 39 | |
Brandon Kim | 286cc6a | 2019-11-05 16:39:47 -0800 | [diff] [blame] | 40 | class PpcMemDevice : public HostIoInterface |
| 41 | { |
| 42 | public: |
Rui Zhang | d8515a6 | 2020-03-24 16:46:44 -0700 | [diff] [blame] | 43 | explicit PpcMemDevice(const std::string& ppcMemPath, |
Brandon Kim | 286cc6a | 2019-11-05 16:39:47 -0800 | [diff] [blame] | 44 | const internal::Sys* sys = &internal::sys_impl) : |
| 45 | ppcMemPath(ppcMemPath), |
| 46 | sys(sys) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 47 | {} |
Brandon Kim | 286cc6a | 2019-11-05 16:39:47 -0800 | [diff] [blame] | 48 | |
| 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 Venture | ea0e470 | 2020-10-05 12:22:59 -0700 | [diff] [blame] | 64 | void close(); |
| 65 | |
Brandon Kim | 286cc6a | 2019-11-05 16:39:47 -0800 | [diff] [blame] | 66 | int ppcMemFd = -1; |
| 67 | const std::string ppcMemPath; |
| 68 | const internal::Sys* sys; |
| 69 | }; |
| 70 | |
Patrick Venture | 030b1a8 | 2019-01-18 08:33:02 -0800 | [diff] [blame] | 71 | } // namespace host_tool |