180509c55SSean Christopherson /* 280509c55SSean Christopherson * SGX EPC device 380509c55SSean Christopherson * 480509c55SSean Christopherson * Copyright (C) 2019 Intel Corporation 580509c55SSean Christopherson * 680509c55SSean Christopherson * Authors: 780509c55SSean Christopherson * Sean Christopherson <sean.j.christopherson@intel.com> 880509c55SSean Christopherson * 980509c55SSean Christopherson * This work is licensed under the terms of the GNU GPL, version 2 or later. 1080509c55SSean Christopherson * See the COPYING file in the top-level directory. 1180509c55SSean Christopherson */ 1280509c55SSean Christopherson #ifndef QEMU_SGX_EPC_H 1380509c55SSean Christopherson #define QEMU_SGX_EPC_H 1480509c55SSean Christopherson 1580509c55SSean Christopherson #include "hw/i386/hostmem-epc.h" 1680509c55SSean Christopherson 1780509c55SSean Christopherson #define TYPE_SGX_EPC "sgx-epc" 1880509c55SSean Christopherson #define SGX_EPC(obj) \ 1980509c55SSean Christopherson OBJECT_CHECK(SGXEPCDevice, (obj), TYPE_SGX_EPC) 2080509c55SSean Christopherson #define SGX_EPC_CLASS(oc) \ 2180509c55SSean Christopherson OBJECT_CLASS_CHECK(SGXEPCDeviceClass, (oc), TYPE_SGX_EPC) 2280509c55SSean Christopherson #define SGX_EPC_GET_CLASS(obj) \ 2380509c55SSean Christopherson OBJECT_GET_CLASS(SGXEPCDeviceClass, (obj), TYPE_SGX_EPC) 2480509c55SSean Christopherson 2580509c55SSean Christopherson #define SGX_EPC_ADDR_PROP "addr" 2680509c55SSean Christopherson #define SGX_EPC_SIZE_PROP "size" 2780509c55SSean Christopherson #define SGX_EPC_MEMDEV_PROP "memdev" 2880509c55SSean Christopherson 2980509c55SSean Christopherson /** 3080509c55SSean Christopherson * SGXEPCDevice: 3180509c55SSean Christopherson * @addr: starting guest physical address, where @SGXEPCDevice is mapped. 3280509c55SSean Christopherson * Default value: 0, means that address is auto-allocated. 3380509c55SSean Christopherson * @hostmem: host memory backend providing memory for @SGXEPCDevice 3480509c55SSean Christopherson */ 3580509c55SSean Christopherson typedef struct SGXEPCDevice { 3680509c55SSean Christopherson /* private */ 3780509c55SSean Christopherson DeviceState parent_obj; 3880509c55SSean Christopherson 3980509c55SSean Christopherson /* public */ 4080509c55SSean Christopherson uint64_t addr; 4180509c55SSean Christopherson HostMemoryBackendEpc *hostmem; 4280509c55SSean Christopherson } SGXEPCDevice; 4380509c55SSean Christopherson 44dfce81f1SSean Christopherson /* 45dfce81f1SSean Christopherson * @base: address in guest physical address space where EPC regions start 46dfce81f1SSean Christopherson * @mr: address space container for memory devices 47dfce81f1SSean Christopherson */ 48dfce81f1SSean Christopherson typedef struct SGXEPCState { 49dfce81f1SSean Christopherson uint64_t base; 50dfce81f1SSean Christopherson uint64_t size; 51dfce81f1SSean Christopherson 52dfce81f1SSean Christopherson MemoryRegion mr; 53dfce81f1SSean Christopherson 54dfce81f1SSean Christopherson struct SGXEPCDevice **sections; 55dfce81f1SSean Christopherson int nr_sections; 56dfce81f1SSean Christopherson } SGXEPCState; 57dfce81f1SSean Christopherson 581dec2e1fSSean Christopherson int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size); 591dec2e1fSSean Christopherson 60*0cf4ce00SSean Christopherson static inline uint64_t sgx_epc_above_4g_end(SGXEPCState *sgx_epc) 61*0cf4ce00SSean Christopherson { 62*0cf4ce00SSean Christopherson assert(sgx_epc != NULL && sgx_epc->base >= 0x100000000ULL); 63*0cf4ce00SSean Christopherson 64*0cf4ce00SSean Christopherson return sgx_epc->base + sgx_epc->size; 65*0cf4ce00SSean Christopherson } 66*0cf4ce00SSean Christopherson 6780509c55SSean Christopherson #endif 68