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