ifpga_intr.h revision 1.1 1 1.1 rearnsha /* $NetBSD: ifpga_intr.h,v 1.1 2003/09/06 11:31:21 rearnsha 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.1 rearnsha void ifpga_do_pending(void);
52 1.1 rearnsha
53 1.1 rearnsha static __inline void __attribute__((__unused__))
54 1.1 rearnsha ifpga_set_intrmask(void)
55 1.1 rearnsha {
56 1.1 rearnsha extern __volatile uint32_t intr_enabled;
57 1.1 rearnsha extern struct ifpga_softc *ifpga_sc;
58 1.1 rearnsha uint32_t mask = intr_enabled;
59 1.1 rearnsha
60 1.1 rearnsha bus_space_write_4 (ifpga_sc->sc_iot, ifpga_sc->sc_irq_ioh,
61 1.1 rearnsha IFPGA_INTR_ENABLECLR, ~mask);
62 1.1 rearnsha bus_space_write_4 (ifpga_sc->sc_iot, ifpga_sc->sc_irq_ioh,
63 1.1 rearnsha IFPGA_INTR_ENABLESET, mask);
64 1.1 rearnsha }
65 1.1 rearnsha
66 1.1 rearnsha #define INT_SWMASK \
67 1.1 rearnsha (IFPGA_INTR_bit31 | IFPGA_INTR_bit30 | \
68 1.1 rearnsha IFPGA_INTR_bit29 | IFPGA_INTR_bit28)
69 1.1 rearnsha
70 1.1 rearnsha static __inline void __attribute__((__unused__))
71 1.1 rearnsha ifpga_splx(int new)
72 1.1 rearnsha {
73 1.1 rearnsha extern __volatile uint32_t intr_enabled;
74 1.1 rearnsha extern __volatile int current_spl_level;
75 1.1 rearnsha extern __volatile int ifpga_ipending;
76 1.1 rearnsha extern void ifpga_do_pending(void);
77 1.1 rearnsha int oldirqstate, hwpend;
78 1.1 rearnsha
79 1.1 rearnsha oldirqstate = disable_interrupts(I32_bit);
80 1.1 rearnsha current_spl_level = new;
81 1.1 rearnsha
82 1.1 rearnsha hwpend = (ifpga_ipending & IFPGA_INTR_HWMASK) & ~new;
83 1.1 rearnsha if (hwpend != 0) {
84 1.1 rearnsha intr_enabled |= hwpend;
85 1.1 rearnsha ifpga_set_intrmask();
86 1.1 rearnsha }
87 1.1 rearnsha
88 1.1 rearnsha restore_interrupts(oldirqstate);
89 1.1 rearnsha
90 1.1 rearnsha if ((ifpga_ipending & INT_SWMASK) & ~new)
91 1.1 rearnsha ifpga_do_pending();
92 1.1 rearnsha }
93 1.1 rearnsha
94 1.1 rearnsha static __inline int __attribute__((__unused__))
95 1.1 rearnsha ifpga_splraise(int ipl)
96 1.1 rearnsha {
97 1.1 rearnsha extern __volatile int current_spl_level;
98 1.1 rearnsha extern int ifpga_imask[];
99 1.1 rearnsha int old;
100 1.1 rearnsha
101 1.1 rearnsha old = current_spl_level;
102 1.1 rearnsha current_spl_level |= ifpga_imask[ipl];
103 1.1 rearnsha
104 1.1 rearnsha return (old);
105 1.1 rearnsha }
106 1.1 rearnsha
107 1.1 rearnsha static __inline int __attribute__((__unused__))
108 1.1 rearnsha ifpga_spllower(int ipl)
109 1.1 rearnsha {
110 1.1 rearnsha extern __volatile int current_spl_level;
111 1.1 rearnsha extern int ifpga_imask[];
112 1.1 rearnsha int old = current_spl_level;
113 1.1 rearnsha
114 1.1 rearnsha ifpga_splx(ifpga_imask[ipl]);
115 1.1 rearnsha return(old);
116 1.1 rearnsha }
117 1.1 rearnsha
118 1.1 rearnsha #if !defined(EVBARM_SPL_NOINLINE)
119 1.1 rearnsha
120 1.1 rearnsha #define splx(new) ifpga_splx(new)
121 1.1 rearnsha #define _spllower(ipl) ifpga_spllower(ipl)
122 1.1 rearnsha #define _splraise(ipl) ifpga_splraise(ipl)
123 1.1 rearnsha void _setsoftintr(int);
124 1.1 rearnsha
125 1.1 rearnsha #else
126 1.1 rearnsha
127 1.1 rearnsha int _splraise(int);
128 1.1 rearnsha int _spllower(int);
129 1.1 rearnsha void splx(int);
130 1.1 rearnsha void _setsoftintr(int);
131 1.1 rearnsha
132 1.1 rearnsha #endif /* ! EVBARM_SPL_NOINLINE */
133 1.1 rearnsha
134 1.1 rearnsha #endif /* _LOCORE */
135 1.1 rearnsha
136 1.1 rearnsha #endif _IFPGA_INTR_H_
137