^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Extensible SAL Interface (ESI) support routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006 Hewlett-Packard Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Alex Williamson <alex.williamson@hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/esi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/sal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) MODULE_AUTHOR("Alex Williamson <alex.williamson@hp.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_DESCRIPTION("Extensible SAL Interface (ESI) support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define MODULE_NAME "esi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) enum esi_systab_entry_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) ESI_DESC_ENTRY_POINT = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Entry type: Size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * 0 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define ESI_DESC_SIZE(type) "\060"[(unsigned) (type)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) typedef struct ia64_esi_desc_entry_point {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u8 reserved1[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u64 esi_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u64 gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) efi_guid_t guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) } ia64_esi_desc_entry_point_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct pdesc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) void *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) void *gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct ia64_sal_systab *esi_systab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) extern unsigned long esi_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int __init esi_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct ia64_sal_systab *systab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (esi_phys == EFI_INVALID_TABLE_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) systab = __va(esi_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (strncmp(systab->signature, "ESIT", 4) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) printk(KERN_ERR "bad signature in ESI system table!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) p = (char *) (systab + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) for (i = 0; i < systab->entry_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * The first byte of each entry type contains the type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) switch (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case ESI_DESC_ENTRY_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) printk(KERN_WARNING "Unknown table type %d found in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "ESI table, ignoring rest of table\n", *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) p += ESI_DESC_SIZE(*p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) esi_systab = systab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int ia64_esi_call (efi_guid_t guid, struct ia64_sal_retval *isrvp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) enum esi_proc_type proc_type, u64 func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u64 arg7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct ia64_fpreg fr[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (!esi_systab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) p = (char *) (esi_systab + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) for (i = 0; i < esi_systab->entry_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (*p == ESI_DESC_ENTRY_POINT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ia64_esi_desc_entry_point_t *esi = (void *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!efi_guidcmp(guid, esi->guid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ia64_sal_handler esi_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct pdesc pdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) pdesc.addr = __va(esi->esi_proc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pdesc.gp = __va(esi->gp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) esi_proc = (ia64_sal_handler) &pdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ia64_save_scratch_fpregs(fr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (proc_type == ESI_PROC_SERIALIZED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) spin_lock_irqsave(&sal_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) else if (proc_type == ESI_PROC_MP_SAFE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *isrvp = (*esi_proc)(func, arg1, arg2, arg3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) arg4, arg5, arg6, arg7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (proc_type == ESI_PROC_SERIALIZED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) spin_unlock_irqrestore(&sal_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) else if (proc_type == ESI_PROC_MP_SAFE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ia64_load_scratch_fpregs(fr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) p += ESI_DESC_SIZE(*p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) EXPORT_SYMBOL_GPL(ia64_esi_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int ia64_esi_call_phys (efi_guid_t guid, struct ia64_sal_retval *isrvp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u64 func, u64 arg1, u64 arg2, u64 arg3, u64 arg4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) u64 arg5, u64 arg6, u64 arg7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct ia64_fpreg fr[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u64 esi_params[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!esi_systab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) p = (char *) (esi_systab + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) for (i = 0; i < esi_systab->entry_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (*p == ESI_DESC_ENTRY_POINT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ia64_esi_desc_entry_point_t *esi = (void *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!efi_guidcmp(guid, esi->guid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ia64_sal_handler esi_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct pdesc pdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pdesc.addr = (void *)esi->esi_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pdesc.gp = (void *)esi->gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) esi_proc = (ia64_sal_handler) &pdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) esi_params[0] = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) esi_params[1] = arg1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) esi_params[2] = arg2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) esi_params[3] = arg3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) esi_params[4] = arg4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) esi_params[5] = arg5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) esi_params[6] = arg6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) esi_params[7] = arg7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ia64_save_scratch_fpregs(fr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) spin_lock_irqsave(&sal_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *isrvp = esi_call_phys(esi_proc, esi_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) spin_unlock_irqrestore(&sal_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ia64_load_scratch_fpregs(fr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) p += ESI_DESC_SIZE(*p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL_GPL(ia64_esi_call_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void __exit esi_exit (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) module_init(esi_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) module_exit(esi_exit); /* makes module removable... */