ifpga_intr.h revision 1.7 1 1.7 matt /* $NetBSD: ifpga_intr.h,v 1.7 2008/01/06 01:37:58 matt Exp $ */
2 1.1 rearnsha
3 1.1 rearnsha /*
4 1.1 rearnsha * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.1 rearnsha * All rights reserved.
6 1.1 rearnsha *
7 1.1 rearnsha * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 rearnsha *
9 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
10 1.1 rearnsha * modification, are permitted provided that the following conditions
11 1.1 rearnsha * are met:
12 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
13 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
14 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
16 1.1 rearnsha * documentation and/or other materials provided with the distribution.
17 1.1 rearnsha * 3. All advertising materials mentioning features or use of this software
18 1.1 rearnsha * must display the following acknowledgement:
19 1.1 rearnsha * This product includes software developed for the NetBSD Project by
20 1.1 rearnsha * Wasabi Systems, Inc.
21 1.1 rearnsha * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 rearnsha * or promote products derived from this software without specific prior
23 1.1 rearnsha * written permission.
24 1.1 rearnsha *
25 1.1 rearnsha * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 rearnsha * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 rearnsha * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 rearnsha * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 rearnsha * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 rearnsha * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 rearnsha * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 rearnsha * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 rearnsha * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 rearnsha * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 rearnsha * POSSIBILITY OF SUCH DAMAGE.
36 1.1 rearnsha */
37 1.1 rearnsha
38 1.1 rearnsha #ifndef _IFPGA_INTR_H_
39 1.1 rearnsha #define _IFPGA_INTR_H_
40 1.1 rearnsha
41 1.1 rearnsha #define ARM_IRQ_HANDLER _C_LABEL(ifpga_intr_dispatch)
42 1.1 rearnsha
43 1.1 rearnsha #ifndef _LOCORE
44 1.1 rearnsha
45 1.1 rearnsha #include <arm/armreg.h>
46 1.1 rearnsha #include <arm/cpufunc.h>
47 1.1 rearnsha
48 1.1 rearnsha #include <evbarm/ifpga/ifpgareg.h>
49 1.1 rearnsha #include <evbarm/ifpga/ifpgavar.h>
50 1.1 rearnsha
51 1.7 matt #ifdef __HAVE_FAST_SOFTINTS
52 1.1 rearnsha void ifpga_do_pending(void);
53 1.7 matt #endif
54 1.1 rearnsha
55 1.5 perry static inline void __attribute__((__unused__))
56 1.1 rearnsha ifpga_set_intrmask(void)
57 1.1 rearnsha {
58 1.5 perry extern volatile uint32_t intr_enabled;
59 1.1 rearnsha extern struct ifpga_softc *ifpga_sc;
60 1.1 rearnsha uint32_t mask = intr_enabled;
61 1.1 rearnsha
62 1.1 rearnsha bus_space_write_4 (ifpga_sc->sc_iot, ifpga_sc->sc_irq_ioh,
63 1.1 rearnsha IFPGA_INTR_ENABLECLR, ~mask);
64 1.1 rearnsha bus_space_write_4 (ifpga_sc->sc_iot, ifpga_sc->sc_irq_ioh,
65 1.1 rearnsha IFPGA_INTR_ENABLESET, mask);
66 1.1 rearnsha }
67 1.1 rearnsha
68 1.7 matt #ifdef __HAVE_FAST_SOFTINTS
69 1.1 rearnsha #define INT_SWMASK \
70 1.1 rearnsha (IFPGA_INTR_bit31 | IFPGA_INTR_bit30 | \
71 1.1 rearnsha IFPGA_INTR_bit29 | IFPGA_INTR_bit28)
72 1.7 matt #endif
73 1.1 rearnsha
74 1.5 perry static inline void __attribute__((__unused__))
75 1.1 rearnsha ifpga_splx(int new)
76 1.1 rearnsha {
77 1.5 perry extern volatile uint32_t intr_enabled;
78 1.5 perry extern volatile int current_spl_level;
79 1.5 perry extern volatile int ifpga_ipending;
80 1.1 rearnsha int oldirqstate, hwpend;
81 1.1 rearnsha
82 1.3 rearnsha __insn_barrier();
83 1.3 rearnsha
84 1.1 rearnsha oldirqstate = disable_interrupts(I32_bit);
85 1.1 rearnsha current_spl_level = new;
86 1.1 rearnsha
87 1.1 rearnsha hwpend = (ifpga_ipending & IFPGA_INTR_HWMASK) & ~new;
88 1.1 rearnsha if (hwpend != 0) {
89 1.1 rearnsha intr_enabled |= hwpend;
90 1.1 rearnsha ifpga_set_intrmask();
91 1.1 rearnsha }
92 1.1 rearnsha
93 1.1 rearnsha restore_interrupts(oldirqstate);
94 1.1 rearnsha
95 1.7 matt #ifdef __HAVE_FAST_SOFTINTS
96 1.1 rearnsha if ((ifpga_ipending & INT_SWMASK) & ~new)
97 1.1 rearnsha ifpga_do_pending();
98 1.7 matt #endif
99 1.1 rearnsha }
100 1.1 rearnsha
101 1.5 perry static inline int __attribute__((__unused__))
102 1.1 rearnsha ifpga_splraise(int ipl)
103 1.1 rearnsha {
104 1.5 perry extern volatile int current_spl_level;
105 1.1 rearnsha extern int ifpga_imask[];
106 1.1 rearnsha int old;
107 1.1 rearnsha
108 1.1 rearnsha old = current_spl_level;
109 1.3 rearnsha current_spl_level = old | ifpga_imask[ipl];
110 1.3 rearnsha
111 1.3 rearnsha __insn_barrier();
112 1.1 rearnsha
113 1.1 rearnsha return (old);
114 1.1 rearnsha }
115 1.1 rearnsha
116 1.5 perry static inline int __attribute__((__unused__))
117 1.1 rearnsha ifpga_spllower(int ipl)
118 1.1 rearnsha {
119 1.5 perry extern volatile int current_spl_level;
120 1.1 rearnsha extern int ifpga_imask[];
121 1.1 rearnsha int old = current_spl_level;
122 1.1 rearnsha
123 1.1 rearnsha ifpga_splx(ifpga_imask[ipl]);
124 1.1 rearnsha return(old);
125 1.1 rearnsha }
126 1.1 rearnsha
127 1.1 rearnsha #if !defined(EVBARM_SPL_NOINLINE)
128 1.1 rearnsha
129 1.1 rearnsha #define splx(new) ifpga_splx(new)
130 1.1 rearnsha #define _spllower(ipl) ifpga_spllower(ipl)
131 1.1 rearnsha #define _splraise(ipl) ifpga_splraise(ipl)
132 1.7 matt #ifdef __HAVE_FAST_SOFTINTS
133 1.1 rearnsha void _setsoftintr(int);
134 1.7 matt #endif
135 1.1 rearnsha
136 1.1 rearnsha #else
137 1.1 rearnsha
138 1.1 rearnsha int _splraise(int);
139 1.1 rearnsha int _spllower(int);
140 1.1 rearnsha void splx(int);
141 1.7 matt #ifdef __HAVE_FAST_SOFTINTS
142 1.1 rearnsha void _setsoftintr(int);
143 1.7 matt #endif
144 1.1 rearnsha
145 1.1 rearnsha #endif /* ! EVBARM_SPL_NOINLINE */
146 1.1 rearnsha
147 1.1 rearnsha #endif /* _LOCORE */
148 1.1 rearnsha
149 1.2 matt #endif /* _IFPGA_INTR_H_ */
150