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