xref: /freebsd/sys/powerpc/powerpc/interrupt.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * Copyright 2002 by Peter Grehan. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * Interrupts are dispatched to here from locore asm
30  */
31 
32 #include "opt_hwpmc_hooks.h"
33 #include "opt_platform.h"
34 
35 #include <sys/cdefs.h>                  /* RCS ID & Copyright macro defns */
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/bus.h>
40 #include <sys/interrupt.h>
41 #include <sys/kernel.h>
42 #include <sys/kthread.h>
43 #include <sys/ktr.h>
44 #include <sys/lock.h>
45 #include <sys/malloc.h>
46 #include <sys/mutex.h>
47 #ifdef HWPMC_HOOKS
48 #include <sys/pmckern.h>
49 #endif
50 #include <sys/proc.h>
51 #include <sys/smp.h>
52 #include <sys/unistd.h>
53 #include <sys/vmmeter.h>
54 
55 #include <machine/cpu.h>
56 #include <machine/clock.h>
57 #include <machine/db_machdep.h>
58 #include <machine/fpu.h>
59 #include <machine/frame.h>
60 #include <machine/intr_machdep.h>
61 #include <machine/md_var.h>
62 #include <machine/pcb.h>
63 #include <machine/psl.h>
64 #include <machine/trap.h>
65 #include <machine/spr.h>
66 #include <machine/sr.h>
67 
68 #include "pic_if.h"
69 
70 #ifdef POWERNV
71 int (*hmi_handler)(struct trapframe *);
72 #endif
73 
74 /*
75  * A very short dispatch, to try and maximise assembler code use
76  * between all exception types. Maybe 'true' interrupts should go
77  * here, and the trap code can come in separately
78  */
79 void
powerpc_interrupt(struct trapframe * framep)80 powerpc_interrupt(struct trapframe *framep)
81 {
82 	struct thread *td;
83 	struct trapframe *oldframe;
84 	register_t ee;
85 
86 	td = curthread;
87 
88 	CTR2(KTR_INTR, "%s: EXC=%x", __func__, framep->exc);
89 
90 	switch (framep->exc) {
91 	case EXC_EXI:
92 	case EXC_HVI:
93 		critical_enter();
94 		PIC_DISPATCH(root_pic, framep);
95 		critical_exit();
96 #ifdef BOOKE
97 		framep->srr1 &= ~PSL_WE;
98 #endif
99 		break;
100 
101 	case EXC_DECR:
102 		critical_enter();
103 		atomic_add_int(&td->td_intr_nesting_level, 1);
104 		oldframe = td->td_intr_frame;
105 		td->td_intr_frame = framep;
106 		decr_intr(framep);
107 		td->td_intr_frame = oldframe;
108 		atomic_subtract_int(&td->td_intr_nesting_level, 1);
109 		critical_exit();
110 #ifdef BOOKE
111 		framep->srr1 &= ~PSL_WE;
112 #endif
113 		break;
114 #ifdef HWPMC_HOOKS
115 	case EXC_PERF:
116 		critical_enter();
117 		KASSERT(pmc_intr != NULL, ("Performance exception, but no handler!"));
118 		(*pmc_intr)(framep);
119 		critical_exit();
120 		if (pmc_hook && (PCPU_GET(curthread)->td_pflags & TDP_CALLCHAIN))
121 			pmc_hook(PCPU_GET(curthread), PMC_FN_USER_CALLCHAIN, framep);
122 		break;
123 #endif
124 
125 #ifdef POWERNV
126 	case EXC_HMI:
127 		if (hmi_handler != 0 && hmi_handler(framep) == 0)
128 			break;
129 		/* If no handler, or failure to handle, just drop to trap. */
130 #endif
131 
132 	default:
133 		/* Re-enable interrupts if applicable. */
134 		ee = framep->srr1 & PSL_EE;
135 		if (ee != 0)
136 			mtmsr(mfmsr() | ee);
137 		trap(framep);
138 	}
139 }
140