1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2021 Western Digital Corporation or its affiliates. 4 * Copyright (c) 2022 Ventana Micro Systems Inc. 5 * Copyright (c) 2025 Beijing Institute of Open Source Chip (BOSC) 6 * 7 * Authors: 8 * Anup Patel <anup.patel@wdc.com> 9 * Huang Borong <huangborong@bosc.ac.cn> 10 */ 11 12 #ifndef __DRIVERS_IMSIC_H 13 #define __DRIVERS_IMSIC_H 14 15 #include <kernel/interrupt.h> 16 #include <tee_api_defines.h> 17 #include <types_ext.h> 18 19 /* 20 * struct imsic_data - IMISC interrupt controller 21 * @imsic_base: Base address of the interrupt file 22 * @size: Size of the interrupt file in bytes 23 * @targets_mmode: Indicates if IMSIC targets Machine mode (true) or not (false) 24 * @num_ids: Number of interrupt identities supported by an interrupt file 25 * @guest_index_bits: Number of guest index bits in the MSI target address 26 * @hart_index_bits: Number of hart index bits in the MSI target address 27 * @group_index_bits: Number of group index bits in the MSI target address 28 * @group_index_shift: Number of bits to shift the group index 29 * @aplic_chip: Pointer to the associated APLIC's itr_chip 30 * @chip: Interrupt controller base class 31 */ 32 struct imsic_data { 33 vaddr_t imsic_base; 34 uint32_t size; 35 bool targets_mmode; 36 uint32_t num_ids; 37 uint32_t guest_index_bits; 38 uint32_t hart_index_bits; 39 uint32_t group_index_bits; 40 uint32_t group_index_shift; 41 struct itr_chip *aplic_chip; 42 struct itr_chip chip; 43 }; 44 45 /* 46 * The imsic_init() function initializes the struct imsic_data which 47 * is then used by other functions. This function also initializes 48 * the IMSIC and should only be called from the primary boot hart. 49 */ 50 void imsic_init(paddr_t imsic_base_pa); 51 52 /* 53 * Does per-hart specific IMSIC initialization, should be called by all 54 * secondary harts when booting. 55 */ 56 void imsic_init_per_hart(void); 57 58 /* Handle external interrupts */ 59 void imsic_it_handle(void); 60 61 /* Print IMSIC state to console */ 62 void imsic_dump_state(void); 63 64 #if defined(CFG_DT) && defined(CFG_RISCV_IMSIC) 65 /* 66 * imisc_parse_fdt_node() - Parse the IMSIC node from the device tree 67 * 68 * @fdt: Device tree to work on 69 * @nodeoff: Offset of the node in the device tree 70 * @imsic: Pointer to an imsic_data structure to store parsed information 71 * 72 * Returns TEE_Result value 73 */ 74 TEE_Result imisc_parse_fdt_node(const void *fdt, int nodeoff, 75 struct imsic_data *imsic); 76 #else 77 static inline TEE_Result imisc_parse_fdt_node(const void * fdt __unused,int nodeoff __unused,struct imsic_data * imsic __unused)78imisc_parse_fdt_node(const void *fdt __unused, 79 int nodeoff __unused, struct imsic_data *imsic __unused) 80 { 81 return TEE_ERROR_NOT_SUPPORTED; 82 } 83 #endif 84 85 #endif /* __DRIVERS_IMSIC_H */ 86