typedef struct XenPhysmap {
hwaddr start_addr;
ram_addr_t size;
- char *name;
+ const char *name;
hwaddr phys_offset;
QLIST_ENTRY(XenPhysmap) list;
{
MemoryRegion *sysmem = get_system_memory();
ram_addr_t block_len;
+ uint64_t user_lowmem = object_property_get_int(qdev_get_machine(),
+ PC_MACHINE_MAX_RAM_BELOW_4G,
+ &error_abort);
- block_len = ram_size;
- if (ram_size >= HVM_BELOW_4G_RAM_END) {
- /* Xen does not allocate the memory continuously, and keep a hole at
- * HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH
- */
- block_len += HVM_BELOW_4G_MMIO_LENGTH;
+ /* Handle the machine opt max-ram-below-4g. It is basically doing
+ * min(xen limit, user limit).
+ */
+ if (HVM_BELOW_4G_RAM_END <= user_lowmem) {
+ user_lowmem = HVM_BELOW_4G_RAM_END;
}
- memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
- *ram_memory_p = &ram_memory;
- vmstate_register_ram_global(&ram_memory);
- if (ram_size >= HVM_BELOW_4G_RAM_END) {
- *above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END;
- *below_4g_mem_size = HVM_BELOW_4G_RAM_END;
+ if (ram_size >= user_lowmem) {
+ *above_4g_mem_size = ram_size - user_lowmem;
+ *below_4g_mem_size = user_lowmem;
} else {
*above_4g_mem_size = 0;
*below_4g_mem_size = ram_size;
}
+ if (!*above_4g_mem_size) {
+ block_len = ram_size;
+ } else {
+ /*
+ * Xen does not allocate the memory continuously, it keeps a
+ * hole of the size computed above or passed in.
+ */
+ block_len = (1ULL << 32) + *above_4g_mem_size;
+ }
+ memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
+ *ram_memory_p = &ram_memory;
+ vmstate_register_ram_global(&ram_memory);
memory_region_init_alias(&ram_640k, NULL, "xen.ram.640k",
&ram_memory, 0, 0xa0000);
hwaddr pfn, start_gpfn;
hwaddr phys_offset = memory_region_get_ram_addr(mr);
char path[80], value[17];
+ const char *mr_name;
if (get_physmapping(state, start_addr, size)) {
return 0;
}
}
+ mr_name = memory_region_name(mr);
+
physmap = g_malloc(sizeof (XenPhysmap));
physmap->start_addr = start_addr;
physmap->size = size;
- physmap->name = (char *)mr->name;
+ physmap->name = mr_name;
physmap->phys_offset = phys_offset;
QLIST_INSERT_HEAD(&state->physmap, physmap, list);
if (!xs_write(state->xenstore, 0, path, value, strlen(value))) {
return -1;
}
- if (mr->name) {
+ if (mr_name) {
snprintf(path, sizeof(path),
"/local/domain/0/device-model/%d/physmap/%"PRIx64"/name",
xen_domid, (uint64_t)phys_offset);
- if (!xs_write(state->xenstore, 0, path, mr->name, strlen(mr->name))) {
+ if (!xs_write(state->xenstore, 0, path, mr_name, strlen(mr_name))) {
return -1;
}
}
start_addr >>= TARGET_PAGE_BITS;
phys_offset >>= TARGET_PAGE_BITS;
for (i = 0; i < size; i++) {
- unsigned long idx = start_addr + i;
+ xen_pfn_t idx = start_addr + i;
xen_pfn_t gpfn = phys_offset + i;
rc = xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE_gmfn, idx, gpfn);
start_addr >> TARGET_PAGE_BITS, npages,
bitmap);
if (rc < 0) {
- if (rc != -ENODATA) {
+#ifndef ENODATA
+#define ENODATA ENOENT
+#endif
+ if (errno == ENODATA) {
memory_region_set_dirty(framebuffer, 0, size);
DPRINTF("xen: track_dirty_vram failed (0x" TARGET_FMT_plx
", 0x" TARGET_FMT_plx "): %s\n",
- start_addr, start_addr + size, strerror(-rc));
+ start_addr, start_addr + size, strerror(errno));
}
return;
}