xref: /optee_os/core/include/kernel/interrupt.h (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1*1bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
27315b7b4SJens Wiklander /*
37315b7b4SJens Wiklander  * Copyright (c) 2016, Linaro Limited
47315b7b4SJens Wiklander  * All rights reserved.
57315b7b4SJens Wiklander  *
67315b7b4SJens Wiklander  * Redistribution and use in source and binary forms, with or without
77315b7b4SJens Wiklander  * modification, are permitted provided that the following conditions are met:
87315b7b4SJens Wiklander  *
97315b7b4SJens Wiklander  * 1. Redistributions of source code must retain the above copyright notice,
107315b7b4SJens Wiklander  * this list of conditions and the following disclaimer.
117315b7b4SJens Wiklander  *
127315b7b4SJens Wiklander  * 2. Redistributions in binary form must reproduce the above copyright notice,
137315b7b4SJens Wiklander  * this list of conditions and the following disclaimer in the documentation
147315b7b4SJens Wiklander  * and/or other materials provided with the distribution.
157315b7b4SJens Wiklander  *
167315b7b4SJens Wiklander  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
177315b7b4SJens Wiklander  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
187315b7b4SJens Wiklander  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
197315b7b4SJens Wiklander  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
207315b7b4SJens Wiklander  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
217315b7b4SJens Wiklander  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
227315b7b4SJens Wiklander  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
237315b7b4SJens Wiklander  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
247315b7b4SJens Wiklander  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
257315b7b4SJens Wiklander  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
267315b7b4SJens Wiklander  * POSSIBILITY OF SUCH DAMAGE.
277315b7b4SJens Wiklander  */
287315b7b4SJens Wiklander #ifndef __KERNEL_INTERRUPT_H
297315b7b4SJens Wiklander #define __KERNEL_INTERRUPT_H
307315b7b4SJens Wiklander 
317315b7b4SJens Wiklander #include <types_ext.h>
327315b7b4SJens Wiklander #include <sys/queue.h>
337315b7b4SJens Wiklander 
347315b7b4SJens Wiklander #define ITRF_TRIGGER_LEVEL	(1 << 0)
357315b7b4SJens Wiklander 
367315b7b4SJens Wiklander struct itr_chip {
377315b7b4SJens Wiklander 	const struct itr_ops *ops;
387315b7b4SJens Wiklander };
397315b7b4SJens Wiklander 
407315b7b4SJens Wiklander struct itr_ops {
417315b7b4SJens Wiklander 	void (*add)(struct itr_chip *chip, size_t it, uint32_t flags);
427315b7b4SJens Wiklander 	void (*enable)(struct itr_chip *chip, size_t it);
437315b7b4SJens Wiklander 	void (*disable)(struct itr_chip *chip, size_t it);
4426ed70ecSGuanchao Liang 	void (*raise_pi)(struct itr_chip *chip, size_t it);
4526ed70ecSGuanchao Liang 	void (*raise_sgi)(struct itr_chip *chip, size_t it,
4626ed70ecSGuanchao Liang 		uint8_t cpu_mask);
4726ed70ecSGuanchao Liang 	void (*set_affinity)(struct itr_chip *chip, size_t it,
4826ed70ecSGuanchao Liang 		uint8_t cpu_mask);
497315b7b4SJens Wiklander };
507315b7b4SJens Wiklander 
517315b7b4SJens Wiklander enum itr_return {
527315b7b4SJens Wiklander 	ITRR_NONE,
537315b7b4SJens Wiklander 	ITRR_HANDLED,
547315b7b4SJens Wiklander };
557315b7b4SJens Wiklander 
567315b7b4SJens Wiklander struct itr_handler {
577315b7b4SJens Wiklander 	size_t it;
587315b7b4SJens Wiklander 	uint32_t flags;
597315b7b4SJens Wiklander 	enum itr_return (*handler)(struct itr_handler *h);
607315b7b4SJens Wiklander 	void *data;
617315b7b4SJens Wiklander 	SLIST_ENTRY(itr_handler) link;
627315b7b4SJens Wiklander };
637315b7b4SJens Wiklander 
647315b7b4SJens Wiklander void itr_init(struct itr_chip *data);
657315b7b4SJens Wiklander void itr_handle(size_t it);
667315b7b4SJens Wiklander 
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 
837315b7b4SJens Wiklander #endif /*__KERNEL_INTERRUPT_H*/
84