]> 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 remoteproc: cleanup IPI in the driver probe
[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 <string.h>
44 #include "openamp/hil.h"
45 #include "machine.h"
47 /* -- FIX ME: ipi info is to be defined -- */
48 struct ipi_info {
49         uint32_t ipi_base_addr;
50         uint32_t ipi_chn_mask;
51 };
53 /*--------------------------- Declare Functions ------------------------ */
54 static int _enable_interrupt(struct proc_vring *vring_hw);
55 static void _notify(int cpu_id, struct proc_intr *intr_info);
56 static int _boot_cpu(int cpu_id, unsigned int load_addr);
57 static void _shutdown_cpu(int cpu_id);
58 static struct hil_proc *_initialize(void *pdata, int cpu_id);
59 static void _release(struct hil_proc *proc);
61 static void _ipi_handler(int vect_id, void *data);
63 /*--------------------------- Globals ---------------------------------- */
64 struct hil_platform_ops zynqmp_r5_a53_proc_ops = {
65         .enable_interrupt     = _enable_interrupt,
66         .notify               = _notify,
67         .boot_cpu             = _boot_cpu,
68         .shutdown_cpu         = _shutdown_cpu,
69         .initialize    = _initialize,
70         .release    = _release,
71 };
73 /* Extern functions defined out from OpenAMP lib */
74 extern void ipi_enable_interrupt(unsigned int vector);
75 extern void ipi_isr(int vect_id, void *data);
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 static int _enable_interrupt(struct proc_vring *vring_hw)
99 {
100         struct ipi_info *chn_ipi_info =
101             (struct ipi_info *)(vring_hw->intr_info.data);
102         unsigned int ipi_base_addr = chn_ipi_info->ipi_base_addr;
104         if (vring_hw->intr_info.vect_id == 0xFFFFFFFF) {
105                 return 0;
106         }
108         /* Register ISR */
109         env_register_isr_shared(vring_hw->intr_info.vect_id,
110                          vring_hw, _ipi_handler, "remoteproc_a53", 1);
111         /* Enable IPI interrupt */
112         env_enable_interrupt(vring_hw->intr_info.vect_id,
113                              vring_hw->intr_info.priority,
114                              vring_hw->intr_info.trigger_type);
115         HIL_MEM_WRITE32((ipi_base_addr + IPI_IER_OFFSET),
116                 chn_ipi_info->ipi_chn_mask);
117         return 0;
120 static void _notify(int cpu_id, struct proc_intr *intr_info)
123         (void)cpu_id;
124         struct ipi_info *chn_ipi_info = (struct ipi_info *)(intr_info->data);
125         if (chn_ipi_info == NULL)
126                 return;
127         platform_dcache_all_flush();
129         /* Trigger IPI */
130         HIL_MEM_WRITE32((chn_ipi_info->ipi_base_addr + IPI_TRIG_OFFSET),
131                         chn_ipi_info->ipi_chn_mask);
134 static int _boot_cpu(int cpu_id, unsigned int load_addr)
136         (void)cpu_id;
137         (void)load_addr;
138         return -1;
141 static void _shutdown_cpu(int cpu_id)
143         (void)cpu_id;
144         return;
147 static struct hil_proc * _initialize(void *pdata, int cpu_id)
149         (void) cpu_id;
151         struct hil_proc *proc;
152         struct ipi_info *chn_ipi_info;
153         unsigned int ipi_base_addr;
154         unsigned int ipi_intr_status;
156         /* Allocate memory for proc instance */
157         proc = env_allocate_memory(sizeof(struct hil_proc));
158         if (!proc) {
159                 return NULL;
160         }
162         memcpy(proc, pdata, sizeof(struct hil_proc));
163         chn_ipi_info =
164                 (struct ipi_info *)&proc->vdev.vring_info[1];
165         ipi_base_addr = chn_ipi_info->ipi_base_addr;
166         ipi_intr_status =
167             (unsigned int)HIL_MEM_READ32(ipi_base_addr + IPI_ISR_OFFSET);
168         if (ipi_intr_status & chn_ipi_info->ipi_chn_mask) {
169                 HIL_MEM_WRITE32((ipi_base_addr + IPI_ISR_OFFSET),
170                                 chn_ipi_info->ipi_chn_mask);
171         }
172         /* Enable mapping for the shared memory region */
173         if (proc->sh_buff.size)
174                 env_map_memory((unsigned int)proc->sh_buff.start_addr,
175                             (unsigned int)proc->sh_buff.start_addr,
176                             proc->sh_buff.size, (SHARED_MEM | UNCACHED));
177         return proc;
180 static void _release(struct hil_proc *proc)
182         env_free_memory(proc);