Home | History | Annotate | Line # | Download | only in footbridge
      1  1.22     skrll /* 	$NetBSD: footbridge_intr.h,v 1.22 2021/08/13 11:40:43 skrll Exp $	*/
      2   1.1     chris 
      3   1.1     chris /*
      4   1.3     chris  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
      5   1.1     chris  * All rights reserved.
      6   1.1     chris  *
      7   1.3     chris  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8   1.3     chris  *
      9   1.1     chris  * Redistribution and use in source and binary forms, with or without
     10   1.1     chris  * modification, are permitted provided that the following conditions
     11   1.1     chris  * are met:
     12   1.1     chris  * 1. Redistributions of source code must retain the above copyright
     13   1.1     chris  *    notice, this list of conditions and the following disclaimer.
     14   1.1     chris  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1     chris  *    notice, this list of conditions and the following disclaimer in the
     16   1.1     chris  *    documentation and/or other materials provided with the distribution.
     17   1.1     chris  * 3. All advertising materials mentioning features or use of this software
     18   1.1     chris  *    must display the following acknowledgement:
     19   1.3     chris  *	This product includes software developed for the NetBSD Project by
     20   1.3     chris  *	Wasabi Systems, Inc.
     21   1.3     chris  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22   1.3     chris  *    or promote products derived from this software without specific prior
     23   1.3     chris  *    written permission.
     24   1.1     chris  *
     25   1.3     chris  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26   1.3     chris  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27   1.3     chris  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28   1.3     chris  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29   1.3     chris  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30   1.3     chris  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31   1.3     chris  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32   1.3     chris  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33   1.3     chris  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34   1.3     chris  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35   1.3     chris  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1     chris  */
     37   1.1     chris 
     38   1.1     chris #ifndef _FOOTBRIDGE_INTR_H_
     39   1.1     chris #define _FOOTBRIDGE_INTR_H_
     40   1.1     chris 
     41  1.19  christos #ifndef _LOCORE
     42  1.18  christos typedef uint8_t ipl_t;
     43  1.18  christos typedef struct {
     44  1.18  christos 	ipl_t _ipl;
     45  1.18  christos } ipl_cookie_t;
     46  1.18  christos 
     47  1.17  christos #include <arm/mutex.h>
     48  1.19  christos #endif
     49  1.14        he #include <arm/cpu.h>
     50   1.2     chris #include <arm/armreg.h>
     51   1.2     chris 
     52   1.2     chris #define IPL_NONE	0	/* nothing */
     53  1.11        ad #define IPL_SOFTCLOCK	1	/* clock soft interrupts */
     54  1.11        ad #define IPL_SOFTBIO	2	/* block i/o */
     55   1.2     chris #define IPL_SOFTNET	3	/* network software interrupts */
     56  1.11        ad #define IPL_SOFTSERIAL	4	/* serial software interrupts */
     57  1.11        ad #define IPL_VM		5	/* memory allocation */
     58  1.11        ad #define IPL_SCHED	6	/* clock */
     59  1.11        ad #define IPL_HIGH	7	/* everything */
     60   1.1     chris 
     61  1.11        ad #define NIPL		8
     62   1.1     chris 
     63   1.1     chris #define	IST_UNUSABLE	-1	/* interrupt cannot be used */
     64   1.1     chris #define	IST_NONE	0	/* none (dummy) */
     65   1.1     chris #define	IST_PULSE	1	/* pulsed */
     66   1.1     chris #define	IST_EDGE	2	/* edge-triggered */
     67   1.1     chris #define	IST_LEVEL	3	/* level-triggered */
     68   1.1     chris 
     69   1.4   thorpej #define	ARM_IRQ_HANDLER	_C_LABEL(footbridge_intr_dispatch)
     70   1.2     chris 
     71   1.2     chris #ifndef _LOCORE
     72   1.2     chris #include <arm/cpufunc.h>
     73   1.2     chris 
     74   1.2     chris #include <arm/footbridge/dc21285mem.h>
     75   1.2     chris #include <arm/footbridge/dc21285reg.h>
     76   1.1     chris 
     77   1.2     chris #define INT_SWMASK							\
     78   1.2     chris 	((1U << IRQ_SOFTINT) | (1U << IRQ_RESERVED0) |			\
     79   1.2     chris 	 (1U << IRQ_RESERVED1) | (1U << IRQ_RESERVED2))
     80   1.2     chris #define ICU_INT_HWMASK	(0xffffffff & ~(INT_SWMASK |  (1U << IRQ_RESERVED3)))
     81   1.2     chris 
     82   1.2     chris /* only call this with interrupts off */
     83   1.6     perry static inline void __attribute__((__unused__))
     84  1.13      matt footbridge_set_intrmask(void)
     85   1.2     chris {
     86  1.13      matt 	extern volatile uint32_t intr_enabled;
     87  1.22     skrll 	volatile uint32_t * const dc21285_armcsr_vbase =
     88  1.13      matt 	    (volatile uint32_t *)(DC21285_ARMCSR_VBASE);
     89  1.13      matt 
     90  1.13      matt 	/* fetch once so we write the same number to both registers */
     91  1.13      matt 	uint32_t tmp = intr_enabled & ICU_INT_HWMASK;
     92   1.2     chris 
     93  1.13      matt 	dc21285_armcsr_vbase[IRQ_ENABLE_SET>>2] = tmp;
     94  1.13      matt 	dc21285_armcsr_vbase[IRQ_ENABLE_CLEAR>>2] = ~tmp;
     95   1.2     chris }
     96  1.22     skrll 
     97   1.6     perry static inline void __attribute__((__unused__))
     98  1.13      matt footbridge_splx(int ipl)
     99   1.2     chris {
    100  1.13      matt 	extern int footbridge_imask[];
    101   1.6     perry 	extern volatile uint32_t intr_enabled;
    102   1.6     perry 	extern volatile int footbridge_ipending;
    103   1.2     chris 	int oldirqstate, hwpend;
    104   1.2     chris 
    105   1.8     chris 	/* Don't let the compiler re-order this code with preceding code */
    106   1.8     chris 	__insn_barrier();
    107   1.8     chris 
    108  1.13      matt 	set_curcpl(ipl);
    109   1.2     chris 
    110  1.13      matt 	hwpend = footbridge_ipending & ICU_INT_HWMASK & ~footbridge_imask[ipl];
    111   1.2     chris 	if (hwpend != 0) {
    112   1.2     chris 		oldirqstate = disable_interrupts(I32_bit);
    113   1.2     chris 		intr_enabled |= hwpend;
    114   1.2     chris 		footbridge_set_intrmask();
    115   1.2     chris 		restore_interrupts(oldirqstate);
    116   1.2     chris 	}
    117   1.2     chris 
    118  1.13      matt #ifdef __HAVE_FAST_SOFTINTS
    119  1.13      matt 	cpu_dosoftints();
    120  1.13      matt #endif
    121   1.2     chris }
    122   1.2     chris 
    123   1.6     perry static inline int __attribute__((__unused__))
    124   1.2     chris footbridge_splraise(int ipl)
    125   1.2     chris {
    126   1.2     chris 	int	old;
    127   1.2     chris 
    128  1.13      matt 	old = curcpl();
    129  1.13      matt 	set_curcpl(ipl);
    130   1.2     chris 
    131   1.8     chris 	/* Don't let the compiler re-order this code with subsequent code */
    132   1.8     chris 	__insn_barrier();
    133   1.8     chris 
    134   1.2     chris 	return (old);
    135   1.2     chris }
    136   1.2     chris 
    137   1.6     perry static inline int __attribute__((__unused__))
    138   1.2     chris footbridge_spllower(int ipl)
    139   1.2     chris {
    140  1.13      matt 	int old = curcpl();
    141   1.2     chris 
    142  1.13      matt 	footbridge_splx(ipl);
    143   1.2     chris 	return(old);
    144   1.2     chris }
    145   1.2     chris 
    146   1.2     chris /* should only be defined in footbridge_intr.c */
    147   1.2     chris #if !defined(ARM_SPL_NOINLINE)
    148   1.2     chris 
    149   1.2     chris #define splx(newspl)		footbridge_splx(newspl)
    150   1.2     chris #define	_spllower(ipl)		footbridge_spllower(ipl)
    151   1.2     chris #define	_splraise(ipl)		footbridge_splraise(ipl)
    152   1.2     chris 
    153   1.2     chris #else
    154   1.2     chris 
    155   1.2     chris int	_splraise(int);
    156   1.2     chris int	_spllower(int);
    157   1.2     chris void	splx(int);
    158   1.1     chris 
    159   1.2     chris #endif /* ! ARM_SPL_NOINLINE */
    160   1.1     chris 
    161  1.12        ad #include <sys/evcnt.h>
    162   1.2     chris #include <sys/queue.h>
    163   1.1     chris #include <machine/irqhandler.h>
    164   1.2     chris 
    165   1.2     chris #define	splsoft()	_splraise(IPL_SOFT)
    166   1.2     chris 
    167   1.2     chris #define	spl0()		(void)_spllower(IPL_NONE)
    168   1.2     chris #define	spllowersoftclock() (void)_spllower(IPL_SOFTCLOCK)
    169   1.2     chris 
    170   1.9      yamt 
    171   1.9      yamt static inline ipl_cookie_t
    172   1.9      yamt makeiplcookie(ipl_t ipl)
    173   1.9      yamt {
    174   1.9      yamt 
    175   1.9      yamt 	return (ipl_cookie_t){._ipl = ipl};
    176   1.9      yamt }
    177   1.9      yamt 
    178   1.9      yamt static inline int
    179   1.9      yamt splraiseipl(ipl_cookie_t icookie)
    180   1.9      yamt {
    181   1.9      yamt 
    182   1.9      yamt 	return _splraise(icookie._ipl);
    183   1.9      yamt }
    184   1.9      yamt 
    185   1.7      yamt #include <sys/spl.h>
    186   1.2     chris 
    187   1.2     chris /* footbridge has 32 interrupt lines */
    188   1.2     chris #define	NIRQ		32
    189   1.2     chris 
    190   1.2     chris struct intrhand {
    191   1.2     chris 	TAILQ_ENTRY(intrhand) ih_list;	/* link on intrq list */
    192   1.2     chris 	int (*ih_func)(void *);		/* handler */
    193   1.2     chris 	void *ih_arg;			/* arg for handler */
    194   1.2     chris 	int ih_ipl;			/* IPL_* */
    195   1.2     chris 	int ih_irq;			/* IRQ number */
    196   1.2     chris };
    197   1.2     chris 
    198   1.2     chris #define	IRQNAMESIZE	sizeof("footbridge irq 31")
    199   1.2     chris 
    200   1.2     chris struct intrq {
    201   1.2     chris 	TAILQ_HEAD(, intrhand) iq_list;	/* handler list */
    202   1.2     chris 	struct evcnt iq_ev;		/* event counter */
    203   1.2     chris 	int iq_mask;			/* IRQs to mask while handling */
    204   1.2     chris 	int iq_levels;			/* IPL_*'s this IRQ has */
    205   1.2     chris 	int iq_ist;			/* share type */
    206  1.13      matt 	int iq_ipl;			/* max ipl */
    207   1.2     chris 	char iq_name[IRQNAMESIZE];	/* interrupt name */
    208   1.2     chris };
    209   1.2     chris 
    210   1.2     chris #endif /* _LOCORE */
    211   1.1     chris 
    212   1.1     chris #endif	/* _FOOTBRIDGE_INTR_H */
    213