1 /* $NetBSD: sal.c,v 1.2 2006/04/08 14:52:09 cherry Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 Doug Rabson 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 31 #include <sys/param.h> 32 #include <sys/reboot.h> 33 #include <sys/systm.h> 34 #include <sys/kernel.h> 35 #include <sys/malloc.h> 36 37 #include <machine/efi.h> 38 #include <machine/vmparam.h> 39 #include <machine/md_var.h> 40 #include <machine/sal.h> 41 #include <machine/smp.h> 42 43 /* 44 * IPIs are used more genericly than only 45 * for inter-processor interrupts. Don't 46 * make it a SMP specific thing... 47 */ 48 int ipi_vector[IPI_COUNT]; 49 50 static struct ia64_fdesc sal_fdesc; 51 static sal_entry_t fake_sal; 52 53 extern u_int64_t ia64_pal_entry; 54 sal_entry_t *ia64_sal_entry = fake_sal; 55 56 static struct uuid sal_table = EFI_TABLE_SAL; 57 static struct sal_system_table *sal_systbl; 58 59 static struct ia64_sal_result 60 fake_sal(u_int64_t a1, u_int64_t a2, u_int64_t a3, u_int64_t a4, 61 u_int64_t a5, u_int64_t a6, u_int64_t a7, u_int64_t a8) 62 { 63 struct ia64_sal_result res; 64 res.sal_status = -3; 65 res.sal_result[0] = 0; 66 res.sal_result[1] = 0; 67 res.sal_result[2] = 0; 68 return res; 69 } 70 71 static void 72 setup_ipi_vectors(int ceil) 73 { 74 int ipi; 75 76 ipi_vector[IPI_MCA_RENDEZ] = ceil - 0x10; 77 ipi_vector[IPI_MCA_CMCV] = ceil - 0x30; 78 ipi_vector[IPI_TEST] = ceil - 0x30 + 1; 79 80 ipi = IPI_AST; /* First generic IPI. */ 81 ceil -= 0x20; /* First vector in group. */ 82 while (ipi < IPI_COUNT) 83 ipi_vector[ipi++] = ceil++; 84 } 85 86 void 87 ia64_sal_init(void) 88 { 89 static int sizes[6] = { 90 48, 32, 16, 32, 16, 16 91 }; 92 u_int8_t *p; 93 int i; 94 95 sal_systbl = efi_get_table(&sal_table); 96 if (sal_systbl == NULL) 97 return; 98 99 if (memcmp(sal_systbl->sal_signature, SAL_SIGNATURE, 4)) { 100 printf("Bad signature for SAL System Table\n"); 101 return; 102 } 103 104 p = (u_int8_t *) (sal_systbl + 1); 105 for (i = 0; i < sal_systbl->sal_entry_count; i++) { 106 switch (*p) { 107 case 0: { 108 struct sal_entrypoint_descriptor *dp; 109 110 dp = (struct sal_entrypoint_descriptor*)p; 111 ia64_pal_entry = IA64_PHYS_TO_RR7(dp->sale_pal_proc); 112 if (bootverbose) 113 printf("PAL Proc at 0x%lx\n", ia64_pal_entry); 114 sal_fdesc.func = IA64_PHYS_TO_RR7(dp->sale_sal_proc); 115 sal_fdesc.gp = IA64_PHYS_TO_RR7(dp->sale_sal_gp); 116 if (bootverbose) 117 printf("SAL Proc at 0x%lx, GP at 0x%lx\n", 118 sal_fdesc.func, sal_fdesc.gp); 119 ia64_sal_entry = (sal_entry_t *) &sal_fdesc; 120 break; 121 } 122 case 5: { 123 struct sal_ap_wakeup_descriptor *dp; 124 #ifdef SMP 125 struct ia64_sal_result result; 126 struct ia64_fdesc *fd; 127 #endif 128 129 dp = (struct sal_ap_wakeup_descriptor*)p; 130 if (dp->sale_mechanism != 0) { 131 printf("SAL: unsupported AP wake-up mechanism " 132 "(%d)\n", dp->sale_mechanism); 133 break; 134 } 135 136 if (dp->sale_vector < 0x10 || dp->sale_vector > 0xff) { 137 printf("SAL: invalid AP wake-up vector " 138 "(0x%lx)\n", dp->sale_vector); 139 break; 140 } 141 142 /* 143 * SAL documents that the wake-up vector should be 144 * high (close to 255). The MCA rendezvous vector 145 * should be less than the wake-up vector, but still 146 * "high". We use the following priority assignment: 147 * Wake-up: priority of the sale_vector 148 * Rendezvous: priority-1 149 * Generic IPIs: priority-2 150 * Special IPIs: priority-3 151 * Consequently, the wake-up priority should be at 152 * least 4 (ie vector >= 0x40). 153 */ 154 if (dp->sale_vector < 0x40) { 155 printf("SAL: AP wake-up vector too low " 156 "(0x%lx)\n", dp->sale_vector); 157 break; 158 } 159 160 if (bootverbose) 161 printf("SAL: AP wake-up vector: 0x%lx\n", 162 dp->sale_vector); 163 164 ipi_vector[IPI_AP_WAKEUP] = dp->sale_vector; 165 setup_ipi_vectors(dp->sale_vector & 0xf0); 166 167 #ifdef SMP 168 fd = (struct ia64_fdesc *) os_boot_rendez; 169 result = ia64_sal_entry(SAL_SET_VECTORS, 170 SAL_OS_BOOT_RENDEZ, ia64_tpa(fd->func), 171 ia64_tpa(fd->gp), 0, 0, 0, 0); 172 #endif 173 174 break; 175 } 176 } 177 p += sizes[*p]; 178 } 179 180 if (ipi_vector[IPI_AP_WAKEUP] == 0) 181 setup_ipi_vectors(0xf0); 182 } 183