intr.h revision 1.4
11.4Sskrll/* $NetBSD: intr.h,v 1.4 2023/06/12 19:04:14 skrll 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.3Sskrll#define	IPL_SOFTCLOCK	(IPL_NONE + 1)
451.3Sskrll#define	IPL_SOFTBIO	(IPL_SOFTCLOCK + 1)
461.3Sskrll#define	IPL_SOFTNET	(IPL_SOFTBIO + 1)
471.3Sskrll#define	IPL_SOFTSERIAL	(IPL_SOFTNET + 1)
481.3Sskrll#define	IPL_VM		(IPL_SOFTSERIAL + 1)
491.3Sskrll#define	IPL_SCHED	(IPL_VM + 1)
501.3Sskrll//#define	IPL_DDB		(IPL_SCHED + 1)
511.3Sskrll#define	IPL_HIGH	(IPL_SCHED + 1)
521.1Smatt
531.1Smatt#define	IPL_SAFEPRI	IPL_SOFTSERIAL
541.1Smatt
551.3Sskrll#define	_IPL_N		(IPL_HIGH + 1)
561.3Sskrll
571.3Sskrll#if 0
581.1Smatt#define	_IPL_NAMES(pfx)	{ pfx"none", pfx"softclock/bio", pfx"softnet/serial", \
591.1Smatt			  pfx"vm", pfx"sched", pfx"ddb", pfx"high" }
601.3Sskrll#endif
611.1Smatt
621.1Smatt#define	IST_UNUSABLE	-1		/* interrupt cannot be used */
631.1Smatt#define	IST_NONE	0		/* none (dummy) */
641.1Smatt#define	IST_PULSE	1		/* pulsed */
651.1Smatt#define	IST_EDGE	2		/* edge-triggered */
661.1Smatt#define	IST_LEVEL	3		/* level-triggered */
671.1Smatt#define	IST_LEVEL_HIGH	4		/* level triggered, active high */
681.1Smatt#define	IST_LEVEL_LOW	5		/* level triggered, active low */
691.3Sskrll#define	IST_MPSAFE	0x100
701.1Smatt
711.1Smatt#define	IPI_NOP		0		/* do nothing, interrupt only */
721.1Smatt#define	IPI_AST		1		/* force ast */
731.1Smatt#define	IPI_SHOOTDOWN	2		/* do a tlb shootdown */
741.1Smatt#define	IPI_SYNCICACHE	3		/* sync icache for pages */
751.1Smatt#define	IPI_KPREEMPT	4		/* schedule a kernel preemption */
761.1Smatt#define	IPI_SUSPEND	5		/* DDB suspend signaling */
771.1Smatt#define	IPI_HALT	6		/* halt cpu */
781.1Smatt#define	IPI_XCALL	7		/* xcall */
791.1Smatt#define	IPI_GENERIC	8		/* generic IPI */
801.1Smatt#define	NIPIS		9
811.1Smatt
821.1Smatt#ifdef __INTR_PRIVATE
831.1Smatt#if 0
841.1Smattstruct splsw {
851.1Smatt	int	(*splsw_splhigh)(void);
861.1Smatt	int	(*splsw_splsched)(void);
871.1Smatt	int	(*splsw_splvm)(void);
881.1Smatt	int	(*splsw_splsoftserial)(void);
891.1Smatt	int	(*splsw_splsoftnet)(void);
901.1Smatt	int	(*splsw_splsoftbio)(void);
911.1Smatt	int	(*splsw_splsoftclock)(void);
921.1Smatt	int	(*splsw_splraise)(int);
931.1Smatt	void	(*splsw_spl0)(void);
941.1Smatt	void	(*splsw_splx)(int);
951.1Smatt	int	(*splsw_splhigh_noprof)(void);
961.1Smatt	void	(*splsw_splx_noprof)(int);
971.1Smatt	int	(*splsw_splintr)(uint32_t *);
981.1Smatt	void	(*splsw_splcheck)(void);
991.1Smatt};
1001.1Smatt
1011.1Smattstruct ipl_sr_map {
1021.1Smatt	uint32_t sr_bits[_IPL_N];
1031.1Smatt};
1041.1Smatt#endif
1051.1Smatt#else
1061.1Smattstruct splsw;
1071.1Smatt#endif /* __INTR_PRIVATE */
1081.1Smatt
1091.1Smatttypedef int ipl_t;
1101.1Smatttypedef struct {
1111.1Smatt        ipl_t _spl;
1121.1Smatt} ipl_cookie_t;
1131.1Smatt
1141.1Smatt#ifdef _KERNEL
1151.1Smatt
1161.1Smatt#if defined(MULTIPROCESSOR) && defined(__HAVE_FAST_SOFTINTS)
1171.1Smatt#define __HAVE_PREEMPTION	1
1181.1Smatt#define SOFTINT_KPREEMPT	(SOFTINT_COUNT+0)
1191.1Smatt#endif
1201.1Smatt
1211.1Smatt#ifdef __INTR_PRIVATE
1221.1Smatt#if 0
1231.1Smattextern	struct splsw	cpu_splsw;
1241.1Smatt#endif
1251.1Smattextern	struct ipl_sr_map ipl_sr_map;
1261.1Smatt#endif /* __INTR_PRIVATE */
1271.1Smatt
1281.1Smattint	splhigh(void);
1291.1Smattint	splhigh_noprof(void);
1301.1Smattint	splsched(void);
1311.1Smattint	splvm(void);
1321.1Smattint	splsoftserial(void);
1331.1Smattint	splsoftnet(void);
1341.1Smattint	splsoftbio(void);
1351.1Smattint	splsoftclock(void);
1361.1Smattint	splraise(int);
1371.1Smattvoid	splx(int);
1381.1Smattvoid	splx_noprof(int);
1391.1Smattvoid	spl0(void);
1401.4Sskrllint	splintr(unsigned long *);
1411.1Smatt
1421.2Smattvoid	softint_deliver(void);
1431.2Smatt
1441.1Smattstruct cpu_info;
1451.1Smatt
1461.3Sskrll#define ENABLE_INTERRUPTS()	csr_sstatus_set(SR_SIE)
1471.3Sskrll
1481.3Sskrll#define DISABLE_INTERRUPTS()	csr_sstatus_clear(SR_SIE)
1491.3Sskrll
1501.1Smattvoid	ipi_init(struct cpu_info *);
1511.4Sskrllvoid	ipi_process(struct cpu_info *, unsigned long);
1521.4Sskrll
1531.4Sskrllint	riscv_ipi_intr(void *arg);
1541.1Smatt
1551.1Smatt/*
1561.1Smatt * These make no sense *NOT* to be inlined.
1571.1Smatt */
1581.1Smattstatic inline ipl_cookie_t
1591.1Smattmakeiplcookie(ipl_t s)
1601.1Smatt{
1611.1Smatt	return (ipl_cookie_t){._spl = s};
1621.1Smatt}
1631.1Smatt
1641.1Smattstatic inline int
1651.1Smattsplraiseipl(ipl_cookie_t icookie)
1661.1Smatt{
1671.1Smatt	return splraise(icookie._spl);
1681.1Smatt}
1691.1Smatt
1701.3Sskrllvoid *intr_establish(int, int, int, int (*)(void *), void *);
1711.3Sskrllvoid intr_disestablish(void *);
1721.3Sskrll
1731.1Smatt#endif /* _KERNEL */
1741.1Smatt#endif /* _RISCV_INTR_H_ */
175