xref: /openbmc/qemu/hw/core/cpu-sysemu.c (revision 05caa062)
1 /*
2  * QEMU CPU model (system emulation specific)
3  *
4  * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <http://www.gnu.org/licenses/gpl-2.0.html>
19  */
20 
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "exec/tswap.h"
24 #include "hw/core/sysemu-cpu-ops.h"
25 
26 bool cpu_paging_enabled(const CPUState *cpu)
27 {
28     CPUClass *cc = CPU_GET_CLASS(cpu);
29 
30     if (cc->sysemu_ops->get_paging_enabled) {
31         return cc->sysemu_ops->get_paging_enabled(cpu);
32     }
33 
34     return false;
35 }
36 
37 bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
38                             Error **errp)
39 {
40     CPUClass *cc = CPU_GET_CLASS(cpu);
41 
42     if (cc->sysemu_ops->get_memory_mapping) {
43         return cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
44     }
45 
46     error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
47     return false;
48 }
49 
50 hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
51                                      MemTxAttrs *attrs)
52 {
53     CPUClass *cc = CPU_GET_CLASS(cpu);
54 
55     if (cc->sysemu_ops->get_phys_page_attrs_debug) {
56         return cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs);
57     }
58     /* Fallback for CPUs which don't implement the _attrs_ hook */
59     *attrs = MEMTXATTRS_UNSPECIFIED;
60     return cc->sysemu_ops->get_phys_page_debug(cpu, addr);
61 }
62 
63 hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
64 {
65     MemTxAttrs attrs = {};
66 
67     return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
68 }
69 
70 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
71 {
72     int ret = 0;
73 
74     if (cpu->cc->sysemu_ops->asidx_from_attrs) {
75         ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
76         assert(ret < cpu->num_ases && ret >= 0);
77     }
78     return ret;
79 }
80 
81 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
82                              void *opaque)
83 {
84     CPUClass *cc = CPU_GET_CLASS(cpu);
85 
86     if (!cc->sysemu_ops->write_elf32_qemunote) {
87         return 0;
88     }
89     return (*cc->sysemu_ops->write_elf32_qemunote)(f, cpu, opaque);
90 }
91 
92 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
93                          int cpuid, void *opaque)
94 {
95     CPUClass *cc = CPU_GET_CLASS(cpu);
96 
97     if (!cc->sysemu_ops->write_elf32_note) {
98         return -1;
99     }
100     return (*cc->sysemu_ops->write_elf32_note)(f, cpu, cpuid, opaque);
101 }
102 
103 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
104                              void *opaque)
105 {
106     CPUClass *cc = CPU_GET_CLASS(cpu);
107 
108     if (!cc->sysemu_ops->write_elf64_qemunote) {
109         return 0;
110     }
111     return (*cc->sysemu_ops->write_elf64_qemunote)(f, cpu, opaque);
112 }
113 
114 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
115                          int cpuid, void *opaque)
116 {
117     CPUClass *cc = CPU_GET_CLASS(cpu);
118 
119     if (!cc->sysemu_ops->write_elf64_note) {
120         return -1;
121     }
122     return (*cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque);
123 }
124 
125 bool cpu_virtio_is_big_endian(CPUState *cpu)
126 {
127     CPUClass *cc = CPU_GET_CLASS(cpu);
128 
129     if (cc->sysemu_ops->virtio_is_big_endian) {
130         return cc->sysemu_ops->virtio_is_big_endian(cpu);
131     }
132     return target_words_bigendian();
133 }
134 
135 GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
136 {
137     CPUClass *cc = CPU_GET_CLASS(cpu);
138     GuestPanicInformation *res = NULL;
139 
140     if (cc->sysemu_ops->get_crash_info) {
141         res = cc->sysemu_ops->get_crash_info(cpu);
142     }
143     return res;
144 }
145