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