ifpga_intr.h revision 1.8 1 1.8 matt /* $NetBSD: ifpga_intr.h,v 1.8 2008/04/27 18:58:46 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.5 perry static inline void __attribute__((__unused__))
52 1.1 rearnsha ifpga_set_intrmask(void)
53 1.1 rearnsha {
54 1.5 perry extern volatile uint32_t intr_enabled;
55 1.1 rearnsha extern struct ifpga_softc *ifpga_sc;
56 1.1 rearnsha uint32_t mask = intr_enabled;
57 1.1 rearnsha
58 1.1 rearnsha bus_space_write_4 (ifpga_sc->sc_iot, ifpga_sc->sc_irq_ioh,
59 1.1 rearnsha IFPGA_INTR_ENABLECLR, ~mask);
60 1.1 rearnsha bus_space_write_4 (ifpga_sc->sc_iot, ifpga_sc->sc_irq_ioh,
61 1.1 rearnsha IFPGA_INTR_ENABLESET, mask);
62 1.1 rearnsha }
63 1.1 rearnsha
64 1.5 perry static inline void __attribute__((__unused__))
65 1.1 rearnsha ifpga_splx(int new)
66 1.1 rearnsha {
67 1.5 perry extern volatile uint32_t intr_enabled;
68 1.5 perry extern volatile int ifpga_ipending;
69 1.1 rearnsha int oldirqstate, hwpend;
70 1.1 rearnsha
71 1.3 rearnsha __insn_barrier();
72 1.3 rearnsha
73 1.1 rearnsha oldirqstate = disable_interrupts(I32_bit);
74 1.8 matt set_curcpl(new);
75 1.1 rearnsha
76 1.1 rearnsha hwpend = (ifpga_ipending & IFPGA_INTR_HWMASK) & ~new;
77 1.1 rearnsha if (hwpend != 0) {
78 1.1 rearnsha intr_enabled |= hwpend;
79 1.1 rearnsha ifpga_set_intrmask();
80 1.1 rearnsha }
81 1.1 rearnsha
82 1.1 rearnsha restore_interrupts(oldirqstate);
83 1.1 rearnsha
84 1.7 matt #ifdef __HAVE_FAST_SOFTINTS
85 1.8 matt cpu_dosoftints();
86 1.7 matt #endif
87 1.1 rearnsha }
88 1.1 rearnsha
89 1.5 perry static inline int __attribute__((__unused__))
90 1.1 rearnsha ifpga_splraise(int ipl)
91 1.1 rearnsha {
92 1.1 rearnsha extern int ifpga_imask[];
93 1.8 matt const int old = curcpl();
94 1.8 matt set_curcpl(old | ifpga_imask[ipl]);
95 1.3 rearnsha
96 1.3 rearnsha __insn_barrier();
97 1.1 rearnsha
98 1.1 rearnsha return (old);
99 1.1 rearnsha }
100 1.1 rearnsha
101 1.5 perry static inline int __attribute__((__unused__))
102 1.1 rearnsha ifpga_spllower(int ipl)
103 1.1 rearnsha {
104 1.1 rearnsha extern int ifpga_imask[];
105 1.8 matt const int old = curcpl();
106 1.1 rearnsha
107 1.1 rearnsha ifpga_splx(ifpga_imask[ipl]);
108 1.1 rearnsha return(old);
109 1.1 rearnsha }
110 1.1 rearnsha
111 1.1 rearnsha #if !defined(EVBARM_SPL_NOINLINE)
112 1.1 rearnsha
113 1.1 rearnsha #define splx(new) ifpga_splx(new)
114 1.1 rearnsha #define _spllower(ipl) ifpga_spllower(ipl)
115 1.1 rearnsha #define _splraise(ipl) ifpga_splraise(ipl)
116 1.1 rearnsha
117 1.1 rearnsha #else
118 1.1 rearnsha
119 1.1 rearnsha int _splraise(int);
120 1.1 rearnsha int _spllower(int);
121 1.1 rearnsha void splx(int);
122 1.1 rearnsha
123 1.1 rearnsha #endif /* ! EVBARM_SPL_NOINLINE */
124 1.1 rearnsha
125 1.1 rearnsha #endif /* _LOCORE */
126 1.1 rearnsha
127 1.2 matt #endif /* _IFPGA_INTR_H_ */
128