9e32a125e23e1b7e87f03fa792a46d699f5f4806
1 /*
2 * Copyright (c) 2014, Mentor Graphics Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. Neither the name of Mentor Graphics Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
30 /**************************************************************************
31 * FILE NAME
32 *
33 * platform_info.c
34 *
35 * DESCRIPTION
36 *
37 * This file implements APIs to get platform specific
38 * information for OpenAMP.
39 *
40 **************************************************************************/
42 #include <string.h>
43 #include "openamp/hil.h"
45 /* Reference implementation that show cases platform_get_cpu_info and
46 platform_get_for_firmware API implementation for Bare metal environment */
48 extern struct hil_platform_ops proc_ops;
50 /* IPC Device parameters */
51 #define SHM_ADDR (void *)0x08008000
52 #define SHM_SIZE 0x00200000
53 #define VRING0_IPI_VECT 15
54 #define VRING1_IPI_VECT 14
55 #define MASTER_CPU_ID 0
56 #define REMOTE_CPU_ID 1
58 /**
59 * This array provdes defnition of CPU nodes for master and remote
60 * context. It contains two nodes beacuse the same file is intended
61 * to use with both master and remote configurations. On zynq platform
62 * only one node defintion is required for master/remote as there
63 * are only two cores present in the platform.
64 *
65 * Only platform specific info is populated here. Rest of information
66 * is obtained during resource table parsing.The platform specific
67 * information includes;
68 *
69 * -CPU ID
70 * -Shared Memory
71 * -Interrupts
72 * -Channel info.
73 *
74 * Although the channel info is not platform specific information
75 * but it is conveneient to keep it in HIL so that user can easily
76 * provide it without modifying the generic part.
77 *
78 * It is good idea to define hil_proc structure with platform
79 * specific fields populated as this can be easily copied to hil_proc
80 * structure passed as parameter in platform_get_processor_info. The
81 * other option is to populate the required structures individually
82 * and copy them one by one to hil_proc structure in platform_get_processor_info
83 * function. The first option is adopted here.
84 *
85 *
86 * 1) First node in the array is intended for the remote contexts and it
87 * defines Master CPU ID, shared memory, interrupts info, number of channels
88 * and there names. This node defines only one channel
89 * "rpmsg-openamp-demo-channel".
90 *
91 * 2)Second node is required by the master and it defines remote CPU ID,
92 * shared memory and interrupts info. In general no channel info is required by the
93 * Master node, however in baremetal master and linux remote case the linux
94 * rpmsg bus driver behaves as master so the rpmsg driver on linux side still needs
95 * channel info. This information is not required by the masters for baremetal
96 * remotes.
97 *
98 */
99 struct hil_proc proc_table[] = {
101 /* CPU node for remote context */
102 {
103 /* CPU ID of master */
104 MASTER_CPU_ID,
106 /* Shared memory info - Last field is not used currently */
107 {
108 SHM_ADDR, SHM_SIZE, 0x00},
110 /* VirtIO device info */
111 {
112 /* Leave these three fields empty as these are obtained from rsc
113 * table.
114 */
115 0, 0, 0,
117 /* Vring info */
118 {
120 {
121 /* Provide only vring interrupts info here. Other fields are
122 * obtained from the resource table so leave them empty.
123 */
124 NULL, NULL, 0, 0,
125 {
126 VRING0_IPI_VECT, 0x1006, 1, NULL}
127 },
128 {
129 NULL, NULL, 0, 0,
130 {
131 VRING1_IPI_VECT, 0x1006, 1, NULL}
132 }
133 }
134 },
136 /* Number of RPMSG channels */
137 1,
139 /* RPMSG channel info - Only channel name is expected currently */
140 {
141 {"rpmsg-openamp-demo-channel"}
142 },
144 /* HIL platform ops table. */
145 &proc_ops,
147 /* Next three fields are for future use only */
148 0,
149 0,
150 NULL,
151 {NULL, NULL}
152 },
154 /* CPU node for remote context */
155 {
156 /* CPU ID of remote */
157 REMOTE_CPU_ID,
159 /* Shared memory info - Last field is not used currently */
160 {
161 SHM_ADDR, SHM_SIZE, 0x00},
163 /* VirtIO device info */
164 {
165 0, 0, 0,
166 {
167 {
168 /* Provide vring interrupts info here. Other fields are obtained
169 * from the rsc table so leave them empty.
170 */
171 NULL, NULL, 0, 0,
172 {
173 VRING0_IPI_VECT, 0x1006, 1}
174 },
175 {
176 NULL, NULL, 0, 0,
177 {
178 VRING1_IPI_VECT, 0x1006, 1}
179 }
180 }
181 },
183 /* Number of RPMSG channels */
184 1,
186 /* RPMSG channel info - Only channel name is expected currently */
187 {
188 {"rpmsg-openamp-demo-channel"}
189 },
191 /* HIL platform ops table. */
192 &proc_ops,
194 /* Next three fields are for future use only */
195 0,
196 0,
197 NULL,
198 {NULL, NULL}
199 }
200 };
202 /**
203 * platform_get_processor_info
204 *
205 * Copies the target info from the user defined data structures to
206 * HIL proc data structure.In case of remote contexts this function
207 * is called with the reserved CPU ID HIL_RSVD_CPU_ID, because for
208 * remotes there is only one master.
209 *
210 * @param proc - HIL proc to populate
211 * @param cpu_id - CPU ID
212 *
213 * return - status of execution
214 */
215 int platform_get_processor_info(struct hil_proc *proc, int cpu_id)
216 {
217 int idx;
218 for (idx = 0; idx < sizeof(proc_table) / sizeof(struct hil_proc); idx++) {
219 if ((cpu_id == HIL_RSVD_CPU_ID)
220 || (proc_table[idx].cpu_id == cpu_id)) {
221 memcpy(proc, &proc_table[idx],
222 sizeof(struct hil_proc));
223 return 0;
224 }
225 }
226 return -1;
227 }
229 int platform_get_processor_for_fw(char *fw_name)
230 {
232 return 1;
233 }