Skip to contentSkip to conversation

ACPI: Using correct irq when uninstalling acpi irq handler

PATCH Superseded Chen Yu 2 participants 3 messages Oct 22, 2015 – Oct 24, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chen Yu

author
#0 lore raw

PATCH 1/3 ACPI: Using correct irq when uninstalling acpi irq handler

Currently when system is trying to uninstall the acpi irq handler, it uses the acpi_gbl_FADT.sci_interrupt directly. But acpi irq handler is actually installed by mapped irq in acpi_os_install_interrupt_handler, so this patch fixes this problem by using the mapped irq returned from acpi_gsi_to_irq.

---
 drivers/acpi/osl.c   | 10 +++++++---
 include/linux/acpi.h |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +7 -3
index 739a4a6..2e9eccf 100644
@@ -81,6 +81,7 @@ static struct workqueue_struct *kacpid_wq;
 static struct workqueue_struct *kacpi_notify_wq;
 static struct workqueue_struct *kacpi_hotplug_wq;
 static bool acpi_os_initialized;
+unsigned int acpi_sci_irq = INVALID_ACPI_IRQ;
 
 /*
  * This list of permanent mappings is for memory that may be accessed from
@@ -856,17 +857,20 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
 		acpi_irq_handler = NULL;
 		return AE_NOT_ACQUIRED;
 	}
+	acpi_sci_irq = irq;
 
 	return AE_OK;
 }
 
-acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
+acpi_status acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
 {
-	if (irq != acpi_gbl_FADT.sci_interrupt)
+	if ((gsi != acpi_gbl_FADT.sci_interrupt) ||
+			IS_INVALID_ACPI_IRQ(acpi_sci_irq))
 		return AE_BAD_PARAMETER;
 
-	free_irq(irq, acpi_irq);
+	free_irq(acpi_sci_irq, acpi_irq);
 	acpi_irq_handler = NULL;
+	acpi_sci_irq = INVALID_ACPI_IRQ;
 
 	return AE_OK;
 }
include/linux/acpi.h +3 -0
index 43856d1..bad159c 100644
@@ -193,6 +193,9 @@ int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);
 void acpi_irq_stats_init(void);
 extern u32 acpi_irq_handled;
 extern u32 acpi_irq_not_handled;
+extern unsigned int acpi_sci_irq;
+#define INVALID_ACPI_IRQ ((unsigned)-1)
+#define IS_INVALID_ACPI_IRQ(x) unlikely((x) == INVALID_ACPI_IRQ)
 
 extern int sbf_port;
 extern unsigned long acpi_realmode_flags;
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 31 lines · Chen Yu

Currently when system is trying to uninstall the acpi irq handler, it uses the acpi_gbl_FADT.sci_interrupt directly. But acpi irq handler is actually installed by mapped irq in acpi_os_install_interrupt_handler, so this patch fixes this problem by using the mapped irq returned from acpi_gsi_to_irq.

---
 drivers/acpi/osl.c   | 10 +++++++---
 include/linux/acpi.h |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +2 -0
index 739a4a6..2e9eccf 100644
@@ -81,6 +81,7 @@ static struct workqueue_struct *kacpid_wq;
 static struct workqueue_struct *kacpi_notify_wq;
 static struct workqueue_struct *kacpi_hotplug_wq;
 static bool acpi_os_initialized;
+unsigned int acpi_sci_irq = INVALID_ACPI_IRQ;
 
 /*
  * This list of permanent mappings is for memory that may be accessed from
@@ -856,17 +857,20 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
 		acpi_irq_handler = NULL;
 		return AE_NOT_ACQUIRED;
 	}
+	acpi_sci_irq = irq;

drivers/acpi/osl.c acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, · line 868

Quoted 10 lines
drivers/acpi/osl.c +3 -2
 
 	return AE_OK;
 }
 
-acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
+acpi_status acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
 {
-	if (irq != acpi_gbl_FADT.sci_interrupt)
+	if ((gsi != acpi_gbl_FADT.sci_interrupt) ||
+			IS_INVALID_ACPI_IRQ(acpi_sci_irq))

The white space doesn't follow the kernel coding style, should be something like

	if ((gsi != acpi_gbl_FADT.sci_interrupt) ||
	    IS_INVALID_ACPI_IRQ(acpi_sci_irq))

(spaces instead of the second tab).

Another minor nit is that this probably is the only place you check the IS_INVALID_ACPI_IRQ(acpi_sci_irq) thing without logical negation and you only pass acpi_sci_irq to IS_INVALID_ACPI_IRQ() AFAICS.

It would be more straightforward to define something like acpi_sci_irq_valid() instead (see below) IMO.

Quoted 14 lines
drivers/acpi/osl.c +2 -1
 		return AE_BAD_PARAMETER;
 
-	free_irq(irq, acpi_irq);
+	free_irq(acpi_sci_irq, acpi_irq);
 	acpi_irq_handler = NULL;
+	acpi_sci_irq = INVALID_ACPI_IRQ;
 
 	return AE_OK;
 }
include/linux/acpi.h +0 -0
index 43856d1..bad159c 100644

include/linux/acpi.h int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base); · line 197

Quoted 5 lines
include/linux/acpi.h +2 -0
@@ -193,6 +193,9 @@ int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);
 void acpi_irq_stats_init(void);
 extern u32 acpi_irq_handled;
 extern u32 acpi_irq_not_handled;
+extern unsigned int acpi_sci_irq;
+#define INVALID_ACPI_IRQ ((unsigned)-1)

#define INVALID_ACPI_IRQ ((unsigned int)-1)

include/linux/acpi.h int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base); · line 198

Quoted 1 line
include/linux/acpi.h +1 -0
+#define IS_INVALID_ACPI_IRQ(x) unlikely((x) == INVALID_ACPI_IRQ)

Maybe something like:

	static inline bool acpi_sci_irq_valid(void)
	{
		return acpi_sci_irq != INVALID_ACPI_IRQ;
	}

include/linux/acpi.h int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);

Quoted 4 lines
include/linux/acpi.h +0 -0
 extern int sbf_port;
 extern unsigned long acpi_realmode_flags;
 

Thanks,
Rafael

author
#2 lore raw

Hi, Rafael

Quoted 58 lines

-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Saturday, October 24, 2015 9:32 PM
To: Chen, Yu C
Cc: [email protected]; Zhang, Rui; Zheng, Lv; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/3] ACPI: Using correct irq when uninstalling acpi irq handler

Quoted 23 lines · Chen Yu

Currently when system is trying to uninstall the acpi irq handler, it uses the acpi_gbl_FADT.sci_interrupt directly.
But acpi irq handler is actually installed by mapped irq in acpi_os_install_interrupt_handler, so this patch fixes this problem by using the mapped irq returned from acpi_gsi_to_irq.

---
 drivers/acpi/osl.c   | 10 +++++++---
 include/linux/acpi.h |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/acpi/osl.c index renamed from drivers/acpi/osl.c +0 -0

739a4a6..2e9eccf 100644

drivers/acpi/osl.c +0 -0
@@ -81,6 +81,7 @@ static struct workqueue_struct *kacpid_wq;  static

struct workqueue_struct *kacpi_notify_wq; static struct workqueue_struct *kacpi_hotplug_wq; static bool acpi_os_initialized; +unsigned int acpi_sci_irq = INVALID_ACPI_IRQ;

Quoted 3 lines

/*
* This list of permanent mappings is for memory that may be accessed
from @@ -856,17 +857,20 @@ acpi_os_install_interrupt_handler(u32 gsi,

acpi_osd_handler handler,

Quoted 10 lines
drivers/acpi/osl.c +1 -1
 		acpi_irq_handler = NULL;
 		return AE_NOT_ACQUIRED;
 	}
+	acpi_sci_irq = irq;
 
 	return AE_OK;
 }
 
-acpi_status acpi_os_remove_interrupt_handler(u32 irq,

acpi_osd_handler handler)

drivers/acpi/osl.c acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, · line 868

Quoted 6 lines
drivers/acpi/osl.c +4 -1
+acpi_status acpi_os_remove_interrupt_handler(u32 gsi,
+acpi_osd_handler handler)
 {
-	if (irq != acpi_gbl_FADT.sci_interrupt)
+	if ((gsi != acpi_gbl_FADT.sci_interrupt) ||
+			IS_INVALID_ACPI_IRQ(acpi_sci_irq))

The white space doesn't follow the kernel coding style, should be something like

Quoted 5 lines
	if ((gsi != acpi_gbl_FADT.sci_interrupt) ||
	    IS_INVALID_ACPI_IRQ(acpi_sci_irq))

(spaces instead of the second tab).

Ah, got it, thanks.

Quoted 28 lines

Another minor nit is that this probably is the only place you check the IS_INVALID_ACPI_IRQ(acpi_sci_irq) thing without logical negation and you only pass acpi_sci_irq to IS_INVALID_ACPI_IRQ() AFAICS.

It would be more straightforward to define something like acpi_sci_irq_valid() instead (see below) IMO.

Quoted 16 lines
drivers/acpi/osl.c +2 -1
 		return AE_BAD_PARAMETER;
 
-	free_irq(irq, acpi_irq);
+	free_irq(acpi_sci_irq, acpi_irq);
 	acpi_irq_handler = NULL;
+	acpi_sci_irq = INVALID_ACPI_IRQ;
 
 	return AE_OK;
 }
include/linux/acpi.h index renamed from include/linux/acpi.h +0 -0

43856d1..bad159c 100644

include/linux/acpi.h +0 -0
@@ -193,6 +193,9 @@ int acpi_ioapic_registered(acpi_handle handle, u32

gsi_base); void acpi_irq_stats_init(void); extern u32 acpi_irq_handled; extern u32 acpi_irq_not_handled;

include/linux/acpi.h int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base); · line 197

Quoted 2 lines
include/linux/acpi.h +2 -0
+extern unsigned int acpi_sci_irq;
+#define INVALID_ACPI_IRQ ((unsigned)-1)

#define INVALID_ACPI_IRQ ((unsigned int)-1)

Quoted 9 lines
Quoted 1 line

+#define IS_INVALID_ACPI_IRQ(x) unlikely((x) == INVALID_ACPI_IRQ)

Maybe something like:

	static inline bool acpi_sci_irq_valid(void)
	{
		return acpi_sci_irq != INVALID_ACPI_IRQ;
	}

OK, will send out a version 2 with both another two patches modified.

Best Regards,
Yu