xref: /openbsd-src/sys/arch/sh/include/intr.h (revision 4448e60c8618d2be6ff73483a5e4d177f9d45770)
1*4448e60cSderaadt /*	$OpenBSD: intr.h,v 1.10 2016/01/15 18:53:26 deraadt Exp $	*/
295c7671fSmiod /*	$NetBSD: intr.h,v 1.22 2006/01/24 23:51:42 uwe Exp $	*/
395c7671fSmiod 
495c7671fSmiod /*-
595c7671fSmiod  * Copyright (c) 2002 The NetBSD Foundation, Inc.
695c7671fSmiod  * All rights reserved.
795c7671fSmiod  *
895c7671fSmiod  * Redistribution and use in source and binary forms, with or without
995c7671fSmiod  * modification, are permitted provided that the following conditions
1095c7671fSmiod  * are met:
1195c7671fSmiod  * 1. Redistributions of source code must retain the above copyright
1295c7671fSmiod  *    notice, this list of conditions and the following disclaimer.
1395c7671fSmiod  * 2. Redistributions in binary form must reproduce the above copyright
1495c7671fSmiod  *    notice, this list of conditions and the following disclaimer in the
1595c7671fSmiod  *    documentation and/or other materials provided with the distribution.
1695c7671fSmiod  *
1795c7671fSmiod  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1895c7671fSmiod  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1995c7671fSmiod  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2095c7671fSmiod  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2195c7671fSmiod  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2295c7671fSmiod  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2395c7671fSmiod  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2495c7671fSmiod  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2595c7671fSmiod  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2695c7671fSmiod  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2795c7671fSmiod  * POSSIBILITY OF SUCH DAMAGE.
2895c7671fSmiod  */
2995c7671fSmiod 
3095c7671fSmiod #ifndef _SH_INTR_H_
3195c7671fSmiod #define	_SH_INTR_H_
3295c7671fSmiod 
3395c7671fSmiod #ifdef	_KERNEL
3495c7671fSmiod 
3595c7671fSmiod #include <sys/device.h>
3695c7671fSmiod #include <sys/evcount.h>
37101cceb1Soga #include <sys/mutex.h>
3895c7671fSmiod #include <sys/queue.h>
3995c7671fSmiod #include <sh/psl.h>
4095c7671fSmiod 
4195c7671fSmiod /* Interrupt sharing types. */
4295c7671fSmiod #define	IST_NONE		0	/* none */
4395c7671fSmiod #define	IST_PULSE		1	/* pulsed */
4495c7671fSmiod #define	IST_EDGE		2	/* edge-triggered */
4595c7671fSmiod #define	IST_LEVEL		3	/* level-triggered */
4695c7671fSmiod 
4795c7671fSmiod /* Interrupt priority levels */
4895c7671fSmiod #define	_IPL_N		15
4995c7671fSmiod #define	_IPL_NSOFT	4
5095c7671fSmiod 
5195c7671fSmiod #define	IPL_NONE	0	/* nothing */
5295c7671fSmiod #define	IPL_SOFT	1
5395c7671fSmiod #define	IPL_SOFTCLOCK	2	/* timeouts */
5495c7671fSmiod #define	IPL_SOFTNET	3	/* protocol stacks */
5595c7671fSmiod #define	IPL_SOFTSERIAL	4	/* serial */
5695c7671fSmiod 
5795c7671fSmiod #define	IPL_SOFTNAMES {							\
5895c7671fSmiod 	"misc",								\
5995c7671fSmiod 	"clock",							\
6095c7671fSmiod 	"net",								\
6195c7671fSmiod 	"serial",							\
6295c7671fSmiod }
6395c7671fSmiod 
6495c7671fSmiod struct intc_intrhand {
6595c7671fSmiod 	int	(*ih_func)(void *);
6695c7671fSmiod 	void	*ih_arg;
6795c7671fSmiod 	int	ih_level;	/* SR.I[0:3] value */
6895c7671fSmiod 	int	ih_evtcode;	/* INTEVT or INTEVT2(SH7709/SH7709A) */
6995c7671fSmiod 	int	ih_idx;		/* evtcode -> intrhand mapping */
70962dfcddSmiod 	int	ih_irq;
7195c7671fSmiod 	struct evcount ih_count;
72962dfcddSmiod 	const char *ih_name;
7395c7671fSmiod };
7495c7671fSmiod 
75*4448e60cSderaadt void intr_barrier(void *);
76*4448e60cSderaadt 
7795c7671fSmiod /* from 0x200 by 0x20 -> from 0 by 1 */
7895c7671fSmiod #define	EVTCODE_TO_MAP_INDEX(x)		(((x) >> 5) - 0x10)
7995c7671fSmiod #define	EVTCODE_TO_IH_INDEX(x)						\
8095c7671fSmiod 	__intc_evtcode_to_ih[EVTCODE_TO_MAP_INDEX(x)]
8195c7671fSmiod #define	EVTCODE_IH(x)	(&__intc_intrhand[EVTCODE_TO_IH_INDEX(x)])
8295c7671fSmiod extern int8_t __intc_evtcode_to_ih[];
8395c7671fSmiod extern struct intc_intrhand __intc_intrhand[];
8495c7671fSmiod 
8595c7671fSmiod void intc_init(void);
8695c7671fSmiod void *intc_intr_establish(int, int, int, int (*)(void *), void *, const char *);
8795c7671fSmiod void intc_intr_disestablish(void *);
8895c7671fSmiod void intc_intr_enable(int);
8995c7671fSmiod void intc_intr_disable(int);
9095c7671fSmiod void intc_intr(int, int, int);
9195c7671fSmiod 
9295c7671fSmiod void intpri_intr_priority(int evtcode, int level);
9395c7671fSmiod 
9495c7671fSmiod /*
9595c7671fSmiod  * software simulated interrupt
9695c7671fSmiod  */
9795c7671fSmiod struct sh_soft_intrhand {
9895c7671fSmiod 	TAILQ_ENTRY(sh_soft_intrhand) sih_q;
9995c7671fSmiod 	struct sh_soft_intr *sih_intrhead;
10095c7671fSmiod 	void	(*sih_fn)(void *);
10195c7671fSmiod 	void	*sih_arg;
10295c7671fSmiod 	int	sih_pending;
10395c7671fSmiod };
10495c7671fSmiod 
10595c7671fSmiod struct sh_soft_intr {
106101cceb1Soga 	TAILQ_HEAD(, sh_soft_intrhand)
107101cceb1Soga 			softintr_q;
10895c7671fSmiod 	unsigned long	softintr_ipl;
109101cceb1Soga 	struct mutex	softintr_lock;
11095c7671fSmiod };
11195c7671fSmiod 
11295c7671fSmiod void	 softintr_disestablish(void *);
11395c7671fSmiod void	 softintr_dispatch(int);
1149e667fd0Smiod void	*softintr_establish(int, void (*)(void *), void *);
1159e667fd0Smiod void	 softintr_init(void);
1169e667fd0Smiod void	 softintr_schedule(void *);
11795c7671fSmiod 
11895c7671fSmiod #endif	/* _KERNEL */
11995c7671fSmiod 
12095c7671fSmiod #endif /* !_SH_INTR_H_ */
121