1 /* $NetBSD: picvar.h,v 1.7 2012/09/01 00:00:42 matt Exp $ */ 2 /*- 3 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Matt Thomas. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #ifndef _ARM_PIC_PICVAR_H_ 31 #define _ARM_PIC_PICVAR_H_ 32 33 #ifdef MULTIPROCESSOR 34 #include <sys/kcpuset.h> 35 #endif 36 37 int _splraise(int); 38 int _spllower(int); 39 void splx(int); 40 const char * 41 intr_typename(int); 42 43 struct pic_softc; 44 struct intrsource; 45 struct cpu_info; 46 47 #define IPI_AST 0 /* just get an interrupt */ 48 #define IPI_XCALL 1 /* xcall */ 49 #define IPI_NOP 2 /* just get an interrupt (armv6) */ 50 #ifndef __HAVE_PREEMPTION 51 #define NIPI 3 52 #else 53 #define IPI_KPREEMPT 4 /* cause a preemption */ 54 #define NIPI 4 55 #endif 56 57 int pic_handle_intr(void *); 58 void pic_mark_pending(struct pic_softc *pic, int irq); 59 void pic_mark_pending_source(struct pic_softc *pic, struct intrsource *is); 60 uint32_t pic_mark_pending_sources(struct pic_softc *pic, size_t irq_base, 61 uint32_t pending); 62 void *pic_establish_intr(struct pic_softc *pic, int irq, int ipl, int type, 63 int (*func)(void *), void *arg); 64 int pic_alloc_irq(struct pic_softc *pic); 65 void pic_disestablish_source(struct intrsource *is); 66 void pic_do_pending_ints(register_t psw, int newipl, void *frame); 67 void pic_dispatch(struct intrsource *is, void *frame); 68 69 void *intr_establish(int irq, int ipl, int type, int (*func)(void *), 70 void *arg); 71 void intr_disestablish(void *); 72 #ifdef MULTIPROCESSOR 73 void intr_cpu_init(struct cpu_info *); 74 void intr_ipi_send(const kcpuset_t *, u_long ipi); 75 #endif 76 77 #ifdef _INTR_PRIVATE 78 79 #include "opt_arm_intr_impl.h" 80 81 #include <sys/evcnt.h> 82 #include <sys/percpu.h> 83 84 #ifndef PIC_MAXPICS 85 #define PIC_MAXPICS 32 86 #endif 87 #ifndef PIC_MAXSOURCES 88 #define PIC_MAXSOURCES 64 89 #endif 90 #ifndef PIC_MAXMAXSOURCES 91 #define PIC_MAXMAXSOURCES 128 92 #endif 93 94 struct intrsource { 95 int (*is_func)(void *); 96 void *is_arg; 97 struct pic_softc *is_pic; /* owning PIC */ 98 uint8_t is_type; /* IST_xxx */ 99 uint8_t is_ipl; /* IPL_xxx */ 100 uint8_t is_irq; /* local to pic */ 101 uint8_t is_iplidx; 102 char is_source[16]; 103 }; 104 105 struct pic_percpu { 106 struct evcnt *pcpu_evs; 107 char *pcpu_name; 108 uint32_t pcpu_magic; 109 }; 110 111 #define PICPERCPU_MAGIC 0xfeedface 112 113 struct pic_softc { 114 const struct pic_ops *pic_ops; 115 struct intrsource **pic_sources; 116 volatile uint32_t pic_pending_irqs[(PIC_MAXSOURCES + 31) / 32]; 117 volatile uint32_t pic_blocked_irqs[(PIC_MAXSOURCES + 31) / 32]; 118 volatile uint32_t pic_pending_ipls; 119 size_t pic_maxsources; 120 percpu_t *pic_percpu; 121 uint8_t pic_id; 122 int16_t pic_irqbase; 123 char pic_name[14]; 124 }; 125 126 struct pic_ops { 127 void (*pic_unblock_irqs)(struct pic_softc *, size_t, uint32_t); 128 void (*pic_block_irqs)(struct pic_softc *, size_t, uint32_t); 129 int (*pic_find_pending_irqs)(struct pic_softc *); 130 131 void (*pic_establish_irq)(struct pic_softc *, struct intrsource *); 132 void (*pic_source_name)(struct pic_softc *, int, char *, size_t); 133 134 #ifdef __HAVE_PIC_SET_PRIORITY 135 void (*pic_set_priority)(struct pic_softc *, int); 136 #endif 137 #ifdef MULTIPROCESSOR 138 void (*pic_cpu_init)(struct pic_softc *, struct cpu_info *); 139 void (*pic_ipi_send)(struct pic_softc *, const kcpuset_t *, u_long); 140 #endif 141 }; 142 143 #ifdef __HAVE_PIC_SET_PRIORITY 144 /* 145 * This is used to update a hardware pic with a value corresponding 146 * to the ipl being set. 147 */ 148 struct cpu_info; 149 void pic_set_priority(struct cpu_info *, int); 150 #else 151 /* Using an inline causes catch-22 problems with cpu.h */ 152 #define pic_set_priority(ci, newipl) ((void)((ci)->ci_cpl = (newipl))) 153 #endif 154 155 void pic_add(struct pic_softc *, int); 156 void pic_do_pending_int(void); 157 #ifdef MULTIPROCESSOR 158 int pic_ipi_nop(void *); 159 int pic_ipi_xcall(void *); 160 #endif 161 #ifdef __HAVE_PIC_FAST_SOFTINTS 162 int pic_handle_softint(void *); 163 #endif 164 165 extern struct pic_softc * pic_list[PIC_MAXPICS]; 166 #endif /* _INTR_PRIVATE */ 167 168 #endif /* _ARM_PIC_PICVAR_H_ */ 169