intr.h revision 1.6
11.6Sskrll/* $NetBSD: intr.h,v 1.6 2024/08/04 08:16:25 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.5Sskrll#define IPI_KPREEMPT 2 /* schedule a kernel preemption */ 741.5Sskrll#define IPI_SUSPEND 3 /* DDB suspend signaling */ 751.5Sskrll#define IPI_HALT 4 /* halt cpu */ 761.5Sskrll#define IPI_XCALL 5 /* xcall */ 771.5Sskrll#define IPI_GENERIC 6 /* generic IPI */ 781.5Sskrll#define NIPIS 7 791.1Smatt 801.1Smatt#ifdef __INTR_PRIVATE 811.1Smatt#if 0 821.1Smattstruct splsw { 831.1Smatt int (*splsw_splhigh)(void); 841.1Smatt int (*splsw_splsched)(void); 851.1Smatt int (*splsw_splvm)(void); 861.1Smatt int (*splsw_splsoftserial)(void); 871.1Smatt int (*splsw_splsoftnet)(void); 881.1Smatt int (*splsw_splsoftbio)(void); 891.1Smatt int (*splsw_splsoftclock)(void); 901.1Smatt int (*splsw_splraise)(int); 911.1Smatt void (*splsw_spl0)(void); 921.1Smatt void (*splsw_splx)(int); 931.1Smatt int (*splsw_splhigh_noprof)(void); 941.1Smatt void (*splsw_splx_noprof)(int); 951.1Smatt int (*splsw_splintr)(uint32_t *); 961.1Smatt void (*splsw_splcheck)(void); 971.1Smatt}; 981.1Smatt 991.1Smattstruct ipl_sr_map { 1001.1Smatt uint32_t sr_bits[_IPL_N]; 1011.1Smatt}; 1021.1Smatt#endif 1031.1Smatt#else 1041.1Smattstruct splsw; 1051.1Smatt#endif /* __INTR_PRIVATE */ 1061.1Smatt 1071.1Smatttypedef int ipl_t; 1081.1Smatttypedef struct { 1091.6Sskrll ipl_t _spl; 1101.1Smatt} ipl_cookie_t; 1111.1Smatt 1121.1Smatt#ifdef _KERNEL 1131.1Smatt 1141.1Smatt#if defined(MULTIPROCESSOR) && defined(__HAVE_FAST_SOFTINTS) 1151.1Smatt#define __HAVE_PREEMPTION 1 1161.1Smatt#define SOFTINT_KPREEMPT (SOFTINT_COUNT+0) 1171.1Smatt#endif 1181.1Smatt 1191.1Smatt#ifdef __INTR_PRIVATE 1201.1Smatt#if 0 1211.1Smattextern struct splsw cpu_splsw; 1221.1Smatt#endif 1231.1Smattextern struct ipl_sr_map ipl_sr_map; 1241.1Smatt#endif /* __INTR_PRIVATE */ 1251.1Smatt 1261.1Smattint splhigh(void); 1271.1Smattint splhigh_noprof(void); 1281.1Smattint splsched(void); 1291.1Smattint splvm(void); 1301.1Smattint splsoftserial(void); 1311.1Smattint splsoftnet(void); 1321.1Smattint splsoftbio(void); 1331.1Smattint splsoftclock(void); 1341.1Smattint splraise(int); 1351.1Smattvoid splx(int); 1361.1Smattvoid splx_noprof(int); 1371.1Smattvoid spl0(void); 1381.4Sskrllint splintr(unsigned long *); 1391.1Smatt 1401.2Smattvoid softint_deliver(void); 1411.2Smatt 1421.1Smattstruct cpu_info; 1431.1Smatt 1441.3Sskrll#define ENABLE_INTERRUPTS() csr_sstatus_set(SR_SIE) 1451.3Sskrll 1461.3Sskrll#define DISABLE_INTERRUPTS() csr_sstatus_clear(SR_SIE) 1471.3Sskrll 1481.1Smattvoid ipi_init(struct cpu_info *); 1491.4Sskrllvoid ipi_process(struct cpu_info *, unsigned long); 1501.4Sskrll 1511.4Sskrllint riscv_ipi_intr(void *arg); 1521.1Smatt 1531.1Smatt/* 1541.1Smatt * These make no sense *NOT* to be inlined. 1551.1Smatt */ 1561.1Smattstatic inline ipl_cookie_t 1571.1Smattmakeiplcookie(ipl_t s) 1581.1Smatt{ 1591.1Smatt return (ipl_cookie_t){._spl = s}; 1601.1Smatt} 1611.1Smatt 1621.1Smattstatic inline int 1631.1Smattsplraiseipl(ipl_cookie_t icookie) 1641.1Smatt{ 1651.1Smatt return splraise(icookie._spl); 1661.1Smatt} 1671.1Smatt 1681.3Sskrllvoid *intr_establish(int, int, int, int (*)(void *), void *); 1691.3Sskrllvoid intr_disestablish(void *); 1701.3Sskrll 1711.1Smatt#endif /* _KERNEL */ 1721.1Smatt#endif /* _RISCV_INTR_H_ */ 173