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