forked from sifive/example-empty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplatform_info.c
213 lines (183 loc) · 5 KB
/
platform_info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* Copyright (c) 2014, Mentor Graphics Corporation. All rights reserved.
* Copyright (c) 2017 - 2018 Xilinx, Inc. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**************************************************************************
* FILE NAME
*
* platform_info.c
*
* DESCRIPTION
*
* This file define platform specific data and implements APIs to set
* platform specific information for OpenAMP.
*
**************************************************************************/
#include <openamp/remoteproc.h>
#include <openamp/rpmsg_virtio.h>
#include <metal/atomic.h>
#include <metal/device.h>
#include <metal/io.h>
#include <metal/irq.h>
#include <metal/sys.h>
#include "platform_info.h"
#include "rsc_table.h"
#include <metal/csr.h>
#define _rproc_wait() asm volatile("wfi")
/* processor operations for hil_proc for A9. It defines
* notification operation and remote processor management. */
extern struct remoteproc_ops sifive_u_proc_ops;
/* Remoteproc instance */
static struct remoteproc rproc_inst;
/* External functions */
extern int init_system(void);
extern void cleanup_system(void);
static struct remoteproc *
platform_create_proc(int proc_index, int rsc_index)
{
void *rsc_table;
int rsc_size;
int ret;
metal_phys_addr_t pa;
(void) proc_index;
rsc_table = get_resource_table(rsc_index, &rsc_size);
/* Initialize remoteproc instance */
if (!remoteproc_init(&rproc_inst, &sifive_u_proc_ops, NULL)) {
return NULL;
}
/*
* Mmap shared memories
* Or shall we constraint that they will be set as carved out
* in the resource table?
*/
/* mmap resource table */
pa = (metal_phys_addr_t)rsc_table;
(void *)remoteproc_mmap(&rproc_inst, &pa,
NULL, rsc_size,
(uintptr_t) NULL,
&rproc_inst.rsc_io);
/* mmap shared memory */
pa = SHARED_MEM_PA;
(void *)remoteproc_mmap(&rproc_inst, &pa,
NULL, SHARED_MEM_SIZE,
(uintptr_t) NULL,
NULL);
/* parse resource table to remoteproc */
ret = remoteproc_set_rsc_table(&rproc_inst, rsc_table, rsc_size);
if (ret) {
printf("Failed to intialize remoteproc ret =%d\r\n", ret);
remoteproc_remove(&rproc_inst);
return NULL;
}
printf("Initialize remoteproc successfully.\r\n");
return &rproc_inst;
}
int platform_init(int argc, char *argv[], void **platform)
{
unsigned long proc_id = 0;
unsigned long rsc_id = 0;
struct remoteproc *rproc;
if (!platform) {
printf("Failed to initialize platform,"
"NULL pointer to store platform data.\r\n");
return -EINVAL;
}
/* Initialize HW system components */
init_system();
if (argc >= 2) {
proc_id = strtoul(argv[1], NULL, 0);
}
if (argc >= 3) {
rsc_id = strtoul(argv[2], NULL, 0);
}
rproc = platform_create_proc(proc_id, rsc_id);
if (!rproc) {
printf("Failed to create remoteproc device.\r\n");
return -EINVAL;
}
*platform = rproc;
return 0;
}
/* RPMsg virtio shared buffer pool */
static struct rpmsg_virtio_shm_pool shpool;
struct rpmsg_device *
platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index,
unsigned int role,
void (*rst_cb)(struct virtio_device *vdev),
rpmsg_ns_bind_cb ns_bind_cb)
{
struct remoteproc *rproc = platform;
struct rpmsg_virtio_device *rpmsg_vdev;
struct virtio_device *vdev;
void *shbuf;
struct metal_io_region *shbuf_io;
int ret;
rpmsg_vdev = metal_allocate_memory(sizeof(*rpmsg_vdev));
if (!rpmsg_vdev) {
printf("rpmsg_vdev after malloc is %x\n", rpmsg_vdev);
return NULL;
}
shbuf_io = remoteproc_get_io_with_pa(rproc, SHARED_MEM_PA);
if (!shbuf_io)
return NULL;
shbuf = metal_io_phys_to_virt(shbuf_io,
SHARED_MEM_PA + SHARED_BUF_OFFSET);
printf("creating remoteproc virtio\r\n");
/* TODO: can we have a wrapper for the following two functions? */
vdev = remoteproc_create_virtio(rproc, vdev_index, role, rst_cb);
if (!vdev) {
printf("failed remoteproc_create_virtio\r\n");
goto err1;
}
printf("initializing rpmsg vdev\r\n");
if (role == VIRTIO_DEV_MASTER) {
/* Only RPMsg virtio master needs to initialize the
* shared buffers pool
*/
rpmsg_virtio_init_shm_pool(&shpool, shbuf,
(SHARED_MEM_SIZE -
SHARED_BUF_OFFSET));
/* RPMsg virtio slave can set shared buffers pool
* argument to NULL
*/
ret = rpmsg_init_vdev(rpmsg_vdev, vdev, ns_bind_cb,
shbuf_io, &shpool);
} else {
ret = rpmsg_init_vdev(rpmsg_vdev, vdev, ns_bind_cb,
shbuf_io, NULL);
}
if (ret) {
printf("failed rpmsg_init_vdev\r\n");
goto err2;
}
printf("initializing rpmsg vdev\r\n");
return rpmsg_virtio_get_rpmsg_device(rpmsg_vdev);
err2:
remoteproc_remove_virtio(rproc, vdev);
err1:
metal_free_memory(rpmsg_vdev);
return NULL;
}
int platform_poll(void *priv)
{
struct remoteproc *rproc = priv;
while(1) {
remoteproc_get_notification(rproc, RSC_NOTIFY_ID_ANY);
break;
// _rproc_wait();
}
return 0;
}
void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev)
{
(void)rpdev;
}
void platform_cleanup(void *platform)
{
struct remoteproc *rproc = platform;
if (rproc)
remoteproc_remove(rproc);
cleanup_system();
}