764c384c58f6ac6c0d30d3d5ecd58672702d1195
[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 platform_isr(int vect_id, void *data);
58 static void _reg_ipi_after_deinit(struct proc_vring *vring_hw);
60 /*--------------------------- Globals ---------------------------------- */
61 struct hil_platform_ops proc_ops = {
62         .enable_interrupt = _enable_interrupt,
63         .reg_ipi_after_deinit = _reg_ipi_after_deinit,
64         .notify = _notify,
65         .boot_cpu = _boot_cpu,
66         .shutdown_cpu = _shutdown_cpu,
67 };
69 /* Extern functions defined out from OpenAMP lib */
70 extern void ipi_enable_interrupt(unsigned int vector);
71 extern void ipi_isr(int vect_id, void *data);
73 /*------------------- Extern variable -----------------------------------*/
74 extern struct hil_proc proc_table[];
75 extern const int proc_table_size;
77 extern void ipi_register_interrupt(unsigned long ipi_base_addr,
78                                    unsigned int intr_mask, void *data,
79                                    void *ipi_handler);
81 void _ipi_handler(unsigned long ipi_base_addr, unsigned int intr_mask,
82                   void *data)
83 {
84         (void)ipi_base_addr;
85         (void)intr_mask;
86         struct proc_vring *vring_hw = (struct proc_vring *)data;
87         platform_dcache_all_flush();
88         hil_isr(vring_hw);
89 }
91 void _ipi_handler_deinit(unsigned long ipi_base_addr, unsigned int intr_mask,
92                          void *data)
93 {
94         (void)ipi_base_addr;
95         (void)intr_mask;
96         (void)data;
97         return;
98 }
100 int _enable_interrupt(struct proc_vring *vring_hw)
103         struct ipi_info *chn_ipi_info =
104             (struct ipi_info *)(vring_hw->intr_info.data);
106         if (vring_hw->intr_info.vect_id == 0xFFFFFFFF)
107                 return 0;
108         /* Register IPI handler */
109         ipi_register_handler(chn_ipi_info->ipi_base_addr,
110                              chn_ipi_info->ipi_chn_mask, vring_hw,
111                              _ipi_handler);
112         /* Register ISR */
113         env_register_isr(vring_hw->intr_info.vect_id,
114                          &(chn_ipi_info->ipi_base_addr), ipi_isr);
115         /* Enable IPI interrupt */
116         env_enable_interrupt(vring_hw->intr_info.vect_id,
117                              vring_hw->intr_info.priority,
118                              vring_hw->intr_info.trigger_type);
119         return 0;
122 void _reg_ipi_after_deinit(struct proc_vring *vring_hw)
124         struct ipi_info *chn_ipi_info =
125             (struct ipi_info *)(vring_hw->intr_info.data);
126         env_disable_interrupts();
127         ipi_register_handler(chn_ipi_info->ipi_base_addr,
128                              chn_ipi_info->ipi_chn_mask, 0,
129                              _ipi_handler_deinit);
130         env_restore_interrupts();
133 void _notify(int cpu_id, struct proc_intr *intr_info)
136         (void)cpu_id;
137         struct ipi_info *chn_ipi_info = (struct ipi_info *)(intr_info->data);
138         if (chn_ipi_info == NULL)
139                 return;
140         platform_dcache_all_flush();
141         env_wmb();
142         /* Trigger IPI */
143         ipi_trigger(chn_ipi_info->ipi_base_addr, chn_ipi_info->ipi_chn_mask);
146 int _boot_cpu(int cpu_id, unsigned int load_addr)
148         (void)cpu_id;
149         (void)load_addr;
150         return -1;
153 void _shutdown_cpu(int cpu_id)
155         (void)cpu_id;
156         return;
159 /**
160  * platform_get_processor_info
161  *
162  * Copies the target info from the user defined data structures to
163  * HIL proc  data structure.In case of remote contexts this function
164  * is called with the reserved CPU ID HIL_RSVD_CPU_ID, because for
165  * remotes there is only one master.
166  *
167  * @param proc   - HIL proc to populate
168  * @param cpu_id - CPU ID
169  *
170  * return  - status of execution
171  */
172 int platform_get_processor_info(struct hil_proc *proc , int cpu_id)
174         int idx;
175         for(idx = 0; idx < proc_table_size; idx++) {
176                 if((cpu_id == HIL_RSVD_CPU_ID) || (proc_table[idx].cpu_id == cpu_id) ) {
177                         env_memcpy(proc,&proc_table[idx], sizeof(struct hil_proc));
178                         return 0;
179                 }
180         }
181         return -1;
184 int platform_get_processor_for_fw(char *fw_name)
186         (void)fw_name;
187         return 1;