root / target-ppc / kvm_ppc.c @ a8a358bf
History | View | Annotate | Download (2.6 kB)
1 | d76d1650 | aurel32 | /*
|
---|---|---|---|
2 | d76d1650 | aurel32 | * PowerPC KVM support
|
3 | d76d1650 | aurel32 | *
|
4 | d76d1650 | aurel32 | * Copyright IBM Corp. 2008
|
5 | d76d1650 | aurel32 | *
|
6 | d76d1650 | aurel32 | * Authors:
|
7 | d76d1650 | aurel32 | * Hollis Blanchard <hollisb@us.ibm.com>
|
8 | d76d1650 | aurel32 | *
|
9 | d76d1650 | aurel32 | * This work is licensed under the terms of the GNU GPL, version 2 or later.
|
10 | d76d1650 | aurel32 | * See the COPYING file in the top-level directory.
|
11 | d76d1650 | aurel32 | *
|
12 | d76d1650 | aurel32 | */
|
13 | d76d1650 | aurel32 | |
14 | d76d1650 | aurel32 | #include "qemu-common.h" |
15 | d76d1650 | aurel32 | #include "qemu-timer.h" |
16 | d76d1650 | aurel32 | #include "kvm_ppc.h" |
17 | d76d1650 | aurel32 | #include "device_tree.h" |
18 | d76d1650 | aurel32 | |
19 | d76d1650 | aurel32 | #define PROC_DEVTREE_PATH "/proc/device-tree" |
20 | d76d1650 | aurel32 | |
21 | d76d1650 | aurel32 | static QEMUTimer *kvmppc_timer;
|
22 | d76d1650 | aurel32 | static unsigned int kvmppc_timer_rate; |
23 | d76d1650 | aurel32 | |
24 | 3f0855b1 | Juan Quintela | #ifdef CONFIG_FDT
|
25 | ea23bc20 | aurel32 | int kvmppc_read_host_property(const char *node_path, const char *prop, |
26 | d76d1650 | aurel32 | void *val, size_t len)
|
27 | d76d1650 | aurel32 | { |
28 | d76d1650 | aurel32 | char *path;
|
29 | d76d1650 | aurel32 | FILE *f; |
30 | 57be80f9 | aliguori | int ret = 0; |
31 | d76d1650 | aurel32 | int pathlen;
|
32 | d76d1650 | aurel32 | |
33 | d76d1650 | aurel32 | pathlen = snprintf(NULL, 0, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop) |
34 | d76d1650 | aurel32 | + 1;
|
35 | d76d1650 | aurel32 | path = qemu_malloc(pathlen); |
36 | d76d1650 | aurel32 | |
37 | d76d1650 | aurel32 | snprintf(path, pathlen, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop);
|
38 | d76d1650 | aurel32 | |
39 | d76d1650 | aurel32 | f = fopen(path, "rb");
|
40 | d76d1650 | aurel32 | if (f == NULL) { |
41 | d76d1650 | aurel32 | ret = errno; |
42 | d76d1650 | aurel32 | goto free;
|
43 | d76d1650 | aurel32 | } |
44 | d76d1650 | aurel32 | |
45 | d76d1650 | aurel32 | len = fread(val, len, 1, f);
|
46 | d76d1650 | aurel32 | if (len != 1) { |
47 | d76d1650 | aurel32 | ret = ferror(f); |
48 | d76d1650 | aurel32 | goto close;
|
49 | d76d1650 | aurel32 | } |
50 | d76d1650 | aurel32 | |
51 | d76d1650 | aurel32 | close:
|
52 | d76d1650 | aurel32 | fclose(f); |
53 | d76d1650 | aurel32 | free:
|
54 | d76d1650 | aurel32 | free(path); |
55 | d76d1650 | aurel32 | out:
|
56 | d76d1650 | aurel32 | return ret;
|
57 | d76d1650 | aurel32 | } |
58 | d76d1650 | aurel32 | |
59 | d76d1650 | aurel32 | static int kvmppc_copy_host_cell(void *fdt, const char *node, const char *prop) |
60 | d76d1650 | aurel32 | { |
61 | d76d1650 | aurel32 | uint32_t cell; |
62 | d76d1650 | aurel32 | int ret;
|
63 | d76d1650 | aurel32 | |
64 | d76d1650 | aurel32 | ret = kvmppc_read_host_property(node, prop, &cell, sizeof(cell));
|
65 | d76d1650 | aurel32 | if (ret < 0) { |
66 | d76d1650 | aurel32 | fprintf(stderr, "couldn't read host %s/%s\n", node, prop);
|
67 | d76d1650 | aurel32 | goto out;
|
68 | d76d1650 | aurel32 | } |
69 | d76d1650 | aurel32 | |
70 | d76d1650 | aurel32 | ret = qemu_devtree_setprop_cell(fdt, node, prop, cell); |
71 | d76d1650 | aurel32 | if (ret < 0) { |
72 | d76d1650 | aurel32 | fprintf(stderr, "couldn't set guest %s/%s\n", node, prop);
|
73 | d76d1650 | aurel32 | goto out;
|
74 | d76d1650 | aurel32 | } |
75 | d76d1650 | aurel32 | |
76 | d76d1650 | aurel32 | out:
|
77 | d76d1650 | aurel32 | return ret;
|
78 | d76d1650 | aurel32 | } |
79 | d76d1650 | aurel32 | |
80 | d76d1650 | aurel32 | void kvmppc_fdt_update(void *fdt) |
81 | d76d1650 | aurel32 | { |
82 | d76d1650 | aurel32 | /* Copy data from the host device tree into the guest. Since the guest can
|
83 | d76d1650 | aurel32 | * directly access the timebase without host involvement, we must expose
|
84 | d76d1650 | aurel32 | * the correct frequencies. */
|
85 | d76d1650 | aurel32 | kvmppc_copy_host_cell(fdt, "/cpus/cpu@0", "clock-frequency"); |
86 | d76d1650 | aurel32 | kvmppc_copy_host_cell(fdt, "/cpus/cpu@0", "timebase-frequency"); |
87 | d76d1650 | aurel32 | } |
88 | d76d1650 | aurel32 | #endif
|
89 | d76d1650 | aurel32 | |
90 | d76d1650 | aurel32 | static void kvmppc_timer_hack(void *opaque) |
91 | d76d1650 | aurel32 | { |
92 | d76d1650 | aurel32 | qemu_service_io(); |
93 | d76d1650 | aurel32 | qemu_mod_timer(kvmppc_timer, qemu_get_clock(vm_clock) + kvmppc_timer_rate); |
94 | d76d1650 | aurel32 | } |
95 | d76d1650 | aurel32 | |
96 | d76d1650 | aurel32 | void kvmppc_init(void) |
97 | d76d1650 | aurel32 | { |
98 | d76d1650 | aurel32 | /* XXX The only reason KVM yields control back to qemu is device IO. Since
|
99 | d76d1650 | aurel32 | * an idle guest does no IO, qemu's device model will never get a chance to
|
100 | d76d1650 | aurel32 | * run. So, until Qemu gains IO threads, we create this timer to ensure
|
101 | d76d1650 | aurel32 | * that the device model gets a chance to run. */
|
102 | d76d1650 | aurel32 | kvmppc_timer_rate = ticks_per_sec / 10;
|
103 | d76d1650 | aurel32 | kvmppc_timer = qemu_new_timer(vm_clock, &kvmppc_timer_hack, NULL);
|
104 | d76d1650 | aurel32 | qemu_mod_timer(kvmppc_timer, qemu_get_clock(vm_clock) + kvmppc_timer_rate); |
105 | d76d1650 | aurel32 | } |