Home | History | Annotate | Line # | Download | only in pic
picvar.h revision 1.17
      1 /*	$NetBSD: picvar.h,v 1.17 2018/07/15 16:03:24 jmcneill 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 _KERNEL_OPT
     34 #include "opt_multiprocessor.h"
     35 #endif
     36 
     37 #ifdef MULTIPROCESSOR
     38 #include <sys/kcpuset.h>
     39 #endif
     40 
     41 int	_splraise(int);
     42 int	_spllower(int);
     43 void	splx(int);
     44 const char *
     45 	intr_typename(int);
     46 
     47 struct pic_softc;
     48 struct intrsource;
     49 struct cpu_info;
     50 
     51 #define	IPI_AST			0	/* just get an interrupt */
     52 #define	IPI_XCALL		1	/* xcall */
     53 #define	IPI_NOP			2	/* just get an interrupt (armv6) */
     54 #define	IPI_SHOOTDOWN		3	/* cause a tlb shootdown */
     55 #define	IPI_DDB			4	/* enter DDB */
     56 #define	IPI_GENERIC		5	/* generic IPI */
     57 #ifdef __HAVE_PREEMPTION
     58 #define	IPI_KPREEMPT		6	/* cause a preemption */
     59 #define	NIPI			7
     60 #else
     61 #define	NIPI			6
     62 #endif
     63 
     64 #if !defined(__HAVE_PIC_SET_PRIORITY)
     65 #define __HAVE_PIC_PENDING_INTRS
     66 #endif
     67 
     68 int	pic_handle_intr(void *);
     69 #if defined(__HAVE_PIC_PENDING_INTRS)
     70 void	pic_mark_pending(struct pic_softc *pic, int irq);
     71 void	pic_mark_pending_source(struct pic_softc *pic, struct intrsource *is);
     72 uint32_t pic_mark_pending_sources(struct pic_softc *pic, size_t irq_base,
     73 	    uint32_t pending);
     74 #endif /* __HAVE_PIC_PENDING_INTRS */
     75 void	*pic_establish_intr(struct pic_softc *pic, int irq, int ipl, int type,
     76 	    int (*func)(void *), void *arg);
     77 int	pic_alloc_irq(struct pic_softc *pic);
     78 void	pic_disestablish_source(struct intrsource *is);
     79 #ifdef MULTIPROCESSOR
     80 void	pic_distribute_source(struct intrsource *is, const kcpuset_t *,
     81 	    kcpuset_t *);
     82 #endif
     83 void	pic_do_pending_ints(register_t psw, int newipl, void *frame);
     84 void	pic_dispatch(struct intrsource *is, void *frame);
     85 
     86 void	*intr_establish(int irq, int ipl, int type, int (*func)(void *),
     87 	    void *arg);
     88 void	intr_disestablish(void *);
     89 #ifdef MULTIPROCESSOR
     90 void	intr_cpu_init(struct cpu_info *);
     91 void	intr_ipi_send(const kcpuset_t *, u_long ipi);
     92 #endif
     93 
     94 #ifdef _INTR_PRIVATE
     95 
     96 #include "opt_arm_intr_impl.h"
     97 
     98 #include <sys/evcnt.h>
     99 #include <sys/percpu.h>
    100 
    101 #ifndef PIC_MAXPICS
    102 #define PIC_MAXPICS	32
    103 #endif
    104 #ifndef PIC_MAXSOURCES
    105 #define	PIC_MAXSOURCES	64
    106 #endif
    107 #ifndef PIC_MAXMAXSOURCES
    108 #define	PIC_MAXMAXSOURCES	128
    109 #endif
    110 
    111 struct intrsource {
    112 	int (*is_func)(void *);
    113 	void *is_arg;
    114 	struct pic_softc *is_pic;		/* owning PIC */
    115 	uint8_t is_type;			/* IST_xxx */
    116 	uint8_t is_ipl;				/* IPL_xxx */
    117 	uint8_t is_irq;				/* local to pic */
    118 	uint8_t is_iplidx;
    119 	bool is_mpsafe;
    120 	char is_source[16];
    121 #ifdef MULTIPROCESSOR
    122 	kcpuset_t *is_affinity;
    123 #endif
    124 };
    125 
    126 struct pic_percpu {
    127 	struct evcnt *pcpu_evs;
    128 	char *pcpu_name;
    129 	uint32_t pcpu_magic;
    130 };
    131 
    132 #define	PICPERCPU_MAGIC		0xfeedface
    133 
    134 struct pic_softc {
    135 	const struct pic_ops *pic_ops;
    136 	struct intrsource **pic_sources;
    137 #ifdef __HAVE_PIC_PENDING_INTRS
    138 	volatile uint32_t pic_pending_irqs[(PIC_MAXSOURCES + 31) / 32];
    139 	volatile uint32_t pic_blocked_irqs[(PIC_MAXSOURCES + 31) / 32];
    140 	volatile uint32_t pic_pending_ipls;
    141 #endif
    142 #ifdef MULTIPROCESSOR
    143 	kcpuset_t *pic_cpus;
    144 #endif
    145 	size_t pic_maxsources;
    146 	percpu_t *pic_percpu;
    147 	uint8_t pic_id;
    148 	int16_t pic_irqbase;
    149 	char pic_name[14];
    150 };
    151 
    152 struct pic_ops {
    153 	void (*pic_unblock_irqs)(struct pic_softc *, size_t, uint32_t);
    154 	void (*pic_block_irqs)(struct pic_softc *, size_t, uint32_t);
    155 	int (*pic_find_pending_irqs)(struct pic_softc *);
    156 
    157 	void (*pic_establish_irq)(struct pic_softc *, struct intrsource *);
    158 	void (*pic_source_name)(struct pic_softc *, int, char *, size_t);
    159 
    160 #ifdef __HAVE_PIC_SET_PRIORITY
    161 	void (*pic_set_priority)(struct pic_softc *, int);
    162 #endif
    163 #ifdef MULTIPROCESSOR
    164 	void (*pic_cpu_init)(struct pic_softc *, struct cpu_info *);
    165 	void (*pic_ipi_send)(struct pic_softc *, const kcpuset_t *, u_long);
    166 	int (*pic_set_affinity)(struct pic_softc *, size_t, const kcpuset_t *);
    167 	void (*pic_get_affinity)(struct pic_softc *, size_t, kcpuset_t *);
    168 #endif
    169 };
    170 
    171 #ifdef __HAVE_PIC_SET_PRIORITY
    172 /*
    173  * This is used to update a hardware pic with a value corresponding
    174  * to the ipl being set.
    175  */
    176 struct cpu_info;
    177 void	pic_set_priority(struct cpu_info *, int);
    178 #else
    179 /* Using an inline causes catch-22 problems with cpu.h */
    180 #define	pic_set_priority(ci, newipl)	((void)((ci)->ci_cpl = (newipl)))
    181 #endif
    182 
    183 void	pic_add(struct pic_softc *, int);
    184 void	pic_do_pending_int(void);
    185 #ifdef MULTIPROCESSOR
    186 int	pic_ipi_ast(void *);
    187 int	pic_ipi_nop(void *);
    188 int	pic_ipi_xcall(void *);
    189 int	pic_ipi_generic(void *);
    190 int	pic_ipi_shootdown(void *);
    191 int	pic_ipi_ddb(void *);
    192 int	pic_ipi_kpreempt(void *);
    193 #endif
    194 #ifdef __HAVE_PIC_FAST_SOFTINTS
    195 int	pic_handle_softint(void *);
    196 #endif
    197 
    198 extern struct pic_softc * pic_list[PIC_MAXPICS];
    199 #endif /* _INTR_PRIVATE */
    200 
    201 #endif /* _ARM_PIC_PICVAR_H_ */
    202