/*-1* Copyright (c) 2017 Ruslan Bukin <[email protected]>2* All rights reserved.3*4* This software was developed by BAE Systems, the University of Cambridge5* Computer Laboratory, and Memorial University under DARPA/AFRL contract6* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing7* (TC) research program.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#ifndef _AMD64_SGX_SGXVAR_H_32#define _AMD64_SGX_SGXVAR_H_3334#define SGX_CPUID 0x1235#define SGX_PAGE_SIZE 409636#define SGX_VA_PAGE_SLOTS 51237#define SGX_VA_PAGES_OFFS 51238#define SGX_SECS_VM_OBJECT_INDEX -139#define SGX_SIGSTRUCT_SIZE 180840#define SGX_EINITTOKEN_SIZE 30441#define SGX_IOCTL_MAX_DATA_LEN 2642#define SGX_ENCL_SIZE_MAX_DEF 0x1000000000ULL43#define SGX_EFAULT 994445#ifndef LOCORE46static MALLOC_DEFINE(M_SGX, "sgx", "SGX driver");4748struct sgx_vm_handle {49struct sgx_softc *sc;50vm_object_t mem;51uint64_t base;52vm_size_t size;53struct sgx_enclave *enclave;54};5556/* EPC (Enclave Page Cache) page. */57struct epc_page {58uint64_t base;59uint64_t phys;60int index;61};6263struct sgx_enclave {64uint64_t base;65uint64_t size;66struct sgx_vm_handle *vmh;67TAILQ_ENTRY(sgx_enclave) next;68vm_object_t object;69struct epc_page *secs_epc_page;70};7172struct sgx_softc {73struct cdev *sgx_cdev;74struct mtx mtx_encls;75struct mtx mtx;76uint64_t epc_base;77uint64_t epc_size;78struct epc_page *epc_pages;79struct vmem *vmem_epc;80uint32_t npages;81TAILQ_HEAD(, sgx_enclave) enclaves;82uint64_t enclave_size_max;83uint8_t state;84#define SGX_STATE_RUNNING (1 << 0)85};86#endif /* !LOCORE */8788#endif /* !_AMD64_SGX_SGXVAR_H_ */899091