1 // Copyright 2019 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #include <inttypes.h> 17 18 extern "C" { 19 20 struct AddressSpaceHwFuncs; 21 22 struct AddressSpaceCreateInfo { 23 uint32_t handle; 24 uint32_t type; 25 uint64_t physAddr; 26 bool fromSnapshot; 27 bool createRenderThread; 28 void *externalAddr; 29 uint64_t externalAddrSize; 30 uint32_t virtioGpuContextId; 31 uint32_t virtioGpuCapsetId; 32 const char *contextName; 33 uint32_t contextNameSize; 34 }; 35 36 typedef uint32_t (*address_space_device_gen_handle_t)(void); 37 typedef void (*address_space_device_destroy_handle_t)(uint32_t); 38 typedef void (*address_space_device_create_instance_t)(const struct AddressSpaceCreateInfo& create); 39 typedef void (*address_space_device_tell_ping_info_t)(uint32_t handle, uint64_t gpa); 40 typedef void (*address_space_device_ping_t)(uint32_t handle); 41 typedef int (*address_space_device_add_memory_mapping_t)(uint64_t gpa, void *ptr, uint64_t size); 42 typedef int (*address_space_device_remove_memory_mapping_t)(uint64_t gpa, void *ptr, uint64_t size); 43 typedef void* (*address_space_device_get_host_ptr_t)(uint64_t gpa); 44 typedef void* (*address_space_device_handle_to_context_t)(uint32_t handle); 45 typedef void (*address_space_device_clear_t)(void); 46 // virtio-gpu-next 47 typedef uint64_t (*address_space_device_hostmem_register_t)(const struct MemEntry *entry); 48 typedef void (*address_space_device_hostmem_unregister_t)(uint64_t id); 49 typedef void (*address_space_device_ping_at_hva_t)(uint32_t handle, void* hva); 50 // deallocation callbacks 51 typedef void (*address_space_device_deallocation_callback_t)(void* context, uint64_t gpa); 52 typedef void (*address_space_device_register_deallocation_callback_t)(void* context, uint64_t gpa, address_space_device_deallocation_callback_t); 53 typedef void (*address_space_device_run_deallocation_callbacks_t)(uint64_t gpa); 54 typedef const struct AddressSpaceHwFuncs* (*address_space_device_control_get_hw_funcs_t)(void); 55 56 struct address_space_device_control_ops { 57 address_space_device_gen_handle_t gen_handle; 58 address_space_device_destroy_handle_t destroy_handle; 59 address_space_device_tell_ping_info_t tell_ping_info; 60 address_space_device_ping_t ping; 61 address_space_device_add_memory_mapping_t add_memory_mapping; 62 address_space_device_remove_memory_mapping_t remove_memory_mapping; 63 address_space_device_get_host_ptr_t get_host_ptr; 64 address_space_device_handle_to_context_t handle_to_context; 65 address_space_device_clear_t clear; 66 address_space_device_hostmem_register_t hostmem_register; 67 address_space_device_hostmem_unregister_t hostmem_unregister; 68 address_space_device_ping_at_hva_t ping_at_hva; 69 address_space_device_register_deallocation_callback_t register_deallocation_callback; 70 address_space_device_run_deallocation_callbacks_t run_deallocation_callbacks; 71 address_space_device_control_get_hw_funcs_t control_get_hw_funcs; 72 address_space_device_create_instance_t create_instance; 73 }; 74 75 struct address_space_device_control_ops* 76 get_address_space_device_control_ops(void); 77 78 struct QAndroidVmOperations; 79 void address_space_set_vm_operations(const QAndroidVmOperations* vmops); 80 81 struct AddressSpaceHwFuncs { 82 /* Called by the host to reserve a shared region. Guest users can then 83 * suballocate into this region. This saves us a lot of KVM slots. 84 * Returns the relative offset to the starting phys addr in |offset| 85 * and returns 0 if successful, -errno otherwise. */ 86 int (*allocSharedHostRegion)(uint64_t page_aligned_size, uint64_t* offset); 87 /* Called by the host to free a shared region. Only useful on teardown 88 * or when loading a snapshot while the emulator is running. 89 * Returns 0 if successful, -errno otherwise. */ 90 int (*freeSharedHostRegion)(uint64_t offset); 91 92 /* Versions of the above but when the state is already locked. */ 93 int (*allocSharedHostRegionLocked)(uint64_t page_aligned_size, uint64_t* offset); 94 int (*freeSharedHostRegionLocked)(uint64_t offset); 95 96 /* Obtains the starting physical address for which the resulting offsets 97 * are relative to. */ 98 uint64_t (*getPhysAddrStart)(void); 99 uint64_t (*getPhysAddrStartLocked)(void); 100 uint32_t (*getGuestPageSize)(void); 101 102 /* Version of allocSharedHostRegionLocked but for a fixed offset */ 103 int (*allocSharedHostRegionFixedLocked)(uint64_t page_aligned_size, uint64_t offset); 104 }; 105 106 extern const struct AddressSpaceHwFuncs* address_space_set_hw_funcs( 107 const struct AddressSpaceHwFuncs* hwFuncs); 108 const struct AddressSpaceHwFuncs* get_address_space_device_hw_funcs(void); 109 110 } // extern "C" 111