@@ -51,6 +51,8 @@ pub const CPU_CONTAINER_ACPI_SIZE: usize = 0xC;
51
51
52
52
const CPU_ENABLE_BIT : u8 = 1 << 0 ;
53
53
const CPU_INSERTING_BIT : u8 = 1 << 1 ;
54
+ const CPU_REMOVING_BIT : u8 = 1 << 2 ;
55
+ const CPU_EJECT_BIT : u8 = 1 << 3 ;
54
56
55
57
const CPU_SELECTION_OFFSET : u64 = 0 ;
56
58
const CPU_STATUS_OFFSET : u64 = 4 ;
@@ -94,6 +96,7 @@ impl CpuContainer {
94
96
cpu_id : i,
95
97
active : i < boot_count,
96
98
inserting : false ,
99
+ removing : false ,
97
100
} )
98
101
}
99
102
@@ -123,6 +126,9 @@ impl CpuContainer {
123
126
if cpu_device. inserting {
124
127
data[ 0 ] |= CPU_INSERTING_BIT ;
125
128
}
129
+ if cpu_device. removing {
130
+ data[ 0 ] |= CPU_REMOVING_BIT ;
131
+ }
126
132
} else {
127
133
error ! ( "Out of range vCPU id: {}" , self . selected_cpu)
128
134
}
@@ -143,6 +149,10 @@ impl CpuContainer {
143
149
if data[ 0 ] & CPU_ENABLE_BIT != 0 {
144
150
cpu_device. active = true ;
145
151
}
152
+ if data[ 0 ] & CPU_EJECT_BIT != 0 {
153
+ cpu_device. active = false ;
154
+ // TODO: Remove vCPU handle from VMM
155
+ }
146
156
} else {
147
157
error ! ( "Out of range vCPU id: {}" , self . selected_cpu)
148
158
}
@@ -215,7 +225,9 @@ impl Aml for CpuContainer {
215
225
aml:: FieldEntry :: Reserved ( 32 ) ,
216
226
aml:: FieldEntry :: Named ( * b"CPEN" , 1 ) ,
217
227
aml:: FieldEntry :: Named ( * b"CINS" , 1 ) ,
218
- aml:: FieldEntry :: Reserved ( 6 ) ,
228
+ aml:: FieldEntry :: Named ( * b"CRMV" , 1 ) ,
229
+ aml:: FieldEntry :: Named ( * b"CEJ0" , 1 ) ,
230
+ aml:: FieldEntry :: Reserved ( 4 ) ,
219
231
aml:: FieldEntry :: Named ( * b"CCMD" , 8 ) ,
220
232
] ,
221
233
) ,
@@ -270,6 +282,8 @@ pub struct CpuDevice {
270
282
pub active : bool ,
271
283
/// Whether this CPU is in the process of being inserted
272
284
pub inserting : bool ,
285
+ /// Whether this CPU is in the process of being removed
286
+ pub removing : bool ,
273
287
}
274
288
275
289
impl CpuDevice {
@@ -305,6 +319,16 @@ impl Aml for CpuDevice {
305
319
) ) ] ,
306
320
) ,
307
321
& aml:: Name :: new( "_MAT" . into( ) , & aml:: Buffer :: new( mat_data) ) ,
322
+ & aml:: Method :: new(
323
+ "_EJ0" . into( ) ,
324
+ 1 ,
325
+ false ,
326
+ // Call into CEJ0 method which will actually eject device
327
+ vec![ & aml:: MethodCall :: new(
328
+ "\\ _SB_.CPUS.CEJ0" . into( ) ,
329
+ vec![ & self . cpu_id] ,
330
+ ) ] ,
331
+ ) ,
308
332
] ,
309
333
)
310
334
. append_aml_bytes ( v)
@@ -320,7 +344,7 @@ impl Aml for CpuNotify {
320
344
let object = aml:: Path :: new ( & format ! ( "C{:03X}" , self . cpu_id) ) ;
321
345
aml:: If :: new (
322
346
& aml:: Equal :: new ( & aml:: Arg ( 0 ) , & self . cpu_id ) ,
323
- vec ! [ & aml:: Notify :: new( & object, & 1u8 ) ] ,
347
+ vec ! [ & aml:: Notify :: new( & object, & aml :: Arg ( 1 ) ) ] ,
324
348
)
325
349
. append_aml_bytes ( v)
326
350
}
@@ -369,6 +393,21 @@ impl Aml for CpuMethods {
369
393
370
394
aml:: Method :: new ( "CTFY" . into ( ) , 2 , true , cpu_notifies_refs) . append_aml_bytes ( v) ;
371
395
396
+ aml:: Method :: new (
397
+ "CEJ0" . into ( ) ,
398
+ 1 ,
399
+ true ,
400
+ vec ! [
401
+ & aml:: Acquire :: new( "\\ _SB_.PRES.CPLK" . into( ) , 0xffff ) ,
402
+ // Write CPU number (in first argument) to I/O port via field
403
+ & aml:: Store :: new( & aml:: Path :: new( "\\ _SB_.PRES.CSEL" ) , & aml:: Arg ( 0 ) ) ,
404
+ // Set CEJ0 bit
405
+ & aml:: Store :: new( & aml:: Path :: new( "\\ _SB_.PRES.CEJ0" ) , & aml:: ONE ) ,
406
+ & aml:: Release :: new( "\\ _SB_.PRES.CPLK" . into( ) ) ,
407
+ ] ,
408
+ )
409
+ . append_aml_bytes ( v) ;
410
+
372
411
aml:: Method :: new (
373
412
"CSCN" . into ( ) ,
374
413
0 ,
@@ -396,6 +435,15 @@ impl Aml for CpuMethods {
396
435
& aml:: Store :: new( & aml:: Path :: new( "\\ _SB_.PRES.CINS" ) , & aml:: ONE ) ,
397
436
] ,
398
437
) ,
438
+ & aml:: If :: new(
439
+ & aml:: Equal :: new( & aml:: Path :: new( "\\ _SB_.PRES.CRMV" ) , & aml:: ONE ) ,
440
+ // Notify device if it is (with the eject constant 0x3)
441
+ vec![
442
+ & aml:: MethodCall :: new( "CTFY" . into( ) , vec![ & aml:: Local ( 0 ) , & 3u8 ] ) ,
443
+ // Reset CRMV bit
444
+ & aml:: Store :: new( & aml:: Path :: new( "\\ _SB_.PRES.CRMV" ) , & aml:: ONE ) ,
445
+ ] ,
446
+ ) ,
399
447
& aml:: Add :: new( & aml:: Local ( 0 ) , & aml:: Local ( 0 ) , & aml:: ONE ) ,
400
448
] ,
401
449
) ,
0 commit comments