spapr: Expose the name of the interrupt controller node
[qemu/ar7.git] / include / hw / mem / memory-device.h
blob0293a96abb237ac84d25cf914bebf3282553a144
1 /*
2 * Memory Device Interface
4 * Copyright (c) 2018 Red Hat, Inc.
6 * Authors:
7 * David Hildenbrand <david@redhat.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 #ifndef MEMORY_DEVICE_H
14 #define MEMORY_DEVICE_H
16 #include "qom/object.h"
17 #include "hw/qdev.h"
19 #define TYPE_MEMORY_DEVICE "memory-device"
21 #define MEMORY_DEVICE_CLASS(klass) \
22 OBJECT_CLASS_CHECK(MemoryDeviceClass, (klass), TYPE_MEMORY_DEVICE)
23 #define MEMORY_DEVICE_GET_CLASS(obj) \
24 OBJECT_GET_CLASS(MemoryDeviceClass, (obj), TYPE_MEMORY_DEVICE)
25 #define MEMORY_DEVICE(obj) \
26 INTERFACE_CHECK(MemoryDeviceState, (obj), TYPE_MEMORY_DEVICE)
28 typedef struct MemoryDeviceState MemoryDeviceState;
30 /**
31 * MemoryDeviceClass:
33 * All memory devices need to implement TYPE_MEMORY_DEVICE as an interface.
35 * A memory device is a device that owns a memory region which is
36 * mapped into guest physical address space at a certain address. The
37 * address in guest physical memory can either be specified explicitly
38 * or get assigned automatically.
40 * Conceptually, memory devices only span one memory region. If multiple
41 * successive memory regions are used, a covering memory region has to
42 * be provided. Scattered memory regions are not supported for single
43 * devices.
45 typedef struct MemoryDeviceClass {
46 /* private */
47 InterfaceClass parent_class;
50 * Return the address of the memory device in guest physical memory.
52 * Called when (un)plugging a memory device or when iterating over
53 * all memory devices mapped into guest physical address space.
55 * If "0" is returned, no address has been specified by the user and
56 * no address has been assigned to this memory device yet.
58 uint64_t (*get_addr)(const MemoryDeviceState *md);
61 * Set the address of the memory device in guest physical memory.
63 * Called when plugging the memory device to configure the determined
64 * address in guest physical memory.
66 void (*set_addr)(MemoryDeviceState *md, uint64_t addr, Error **errp);
69 * Return the amount of memory provided by the memory device currently
70 * usable ("plugged") by the VM.
72 * Called when calculating the total amount of ram available to the
73 * VM (e.g. to report memory stats to the user).
75 * This is helpful for devices that dynamically manage the amount of
76 * memory accessible by the guest via the reserved memory region. For
77 * most devices, this corresponds to the size of the memory region.
79 uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
82 * Return the memory region of the memory device.
84 * Called when (un)plugging the memory device, to (un)map the
85 * memory region in guest physical memory, but also to detect the
86 * required alignment during address assignment or when the size of the
87 * memory region is required.
89 MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
92 * Translate the memory device into #MemoryDeviceInfo.
94 void (*fill_device_info)(const MemoryDeviceState *md,
95 MemoryDeviceInfo *info);
96 } MemoryDeviceClass;
98 MemoryDeviceInfoList *qmp_memory_device_list(void);
99 uint64_t get_plugged_memory_size(void);
100 void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
101 const uint64_t *legacy_align, Error **errp);
102 void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
103 void memory_device_unplug(MemoryDeviceState *md, MachineState *ms);
104 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
105 Error **errp);
107 #endif