]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[pic8259] Return previous state when enabling or disabling IRQs
authorMichael Brown <mcb30@ipxe.org>
Fri, 14 Mar 2025 14:09:26 +0000 (14:09 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 14 Mar 2025 14:09:26 +0000 (14:09 +0000)
Return the previous interrupt enabled state from enable_irq() and
disable_irq(), to allow callers to more easily restore this state.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/include/pic8259.h

index dbec5fd2ca27bb3ce00c716ac98a397d020c74f9..0dc59cf272b8a54a65198b2fac63d1c4f329e913 100644 (file)
@@ -47,9 +47,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 /* Macros to enable/disable IRQs */
 #define IMR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_IMR : PIC2_IMR )
 #define IMR_BIT(x) ( 1 << ( (x) % IRQ_PIC_CUTOFF ) )
-#define irq_enabled(x) ( ( inb ( IMR_REG(x) ) & IMR_BIT(x) ) == 0 )
-#define enable_irq(x) outb ( inb( IMR_REG(x) ) & ~IMR_BIT(x), IMR_REG(x) )
-#define disable_irq(x) outb ( inb( IMR_REG(x) ) | IMR_BIT(x), IMR_REG(x) )
 
 /* Macros for acknowledging IRQs */
 #define ICR_REG( irq ) ( (irq) < IRQ_PIC_CUTOFF ? PIC1_ICR : PIC2_ICR )
@@ -63,6 +60,50 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define IRQ_MAX 15
 #define IRQ_NONE -1U
 
+/**
+ * Check if interrupt is enabled
+ *
+ * @v irq              Interrupt number
+ * @ret enabled                Interrupt is currently enabled
+ */
+static inline __attribute__ (( always_inline )) int
+irq_enabled ( unsigned int irq ) {
+       int imr = inb ( IMR_REG ( irq ) );
+       int mask = IMR_BIT ( irq );
+
+       return ( ( imr & mask ) == 0 );
+}
+
+/**
+ * Enable interrupt
+ *
+ * @v irq              Interrupt number
+ * @ret enabled                Interrupt was previously enabled
+ */
+static inline __attribute__ (( always_inline )) int
+enable_irq ( unsigned int irq ) {
+       int imr = inb ( IMR_REG ( irq ) );
+       int mask = IMR_BIT ( irq );
+
+       outb ( ( imr & ~mask ), IMR_REG ( irq ) );
+       return ( ( imr & mask ) == 0 );
+}
+
+/**
+ * Disable interrupt
+ *
+ * @v irq              Interrupt number
+ * @ret enabled                Interrupt was previously enabled
+ */
+static inline __attribute__ (( always_inline )) int
+disable_irq ( unsigned int irq ) {
+       int imr = inb ( IMR_REG ( irq ) );
+       int mask = IMR_BIT ( irq );
+
+       outb ( ( imr | mask ), IMR_REG ( irq ) );
+       return ( ( imr & mask ) == 0 );
+}
+
 /* Function prototypes
  */
 void send_eoi ( unsigned int irq );