11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */ 27315b7b4SJens Wiklander /* 3e9f46c74SJens Wiklander * Copyright (c) 2016-2019, Linaro Limited 47315b7b4SJens Wiklander */ 57315b7b4SJens Wiklander #ifndef __KERNEL_INTERRUPT_H 67315b7b4SJens Wiklander #define __KERNEL_INTERRUPT_H 77315b7b4SJens Wiklander 87315b7b4SJens Wiklander #include <types_ext.h> 97315b7b4SJens Wiklander #include <sys/queue.h> 101c832d7cSdavidwang #include <util.h> 117315b7b4SJens Wiklander 121c832d7cSdavidwang #define ITRF_TRIGGER_LEVEL BIT(0) 131c832d7cSdavidwang #define ITRF_SHARED BIT(1) 147315b7b4SJens Wiklander 157315b7b4SJens Wiklander struct itr_chip { 167315b7b4SJens Wiklander const struct itr_ops *ops; 1767729d8dSLudovic Barre int (*dt_get_irq)(const uint32_t *properties, int len); 187315b7b4SJens Wiklander }; 197315b7b4SJens Wiklander 207315b7b4SJens Wiklander struct itr_ops { 217315b7b4SJens Wiklander void (*add)(struct itr_chip *chip, size_t it, uint32_t flags); 227315b7b4SJens Wiklander void (*enable)(struct itr_chip *chip, size_t it); 237315b7b4SJens Wiklander void (*disable)(struct itr_chip *chip, size_t it); 2426ed70ecSGuanchao Liang void (*raise_pi)(struct itr_chip *chip, size_t it); 2526ed70ecSGuanchao Liang void (*raise_sgi)(struct itr_chip *chip, size_t it, 2626ed70ecSGuanchao Liang uint8_t cpu_mask); 2726ed70ecSGuanchao Liang void (*set_affinity)(struct itr_chip *chip, size_t it, 2826ed70ecSGuanchao Liang uint8_t cpu_mask); 297315b7b4SJens Wiklander }; 307315b7b4SJens Wiklander 317315b7b4SJens Wiklander enum itr_return { 327315b7b4SJens Wiklander ITRR_NONE, 337315b7b4SJens Wiklander ITRR_HANDLED, 347315b7b4SJens Wiklander }; 357315b7b4SJens Wiklander 36*acc5dd21SLudovic Barre struct itr_handler; 37*acc5dd21SLudovic Barre 38*acc5dd21SLudovic Barre typedef enum itr_return (*itr_handler_t)(struct itr_handler *h); 39*acc5dd21SLudovic Barre 407315b7b4SJens Wiklander struct itr_handler { 417315b7b4SJens Wiklander size_t it; 427315b7b4SJens Wiklander uint32_t flags; 43*acc5dd21SLudovic Barre itr_handler_t handler; 447315b7b4SJens Wiklander void *data; 457315b7b4SJens Wiklander SLIST_ENTRY(itr_handler) link; 467315b7b4SJens Wiklander }; 477315b7b4SJens Wiklander 487315b7b4SJens Wiklander void itr_init(struct itr_chip *data); 497315b7b4SJens Wiklander void itr_handle(size_t it); 507315b7b4SJens Wiklander 5167729d8dSLudovic Barre #ifdef CFG_DT 5267729d8dSLudovic Barre /* 5367729d8dSLudovic Barre * Get the DT interrupt property at @node. In the DT an interrupt 5467729d8dSLudovic Barre * 5567729d8dSLudovic Barre * @fdt reference to the Device Tree 5667729d8dSLudovic Barre * @node is the node offset to read 5767729d8dSLudovic Barre * 5867729d8dSLudovic Barre * Returns the interrupt number if value >= 0 5967729d8dSLudovic Barre * otherwise DT_INFO_INVALID_INTERRUPT 6067729d8dSLudovic Barre */ 6167729d8dSLudovic Barre int dt_get_irq(const void *fdt, int node); 6267729d8dSLudovic Barre #endif 6367729d8dSLudovic Barre 64*acc5dd21SLudovic Barre struct itr_handler *itr_alloc_add(size_t it, itr_handler_t handler, 65*acc5dd21SLudovic Barre uint32_t flags, void *data); 66*acc5dd21SLudovic Barre void itr_free(struct itr_handler *hdl); 677315b7b4SJens Wiklander void itr_add(struct itr_handler *handler); 6826ed70ecSGuanchao Liang void itr_enable(size_t it); 6926ed70ecSGuanchao Liang void itr_disable(size_t it); 7026ed70ecSGuanchao Liang /* raise the Peripheral Interrupt corresponding to the interrupt ID */ 7126ed70ecSGuanchao Liang void itr_raise_pi(size_t it); 7226ed70ecSGuanchao Liang /* 7326ed70ecSGuanchao Liang * raise the Software Generated Interrupt corresponding to the interrupt ID, 7426ed70ecSGuanchao Liang * the cpu_mask represents which cpu interface to forward. 7526ed70ecSGuanchao Liang */ 7626ed70ecSGuanchao Liang void itr_raise_sgi(size_t it, uint8_t cpu_mask); 7726ed70ecSGuanchao Liang /* 7826ed70ecSGuanchao Liang * let corresponding interrupt forward to the cpu interface 7926ed70ecSGuanchao Liang * according to the cpu_mask. 8026ed70ecSGuanchao Liang */ 8126ed70ecSGuanchao Liang void itr_set_affinity(size_t it, uint8_t cpu_mask); 827315b7b4SJens Wiklander 83e9f46c74SJens Wiklander /* 84e9f46c74SJens Wiklander * __weak overridable function which is called when a secure interrupt is 85e9f46c74SJens Wiklander * received. The default function calls panic() immediately, platforms which 86e9f46c74SJens Wiklander * expects to receive secure interrupts should override this function. 87e9f46c74SJens Wiklander */ 88e9f46c74SJens Wiklander void itr_core_handler(void); 89e9f46c74SJens Wiklander 907315b7b4SJens Wiklander #endif /*__KERNEL_INTERRUPT_H*/ 91