1 // Copyright 2023 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 15 #pragma once 16 17 #include <inttypes.h> 18 #include <stddef.h> 19 20 #if defined(__Fuchsia__) 21 typedef void* address_space_handle_t; 22 #else 23 typedef int address_space_handle_t; 24 #endif 25 26 enum AddressSpaceSubdeviceType { 27 NoSubdevice = -1, 28 Graphics = 0, 29 Media = 1, 30 HostMemoryAllocator = 5, 31 SharedSlotsHostMemoryAllocator = 6, 32 VirtioGpuGraphics = 10, 33 }; 34 35 // We also expose the ping info struct that is shared between host and guest. 36 struct address_space_ping { 37 uint64_t offset; 38 uint64_t size; 39 uint64_t metadata; 40 uint32_t resourceId; 41 uint32_t wait_fd; 42 uint32_t wait_flags; 43 uint32_t direction; 44 }; 45 46 // typedef/struct to abstract over goldfish vs virtio-gpu implementations 47 typedef address_space_handle_t (*address_space_open_t)(void); 48 typedef void (*address_space_close_t)(address_space_handle_t); 49 50 typedef bool (*address_space_allocate_t)( 51 address_space_handle_t, size_t size, uint64_t* phys_addr, uint64_t* offset); 52 typedef bool (*address_space_free_t)( 53 address_space_handle_t, uint64_t offset); 54 55 typedef bool (*address_space_claim_shared_t)( 56 address_space_handle_t, uint64_t offset, uint64_t size); 57 typedef bool (*address_space_unclaim_shared_t)( 58 address_space_handle_t, uint64_t offset); 59 60 // pgoff is the offset into the page to return in the result 61 typedef void* (*address_space_map_t)( 62 address_space_handle_t, uint64_t offset, uint64_t size, uint64_t pgoff); 63 typedef void (*address_space_unmap_t)(void* ptr, uint64_t size); 64 65 typedef bool (*address_space_set_subdevice_type_t)( 66 address_space_handle_t, AddressSpaceSubdeviceType type, address_space_handle_t*); 67 typedef bool (*address_space_ping_t)( 68 address_space_handle_t, struct address_space_ping*); 69 70 struct address_space_ops { 71 address_space_open_t open; 72 address_space_close_t close; 73 address_space_claim_shared_t claim_shared; 74 address_space_unclaim_shared_t unclaim_shared; 75 address_space_map_t map; 76 address_space_unmap_t unmap; 77 address_space_set_subdevice_type_t set_subdevice_type; 78 address_space_ping_t ping; 79 }; 80