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 "qemu/osdep.h"
17 #include "hw/acpi/cpu_hotplug.h"
19 void build_cpu_hotplug_aml(Aml
*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);
34 * _MAT method - creates an madt apic buffer
35 * cpu_id = Arg0 = Processor ID = Local APIC ID
36 * cpu_on = Local0 = CPON flag for this cpu
37 * madt = Local1 = Buffer (in madt apic form) to return
39 method
= aml_method(CPU_MAT_METHOD
, 1, AML_NOTSERIALIZED
);
41 aml_store(aml_derefof(aml_index(cpus_map
, cpu_id
)), cpu_on
));
43 aml_store(aml_buffer(sizeof(madt_tmpl
), madt_tmpl
), madt
));
44 /* Update the processor id, lapic id, and enable/disable status */
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
);
52 * _STA method - return ON status of cpu
53 * cpu_id = Arg0 = Processor ID = Local APIC ID
54 * cpu_on = Local0 = CPON flag for this cpu
56 method
= aml_method(CPU_STATUS_METHOD
, 1, AML_NOTSERIALIZED
);
58 aml_store(aml_derefof(aml_index(cpus_map
, cpu_id
)), cpu_on
));
59 if_ctx
= aml_if(cpu_on
);
61 aml_append(if_ctx
, aml_return(aml_int(0xF)));
63 aml_append(method
, if_ctx
);
64 else_ctx
= aml_else();
66 aml_append(else_ctx
, aml_return(zero
));
68 aml_append(method
, else_ctx
);
69 aml_append(sb_scope
, method
);
71 method
= aml_method(CPU_EJECT_METHOD
, 2, AML_NOTSERIALIZED
);
72 aml_append(method
, aml_sleep(200));
73 aml_append(sb_scope
, method
);
75 method
= aml_method(CPU_SCAN_METHOD
, 0, AML_NOTSERIALIZED
);
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); /* Local5 = active cpu bitmap */
81 Aml
*byte
= aml_local(2); /* Local2 = last read byte from bitmap */
82 Aml
*idx
= aml_local(0); /* Processor ID / APIC ID iterator */
83 Aml
*is_cpu_on
= aml_local(1); /* Local1 = CPON flag for cpu */
84 Aml
*status
= aml_local(3); /* Local3 = active state for cpu */
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
));
90 /* While (idx < SizeOf(CPON)) */
91 while_ctx
= aml_while(aml_lless(idx
, aml_sizeof(cpus_map
)));
93 aml_store(aml_derefof(aml_index(cpus_map
, idx
)), is_cpu_on
));
95 if_ctx
= aml_if(aml_and(idx
, aml_int(0x07), NULL
));
97 /* Shift down previously read bitmap byte */
98 aml_append(if_ctx
, aml_shiftright(byte
, one
, byte
));
100 aml_append(while_ctx
, if_ctx
);
102 else_ctx
= aml_else();
104 /* Read next byte from cpu bitmap */
105 aml_append(else_ctx
, aml_store(aml_derefof(aml_index(status_map
,
106 aml_shiftright(idx
, aml_int(3), NULL
))), byte
));
108 aml_append(while_ctx
, else_ctx
);
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
)));
113 /* State change - update CPON with new state */
114 aml_append(if_ctx
, aml_store(status
, aml_index(cpus_map
, idx
)));
115 if_ctx2
= aml_if(aml_equal(status
, one
));
118 aml_call2(AML_NOTIFY_METHOD
, idx
, bus_check_evt
));
120 aml_append(if_ctx
, if_ctx2
);
121 else_ctx2
= aml_else();
123 aml_append(else_ctx2
,
124 aml_call2(AML_NOTIFY_METHOD
, idx
, remove_evt
));
127 aml_append(if_ctx
, else_ctx2
);
128 aml_append(while_ctx
, if_ctx
);
130 aml_append(while_ctx
, aml_increment(idx
)); /* go to next cpu */
131 aml_append(method
, while_ctx
);
133 aml_append(sb_scope
, method
);
135 aml_append(ctx
, sb_scope
);