1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "qemu/osdep.h"
17#include "hw/acpi/cpu_hotplug.h"
18
19void build_cpu_hotplug_aml(Aml *ctx)
20{
21 Aml *method;
22 Aml *if_ctx;
23 Aml *else_ctx;
24 Aml *sb_scope = aml_scope("_SB");
25 uint8_t madt_tmpl[8] = {0x00, 0x08, 0x00, 0x00, 0x00, 0, 0, 0};
26 Aml *cpu_id = aml_arg(0);
27 Aml *cpu_on = aml_local(0);
28 Aml *madt = aml_local(1);
29 Aml *cpus_map = aml_name(CPU_ON_BITMAP);
30 Aml *zero = aml_int(0);
31 Aml *one = aml_int(1);
32
33
34
35
36
37
38
39 method = aml_method(CPU_MAT_METHOD, 1, AML_NOTSERIALIZED);
40 aml_append(method,
41 aml_store(aml_derefof(aml_index(cpus_map, cpu_id)), cpu_on));
42 aml_append(method,
43 aml_store(aml_buffer(sizeof(madt_tmpl), madt_tmpl), madt));
44
45 aml_append(method, aml_store(cpu_id, aml_index(madt, aml_int(2))));
46 aml_append(method, aml_store(cpu_id, aml_index(madt, aml_int(3))));
47 aml_append(method, aml_store(cpu_on, aml_index(madt, aml_int(4))));
48 aml_append(method, aml_return(madt));
49 aml_append(sb_scope, method);
50
51
52
53
54
55
56 method = aml_method(CPU_STATUS_METHOD, 1, AML_NOTSERIALIZED);
57 aml_append(method,
58 aml_store(aml_derefof(aml_index(cpus_map, cpu_id)), cpu_on));
59 if_ctx = aml_if(cpu_on);
60 {
61 aml_append(if_ctx, aml_return(aml_int(0xF)));
62 }
63 aml_append(method, if_ctx);
64 else_ctx = aml_else();
65 {
66 aml_append(else_ctx, aml_return(zero));
67 }
68 aml_append(method, else_ctx);
69 aml_append(sb_scope, method);
70
71 method = aml_method(CPU_EJECT_METHOD, 2, AML_NOTSERIALIZED);
72 aml_append(method, aml_sleep(200));
73 aml_append(sb_scope, method);
74
75 method = aml_method(CPU_SCAN_METHOD, 0, AML_NOTSERIALIZED);
76 {
77 Aml *while_ctx, *if_ctx2, *else_ctx2;
78 Aml *bus_check_evt = aml_int(1);
79 Aml *remove_evt = aml_int(3);
80 Aml *status_map = aml_local(5);
81 Aml *byte = aml_local(2);
82 Aml *idx = aml_local(0);
83 Aml *is_cpu_on = aml_local(1);
84 Aml *status = aml_local(3);
85
86 aml_append(method, aml_store(aml_name(CPU_STATUS_MAP), status_map));
87 aml_append(method, aml_store(zero, byte));
88 aml_append(method, aml_store(zero, idx));
89
90
91 while_ctx = aml_while(aml_lless(idx, aml_sizeof(cpus_map)));
92 aml_append(while_ctx,
93 aml_store(aml_derefof(aml_index(cpus_map, idx)), is_cpu_on));
94
95 if_ctx = aml_if(aml_and(idx, aml_int(0x07), NULL));
96 {
97
98 aml_append(if_ctx, aml_shiftright(byte, one, byte));
99 }
100 aml_append(while_ctx, if_ctx);
101
102 else_ctx = aml_else();
103 {
104
105 aml_append(else_ctx, aml_store(aml_derefof(aml_index(status_map,
106 aml_shiftright(idx, aml_int(3), NULL))), byte));
107 }
108 aml_append(while_ctx, else_ctx);
109
110 aml_append(while_ctx, aml_store(aml_and(byte, one, NULL), status));
111 if_ctx = aml_if(aml_lnot(aml_equal(is_cpu_on, status)));
112 {
113
114 aml_append(if_ctx, aml_store(status, aml_index(cpus_map, idx)));
115 if_ctx2 = aml_if(aml_equal(status, one));
116 {
117 aml_append(if_ctx2,
118 aml_call2(AML_NOTIFY_METHOD, idx, bus_check_evt));
119 }
120 aml_append(if_ctx, if_ctx2);
121 else_ctx2 = aml_else();
122 {
123 aml_append(else_ctx2,
124 aml_call2(AML_NOTIFY_METHOD, idx, remove_evt));
125 }
126 }
127 aml_append(if_ctx, else_ctx2);
128 aml_append(while_ctx, if_ctx);
129
130 aml_append(while_ctx, aml_increment(idx));
131 aml_append(method, while_ctx);
132 }
133 aml_append(sb_scope, method);
134
135 aml_append(ctx, sb_scope);
136}
137