Print this page
4665 pcplusmp open-codes register operations
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Approved by: Robert Mustacchi <rm@joyent.com>
4664 CPU->cpu_pri_data hasn't been used for years
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Approved by: Robert Mustacchi <rm@joyent.com>
4663 apic_cr8pri complicates pcplusmp
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Approved by: Robert Mustacchi <rm@joyent.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/i86pc/io/pcplusmp/apic.c
+++ new/usr/src/uts/i86pc/io/pcplusmp/apic.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright (c) 2010, Intel Corporation.
27 27 * All rights reserved.
28 28 */
29 29 /*
30 30 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
31 31 */
32 32
33 33 /*
34 34 * To understand how the pcplusmp module interacts with the interrupt subsystem
35 35 * read the theory statement in uts/i86pc/os/intr.c.
36 36 */
37 37
38 38 /*
39 39 * PSMI 1.1 extensions are supported only in 2.6 and later versions.
40 40 * PSMI 1.2 extensions are supported only in 2.7 and later versions.
41 41 * PSMI 1.3 and 1.4 extensions are supported in Solaris 10.
42 42 * PSMI 1.5 extensions are supported in Solaris Nevada.
43 43 * PSMI 1.6 extensions are supported in Solaris Nevada.
44 44 * PSMI 1.7 extensions are supported in Solaris Nevada.
45 45 */
46 46 #define PSMI_1_7
47 47
48 48 #include <sys/processor.h>
49 49 #include <sys/time.h>
50 50 #include <sys/psm.h>
51 51 #include <sys/smp_impldefs.h>
52 52 #include <sys/cram.h>
53 53 #include <sys/acpi/acpi.h>
54 54 #include <sys/acpica.h>
55 55 #include <sys/psm_common.h>
56 56 #include <sys/apic.h>
57 57 #include <sys/pit.h>
58 58 #include <sys/ddi.h>
59 59 #include <sys/sunddi.h>
60 60 #include <sys/ddi_impldefs.h>
61 61 #include <sys/pci.h>
62 62 #include <sys/promif.h>
63 63 #include <sys/x86_archext.h>
64 64 #include <sys/cpc_impl.h>
65 65 #include <sys/uadmin.h>
66 66 #include <sys/panic.h>
67 67 #include <sys/debug.h>
68 68 #include <sys/archsystm.h>
69 69 #include <sys/trap.h>
70 70 #include <sys/machsystm.h>
71 71 #include <sys/sysmacros.h>
72 72 #include <sys/cpuvar.h>
73 73 #include <sys/rm_platter.h>
74 74 #include <sys/privregs.h>
75 75 #include <sys/note.h>
76 76 #include <sys/pci_intr_lib.h>
77 77 #include <sys/spl.h>
78 78 #include <sys/clock.h>
79 79 #include <sys/cyclic.h>
80 80 #include <sys/dditypes.h>
81 81 #include <sys/sunddi.h>
82 82 #include <sys/x_call.h>
83 83 #include <sys/reboot.h>
84 84 #include <sys/hpet.h>
85 85 #include <sys/apic_common.h>
86 86 #include <sys/apic_timer.h>
87 87
88 88 /*
89 89 * Local Function Prototypes
90 90 */
91 91 static void apic_init_intr(void);
92 92
93 93 /*
94 94 * standard MP entries
95 95 */
96 96 static int apic_probe(void);
97 97 static int apic_getclkirq(int ipl);
98 98 static void apic_init(void);
99 99 static void apic_picinit(void);
100 100 static int apic_post_cpu_start(void);
101 101 static int apic_intr_enter(int ipl, int *vect);
102 102 static void apic_setspl(int ipl);
103 103 static void x2apic_setspl(int ipl);
104 104 static int apic_addspl(int ipl, int vector, int min_ipl, int max_ipl);
105 105 static int apic_delspl(int ipl, int vector, int min_ipl, int max_ipl);
106 106 static int apic_disable_intr(processorid_t cpun);
107 107 static void apic_enable_intr(processorid_t cpun);
108 108 static int apic_get_ipivect(int ipl, int type);
109 109 static void apic_post_cyclic_setup(void *arg);
110 110
111 111 /*
112 112 * The following vector assignments influence the value of ipltopri and
113 113 * vectortoipl. Note that vectors 0 - 0x1f are not used. We can program
114 114 * idle to 0 and IPL 0 to 0xf to differentiate idle in case
115 115 * we care to do so in future. Note some IPLs which are rarely used
116 116 * will share the vector ranges and heavily used IPLs (5 and 6) have
117 117 * a wide range.
118 118 *
119 119 * This array is used to initialize apic_ipls[] (in apic_init()).
120 120 *
121 121 * IPL Vector range. as passed to intr_enter
122 122 * 0 none.
123 123 * 1,2,3 0x20-0x2f 0x0-0xf
124 124 * 4 0x30-0x3f 0x10-0x1f
125 125 * 5 0x40-0x5f 0x20-0x3f
126 126 * 6 0x60-0x7f 0x40-0x5f
127 127 * 7,8,9 0x80-0x8f 0x60-0x6f
128 128 * 10 0x90-0x9f 0x70-0x7f
129 129 * 11 0xa0-0xaf 0x80-0x8f
130 130 * ... ...
131 131 * 15 0xe0-0xef 0xc0-0xcf
132 132 * 15 0xf0-0xff 0xd0-0xdf
133 133 */
134 134 uchar_t apic_vectortoipl[APIC_AVAIL_VECTOR / APIC_VECTOR_PER_IPL] = {
135 135 3, 4, 5, 5, 6, 6, 9, 10, 11, 12, 13, 14, 15, 15
|
↓ open down ↓ |
135 lines elided |
↑ open up ↑ |
136 136 };
137 137 /*
138 138 * The ipl of an ISR at vector X is apic_vectortoipl[X>>4]
139 139 * NOTE that this is vector as passed into intr_enter which is
140 140 * programmed vector - 0x20 (APIC_BASE_VECT)
141 141 */
142 142
143 143 uchar_t apic_ipltopri[MAXIPL + 1]; /* unix ipl to apic pri */
144 144 /* The taskpri to be programmed into apic to mask given ipl */
145 145
146 -#if defined(__amd64)
147 -uchar_t apic_cr8pri[MAXIPL + 1]; /* unix ipl to cr8 pri */
148 -#endif
149 -
150 146 /*
151 147 * Correlation of the hardware vector to the IPL in use, initialized
152 148 * from apic_vectortoipl[] in apic_init(). The final IPLs may not correlate
153 149 * to the IPLs in apic_vectortoipl on some systems that share interrupt lines
154 150 * connected to errata-stricken IOAPICs
155 151 */
156 152 uchar_t apic_ipls[APIC_AVAIL_VECTOR];
157 153
158 154 /*
159 155 * Patchable global variables.
160 156 */
161 157 int apic_enable_hwsoftint = 0; /* 0 - disable, 1 - enable */
162 158 int apic_enable_bind_log = 1; /* 1 - display interrupt binding log */
163 159
164 160 /*
165 161 * Local static data
166 162 */
167 163 static struct psm_ops apic_ops = {
168 164 apic_probe,
169 165
170 166 apic_init,
171 167 apic_picinit,
172 168 apic_intr_enter,
173 169 apic_intr_exit,
174 170 apic_setspl,
175 171 apic_addspl,
176 172 apic_delspl,
177 173 apic_disable_intr,
178 174 apic_enable_intr,
179 175 (int (*)(int))NULL, /* psm_softlvl_to_irq */
180 176 (void (*)(int))NULL, /* psm_set_softintr */
181 177
182 178 apic_set_idlecpu,
183 179 apic_unset_idlecpu,
184 180
185 181 apic_clkinit,
186 182 apic_getclkirq,
187 183 (void (*)(void))NULL, /* psm_hrtimeinit */
188 184 apic_gethrtime,
189 185
190 186 apic_get_next_processorid,
191 187 apic_cpu_start,
192 188 apic_post_cpu_start,
193 189 apic_shutdown,
194 190 apic_get_ipivect,
195 191 apic_send_ipi,
196 192
197 193 (int (*)(dev_info_t *, int))NULL, /* psm_translate_irq */
198 194 (void (*)(int, char *))NULL, /* psm_notify_error */
199 195 (void (*)(int))NULL, /* psm_notify_func */
200 196 apic_timer_reprogram,
201 197 apic_timer_enable,
202 198 apic_timer_disable,
203 199 apic_post_cyclic_setup,
204 200 apic_preshutdown,
205 201 apic_intr_ops, /* Advanced DDI Interrupt framework */
206 202 apic_state, /* save, restore apic state for S3 */
207 203 apic_cpu_ops, /* CPU control interface. */
208 204 };
209 205
210 206 struct psm_ops *psmops = &apic_ops;
211 207
212 208 static struct psm_info apic_psm_info = {
213 209 PSM_INFO_VER01_7, /* version */
214 210 PSM_OWN_EXCLUSIVE, /* ownership */
215 211 (struct psm_ops *)&apic_ops, /* operation */
216 212 APIC_PCPLUSMP_NAME, /* machine name */
217 213 "pcplusmp v1.4 compatible",
218 214 };
219 215
220 216 static void *apic_hdlp;
221 217
222 218 /*
223 219 * apic_let_idle_redistribute can have the following values:
224 220 * 0 - If clock decremented it from 1 to 0, clock has to call redistribute.
225 221 * apic_redistribute_lock prevents multiple idle cpus from redistributing
226 222 */
227 223 int apic_num_idle_redistributions = 0;
228 224 static int apic_let_idle_redistribute = 0;
229 225
230 226 /* to gather intr data and redistribute */
231 227 static void apic_redistribute_compute(void);
232 228
233 229 /*
234 230 * This is the loadable module wrapper
235 231 */
236 232
237 233 int
238 234 _init(void)
239 235 {
240 236 if (apic_coarse_hrtime)
241 237 apic_ops.psm_gethrtime = &apic_gettime;
242 238 return (psm_mod_init(&apic_hdlp, &apic_psm_info));
243 239 }
244 240
245 241 int
246 242 _fini(void)
247 243 {
248 244 return (psm_mod_fini(&apic_hdlp, &apic_psm_info));
249 245 }
250 246
251 247 int
252 248 _info(struct modinfo *modinfop)
253 249 {
254 250 return (psm_mod_info(&apic_hdlp, &apic_psm_info, modinfop));
255 251 }
256 252
257 253 static int
258 254 apic_probe(void)
259 255 {
260 256 /* check if apix is initialized */
261 257 if (apix_enable && apix_loaded())
262 258 return (PSM_FAILURE);
263 259 else
264 260 apix_enable = 0; /* continue using pcplusmp PSM */
265 261
266 262 return (apic_probe_common(apic_psm_info.p_mach_idstring));
267 263 }
268 264
269 265 static uchar_t
270 266 apic_xlate_vector_by_irq(uchar_t irq)
271 267 {
272 268 if (apic_irq_table[irq] == NULL)
273 269 return (0);
274 270
275 271 return (apic_irq_table[irq]->airq_vector);
276 272 }
277 273
278 274 void
279 275 apic_init(void)
280 276 {
281 277 int i;
282 278 int j = 1;
283 279
284 280 psm_get_ioapicid = apic_get_ioapicid;
285 281 psm_get_localapicid = apic_get_localapicid;
286 282 psm_xlate_vector_by_irq = apic_xlate_vector_by_irq;
287 283
288 284 apic_ipltopri[0] = APIC_VECTOR_PER_IPL; /* leave 0 for idle */
289 285 for (i = 0; i < (APIC_AVAIL_VECTOR / APIC_VECTOR_PER_IPL); i++) {
290 286 if ((i < ((APIC_AVAIL_VECTOR / APIC_VECTOR_PER_IPL) - 1)) &&
291 287 (apic_vectortoipl[i + 1] == apic_vectortoipl[i]))
292 288 /* get to highest vector at the same ipl */
|
↓ open down ↓ |
133 lines elided |
↑ open up ↑ |
293 289 continue;
294 290 for (; j <= apic_vectortoipl[i]; j++) {
295 291 apic_ipltopri[j] = (i << APIC_IPL_SHIFT) +
296 292 APIC_BASE_VECT;
297 293 }
298 294 }
299 295 for (; j < MAXIPL + 1; j++)
300 296 /* fill up any empty ipltopri slots */
301 297 apic_ipltopri[j] = (i << APIC_IPL_SHIFT) + APIC_BASE_VECT;
302 298 apic_init_common();
303 -#if defined(__amd64)
304 - /*
305 - * Make cpu-specific interrupt info point to cr8pri vector
306 - */
307 - for (i = 0; i <= MAXIPL; i++)
308 - apic_cr8pri[i] = apic_ipltopri[i] >> APIC_IPL_SHIFT;
309 - CPU->cpu_pri_data = apic_cr8pri;
310 -#else
299 +
300 +#if !defined(__amd64)
311 301 if (cpuid_have_cr8access(CPU))
312 302 apic_have_32bit_cr8 = 1;
313 -#endif /* __amd64 */
303 +#endif
314 304 }
315 305
316 306 static void
317 307 apic_init_intr(void)
318 308 {
319 309 processorid_t cpun = psm_get_cpu_id();
320 310 uint_t nlvt;
321 311 uint32_t svr = AV_UNIT_ENABLE | APIC_SPUR_INTR;
322 312
323 313 apic_reg_ops->apic_write_task_reg(APIC_MASK_ALL);
324 314
325 315 if (apic_mode == LOCAL_APIC) {
326 316 /*
327 317 * We are running APIC in MMIO mode.
328 318 */
329 319 if (apic_flat_model) {
330 320 apic_reg_ops->apic_write(APIC_FORMAT_REG,
331 321 APIC_FLAT_MODEL);
332 322 } else {
333 323 apic_reg_ops->apic_write(APIC_FORMAT_REG,
334 324 APIC_CLUSTER_MODEL);
335 325 }
336 326
337 327 apic_reg_ops->apic_write(APIC_DEST_REG,
338 328 AV_HIGH_ORDER >> cpun);
339 329 }
340 330
341 331 if (apic_directed_EOI_supported()) {
342 332 /*
343 333 * Setting the 12th bit in the Spurious Interrupt Vector
344 334 * Register suppresses broadcast EOIs generated by the local
345 335 * APIC. The suppression of broadcast EOIs happens only when
346 336 * interrupts are level-triggered.
347 337 */
348 338 svr |= APIC_SVR_SUPPRESS_BROADCAST_EOI;
349 339 }
350 340
351 341 /* need to enable APIC before unmasking NMI */
352 342 apic_reg_ops->apic_write(APIC_SPUR_INT_REG, svr);
353 343
354 344 /*
355 345 * Presence of an invalid vector with delivery mode AV_FIXED can
356 346 * cause an error interrupt, even if the entry is masked...so
357 347 * write a valid vector to LVT entries along with the mask bit
358 348 */
359 349
360 350 /* All APICs have timer and LINT0/1 */
361 351 apic_reg_ops->apic_write(APIC_LOCAL_TIMER, AV_MASK|APIC_RESV_IRQ);
362 352 apic_reg_ops->apic_write(APIC_INT_VECT0, AV_MASK|APIC_RESV_IRQ);
363 353 apic_reg_ops->apic_write(APIC_INT_VECT1, AV_NMI); /* enable NMI */
364 354
365 355 /*
366 356 * On integrated APICs, the number of LVT entries is
367 357 * 'Max LVT entry' + 1; on 82489DX's (non-integrated
368 358 * APICs), nlvt is "3" (LINT0, LINT1, and timer)
369 359 */
370 360
371 361 if (apic_cpus[cpun].aci_local_ver < APIC_INTEGRATED_VERS) {
372 362 nlvt = 3;
373 363 } else {
374 364 nlvt = ((apic_reg_ops->apic_read(APIC_VERS_REG) >> 16) &
375 365 0xFF) + 1;
376 366 }
377 367
378 368 if (nlvt >= 5) {
379 369 /* Enable performance counter overflow interrupt */
380 370
381 371 if (!is_x86_feature(x86_featureset, X86FSET_MSR))
382 372 apic_enable_cpcovf_intr = 0;
383 373 if (apic_enable_cpcovf_intr) {
384 374 if (apic_cpcovf_vect == 0) {
385 375 int ipl = APIC_PCINT_IPL;
386 376 int irq = apic_get_ipivect(ipl, -1);
387 377
388 378 ASSERT(irq != -1);
389 379 apic_cpcovf_vect =
390 380 apic_irq_table[irq]->airq_vector;
391 381 ASSERT(apic_cpcovf_vect);
392 382 (void) add_avintr(NULL, ipl,
393 383 (avfunc)kcpc_hw_overflow_intr,
394 384 "apic pcint", irq, NULL, NULL, NULL, NULL);
395 385 kcpc_hw_overflow_intr_installed = 1;
396 386 kcpc_hw_enable_cpc_intr =
397 387 apic_cpcovf_mask_clear;
398 388 }
399 389 apic_reg_ops->apic_write(APIC_PCINT_VECT,
400 390 apic_cpcovf_vect);
401 391 }
402 392 }
403 393
404 394 if (nlvt >= 6) {
405 395 /* Only mask TM intr if the BIOS apparently doesn't use it */
406 396
407 397 uint32_t lvtval;
408 398
409 399 lvtval = apic_reg_ops->apic_read(APIC_THERM_VECT);
410 400 if (((lvtval & AV_MASK) == AV_MASK) ||
411 401 ((lvtval & AV_DELIV_MODE) != AV_SMI)) {
412 402 apic_reg_ops->apic_write(APIC_THERM_VECT,
413 403 AV_MASK|APIC_RESV_IRQ);
414 404 }
415 405 }
416 406
417 407 /* Enable error interrupt */
418 408
419 409 if (nlvt >= 4 && apic_enable_error_intr) {
420 410 if (apic_errvect == 0) {
421 411 int ipl = 0xf; /* get highest priority intr */
422 412 int irq = apic_get_ipivect(ipl, -1);
423 413
424 414 ASSERT(irq != -1);
425 415 apic_errvect = apic_irq_table[irq]->airq_vector;
426 416 ASSERT(apic_errvect);
427 417 /*
428 418 * Not PSMI compliant, but we are going to merge
429 419 * with ON anyway
430 420 */
431 421 (void) add_avintr((void *)NULL, ipl,
432 422 (avfunc)apic_error_intr, "apic error intr",
433 423 irq, NULL, NULL, NULL, NULL);
434 424 }
435 425 apic_reg_ops->apic_write(APIC_ERR_VECT, apic_errvect);
436 426 apic_reg_ops->apic_write(APIC_ERROR_STATUS, 0);
437 427 apic_reg_ops->apic_write(APIC_ERROR_STATUS, 0);
438 428 }
439 429
440 430 /* Enable CMCI interrupt */
441 431 if (cmi_enable_cmci) {
442 432
443 433 mutex_enter(&cmci_cpu_setup_lock);
444 434 if (cmci_cpu_setup_registered == 0) {
445 435 mutex_enter(&cpu_lock);
446 436 register_cpu_setup_func(cmci_cpu_setup, NULL);
447 437 mutex_exit(&cpu_lock);
448 438 cmci_cpu_setup_registered = 1;
449 439 }
450 440 mutex_exit(&cmci_cpu_setup_lock);
451 441
452 442 if (apic_cmci_vect == 0) {
453 443 int ipl = 0x2;
454 444 int irq = apic_get_ipivect(ipl, -1);
455 445
456 446 ASSERT(irq != -1);
457 447 apic_cmci_vect = apic_irq_table[irq]->airq_vector;
458 448 ASSERT(apic_cmci_vect);
459 449
460 450 (void) add_avintr(NULL, ipl,
461 451 (avfunc)cmi_cmci_trap,
462 452 "apic cmci intr", irq, NULL, NULL, NULL, NULL);
463 453 }
464 454 apic_reg_ops->apic_write(APIC_CMCI_VECT, apic_cmci_vect);
465 455 }
466 456 }
467 457
468 458 static void
469 459 apic_picinit(void)
470 460 {
471 461 int i, j;
472 462 uint_t isr;
473 463
474 464 /*
475 465 * Initialize and enable interrupt remapping before apic
476 466 * hardware initialization
477 467 */
478 468 apic_intrmap_init(apic_mode);
479 469
480 470 /*
481 471 * On UniSys Model 6520, the BIOS leaves vector 0x20 isr
482 472 * bit on without clearing it with EOI. Since softint
483 473 * uses vector 0x20 to interrupt itself, so softint will
484 474 * not work on this machine. In order to fix this problem
485 475 * a check is made to verify all the isr bits are clear.
486 476 * If not, EOIs are issued to clear the bits.
487 477 */
488 478 for (i = 7; i >= 1; i--) {
489 479 isr = apic_reg_ops->apic_read(APIC_ISR_REG + (i * 4));
490 480 if (isr != 0)
491 481 for (j = 0; ((j < 32) && (isr != 0)); j++)
492 482 if (isr & (1 << j)) {
493 483 apic_reg_ops->apic_write(
494 484 APIC_EOI_REG, 0);
495 485 isr &= ~(1 << j);
496 486 apic_error |= APIC_ERR_BOOT_EOI;
497 487 }
498 488 }
499 489
500 490 /* set a flag so we know we have run apic_picinit() */
501 491 apic_picinit_called = 1;
502 492 LOCK_INIT_CLEAR(&apic_gethrtime_lock);
503 493 LOCK_INIT_CLEAR(&apic_ioapic_lock);
504 494 LOCK_INIT_CLEAR(&apic_error_lock);
505 495 LOCK_INIT_CLEAR(&apic_mode_switch_lock);
506 496
507 497 picsetup(); /* initialise the 8259 */
508 498
509 499 /* add nmi handler - least priority nmi handler */
510 500 LOCK_INIT_CLEAR(&apic_nmi_lock);
511 501
512 502 if (!psm_add_nmintr(0, (avfunc) apic_nmi_intr,
513 503 "pcplusmp NMI handler", (caddr_t)NULL))
514 504 cmn_err(CE_WARN, "pcplusmp: Unable to add nmi handler");
515 505
516 506 /*
517 507 * Check for directed-EOI capability in the local APIC.
518 508 */
519 509 if (apic_directed_EOI_supported() == 1) {
520 510 apic_set_directed_EOI_handler();
521 511 }
522 512
523 513 apic_init_intr();
524 514
525 515 /* enable apic mode if imcr present */
526 516 if (apic_imcrp) {
527 517 outb(APIC_IMCR_P1, (uchar_t)APIC_IMCR_SELECT);
528 518 outb(APIC_IMCR_P2, (uchar_t)APIC_IMCR_APIC);
529 519 }
530 520
531 521 ioapic_init_intr(IOAPIC_MASK);
532 522 }
533 523
534 524 #ifdef DEBUG
535 525 void
536 526 apic_break(void)
537 527 {
538 528 }
539 529 #endif /* DEBUG */
540 530
541 531 /*
542 532 * platform_intr_enter
543 533 *
544 534 * Called at the beginning of the interrupt service routine to
545 535 * mask all level equal to and below the interrupt priority
546 536 * of the interrupting vector. An EOI should be given to
547 537 * the interrupt controller to enable other HW interrupts.
548 538 *
549 539 * Return -1 for spurious interrupts
550 540 *
551 541 */
552 542 /*ARGSUSED*/
553 543 static int
554 544 apic_intr_enter(int ipl, int *vectorp)
555 545 {
556 546 uchar_t vector;
557 547 int nipl;
558 548 int irq;
559 549 ulong_t iflag;
560 550 apic_cpus_info_t *cpu_infop;
561 551
562 552 /*
563 553 * The real vector delivered is (*vectorp + 0x20), but our caller
564 554 * subtracts 0x20 from the vector before passing it to us.
565 555 * (That's why APIC_BASE_VECT is 0x20.)
566 556 */
567 557 vector = (uchar_t)*vectorp;
568 558
569 559 /* if interrupted by the clock, increment apic_nsec_since_boot */
570 560 if (vector == apic_clkvect) {
571 561 if (!apic_oneshot) {
572 562 /* NOTE: this is not MT aware */
573 563 apic_hrtime_stamp++;
|
↓ open down ↓ |
250 lines elided |
↑ open up ↑ |
574 564 apic_nsec_since_boot += apic_nsec_per_intr;
575 565 apic_hrtime_stamp++;
576 566 last_count_read = apic_hertz_count;
577 567 apic_redistribute_compute();
578 568 }
579 569
580 570 /* We will avoid all the book keeping overhead for clock */
581 571 nipl = apic_ipls[vector];
582 572
583 573 *vectorp = apic_vector_to_irq[vector + APIC_BASE_VECT];
584 - if (apic_mode == LOCAL_APIC) {
585 -#if defined(__amd64)
586 - setcr8((ulong_t)(apic_ipltopri[nipl] >>
587 - APIC_IPL_SHIFT));
588 -#else
589 - if (apic_have_32bit_cr8)
590 - setcr8((ulong_t)(apic_ipltopri[nipl] >>
591 - APIC_IPL_SHIFT));
592 - else
593 - LOCAL_APIC_WRITE_REG(APIC_TASK_REG,
594 - (uint32_t)apic_ipltopri[nipl]);
595 -#endif
596 - LOCAL_APIC_WRITE_REG(APIC_EOI_REG, 0);
597 - } else {
598 - X2APIC_WRITE(APIC_TASK_REG, apic_ipltopri[nipl]);
599 - X2APIC_WRITE(APIC_EOI_REG, 0);
600 - }
601 574
575 + apic_reg_ops->apic_write_task_reg(apic_ipltopri[nipl]);
576 + apic_reg_ops->apic_send_eoi(0);
577 +
602 578 return (nipl);
603 579 }
604 580
605 581 cpu_infop = &apic_cpus[psm_get_cpu_id()];
606 582
607 583 if (vector == (APIC_SPUR_INTR - APIC_BASE_VECT)) {
608 584 cpu_infop->aci_spur_cnt++;
609 585 return (APIC_INT_SPURIOUS);
610 586 }
611 587
612 588 /* Check if the vector we got is really what we need */
613 589 if (apic_revector_pending) {
614 590 /*
615 591 * Disable interrupts for the duration of
616 592 * the vector translation to prevent a self-race for
617 593 * the apic_revector_lock. This cannot be done
618 594 * in apic_xlate_vector because it is recursive and
619 595 * we want the vector translation to be atomic with
620 596 * respect to other (higher-priority) interrupts.
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
621 597 */
622 598 iflag = intr_clear();
623 599 vector = apic_xlate_vector(vector + APIC_BASE_VECT) -
624 600 APIC_BASE_VECT;
625 601 intr_restore(iflag);
626 602 }
627 603
628 604 nipl = apic_ipls[vector];
629 605 *vectorp = irq = apic_vector_to_irq[vector + APIC_BASE_VECT];
630 606
631 - if (apic_mode == LOCAL_APIC) {
632 -#if defined(__amd64)
633 - setcr8((ulong_t)(apic_ipltopri[nipl] >> APIC_IPL_SHIFT));
634 -#else
635 - if (apic_have_32bit_cr8)
636 - setcr8((ulong_t)(apic_ipltopri[nipl] >>
637 - APIC_IPL_SHIFT));
638 - else
639 - LOCAL_APIC_WRITE_REG(APIC_TASK_REG,
640 - (uint32_t)apic_ipltopri[nipl]);
641 -#endif
642 - } else {
643 - X2APIC_WRITE(APIC_TASK_REG, apic_ipltopri[nipl]);
644 - }
607 + apic_reg_ops->apic_write_task_reg(apic_ipltopri[nipl]);
645 608
646 609 cpu_infop->aci_current[nipl] = (uchar_t)irq;
647 610 cpu_infop->aci_curipl = (uchar_t)nipl;
648 611 cpu_infop->aci_ISR_in_progress |= 1 << nipl;
649 612
650 613 /*
651 614 * apic_level_intr could have been assimilated into the irq struct.
652 615 * but, having it as a character array is more efficient in terms of
653 616 * cache usage. So, we leave it as is.
654 617 */
655 618 if (!apic_level_intr[irq]) {
656 - if (apic_mode == LOCAL_APIC) {
657 - LOCAL_APIC_WRITE_REG(APIC_EOI_REG, 0);
658 - } else {
659 - X2APIC_WRITE(APIC_EOI_REG, 0);
660 - }
619 + apic_reg_ops->apic_send_eoi(0);
661 620 }
662 621
663 622 #ifdef DEBUG
664 623 APIC_DEBUG_BUF_PUT(vector);
665 624 APIC_DEBUG_BUF_PUT(irq);
666 625 APIC_DEBUG_BUF_PUT(nipl);
667 626 APIC_DEBUG_BUF_PUT(psm_get_cpu_id());
668 627 if ((apic_stretch_interrupts) && (apic_stretch_ISR & (1 << nipl)))
669 628 drv_usecwait(apic_stretch_interrupts);
670 629
671 630 if (apic_break_on_cpu == psm_get_cpu_id())
672 631 apic_break();
673 632 #endif /* DEBUG */
674 633 return (nipl);
675 634 }
676 635
677 636 /*
678 637 * This macro is a common code used by MMIO local apic and X2APIC
679 638 * local apic.
680 639 */
681 640 #define APIC_INTR_EXIT() \
682 641 { \
683 642 cpu_infop = &apic_cpus[psm_get_cpu_id()]; \
684 643 if (apic_level_intr[irq]) \
685 644 apic_reg_ops->apic_send_eoi(irq); \
686 645 cpu_infop->aci_curipl = (uchar_t)prev_ipl; \
687 646 /* ISR above current pri could not be in progress */ \
688 647 cpu_infop->aci_ISR_in_progress &= (2 << prev_ipl) - 1; \
689 648 }
|
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
690 649
691 650 /*
692 651 * Any changes made to this function must also change X2APIC
693 652 * version of intr_exit.
694 653 */
695 654 void
696 655 apic_intr_exit(int prev_ipl, int irq)
697 656 {
698 657 apic_cpus_info_t *cpu_infop;
699 658
700 -#if defined(__amd64)
701 - setcr8((ulong_t)apic_cr8pri[prev_ipl]);
702 -#else
703 - if (apic_have_32bit_cr8)
704 - setcr8((ulong_t)(apic_ipltopri[prev_ipl] >> APIC_IPL_SHIFT));
705 - else
706 - apicadr[APIC_TASK_REG] = apic_ipltopri[prev_ipl];
707 -#endif
659 + apic_reg_ops->apic_write_task_reg(apic_ipltopri[prev_ipl]);
708 660
709 661 APIC_INTR_EXIT();
710 662 }
711 663
712 664 /*
713 665 * Same as apic_intr_exit() except it uses MSR rather than MMIO
714 666 * to access local apic registers.
715 667 */
716 668 void
717 669 x2apic_intr_exit(int prev_ipl, int irq)
718 670 {
719 671 apic_cpus_info_t *cpu_infop;
720 672
721 673 X2APIC_WRITE(APIC_TASK_REG, apic_ipltopri[prev_ipl]);
722 674 APIC_INTR_EXIT();
723 675 }
724 676
725 677 intr_exit_fn_t
726 678 psm_intr_exit_fn(void)
727 679 {
728 680 if (apic_mode == LOCAL_X2APIC)
729 681 return (x2apic_intr_exit);
730 682
731 683 return (apic_intr_exit);
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
732 684 }
733 685
734 686 /*
735 687 * Mask all interrupts below or equal to the given IPL.
736 688 * Any changes made to this function must also change X2APIC
737 689 * version of setspl.
738 690 */
739 691 static void
740 692 apic_setspl(int ipl)
741 693 {
742 -#if defined(__amd64)
743 - setcr8((ulong_t)apic_cr8pri[ipl]);
744 -#else
745 - if (apic_have_32bit_cr8)
746 - setcr8((ulong_t)(apic_ipltopri[ipl] >> APIC_IPL_SHIFT));
747 - else
748 - apicadr[APIC_TASK_REG] = apic_ipltopri[ipl];
749 -#endif
694 + apic_reg_ops->apic_write_task_reg(apic_ipltopri[ipl]);
750 695
751 696 /* interrupts at ipl above this cannot be in progress */
752 697 apic_cpus[psm_get_cpu_id()].aci_ISR_in_progress &= (2 << ipl) - 1;
753 698 /*
754 699 * this is a patch fix for the ALR QSMP P5 machine, so that interrupts
755 700 * have enough time to come in before the priority is raised again
756 701 * during the idle() loop.
757 702 */
758 703 if (apic_setspl_delay)
759 704 (void) apic_reg_ops->apic_get_pri();
760 705 }
761 706
762 707 /*
763 708 * X2APIC version of setspl.
764 709 * Mask all interrupts below or equal to the given IPL
765 710 */
766 711 static void
767 712 x2apic_setspl(int ipl)
768 713 {
769 714 X2APIC_WRITE(APIC_TASK_REG, apic_ipltopri[ipl]);
770 715
771 716 /* interrupts at ipl above this cannot be in progress */
772 717 apic_cpus[psm_get_cpu_id()].aci_ISR_in_progress &= (2 << ipl) - 1;
773 718 }
774 719
775 720 /*ARGSUSED*/
776 721 static int
777 722 apic_addspl(int irqno, int ipl, int min_ipl, int max_ipl)
778 723 {
779 724 return (apic_addspl_common(irqno, ipl, min_ipl, max_ipl));
780 725 }
781 726
782 727 static int
783 728 apic_delspl(int irqno, int ipl, int min_ipl, int max_ipl)
784 729 {
785 730 return (apic_delspl_common(irqno, ipl, min_ipl, max_ipl));
786 731 }
787 732
788 733 static int
789 734 apic_post_cpu_start(void)
790 735 {
791 736 int cpun;
792 737 static int cpus_started = 1;
793 738
794 739 /* We know this CPU + BSP started successfully. */
795 740 cpus_started++;
796 741
797 742 /*
798 743 * On BSP we would have enabled X2APIC, if supported by processor,
799 744 * in acpi_probe(), but on AP we do it here.
800 745 *
801 746 * We enable X2APIC mode only if BSP is running in X2APIC & the
802 747 * local APIC mode of the current CPU is MMIO (xAPIC).
803 748 */
804 749 if (apic_mode == LOCAL_X2APIC && apic_detect_x2apic() &&
805 750 apic_local_mode() == LOCAL_APIC) {
806 751 apic_enable_x2apic();
807 752 }
808 753
809 754 /*
810 755 * Switch back to x2apic IPI sending method for performance when target
811 756 * CPU has entered x2apic mode.
812 757 */
813 758 if (apic_mode == LOCAL_X2APIC) {
814 759 apic_switch_ipi_callback(B_FALSE);
815 760 }
816 761
817 762 splx(ipltospl(LOCK_LEVEL));
818 763 apic_init_intr();
819 764
820 765 /*
821 766 * since some systems don't enable the internal cache on the non-boot
822 767 * cpus, so we have to enable them here
823 768 */
824 769 setcr0(getcr0() & ~(CR0_CD | CR0_NW));
825 770
826 771 #ifdef DEBUG
827 772 APIC_AV_PENDING_SET();
828 773 #else
829 774 if (apic_mode == LOCAL_APIC)
830 775 APIC_AV_PENDING_SET();
831 776 #endif /* DEBUG */
832 777
833 778 /*
834 779 * We may be booting, or resuming from suspend; aci_status will
835 780 * be APIC_CPU_INTR_ENABLE if coming from suspend, so we add the
836 781 * APIC_CPU_ONLINE flag here rather than setting aci_status completely.
837 782 */
838 783 cpun = psm_get_cpu_id();
839 784 apic_cpus[cpun].aci_status |= APIC_CPU_ONLINE;
840 785
841 786 apic_reg_ops->apic_write(APIC_DIVIDE_REG, apic_divide_reg_init);
842 787 return (PSM_SUCCESS);
843 788 }
844 789
845 790 /*
846 791 * type == -1 indicates it is an internal request. Do not change
847 792 * resv_vector for these requests
848 793 */
849 794 static int
850 795 apic_get_ipivect(int ipl, int type)
851 796 {
852 797 uchar_t vector;
853 798 int irq;
854 799
855 800 if ((irq = apic_allocate_irq(APIC_VECTOR(ipl))) != -1) {
856 801 if (vector = apic_allocate_vector(ipl, irq, 1)) {
857 802 apic_irq_table[irq]->airq_mps_intr_index =
858 803 RESERVE_INDEX;
859 804 apic_irq_table[irq]->airq_vector = vector;
860 805 if (type != -1) {
861 806 apic_resv_vector[ipl] = vector;
862 807 }
863 808 return (irq);
864 809 }
865 810 }
866 811 apic_error |= APIC_ERR_GET_IPIVECT_FAIL;
867 812 return (-1); /* shouldn't happen */
868 813 }
869 814
870 815 static int
871 816 apic_getclkirq(int ipl)
872 817 {
873 818 int irq;
874 819
875 820 if ((irq = apic_get_ipivect(ipl, -1)) == -1)
876 821 return (-1);
877 822 /*
878 823 * Note the vector in apic_clkvect for per clock handling.
879 824 */
880 825 apic_clkvect = apic_irq_table[irq]->airq_vector - APIC_BASE_VECT;
881 826 APIC_VERBOSE_IOAPIC((CE_NOTE, "get_clkirq: vector = %x\n",
882 827 apic_clkvect));
883 828 return (irq);
884 829 }
885 830
886 831 /*
887 832 * Try and disable all interrupts. We just assign interrupts to other
888 833 * processors based on policy. If any were bound by user request, we
889 834 * let them continue and return failure. We do not bother to check
890 835 * for cache affinity while rebinding.
891 836 */
892 837
893 838 static int
894 839 apic_disable_intr(processorid_t cpun)
895 840 {
896 841 int bind_cpu = 0, i, hardbound = 0;
897 842 apic_irq_t *irq_ptr;
898 843 ulong_t iflag;
899 844
900 845 iflag = intr_clear();
901 846 lock_set(&apic_ioapic_lock);
902 847
903 848 for (i = 0; i <= APIC_MAX_VECTOR; i++) {
904 849 if (apic_reprogram_info[i].done == B_FALSE) {
905 850 if (apic_reprogram_info[i].bindcpu == cpun) {
906 851 /*
907 852 * CPU is busy -- it's the target of
908 853 * a pending reprogramming attempt
909 854 */
910 855 lock_clear(&apic_ioapic_lock);
911 856 intr_restore(iflag);
912 857 return (PSM_FAILURE);
913 858 }
914 859 }
915 860 }
916 861
917 862 apic_cpus[cpun].aci_status &= ~APIC_CPU_INTR_ENABLE;
918 863
919 864 apic_cpus[cpun].aci_curipl = 0;
920 865
921 866 i = apic_min_device_irq;
922 867 for (; i <= apic_max_device_irq; i++) {
923 868 /*
924 869 * If there are bound interrupts on this cpu, then
925 870 * rebind them to other processors.
926 871 */
927 872 if ((irq_ptr = apic_irq_table[i]) != NULL) {
928 873 ASSERT((irq_ptr->airq_temp_cpu == IRQ_UNBOUND) ||
929 874 (irq_ptr->airq_temp_cpu == IRQ_UNINIT) ||
930 875 (apic_cpu_in_range(irq_ptr->airq_temp_cpu)));
931 876
932 877 if (irq_ptr->airq_temp_cpu == (cpun | IRQ_USER_BOUND)) {
933 878 hardbound = 1;
934 879 continue;
935 880 }
936 881
937 882 if (irq_ptr->airq_temp_cpu == cpun) {
938 883 do {
939 884 bind_cpu =
940 885 apic_find_cpu(APIC_CPU_INTR_ENABLE);
941 886 } while (apic_rebind_all(irq_ptr, bind_cpu));
942 887 }
943 888 }
944 889 }
945 890
946 891 lock_clear(&apic_ioapic_lock);
947 892 intr_restore(iflag);
948 893
949 894 if (hardbound) {
950 895 cmn_err(CE_WARN, "Could not disable interrupts on %d"
951 896 "due to user bound interrupts", cpun);
952 897 return (PSM_FAILURE);
953 898 }
954 899 else
955 900 return (PSM_SUCCESS);
956 901 }
957 902
958 903 /*
959 904 * Bind interrupts to the CPU's local APIC.
960 905 * Interrupts should not be bound to a CPU's local APIC until the CPU
961 906 * is ready to receive interrupts.
962 907 */
963 908 static void
964 909 apic_enable_intr(processorid_t cpun)
965 910 {
966 911 int i;
967 912 apic_irq_t *irq_ptr;
968 913 ulong_t iflag;
969 914
970 915 iflag = intr_clear();
971 916 lock_set(&apic_ioapic_lock);
972 917
973 918 apic_cpus[cpun].aci_status |= APIC_CPU_INTR_ENABLE;
974 919
975 920 i = apic_min_device_irq;
976 921 for (i = apic_min_device_irq; i <= apic_max_device_irq; i++) {
977 922 if ((irq_ptr = apic_irq_table[i]) != NULL) {
978 923 if ((irq_ptr->airq_cpu & ~IRQ_USER_BOUND) == cpun) {
979 924 (void) apic_rebind_all(irq_ptr,
980 925 irq_ptr->airq_cpu);
981 926 }
982 927 }
983 928 }
984 929
985 930 if (apic_cpus[cpun].aci_status & APIC_CPU_SUSPEND)
986 931 apic_cpus[cpun].aci_status &= ~APIC_CPU_SUSPEND;
987 932
988 933 lock_clear(&apic_ioapic_lock);
989 934 intr_restore(iflag);
990 935 }
991 936
992 937 /*
993 938 * If this module needs a periodic handler for the interrupt distribution, it
994 939 * can be added here. The argument to the periodic handler is not currently
995 940 * used, but is reserved for future.
996 941 */
997 942 static void
998 943 apic_post_cyclic_setup(void *arg)
999 944 {
1000 945 _NOTE(ARGUNUSED(arg))
1001 946
1002 947 cyc_handler_t cyh;
1003 948 cyc_time_t cyt;
1004 949
1005 950 /* cpu_lock is held */
1006 951 /* set up a periodic handler for intr redistribution */
1007 952
1008 953 /*
1009 954 * In peridoc mode intr redistribution processing is done in
1010 955 * apic_intr_enter during clk intr processing
1011 956 */
1012 957 if (!apic_oneshot)
1013 958 return;
1014 959
1015 960 /*
1016 961 * Register a periodical handler for the redistribution processing.
1017 962 * Though we would generally prefer to use the DDI interface for
1018 963 * periodic handler invocation, ddi_periodic_add(9F), we are
1019 964 * unfortunately already holding cpu_lock, which ddi_periodic_add will
1020 965 * attempt to take for us. Thus, we add our own cyclic directly:
1021 966 */
1022 967 cyh.cyh_func = (void (*)(void *))apic_redistribute_compute;
1023 968 cyh.cyh_arg = NULL;
1024 969 cyh.cyh_level = CY_LOW_LEVEL;
1025 970
1026 971 cyt.cyt_when = 0;
1027 972 cyt.cyt_interval = apic_redistribute_sample_interval;
1028 973
1029 974 apic_cyclic_id = cyclic_add(&cyh, &cyt);
1030 975 }
1031 976
1032 977 static void
1033 978 apic_redistribute_compute(void)
1034 979 {
1035 980 int i, j, max_busy;
1036 981
1037 982 if (apic_enable_dynamic_migration) {
1038 983 if (++apic_nticks == apic_sample_factor_redistribution) {
1039 984 /*
1040 985 * Time to call apic_intr_redistribute().
1041 986 * reset apic_nticks. This will cause max_busy
1042 987 * to be calculated below and if it is more than
1043 988 * apic_int_busy, we will do the whole thing
1044 989 */
1045 990 apic_nticks = 0;
1046 991 }
1047 992 max_busy = 0;
1048 993 for (i = 0; i < apic_nproc; i++) {
1049 994 if (!apic_cpu_in_range(i))
1050 995 continue;
1051 996
1052 997 /*
1053 998 * Check if curipl is non zero & if ISR is in
1054 999 * progress
1055 1000 */
1056 1001 if (((j = apic_cpus[i].aci_curipl) != 0) &&
1057 1002 (apic_cpus[i].aci_ISR_in_progress & (1 << j))) {
1058 1003
1059 1004 int irq;
1060 1005 apic_cpus[i].aci_busy++;
1061 1006 irq = apic_cpus[i].aci_current[j];
1062 1007 apic_irq_table[irq]->airq_busy++;
1063 1008 }
1064 1009
1065 1010 if (!apic_nticks &&
1066 1011 (apic_cpus[i].aci_busy > max_busy))
1067 1012 max_busy = apic_cpus[i].aci_busy;
1068 1013 }
1069 1014 if (!apic_nticks) {
1070 1015 if (max_busy > apic_int_busy_mark) {
1071 1016 /*
1072 1017 * We could make the following check be
1073 1018 * skipped > 1 in which case, we get a
1074 1019 * redistribution at half the busy mark (due to
1075 1020 * double interval). Need to be able to collect
1076 1021 * more empirical data to decide if that is a
1077 1022 * good strategy. Punt for now.
1078 1023 */
1079 1024 if (apic_skipped_redistribute) {
1080 1025 apic_cleanup_busy();
1081 1026 apic_skipped_redistribute = 0;
1082 1027 } else {
1083 1028 apic_intr_redistribute();
1084 1029 }
1085 1030 } else
1086 1031 apic_skipped_redistribute++;
1087 1032 }
1088 1033 }
1089 1034 }
1090 1035
1091 1036
1092 1037 /*
1093 1038 * The following functions are in the platform specific file so that they
1094 1039 * can be different functions depending on whether we are running on
1095 1040 * bare metal or a hypervisor.
1096 1041 */
1097 1042
1098 1043 /*
1099 1044 * Check to make sure there are enough irq slots
1100 1045 */
1101 1046 int
1102 1047 apic_check_free_irqs(int count)
1103 1048 {
1104 1049 int i, avail;
1105 1050
1106 1051 avail = 0;
1107 1052 for (i = APIC_FIRST_FREE_IRQ; i < APIC_RESV_IRQ; i++) {
1108 1053 if ((apic_irq_table[i] == NULL) ||
1109 1054 apic_irq_table[i]->airq_mps_intr_index == FREE_INDEX) {
1110 1055 if (++avail >= count)
1111 1056 return (PSM_SUCCESS);
1112 1057 }
1113 1058 }
1114 1059 return (PSM_FAILURE);
1115 1060 }
1116 1061
1117 1062 /*
1118 1063 * This function allocates "count" MSI vector(s) for the given "dip/pri/type"
1119 1064 */
1120 1065 int
1121 1066 apic_alloc_msi_vectors(dev_info_t *dip, int inum, int count, int pri,
1122 1067 int behavior)
1123 1068 {
1124 1069 int rcount, i;
1125 1070 uchar_t start, irqno;
1126 1071 uint32_t cpu;
1127 1072 major_t major;
1128 1073 apic_irq_t *irqptr;
1129 1074
1130 1075 DDI_INTR_IMPLDBG((CE_CONT, "apic_alloc_msi_vectors: dip=0x%p "
1131 1076 "inum=0x%x pri=0x%x count=0x%x behavior=%d\n",
1132 1077 (void *)dip, inum, pri, count, behavior));
1133 1078
1134 1079 if (count > 1) {
1135 1080 if (behavior == DDI_INTR_ALLOC_STRICT &&
1136 1081 apic_multi_msi_enable == 0)
1137 1082 return (0);
1138 1083 if (apic_multi_msi_enable == 0)
1139 1084 count = 1;
1140 1085 }
1141 1086
1142 1087 if ((rcount = apic_navail_vector(dip, pri)) > count)
1143 1088 rcount = count;
1144 1089 else if (rcount == 0 || (rcount < count &&
1145 1090 behavior == DDI_INTR_ALLOC_STRICT))
1146 1091 return (0);
1147 1092
1148 1093 /* if not ISP2, then round it down */
1149 1094 if (!ISP2(rcount))
1150 1095 rcount = 1 << (highbit(rcount) - 1);
1151 1096
1152 1097 mutex_enter(&airq_mutex);
1153 1098
1154 1099 for (start = 0; rcount > 0; rcount >>= 1) {
1155 1100 if ((start = apic_find_multi_vectors(pri, rcount)) != 0 ||
1156 1101 behavior == DDI_INTR_ALLOC_STRICT)
1157 1102 break;
1158 1103 }
1159 1104
1160 1105 if (start == 0) {
1161 1106 /* no vector available */
1162 1107 mutex_exit(&airq_mutex);
1163 1108 return (0);
1164 1109 }
1165 1110
1166 1111 if (apic_check_free_irqs(rcount) == PSM_FAILURE) {
1167 1112 /* not enough free irq slots available */
1168 1113 mutex_exit(&airq_mutex);
1169 1114 return (0);
1170 1115 }
1171 1116
1172 1117 major = (dip != NULL) ? ddi_driver_major(dip) : 0;
1173 1118 for (i = 0; i < rcount; i++) {
1174 1119 if ((irqno = apic_allocate_irq(apic_first_avail_irq)) ==
1175 1120 (uchar_t)-1) {
1176 1121 /*
1177 1122 * shouldn't happen because of the
1178 1123 * apic_check_free_irqs() check earlier
1179 1124 */
1180 1125 mutex_exit(&airq_mutex);
1181 1126 DDI_INTR_IMPLDBG((CE_CONT, "apic_alloc_msi_vectors: "
1182 1127 "apic_allocate_irq failed\n"));
1183 1128 return (i);
1184 1129 }
1185 1130 apic_max_device_irq = max(irqno, apic_max_device_irq);
1186 1131 apic_min_device_irq = min(irqno, apic_min_device_irq);
1187 1132 irqptr = apic_irq_table[irqno];
1188 1133 #ifdef DEBUG
1189 1134 if (apic_vector_to_irq[start + i] != APIC_RESV_IRQ)
1190 1135 DDI_INTR_IMPLDBG((CE_CONT, "apic_alloc_msi_vectors: "
1191 1136 "apic_vector_to_irq is not APIC_RESV_IRQ\n"));
1192 1137 #endif
1193 1138 apic_vector_to_irq[start + i] = (uchar_t)irqno;
1194 1139
1195 1140 irqptr->airq_vector = (uchar_t)(start + i);
1196 1141 irqptr->airq_ioapicindex = (uchar_t)inum; /* start */
1197 1142 irqptr->airq_intin_no = (uchar_t)rcount;
1198 1143 irqptr->airq_ipl = pri;
1199 1144 irqptr->airq_vector = start + i;
1200 1145 irqptr->airq_origirq = (uchar_t)(inum + i);
1201 1146 irqptr->airq_share_id = 0;
1202 1147 irqptr->airq_mps_intr_index = MSI_INDEX;
1203 1148 irqptr->airq_dip = dip;
1204 1149 irqptr->airq_major = major;
1205 1150 if (i == 0) /* they all bound to the same cpu */
1206 1151 cpu = irqptr->airq_cpu = apic_bind_intr(dip, irqno,
1207 1152 0xff, 0xff);
1208 1153 else
1209 1154 irqptr->airq_cpu = cpu;
1210 1155 DDI_INTR_IMPLDBG((CE_CONT, "apic_alloc_msi_vectors: irq=0x%x "
1211 1156 "dip=0x%p vector=0x%x origirq=0x%x pri=0x%x\n", irqno,
1212 1157 (void *)irqptr->airq_dip, irqptr->airq_vector,
1213 1158 irqptr->airq_origirq, pri));
1214 1159 }
1215 1160 mutex_exit(&airq_mutex);
1216 1161 return (rcount);
1217 1162 }
1218 1163
1219 1164 /*
1220 1165 * This function allocates "count" MSI-X vector(s) for the given "dip/pri/type"
1221 1166 */
1222 1167 int
1223 1168 apic_alloc_msix_vectors(dev_info_t *dip, int inum, int count, int pri,
1224 1169 int behavior)
1225 1170 {
1226 1171 int rcount, i;
1227 1172 major_t major;
1228 1173
1229 1174 mutex_enter(&airq_mutex);
1230 1175
1231 1176 if ((rcount = apic_navail_vector(dip, pri)) > count)
1232 1177 rcount = count;
1233 1178 else if (rcount == 0 || (rcount < count &&
1234 1179 behavior == DDI_INTR_ALLOC_STRICT)) {
1235 1180 rcount = 0;
1236 1181 goto out;
1237 1182 }
1238 1183
1239 1184 if (apic_check_free_irqs(rcount) == PSM_FAILURE) {
1240 1185 /* not enough free irq slots available */
1241 1186 rcount = 0;
1242 1187 goto out;
1243 1188 }
1244 1189
1245 1190 major = (dip != NULL) ? ddi_driver_major(dip) : 0;
1246 1191 for (i = 0; i < rcount; i++) {
1247 1192 uchar_t vector, irqno;
1248 1193 apic_irq_t *irqptr;
1249 1194
1250 1195 if ((irqno = apic_allocate_irq(apic_first_avail_irq)) ==
1251 1196 (uchar_t)-1) {
1252 1197 /*
1253 1198 * shouldn't happen because of the
1254 1199 * apic_check_free_irqs() check earlier
1255 1200 */
1256 1201 DDI_INTR_IMPLDBG((CE_CONT, "apic_alloc_msix_vectors: "
1257 1202 "apic_allocate_irq failed\n"));
1258 1203 rcount = i;
1259 1204 goto out;
1260 1205 }
1261 1206 if ((vector = apic_allocate_vector(pri, irqno, 1)) == 0) {
1262 1207 /*
1263 1208 * shouldn't happen because of the
1264 1209 * apic_navail_vector() call earlier
1265 1210 */
1266 1211 DDI_INTR_IMPLDBG((CE_CONT, "apic_alloc_msix_vectors: "
1267 1212 "apic_allocate_vector failed\n"));
1268 1213 rcount = i;
1269 1214 goto out;
1270 1215 }
1271 1216 apic_max_device_irq = max(irqno, apic_max_device_irq);
1272 1217 apic_min_device_irq = min(irqno, apic_min_device_irq);
1273 1218 irqptr = apic_irq_table[irqno];
1274 1219 irqptr->airq_vector = (uchar_t)vector;
1275 1220 irqptr->airq_ipl = pri;
1276 1221 irqptr->airq_origirq = (uchar_t)(inum + i);
1277 1222 irqptr->airq_share_id = 0;
1278 1223 irqptr->airq_mps_intr_index = MSIX_INDEX;
1279 1224 irqptr->airq_dip = dip;
1280 1225 irqptr->airq_major = major;
1281 1226 irqptr->airq_cpu = apic_bind_intr(dip, irqno, 0xff, 0xff);
1282 1227 }
1283 1228 out:
1284 1229 mutex_exit(&airq_mutex);
1285 1230 return (rcount);
1286 1231 }
1287 1232
1288 1233 /*
1289 1234 * Allocate a free vector for irq at ipl. Takes care of merging of multiple
1290 1235 * IPLs into a single APIC level as well as stretching some IPLs onto multiple
1291 1236 * levels. APIC_HI_PRI_VECTS interrupts are reserved for high priority
1292 1237 * requests and allocated only when pri is set.
1293 1238 */
1294 1239 uchar_t
1295 1240 apic_allocate_vector(int ipl, int irq, int pri)
1296 1241 {
1297 1242 int lowest, highest, i;
1298 1243
1299 1244 highest = apic_ipltopri[ipl] + APIC_VECTOR_MASK;
1300 1245 lowest = apic_ipltopri[ipl - 1] + APIC_VECTOR_PER_IPL;
1301 1246
1302 1247 if (highest < lowest) /* Both ipl and ipl - 1 map to same pri */
1303 1248 lowest -= APIC_VECTOR_PER_IPL;
1304 1249
1305 1250 #ifdef DEBUG
1306 1251 if (apic_restrict_vector) /* for testing shared interrupt logic */
1307 1252 highest = lowest + apic_restrict_vector + APIC_HI_PRI_VECTS;
1308 1253 #endif /* DEBUG */
1309 1254 if (pri == 0)
1310 1255 highest -= APIC_HI_PRI_VECTS;
1311 1256
1312 1257 for (i = lowest; i <= highest; i++) {
1313 1258 if (APIC_CHECK_RESERVE_VECTORS(i))
1314 1259 continue;
1315 1260 if (apic_vector_to_irq[i] == APIC_RESV_IRQ) {
1316 1261 apic_vector_to_irq[i] = (uchar_t)irq;
1317 1262 return (i);
1318 1263 }
1319 1264 }
1320 1265
1321 1266 return (0);
1322 1267 }
1323 1268
1324 1269 /* Mark vector as not being used by any irq */
1325 1270 void
1326 1271 apic_free_vector(uchar_t vector)
1327 1272 {
1328 1273 apic_vector_to_irq[vector] = APIC_RESV_IRQ;
1329 1274 }
1330 1275
1331 1276 /*
1332 1277 * Call rebind to do the actual programming.
1333 1278 * Must be called with interrupts disabled and apic_ioapic_lock held
1334 1279 * 'p' is polymorphic -- if this function is called to process a deferred
1335 1280 * reprogramming, p is of type 'struct ioapic_reprogram_data *', from which
1336 1281 * the irq pointer is retrieved. If not doing deferred reprogramming,
1337 1282 * p is of the type 'apic_irq_t *'.
1338 1283 *
1339 1284 * apic_ioapic_lock must be held across this call, as it protects apic_rebind
1340 1285 * and it protects apic_get_next_bind_cpu() from a race in which a CPU can be
1341 1286 * taken offline after a cpu is selected, but before apic_rebind is called to
1342 1287 * bind interrupts to it.
1343 1288 */
1344 1289 int
1345 1290 apic_setup_io_intr(void *p, int irq, boolean_t deferred)
1346 1291 {
1347 1292 apic_irq_t *irqptr;
1348 1293 struct ioapic_reprogram_data *drep = NULL;
1349 1294 int rv;
1350 1295
1351 1296 if (deferred) {
1352 1297 drep = (struct ioapic_reprogram_data *)p;
1353 1298 ASSERT(drep != NULL);
1354 1299 irqptr = drep->irqp;
1355 1300 } else
1356 1301 irqptr = (apic_irq_t *)p;
1357 1302
1358 1303 ASSERT(irqptr != NULL);
1359 1304
1360 1305 rv = apic_rebind(irqptr, apic_irq_table[irq]->airq_cpu, drep);
1361 1306 if (rv) {
1362 1307 /*
1363 1308 * CPU is not up or interrupts are disabled. Fall back to
1364 1309 * the first available CPU
1365 1310 */
1366 1311 rv = apic_rebind(irqptr, apic_find_cpu(APIC_CPU_INTR_ENABLE),
1367 1312 drep);
1368 1313 }
1369 1314
1370 1315 return (rv);
1371 1316 }
1372 1317
1373 1318
1374 1319 uchar_t
1375 1320 apic_modify_vector(uchar_t vector, int irq)
1376 1321 {
1377 1322 apic_vector_to_irq[vector] = (uchar_t)irq;
1378 1323 return (vector);
1379 1324 }
1380 1325
1381 1326 char *
1382 1327 apic_get_apic_type(void)
1383 1328 {
1384 1329 return (apic_psm_info.p_mach_idstring);
1385 1330 }
1386 1331
1387 1332 void
1388 1333 x2apic_update_psm(void)
1389 1334 {
1390 1335 struct psm_ops *pops = &apic_ops;
1391 1336
1392 1337 ASSERT(pops != NULL);
1393 1338
1394 1339 pops->psm_intr_exit = x2apic_intr_exit;
1395 1340 pops->psm_setspl = x2apic_setspl;
1396 1341
1397 1342 pops->psm_send_ipi = x2apic_send_ipi;
1398 1343 send_dirintf = pops->psm_send_ipi;
1399 1344
1400 1345 apic_mode = LOCAL_X2APIC;
1401 1346 apic_change_ops();
1402 1347 }
|
↓ open down ↓ |
643 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX