]> git.proxmox.com Git - mirror_qemu.git/blame_incremental - backends/hostmem-ram.c
Merge tag 'hw-cpus-20240119' of https://github.com/philmd/qemu into staging
[mirror_qemu.git] / backends / hostmem-ram.c
... / ...
CommitLineData
1/*
2 * QEMU Host Memory Backend
3 *
4 * Copyright (C) 2013-2014 Red Hat Inc
5 *
6 * Authors:
7 * Igor Mammedov <imammedo@redhat.com>
8 *
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.
11 */
12
13#include "qemu/osdep.h"
14#include "sysemu/hostmem.h"
15#include "qapi/error.h"
16#include "qemu/module.h"
17#include "qom/object_interfaces.h"
18
19static bool
20ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
21{
22 g_autofree char *name = NULL;
23 uint32_t ram_flags;
24
25 if (!backend->size) {
26 error_setg(errp, "can't create backend with size 0");
27 return false;
28 }
29
30 name = host_memory_backend_get_name(backend);
31 ram_flags = backend->share ? RAM_SHARED : 0;
32 ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
33 return memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend),
34 name, backend->size,
35 ram_flags, errp);
36}
37
38static void
39ram_backend_class_init(ObjectClass *oc, void *data)
40{
41 HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
42
43 bc->alloc = ram_backend_memory_alloc;
44}
45
46static const TypeInfo ram_backend_info = {
47 .name = TYPE_MEMORY_BACKEND_RAM,
48 .parent = TYPE_MEMORY_BACKEND,
49 .class_init = ram_backend_class_init,
50};
51
52static void register_types(void)
53{
54 type_register_static(&ram_backend_info);
55}
56
57type_init(register_types);