zynqmp_r5: remove IPI handler
[processor-sdk/open-amp.git] / lib / remoteproc / drivers / zynqmp_remoteproc_a53.c
1 /*
2  * Copyright (c) 2014, Mentor Graphics Corporation
3  * All rights reserved.
4  * Copyright (c) 2015 Xilinx, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  *    this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  * 3. Neither the name of Mentor Graphics Corporation nor the names of its
15  *    contributors may be used to endorse or promote products derived from this
16  *    software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
31 /**************************************************************************
32  * FILE NAME
33  *
34  *       platform.c
35  *
36  * DESCRIPTION
37  *
38  *       This file is the Implementation of IPC hardware layer interface
39  *       for Xilinx Zynq ZC702EVK platform.
40  *
41  **************************************************************************/
43 #include "openamp/hil.h"
44 #include "machine.h"
46 /* -- FIX ME: ipi info is to be defined -- */
47 struct ipi_info {
48         uint32_t ipi_base_addr;
49         uint32_t ipi_chn_mask;
50 };
52 /*--------------------------- Declare Functions ------------------------ */
53 static int _enable_interrupt(struct proc_vring *vring_hw);
54 static void _notify(int cpu_id, struct proc_intr *intr_info);
55 static int _boot_cpu(int cpu_id, unsigned int load_addr);
56 static void _shutdown_cpu(int cpu_id);
57 static void _ipi_handler(int vect_id, void *data);
58 static void _ipi_handler_deinit(int vect_id, void *data);
59 static void _reg_ipi_after_deinit(struct proc_vring *vring_hw);
61 /*--------------------------- Globals ---------------------------------- */
62 struct hil_platform_ops proc_ops = {
63         .enable_interrupt = _enable_interrupt,
64         .reg_ipi_after_deinit = _reg_ipi_after_deinit,
65         .notify = _notify,
66         .boot_cpu = _boot_cpu,
67         .shutdown_cpu = _shutdown_cpu,
68 };
70 /* Extern functions defined out from OpenAMP lib */
71 extern void ipi_enable_interrupt(unsigned int vector);
72 extern void ipi_isr(int vect_id, void *data);
74 /* static variables */
75 static struct ipi_info saved_ipi_info;
77 /*------------------- Extern variable -----------------------------------*/
78 extern struct hil_proc proc_table[];
79 extern const int proc_table_size;
81 void _ipi_handler(int vect_id, void *data)
82 {
83         (void) vect_id;
84         struct proc_vring *vring_hw = (struct proc_vring *)(data);
85         struct ipi_info *chn_ipi_info =
86                 (struct ipi_info *)(vring_hw->intr_info.data);
87         unsigned int ipi_base_addr = chn_ipi_info->ipi_base_addr;
88         unsigned int ipi_intr_status =
89             (unsigned int)HIL_MEM_READ32(ipi_base_addr + IPI_ISR_OFFSET);
90         if (ipi_intr_status && chn_ipi_info->ipi_chn_mask) {
91                 platform_dcache_all_flush();
92                 hil_isr(vring_hw);
93                 HIL_MEM_WRITE32((ipi_base_addr + IPI_ISR_OFFSET),
94                                 chn_ipi_info->ipi_chn_mask);
95         }
96 }
98 void _ipi_handler_deinit(int vect_id, void *data)
99 {
100         (void) vect_id;
101         struct ipi_info *chn_ipi_info =
102                 (struct ipi_info *)(data);
103         unsigned int ipi_base_addr = chn_ipi_info->ipi_base_addr;
104         unsigned int ipi_intr_status =
105             (unsigned int)HIL_MEM_READ32(ipi_base_addr + IPI_ISR_OFFSET);
106         if (ipi_intr_status && chn_ipi_info->ipi_chn_mask) {
107                 HIL_MEM_WRITE32((ipi_base_addr + IPI_ISR_OFFSET),
108                                 chn_ipi_info->ipi_chn_mask);
109         }
110         return;
113 static int _enable_interrupt(struct proc_vring *vring_hw)
115         if (vring_hw->intr_info.vect_id == 0xFFFFFFFF)
116                 return 0;
118         /* Register ISR */
119         env_register_isr_shared(vring_hw->intr_info.vect_id,
120                          vring_hw, _ipi_handler, "remoteproc_a53", 1);
121         /* Enable IPI interrupt */
122         env_enable_interrupt(vring_hw->intr_info.vect_id,
123                              vring_hw->intr_info.priority,
124                              vring_hw->intr_info.trigger_type);
125         return 0;
128 /* In case there is an interrupt received after deinit. */
129 void _reg_ipi_after_deinit(struct proc_vring *vring_hw)
131         struct ipi_info *chn_ipi_info =
132             (struct ipi_info *)(vring_hw->intr_info.data);
134         if (vring_hw->intr_info.vect_id == 0xFFFFFFFF)
135                 return;
136         saved_ipi_info.ipi_base_addr = chn_ipi_info->ipi_base_addr;
137         saved_ipi_info.ipi_chn_mask = chn_ipi_info->ipi_chn_mask;
139         env_update_isr(vring_hw->intr_info.vect_id, &saved_ipi_info,
140                     _ipi_handler_deinit,
141                     "remoteproc_a53", 1);
144 void _notify(int cpu_id, struct proc_intr *intr_info)
147         (void)cpu_id;
148         struct ipi_info *chn_ipi_info = (struct ipi_info *)(intr_info->data);
149         if (chn_ipi_info == NULL)
150                 return;
151         platform_dcache_all_flush();
152         env_wmb();
153         /* Trigger IPI */
154         HIL_MEM_WRITE32((chn_ipi_info->ipi_base_addr + IPI_TRIG_OFFSET),
155                         chn_ipi_info->ipi_chn_mask);
158 int _boot_cpu(int cpu_id, unsigned int load_addr)
160         (void)cpu_id;
161         (void)load_addr;
162         return -1;
165 void _shutdown_cpu(int cpu_id)
167         (void)cpu_id;
168         return;
171 /**
172  * platform_get_processor_info
173  *
174  * Copies the target info from the user defined data structures to
175  * HIL proc  data structure.In case of remote contexts this function
176  * is called with the reserved CPU ID HIL_RSVD_CPU_ID, because for
177  * remotes there is only one master.
178  *
179  * @param proc   - HIL proc to populate
180  * @param cpu_id - CPU ID
181  *
182  * return  - status of execution
183  */
184 int platform_get_processor_info(struct hil_proc *proc , int cpu_id)
186         int idx;
187         for(idx = 0; idx < proc_table_size; idx++) {
188                 if((cpu_id == HIL_RSVD_CPU_ID) || (proc_table[idx].cpu_id == cpu_id) ) {
189                         env_memcpy(proc,&proc_table[idx], sizeof(struct hil_proc));
190                         return 0;
191                 }
192         }
193         return -1;
196 int platform_get_processor_for_fw(char *fw_name)
198         (void)fw_name;
199         return 1;