Skip to content

Commit 3513bb1

Browse files
davidhildenbrandbonzini
authored andcommitted
softmmu/memory_mapping: factor out adding physical memory ranges
Let's factor out adding a MemoryRegionSection to the list, to be reused in RamDiscardManager context next. Reviewed-by: Stefan Berger <[email protected]> Reviewed-by: Peter Xu <[email protected]> Cc: Marc-André Lureau <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Eduardo Habkost <[email protected]> Cc: Alex Williamson <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: Igor Mammedov <[email protected]> Cc: Claudio Fontana <[email protected]> Cc: Thomas Huth <[email protected]> Cc: "Alex Bennée" <[email protected]> Cc: Peter Xu <[email protected]> Cc: Laurent Vivier <[email protected]> Cc: Stefan Berger <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 602f8ea commit 3513bb1

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

softmmu/memory_mapping.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,14 @@ typedef struct GuestPhysListener {
193193
MemoryListener listener;
194194
} GuestPhysListener;
195195

196-
static void guest_phys_blocks_region_add(MemoryListener *listener,
196+
static void guest_phys_block_add_section(GuestPhysListener *g,
197197
MemoryRegionSection *section)
198198
{
199-
GuestPhysListener *g;
200-
uint64_t section_size;
201-
hwaddr target_start, target_end;
202-
uint8_t *host_addr;
203-
GuestPhysBlock *predecessor;
204-
205-
/* we only care about RAM */
206-
if (!memory_region_is_ram(section->mr) ||
207-
memory_region_is_ram_device(section->mr) ||
208-
memory_region_is_nonvolatile(section->mr)) {
209-
return;
210-
}
211-
212-
g = container_of(listener, GuestPhysListener, listener);
213-
section_size = int128_get64(section->size);
214-
target_start = section->offset_within_address_space;
215-
target_end = target_start + section_size;
216-
host_addr = memory_region_get_ram_ptr(section->mr) +
217-
section->offset_within_region;
218-
predecessor = NULL;
199+
const hwaddr target_start = section->offset_within_address_space;
200+
const hwaddr target_end = target_start + int128_get64(section->size);
201+
uint8_t *host_addr = memory_region_get_ram_ptr(section->mr) +
202+
section->offset_within_region;
203+
GuestPhysBlock *predecessor = NULL;
219204

220205
/* find continuity in guest physical address space */
221206
if (!QTAILQ_EMPTY(&g->list->head)) {
@@ -261,6 +246,20 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
261246
#endif
262247
}
263248

249+
static void guest_phys_blocks_region_add(MemoryListener *listener,
250+
MemoryRegionSection *section)
251+
{
252+
GuestPhysListener *g = container_of(listener, GuestPhysListener, listener);
253+
254+
/* we only care about RAM */
255+
if (!memory_region_is_ram(section->mr) ||
256+
memory_region_is_ram_device(section->mr) ||
257+
memory_region_is_nonvolatile(section->mr)) {
258+
return;
259+
}
260+
guest_phys_block_add_section(g, section);
261+
}
262+
264263
void guest_phys_blocks_append(GuestPhysBlockList *list)
265264
{
266265
GuestPhysListener g = { 0 };

0 commit comments

Comments
 (0)