blob: 10e4a90730190ded6e9f26b800f8d3d56b838ec4 [file] [log] [blame]
Ralf Baechle39b8d522008-04-28 17:14:26 +01001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2000, 07 MIPS Technologies, Inc.
Ralf Baechle39b8d522008-04-28 17:14:26 +01007 */
Andrew Bresticker824f3f72014-10-20 12:03:54 -07008#ifndef __LINUX_IRQCHIP_MIPS_GIC_H
9#define __LINUX_IRQCHIP_MIPS_GIC_H
Ralf Baechle39b8d522008-04-28 17:14:26 +010010
Andrew Bresticker824f3f72014-10-20 12:03:54 -070011#include <linux/clocksource.h>
Jeffrey Deansc9750482014-07-17 09:20:54 +010012
Andrew Brestickerfbd55242014-09-18 14:47:25 -070013#define GIC_MAX_INTRS 256
14
Ralf Baechle39b8d522008-04-28 17:14:26 +010015/* Constants */
16#define GIC_POL_POS 1
17#define GIC_POL_NEG 0
18#define GIC_TRIG_EDGE 1
19#define GIC_TRIG_LEVEL 0
Andrew Bresticker95150ae2014-09-18 14:47:21 -070020#define GIC_TRIG_DUAL_ENABLE 1
21#define GIC_TRIG_DUAL_DISABLE 0
Ralf Baechle39b8d522008-04-28 17:14:26 +010022
Ralf Baechle39b8d522008-04-28 17:14:26 +010023#define MSK(n) ((1 << (n)) - 1)
Ralf Baechle39b8d522008-04-28 17:14:26 +010024
25/* Accessors */
Andrew Bresticker5f68fea2014-10-20 12:03:52 -070026#define GIC_REG(segment, offset) (segment##_##SECTION_OFS + offset##_##OFS)
Ralf Baechle39b8d522008-04-28 17:14:26 +010027
28/* GIC Address Space */
29#define SHARED_SECTION_OFS 0x0000
30#define SHARED_SECTION_SIZE 0x8000
31#define VPE_LOCAL_SECTION_OFS 0x8000
32#define VPE_LOCAL_SECTION_SIZE 0x4000
33#define VPE_OTHER_SECTION_OFS 0xc000
34#define VPE_OTHER_SECTION_SIZE 0x4000
35#define USM_VISIBLE_SECTION_OFS 0x10000
36#define USM_VISIBLE_SECTION_SIZE 0x10000
37
38/* Register Map for Shared Section */
Ralf Baechle39b8d522008-04-28 17:14:26 +010039
Ralf Baechle70342282013-01-22 12:59:30 +010040#define GIC_SH_CONFIG_OFS 0x0000
Ralf Baechle39b8d522008-04-28 17:14:26 +010041
42/* Shared Global Counter */
43#define GIC_SH_COUNTER_31_00_OFS 0x0010
44#define GIC_SH_COUNTER_63_32_OFS 0x0014
Chris Dearman7098f742009-07-10 01:54:09 -070045#define GIC_SH_REVISIONID_OFS 0x0020
Ralf Baechle39b8d522008-04-28 17:14:26 +010046
Chris Dearman7098f742009-07-10 01:54:09 -070047/* Convert an interrupt number to a byte offset/bit for multi-word registers */
Markos Chandrasc3f57f02015-07-14 10:26:09 +010048#define GIC_INTR_OFS(intr) ({ \
49 unsigned bits = mips_cm_is64 ? 64 : 32; \
50 unsigned reg_idx = (intr) / bits; \
51 unsigned reg_width = bits / 8; \
52 \
53 reg_idx * reg_width; \
54})
55#define GIC_INTR_BIT(intr) ((intr) % (mips_cm_is64 ? 64 : 32))
Chris Dearman7098f742009-07-10 01:54:09 -070056
Ralf Baechle39b8d522008-04-28 17:14:26 +010057/* Polarity : Reset Value is always 0 */
58#define GIC_SH_SET_POLARITY_OFS 0x0100
Ralf Baechle39b8d522008-04-28 17:14:26 +010059
60/* Triggering : Reset Value is always 0 */
61#define GIC_SH_SET_TRIGGER_OFS 0x0180
Ralf Baechle39b8d522008-04-28 17:14:26 +010062
Andrew Bresticker95150ae2014-09-18 14:47:21 -070063/* Dual edge triggering : Reset Value is always 0 */
64#define GIC_SH_SET_DUAL_OFS 0x0200
Andrew Bresticker95150ae2014-09-18 14:47:21 -070065
Andrew Bresticker824f3f72014-10-20 12:03:54 -070066/* Set/Clear corresponding bit in Edge Detect Register */
67#define GIC_SH_WEDGE_OFS 0x0280
68
Ralf Baechle39b8d522008-04-28 17:14:26 +010069/* Mask manipulation */
Ralf Baechle39b8d522008-04-28 17:14:26 +010070#define GIC_SH_RMASK_OFS 0x0300
Andrew Bresticker824f3f72014-10-20 12:03:54 -070071#define GIC_SH_SMASK_OFS 0x0380
72
73/* Global Interrupt Mask Register (RO) - Bit Set == Interrupt enabled */
74#define GIC_SH_MASK_OFS 0x0400
75
76/* Pending Global Interrupts (RO) */
77#define GIC_SH_PEND_OFS 0x0480
78
79/* Maps Interrupt X to a Pin */
80#define GIC_SH_INTR_MAP_TO_PIN_BASE_OFS 0x0500
81#define GIC_SH_MAP_TO_PIN(intr) (4 * (intr))
82
83/* Maps Interrupt X to a VPE */
84#define GIC_SH_INTR_MAP_TO_VPE_BASE_OFS 0x2000
85#define GIC_SH_MAP_TO_VPE_REG_OFF(intr, vpe) \
86 ((32 * (intr)) + (((vpe) / 32) * 4))
87#define GIC_SH_MAP_TO_VPE_REG_BIT(vpe) (1 << ((vpe) % 32))
Ralf Baechle39b8d522008-04-28 17:14:26 +010088
89/* Register Map for Local Section */
90#define GIC_VPE_CTL_OFS 0x0000
91#define GIC_VPE_PEND_OFS 0x0004
92#define GIC_VPE_MASK_OFS 0x0008
93#define GIC_VPE_RMASK_OFS 0x000c
94#define GIC_VPE_SMASK_OFS 0x0010
95#define GIC_VPE_WD_MAP_OFS 0x0040
96#define GIC_VPE_COMPARE_MAP_OFS 0x0044
97#define GIC_VPE_TIMER_MAP_OFS 0x0048
Andrew Brestickere9de6882014-09-18 14:47:27 -070098#define GIC_VPE_FDC_MAP_OFS 0x004c
Ralf Baechle39b8d522008-04-28 17:14:26 +010099#define GIC_VPE_PERFCTR_MAP_OFS 0x0050
100#define GIC_VPE_SWINT0_MAP_OFS 0x0054
101#define GIC_VPE_SWINT1_MAP_OFS 0x0058
102#define GIC_VPE_OTHER_ADDR_OFS 0x0080
103#define GIC_VPE_WD_CONFIG0_OFS 0x0090
104#define GIC_VPE_WD_COUNT0_OFS 0x0094
105#define GIC_VPE_WD_INITIAL0_OFS 0x0098
106#define GIC_VPE_COMPARE_LO_OFS 0x00a0
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -0500107#define GIC_VPE_COMPARE_HI_OFS 0x00a4
Ralf Baechle39b8d522008-04-28 17:14:26 +0100108
Andrew Bresticker5f68fea2014-10-20 12:03:52 -0700109#define GIC_VPE_EIC_SHADOW_SET_BASE_OFS 0x0100
110#define GIC_VPE_EIC_SS(intr) (4 * (intr))
Ralf Baechle39b8d522008-04-28 17:14:26 +0100111
Andrew Bresticker5f68fea2014-10-20 12:03:52 -0700112#define GIC_VPE_EIC_VEC_BASE_OFS 0x0800
113#define GIC_VPE_EIC_VEC(intr) (4 * (intr))
Ralf Baechle39b8d522008-04-28 17:14:26 +0100114
115#define GIC_VPE_TENABLE_NMI_OFS 0x1000
116#define GIC_VPE_TENABLE_YQ_OFS 0x1004
117#define GIC_VPE_TENABLE_INT_31_0_OFS 0x1080
118#define GIC_VPE_TENABLE_INT_63_32_OFS 0x1084
119
120/* User Mode Visible Section Register Map */
121#define GIC_UMV_SH_COUNTER_31_00_OFS 0x0000
122#define GIC_UMV_SH_COUNTER_63_32_OFS 0x0004
123
Ralf Baechle39b8d522008-04-28 17:14:26 +0100124/* Masks */
125#define GIC_SH_CONFIG_COUNTSTOP_SHF 28
126#define GIC_SH_CONFIG_COUNTSTOP_MSK (MSK(1) << GIC_SH_CONFIG_COUNTSTOP_SHF)
127
128#define GIC_SH_CONFIG_COUNTBITS_SHF 24
129#define GIC_SH_CONFIG_COUNTBITS_MSK (MSK(4) << GIC_SH_CONFIG_COUNTBITS_SHF)
130
131#define GIC_SH_CONFIG_NUMINTRS_SHF 16
132#define GIC_SH_CONFIG_NUMINTRS_MSK (MSK(8) << GIC_SH_CONFIG_NUMINTRS_SHF)
133
134#define GIC_SH_CONFIG_NUMVPES_SHF 0
135#define GIC_SH_CONFIG_NUMVPES_MSK (MSK(8) << GIC_SH_CONFIG_NUMVPES_SHF)
136
Andrew Bresticker824f3f72014-10-20 12:03:54 -0700137#define GIC_SH_WEDGE_SET(intr) ((intr) | (0x1 << 31))
138#define GIC_SH_WEDGE_CLR(intr) ((intr) & ~(0x1 << 31))
Ralf Baechle39b8d522008-04-28 17:14:26 +0100139
140#define GIC_MAP_TO_PIN_SHF 31
141#define GIC_MAP_TO_PIN_MSK (MSK(1) << GIC_MAP_TO_PIN_SHF)
142#define GIC_MAP_TO_NMI_SHF 30
143#define GIC_MAP_TO_NMI_MSK (MSK(1) << GIC_MAP_TO_NMI_SHF)
144#define GIC_MAP_TO_YQ_SHF 29
145#define GIC_MAP_TO_YQ_MSK (MSK(1) << GIC_MAP_TO_YQ_SHF)
146#define GIC_MAP_SHF 0
147#define GIC_MAP_MSK (MSK(6) << GIC_MAP_SHF)
148
149/* GIC_VPE_CTL Masks */
Andrew Brestickere9de6882014-09-18 14:47:27 -0700150#define GIC_VPE_CTL_FDC_RTBL_SHF 4
151#define GIC_VPE_CTL_FDC_RTBL_MSK (MSK(1) << GIC_VPE_CTL_FDC_RTBL_SHF)
152#define GIC_VPE_CTL_SWINT_RTBL_SHF 3
153#define GIC_VPE_CTL_SWINT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_SWINT_RTBL_SHF)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100154#define GIC_VPE_CTL_PERFCNT_RTBL_SHF 2
155#define GIC_VPE_CTL_PERFCNT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_PERFCNT_RTBL_SHF)
156#define GIC_VPE_CTL_TIMER_RTBL_SHF 1
157#define GIC_VPE_CTL_TIMER_RTBL_MSK (MSK(1) << GIC_VPE_CTL_TIMER_RTBL_SHF)
158#define GIC_VPE_CTL_EIC_MODE_SHF 0
159#define GIC_VPE_CTL_EIC_MODE_MSK (MSK(1) << GIC_VPE_CTL_EIC_MODE_SHF)
160
161/* GIC_VPE_PEND Masks */
162#define GIC_VPE_PEND_WD_SHF 0
163#define GIC_VPE_PEND_WD_MSK (MSK(1) << GIC_VPE_PEND_WD_SHF)
164#define GIC_VPE_PEND_CMP_SHF 1
165#define GIC_VPE_PEND_CMP_MSK (MSK(1) << GIC_VPE_PEND_CMP_SHF)
166#define GIC_VPE_PEND_TIMER_SHF 2
167#define GIC_VPE_PEND_TIMER_MSK (MSK(1) << GIC_VPE_PEND_TIMER_SHF)
168#define GIC_VPE_PEND_PERFCOUNT_SHF 3
169#define GIC_VPE_PEND_PERFCOUNT_MSK (MSK(1) << GIC_VPE_PEND_PERFCOUNT_SHF)
170#define GIC_VPE_PEND_SWINT0_SHF 4
171#define GIC_VPE_PEND_SWINT0_MSK (MSK(1) << GIC_VPE_PEND_SWINT0_SHF)
172#define GIC_VPE_PEND_SWINT1_SHF 5
173#define GIC_VPE_PEND_SWINT1_MSK (MSK(1) << GIC_VPE_PEND_SWINT1_SHF)
James Hoganea3c0232015-01-27 21:45:51 +0000174#define GIC_VPE_PEND_FDC_SHF 6
175#define GIC_VPE_PEND_FDC_MSK (MSK(1) << GIC_VPE_PEND_FDC_SHF)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100176
177/* GIC_VPE_RMASK Masks */
178#define GIC_VPE_RMASK_WD_SHF 0
179#define GIC_VPE_RMASK_WD_MSK (MSK(1) << GIC_VPE_RMASK_WD_SHF)
180#define GIC_VPE_RMASK_CMP_SHF 1
181#define GIC_VPE_RMASK_CMP_MSK (MSK(1) << GIC_VPE_RMASK_CMP_SHF)
182#define GIC_VPE_RMASK_TIMER_SHF 2
183#define GIC_VPE_RMASK_TIMER_MSK (MSK(1) << GIC_VPE_RMASK_TIMER_SHF)
184#define GIC_VPE_RMASK_PERFCNT_SHF 3
185#define GIC_VPE_RMASK_PERFCNT_MSK (MSK(1) << GIC_VPE_RMASK_PERFCNT_SHF)
186#define GIC_VPE_RMASK_SWINT0_SHF 4
187#define GIC_VPE_RMASK_SWINT0_MSK (MSK(1) << GIC_VPE_RMASK_SWINT0_SHF)
188#define GIC_VPE_RMASK_SWINT1_SHF 5
189#define GIC_VPE_RMASK_SWINT1_MSK (MSK(1) << GIC_VPE_RMASK_SWINT1_SHF)
James Hoganea3c0232015-01-27 21:45:51 +0000190#define GIC_VPE_RMASK_FDC_SHF 6
191#define GIC_VPE_RMASK_FDC_MSK (MSK(1) << GIC_VPE_RMASK_FDC_SHF)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100192
193/* GIC_VPE_SMASK Masks */
194#define GIC_VPE_SMASK_WD_SHF 0
195#define GIC_VPE_SMASK_WD_MSK (MSK(1) << GIC_VPE_SMASK_WD_SHF)
196#define GIC_VPE_SMASK_CMP_SHF 1
197#define GIC_VPE_SMASK_CMP_MSK (MSK(1) << GIC_VPE_SMASK_CMP_SHF)
198#define GIC_VPE_SMASK_TIMER_SHF 2
199#define GIC_VPE_SMASK_TIMER_MSK (MSK(1) << GIC_VPE_SMASK_TIMER_SHF)
200#define GIC_VPE_SMASK_PERFCNT_SHF 3
201#define GIC_VPE_SMASK_PERFCNT_MSK (MSK(1) << GIC_VPE_SMASK_PERFCNT_SHF)
202#define GIC_VPE_SMASK_SWINT0_SHF 4
203#define GIC_VPE_SMASK_SWINT0_MSK (MSK(1) << GIC_VPE_SMASK_SWINT0_SHF)
204#define GIC_VPE_SMASK_SWINT1_SHF 5
205#define GIC_VPE_SMASK_SWINT1_MSK (MSK(1) << GIC_VPE_SMASK_SWINT1_SHF)
James Hoganea3c0232015-01-27 21:45:51 +0000206#define GIC_VPE_SMASK_FDC_SHF 6
207#define GIC_VPE_SMASK_FDC_MSK (MSK(1) << GIC_VPE_SMASK_FDC_SHF)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100208
Steven J. Hill0b271f52012-08-31 16:05:37 -0500209/* GIC nomenclature for Core Interrupt Pins. */
210#define GIC_CPU_INT0 0 /* Core Interrupt 2 */
Ralf Baechle70342282013-01-22 12:59:30 +0100211#define GIC_CPU_INT1 1 /* . */
212#define GIC_CPU_INT2 2 /* . */
213#define GIC_CPU_INT3 3 /* . */
214#define GIC_CPU_INT4 4 /* . */
Tony Wu42a11172013-06-21 10:09:23 +0000215#define GIC_CPU_INT5 5 /* Core Interrupt 7 */
Steven J. Hill0b271f52012-08-31 16:05:37 -0500216
Andrew Bresticker18743d22014-09-18 14:47:24 -0700217/* Add 2 to convert GIC CPU pin to core interrupt */
218#define GIC_CPU_PIN_OFFSET 2
219
Steven J. Hill0b271f52012-08-31 16:05:37 -0500220/* Add 2 to convert non-EIC hardware interrupt to EIC vector number. */
Andrew Bresticker824f3f72014-10-20 12:03:54 -0700221#define GIC_CPU_TO_VEC_OFFSET 2
Steven J. Hill0b271f52012-08-31 16:05:37 -0500222
223/* Mapped interrupt to pin X, then GIC will generate the vector (X+1). */
Andrew Bresticker824f3f72014-10-20 12:03:54 -0700224#define GIC_PIN_TO_VEC_OFFSET 1
Steven J. Hill0b271f52012-08-31 16:05:37 -0500225
Andrew Brestickere9de6882014-09-18 14:47:27 -0700226/* Local GIC interrupts. */
227#define GIC_LOCAL_INT_WD 0 /* GIC watchdog */
228#define GIC_LOCAL_INT_COMPARE 1 /* GIC count and compare timer */
229#define GIC_LOCAL_INT_TIMER 2 /* CPU timer interrupt */
230#define GIC_LOCAL_INT_PERFCTR 3 /* CPU performance counter */
231#define GIC_LOCAL_INT_SWINT0 4 /* CPU software interrupt 0 */
232#define GIC_LOCAL_INT_SWINT1 5 /* CPU software interrupt 1 */
233#define GIC_LOCAL_INT_FDC 6 /* CPU fast debug channel */
234#define GIC_NUM_LOCAL_INTRS 7
235
236/* Convert between local/shared IRQ number and GIC HW IRQ number. */
237#define GIC_LOCAL_HWIRQ_BASE 0
238#define GIC_LOCAL_TO_HWIRQ(x) (GIC_LOCAL_HWIRQ_BASE + (x))
239#define GIC_HWIRQ_TO_LOCAL(x) ((x) - GIC_LOCAL_HWIRQ_BASE)
240#define GIC_SHARED_HWIRQ_BASE GIC_NUM_LOCAL_INTRS
241#define GIC_SHARED_TO_HWIRQ(x) (GIC_SHARED_HWIRQ_BASE + (x))
242#define GIC_HWIRQ_TO_SHARED(x) ((x) - GIC_SHARED_HWIRQ_BASE)
243
Steven J. Hillff867142013-04-10 16:27:04 -0500244extern unsigned int gic_present;
Steven J. Hill0b271f52012-08-31 16:05:37 -0500245
Ralf Baechle39b8d522008-04-28 17:14:26 +0100246extern void gic_init(unsigned long gic_base_addr,
Andrew Bresticker18743d22014-09-18 14:47:24 -0700247 unsigned long gic_addrspace_size, unsigned int cpu_vec,
248 unsigned int irqbase);
Steven J. Hill0b271f52012-08-31 16:05:37 -0500249extern void gic_clocksource_init(unsigned int);
Steven J. Hilldfa762e2013-04-10 16:28:36 -0500250extern cycle_t gic_read_count(void);
Andrew Bresticker387904f2014-10-20 12:03:49 -0700251extern unsigned int gic_get_count_width(void);
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -0500252extern cycle_t gic_read_compare(void);
253extern void gic_write_compare(cycle_t cnt);
Paul Burton414408d02014-03-05 11:35:53 +0000254extern void gic_write_cpu_compare(cycle_t cnt, int cpu);
Markos Chandras8fa4b932015-03-23 12:32:01 +0000255extern void gic_start_count(void);
256extern void gic_stop_count(void);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100257extern void gic_send_ipi(unsigned int intr);
Tim Anderson03650702009-06-17 16:22:53 -0700258extern unsigned int plat_ipi_call_int_xlate(unsigned int);
259extern unsigned int plat_ipi_resched_int_xlate(unsigned int);
Andrew Brestickere9de6882014-09-18 14:47:27 -0700260extern int gic_get_c0_compare_int(void);
261extern int gic_get_c0_perfcount_int(void);
James Hogan6429e2b2015-01-29 11:14:09 +0000262extern int gic_get_c0_fdc_int(void);
Andrew Bresticker824f3f72014-10-20 12:03:54 -0700263#endif /* __LINUX_IRQCHIP_MIPS_GIC_H */