xref: /openbmc/qemu/hw/core/machine.c (revision bfb27e60)
1 /*
2  * QEMU Machine
3  *
4  * Copyright (C) 2014 Red Hat Inc
5  *
6  * Authors:
7  *   Marcel Apfelbaum <marcel.a@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #include "hw/boards.h"
14 #include "qapi/visitor.h"
15 
16 static char *machine_get_accel(Object *obj, Error **errp)
17 {
18     MachineState *ms = MACHINE(obj);
19 
20     return g_strdup(ms->accel);
21 }
22 
23 static void machine_set_accel(Object *obj, const char *value, Error **errp)
24 {
25     MachineState *ms = MACHINE(obj);
26 
27     ms->accel = g_strdup(value);
28 }
29 
30 static bool machine_get_kernel_irqchip(Object *obj, Error **errp)
31 {
32     MachineState *ms = MACHINE(obj);
33 
34     return ms->kernel_irqchip;
35 }
36 
37 static void machine_set_kernel_irqchip(Object *obj, bool value, Error **errp)
38 {
39     MachineState *ms = MACHINE(obj);
40 
41     ms->kernel_irqchip = value;
42 }
43 
44 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
45                                        void *opaque, const char *name,
46                                        Error **errp)
47 {
48     MachineState *ms = MACHINE(obj);
49     int64_t value = ms->kvm_shadow_mem;
50 
51     visit_type_int(v, &value, name, errp);
52 }
53 
54 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
55                                        void *opaque, const char *name,
56                                        Error **errp)
57 {
58     MachineState *ms = MACHINE(obj);
59     Error *error = NULL;
60     int64_t value;
61 
62     visit_type_int(v, &value, name, &error);
63     if (error) {
64         error_propagate(errp, error);
65         return;
66     }
67 
68     ms->kvm_shadow_mem = value;
69 }
70 
71 static char *machine_get_kernel(Object *obj, Error **errp)
72 {
73     MachineState *ms = MACHINE(obj);
74 
75     return g_strdup(ms->kernel_filename);
76 }
77 
78 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
79 {
80     MachineState *ms = MACHINE(obj);
81 
82     ms->kernel_filename = g_strdup(value);
83 }
84 
85 static char *machine_get_initrd(Object *obj, Error **errp)
86 {
87     MachineState *ms = MACHINE(obj);
88 
89     return g_strdup(ms->initrd_filename);
90 }
91 
92 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
93 {
94     MachineState *ms = MACHINE(obj);
95 
96     ms->initrd_filename = g_strdup(value);
97 }
98 
99 static char *machine_get_append(Object *obj, Error **errp)
100 {
101     MachineState *ms = MACHINE(obj);
102 
103     return g_strdup(ms->kernel_cmdline);
104 }
105 
106 static void machine_set_append(Object *obj, const char *value, Error **errp)
107 {
108     MachineState *ms = MACHINE(obj);
109 
110     ms->kernel_cmdline = g_strdup(value);
111 }
112 
113 static char *machine_get_dtb(Object *obj, Error **errp)
114 {
115     MachineState *ms = MACHINE(obj);
116 
117     return g_strdup(ms->dtb);
118 }
119 
120 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
121 {
122     MachineState *ms = MACHINE(obj);
123 
124     ms->dtb = g_strdup(value);
125 }
126 
127 static char *machine_get_dumpdtb(Object *obj, Error **errp)
128 {
129     MachineState *ms = MACHINE(obj);
130 
131     return g_strdup(ms->dumpdtb);
132 }
133 
134 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
135 {
136     MachineState *ms = MACHINE(obj);
137 
138     ms->dumpdtb = g_strdup(value);
139 }
140 
141 static void machine_get_phandle_start(Object *obj, Visitor *v,
142                                        void *opaque, const char *name,
143                                        Error **errp)
144 {
145     MachineState *ms = MACHINE(obj);
146     int64_t value = ms->phandle_start;
147 
148     visit_type_int(v, &value, name, errp);
149 }
150 
151 static void machine_set_phandle_start(Object *obj, Visitor *v,
152                                        void *opaque, const char *name,
153                                        Error **errp)
154 {
155     MachineState *ms = MACHINE(obj);
156     Error *error = NULL;
157     int64_t value;
158 
159     visit_type_int(v, &value, name, &error);
160     if (error) {
161         error_propagate(errp, error);
162         return;
163     }
164 
165     ms->phandle_start = value;
166 }
167 
168 static char *machine_get_dt_compatible(Object *obj, Error **errp)
169 {
170     MachineState *ms = MACHINE(obj);
171 
172     return g_strdup(ms->dt_compatible);
173 }
174 
175 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
176 {
177     MachineState *ms = MACHINE(obj);
178 
179     ms->dt_compatible = g_strdup(value);
180 }
181 
182 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
183 {
184     MachineState *ms = MACHINE(obj);
185 
186     return ms->dump_guest_core;
187 }
188 
189 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
190 {
191     MachineState *ms = MACHINE(obj);
192 
193     ms->dump_guest_core = value;
194 }
195 
196 static bool machine_get_mem_merge(Object *obj, Error **errp)
197 {
198     MachineState *ms = MACHINE(obj);
199 
200     return ms->mem_merge;
201 }
202 
203 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
204 {
205     MachineState *ms = MACHINE(obj);
206 
207     ms->mem_merge = value;
208 }
209 
210 static bool machine_get_usb(Object *obj, Error **errp)
211 {
212     MachineState *ms = MACHINE(obj);
213 
214     return ms->usb;
215 }
216 
217 static void machine_set_usb(Object *obj, bool value, Error **errp)
218 {
219     MachineState *ms = MACHINE(obj);
220 
221     ms->usb = value;
222 }
223 
224 static char *machine_get_firmware(Object *obj, Error **errp)
225 {
226     MachineState *ms = MACHINE(obj);
227 
228     return g_strdup(ms->firmware);
229 }
230 
231 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
232 {
233     MachineState *ms = MACHINE(obj);
234 
235     ms->firmware = g_strdup(value);
236 }
237 
238 static bool machine_get_iommu(Object *obj, Error **errp)
239 {
240     MachineState *ms = MACHINE(obj);
241 
242     return ms->iommu;
243 }
244 
245 static void machine_set_iommu(Object *obj, bool value, Error **errp)
246 {
247     MachineState *ms = MACHINE(obj);
248 
249     ms->iommu = value;
250 }
251 
252 static void machine_initfn(Object *obj)
253 {
254     object_property_add_str(obj, "accel",
255                             machine_get_accel, machine_set_accel, NULL);
256     object_property_add_bool(obj, "kernel-irqchip",
257                              machine_get_kernel_irqchip,
258                              machine_set_kernel_irqchip,
259                              NULL);
260     object_property_add(obj, "kvm-shadow-mem", "int",
261                         machine_get_kvm_shadow_mem,
262                         machine_set_kvm_shadow_mem,
263                         NULL, NULL, NULL);
264     object_property_add_str(obj, "kernel",
265                             machine_get_kernel, machine_set_kernel, NULL);
266     object_property_add_str(obj, "initrd",
267                             machine_get_initrd, machine_set_initrd, NULL);
268     object_property_add_str(obj, "append",
269                             machine_get_append, machine_set_append, NULL);
270     object_property_add_str(obj, "dtb",
271                             machine_get_dtb, machine_set_dtb, NULL);
272     object_property_add_str(obj, "dumpdtb",
273                             machine_get_dumpdtb, machine_set_dumpdtb, NULL);
274     object_property_add(obj, "phandle-start", "int",
275                         machine_get_phandle_start,
276                         machine_set_phandle_start,
277                         NULL, NULL, NULL);
278     object_property_add_str(obj, "dt-compatible",
279                             machine_get_dt_compatible,
280                             machine_set_dt_compatible,
281                             NULL);
282     object_property_add_bool(obj, "dump-guest-core",
283                              machine_get_dump_guest_core,
284                              machine_set_dump_guest_core,
285                              NULL);
286     object_property_add_bool(obj, "mem-merge",
287                              machine_get_mem_merge,
288                              machine_set_mem_merge, NULL);
289     object_property_add_bool(obj, "usb",
290                              machine_get_usb,
291                              machine_set_usb, NULL);
292     object_property_add_str(obj, "firmware",
293                             machine_get_firmware,
294                             machine_set_firmware, NULL);
295     object_property_add_bool(obj, "iommu",
296                              machine_get_iommu,
297                              machine_set_iommu, NULL);
298 }
299 
300 static void machine_finalize(Object *obj)
301 {
302     MachineState *ms = MACHINE(obj);
303 
304     g_free(ms->accel);
305     g_free(ms->kernel_filename);
306     g_free(ms->initrd_filename);
307     g_free(ms->kernel_cmdline);
308     g_free(ms->dtb);
309     g_free(ms->dumpdtb);
310     g_free(ms->dt_compatible);
311     g_free(ms->firmware);
312 }
313 
314 static const TypeInfo machine_info = {
315     .name = TYPE_MACHINE,
316     .parent = TYPE_OBJECT,
317     .abstract = true,
318     .class_size = sizeof(MachineClass),
319     .instance_size = sizeof(MachineState),
320     .instance_init = machine_initfn,
321     .instance_finalize = machine_finalize,
322 };
323 
324 static void machine_register_types(void)
325 {
326     type_register_static(&machine_info);
327 }
328 
329 type_init(machine_register_types)
330