tcg-cpu.c (2964B)
1/* 2 * i386 TCG cpu class initialization functions specific to sysemu 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18 */ 19 20#include "qemu/osdep.h" 21#include "cpu.h" 22#include "tcg/helper-tcg.h" 23 24#include "sysemu/sysemu.h" 25#include "qemu/units.h" 26#include "exec/address-spaces.h" 27 28#include "tcg/tcg-cpu.h" 29 30static void tcg_cpu_machine_done(Notifier *n, void *unused) 31{ 32 X86CPU *cpu = container_of(n, X86CPU, machine_done); 33 MemoryRegion *smram = 34 (MemoryRegion *) object_resolve_path("/machine/smram", NULL); 35 36 if (smram) { 37 cpu->smram = g_new(MemoryRegion, 1); 38 memory_region_init_alias(cpu->smram, OBJECT(cpu), "smram", 39 smram, 0, 4 * GiB); 40 memory_region_set_enabled(cpu->smram, true); 41 memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, 42 cpu->smram, 1); 43 } 44} 45 46bool tcg_cpu_realizefn(CPUState *cs, Error **errp) 47{ 48 X86CPU *cpu = X86_CPU(cs); 49 50 /* 51 * The realize order is important, since x86_cpu_realize() checks if 52 * nothing else has been set by the user (or by accelerators) in 53 * cpu->ucode_rev and cpu->phys_bits, and the memory regions 54 * initialized here are needed for the vcpu initialization. 55 * 56 * realize order: 57 * tcg_cpu -> host_cpu -> x86_cpu 58 */ 59 cpu->cpu_as_mem = g_new(MemoryRegion, 1); 60 cpu->cpu_as_root = g_new(MemoryRegion, 1); 61 62 /* Outer container... */ 63 memory_region_init(cpu->cpu_as_root, OBJECT(cpu), "memory", ~0ull); 64 memory_region_set_enabled(cpu->cpu_as_root, true); 65 66 /* 67 * ... with two regions inside: normal system memory with low 68 * priority, and... 69 */ 70 memory_region_init_alias(cpu->cpu_as_mem, OBJECT(cpu), "memory", 71 get_system_memory(), 0, ~0ull); 72 memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_as_mem, 0); 73 memory_region_set_enabled(cpu->cpu_as_mem, true); 74 75 cs->num_ases = 2; 76 cpu_address_space_init(cs, 0, "cpu-memory", cs->memory); 77 cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root); 78 79 /* ... SMRAM with higher priority, linked from /machine/smram. */ 80 cpu->machine_done.notify = tcg_cpu_machine_done; 81 qemu_add_machine_init_done_notifier(&cpu->machine_done); 82 return true; 83}