1 /*
2  * Copyright (c) 2015, Xilinx Inc. and Contributors. All rights reserved.
3  * Copyright (C) 2023, Advanced Micro Devices, Inc.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 /*
9  * @file	generic/xlnx/sys.h
10  * @brief	generic xlnx system primitives for libmetal.
11  */
12 
13 #ifndef __METAL_GENERIC_SYS__H__
14 #error "Include metal/sys.h instead of metal/generic/@PROJECT_MACHINE@/sys.h"
15 #endif
16 
17 #ifndef __MICROBLAZE__
18 #include "xscugic.h"
19 #endif
20 
21 #include <metal/assert.h>
22 #include <metal/io.h>
23 #include <metal/sys.h>
24 #include <stdint.h>
25 #include <metal/compiler.h>
26 #include <metal/utilities.h>
27 
28 #include <xil_cache.h>
29 #include <xil_exception.h>
30 #include <xparameters.h>
31 
32 #ifdef SDT
33 #include <metal/system/generic/xlnx/sys_devicetree.h>
34 #endif
35 
36 #ifndef __METAL_GENERIC_XLNX_SYS__H__
37 #define __METAL_GENERIC_XLNX_SYS__H__
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #ifndef __MICROBLAZE__
44 #define XLNX_MAXIRQS XSCUGIC_MAX_NUM_INTR_INPUTS
45 #endif
46 
47 #if defined(SDT) && !defined(__MICROBLAZE__)
48 #define XPAR_SCUGIC_0_DIST_BASEADDR XPAR_SCUGIC_DIST_BASEADDR
49 #endif
50 
51 /**
52  * @brief	metal_xlnx_irq_isr
53  *
54  * Xilinx interrupt ISR can be registered to the Xilinx embeddedsw
55  * IRQ controller driver.
56  *
57  * @param[in] arg input argument, interrupt vector id.
58  */
59 void metal_xlnx_irq_isr(void *arg);
60 
61 /**
62  * @brief	metal_xlnx_irq_int
63  *
64  * Xilinx interrupt controller initialization. It will initialize
65  * the metal Xilinx IRQ controller data structure.
66  *
67  * @return 0 for success, or negative value for failure
68  */
69 int metal_xlnx_irq_init(void);
70 
71 /* Microblaze defines these routines */
72 #ifdef __MICROBLAZE__
73 void metal_weak sys_irq_enable(unsigned int vector);
74 
75 void metal_weak sys_irq_disable(unsigned int vector);
76 #else
sys_irq_enable(unsigned int vector)77 static inline void sys_irq_enable(unsigned int vector)
78 {
79 	XScuGic_EnableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector);
80 }
81 
sys_irq_disable(unsigned int vector)82 static inline void sys_irq_disable(unsigned int vector)
83 {
84 	XScuGic_DisableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector);
85 }
86 #endif
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif /* __METAL_GENERIC_XLNX_SYS__H__ */
93