From 7975feece9053b73a2b7b015840f85e9f6ad25db Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Tue, 26 Sep 2023 20:57:26 +0200 Subject: memory-device: Support memory devices with multiple memslots We want to support memory devices that have a memory region container as device memory region that maps multiple RAM memory regions. Let's start by supporting memory devices that statically map multiple RAM memory regions and, thereby, consume multiple memslots. We already have one device that uses a container as device memory region: NVDIMMs. However, a NVDIMM always ends up consuming exactly one memslot. Let's add support for that by asking the memory device via a new callback how many memslots it requires. Message-ID: <20230926185738.277351-7-david@redhat.com> Reviewed-by: Maciej S. Szmigiero Reviewed-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- include/hw/mem/memory-device.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include/hw') diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 48d2611..b51a579 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -41,6 +41,11 @@ typedef struct MemoryDeviceState MemoryDeviceState; * successive memory regions are used, a covering memory region has to * be provided. Scattered memory regions are not supported for single * devices. + * + * The device memory region returned via @get_memory_region may either be a + * single RAM memory region or a memory region container with subregions + * that are RAM memory regions or aliases to RAM memory regions. Other + * memory regions or subregions are not supported. */ struct MemoryDeviceClass { /* private */ @@ -89,6 +94,19 @@ struct MemoryDeviceClass { MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); /* + * Optional for memory devices that require only a single memslot, + * required for all other memory devices: Return the number of memslots + * (distinct RAM memory regions in the device memory region) that are + * required by the device. + * + * If this function is not implemented, the assumption is "1". + * + * Called when (un)plugging the memory device, to check if the requirements + * can be satisfied, and to do proper accounting. + */ + unsigned int (*get_memslots)(MemoryDeviceState *md); + + /* * Optional: Return the desired minimum alignment of the device in guest * physical address space. The final alignment is computed based on this * alignment and the alignment requirements of the memory region. -- cgit v1.1