1 1.2 thorpej /* $NetBSD: intr.h,v 1.2 2024/01/19 05:46:36 thorpej Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.1 thorpej * Copyright (c) 2023 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.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 thorpej * 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 _VIRT68K_INTR_H_ 33 1.1 thorpej #define _VIRT68K_INTR_H_ 34 1.1 thorpej 35 1.1 thorpej #include <machine/psl.h> 36 1.1 thorpej 37 1.1 thorpej /* 38 1.1 thorpej * The Qemu virt68k platform uses 6 Goldfish PICs. Each PIC is 39 1.1 thorpej * connected to one of the CPU interrupt inputs: 40 1.1 thorpej * 41 1.1 thorpej * CPU IRQ 1 -> PIC 1 42 1.1 thorpej * IRQ 1-31 unused 43 1.1 thorpej * IRQ 32 goldfish-tty 44 1.1 thorpej * 45 1.1 thorpej * CPU IRQ 2 -> PIC 2 46 1.1 thorpej * IRQ 1-32 virtio-mmio 1-32 47 1.1 thorpej * 48 1.1 thorpej * CPU IRQ 3 -> PIC 3 49 1.1 thorpej * IRQ 1-32 virtio-mmio 33-64 50 1.1 thorpej * 51 1.1 thorpej * CPU IRQ 4 -> PIC 4 52 1.1 thorpej * IRQ 1-32 virtio-mmio 65-96 53 1.1 thorpej * 54 1.1 thorpej * CPU IRQ 5 -> PIC 5 55 1.1 thorpej * IRQ 1-32 virtio-mmio 97-128 56 1.1 thorpej * 57 1.1 thorpej * CPU IRQ 6 -> PIC 6 58 1.1 thorpej * IRQ 1 goldfish-rtc 59 1.1 thorpej * IRQ 2-32 unused 60 1.1 thorpej * 61 1.1 thorpej * CPU IRQ 7 -> NMI 62 1.1 thorpej * 63 1.1 thorpej * Qemu counts the 8 CPU IPLs as IRQs, so then the IRQ numbers 64 1.1 thorpej * reported in the bootinfo are: 65 1.1 thorpej * 66 1.1 thorpej * IRQ0 CPU IPL0 67 1.1 thorpej * ... 68 1.1 thorpej * IRQ7 CPU IPL7 69 1.1 thorpej * IRQ8 PIC 1 IRQ 1 IPL1 70 1.1 thorpej * ... 71 1.1 thorpej * IRQ39 PIC 1 IRQ 32 72 1.1 thorpej * IRQ40 PIC 2 IRQ 1 IPL2 73 1.1 thorpej * ... 74 1.1 thorpej * IRQ71 PIC 2 IRQ 32 75 1.1 thorpej * . IPL3 76 1.1 thorpej * . . 77 1.1 thorpej * . . 78 1.1 thorpej * 79 1.1 thorpej * Unfortunately for us, there is a hardware interrupt at IPL1, 80 1.1 thorpej * and the m68k platforms have historically used IPL1 as the 81 1.1 thorpej * soft interrupt IPL. We will continue to do this, but may have 82 1.1 thorpej * to re-think things if it negatively impacts using the Goldfish 83 1.1 thorpej * TTY console. 84 1.1 thorpej */ 85 1.1 thorpej 86 1.1 thorpej #define IRQ_CPU_BASE 1 /* can't hook up to "IPL0" */ 87 1.1 thorpej #define IRQ_PIC_BASE 8 88 1.1 thorpej #define IRQ_TO_PIC(x) (((x) - IRQ_PIC_BASE) >> 5) 89 1.1 thorpej #define IRQ_TO_PIRQ(x) (((x) - IRQ_PIC_BASE) & 31) 90 1.1 thorpej #define NPIC 6 91 1.1 thorpej #define NIRQ_PER_PIC 32 92 1.1 thorpej 93 1.1 thorpej #define NIRQ (IRQ_PIC_BASE + (NIRQ_PER_PIC * NPIC)) 94 1.1 thorpej 95 1.1 thorpej #define IPL_NONE 0 96 1.1 thorpej #define IPL_SOFTCLOCK 1 /* clock software interrupts */ 97 1.1 thorpej #define IPL_SOFTBIO 1 /* block software interrupts */ 98 1.1 thorpej #define IPL_SOFTNET 1 /* network software interrupts */ 99 1.1 thorpej #define IPL_SOFTSERIAL 1 /* serial software interrupts */ 100 1.1 thorpej #define IPL_VM 5 101 1.1 thorpej #define IPL_SCHED 6 102 1.1 thorpej #define IPL_HIGH 7 103 1.1 thorpej #define NIPL 8 104 1.1 thorpej 105 1.1 thorpej #if defined(_KERNEL) || defined(_KMEMUSER) 106 1.1 thorpej typedef struct { 107 1.1 thorpej uint16_t _psl; 108 1.1 thorpej } ipl_cookie_t; 109 1.1 thorpej #endif 110 1.1 thorpej 111 1.1 thorpej #ifdef _KERNEL 112 1.1 thorpej #define spl0() _spl0() 113 1.1 thorpej #define splsoftclock() splraise1() 114 1.1 thorpej #define splsoftbio() splraise1() 115 1.1 thorpej #define splsoftnet() splraise1() 116 1.1 thorpej #define splsoftserial() splraise1() 117 1.1 thorpej #define splvm() splraise5() 118 1.1 thorpej #define splsched() splraise6() 119 1.1 thorpej #define splhigh() spl7() 120 1.1 thorpej 121 1.1 thorpej #ifndef _LOCORE 122 1.1 thorpej 123 1.1 thorpej extern const uint16_t ipl2psl_table[NIPL]; 124 1.1 thorpej 125 1.1 thorpej typedef int ipl_t; 126 1.1 thorpej 127 1.1 thorpej static __inline ipl_cookie_t 128 1.1 thorpej makeiplcookie(ipl_t ipl) 129 1.1 thorpej { 130 1.1 thorpej 131 1.1 thorpej return (ipl_cookie_t){._psl = ipl2psl_table[ipl]}; 132 1.1 thorpej } 133 1.1 thorpej 134 1.1 thorpej static __inline int 135 1.1 thorpej splraiseipl(ipl_cookie_t icookie) 136 1.1 thorpej { 137 1.1 thorpej 138 1.1 thorpej return _splraise(icookie._psl); 139 1.1 thorpej } 140 1.1 thorpej 141 1.1 thorpej static __inline void 142 1.1 thorpej splx(int sr) 143 1.1 thorpej { 144 1.1 thorpej 145 1.1 thorpej __asm volatile("movw %0,%%sr" : : "di" (sr)); 146 1.1 thorpej } 147 1.1 thorpej 148 1.1 thorpej #define INTR_STRING_BUFSIZE 64 149 1.1 thorpej 150 1.1 thorpej void intr_init(void); 151 1.1 thorpej void *intr_establish(int (*)(void *), void *, int, int, int); 152 1.1 thorpej void intr_disestablish(void *); 153 1.1 thorpej const char *intr_string(void *, char *, size_t); 154 1.1 thorpej 155 1.1 thorpej struct device; /* XXX */ 156 1.1 thorpej void intr_register_pic(struct device *, int); 157 1.1 thorpej 158 1.1 thorpej /* Flags for intr_establish() */ 159 1.1 thorpej #define INTR_F_MPSAFE __BIT(0) 160 1.1 thorpej 161 1.1 thorpej #ifdef _VIRT68K_INTR_PRIVATE 162 1.1 thorpej #include <sys/cpu.h> 163 1.1 thorpej #include <sys/device.h> 164 1.1 thorpej 165 1.2 thorpej void intr_dispatch(struct clockframe); 166 1.1 thorpej #endif /* _VIRT68K_INTR_PRIVATE */ 167 1.1 thorpej 168 1.1 thorpej #endif /* !_LOCORE */ 169 1.1 thorpej #endif /* _KERNEL */ 170 1.1 thorpej 171 1.1 thorpej #endif /* _VIRT68K_INTR_H_ */ 172