@@ -251,6 +251,17 @@ pub fn local_apic_id_count() -> u32 {
251
251
unsafe { CPU_LOCAL_APIC_IDS . as_ref ( ) . unwrap ( ) . len ( ) as u32 }
252
252
}
253
253
254
+ unsafe fn init_ioapic_address ( phys_addr : PhysAddr ) {
255
+ unsafe {
256
+ IOAPIC_ADDRESS = virtualmem:: allocate ( BasePageSize :: SIZE as usize ) . unwrap ( ) ;
257
+ debug ! ( "Mapping IOAPIC at {phys_addr:p} to virtual address {IOAPIC_ADDRESS:p}" , ) ;
258
+
259
+ let mut flags = PageTableEntryFlags :: empty ( ) ;
260
+ flags. device ( ) . writable ( ) . execute_disable ( ) ;
261
+ paging:: map :: < BasePageSize > ( IOAPIC_ADDRESS , phys_addr, 1 , flags) ;
262
+ }
263
+ }
264
+
254
265
#[ cfg( not( feature = "acpi" ) ) ]
255
266
fn detect_from_acpi ( ) -> Result < PhysAddr , ( ) > {
256
267
// dummy implementation if acpi support is disabled
@@ -291,21 +302,7 @@ fn detect_from_acpi() -> Result<PhysAddr, ()> {
291
302
debug ! ( "Found I/O APIC record: {}" , ioapic_record) ;
292
303
293
304
unsafe {
294
- IOAPIC_ADDRESS = virtualmem:: allocate ( BasePageSize :: SIZE as usize ) . unwrap ( ) ;
295
- let record_addr = ioapic_record. address ;
296
- debug ! (
297
- "Mapping IOAPIC at {:#X} to virtual address {:#X}" ,
298
- record_addr, IOAPIC_ADDRESS
299
- ) ;
300
-
301
- let mut flags = PageTableEntryFlags :: empty ( ) ;
302
- flags. device ( ) . writable ( ) . execute_disable ( ) ;
303
- paging:: map :: < BasePageSize > (
304
- IOAPIC_ADDRESS ,
305
- PhysAddr ( record_addr. into ( ) ) ,
306
- 1 ,
307
- flags,
308
- ) ;
305
+ init_ioapic_address ( PhysAddr ( ioapic_record. address . into ( ) ) ) ;
309
306
}
310
307
}
311
308
_ => {
@@ -401,15 +398,7 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
401
398
let default_address = PhysAddr ( 0xFEC0_0000 ) ;
402
399
403
400
unsafe {
404
- IOAPIC_ADDRESS = virtualmem:: allocate ( BasePageSize :: SIZE as usize ) . unwrap ( ) ;
405
- debug ! (
406
- "Mapping IOAPIC at {:#X} to virtual address {:#X}" ,
407
- default_address, IOAPIC_ADDRESS
408
- ) ;
409
-
410
- let mut flags = PageTableEntryFlags :: empty ( ) ;
411
- flags. device ( ) . writable ( ) . execute_disable ( ) ;
412
- paging:: map :: < BasePageSize > ( IOAPIC_ADDRESS , default_address, 1 , flags) ;
401
+ init_ioapic_address ( default_address) ;
413
402
}
414
403
} else {
415
404
// entries starts directly after the config table
@@ -428,24 +417,11 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
428
417
// IO-APIC entry
429
418
2 => {
430
419
let io_entry: & ApicIoEntry = unsafe { & * ( addr as * const ApicIoEntry ) } ;
431
- let ioapic = io_entry. addr ;
420
+ let ioapic = PhysAddr ( io_entry. addr . into ( ) ) ;
432
421
info ! ( "Found IOAPIC at 0x{:x}" , ioapic) ;
433
422
434
423
unsafe {
435
- IOAPIC_ADDRESS = virtualmem:: allocate ( BasePageSize :: SIZE as usize ) . unwrap ( ) ;
436
- debug ! (
437
- "Mapping IOAPIC at {:#X} to virtual address {:#X}" ,
438
- ioapic, IOAPIC_ADDRESS
439
- ) ;
440
-
441
- let mut flags = PageTableEntryFlags :: empty ( ) ;
442
- flags. device ( ) . writable ( ) . execute_disable ( ) ;
443
- paging:: map :: < BasePageSize > (
444
- IOAPIC_ADDRESS ,
445
- PhysAddr ( ioapic as u64 ) ,
446
- 1 ,
447
- flags,
448
- ) ;
424
+ init_ioapic_address ( ioapic) ;
449
425
}
450
426
451
427
addr += mem:: size_of :: < ApicIoEntry > ( ) ;
@@ -463,43 +439,27 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
463
439
fn default_apic ( ) -> PhysAddr {
464
440
warn ! ( "Try to use default APIC address" ) ;
465
441
466
- let default_address = PhysAddr ( 0xFEC0_0000 ) ;
442
+ let default_address = PhysAddr ( 0xFEE0_0000 ) ;
467
443
468
444
unsafe {
469
- IOAPIC_ADDRESS = virtualmem:: allocate ( BasePageSize :: SIZE as usize ) . unwrap ( ) ;
470
- debug ! (
471
- "Mapping IOAPIC at {:#X} to virtual address {:#X}" ,
472
- default_address, IOAPIC_ADDRESS
473
- ) ;
474
-
475
- let mut flags = PageTableEntryFlags :: empty ( ) ;
476
- flags. device ( ) . writable ( ) . execute_disable ( ) ;
477
- paging:: map :: < BasePageSize > ( IOAPIC_ADDRESS , default_address, 1 , flags) ;
445
+ init_ioapic_address ( default_address) ;
478
446
}
479
447
480
- PhysAddr ( 0xFEE0_0000 )
448
+ default_address
481
449
}
482
450
483
451
fn detect_from_uhyve ( ) -> Result < PhysAddr , ( ) > {
484
452
if env:: is_uhyve ( ) {
485
- let default_address = PhysAddr ( 0xFEC0_0000 ) ;
453
+ let default_address = PhysAddr ( 0xFEE0_0000 ) ;
486
454
487
455
unsafe {
488
- IOAPIC_ADDRESS = virtualmem:: allocate ( BasePageSize :: SIZE as usize ) . unwrap ( ) ;
489
- debug ! (
490
- "Mapping IOAPIC at {:#X} to virtual address {:#X}" ,
491
- default_address, IOAPIC_ADDRESS
492
- ) ;
493
-
494
- let mut flags = PageTableEntryFlags :: empty ( ) ;
495
- flags. device ( ) . writable ( ) . execute_disable ( ) ;
496
- paging:: map :: < BasePageSize > ( IOAPIC_ADDRESS , default_address, 1 , flags) ;
456
+ init_ioapic_address ( default_address) ;
497
457
}
498
458
499
- return Ok ( PhysAddr ( 0xFEE0_0000 ) ) ;
459
+ Ok ( default_address)
460
+ } else {
461
+ Err ( ( ) )
500
462
}
501
-
502
- Err ( ( ) )
503
463
}
504
464
505
465
#[ no_mangle]
0 commit comments