Skip to content

Commit

Permalink
platform: implement SvsmPlatform::is_external_interrupt for TDP.
Browse files Browse the repository at this point in the history
The TDP platform must use APIC virtualization to check whether a given
interrupt event originates from a hardware interrupt or a software
interrupt.  This change implements the logic to read the required state
from the APIC.

Signed-off-by: Jon Lange <[email protected]>
  • Loading branch information
msft-jlange committed Jan 23, 2025
1 parent 5cd227c commit 6ef4e57
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
16 changes: 16 additions & 0 deletions kernel/src/cpu/x86/apic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) Microsoft Corporation
//
// Author: Jon Lange <[email protected]>

pub const APIC_MSR_EOI: u32 = 0x80B;
pub const APIC_MSR_ISR: u32 = 0x810;
pub const APIC_MSR_ICR: u32 = 0x830;

// Returns the MSR offset and bitmask to identify a specific vector in an
// APIC register (IRR, ISR, or TMR).
pub fn apic_register_bit(vector: usize) -> (u32, u32) {
let index: u8 = (vector & 0xFF) as u8;
((index >> 5) as u32, 1 << (index & 0x1F))
}
1 change: 1 addition & 0 deletions kernel/src/cpu/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
//
// Authors: Thomas Leroy <[email protected]>

pub mod apic;
pub mod smap;
4 changes: 1 addition & 3 deletions kernel/src/platform/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::cpu::cpuid::CpuidResult;
use crate::cpu::msr::{read_msr, write_msr};
use crate::cpu::percpu::PerCpu;
use crate::cpu::smp::create_ap_start_context;
use crate::cpu::x86::apic::{APIC_MSR_EOI, APIC_MSR_ICR};
use crate::error::SvsmError;
use crate::hyperv;
use crate::hyperv::{hyperv_setup_hypercalls, hyperv_start_cpu, is_hyperv_hypervisor};
Expand All @@ -33,9 +34,6 @@ use bootlib::platform::SvsmPlatformType;
const MSR_APIC_BASE: u32 = 0x1B;
const APIC_X2_ENABLE_MASK: u64 = 0xC00;

const APIC_MSR_EOI: u32 = 0x80B;
const APIC_MSR_ICR: u32 = 0x830;

#[derive(Clone, Copy, Debug)]
pub struct NativePlatform {
is_hyperv: bool,
Expand Down
8 changes: 5 additions & 3 deletions kernel/src/platform/tdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use crate::address::{Address, PhysAddr, VirtAddr};
use crate::console::init_svsm_console;
use crate::cpu::cpuid::CpuidResult;
use crate::cpu::msr::read_msr;
use crate::cpu::percpu::PerCpu;
use crate::cpu::x86::apic::{apic_register_bit, APIC_MSR_ISR};
use crate::error::SvsmError;
use crate::hyperv;
use crate::io::IOPort;
Expand Down Expand Up @@ -171,11 +173,11 @@ impl SvsmPlatform for TdpPlatform {

fn eoi(&self) {}

fn is_external_interrupt(&self, _vector: usize) -> bool {
fn is_external_interrupt(&self, vector: usize) -> bool {
// Examine the APIC ISR to determine whether this interrupt vector is
// active. If so, it is assumed to be an external interrupt.
// TODO - add code to read the APIC ISR.
todo!();
let (msr, mask) = apic_register_bit(vector);
(read_msr(APIC_MSR_ISR + msr) & mask as u64) != 0
}

fn start_cpu(
Expand Down

0 comments on commit 6ef4e57

Please sign in to comment.