Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.35
      1  1.35  riastrad /*	$NetBSD: intr.h,v 1.35 2023/07/11 10:42:26 riastradh Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4   1.6   thorpej  * Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   thorpej  * by Jason R. Thorpe.
      9   1.1   thorpej  *
     10   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11   1.1   thorpej  * modification, are permitted provided that the following conditions
     12   1.1   thorpej  * are met:
     13   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18   1.1   thorpej  *
     19   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.3       jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.3       jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1   thorpej  */
     31   1.1   thorpej 
     32   1.1   thorpej #ifndef _HP300_INTR_H_
     33   1.1   thorpej #define	_HP300_INTR_H_
     34   1.1   thorpej 
     35  1.35  riastrad #include <sys/types.h>
     36  1.35  riastrad 
     37  1.33   tsutsui #include <sys/evcnt.h>
     38  1.12  gmcgarry #include <sys/queue.h>
     39  1.35  riastrad #include <sys/stdbool.h>
     40  1.35  riastrad 
     41   1.1   thorpej #include <machine/psl.h>
     42   1.1   thorpej 
     43   1.1   thorpej /*
     44   1.1   thorpej  * Interrupt "levels".  These are a more abstract representation
     45   1.1   thorpej  * of interrupt levels, and do not have the same meaning as m68k
     46  1.16      yamt  * CPU interrupt levels.  They serve the following purposes:
     47   1.1   thorpej  *
     48   1.1   thorpej  *	- properly order ISRs in the list for that CPU ipl
     49   1.1   thorpej  *	- compute CPU PSL values for the spl*() calls.
     50  1.16      yamt  *	- used to create cookie for the splraiseipl().
     51   1.1   thorpej  */
     52  1.16      yamt #define	IPL_NONE	0
     53  1.16      yamt #define	IPL_SOFTCLOCK	1
     54  1.26        ad #define	IPL_SOFTBIO	2
     55  1.26        ad #define	IPL_SOFTNET	3
     56  1.26        ad #define	IPL_SOFTSERIAL	4
     57  1.26        ad #define	IPL_VM		5
     58  1.26        ad #define	IPL_SCHED	6
     59  1.26        ad #define	IPL_HIGH	7
     60  1.26        ad #define	NIPL		8
     61  1.16      yamt 
     62   1.1   thorpej /*
     63  1.16      yamt  * Convert PSL values to m68k CPU IPLs and vice-versa.
     64  1.16      yamt  * Note: CPU IPL values are different from IPL_* used by splraiseipl().
     65   1.1   thorpej  */
     66   1.1   thorpej #define	PSLTOIPL(x)	(((x) >> 8) & 0xf)
     67   1.1   thorpej #define	IPLTOPSL(x)	((((x) & 0xf) << 8) | PSL_S)
     68   1.1   thorpej 
     69  1.27   tsutsui extern int idepth;
     70  1.31   tsutsui 
     71  1.31   tsutsui static inline bool
     72  1.34   tsutsui cpu_intr_p(void)
     73  1.31   tsutsui {
     74  1.34   tsutsui 
     75  1.31   tsutsui 	return idepth != 0;
     76  1.31   tsutsui }
     77  1.31   tsutsui 
     78  1.30   tsutsui extern const uint16_t ipl2psl_table[NIPL];
     79  1.16      yamt 
     80  1.16      yamt typedef int ipl_t;
     81  1.16      yamt typedef struct {
     82  1.23   thorpej 	uint16_t _psl;
     83  1.16      yamt } ipl_cookie_t;
     84  1.16      yamt 
     85  1.16      yamt static inline ipl_cookie_t
     86  1.16      yamt makeiplcookie(ipl_t ipl)
     87  1.16      yamt {
     88  1.16      yamt 
     89  1.29   tsutsui 	return (ipl_cookie_t){._psl = ipl2psl_table[ipl]};
     90  1.16      yamt }
     91  1.16      yamt 
     92  1.16      yamt static inline int
     93  1.16      yamt splraiseipl(ipl_cookie_t icookie)
     94  1.16      yamt {
     95  1.16      yamt 
     96  1.16      yamt 	return _splraise(icookie._psl);
     97  1.16      yamt }
     98   1.1   thorpej 
     99  1.32   tsutsui static inline void
    100  1.32   tsutsui splx(int sr)
    101  1.32   tsutsui {
    102  1.32   tsutsui 
    103  1.32   tsutsui 	__asm volatile("movew %0,%%sr" : : "di" (sr));
    104  1.32   tsutsui }
    105  1.32   tsutsui 
    106   1.1   thorpej /* These spl calls are _not_ to be used by machine-independent code. */
    107   1.7   thorpej #define	splhil()	splraise1()
    108   1.1   thorpej #define	splkbd()	splhil()
    109   1.1   thorpej 
    110   1.1   thorpej /* These spl calls are used by machine-independent code. */
    111  1.32   tsutsui #define	spl0()		_spl0()
    112  1.32   tsutsui 
    113  1.26        ad #define	splsoftbio()	splraise1()
    114  1.26        ad #define	splsoftclock()	splraise1()
    115  1.26        ad #define	splsoftnet()	splraise1()
    116  1.26        ad #define	splsoftserial()	splraise1()
    117  1.30   tsutsui #define	splvm()		splraise5()
    118  1.26        ad #define	splsched()	spl6()
    119   1.1   thorpej #define	splhigh()	spl7()
    120   1.1   thorpej 
    121  1.12  gmcgarry struct hp300_intrhand {
    122  1.12  gmcgarry 	LIST_ENTRY(hp300_intrhand) ih_q;
    123  1.12  gmcgarry 	int (*ih_fn)(void *);
    124  1.12  gmcgarry 	void *ih_arg;
    125  1.12  gmcgarry 	int ih_ipl;
    126  1.12  gmcgarry 	int ih_priority;
    127  1.12  gmcgarry };
    128  1.12  gmcgarry 
    129  1.12  gmcgarry struct hp300_intr {
    130  1.12  gmcgarry 	LIST_HEAD(, hp300_intrhand) hi_q;
    131  1.12  gmcgarry 	struct evcnt hi_evcnt;
    132  1.12  gmcgarry };
    133  1.12  gmcgarry 
    134   1.1   thorpej /* intr.c */
    135  1.12  gmcgarry void	intr_init(void);
    136  1.12  gmcgarry void	*intr_establish(int (*)(void *), void *, int, int);
    137  1.12  gmcgarry void	intr_disestablish(void *);
    138  1.12  gmcgarry void	intr_dispatch(int);
    139  1.12  gmcgarry 
    140   1.1   thorpej #endif /* _HP300_INTR_H_ */
    141