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 typedef uint32_t (*address_space_device_gen_handle_t)(void); 23 typedef void (*address_space_device_destroy_handle_t)(uint32_t); 24 typedef void (*address_space_device_tell_ping_info_t)(uint32_t handle, uint64_t gpa); 25 typedef void (*address_space_device_ping_t)(uint32_t handle); 26 typedef int (*address_space_device_add_memory_mapping_t)(uint64_t gpa, void *ptr, uint64_t size); 27 typedef int (*address_space_device_remove_memory_mapping_t)(uint64_t gpa, void *ptr, uint64_t size); 28 typedef void* (*address_space_device_get_host_ptr_t)(uint64_t gpa); 29 typedef void* (*address_space_device_handle_to_context_t)(uint32_t handle); 30 typedef void (*address_space_device_clear_t)(void); 31 // virtio-gpu-next 32 typedef uint64_t (*address_space_device_hostmem_register_t)(uint64_t hva, uint64_t size, uint32_t register_fixed, uint64_t fixed_id); 33 typedef void (*address_space_device_hostmem_unregister_t)(uint64_t id); 34 typedef void (*address_space_device_ping_at_hva_t)(uint32_t handle, void* hva); 35 // deallocation callbacks 36 typedef void (*address_space_device_deallocation_callback_t)(void* context, uint64_t gpa); 37 typedef void (*address_space_device_register_deallocation_callback_t)(void* context, uint64_t gpa, address_space_device_deallocation_callback_t); 38 typedef void (*address_space_device_run_deallocation_callbacks_t)(uint64_t gpa); 39 typedef const struct AddressSpaceHwFuncs* (*address_space_device_control_get_hw_funcs_t)(void); 40 41 struct address_space_device_control_ops { 42 address_space_device_gen_handle_t gen_handle; 43 address_space_device_destroy_handle_t destroy_handle; 44 address_space_device_tell_ping_info_t tell_ping_info; 45 address_space_device_ping_t ping; 46 address_space_device_add_memory_mapping_t add_memory_mapping; 47 address_space_device_remove_memory_mapping_t remove_memory_mapping; 48 address_space_device_get_host_ptr_t get_host_ptr; 49 address_space_device_handle_to_context_t handle_to_context; 50 address_space_device_clear_t clear; 51 address_space_device_hostmem_register_t hostmem_register; 52 address_space_device_hostmem_unregister_t hostmem_unregister; 53 address_space_device_ping_at_hva_t ping_at_hva; 54 address_space_device_register_deallocation_callback_t register_deallocation_callback; 55 address_space_device_run_deallocation_callbacks_t run_deallocation_callbacks; 56 address_space_device_control_get_hw_funcs_t control_get_hw_funcs; 57 }; 58 59 struct address_space_device_control_ops* 60 get_address_space_device_control_ops(void); 61 62 struct QAndroidVmOperations; 63 void address_space_set_vm_operations(const QAndroidVmOperations* vmops); 64 65 struct AddressSpaceHwFuncs { 66 /* Called by the host to reserve a shared region. Guest users can then 67 * suballocate into this region. This saves us a lot of KVM slots. 68 * Returns the relative offset to the starting phys addr in |offset| 69 * and returns 0 if successful, -errno otherwise. */ 70 int (*allocSharedHostRegion)(uint64_t page_aligned_size, uint64_t* offset); 71 /* Called by the host to free a shared region. Only useful on teardown 72 * or when loading a snapshot while the emulator is running. 73 * Returns 0 if successful, -errno otherwise. */ 74 int (*freeSharedHostRegion)(uint64_t offset); 75 76 /* Versions of the above but when the state is already locked. */ 77 int (*allocSharedHostRegionLocked)(uint64_t page_aligned_size, uint64_t* offset); 78 int (*freeSharedHostRegionLocked)(uint64_t offset); 79 80 /* Obtains the starting physical address for which the resulting offsets 81 * are relative to. */ 82 uint64_t (*getPhysAddrStart)(void); 83 uint64_t (*getPhysAddrStartLocked)(void); 84 85 /* Version of allocSharedHostRegionLocked but for a fixed offset */ 86 int (*allocSharedHostRegionFixedLocked)(uint64_t page_aligned_size, uint64_t offset); 87 }; 88 89 extern const struct AddressSpaceHwFuncs* address_space_set_hw_funcs( 90 const struct AddressSpaceHwFuncs* hwFuncs); 91 const struct AddressSpaceHwFuncs* get_address_space_device_hw_funcs(void); 92 93 } // extern "C" 94