From 148ee1ed7762b79b411fb3f5be5aaa779ba305ae Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 17 Aug 2026 05:17:45 +0200 Subject: [PATCH] bsps/x86_64/amd64: Implement the vector operations rtems_interrupt_vector_is_enabled() and rtems_interrupt_clear() returned RTEMS_UNSATISFIED for every vector, while enable and disable claimed success without doing anything, and the attributes said nothing about either. ts-validation-intr reported 1664 failed steps. The three vectors which are left are delivered by the Local APIC. Only the local vector table entry of the timer has a mask bit, so it is the only one which can be enabled and disabled. The interprocessor and software vectors are delivered by a write to the interrupt command register and nothing masks them, so they are always enabled and the attributes say that they cannot be disabled. ts-validation-intr now has no failed step. Update #5692. Assisted-by: Claude:claude-opus-5 claude-code Signed-off-by: Sebastian Huber --- bsps/x86_64/amd64/include/apic.h | 16 +++++++++ bsps/x86_64/amd64/interrupts/apic.c | 18 +++++++++++ bsps/x86_64/amd64/interrupts/idt.c | 50 +++++++++++++++++++++-------- 3 files changed, 71 insertions(+), 13 deletions(-) diff --git a/bsps/x86_64/amd64/include/apic.h b/bsps/x86_64/amd64/include/apic.h index 1bdcab3040..766f858e2e 100644 --- a/bsps/x86_64/amd64/include/apic.h +++ b/bsps/x86_64/amd64/include/apic.h @@ -206,6 +206,22 @@ uint32_t lapic_timer_calc_ticks(uint64_t desired_freq_hz); */ void lapic_timer_enable(uint32_t reload_value); +/** + * @brief Masks or unmasks the local vector table entry of the Local APIC + * timer. + * + * @param masked Mask the entry, if true, otherwise unmask it. + */ +void lapic_timer_set_masked(bool masked); + +/** + * @brief Checks if the local vector table entry of the Local APIC timer is + * masked. + * + * @return true if the entry is masked. + */ +bool lapic_timer_is_masked(void); + /** * @brief Raises the interrupt vector on the processor executing this function. * diff --git a/bsps/x86_64/amd64/interrupts/apic.c b/bsps/x86_64/amd64/interrupts/apic.c index 0703c2cd31..e86cb9dd04 100644 --- a/bsps/x86_64/amd64/interrupts/apic.c +++ b/bsps/x86_64/amd64/interrupts/apic.c @@ -319,6 +319,24 @@ void lapic_timer_enable(uint32_t reload_value) amd64_lapic_base[LAPIC_REGISTER_TIMER_INITCNT] = reload_value; } +void lapic_timer_set_masked(bool masked) +{ + uint32_t lvt = amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER]; + + if (masked) { + lvt |= LAPIC_LVT_MASK; + } else { + lvt &= ~LAPIC_LVT_MASK; + } + + amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] = lvt; +} + +bool lapic_timer_is_masked(void) +{ + return (amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] & LAPIC_LVT_MASK) != 0; +} + void lapic_raise_self(uint32_t vector) { amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] = diff --git a/bsps/x86_64/amd64/interrupts/idt.c b/bsps/x86_64/amd64/interrupts/idt.c index 68985161f3..8cc50985ab 100644 --- a/bsps/x86_64/amd64/interrupts/idt.c +++ b/bsps/x86_64/amd64/interrupts/idt.c @@ -202,11 +202,20 @@ void bsp_interrupt_facility_initialize(void) } } +/* + * Only the local vector table entry of the Local APIC timer has a mask bit. + * The interprocessor and software vectors are delivered by a write to the + * interrupt command register and there is nothing which masks them. + */ rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector) { - (void) vector; + bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); - /* XXX: Should be implemented once I/O APIC support is added */ + if (vector != BSP_VECTOR_APIC_TIMER) { + return RTEMS_UNSATISFIED; + } + + lapic_timer_set_masked(true); return RTEMS_SUCCESSFUL; } @@ -240,13 +249,20 @@ rtems_status_code bsp_interrupt_get_attributes( rtems_interrupt_attributes *attributes ) { - if (vector >= BSP_VECTOR_APIC_FIRST) { - attributes->is_maskable = true; - attributes->can_raise = true; - attributes->cleared_by_acknowledge = true; + bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); + + attributes->is_maskable = true; + attributes->can_raise = true; + attributes->cleared_by_acknowledge = true; #ifdef RTEMS_SMP - attributes->can_raise_on = true; + attributes->can_raise_on = true; #endif + + if (vector == BSP_VECTOR_APIC_TIMER) { + attributes->can_enable = true; + attributes->maybe_enable = true; + attributes->can_disable = true; + attributes->maybe_disable = true; } return RTEMS_SUCCESSFUL; @@ -285,19 +301,27 @@ rtems_status_code bsp_interrupt_vector_is_enabled( bool *enabled ) { - (void) vector; - bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); bsp_interrupt_assert(enabled != NULL); - *enabled = false; - return RTEMS_UNSATISFIED; + + if (vector == BSP_VECTOR_APIC_TIMER) { + *enabled = !lapic_timer_is_masked(); + } else { + *enabled = true; + } + + return RTEMS_SUCCESSFUL; } rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector) { - (void) vector; + bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector)); - /* XXX: Should be implemented once I/O APIC support is added */ + if (vector != BSP_VECTOR_APIC_TIMER) { + return RTEMS_UNSATISFIED; + } + + lapic_timer_set_masked(false); return RTEMS_SUCCESSFUL; }