1 /*
2 * i386 TCG cpu class initialization functions specific to system emulation
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 "system/system.h"
25 #include "qemu/units.h"
26 #include "system/address-spaces.h"
27 #include "system/memory.h"
28
29 #include "tcg/tcg-cpu.h"
30
tcg_cpu_machine_done(Notifier * n,void * unused)31 static void tcg_cpu_machine_done(Notifier *n, void *unused)
32 {
33 X86CPU *cpu = container_of(n, X86CPU, machine_done);
34 MemoryRegion *smram =
35 (MemoryRegion *) object_resolve_path("/machine/smram", NULL);
36
37 if (smram) {
38 cpu->smram = g_new(MemoryRegion, 1);
39 memory_region_init_alias(cpu->smram, OBJECT(cpu), "smram",
40 smram, 0, 4 * GiB);
41 memory_region_set_enabled(cpu->smram, true);
42 memory_region_add_subregion_overlap(cpu->cpu_as_root, 0,
43 cpu->smram, 1);
44 }
45 }
46
tcg_cpu_realizefn(CPUState * cs,Error ** errp)47 bool tcg_cpu_realizefn(CPUState *cs, Error **errp)
48 {
49 X86CPU *cpu = X86_CPU(cs);
50
51 /*
52 * The realize order is important, since x86_cpu_realize() checks if
53 * nothing else has been set by the user (or by accelerators) in
54 * cpu->ucode_rev and cpu->phys_bits, and the memory regions
55 * initialized here are needed for the vcpu initialization.
56 *
57 * realize order:
58 * tcg_cpu -> host_cpu -> x86_cpu
59 */
60 cpu->cpu_as_mem = g_new(MemoryRegion, 1);
61 cpu->cpu_as_root = g_new(MemoryRegion, 1);
62
63 /* Outer container... */
64 memory_region_init(cpu->cpu_as_root, OBJECT(cpu), "memory", ~0ull);
65 memory_region_set_enabled(cpu->cpu_as_root, true);
66
67 /*
68 * ... with two regions inside: normal system memory with low
69 * priority, and...
70 */
71 memory_region_init_alias(cpu->cpu_as_mem, OBJECT(cpu), "memory",
72 get_system_memory(), 0, ~0ull);
73 memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_as_mem, 0);
74 memory_region_set_enabled(cpu->cpu_as_mem, true);
75
76 cs->num_ases = 2;
77 cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
78 cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root);
79
80 /* ... SMRAM with higher priority, linked from /machine/smram. */
81 cpu->machine_done.notify = tcg_cpu_machine_done;
82 qemu_add_machine_init_done_notifier(&cpu->machine_done);
83 return true;
84 }
85