@@ -172,6 +172,9 @@ static void xen_ram_init(PCMachineState *pcms,
x86ms->above_4g_mem_size);
memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
}
+
+ /* Add grant mappings as a pseudo RAM region. */
+ ram_grants = *xen_init_grant_ram();
}
static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size)
@@ -9,7 +9,7 @@
#include "hw/boards.h"
#include "hw/xen/arch_hvm.h"
-MemoryRegion ram_memory;
+MemoryRegion ram_memory, ram_grants;
void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
Error **errp)
@@ -26,7 +26,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
return;
}
- if (mr == &ram_memory) {
+ if (mr == &ram_memory || mr == &ram_grants) {
return;
}
@@ -14,7 +14,9 @@
#include <sys/resource.h>
+#include "hw/xen/xen-hvm-common.h"
#include "hw/xen/xen_native.h"
+#include "hw/xen/xen_pvdev.h"
#include "qemu/bitmap.h"
#include "sysemu/runstate.h"
@@ -590,3 +592,28 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
mapcache_unlock();
return p;
}
+
+MemoryRegion *xen_init_grant_ram(void)
+{
+ RAMBlock *block;
+
+ memory_region_init(&ram_grants, NULL, "xen.grants",
+ XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE);
+ block = g_malloc0(sizeof(*block));
+ block->mr = &ram_grants;
+ block->used_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE;
+ block->max_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE;
+ block->fd = -1;
+ block->page_size = XC_PAGE_SIZE;
+ block->host = (void *)XEN_GRANT_ADDR_OFF;
+ block->offset = XEN_GRANT_ADDR_OFF;
+ block->flags = RAM_PREALLOC;
+ ram_grants.ram_block = block;
+ ram_grants.ram = true;
+ ram_grants.terminates = true;
+ ram_block_add_list(block);
+ memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF,
+ &ram_grants);
+
+ return &ram_grants;
+}
@@ -16,6 +16,8 @@
#include <xen/hvm/ioreq.h>
extern MemoryRegion ram_memory;
+
+extern MemoryRegion ram_grants;
extern MemoryListener xen_io_listener;
extern DeviceListener xen_device_listener;
@@ -80,4 +80,7 @@ int xen_pv_send_notify(struct XenLegacyDevice *xendev);
void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
const char *fmt, ...) G_GNUC_PRINTF(3, 4);
+#define XEN_GRANT_ADDR_OFF 0x8000000000000000ULL
+#define XEN_MAX_VIRTIO_GRANTS 65536
+
#endif /* QEMU_HW_XEN_PVDEV_H */
@@ -10,6 +10,7 @@
#define XEN_MAPCACHE_H
#include "exec/cpu-common.h"
+#include "exec/ram_addr.h"
typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset,
ram_addr_t size);
@@ -25,6 +26,8 @@ void xen_invalidate_map_cache(void);
uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
hwaddr new_phys_addr,
hwaddr size);
+MemoryRegion *xen_init_grant_ram(void);
+
#else
static inline void xen_map_cache_init(phys_offset_to_gaddr_t f,