]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/open-amp.git/blob - lib/remoteproc/drivers/zynqmp_remoteproc_a53.c
zynqmp: drivers use platform_isr instead of hil_isr
[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                 platform_isr(vect_id, data);
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         struct ipi_info *chn_ipi_info =
116             (struct ipi_info *)(vring_hw->intr_info.data);
117         unsigned int ipi_base_addr = chn_ipi_info->ipi_base_addr;
119         if (vring_hw->intr_info.vect_id == 0xFFFFFFFF) {
120                 return 0;
121         }
123         /* Register ISR */
124         env_register_isr_shared(vring_hw->intr_info.vect_id,
125                          vring_hw, _ipi_handler, "remoteproc_a53", 1);
126         /* Enable IPI interrupt */
127         env_enable_interrupt(vring_hw->intr_info.vect_id,
128                              vring_hw->intr_info.priority,
129                              vring_hw->intr_info.trigger_type);
130         HIL_MEM_WRITE32((ipi_base_addr + IPI_IER_OFFSET),
131                 chn_ipi_info->ipi_chn_mask);
132         return 0;
135 /* In case there is an interrupt received after deinit. */
136 void _reg_ipi_after_deinit(struct proc_vring *vring_hw)
138         struct ipi_info *chn_ipi_info =
139             (struct ipi_info *)(vring_hw->intr_info.data);
141         if (vring_hw->intr_info.vect_id == 0xFFFFFFFF)
142                 return;
143         saved_ipi_info.ipi_base_addr = chn_ipi_info->ipi_base_addr;
144         saved_ipi_info.ipi_chn_mask = chn_ipi_info->ipi_chn_mask;
146         env_update_isr(vring_hw->intr_info.vect_id, &saved_ipi_info,
147                     _ipi_handler_deinit,
148                     "remoteproc_a53", 1);
151 void _notify(int cpu_id, struct proc_intr *intr_info)
154         (void)cpu_id;
155         struct ipi_info *chn_ipi_info = (struct ipi_info *)(intr_info->data);
156         if (chn_ipi_info == NULL)
157                 return;
158         platform_dcache_all_flush();
159         env_wmb();
160         /* Trigger IPI */
161         HIL_MEM_WRITE32((chn_ipi_info->ipi_base_addr + IPI_TRIG_OFFSET),
162                         chn_ipi_info->ipi_chn_mask);
165 int _boot_cpu(int cpu_id, unsigned int load_addr)
167         (void)cpu_id;
168         (void)load_addr;
169         return -1;
172 void _shutdown_cpu(int cpu_id)
174         (void)cpu_id;
175         return;
178 /**
179  * platform_get_processor_info
180  *
181  * Copies the target info from the user defined data structures to
182  * HIL proc  data structure.In case of remote contexts this function
183  * is called with the reserved CPU ID HIL_RSVD_CPU_ID, because for
184  * remotes there is only one master.
185  *
186  * @param proc   - HIL proc to populate
187  * @param cpu_id - CPU ID
188  *
189  * return  - status of execution
190  */
191 int platform_get_processor_info(struct hil_proc *proc , int cpu_id)
193         int idx;
194         for(idx = 0; idx < proc_table_size; idx++) {
195                 if((cpu_id == HIL_RSVD_CPU_ID) || (proc_table[idx].cpu_id == cpu_id) ) {
196                         env_memcpy(proc,&proc_table[idx], sizeof(struct hil_proc));
197                         return 0;
198                 }
199         }
200         return -1;
203 int platform_get_processor_for_fw(char *fw_name)
205         (void)fw_name;
206         return 1;