xref: /qemu/include/hw/i386/sgx-epc.h (revision e9d2db818ff934afb366aea566d0b33acf7bced1)
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 
157a5951f6SMarkus Armbruster #include "hw/qdev-core.h"
1680509c55SSean Christopherson #include "hw/i386/hostmem-epc.h"
1780509c55SSean Christopherson 
1880509c55SSean Christopherson #define TYPE_SGX_EPC "sgx-epc"
1980509c55SSean Christopherson #define SGX_EPC(obj) \
2080509c55SSean Christopherson     OBJECT_CHECK(SGXEPCDevice, (obj), TYPE_SGX_EPC)
2180509c55SSean Christopherson #define SGX_EPC_CLASS(oc) \
2280509c55SSean Christopherson     OBJECT_CLASS_CHECK(SGXEPCDeviceClass, (oc), TYPE_SGX_EPC)
2380509c55SSean Christopherson #define SGX_EPC_GET_CLASS(obj) \
2480509c55SSean Christopherson     OBJECT_GET_CLASS(SGXEPCDeviceClass, (obj), TYPE_SGX_EPC)
2580509c55SSean Christopherson 
2680509c55SSean Christopherson #define SGX_EPC_ADDR_PROP "addr"
2780509c55SSean Christopherson #define SGX_EPC_SIZE_PROP "size"
2880509c55SSean Christopherson #define SGX_EPC_MEMDEV_PROP "memdev"
2911058123SYang Zhong #define SGX_EPC_NUMA_NODE_PROP "node"
3080509c55SSean Christopherson 
3180509c55SSean Christopherson /**
3280509c55SSean Christopherson  * SGXEPCDevice:
3380509c55SSean Christopherson  * @addr: starting guest physical address, where @SGXEPCDevice is mapped.
3480509c55SSean Christopherson  *         Default value: 0, means that address is auto-allocated.
3580509c55SSean Christopherson  * @hostmem: host memory backend providing memory for @SGXEPCDevice
3680509c55SSean Christopherson  */
3780509c55SSean Christopherson typedef struct SGXEPCDevice {
3880509c55SSean Christopherson     /* private */
3980509c55SSean Christopherson     DeviceState parent_obj;
4080509c55SSean Christopherson 
4180509c55SSean Christopherson     /* public */
4280509c55SSean Christopherson     uint64_t addr;
4311058123SYang Zhong     uint32_t node;
4480509c55SSean Christopherson     HostMemoryBackendEpc *hostmem;
4580509c55SSean Christopherson } SGXEPCDevice;
4680509c55SSean Christopherson 
47dfce81f1SSean Christopherson /*
48dfce81f1SSean Christopherson  * @base: address in guest physical address space where EPC regions start
49dfce81f1SSean Christopherson  * @mr: address space container for memory devices
50dfce81f1SSean Christopherson  */
51dfce81f1SSean Christopherson typedef struct SGXEPCState {
52dfce81f1SSean Christopherson     uint64_t base;
53dfce81f1SSean Christopherson     uint64_t size;
54dfce81f1SSean Christopherson 
55dfce81f1SSean Christopherson     MemoryRegion mr;
56dfce81f1SSean Christopherson 
57dfce81f1SSean Christopherson     struct SGXEPCDevice **sections;
58dfce81f1SSean Christopherson     int nr_sections;
59dfce81f1SSean Christopherson } SGXEPCState;
60dfce81f1SSean Christopherson 
61*ada1f3caSZhao Liu bool check_sgx_support(void);
6205fc8db7SPhilippe Mathieu-Daudé bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size);
6311058123SYang Zhong void sgx_epc_build_srat(GArray *table_data);
641dec2e1fSSean Christopherson 
sgx_epc_above_4g_end(SGXEPCState * sgx_epc)650cf4ce00SSean Christopherson static inline uint64_t sgx_epc_above_4g_end(SGXEPCState *sgx_epc)
660cf4ce00SSean Christopherson {
670cf4ce00SSean Christopherson     assert(sgx_epc != NULL && sgx_epc->base >= 0x100000000ULL);
680cf4ce00SSean Christopherson 
690cf4ce00SSean Christopherson     return sgx_epc->base + sgx_epc->size;
700cf4ce00SSean Christopherson }
710cf4ce00SSean Christopherson 
7280509c55SSean Christopherson #endif
73