Replace noreturn with QEMU_NORETURN
[qemu-kvm/fedora.git] / target-ppc / kvm_ppc.c
blob82c0f42098238d623a7f069386a68b397e3061dc
1 /*
2 * PowerPC KVM support
4 * Copyright IBM Corp. 2008
6 * Authors:
7 * Hollis Blanchard <hollisb@us.ibm.com>
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.
14 #include "qemu-common.h"
15 #include "qemu-timer.h"
16 #include "kvm_ppc.h"
17 #include "device_tree.h"
19 #define PROC_DEVTREE_PATH "/proc/device-tree"
21 static QEMUTimer *kvmppc_timer;
22 static unsigned int kvmppc_timer_rate;
24 #ifdef HAVE_FDT
25 int kvmppc_read_host_property(const char *node_path, const char *prop,
26 void *val, size_t len)
28 char *path;
29 FILE *f;
30 int ret = 0;
31 int pathlen;
33 pathlen = snprintf(NULL, 0, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop)
34 + 1;
35 path = qemu_malloc(pathlen);
36 if (path == NULL) {
37 ret = -ENOMEM;
38 goto out;
41 snprintf(path, pathlen, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop);
43 f = fopen(path, "rb");
44 if (f == NULL) {
45 ret = errno;
46 goto free;
49 len = fread(val, len, 1, f);
50 if (len != 1) {
51 ret = ferror(f);
52 goto close;
55 close:
56 fclose(f);
57 free:
58 free(path);
59 out:
60 return ret;
63 static int kvmppc_copy_host_cell(void *fdt, const char *node, const char *prop)
65 uint32_t cell;
66 int ret;
68 ret = kvmppc_read_host_property(node, prop, &cell, sizeof(cell));
69 if (ret < 0) {
70 fprintf(stderr, "couldn't read host %s/%s\n", node, prop);
71 goto out;
74 ret = qemu_devtree_setprop_cell(fdt, node, prop, cell);
75 if (ret < 0) {
76 fprintf(stderr, "couldn't set guest %s/%s\n", node, prop);
77 goto out;
80 out:
81 return ret;
84 void kvmppc_fdt_update(void *fdt)
86 /* Copy data from the host device tree into the guest. Since the guest can
87 * directly access the timebase without host involvement, we must expose
88 * the correct frequencies. */
89 kvmppc_copy_host_cell(fdt, "/cpus/cpu@0", "clock-frequency");
90 kvmppc_copy_host_cell(fdt, "/cpus/cpu@0", "timebase-frequency");
92 #endif
94 static void kvmppc_timer_hack(void *opaque)
96 qemu_service_io();
97 qemu_mod_timer(kvmppc_timer, qemu_get_clock(vm_clock) + kvmppc_timer_rate);
100 void kvmppc_init(void)
102 /* XXX The only reason KVM yields control back to qemu is device IO. Since
103 * an idle guest does no IO, qemu's device model will never get a chance to
104 * run. So, until Qemu gains IO threads, we create this timer to ensure
105 * that the device model gets a chance to run. */
106 kvmppc_timer_rate = ticks_per_sec / 10;
107 kvmppc_timer = qemu_new_timer(vm_clock, &kvmppc_timer_hack, NULL);
108 qemu_mod_timer(kvmppc_timer, qemu_get_clock(vm_clock) + kvmppc_timer_rate);