]> git.proxmox.com Git - mirror_qemu.git/blame - backends/hostmem-ram.c
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-03-18' into staging
[mirror_qemu.git] / backends / hostmem-ram.c
CommitLineData
1f070489
IM
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 */
9c058332 12#include "qemu/osdep.h"
1f070489
IM
13#include "sysemu/hostmem.h"
14#include "qom/object_interfaces.h"
15
16#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
17
18
19static void
bd9262d9 20ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
1f070489 21{
1f070489
IM
22 char *path;
23
24 if (!backend->size) {
25 error_setg(errp, "can't create backend with size 0");
26 return;
27 }
28
29 path = object_get_canonical_path_component(OBJECT(backend));
30 memory_region_init_ram(&backend->mr, OBJECT(backend), path,
d42e2de7 31 backend->size, errp);
1f070489
IM
32 g_free(path);
33}
34
35static void
36ram_backend_class_init(ObjectClass *oc, void *data)
37{
bd9262d9 38 HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
1f070489 39
bd9262d9 40 bc->alloc = ram_backend_memory_alloc;
1f070489
IM
41}
42
43static const TypeInfo ram_backend_info = {
44 .name = TYPE_MEMORY_BACKEND_RAM,
45 .parent = TYPE_MEMORY_BACKEND,
46 .class_init = ram_backend_class_init,
47};
48
49static void register_types(void)
50{
51 type_register_static(&ram_backend_info);
52}
53
54type_init(register_types);