Skip to contentSkip to conversation

module to support ACPI AML calls to native firmware

RFC In review Bjorn Helgaas 4 participants 9 messages Sep 11, 2007 – Sep 19, 2007 ACPI

lore
Share & tools
lore
#0 lore raw

Here are a couple patches on which I'd like some feedback.

The basic idea is that ACPI AML methods sometimes need to do something that is already implemented as a SAL interface. ACPI doesn't provide a way for an AML method to directly call the SAL interface. That means firmware writers sometimes have to implement things twice: once in SAL, then again in AML, which leads to duplication and errors.

So HP dreamed up a way to reduce this duplication by connecting AML with native firmware by using an ACPI Operation Region. HP firmware uses this for some hotplug functionality. So far, we have not had a Linux driver for this OpRegion, so we haven't been able to take advantage of this hotplug functionality.

These patches implement this OpRegion driver. The OpRegion is connected to an HPQ5001 ACPI device, so it's only useful on HP systems. Therefore, I'd like to make it a module so non-HP systems are not penalized by the 4K or so of space the driver uses.

The driver needs to serialize firmware calls using the sal_lock. That lock is currently not exported, which prevents making the driver a module. We could easily rectify that by exporting sal_lock (this would also enable making arch/ia64/kernel/esi.c a module), but there was some resistance to that in the past.

So I'm interested in feedback on the following patches, which do not export sal_lock, but rather export functions that can be used to call SAL or other native firmware interfaces.

Bjorn

#1 lore raw

PATCH 1/2 ia64: change SAL wrappers from macros to functions and export them

[patch] ia64: change SAL wrappers from macros to functions and export them

This changes the body of SAL_CALL() from a macro into a function, fw_call_lock(). The reasons to do this are:

- SAL_CALL() always calls through the ia64_sal function pointer, and I want to add a new functionality that needs the same conventions as SAL_CALL (FP regs saved/restored, sal_lock acquired, etc), but doesn't use the ia64_sal function pointer, and

- I'd like to make this new functionality a module, and I'd rather export fw_call_lock() than sal_lock.

include/asm-ia64/sal.h +33 -50
Index: w/include/asm-ia64/sal.h
===================================================================
@@ -45,38 +45,38 @@
 
 extern spinlock_t sal_lock;
 
-/* SAL spec _requires_ eight args for each call. */
-#define __SAL_CALL(result,a0,a1,a2,a3,a4,a5,a6,a7)	\
-	result = (*ia64_sal)(a0,a1,a2,a3,a4,a5,a6,a7)
-
-# define SAL_CALL(result,args...) do {				\
-	unsigned long __ia64_sc_flags;				\
-	struct ia64_fpreg __ia64_sc_fr[6];			\
-	ia64_save_scratch_fpregs(__ia64_sc_fr);			\
-	spin_lock_irqsave(&sal_lock, __ia64_sc_flags);		\
-	__SAL_CALL(result, args);				\
-	spin_unlock_irqrestore(&sal_lock, __ia64_sc_flags);	\
-	ia64_load_scratch_fpregs(__ia64_sc_fr);			\
-} while (0)
-
-# define SAL_CALL_NOLOCK(result,args...) do {		\
-	unsigned long __ia64_scn_flags;			\
-	struct ia64_fpreg __ia64_scn_fr[6];		\
-	ia64_save_scratch_fpregs(__ia64_scn_fr);	\
-	local_irq_save(__ia64_scn_flags);		\
-	__SAL_CALL(result, args);			\
-	local_irq_restore(__ia64_scn_flags);		\
-	ia64_load_scratch_fpregs(__ia64_scn_fr);	\
-} while (0)
-
-# define SAL_CALL_REENTRANT(result,args...) do {	\
-	struct ia64_fpreg __ia64_scs_fr[6];		\
-	ia64_save_scratch_fpregs(__ia64_scs_fr);	\
-	preempt_disable();				\
-	__SAL_CALL(result, args);			\
-	preempt_enable();				\
-	ia64_load_scratch_fpregs(__ia64_scs_fr);	\
-} while (0)
+struct ia64_sal_retval {
+	/*
+	 * A zero status value indicates call completed without error.
+	 * A negative status value indicates reason of call failure.
+	 * A positive status value indicates success but an
+	 * informational value should be printed (e.g., "reboot for
+	 * change to take effect").
+	 */
+	s64 status;
+	u64 v0;
+	u64 v1;
+	u64 v2;
+};
+
+typedef struct ia64_sal_retval (*ia64_sal_handler) (u64, ...);
+extern ia64_sal_handler ia64_sal;
+
+extern void fw_call_lock(ia64_sal_handler, struct ia64_sal_retval *,
+	u64, u64, u64, u64, u64, u64, u64, u64);
+extern void fw_call_nolock(ia64_sal_handler, struct ia64_sal_retval *,
+	u64, u64, u64, u64, u64, u64, u64, u64);
+extern void fw_call_reentrant(ia64_sal_handler, struct ia64_sal_retval *,
+	u64, u64, u64, u64, u64, u64, u64, u64);
+
+# define SAL_CALL(result, args...)		\
+	fw_call_lock(ia64_sal, &result, args)
+
+# define SAL_CALL_NOLOCK(result, args...)	\
+	fw_call_nolock(ia64_sal, &result, args)
+
+# define SAL_CALL_REENTRANT(result,args...)	\
+	fw_call_reentrant(ia64_sal, &result, args)
 
 #define SAL_SET_VECTORS			0x01000000
 #define SAL_GET_STATE_INFO		0x01000001
@@ -95,22 +95,6 @@
 
 #define SAL_UPDATE_PAL			0x01000020
 
-struct ia64_sal_retval {
-	/*
-	 * A zero status value indicates call completed without error.
-	 * A negative status value indicates reason of call failure.
-	 * A positive status value indicates success but an
-	 * informational value should be printed (e.g., "reboot for
-	 * change to take effect").
-	 */
-	s64 status;
-	u64 v0;
-	u64 v1;
-	u64 v2;
-};
-
-typedef struct ia64_sal_retval (*ia64_sal_handler) (u64, ...);
-
 enum {
 	SAL_FREQ_BASE_PLATFORM = 0,
 	SAL_FREQ_BASE_INTERVAL_TIMER = 1,
@@ -228,7 +212,6 @@
 	u64 vector;		/* interrupt vector in range 0x10-0xff */
 } ia64_sal_desc_ap_wakeup_t ;
 
-extern ia64_sal_handler ia64_sal;
 extern struct ia64_sal_desc_ptc *ia64_ptc_domain_info;
 
 extern unsigned short sal_revision;	/* supported SAL spec revision */
@@ -692,7 +675,7 @@
 {
 	struct ia64_sal_retval isrv;
 	SAL_CALL_REENTRANT(isrv, SAL_GET_STATE_INFO, sal_info_type, 0,
-	              sal_info, 0, 0, 0, 0);
+	              (u64) sal_info, 0, 0, 0, 0);
 	if (isrv.status)
 		return 0;
 
arch/ia64/kernel/sal.c +44 -0

50 lines not on this page · raw message

include/asm-ia64/sn/sn_sal.h +3 -3
Index: w/include/asm-ia64/sn/sn_sal.h
===================================================================
@@ -547,7 +547,7 @@
 ia64_sn_sys_serial_get(char *buf)
 {
 	struct ia64_sal_retval ret_stuff;
-	SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYS_SERIAL_GET, buf, 0, 0, 0, 0, 0, 0);
+	SAL_CALL_NOLOCK(ret_stuff, SN_SAL_SYS_SERIAL_GET, (u64) buf, 0, 0, 0, 0, 0, 0);
 	return ret_stuff.status;
 }
 
@@ -968,8 +968,8 @@
 		      u64 banlen)
 {
 	struct ia64_sal_retval rv;
-	SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, fitentry,
-			banbuf, banlen, 0, 0);
+	SAL_CALL_NOLOCK(rv, SN_SAL_GET_FIT_COMPT, nasid, index, (u64) fitentry,
+			(u64) banbuf, banlen, 0, 0);
 	return (int) rv.status;
 }
 
#2 lore raw

PATCH 2/2 ia64: add driver for ACPI methods to call native firmware

In reply to Bjorn Helgaas

This driver for HPQ5001 devices installs a global ACPI OpRegion handler. AML methods can use this OpRegion to call native firmware entry points.

This is required to support some hotplug functionality on HP Integrity systems.

arch/ia64/Kconfig +13 -0
Index: w/arch/ia64/Kconfig
===================================================================
@@ -461,6 +461,19 @@
 	  firmware extensions, such as the ability to inject memory-errors
 	  for test-purposes.  If you're unsure, say N.
 
+config IA64_HP_AML_NFW
+	tristate "Support ACPI AML calls to native firmware"
+	help
+	  This driver installs a global ACPI Operation Region handler for
+	  region 0xA1.  AML methods can use this OpRegion to call arbitrary
+	  native firmware functions.  The driver installs the OpRegion
+	  handler if there is an HPQ5001 device or if the user supplies
+	  the "force" module parameter, e.g., with the "aml_nfw.force"
+	  kernel command line option.
+
+	  This driver is required for some hotplug functionality on
+	  HP Integrity systems.
+
 source "drivers/sn/Kconfig"
 
 config KEXEC
arch/ia64/hp/common/Makefile +1 -0
Index: w/arch/ia64/hp/common/Makefile
===================================================================
@@ -8,3 +8,4 @@
 obj-y := sba_iommu.o
 obj-$(CONFIG_IA64_HP_ZX1_SWIOTLB) += hwsw_iommu.o
 obj-$(CONFIG_IA64_GENERIC) += hwsw_iommu.o
+obj-$(CONFIG_IA64_HP_AML_NFW) += aml_nfw.o
arch/ia64/hp/common/aml_nfw.c new file +228 -0

228 lines not on this page · raw message

#3 lore raw

Re: [patch 2/2] ia64: add driver for ACPI methods to call native firmware

arch/ia64/Kconfig line 465

Quoted 2 lines · Bjorn Helgaas
arch/ia64/Kconfig +2 -0
+config IA64_HP_AML_NFW
+	tristate "Support ACPI AML calls to native firmware"

The description seems a bit generic for something that's HP specific?

Signature · 1 line
Matthew Garrett | [email protected]
#4 lore raw

Re: [patch 2/2] ia64: add driver for ACPI methods to call native firmware

Quoted 6 lines · Matthew Garrett

arch/ia64/Kconfig line 465

Quoted 2 lines · Bjorn Helgaas
arch/ia64/Kconfig +2 -0
+config IA64_HP_AML_NFW
+	tristate "Support ACPI AML calls to native firmware"

The description seems a bit generic for something that's HP specific?

It's within arch/ia64/Kconfig, so it will only show up on IA64 boxes... It's possible that Altix or Intel IA64 boxes will want to make SAL calls from ACPI, so it looks ok...

--Kyle

#5 lore raw

Re: [patch 2/2] ia64: add driver for ACPI methods to call native firmware

In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

arch/ia64/Kconfig line 465

Quoted 2 lines · Bjorn Helgaas
arch/ia64/Kconfig +2 -0
+config IA64_HP_AML_NFW
+	tristate "Support ACPI AML calls to native firmware"

The description seems a bit generic for something that's HP specific?

Thanks, I'll wordsmith the description a bit. There's actually nothing in the implementation that prevents this from working on non-HP firmware.

I really want feedback on the best approach of:

1. Always build the driver static, accept the additional 4600 bytes in everybody's image, not export anything.

2. Allow building driver as a module, export sal_lock. This would also enable building arch/ia64/kernel/esi.c as a module.

3. Allow building driver as a module, restructure SAL_CALL so we don't have to export sal_lock, but we do export fw_call_lock() (as done in these patches). This isn't quite sufficient to enable building esi.c as a module.

#1 would be easiest, of course, but I'm not happy about adding stuff that is only used on HP hardware. #2 would be simple, but exporting sal_lock has been resisted in the past.

Bjorn

#6 lore raw
In reply to Bjorn Helgaas
Quoted 4 lines · Bjorn Helgaas

...
So I'm interested in feedback on the following patches, which do not export sal_lock, but rather export functions that can be used to call SAL or other native firmware interfaces.

Hi Tony,

I haven't heard much feedback, and I couldn't come up with any significantly better text for the description.

If you don't object to the two patches, can you incorporate them as originally posted? If you'd prefer a different approach, I'd be happy to rework them, of course.

Thanks,
Bjorn

#7 lore raw
Quoted 3 lines

If you don't object to the two patches, can you incorporate them as originally posted? If you'd prefer a different approach, I'd be happy to rework them, of course.

I think that adding 4K to the kernel (about 0.04% increase looking at a recent build ... or 0.0001% of total memory on a 4G system) isn't really a big deal. I'd rather do that than export all the fw_call_*() functions for all the world to see.

If there is some other reason why the exports are needed, then the names may have to change ... these are ia64 specific routines, but the fw_call_*() names sound very generic.

-Tony

#8 lore raw
Quoted 8 lines · Tony
Quoted 3 lines

If you don't object to the two patches, can you incorporate them as originally posted? If you'd prefer a different approach, I'd be happy to rework them, of course.

I think that adding 4K to the kernel (about 0.04% increase looking at a recent build ... or 0.0001% of total memory on a 4G system) isn't really a big deal. I'd rather do that than export all the fw_call_*() functions for all the world to see.

That's certainly the most straightforward solution. I'll post those patches in a bit.

Bjorn