root / hw / spapr_rtas.c @ 39ac8455
History | View | Annotate | Download (4 kB)
1 | 39ac8455 | David Gibson | /*
|
---|---|---|---|
2 | 39ac8455 | David Gibson | * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
|
3 | 39ac8455 | David Gibson | *
|
4 | 39ac8455 | David Gibson | * Hypercall based emulated RTAS
|
5 | 39ac8455 | David Gibson | *
|
6 | 39ac8455 | David Gibson | * Copyright (c) 2010-2011 David Gibson, IBM Corporation.
|
7 | 39ac8455 | David Gibson | *
|
8 | 39ac8455 | David Gibson | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 | 39ac8455 | David Gibson | * of this software and associated documentation files (the "Software"), to deal
|
10 | 39ac8455 | David Gibson | * in the Software without restriction, including without limitation the rights
|
11 | 39ac8455 | David Gibson | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 | 39ac8455 | David Gibson | * copies of the Software, and to permit persons to whom the Software is
|
13 | 39ac8455 | David Gibson | * furnished to do so, subject to the following conditions:
|
14 | 39ac8455 | David Gibson | *
|
15 | 39ac8455 | David Gibson | * The above copyright notice and this permission notice shall be included in
|
16 | 39ac8455 | David Gibson | * all copies or substantial portions of the Software.
|
17 | 39ac8455 | David Gibson | *
|
18 | 39ac8455 | David Gibson | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19 | 39ac8455 | David Gibson | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20 | 39ac8455 | David Gibson | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
21 | 39ac8455 | David Gibson | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22 | 39ac8455 | David Gibson | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23 | 39ac8455 | David Gibson | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | 39ac8455 | David Gibson | * THE SOFTWARE.
|
25 | 39ac8455 | David Gibson | *
|
26 | 39ac8455 | David Gibson | */
|
27 | 39ac8455 | David Gibson | #include "cpu.h" |
28 | 39ac8455 | David Gibson | #include "sysemu.h" |
29 | 39ac8455 | David Gibson | #include "qemu-char.h" |
30 | 39ac8455 | David Gibson | #include "hw/qdev.h" |
31 | 39ac8455 | David Gibson | #include "device_tree.h" |
32 | 39ac8455 | David Gibson | |
33 | 39ac8455 | David Gibson | #include "hw/spapr.h" |
34 | 39ac8455 | David Gibson | #include "hw/spapr_vio.h" |
35 | 39ac8455 | David Gibson | |
36 | 39ac8455 | David Gibson | #include <libfdt.h> |
37 | 39ac8455 | David Gibson | |
38 | 39ac8455 | David Gibson | #define TOKEN_BASE 0x2000 |
39 | 39ac8455 | David Gibson | #define TOKEN_MAX 0x100 |
40 | 39ac8455 | David Gibson | |
41 | 39ac8455 | David Gibson | static struct rtas_call { |
42 | 39ac8455 | David Gibson | const char *name; |
43 | 39ac8455 | David Gibson | spapr_rtas_fn fn; |
44 | 39ac8455 | David Gibson | } rtas_table[TOKEN_MAX]; |
45 | 39ac8455 | David Gibson | |
46 | 39ac8455 | David Gibson | struct rtas_call *rtas_next = rtas_table;
|
47 | 39ac8455 | David Gibson | |
48 | 39ac8455 | David Gibson | target_ulong spapr_rtas_call(sPAPREnvironment *spapr, |
49 | 39ac8455 | David Gibson | uint32_t token, uint32_t nargs, target_ulong args, |
50 | 39ac8455 | David Gibson | uint32_t nret, target_ulong rets) |
51 | 39ac8455 | David Gibson | { |
52 | 39ac8455 | David Gibson | if ((token >= TOKEN_BASE)
|
53 | 39ac8455 | David Gibson | && ((token - TOKEN_BASE) < TOKEN_MAX)) { |
54 | 39ac8455 | David Gibson | struct rtas_call *call = rtas_table + (token - TOKEN_BASE);
|
55 | 39ac8455 | David Gibson | |
56 | 39ac8455 | David Gibson | if (call->fn) {
|
57 | 39ac8455 | David Gibson | call->fn(spapr, token, nargs, args, nret, rets); |
58 | 39ac8455 | David Gibson | return H_SUCCESS;
|
59 | 39ac8455 | David Gibson | } |
60 | 39ac8455 | David Gibson | } |
61 | 39ac8455 | David Gibson | |
62 | 39ac8455 | David Gibson | hcall_dprintf("Unknown RTAS token 0x%x\n", token);
|
63 | 39ac8455 | David Gibson | rtas_st(rets, 0, -3); |
64 | 39ac8455 | David Gibson | return H_PARAMETER;
|
65 | 39ac8455 | David Gibson | } |
66 | 39ac8455 | David Gibson | |
67 | 39ac8455 | David Gibson | void spapr_rtas_register(const char *name, spapr_rtas_fn fn) |
68 | 39ac8455 | David Gibson | { |
69 | 39ac8455 | David Gibson | assert(rtas_next < (rtas_table + TOKEN_MAX)); |
70 | 39ac8455 | David Gibson | |
71 | 39ac8455 | David Gibson | rtas_next->name = name; |
72 | 39ac8455 | David Gibson | rtas_next->fn = fn; |
73 | 39ac8455 | David Gibson | |
74 | 39ac8455 | David Gibson | rtas_next++; |
75 | 39ac8455 | David Gibson | } |
76 | 39ac8455 | David Gibson | |
77 | 39ac8455 | David Gibson | int spapr_rtas_device_tree_setup(void *fdt, target_phys_addr_t rtas_addr, |
78 | 39ac8455 | David Gibson | target_phys_addr_t rtas_size) |
79 | 39ac8455 | David Gibson | { |
80 | 39ac8455 | David Gibson | int ret;
|
81 | 39ac8455 | David Gibson | int i;
|
82 | 39ac8455 | David Gibson | |
83 | 39ac8455 | David Gibson | ret = fdt_add_mem_rsv(fdt, rtas_addr, rtas_size); |
84 | 39ac8455 | David Gibson | if (ret < 0) { |
85 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add RTAS reserve entry: %s\n",
|
86 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
87 | 39ac8455 | David Gibson | return ret;
|
88 | 39ac8455 | David Gibson | } |
89 | 39ac8455 | David Gibson | |
90 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", "linux,rtas-base", |
91 | 39ac8455 | David Gibson | rtas_addr); |
92 | 39ac8455 | David Gibson | if (ret < 0) { |
93 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add linux,rtas-base property: %s\n",
|
94 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
95 | 39ac8455 | David Gibson | return ret;
|
96 | 39ac8455 | David Gibson | } |
97 | 39ac8455 | David Gibson | |
98 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", "linux,rtas-entry", |
99 | 39ac8455 | David Gibson | rtas_addr); |
100 | 39ac8455 | David Gibson | if (ret < 0) { |
101 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add linux,rtas-entry property: %s\n",
|
102 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
103 | 39ac8455 | David Gibson | return ret;
|
104 | 39ac8455 | David Gibson | } |
105 | 39ac8455 | David Gibson | |
106 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", "rtas-size", |
107 | 39ac8455 | David Gibson | rtas_size); |
108 | 39ac8455 | David Gibson | if (ret < 0) { |
109 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add rtas-size property: %s\n",
|
110 | 39ac8455 | David Gibson | fdt_strerror(ret)); |
111 | 39ac8455 | David Gibson | return ret;
|
112 | 39ac8455 | David Gibson | } |
113 | 39ac8455 | David Gibson | |
114 | 39ac8455 | David Gibson | for (i = 0; i < TOKEN_MAX; i++) { |
115 | 39ac8455 | David Gibson | struct rtas_call *call = &rtas_table[i];
|
116 | 39ac8455 | David Gibson | |
117 | 39ac8455 | David Gibson | if (!call->fn) {
|
118 | 39ac8455 | David Gibson | continue;
|
119 | 39ac8455 | David Gibson | } |
120 | 39ac8455 | David Gibson | |
121 | 39ac8455 | David Gibson | ret = qemu_devtree_setprop_cell(fdt, "/rtas", call->name,
|
122 | 39ac8455 | David Gibson | i + TOKEN_BASE); |
123 | 39ac8455 | David Gibson | if (ret < 0) { |
124 | 39ac8455 | David Gibson | fprintf(stderr, "Couldn't add rtas token for %s: %s\n",
|
125 | 39ac8455 | David Gibson | call->name, fdt_strerror(ret)); |
126 | 39ac8455 | David Gibson | return ret;
|
127 | 39ac8455 | David Gibson | } |
128 | 39ac8455 | David Gibson | |
129 | 39ac8455 | David Gibson | } |
130 | 39ac8455 | David Gibson | return 0; |
131 | 39ac8455 | David Gibson | } |