mycelium_kernel::arch::interrupt::apic

Struct LocalApic

Source
pub struct LocalApic { /* private fields */ }
Expand description

Local APIC state.

§Notes on Mutability

In a multi-core x86_64 system, each CPU core has its own local APIC. Therefore, the Mycelium HAL’s interrupt::Controller type uses core-local storage to store a reference to each CPU core’s local APIC that can be accessed only by that core. The value in core-local storage is a RefCell<Option<LocalApic>>, as the local APIC must be initialized on a per-core basis before it can be used.

Note that the RefCell must only be borrowed mutably in order to initialize the LocalApic value. Once the local APIC has been initialized, it may receive interrupts, and may also be accessed by interrupt handlers in order to send an end-of-interrupt. This means that mutably borrowing the RefCell once interrupts are enabled may result in a panic if an ISR attempts to borrow the local APIC immutably to send an EOI while the local APIC is borrowed mutably.

Therefore, all local APIC operations that mutate state, such as setting the timer calibration, must use interior mutability, so that an interrupt handler may access the local APIC’s state. Interior mutability need not be thread-safe, however, as the local APIC state is only accessed from the core that owns it.

Implementations§

Source§

impl LocalApic

Source

pub fn try_new<A>( pagectrl: &mut impl Map<Size4Kb, A>, frame_alloc: &A, ) -> Result<LocalApic, FeatureNotSupported>
where A: Alloc<Size4Kb>,

Try to construct a LocalApic.

§Arguments
  • pagectrl: a page mapper used to ensure that the local APIC’s memory-mapped register page is mapped and writable.
  • frame_alloc: a frame allocator used to allocate page frame(s) while mapping the MMIO register page.
§Returns
  • Ok(LocalApic) if this CPU supports the APIC interrupt model.
  • Err(FeatureNotSupported) if this CPU does not support APIC interrupt handling.
Source

pub fn new<A>(pagectrl: &mut impl Map<Size4Kb, A>, frame_alloc: &A) -> LocalApic
where A: Alloc<Size4Kb>,

Source

pub fn enable(&self, spurious_vector: u8)

Source

pub fn calibrate_timer(&self, divisor: TimerDivisor)

Source

pub fn version(&self) -> Version

Reads the local APIC’s version register.

The returned Version struct indicates the version of the local APIC, the maximum LVT entry index, and whether or not EOI suppression is supported.

Source

pub fn interrupt_in( &self, duration: Duration, vector: u8, ) -> Result<(), TimerError>

Source

pub fn start_periodic_timer( &self, interval: Duration, vector: u8, ) -> Result<(), TimerError>

Source

pub unsafe fn end_interrupt(&self)

Sends an End of Interrupt (EOI) to the local APIC.

This should be called by an interrupt handler after handling a local APIC interrupt.

§Safety

This should only be called when an interrupt has been triggered by this local APIC.

Source

pub fn check_error(&self) -> Result<(), ErrorStatus>

Reads the error stauts register (ESR) of the local APIC.

Calling this method resets the value of the error status register. Any currently set error bits are cleared. If the same error bits are present in a subsequent call to LocalApic::check_error, they represent new instances of the same error.

§Returns

If any error bits are set, this method returns Err(ErrorStatus). Otherwise, if no error bits are present, this method returns Ok().

Trait Implementations§

Source§

impl Debug for LocalApic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.