162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _NE_MISC_DEV_H_ 762306a36Sopenharmony_ci#define _NE_MISC_DEV_H_ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/cpumask.h> 1062306a36Sopenharmony_ci#include <linux/list.h> 1162306a36Sopenharmony_ci#include <linux/miscdevice.h> 1262306a36Sopenharmony_ci#include <linux/mm.h> 1362306a36Sopenharmony_ci#include <linux/mutex.h> 1462306a36Sopenharmony_ci#include <linux/pci.h> 1562306a36Sopenharmony_ci#include <linux/wait.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include "ne_pci_dev.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/** 2062306a36Sopenharmony_ci * struct ne_mem_region - Entry in the enclave user space memory regions list. 2162306a36Sopenharmony_ci * @mem_region_list_entry: Entry in the list of enclave memory regions. 2262306a36Sopenharmony_ci * @memory_size: Size of the user space memory region. 2362306a36Sopenharmony_ci * @nr_pages: Number of pages that make up the memory region. 2462306a36Sopenharmony_ci * @pages: Pages that make up the user space memory region. 2562306a36Sopenharmony_ci * @userspace_addr: User space address of the memory region. 2662306a36Sopenharmony_ci */ 2762306a36Sopenharmony_cistruct ne_mem_region { 2862306a36Sopenharmony_ci struct list_head mem_region_list_entry; 2962306a36Sopenharmony_ci u64 memory_size; 3062306a36Sopenharmony_ci unsigned long nr_pages; 3162306a36Sopenharmony_ci struct page **pages; 3262306a36Sopenharmony_ci u64 userspace_addr; 3362306a36Sopenharmony_ci}; 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci/** 3662306a36Sopenharmony_ci * struct ne_enclave - Per-enclave data used for enclave lifetime management. 3762306a36Sopenharmony_ci * @enclave_info_mutex : Mutex for accessing this internal state. 3862306a36Sopenharmony_ci * @enclave_list_entry : Entry in the list of created enclaves. 3962306a36Sopenharmony_ci * @eventq: Wait queue used for out-of-band event notifications 4062306a36Sopenharmony_ci * triggered from the PCI device event handler to 4162306a36Sopenharmony_ci * the enclave process via the poll function. 4262306a36Sopenharmony_ci * @has_event: Variable used to determine if the out-of-band event 4362306a36Sopenharmony_ci * was triggered. 4462306a36Sopenharmony_ci * @max_mem_regions: The maximum number of memory regions that can be 4562306a36Sopenharmony_ci * handled by the hypervisor. 4662306a36Sopenharmony_ci * @mem_regions_list: Enclave user space memory regions list. 4762306a36Sopenharmony_ci * @mem_size: Enclave memory size. 4862306a36Sopenharmony_ci * @mm : Enclave process abstraction mm data struct. 4962306a36Sopenharmony_ci * @nr_mem_regions: Number of memory regions associated with the enclave. 5062306a36Sopenharmony_ci * @nr_parent_vm_cores : The size of the threads per core array. The 5162306a36Sopenharmony_ci * total number of CPU cores available on the 5262306a36Sopenharmony_ci * parent / primary VM. 5362306a36Sopenharmony_ci * @nr_threads_per_core: The number of threads that a full CPU core has. 5462306a36Sopenharmony_ci * @nr_vcpus: Number of vcpus associated with the enclave. 5562306a36Sopenharmony_ci * @numa_node: NUMA node of the enclave memory and CPUs. 5662306a36Sopenharmony_ci * @slot_uid: Slot unique id mapped to the enclave. 5762306a36Sopenharmony_ci * @state: Enclave state, updated during enclave lifetime. 5862306a36Sopenharmony_ci * @threads_per_core: Enclave full CPU cores array, indexed by core id, 5962306a36Sopenharmony_ci * consisting of cpumasks with all their threads. 6062306a36Sopenharmony_ci * Full CPU cores are taken from the NE CPU pool 6162306a36Sopenharmony_ci * and are available to the enclave. 6262306a36Sopenharmony_ci * @vcpu_ids: Cpumask of the vCPUs that are set for the enclave. 6362306a36Sopenharmony_ci */ 6462306a36Sopenharmony_cistruct ne_enclave { 6562306a36Sopenharmony_ci struct mutex enclave_info_mutex; 6662306a36Sopenharmony_ci struct list_head enclave_list_entry; 6762306a36Sopenharmony_ci wait_queue_head_t eventq; 6862306a36Sopenharmony_ci bool has_event; 6962306a36Sopenharmony_ci u64 max_mem_regions; 7062306a36Sopenharmony_ci struct list_head mem_regions_list; 7162306a36Sopenharmony_ci u64 mem_size; 7262306a36Sopenharmony_ci struct mm_struct *mm; 7362306a36Sopenharmony_ci unsigned int nr_mem_regions; 7462306a36Sopenharmony_ci unsigned int nr_parent_vm_cores; 7562306a36Sopenharmony_ci unsigned int nr_threads_per_core; 7662306a36Sopenharmony_ci unsigned int nr_vcpus; 7762306a36Sopenharmony_ci int numa_node; 7862306a36Sopenharmony_ci u64 slot_uid; 7962306a36Sopenharmony_ci u16 state; 8062306a36Sopenharmony_ci cpumask_var_t *threads_per_core; 8162306a36Sopenharmony_ci cpumask_var_t vcpu_ids; 8262306a36Sopenharmony_ci}; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/** 8562306a36Sopenharmony_ci * enum ne_state - States available for an enclave. 8662306a36Sopenharmony_ci * @NE_STATE_INIT: The enclave has not been started yet. 8762306a36Sopenharmony_ci * @NE_STATE_RUNNING: The enclave was started and is running as expected. 8862306a36Sopenharmony_ci * @NE_STATE_STOPPED: The enclave exited without userspace interaction. 8962306a36Sopenharmony_ci */ 9062306a36Sopenharmony_cienum ne_state { 9162306a36Sopenharmony_ci NE_STATE_INIT = 0, 9262306a36Sopenharmony_ci NE_STATE_RUNNING = 2, 9362306a36Sopenharmony_ci NE_STATE_STOPPED = U16_MAX, 9462306a36Sopenharmony_ci}; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/** 9762306a36Sopenharmony_ci * struct ne_devs - Data structure to keep refs to the NE misc and PCI devices. 9862306a36Sopenharmony_ci * @ne_misc_dev: Nitro Enclaves misc device. 9962306a36Sopenharmony_ci * @ne_pci_dev : Nitro Enclaves PCI device. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_cistruct ne_devs { 10262306a36Sopenharmony_ci struct miscdevice *ne_misc_dev; 10362306a36Sopenharmony_ci struct ne_pci_dev *ne_pci_dev; 10462306a36Sopenharmony_ci}; 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci/* Nitro Enclaves (NE) data structure for keeping refs to the NE misc and PCI devices. */ 10762306a36Sopenharmony_ciextern struct ne_devs ne_devs; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#endif /* _NE_MISC_DEV_H_ */ 110