xref: /openbsd/sys/arch/loongson/dev/bonito_irq.h (revision d57a735d)
1 /*	$OpenBSD: bonito_irq.h,v 1.2 2010/05/08 21:59:56 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 2009, 2010 Miodrag Vallat.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * Bonito interrupt assignments
21  */
22 
23 /*
24  * Loongson 2F assignments
25  */
26 
27 #define	LOONGSON_INTR_GPIO0		0
28 #define	LOONGSON_INTR_GPIO1		1
29 #define	LOONGSON_INTR_GPIO2		2
30 #define	LOONGSON_INTR_GPIO3		3
31 
32 /* pci interrupts */
33 #define	LOONGSON_INTR_PCIA		4
34 #define	LOONGSON_INTR_PCIB		5
35 #define	LOONGSON_INTR_PCIC		6
36 #define	LOONGSON_INTR_PCID		7
37 
38 #define	LOONGSON_INTR_PCI_PARERR	8
39 #define	LOONGSON_INTR_PCI_SYSERR	9
40 #define	LOONGSON_INTR_DRAM_PARERR	10
41 
42 /* non-PCI interrupts */
43 #define	LOONGSON_INTR_INT0		11
44 #define	LOONGSON_INTR_INT1		12
45 #define	LOONGSON_INTR_INT2		13
46 #define	LOONGSON_INTR_INT3		14
47 
48 #define	LOONGSON_INTRMASK_GPIO0		0x00000001	/* can't interrupt */
49 #define	LOONGSON_INTRMASK_GPIO1		0x00000002
50 #define	LOONGSON_INTRMASK_GPIO2		0x00000004
51 #define	LOONGSON_INTRMASK_GPIO3		0x00000008
52 
53 #define	LOONGSON_INTRMASK_GPIO		0x0000000f
54 
55 /* pci interrupts */
56 #define	LOONGSON_INTRMASK_PCIA		0x00000010
57 #define	LOONGSON_INTRMASK_PCIB		0x00000020
58 #define	LOONGSON_INTRMASK_PCIC		0x00000040
59 #define	LOONGSON_INTRMASK_PCID		0x00000080
60 
61 #define	LOONGSON_INTRMASK_PCI_PARERR	0x00000100
62 #define	LOONGSON_INTRMASK_PCI_SYSERR	0x00000200
63 #define	LOONGSON_INTRMASK_DRAM_PARERR	0x00000400
64 
65 /* non-PCI interrupts */
66 #define	LOONGSON_INTRMASK_INT0		0x00000800
67 #define	LOONGSON_INTRMASK_INT1		0x00001000
68 #define	LOONGSON_INTRMASK_INT2		0x00002000
69 #define	LOONGSON_INTRMASK_INT3		0x00004000
70 
71 #define	LOONGSON_INTRMASK_LVL0		0x00007800 /* not maskable in bonito */
72 #define	LOONGSON_INTRMASK_LVL4		0x000007ff
73 
74 /*
75  * Loongson 2E (Bonito64) assignments
76  */
77 
78 #define	BONITO_INTRMASK_MBOX		0x0000000f
79 #define	BONITO_INTR_MBOX		0
80 #define	BONITO_INTRMASK_DMARDY		0x00000010
81 #define	BONITO_INTRMASK_DMAEMPTY	0x00000020
82 #define	BONITO_INTRMASK_COPYRDY		0x00000040
83 #define	BONITO_INTRMASK_COPYEMPTY	0x00000080
84 #define	BONITO_INTRMASK_COPYERR		0x00000100
85 #define	BONITO_INTRMASK_PCIIRQ		0x00000200
86 #define	BONITO_INTRMASK_MASTERERR	0x00000400
87 #define	BONITO_INTRMASK_SYSTEMERR	0x00000800
88 #define	BONITO_INTRMASK_DRAMPERR	0x00001000
89 #define	BONITO_INTRMASK_RETRYERR	0x00002000
90 #define	BONITO_INTRMASK_GPIO		0x01ff0000
91 #define	BONITO_INTR_GPIO		16
92 #define	BONITO_INTRMASK_GPIN		0x7e000000
93 #define	BONITO_INTR_GPIN		25
94 
95 /*
96  * Bonito interrupt handling recipes:
97  * - we have up to 32 interrupts at the Bonito level.
98  * - systems with ISA devices also have 16 (well, 15) ISA interrupts with the
99  *   usual 8259 pair. Bonito and ISA interrupts happen on two different levels.
100  *
101  * These arbitrary values may be changed as long as interrupt mask variables
102  * use large enough integer types and always use the following macros to
103  * handle interrupt masks.
104  */
105 
106 #define	INTPRI_BONITO		(INTPRI_CLOCK + 1)
107 #define	INTPRI_ISA		(INTPRI_BONITO + 1)
108 
109 #define	BONITO_NDIRECT		32
110 #define	BONITO_NISA		16
111 #define	BONITO_NINTS		(BONITO_NDIRECT + BONITO_NISA)
112 #define	BONITO_ISA_IRQ(i)	((i) + BONITO_NDIRECT)
113 #define	BONITO_DIRECT_IRQ(i)	(i)
114 #define	BONITO_IRQ_IS_ISA(i)	((i) >= BONITO_NDIRECT)
115 #define	BONITO_IRQ_TO_ISA(i)	((i) - BONITO_NDIRECT)
116 
117 #define	BONITO_DIRECT_MASK(imask)	((imask) & ((1L << BONITO_NDIRECT) - 1))
118 #define	BONITO_ISA_MASK(imask)		((imask) >> BONITO_NDIRECT)
119 
120 extern struct intrhand *bonito_intrhand[BONITO_NINTS];
121 extern uint64_t bonito_intem;
122 extern uint64_t bonito_imask[NIPLS];
123