target/s390x: Move trans_exc_code update to do_program_interrupt
[qemu/armbru.git] / backends / hostmem-epc.c
blob4e162d6789e86dc0de4ff3086b6e383fea059be4
1 /*
2 * QEMU host SGX EPC memory backend
4 * Copyright (C) 2019 Intel Corporation
6 * Authors:
7 * Sean Christopherson <sean.j.christopherson@intel.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include <sys/ioctl.h>
15 #include "qom/object_interfaces.h"
16 #include "qapi/error.h"
17 #include "sysemu/hostmem.h"
18 #include "hw/i386/hostmem-epc.h"
20 static void
21 sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
23 uint32_t ram_flags;
24 char *name;
25 int fd;
27 if (!backend->size) {
28 error_setg(errp, "can't create backend with size 0");
29 return;
32 fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
33 if (fd < 0) {
34 error_setg_errno(errp, errno,
35 "failed to open /dev/sgx_vepc to alloc SGX EPC");
36 return;
39 name = object_get_canonical_path(OBJECT(backend));
40 ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED;
41 memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
42 name, backend->size, ram_flags,
43 fd, 0, errp);
44 g_free(name);
47 static void sgx_epc_backend_instance_init(Object *obj)
49 HostMemoryBackend *m = MEMORY_BACKEND(obj);
51 m->share = true;
52 m->merge = false;
53 m->dump = false;
56 static void sgx_epc_backend_class_init(ObjectClass *oc, void *data)
58 HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
60 bc->alloc = sgx_epc_backend_memory_alloc;
63 static const TypeInfo sgx_epc_backed_info = {
64 .name = TYPE_MEMORY_BACKEND_EPC,
65 .parent = TYPE_MEMORY_BACKEND,
66 .instance_init = sgx_epc_backend_instance_init,
67 .class_init = sgx_epc_backend_class_init,
68 .instance_size = sizeof(HostMemoryBackendEpc),
71 static void register_types(void)
73 int fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
74 if (fd >= 0) {
75 close(fd);
77 type_register_static(&sgx_epc_backed_info);
81 type_init(register_types);