Home | History | Annotate | Line # | Download | only in pic
      1 /*	$NetBSD: picvar.h,v 1.17 2026/09/28 20:41:01 rkujawa Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 Michael Lorenz
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: picvar.h,v 1.17 2026/09/28 20:41:01 rkujawa Exp $");
     31 
     32 #ifndef PIC_VAR_H
     33 #define PIC_VAR_H
     34 
     35 #include <sys/intr.h>
     36 
     37 struct pic_ops {
     38 	void *pic_cookie;	/* private stuff / hardware info */
     39 	int pic_intrbase;	/* global number of the 1st IRQ we handle */
     40 	int pic_numintrs;	/* how many IRQs do we handle? */
     41 	/*
     42 	 * all functions that take an IRQ number as argument need a local
     43 	 * interrupt number
     44 	 */
     45 	void (*pic_enable_irq)(struct pic_ops *, int, int);
     46 	void (*pic_reenable_irq)(struct pic_ops *, int, int);
     47 	void (*pic_disable_irq)(struct pic_ops *, int);
     48 	int (*pic_get_irq)(struct pic_ops *, int); /* PIC_GET_* */
     49 	void (*pic_ack_irq)(struct pic_ops *, int); /* IRQ numbner */
     50 	/* IRQ number, type, priority */
     51 	void (*pic_establish_irq)(struct pic_ops *, int, int, int);
     52 	/* finish setup after CPUs are attached */
     53 	void (*pic_finish_setup)(struct pic_ops *);
     54 	int pic_flags;		/* PIC_FLAG_* */
     55 	char pic_name[16];
     56 };
     57 
     58 #define	PIC_FLAG_LEVEL_MASK	(1<<0)
     59 
     60 struct intr_source {
     61 	int is_type;
     62 	int is_ipl;
     63 	int is_hwirq;
     64 	imask_t is_mask;
     65 	struct intrhand *is_hand;
     66 	struct pic_ops *is_pic;
     67 	bool is_cascaded;
     68 	struct evcnt is_ev;
     69 	char is_evname[16];
     70 	struct evcnt is_evmasked;	/* we got it while masked at splN */
     71 	char is_evmaskedname[24];
     72 	char is_intrid[INTRIDBUF];
     73 	u_int is_cpuindex;
     74 };
     75 
     76 #define OPENPIC_MAX_ISUS	4
     77 #define OPENPIC_FLAG_DIST	(1<<0)
     78 #define OPENPIC_FLAG_LE		(1<<1)
     79 
     80 struct openpic_ops {
     81 	struct pic_ops pic;
     82 	uint32_t flags;
     83 	int nrofisus;
     84 	volatile unsigned char **isu;
     85 	uint8_t *irq_per;
     86 };
     87 
     88 struct i8259_ops {
     89 	struct pic_ops pic;
     90 	uint32_t pending_events;
     91 	uint32_t enable_mask;
     92 	uint32_t irqs;
     93 };
     94 
     95 /*
     96  * add a pic, fill in pic_intrbase, return pic_intrbase on success,
     97  * -1 otherwise
     98  * the PIC must be initialized and ready for use
     99  */
    100 int	pic_add(struct pic_ops *);
    101 
    102 void	pic_do_pending_int(void);
    103 void	pic_enable_irq(int);
    104 void	pic_disable_irq(int);
    105 int	pic_handle_intr(void *);
    106 void	pic_mark_pending(int);
    107 void	pic_ext_intr(void);
    108 void	pic_init(void);
    109 const char *intr_typename(int);
    110 void	dummy_pic_establish_intr(struct pic_ops *, int, int, int);
    111 
    112 /* this is called after attaching CPUs so PICs can setup interrupt routing */
    113 void pic_finish_setup(void);
    114 
    115 /* address, enable passthrough */
    116 #define PIC_IVR_IBM	0
    117 #define PIC_IVR_MOT	1
    118 #define PIC_GET_IRQ	0
    119 #define PIC_GET_RECHECK	1
    120 struct pic_ops *setup_openpic(void *, int);
    121 struct pic_ops *setup_distributed_openpic(void *, int, void **, int *);
    122 struct pic_ops *setup_prepivr(int);
    123 struct pic_ops *setup_i8259(void);
    124 struct pic_ops *setup_mpcpic(void *);
    125 void mpcpic_reserv16(void);
    126 struct pic_ops *find_pic_by_cookie(void *);
    127 
    128 /* i8259 common decls */
    129 void i8259_initialize(void);
    130 void i8259_enable_irq(struct pic_ops *, int, int);
    131 void i8259_disable_irq(struct pic_ops *, int);
    132 void i8259_ack_irq(struct pic_ops *, int);
    133 int i8259_get_irq(struct pic_ops *, int);
    134 
    135 /* openpic common decls */
    136 void opic_finish_setup(struct pic_ops *pic);
    137 void openpic_set_priority(int cpu, int pri);
    138 int opic_get_irq(struct pic_ops *pic, int mode);
    139 void opic_ack_irq(struct pic_ops *pic, int irq);
    140 
    141 /* IPI handler */
    142 int cpuintr(void *);
    143 /* XXX - may need to be PIC specific */
    144 #define IPI_VECTOR 128
    145 
    146 #endif /* PIC_VAR_H */
    147