intr.h revision 1.1
11.1Smatt/* $NetBSD: intr.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
21.1Smatt
31.1Smatt/*-
41.1Smatt * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * This code is derived from software contributed to The NetBSD Foundation
81.1Smatt * by Matt Thomas <matt@3am-software.com>.
91.1Smatt *
101.1Smatt * Redistribution and use in source and binary forms, with or without
111.1Smatt * modification, are permitted provided that the following conditions
121.1Smatt * are met:
131.1Smatt * 1. Redistributions of source code must retain the above copyright
141.1Smatt *    notice, this list of conditions and the following disclaimer.
151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
161.1Smatt *    notice, this list of conditions and the following disclaimer in the
171.1Smatt *    documentation and/or other materials provided with the distribution.
181.1Smatt *
191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Smatt * POSSIBILITY OF SUCH DAMAGE.
301.1Smatt */
311.1Smatt
321.1Smatt#ifndef _RISCV_INTR_H_
331.1Smatt#define	_RISCV_INTR_H_
341.1Smatt
351.1Smatt#ifdef _KERNEL_OPT
361.1Smatt#include "opt_multiprocessor.h"
371.1Smatt#endif
381.1Smatt
391.1Smatt/*
401.1Smatt * This is a common <machine/intr.h> for all RISCV platforms.
411.1Smatt */
421.1Smatt
431.1Smatt#define	IPL_NONE	0
441.1Smatt#define	IPL_SOFTCLOCK	(IPL_NONE+1)
451.1Smatt#define	IPL_SOFTBIO	(IPL_SOFTCLOCK)	/* shares SWINT with softclock */
461.1Smatt#define	IPL_SOFTNET	(IPL_SOFTBIO+1)
471.1Smatt#define	IPL_SOFTSERIAL	(IPL_SOFTNET)	/* shares SWINT with softnet */
481.1Smatt#define	IPL_VM		(IPL_SOFTSERIAL+1)
491.1Smatt#define	IPL_SCHED	(IPL_VM+1)
501.1Smatt#define	IPL_DDB		(IPL_SCHED+1)
511.1Smatt#define	IPL_HIGH	(IPL_DDB+1)
521.1Smatt
531.1Smatt#define	IPL_SAFEPRI	IPL_SOFTSERIAL
541.1Smatt
551.1Smatt#define	_IPL_N		(IPL_HIGH+1)
561.1Smatt#define	_IPL_NAMES(pfx)	{ pfx"none", pfx"softclock/bio", pfx"softnet/serial", \
571.1Smatt			  pfx"vm", pfx"sched", pfx"ddb", pfx"high" }
581.1Smatt
591.1Smatt#define	IST_UNUSABLE	-1		/* interrupt cannot be used */
601.1Smatt#define	IST_NONE	0		/* none (dummy) */
611.1Smatt#define	IST_PULSE	1		/* pulsed */
621.1Smatt#define	IST_EDGE	2		/* edge-triggered */
631.1Smatt#define	IST_LEVEL	3		/* level-triggered */
641.1Smatt#define	IST_LEVEL_HIGH	4		/* level triggered, active high */
651.1Smatt#define	IST_LEVEL_LOW	5		/* level triggered, active low */
661.1Smatt
671.1Smatt#define	IPI_NOP		0		/* do nothing, interrupt only */
681.1Smatt#define	IPI_AST		1		/* force ast */
691.1Smatt#define	IPI_SHOOTDOWN	2		/* do a tlb shootdown */
701.1Smatt#define	IPI_SYNCICACHE	3		/* sync icache for pages */
711.1Smatt#define	IPI_KPREEMPT	4		/* schedule a kernel preemption */
721.1Smatt#define	IPI_SUSPEND	5		/* DDB suspend signaling */
731.1Smatt#define	IPI_HALT	6		/* halt cpu */
741.1Smatt#define	IPI_XCALL	7		/* xcall */
751.1Smatt#define	IPI_GENERIC	8		/* generic IPI */
761.1Smatt#define	NIPIS		9
771.1Smatt
781.1Smatt#ifdef __INTR_PRIVATE
791.1Smatt#if 0
801.1Smattstruct splsw {
811.1Smatt	int	(*splsw_splhigh)(void);
821.1Smatt	int	(*splsw_splsched)(void);
831.1Smatt	int	(*splsw_splvm)(void);
841.1Smatt	int	(*splsw_splsoftserial)(void);
851.1Smatt	int	(*splsw_splsoftnet)(void);
861.1Smatt	int	(*splsw_splsoftbio)(void);
871.1Smatt	int	(*splsw_splsoftclock)(void);
881.1Smatt	int	(*splsw_splraise)(int);
891.1Smatt	void	(*splsw_spl0)(void);
901.1Smatt	void	(*splsw_splx)(int);
911.1Smatt	int	(*splsw_splhigh_noprof)(void);
921.1Smatt	void	(*splsw_splx_noprof)(int);
931.1Smatt	int	(*splsw_splintr)(uint32_t *);
941.1Smatt	void	(*splsw_splcheck)(void);
951.1Smatt};
961.1Smatt
971.1Smattstruct ipl_sr_map {
981.1Smatt	uint32_t sr_bits[_IPL_N];
991.1Smatt};
1001.1Smatt#endif
1011.1Smatt#else
1021.1Smattstruct splsw;
1031.1Smatt#endif /* __INTR_PRIVATE */
1041.1Smatt
1051.1Smatttypedef int ipl_t;
1061.1Smatttypedef struct {
1071.1Smatt        ipl_t _spl;
1081.1Smatt} ipl_cookie_t;
1091.1Smatt
1101.1Smatt#ifdef _KERNEL
1111.1Smatt
1121.1Smatt#if defined(MULTIPROCESSOR) && defined(__HAVE_FAST_SOFTINTS)
1131.1Smatt#define __HAVE_PREEMPTION	1
1141.1Smatt#define SOFTINT_KPREEMPT	(SOFTINT_COUNT+0)
1151.1Smatt#endif
1161.1Smatt
1171.1Smatt#ifdef __INTR_PRIVATE
1181.1Smatt#if 0
1191.1Smattextern	struct splsw	cpu_splsw;
1201.1Smatt#endif
1211.1Smattextern	struct ipl_sr_map ipl_sr_map;
1221.1Smatt#endif /* __INTR_PRIVATE */
1231.1Smatt
1241.1Smattint	splhigh(void);
1251.1Smattint	splhigh_noprof(void);
1261.1Smattint	splsched(void);
1271.1Smattint	splvm(void);
1281.1Smattint	splsoftserial(void);
1291.1Smattint	splsoftnet(void);
1301.1Smattint	splsoftbio(void);
1311.1Smattint	splsoftclock(void);
1321.1Smattint	splraise(int);
1331.1Smattvoid	splx(int);
1341.1Smattvoid	splx_noprof(int);
1351.1Smattvoid	spl0(void);
1361.1Smattint	splintr(uint32_t *);
1371.1Smatt
1381.1Smattstruct cpu_info;
1391.1Smatt
1401.1Smattvoid	ipi_init(struct cpu_info *);
1411.1Smattvoid	ipi_process(struct cpu_info *, uint64_t);
1421.1Smatt
1431.1Smatt/*
1441.1Smatt * These make no sense *NOT* to be inlined.
1451.1Smatt */
1461.1Smattstatic inline ipl_cookie_t
1471.1Smattmakeiplcookie(ipl_t s)
1481.1Smatt{
1491.1Smatt	return (ipl_cookie_t){._spl = s};
1501.1Smatt}
1511.1Smatt
1521.1Smattstatic inline int
1531.1Smattsplraiseipl(ipl_cookie_t icookie)
1541.1Smatt{
1551.1Smatt	return splraise(icookie._spl);
1561.1Smatt}
1571.1Smatt
1581.1Smatt#endif /* _KERNEL */
1591.1Smatt#endif /* _RISCV_INTR_H_ */
160