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