1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2016-2019, Linaro Limited 4 */ 5 #ifndef __KERNEL_INTERRUPT_H 6 #define __KERNEL_INTERRUPT_H 7 8 #include <types_ext.h> 9 #include <sys/queue.h> 10 #include <util.h> 11 12 #define ITRF_TRIGGER_LEVEL BIT(0) 13 #define ITRF_SHARED BIT(1) 14 15 struct itr_chip { 16 const struct itr_ops *ops; 17 int (*dt_get_irq)(const uint32_t *properties, int len); 18 }; 19 20 struct itr_ops { 21 void (*add)(struct itr_chip *chip, size_t it, uint32_t flags); 22 void (*enable)(struct itr_chip *chip, size_t it); 23 void (*disable)(struct itr_chip *chip, size_t it); 24 void (*raise_pi)(struct itr_chip *chip, size_t it); 25 void (*raise_sgi)(struct itr_chip *chip, size_t it, 26 uint8_t cpu_mask); 27 void (*set_affinity)(struct itr_chip *chip, size_t it, 28 uint8_t cpu_mask); 29 }; 30 31 enum itr_return { 32 ITRR_NONE, 33 ITRR_HANDLED, 34 }; 35 36 struct itr_handler { 37 size_t it; 38 uint32_t flags; 39 enum itr_return (*handler)(struct itr_handler *h); 40 void *data; 41 SLIST_ENTRY(itr_handler) link; 42 }; 43 44 void itr_init(struct itr_chip *data); 45 void itr_handle(size_t it); 46 47 #ifdef CFG_DT 48 /* 49 * Get the DT interrupt property at @node. In the DT an interrupt 50 * 51 * @fdt reference to the Device Tree 52 * @node is the node offset to read 53 * 54 * Returns the interrupt number if value >= 0 55 * otherwise DT_INFO_INVALID_INTERRUPT 56 */ 57 int dt_get_irq(const void *fdt, int node); 58 #endif 59 60 void itr_add(struct itr_handler *handler); 61 void itr_enable(size_t it); 62 void itr_disable(size_t it); 63 /* raise the Peripheral Interrupt corresponding to the interrupt ID */ 64 void itr_raise_pi(size_t it); 65 /* 66 * raise the Software Generated Interrupt corresponding to the interrupt ID, 67 * the cpu_mask represents which cpu interface to forward. 68 */ 69 void itr_raise_sgi(size_t it, uint8_t cpu_mask); 70 /* 71 * let corresponding interrupt forward to the cpu interface 72 * according to the cpu_mask. 73 */ 74 void itr_set_affinity(size_t it, uint8_t cpu_mask); 75 76 /* 77 * __weak overridable function which is called when a secure interrupt is 78 * received. The default function calls panic() immediately, platforms which 79 * expects to receive secure interrupts should override this function. 80 */ 81 void itr_core_handler(void); 82 83 #endif /*__KERNEL_INTERRUPT_H*/ 84