12adcba79SJarkko Sakkinen // SPDX-License-Identifier: GPL-2.0 22adcba79SJarkko Sakkinen /* Copyright(c) 2016-20 Intel Corporation. */ 32adcba79SJarkko Sakkinen 42adcba79SJarkko Sakkinen #include <stddef.h> 52adcba79SJarkko Sakkinen #include "defines.h" 62adcba79SJarkko Sakkinen 7*abc5cec4SReinette Chatre /* 8*abc5cec4SReinette Chatre * Data buffer spanning two pages that will be placed first in .data 9*abc5cec4SReinette Chatre * segment. Even if not used internally the second page is needed by 10*abc5cec4SReinette Chatre * external test manipulating page permissions. 11*abc5cec4SReinette Chatre */ 1222118ce1SJarkko Sakkinen static uint8_t encl_buffer[8192] = { 1 }; 1322118ce1SJarkko Sakkinen 142adcba79SJarkko Sakkinen static void *memcpy(void *dest, const void *src, size_t n) 152adcba79SJarkko Sakkinen { 162adcba79SJarkko Sakkinen size_t i; 172adcba79SJarkko Sakkinen 182adcba79SJarkko Sakkinen for (i = 0; i < n; i++) 192adcba79SJarkko Sakkinen ((char *)dest)[i] = ((char *)src)[i]; 202adcba79SJarkko Sakkinen 212adcba79SJarkko Sakkinen return dest; 222adcba79SJarkko Sakkinen } 232adcba79SJarkko Sakkinen 24c085dfc7SReinette Chatre static void do_encl_op_put_to_buf(void *op) 2541493a09SJarkko Sakkinen { 26c085dfc7SReinette Chatre struct encl_op_put_to_buf *op2 = op; 2741493a09SJarkko Sakkinen 2841493a09SJarkko Sakkinen memcpy(&encl_buffer[0], &op2->value, 8); 2941493a09SJarkko Sakkinen } 3041493a09SJarkko Sakkinen 31c085dfc7SReinette Chatre static void do_encl_op_get_from_buf(void *op) 3241493a09SJarkko Sakkinen { 33c085dfc7SReinette Chatre struct encl_op_get_from_buf *op2 = op; 3441493a09SJarkko Sakkinen 3541493a09SJarkko Sakkinen memcpy(&op2->value, &encl_buffer[0], 8); 3641493a09SJarkko Sakkinen } 3741493a09SJarkko Sakkinen 38*abc5cec4SReinette Chatre static void do_encl_op_put_to_addr(void *_op) 39*abc5cec4SReinette Chatre { 40*abc5cec4SReinette Chatre struct encl_op_put_to_addr *op = _op; 41*abc5cec4SReinette Chatre 42*abc5cec4SReinette Chatre memcpy((void *)op->addr, &op->value, 8); 43*abc5cec4SReinette Chatre } 44*abc5cec4SReinette Chatre 45*abc5cec4SReinette Chatre static void do_encl_op_get_from_addr(void *_op) 46*abc5cec4SReinette Chatre { 47*abc5cec4SReinette Chatre struct encl_op_get_from_addr *op = _op; 48*abc5cec4SReinette Chatre 49*abc5cec4SReinette Chatre memcpy(&op->value, (void *)op->addr, 8); 50*abc5cec4SReinette Chatre } 51*abc5cec4SReinette Chatre 522adcba79SJarkko Sakkinen void encl_body(void *rdi, void *rsi) 532adcba79SJarkko Sakkinen { 5441493a09SJarkko Sakkinen const void (*encl_op_array[ENCL_OP_MAX])(void *) = { 55c085dfc7SReinette Chatre do_encl_op_put_to_buf, 56c085dfc7SReinette Chatre do_encl_op_get_from_buf, 57*abc5cec4SReinette Chatre do_encl_op_put_to_addr, 58*abc5cec4SReinette Chatre do_encl_op_get_from_addr, 5941493a09SJarkko Sakkinen }; 6022118ce1SJarkko Sakkinen 6141493a09SJarkko Sakkinen struct encl_op_header *op = (struct encl_op_header *)rdi; 6222118ce1SJarkko Sakkinen 6341493a09SJarkko Sakkinen if (op->type < ENCL_OP_MAX) 6441493a09SJarkko Sakkinen (*encl_op_array[op->type])(op); 652adcba79SJarkko Sakkinen } 66