Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 Google, Inc. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef ANDROID_INCLUDE_HARDWARE_GOLDFISH_ADDRESS_SPACE_H |
| 16 | #define ANDROID_INCLUDE_HARDWARE_GOLDFISH_ADDRESS_SPACE_H |
| 17 | |
| 18 | #include <inttypes.h> |
David Reveman | 74e99bb | 2019-02-15 18:47:25 -0500 | [diff] [blame] | 19 | #include <stddef.h> |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 20 | |
| 21 | class GoldfishAddressSpaceBlock; |
| 22 | |
Lingfeng Yang | c08fbfb | 2018-12-05 21:05:17 -0800 | [diff] [blame] | 23 | #ifdef HOST_BUILD |
Lingfeng Yang | a963ea0 | 2019-03-21 21:27:04 -0700 | [diff] [blame] | 24 | class GoldfishAddressSpaceBlockProvider { |
| 25 | public: |
| 26 | GoldfishAddressSpaceBlockProvider(); |
| 27 | ~GoldfishAddressSpaceBlockProvider(); |
| 28 | |
| 29 | uint64_t allocPhys(size_t size); |
| 30 | void freePhys(uint64_t phys); |
| 31 | |
| 32 | private: |
| 33 | void* mAlloc; |
| 34 | |
| 35 | friend class GoldfishAddressSpaceBlock; |
| 36 | }; |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 37 | #else |
| 38 | class GoldfishAddressSpaceBlockProvider { |
| 39 | public: |
| 40 | GoldfishAddressSpaceBlockProvider(); |
| 41 | ~GoldfishAddressSpaceBlockProvider(); |
| 42 | |
| 43 | private: |
| 44 | GoldfishAddressSpaceBlockProvider(const GoldfishAddressSpaceBlockProvider &rhs); |
| 45 | GoldfishAddressSpaceBlockProvider &operator=(const GoldfishAddressSpaceBlockProvider &rhs); |
| 46 | |
| 47 | bool is_opened(); |
David Reveman | 397f568 | 2019-04-08 11:30:05 -0400 | [diff] [blame^] | 48 | #ifdef __Fuchsia__ |
| 49 | uint32_t m_channel; |
| 50 | #else |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 51 | int m_fd; |
David Reveman | 397f568 | 2019-04-08 11:30:05 -0400 | [diff] [blame^] | 52 | #endif |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 53 | |
| 54 | friend class GoldfishAddressSpaceBlock; |
| 55 | }; |
| 56 | #endif |
| 57 | |
| 58 | class GoldfishAddressSpaceBlock { |
| 59 | public: |
| 60 | GoldfishAddressSpaceBlock(); |
| 61 | ~GoldfishAddressSpaceBlock(); |
| 62 | |
| 63 | bool allocate(GoldfishAddressSpaceBlockProvider *provider, size_t size); |
| 64 | uint64_t physAddr() const; |
| 65 | uint64_t hostAddr() const; |
| 66 | void *mmap(uint64_t opaque); |
| 67 | void *guestPtr() const; |
| 68 | void replace(GoldfishAddressSpaceBlock *x); |
| 69 | |
| 70 | private: |
| 71 | void destroy(); |
| 72 | GoldfishAddressSpaceBlock &operator=(const GoldfishAddressSpaceBlock &); |
| 73 | |
Lingfeng Yang | c08fbfb | 2018-12-05 21:05:17 -0800 | [diff] [blame] | 74 | #ifdef HOST_BUILD |
Lingfeng Yang | a963ea0 | 2019-03-21 21:27:04 -0700 | [diff] [blame] | 75 | bool m_alloced; |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 76 | void *m_guest_ptr; |
Lingfeng Yang | a963ea0 | 2019-03-21 21:27:04 -0700 | [diff] [blame] | 77 | uint64_t m_phys_addr; |
| 78 | GoldfishAddressSpaceBlockProvider* m_provider; |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 79 | #else |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 80 | #ifdef __Fuchsia__ |
| 81 | uint32_t m_vmo; |
David Reveman | 397f568 | 2019-04-08 11:30:05 -0400 | [diff] [blame^] | 82 | uint32_t m_channel; |
| 83 | #else |
| 84 | int m_fd; |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 85 | #endif |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 86 | void *m_mmaped_ptr; |
| 87 | uint64_t m_phys_addr; |
| 88 | uint64_t m_host_addr; |
| 89 | uint64_t m_offset; |
| 90 | size_t m_size; |
Roman Kiryanov | daecd14 | 2018-11-14 14:56:27 -0800 | [diff] [blame] | 91 | #endif |
| 92 | }; |
| 93 | |
| 94 | #endif |