blob: 1628221a065e97bb79cd0252a1b329ffa7808135 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __IRQ_H__
8#define __IRQ_H__
9
10#include <platform_def.h> /* For CACHE_WRITEBACK_GRANULE */
11#include <stdint.h>
12
13/*
14 * SGI sent by the timer management framework to notify CPUs when the system
15 * timer fires off
16 */
17#define IRQ_WAKE_SGI IRQ_NS_SGI_7
18
19#ifndef __ASSEMBLY__
20
21/* Prototype of a handler function for an IRQ */
22typedef int (*irq_handler_t)(void *data);
23
24/* Keep track of the IRQ handler registered for a given SPI */
25typedef struct {
26 irq_handler_t handler;
27} spi_desc;
28
29/* Keep track of the IRQ handler registered for a spurious interrupt */
30typedef irq_handler_t spurious_desc;
31
32/*
33 * PPIs and SGIs are interrupts that are private to a GIC CPU interface. These
34 * interrupts are banked in the GIC Distributor. Therefore, each CPU can
35 * set up a different IRQ handler for a given PPI/SGI.
36 *
37 * So we define a data structure representing an IRQ handler aligned on the
38 * size of a cache line. This guarantees that in an array of these, each element
39 * is loaded in a separate cache line. This allows efficient concurrent
40 * manipulation of these elements on different CPUs.
41 */
42typedef struct {
43 irq_handler_t handler;
44} __aligned(CACHE_WRITEBACK_GRANULE) irq_handler_banked_t;
45
46typedef irq_handler_banked_t ppi_desc;
47typedef irq_handler_banked_t sgi_desc;
48
49void tftf_irq_setup(void);
50
51/*
52 * Generic handler called upon reception of an IRQ.
53 *
54 * This function acknowledges the interrupt, calls the user-defined handler
55 * if one has been registered then marks the processing of the interrupt as
56 * complete.
57 */
58int tftf_irq_handler_dispatcher(void);
59
60/*
61 * Enable interrupt #irq_num for the calling core.
62 */
63void tftf_irq_enable(unsigned int irq_num, uint8_t irq_priority);
64
65/*
66 * Disable interrupt #irq_num for the calling core.
67 */
68void tftf_irq_disable(unsigned int irq_num);
69
70/*
71 * Register an interrupt handler for a given interrupt number.
72 * Will fail if there is already an interrupt handler registered for the same
73 * interrupt.
74 *
75 * Return 0 on success, a negative value otherwise.
76 */
77int tftf_irq_register_handler(unsigned int num, irq_handler_t irq_handler);
78
79/*
80 * Unregister an interrupt handler for a given interrupt number.
81 * Will fail if there is no interrupt handler registered for that interrupt.
82 *
83 * Return 0 on success, a negative value otherwise.
84 */
85int tftf_irq_unregister_handler(unsigned int irq_num);
86
87#endif /* __ASSEMBLY__ */
88
89#endif /* __IRQ_H__ */