pc: acpi: cpuhp: move PRSC() method into SSDT
[qemu.git] / hw / acpi / cpu_hotplug_acpi_table.c
blob8dda4f423fb219915ad64fe0f0a9a08a89ecb127
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, see <http://www.gnu.org/licenses/>.
16 #include "hw/acpi/cpu_hotplug.h"
18 void build_cpu_hotplug_aml(Aml *ctx)
20 Aml *method;
21 Aml *if_ctx;
22 Aml *else_ctx;
23 Aml *sb_scope = aml_scope("_SB");
24 uint8_t madt_tmpl[8] = {0x00, 0x08, 0x00, 0x00, 0x00, 0, 0, 0};
25 Aml *cpu_id = aml_arg(0);
26 Aml *cpu_on = aml_local(0);
27 Aml *madt = aml_local(1);
28 Aml *cpus_map = aml_name(CPU_ON_BITMAP);
29 Aml *zero = aml_int(0);
30 Aml *one = aml_int(1);
33 * _MAT method - creates an madt apic buffer
34 * cpu_id = Arg0 = Processor ID = Local APIC ID
35 * cpu_on = Local0 = CPON flag for this cpu
36 * madt = Local1 = Buffer (in madt apic form) to return
38 method = aml_method(CPU_MAT_METHOD, 1, AML_NOTSERIALIZED);
39 aml_append(method,
40 aml_store(aml_derefof(aml_index(cpus_map, cpu_id)), cpu_on));
41 aml_append(method,
42 aml_store(aml_buffer(sizeof(madt_tmpl), madt_tmpl), madt));
43 /* Update the processor id, lapic id, and enable/disable status */
44 aml_append(method, aml_store(cpu_id, aml_index(madt, aml_int(2))));
45 aml_append(method, aml_store(cpu_id, aml_index(madt, aml_int(3))));
46 aml_append(method, aml_store(cpu_on, aml_index(madt, aml_int(4))));
47 aml_append(method, aml_return(madt));
48 aml_append(sb_scope, method);
51 * _STA method - return ON status of cpu
52 * cpu_id = Arg0 = Processor ID = Local APIC ID
53 * cpu_on = Local0 = CPON flag for this cpu
55 method = aml_method(CPU_STATUS_METHOD, 1, AML_NOTSERIALIZED);
56 aml_append(method,
57 aml_store(aml_derefof(aml_index(cpus_map, cpu_id)), cpu_on));
58 if_ctx = aml_if(cpu_on);
60 aml_append(if_ctx, aml_return(aml_int(0xF)));
62 aml_append(method, if_ctx);
63 else_ctx = aml_else();
65 aml_append(else_ctx, aml_return(zero));
67 aml_append(method, else_ctx);
68 aml_append(sb_scope, method);
70 method = aml_method(CPU_EJECT_METHOD, 2, AML_NOTSERIALIZED);
71 aml_append(method, aml_sleep(200));
72 aml_append(sb_scope, method);
74 method = aml_method(stringify(CPU_SCAN_METHOD), 0, AML_NOTSERIALIZED);
76 Aml *while_ctx, *if_ctx2, *else_ctx2;
77 Aml *bus_check_evt = aml_int(1);
78 Aml *remove_evt = aml_int(3);
79 Aml *status_map = aml_local(5); /* Local5 = active cpu bitmap */
80 Aml *byte = aml_local(2); /* Local2 = last read byte from bitmap */
81 Aml *idx = aml_local(0); /* Processor ID / APIC ID iterator */
82 Aml *is_cpu_on = aml_local(1); /* Local1 = CPON flag for cpu */
83 Aml *status = aml_local(3); /* Local3 = active state for cpu */
85 aml_append(method, aml_store(aml_name(CPU_STATUS_MAP), status_map));
86 aml_append(method, aml_store(zero, byte));
87 aml_append(method, aml_store(zero, idx));
89 /* While (idx < SizeOf(CPON)) */
90 while_ctx = aml_while(aml_lless(idx, aml_sizeof(cpus_map)));
91 aml_append(while_ctx,
92 aml_store(aml_derefof(aml_index(cpus_map, idx)), is_cpu_on));
94 if_ctx = aml_if(aml_and(idx, aml_int(0x07), NULL));
96 /* Shift down previously read bitmap byte */
97 aml_append(if_ctx, aml_shiftright(byte, one, byte));
99 aml_append(while_ctx, if_ctx);
101 else_ctx = aml_else();
103 /* Read next byte from cpu bitmap */
104 aml_append(else_ctx, aml_store(aml_derefof(aml_index(status_map,
105 aml_shiftright(idx, aml_int(3), NULL))), byte));
107 aml_append(while_ctx, else_ctx);
109 aml_append(while_ctx, aml_store(aml_and(byte, one, NULL), status));
110 if_ctx = aml_if(aml_lnot(aml_equal(is_cpu_on, status)));
112 /* State change - update CPON with new state */
113 aml_append(if_ctx, aml_store(status, aml_index(cpus_map, idx)));
114 if_ctx2 = aml_if(aml_equal(status, one));
116 aml_append(if_ctx2,
117 aml_call2(AML_NOTIFY_METHOD, idx, bus_check_evt));
119 aml_append(if_ctx, if_ctx2);
120 else_ctx2 = aml_else();
122 aml_append(else_ctx2,
123 aml_call2(AML_NOTIFY_METHOD, idx, remove_evt));
126 aml_append(if_ctx, else_ctx2);
127 aml_append(while_ctx, if_ctx);
129 aml_append(while_ctx, aml_increment(idx)); /* go to next cpu */
130 aml_append(method, while_ctx);
132 aml_append(sb_scope, method);
134 aml_append(ctx, sb_scope);