blob: 802e797e64a24e8ebdcb5233768b188fee530f7d [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Boyan Karatoteve5629bd2025-06-16 11:45:34 +01002 * Copyright (c) 2018-2025, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __ARM_GIC_H__
8#define __ARM_GIC_H__
9
Madhukar Pappireddyc6a3abf2023-10-25 16:47:23 -050010#include <stdbool.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020011#include <stdint.h>
12
13/***************************************************************************
14 * Defines and prototypes for ARM GIC driver.
15 **************************************************************************/
16#define MAX_SGIS 16
17#define MIN_SGI_ID 0
18#define MAX_SGI_ID 15
19#define MIN_PPI_ID 16
20#define MAX_PPI_ID 31
21#define MIN_SPI_ID 32
Deepika Bhavnani73e5cb42020-02-06 17:15:23 -060022#define MAX_SPI_ID 1019
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020023
24#define IS_SGI(irq_num) \
25 (((irq_num) >= MIN_SGI_ID) && ((irq_num) <= MAX_SGI_ID))
26
27#define IS_PPI(irq_num) \
28 (((irq_num) >= MIN_PPI_ID) && ((irq_num) <= MAX_PPI_ID))
29
30#define IS_SPI(irq_num) \
31 (((irq_num) >= MIN_SPI_ID) && ((irq_num) <= MAX_SPI_ID))
32
33#define IS_VALID_INTR_ID(irq_num) \
34 (((irq_num) >= MIN_SGI_ID) && ((irq_num) <= MAX_SPI_ID))
35
36#define GIC_HIGHEST_NS_PRIORITY 0
37#define GIC_LOWEST_NS_PRIORITY 254 /* 255 would disable an interrupt */
38#define GIC_SPURIOUS_INTERRUPT 1023
39
Boyan Karatoteve5629bd2025-06-16 11:45:34 +010040/* return the GIC version detected */
41int arm_gic_get_version(void);
42
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020043/******************************************************************************
44 * Setup the global GIC interface. In case of GICv2, it would be the GIC
45 * Distributor and in case of GICv3 it would be GIC Distributor and
46 * Re-distributor.
47 *****************************************************************************/
48void arm_gic_setup_global(void);
49
50/******************************************************************************
51 * Setup the GIC interface local to the CPU
52 *****************************************************************************/
53void arm_gic_setup_local(void);
54
55/******************************************************************************
56 * Disable interrupts for this local CPU
57 *****************************************************************************/
58void arm_gic_disable_interrupts_local(void);
59
60/******************************************************************************
61 * Enable interrupts for this local CPU
62 *****************************************************************************/
63void arm_gic_enable_interrupts_local(void);
64
65/******************************************************************************
66 * Send SGI with ID `sgi_id` to a core with index `core_pos`.
67 *****************************************************************************/
68void arm_gic_send_sgi(unsigned int sgi_id, unsigned int core_pos);
69
70/******************************************************************************
Boyan Karatotev6d144db2025-06-23 15:04:53 +010071 * Get the INTID for an SGI with number `seq_id` for a core with index
72 * `core_pos`.
73 *****************************************************************************/
74unsigned int arm_gic_get_sgi_num(unsigned int seq_id, unsigned int core_pos);
75
76/******************************************************************************
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020077 * Set the interrupt target of interrupt ID `num` to a core with index
78 * `core_pos`
79 *****************************************************************************/
80void arm_gic_set_intr_target(unsigned int num, unsigned int core_pos);
81
82/******************************************************************************
83 * Get the priority of the interrupt ID `num`.
84 *****************************************************************************/
85unsigned int arm_gic_get_intr_priority(unsigned int num);
86
87/******************************************************************************
88 * Set the priority of the interrupt ID `num` to `priority`.
89 *****************************************************************************/
90void arm_gic_set_intr_priority(unsigned int num, unsigned int priority);
91
92/******************************************************************************
93 * Check if the interrupt ID `num` is enabled
94 *****************************************************************************/
95unsigned int arm_gic_intr_enabled(unsigned int num);
96
97/******************************************************************************
98 * Enable the interrupt ID `num`
99 *****************************************************************************/
100void arm_gic_intr_enable(unsigned int num);
101
102/******************************************************************************
103 * Disable the interrupt ID `num`
104 *****************************************************************************/
105void arm_gic_intr_disable(unsigned int num);
106
107/******************************************************************************
108 * Acknowledge the highest pending interrupt. Return the interrupt ID of the
109 * acknowledged interrupt. The raw interrupt acknowledge register value will
110 * be populated in `raw_iar`.
111 *****************************************************************************/
112unsigned int arm_gic_intr_ack(unsigned int *raw_iar);
113
114/******************************************************************************
115 * Signal the end of interrupt processing of a interrupt. The raw interrupt
116 * acknowledge register value returned by arm_gic_intr_ack() should be passed
117 * as argument to this function.
118 *****************************************************************************/
119void arm_gic_end_of_intr(unsigned int raw_iar);
120
121/******************************************************************************
122 * Check if the interrupt with ID `num` is pending at the GIC. Returns 1 if
123 * interrupt is pending else returns 0.
124 *****************************************************************************/
125unsigned int arm_gic_is_intr_pending(unsigned int num);
126
127/******************************************************************************
128 * Clear the pending status of the interrupt with ID `num` at the GIC.
129 *****************************************************************************/
130void arm_gic_intr_clear(unsigned int num);
131
132/******************************************************************************
Boyan Karatoteve5629bd2025-06-16 11:45:34 +0100133 * Discover the GIC version in use.
134 *****************************************************************************/
135void arm_gic_probe(void);
136
137/******************************************************************************
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200138 * Initialize the GIC Driver. This function will detect the GIC Architecture
139 * present on the system and initialize the appropriate driver. The
140 * `gicr_base` argument will be ignored on GICv2 systems.
141 *****************************************************************************/
142void arm_gic_init(uintptr_t gicc_base, uintptr_t gicd_base, uintptr_t gicr_base);
143
144/******************************************************************************
145 * Save the GIC context local to this CPU (like GIC CPU Interface) which will
146 * be lost when this CPU is powered down.
147 *****************************************************************************/
148void arm_gic_save_context_local(void);
149
150/******************************************************************************
151 * Restore the GIC context local to this CPU ((like GIC CPU Interface) which
152 * was lost when this CPU was powered down.
153 *****************************************************************************/
154void arm_gic_restore_context_local(void);
155
156/******************************************************************************
157 * Save the global GIC context when GIC will be powered down (like GIC
158 * Distributor and Re-distributor) as a result of system suspend.
159 *****************************************************************************/
160void arm_gic_save_context_global(void);
161
162/******************************************************************************
163 * Restore the global GIC context which was lost as a result of GIC power
164 * down (like GIC Distributor and Re-distributor) during system suspend.
165 *****************************************************************************/
166void arm_gic_restore_context_global(void);
167
Madhukar Pappireddyc6a3abf2023-10-25 16:47:23 -0500168/******************************************************************************
169 * Check if extended SPI range is implemented by GIC.
170 *****************************************************************************/
171bool arm_gic_is_espi_supported(void);
172
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200173#endif /* __ARM_GIC_H__ */