blob: a67a134521a3d921b316cdcd5598b7f8ac7e1549 [file] [log] [blame]
Igor Mammedov1f070482014-06-06 17:54:29 +02001/*
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#include "sysemu/hostmem.h"
13#include "qom/object_interfaces.h"
14
15#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
16
17
18static void
Hu Taobd9262d2014-06-10 19:15:19 +080019ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
Igor Mammedov1f070482014-06-06 17:54:29 +020020{
Igor Mammedov1f070482014-06-06 17:54:29 +020021 char *path;
22
23 if (!backend->size) {
24 error_setg(errp, "can't create backend with size 0");
25 return;
26 }
27
28 path = object_get_canonical_path_component(OBJECT(backend));
29 memory_region_init_ram(&backend->mr, OBJECT(backend), path,
Hu Taod42e2de2014-09-09 13:27:58 +080030 backend->size, errp);
Igor Mammedov1f070482014-06-06 17:54:29 +020031 g_free(path);
32}
33
34static void
35ram_backend_class_init(ObjectClass *oc, void *data)
36{
Hu Taobd9262d2014-06-10 19:15:19 +080037 HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
Igor Mammedov1f070482014-06-06 17:54:29 +020038
Hu Taobd9262d2014-06-10 19:15:19 +080039 bc->alloc = ram_backend_memory_alloc;
Igor Mammedov1f070482014-06-06 17:54:29 +020040}
41
42static const TypeInfo ram_backend_info = {
43 .name = TYPE_MEMORY_BACKEND_RAM,
44 .parent = TYPE_MEMORY_BACKEND,
45 .class_init = ram_backend_class_init,
46};
47
48static void register_types(void)
49{
50 type_register_static(&ram_backend_info);
51}
52
53type_init(register_types);