diff options
author | David Mosberger-Tang <David.Mosberger@acm.org> | 2006-06-21 14:19:22 -0400 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2006-06-21 14:19:22 -0400 |
commit | 2ab561a116e16cdee3ae0e13d51910634c15aee9 (patch) | |
tree | 3a1ff4ae7546c57778a2cd4b51fb5d76aaaae93e | |
parent | 22ae813b85df7c0b0fc7c8d6f336d6a9f566ff97 (diff) |
[IA64] esi-support
Add support for making ESI calls [1]. ESI stands for "Extensible SAL
specification" and is basically a way for invoking firmware
subroutines which are identified by a GUID. I don't know whether ESI
is used by vendors other than HP (if you do, please let me know) but
as firmware "backdoors" go, this seems one of the cleaner methods, so
it seems reasonable to support it, even though I'm not aware of any
publicly documented ESI calls. I'd have liked to make the ESI module
completely stand-alone, but unfortunately that is not easily (or not
at all) possible because in order to make ESI calls in physical mode,
a small stub similar to the EFI stub is needed in the kernel proper.
I did try to create a stub that would work in user-level, but it
quickly got ugly beyond recognition (e.g., the stub had to make
assumptions about how the module-loader generated call-stubs work) and
I didn't even get it to work (that's probably fixable, but I didn't
bother because I concluded it was too ugly anyhow). While it's not
terribly elegant to have kernel code which isn't actively used in the
kernel proper, I think it might be worth making an exception here for
two reasons: the code is trivially small (all that's really needed is
esi_stub.S) and by including it in the normal kernel distro, it might
encourage other OEMs to also use ESI, which I think would be far
better than each inventing their own firmware "backdoor".
The code was originally written by Alex. I just massaged and packaged
it a bit (and perhaps messed up some things along the way...).
Changes since first version of patch that was posted to mailing list:
* Export ia64_esi_call and ia64_esi_call_phys() as GPL symbols.
* Disallow building esi.c as a module for now. Building as a module
would currently lead to an unresolved reference to "sal_lock" on SMP kernels
because that symbol doesn't get exported.
* Export esi_call_phys() only if ESI is enabled.
* Remove internal stuff from esi.h and add a "proc_type" argument to
ia64_esi_call() such that serialization-requirements can be expressed (ESI
follows SAL here, where procedure calls may have to be serialized, are
MP-safe, or MP-safe andr reentrant).
[1] h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,919,00.html
Signed-off-by: David Mosberger <David.Mosberger@acm.org>
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r-- | arch/ia64/Kconfig | 8 | ||||
-rw-r--r-- | arch/ia64/kernel/Makefile | 5 | ||||
-rw-r--r-- | arch/ia64/kernel/esi.c | 205 | ||||
-rw-r--r-- | arch/ia64/kernel/esi_stub.S | 96 | ||||
-rw-r--r-- | arch/ia64/kernel/ia64_ksyms.c | 4 | ||||
-rw-r--r-- | include/asm-ia64/esi.h | 30 |
6 files changed, 348 insertions, 0 deletions
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig index 0f3076a820c3..bc106519482c 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig | |||
@@ -413,6 +413,14 @@ config IA64_PALINFO | |||
413 | config SGI_SN | 413 | config SGI_SN |
414 | def_bool y if (IA64_SGI_SN2 || IA64_GENERIC) | 414 | def_bool y if (IA64_SGI_SN2 || IA64_GENERIC) |
415 | 415 | ||
416 | config IA64_ESI | ||
417 | bool "ESI (Extensible SAL Interface) support" | ||
418 | help | ||
419 | If you say Y here, support is built into the kernel to | ||
420 | make ESI calls. ESI calls are used to support vendor-specific | ||
421 | firmware extensions, such as the ability to inject memory-errors | ||
422 | for test-purposes. If you're unsure, say N. | ||
423 | |||
416 | source "drivers/sn/Kconfig" | 424 | source "drivers/sn/Kconfig" |
417 | 425 | ||
418 | source "drivers/firmware/Kconfig" | 426 | source "drivers/firmware/Kconfig" |
diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile index 09a0dbc17fb6..66ac8e3dca9c 100644 --- a/arch/ia64/kernel/Makefile +++ b/arch/ia64/kernel/Makefile | |||
@@ -31,6 +31,11 @@ obj-$(CONFIG_KPROBES) += kprobes.o jprobes.o | |||
31 | obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o | 31 | obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o |
32 | mca_recovery-y += mca_drv.o mca_drv_asm.o | 32 | mca_recovery-y += mca_drv.o mca_drv_asm.o |
33 | 33 | ||
34 | obj-$(CONFIG_IA64_ESI) += esi.o | ||
35 | ifneq ($(CONFIG_IA64_ESI),) | ||
36 | obj-y += esi_stub.o # must be in kernel proper | ||
37 | endif | ||
38 | |||
34 | # The gate DSO image is built using a special linker script. | 39 | # The gate DSO image is built using a special linker script. |
35 | targets += gate.so gate-syms.o | 40 | targets += gate.so gate-syms.o |
36 | 41 | ||
diff --git a/arch/ia64/kernel/esi.c b/arch/ia64/kernel/esi.c new file mode 100644 index 000000000000..ebf4e988e78c --- /dev/null +++ b/arch/ia64/kernel/esi.c | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * Extensible SAL Interface (ESI) support routines. | ||
3 | * | ||
4 | * Copyright (C) 2006 Hewlett-Packard Co | ||
5 | * Alex Williamson <alex.williamson@hp.com> | ||
6 | */ | ||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/init.h> | ||
9 | #include <linux/module.h> | ||
10 | #include <linux/string.h> | ||
11 | |||
12 | #include <asm/esi.h> | ||
13 | #include <asm/sal.h> | ||
14 | |||
15 | MODULE_AUTHOR("Alex Williamson <alex.williamson@hp.com>"); | ||
16 | MODULE_DESCRIPTION("Extensible SAL Interface (ESI) support"); | ||
17 | MODULE_LICENSE("GPL"); | ||
18 | |||
19 | #define MODULE_NAME "esi" | ||
20 | |||
21 | #define ESI_TABLE_GUID \ | ||
22 | EFI_GUID(0x43EA58DC, 0xCF28, 0x4b06, 0xB3, \ | ||
23 | 0x91, 0xB7, 0x50, 0x59, 0x34, 0x2B, 0xD4) | ||
24 | |||
25 | enum esi_systab_entry_type { | ||
26 | ESI_DESC_ENTRY_POINT = 0 | ||
27 | }; | ||
28 | |||
29 | /* | ||
30 | * Entry type: Size: | ||
31 | * 0 48 | ||
32 | */ | ||
33 | #define ESI_DESC_SIZE(type) "\060"[(unsigned) (type)] | ||
34 | |||
35 | typedef struct ia64_esi_desc_entry_point { | ||
36 | u8 type; | ||
37 | u8 reserved1[15]; | ||
38 | u64 esi_proc; | ||
39 | u64 gp; | ||
40 | efi_guid_t guid; | ||
41 | } ia64_esi_desc_entry_point_t; | ||
42 | |||
43 | struct pdesc { | ||
44 | void *addr; | ||
45 | void *gp; | ||
46 | }; | ||
47 | |||
48 | static struct ia64_sal_systab *esi_systab; | ||
49 | |||
50 | static int __init esi_init (void) | ||
51 | { | ||
52 | efi_config_table_t *config_tables; | ||
53 | struct ia64_sal_systab *systab; | ||
54 | unsigned long esi = 0; | ||
55 | char *p; | ||
56 | int i; | ||
57 | |||
58 | config_tables = __va(efi.systab->tables); | ||
59 | |||
60 | for (i = 0; i < (int) efi.systab->nr_tables; ++i) { | ||
61 | if (efi_guidcmp(config_tables[i].guid, ESI_TABLE_GUID) == 0) { | ||
62 | esi = config_tables[i].table; | ||
63 | break; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | if (!esi) | ||
68 | return -ENODEV;; | ||
69 | |||
70 | systab = __va(esi); | ||
71 | |||
72 | if (strncmp(systab->signature, "ESIT", 4) != 0) { | ||
73 | printk(KERN_ERR "bad signature in ESI system table!"); | ||
74 | return -ENODEV; | ||
75 | } | ||
76 | |||
77 | p = (char *) (systab + 1); | ||
78 | for (i = 0; i < systab->entry_count; i++) { | ||
79 | /* | ||
80 | * The first byte of each entry type contains the type | ||
81 | * descriptor. | ||
82 | */ | ||
83 | switch (*p) { | ||
84 | case ESI_DESC_ENTRY_POINT: | ||
85 | break; | ||
86 | default: | ||
87 | printk(KERN_WARNING "Unkown table type %d found in " | ||
88 | "ESI table, ignoring rest of table\n", *p); | ||
89 | return -ENODEV; | ||
90 | } | ||
91 | |||
92 | p += ESI_DESC_SIZE(*p); | ||
93 | } | ||
94 | |||
95 | esi_systab = systab; | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | |||
100 | int ia64_esi_call (efi_guid_t guid, struct ia64_sal_retval *isrvp, | ||
101 | enum esi_proc_type proc_type, u64 func, | ||
102 | u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, | ||
103 | u64 arg7) | ||
104 | { | ||
105 | struct ia64_fpreg fr[6]; | ||
106 | unsigned long flags = 0; | ||
107 | int i; | ||
108 | char *p; | ||
109 | |||
110 | if (!esi_systab) | ||
111 | return -1; | ||
112 | |||
113 | p = (char *) (esi_systab + 1); | ||
114 | for (i = 0; i < esi_systab->entry_count; i++) { | ||
115 | if (*p == ESI_DESC_ENTRY_POINT) { | ||
116 | ia64_esi_desc_entry_point_t *esi = (void *)p; | ||
117 | if (!efi_guidcmp(guid, esi->guid)) { | ||
118 | ia64_sal_handler esi_proc; | ||
119 | struct pdesc pdesc; | ||
120 | |||
121 | pdesc.addr = __va(esi->esi_proc); | ||
122 | pdesc.gp = __va(esi->gp); | ||
123 | |||
124 | esi_proc = (ia64_sal_handler) &pdesc; | ||
125 | |||
126 | ia64_save_scratch_fpregs(fr); | ||
127 | if (proc_type == ESI_PROC_SERIALIZED) | ||
128 | spin_lock_irqsave(&sal_lock, flags); | ||
129 | else if (proc_type == ESI_PROC_MP_SAFE) | ||
130 | local_irq_save(flags); | ||
131 | else | ||
132 | preempt_disable(); | ||
133 | *isrvp = (*esi_proc)(func, arg1, arg2, arg3, | ||
134 | arg4, arg5, arg6, arg7); | ||
135 | if (proc_type == ESI_PROC_SERIALIZED) | ||
136 | spin_unlock_irqrestore(&sal_lock, | ||
137 | flags); | ||
138 | else if (proc_type == ESI_PROC_MP_SAFE) | ||
139 | local_irq_restore(flags); | ||
140 | else | ||
141 | preempt_enable(); | ||
142 | ia64_load_scratch_fpregs(fr); | ||
143 | return 0; | ||
144 | } | ||
145 | } | ||
146 | p += ESI_DESC_SIZE(*p); | ||
147 | } | ||
148 | return -1; | ||
149 | } | ||
150 | EXPORT_SYMBOL_GPL(ia64_esi_call); | ||
151 | |||
152 | int ia64_esi_call_phys (efi_guid_t guid, struct ia64_sal_retval *isrvp, | ||
153 | u64 func, u64 arg1, u64 arg2, u64 arg3, u64 arg4, | ||
154 | u64 arg5, u64 arg6, u64 arg7) | ||
155 | { | ||
156 | struct ia64_fpreg fr[6]; | ||
157 | unsigned long flags; | ||
158 | u64 esi_params[8]; | ||
159 | char *p; | ||
160 | int i; | ||
161 | |||
162 | if (!esi_systab) | ||
163 | return -1; | ||
164 | |||
165 | p = (char *) (esi_systab + 1); | ||
166 | for (i = 0; i < esi_systab->entry_count; i++) { | ||
167 | if (*p == ESI_DESC_ENTRY_POINT) { | ||
168 | ia64_esi_desc_entry_point_t *esi = (void *)p; | ||
169 | if (!efi_guidcmp(guid, esi->guid)) { | ||
170 | ia64_sal_handler esi_proc; | ||
171 | struct pdesc pdesc; | ||
172 | |||
173 | pdesc.addr = (void *)esi->esi_proc; | ||
174 | pdesc.gp = (void *)esi->gp; | ||
175 | |||
176 | esi_proc = (ia64_sal_handler) &pdesc; | ||
177 | |||
178 | esi_params[0] = func; | ||
179 | esi_params[1] = arg1; | ||
180 | esi_params[2] = arg2; | ||
181 | esi_params[3] = arg3; | ||
182 | esi_params[4] = arg4; | ||
183 | esi_params[5] = arg5; | ||
184 | esi_params[6] = arg6; | ||
185 | esi_params[7] = arg7; | ||
186 | ia64_save_scratch_fpregs(fr); | ||
187 | spin_lock_irqsave(&sal_lock, flags); | ||
188 | *isrvp = esi_call_phys(esi_proc, esi_params); | ||
189 | spin_unlock_irqrestore(&sal_lock, flags); | ||
190 | ia64_load_scratch_fpregs(fr); | ||
191 | return 0; | ||
192 | } | ||
193 | } | ||
194 | p += ESI_DESC_SIZE(*p); | ||
195 | } | ||
196 | return -1; | ||
197 | } | ||
198 | EXPORT_SYMBOL_GPL(ia64_esi_call_phys); | ||
199 | |||
200 | static void __exit esi_exit (void) | ||
201 | { | ||
202 | } | ||
203 | |||
204 | module_init(esi_init); | ||
205 | module_exit(esi_exit); /* makes module removable... */ | ||
diff --git a/arch/ia64/kernel/esi_stub.S b/arch/ia64/kernel/esi_stub.S new file mode 100644 index 000000000000..6b3d6c1f99b6 --- /dev/null +++ b/arch/ia64/kernel/esi_stub.S | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * ESI call stub. | ||
3 | * | ||
4 | * Copyright (C) 2005 Hewlett-Packard Co | ||
5 | * Alex Williamson <alex.williamson@hp.com> | ||
6 | * | ||
7 | * Based on EFI call stub by David Mosberger. The stub is virtually | ||
8 | * identical to the one for EFI phys-mode calls, except that ESI | ||
9 | * calls may have up to 8 arguments, so they get passed to this routine | ||
10 | * through memory. | ||
11 | * | ||
12 | * This stub allows us to make ESI calls in physical mode with interrupts | ||
13 | * turned off. ESI calls may not support calling from virtual mode. | ||
14 | * | ||
15 | * Google for "Extensible SAL specification" for a document describing the | ||
16 | * ESI standard. | ||
17 | */ | ||
18 | |||
19 | /* | ||
20 | * PSR settings as per SAL spec (Chapter 8 in the "IA-64 System | ||
21 | * Abstraction Layer Specification", revision 2.6e). Note that | ||
22 | * psr.dfl and psr.dfh MUST be cleared, despite what this manual says. | ||
23 | * Otherwise, SAL dies whenever it's trying to do an IA-32 BIOS call | ||
24 | * (the br.ia instruction fails unless psr.dfl and psr.dfh are | ||
25 | * cleared). Fortunately, SAL promises not to touch the floating | ||
26 | * point regs, so at least we don't have to save f2-f127. | ||
27 | */ | ||
28 | #define PSR_BITS_TO_CLEAR \ | ||
29 | (IA64_PSR_I | IA64_PSR_IT | IA64_PSR_DT | IA64_PSR_RT | \ | ||
30 | IA64_PSR_DD | IA64_PSR_SS | IA64_PSR_RI | IA64_PSR_ED | \ | ||
31 | IA64_PSR_DFL | IA64_PSR_DFH) | ||
32 | |||
33 | #define PSR_BITS_TO_SET \ | ||
34 | (IA64_PSR_BN) | ||
35 | |||
36 | #include <asm/processor.h> | ||
37 | #include <asm/asmmacro.h> | ||
38 | |||
39 | /* | ||
40 | * Inputs: | ||
41 | * in0 = address of function descriptor of ESI routine to call | ||
42 | * in1 = address of array of ESI parameters | ||
43 | * | ||
44 | * Outputs: | ||
45 | * r8 = result returned by called function | ||
46 | */ | ||
47 | GLOBAL_ENTRY(esi_call_phys) | ||
48 | .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2) | ||
49 | alloc loc1=ar.pfs,2,7,8,0 | ||
50 | ld8 r2=[in0],8 // load ESI function's entry point | ||
51 | mov loc0=rp | ||
52 | .body | ||
53 | ;; | ||
54 | ld8 out0=[in1],8 // ESI params loaded from array | ||
55 | ;; // passing all as inputs doesn't work | ||
56 | ld8 out1=[in1],8 | ||
57 | ;; | ||
58 | ld8 out2=[in1],8 | ||
59 | ;; | ||
60 | ld8 out3=[in1],8 | ||
61 | ;; | ||
62 | ld8 out4=[in1],8 | ||
63 | ;; | ||
64 | ld8 out5=[in1],8 | ||
65 | ;; | ||
66 | ld8 out6=[in1],8 | ||
67 | ;; | ||
68 | ld8 out7=[in1] | ||
69 | mov loc2=gp // save global pointer | ||
70 | mov loc4=ar.rsc // save RSE configuration | ||
71 | mov ar.rsc=0 // put RSE in enforced lazy, LE mode | ||
72 | ;; | ||
73 | ld8 gp=[in0] // load ESI function's global pointer | ||
74 | movl r16=PSR_BITS_TO_CLEAR | ||
75 | mov loc3=psr // save processor status word | ||
76 | movl r17=PSR_BITS_TO_SET | ||
77 | ;; | ||
78 | or loc3=loc3,r17 | ||
79 | mov b6=r2 | ||
80 | ;; | ||
81 | andcm r16=loc3,r16 // get psr with IT, DT, and RT bits cleared | ||
82 | br.call.sptk.many rp=ia64_switch_mode_phys | ||
83 | .ret0: mov loc5=r19 // old ar.bsp | ||
84 | mov loc6=r20 // old sp | ||
85 | br.call.sptk.many rp=b6 // call the ESI function | ||
86 | .ret1: mov ar.rsc=0 // put RSE in enforced lazy, LE mode | ||
87 | mov r16=loc3 // save virtual mode psr | ||
88 | mov r19=loc5 // save virtual mode bspstore | ||
89 | mov r20=loc6 // save virtual mode sp | ||
90 | br.call.sptk.many rp=ia64_switch_mode_virt // return to virtual mode | ||
91 | .ret2: mov ar.rsc=loc4 // restore RSE configuration | ||
92 | mov ar.pfs=loc1 | ||
93 | mov rp=loc0 | ||
94 | mov gp=loc2 | ||
95 | br.ret.sptk.many rp | ||
96 | END(esi_call_phys) | ||
diff --git a/arch/ia64/kernel/ia64_ksyms.c b/arch/ia64/kernel/ia64_ksyms.c index bbcfd08378a6..9583f310d486 100644 --- a/arch/ia64/kernel/ia64_ksyms.c +++ b/arch/ia64/kernel/ia64_ksyms.c | |||
@@ -106,5 +106,9 @@ EXPORT_SYMBOL(ia64_spinlock_contention); | |||
106 | # endif | 106 | # endif |
107 | #endif | 107 | #endif |
108 | 108 | ||
109 | #if defined(CONFIG_IA64_ESI) || defined(CONFIG_IA64_ESI_MODULE) | ||
110 | extern void esi_call_phys (void); | ||
111 | EXPORT_SYMBOL_GPL(esi_call_phys); | ||
112 | #endif | ||
109 | extern char ia64_ivt[]; | 113 | extern char ia64_ivt[]; |
110 | EXPORT_SYMBOL(ia64_ivt); | 114 | EXPORT_SYMBOL(ia64_ivt); |
diff --git a/include/asm-ia64/esi.h b/include/asm-ia64/esi.h new file mode 100644 index 000000000000..84aac0e0b583 --- /dev/null +++ b/include/asm-ia64/esi.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | * ESI service calls. | ||
3 | * | ||
4 | * Copyright (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. | ||
5 | * Alex Williamson <alex.williamson@hp.com> | ||
6 | */ | ||
7 | #ifndef esi_h | ||
8 | #define esi_h | ||
9 | |||
10 | #include <linux/efi.h> | ||
11 | |||
12 | #define ESI_QUERY 0x00000001 | ||
13 | #define ESI_OPEN_HANDLE 0x02000000 | ||
14 | #define ESI_CLOSE_HANDLE 0x02000001 | ||
15 | |||
16 | enum esi_proc_type { | ||
17 | ESI_PROC_SERIALIZED, /* calls need to be serialized */ | ||
18 | ESI_PROC_MP_SAFE, /* MP-safe, but not reentrant */ | ||
19 | ESI_PROC_REENTRANT /* MP-safe and reentrant */ | ||
20 | }; | ||
21 | |||
22 | extern int ia64_esi_init (void); | ||
23 | extern struct ia64_sal_retval esi_call_phys (void *, u64 *); | ||
24 | extern int ia64_esi_call(efi_guid_t, struct ia64_sal_retval *, | ||
25 | enum esi_proc_type, | ||
26 | u64, u64, u64, u64, u64, u64, u64, u64); | ||
27 | extern int ia64_esi_call_phys(efi_guid_t, struct ia64_sal_retval *, u64, u64, | ||
28 | u64, u64, u64, u64, u64, u64); | ||
29 | |||
30 | #endif /* esi_h */ | ||