Skip to content

Commit 0e4dc26

Browse files
committed
STM32MP1xx: Add first OpenAMP middleware
1 parent aad5f34 commit 0e4dc26

File tree

473 files changed

+45827
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

473 files changed

+45827
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/**
2+
******************************************************************************
3+
* @file openamp_conf.h
4+
* @author MCD Application Team
5+
* @brief Configuration file for OpenAMP MW
6+
******************************************************************************
7+
* @attention
8+
*
9+
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10+
* All rights reserved.</center></h2>
11+
*
12+
* This software component is licensed by ST under BSD 3-Clause license,
13+
* the "License"; You may not use this file except in compliance with the
14+
* License. You may obtain a copy of the License at:
15+
* opensource.org/licenses/BSD-3-Clause
16+
*
17+
******************************************************************************
18+
*/
19+
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef __OPENAMP_CONF__H__
22+
#define __OPENAMP_CONF__H__
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/* Includes ------------------------------------------------------------------*/
29+
#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_)
30+
#include "log.h"
31+
#endif
32+
33+
/* ########################## Mailbox Interface Selection ############################## */
34+
/**
35+
* @brief This is the list of Mailbox interface to be used in the OpenAMP MW
36+
* Please note that not all interfaces are supported by a STM32 device
37+
*/
38+
//#define MAILBOX_IPCC_IF_ENABLED
39+
//#define MAILBOX_HSEM_IF_ENABLED
40+
41+
/* Includes ------------------------------------------------------------------*/
42+
/**
43+
* @brief Include Maibox interface header file
44+
*/
45+
46+
#ifdef MAILBOX_IPCC_IF_ENABLED
47+
#include "mbox_ipcc.h"
48+
#endif /* MAILBOX_IPCC_IF_ENABLED */
49+
50+
#ifdef MAILBOX_HSEM_IF_ENABLED
51+
#include "mbox_hsem.h"
52+
#endif /* MAILBOX_HSEM_IF_ENABLED */
53+
54+
/* ########################## Virtual Diver Module Selection ############################## */
55+
/**
56+
* @brief This is the list of modules to be used in the OpenAMP Virtual driver module
57+
* Please note that virtual driver are not supported on all stm32 families
58+
*/
59+
//#define VIRTUAL_UART_MODULE_ENABLED
60+
//#define VIRTUAL_I2C_MODULE_ENABLED
61+
62+
63+
/* Includes ------------------------------------------------------------------*/
64+
/**
65+
* @brief Include Virtual Driver module's header file
66+
*/
67+
68+
#ifdef VIRTUAL_UART_MODULE_ENABLED
69+
#include "virt_uart.h"
70+
#endif /* VIRTUAL_UART_MODULE_ENABLED */
71+
72+
#ifdef VIRTUAL_I2C_MODULE_ENABLED
73+
#include "virt_i2c.h"
74+
#endif /* VIRTUAL_I2C_MODULE_ENABLED */
75+
76+
77+
78+
/* USER CODE BEGIN INCLUDE */
79+
80+
/* USER CODE END INCLUDE */
81+
82+
/** @addtogroup OPENAMP_MW
83+
* @{
84+
*/
85+
86+
/** @defgroup OPENAMP_CONF OPENAMP_CONF
87+
* @brief Configuration file for Openamp mw
88+
* @{
89+
*/
90+
91+
/** @defgroup OPENAMP_CONF_Exported_Variables OPENAMP_CONF_Exported_Variables
92+
* @brief Public variables.
93+
* @{
94+
*/
95+
96+
/**
97+
* @}
98+
*/
99+
100+
/** @defgroup OPENAMP_CONF_Exported_Defines OPENAMP_CONF_Exported_Defines
101+
* @brief Defines for configuration of the Openamp mw
102+
* @{
103+
*/
104+
105+
extern int __OPENAMP_region_start__[]; /* defined by linker script */
106+
extern int __OPENAMP_region_end__[]; /* defined by linker script */
107+
108+
109+
#define SHM_START_ADDRESS ((metal_phys_addr_t)__OPENAMP_region_start__)
110+
#define SHM_SIZE (size_t)((void *)__OPENAMP_region_end__-(void *) __OPENAMP_region_start__)
111+
112+
#define VRING_RX_ADDRESS -1 /* allocated by Master processor: CA7 */
113+
#define VRING_TX_ADDRESS -1 /* allocated by Master processor: CA7 */
114+
#define VRING_BUFF_ADDRESS -1 /* allocated by Master processor: CA7 */
115+
#define VRING_ALIGNMENT 16 /* fixed to match with linux constraint */
116+
#define VRING_NUM_BUFFS 16 /* number of rpmsg buffer */
117+
118+
119+
/* Fixed parameter */
120+
#define NUM_RESOURCE_ENTRIES 2
121+
#define VRING_COUNT 2
122+
123+
#define VDEV_ID 0xFF
124+
#define VRING0_ID 0 /* VRING0 ID (master to remote) fixed to 0 for linux compatibility*/
125+
#define VRING1_ID 1 /* VRING1 ID (remote to master) fixed to 1 for linux compatibility */
126+
127+
/**
128+
* @}
129+
*/
130+
131+
/** @defgroup OPENAMP_CONF_Exported_Macros OPENAMP_CONF_Exported_Macros
132+
* @brief Aliases.
133+
* @{
134+
*/
135+
136+
/* DEBUG macros */
137+
138+
#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_)
139+
#define OPENAMP_log_dbg log_dbg
140+
#define OPENAMP_log_info log_info
141+
#define OPENAMP_log_warn log_warn
142+
#define OPENAMP_log_err log_err
143+
#else
144+
#define OPENAMP_log_dbg(...)
145+
#define OPENAMP_log_info(...)
146+
#define OPENAMP_log_warn(...)
147+
#define OPENAMP_log_err(...)
148+
#endif
149+
150+
/**
151+
* @}
152+
*/
153+
154+
/** @defgroup OPENAMP_CONF_Exported_Types OPENAMP_CONF_Exported_Types
155+
* @brief Types.
156+
* @{
157+
*/
158+
159+
/**
160+
* @}
161+
*/
162+
163+
/** @defgroup OPENAMP_CONF_Exported_FunctionsPrototype OPENAMP_CONF_Exported_FunctionsPrototype
164+
* @brief Declaration of public functions for OpenAMP mw.
165+
* @{
166+
*/
167+
168+
/* Exported functions -------------------------------------------------------*/
169+
170+
/**
171+
* @}
172+
*/
173+
174+
/**
175+
* @}
176+
*/
177+
178+
/**
179+
* @}
180+
*/
181+
182+
#ifdef __cplusplus
183+
}
184+
#endif
185+
186+
#endif /* __OPENAMP_CONF__H__ */
187+
188+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/**
2+
******************************************************************************
3+
* @file openamp.c
4+
* @author MCD Application Team
5+
* @brief Code for openamp applications
6+
******************************************************************************
7+
* @attention
8+
*
9+
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10+
* All rights reserved.</center></h2>
11+
*
12+
* This software component is licensed by ST under BSD 3-Clause license,
13+
* the "License"; You may not use this file except in compliance with the
14+
* License. You may obtain a copy of the License at:
15+
* opensource.org/licenses/BSD-3-Clause
16+
*
17+
******************************************************************************
18+
*/
19+
20+
#include "openamp.h"
21+
#include "rsc_table.h"
22+
#include "metal/sys.h"
23+
#include "metal/device.h"
24+
/* Private define ------------------------------------------------------------*/
25+
26+
#define SHM_DEVICE_NAME "STM32_SHM"
27+
28+
/* Globals */
29+
30+
static struct metal_io_region *shm_io;
31+
static struct metal_io_region *rsc_io;
32+
static struct shared_resource_table *rsc_table;
33+
static struct rpmsg_virtio_shm_pool shpool;
34+
static struct rpmsg_virtio_device rvdev;
35+
36+
37+
static metal_phys_addr_t shm_physmap;
38+
39+
struct metal_device shm_device = {
40+
.name = SHM_DEVICE_NAME,
41+
.num_regions = 2,
42+
.regions = {
43+
{.virt = NULL}, /* shared memory */
44+
{.virt = NULL}, /* rsc_table memory */
45+
},
46+
.node = { NULL },
47+
.irq_num = 0,
48+
.irq_info = NULL
49+
};
50+
51+
static int OPENAMP_shmem_init(int RPMsgRole)
52+
{
53+
int status = 0;
54+
struct metal_device *device;
55+
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
56+
void* rsc_tab_addr;
57+
int rsc_size;
58+
59+
metal_init(&metal_params);
60+
61+
status = metal_register_generic_device(&shm_device);
62+
if (status != 0) {
63+
return status;
64+
}
65+
66+
status = metal_device_open("generic", SHM_DEVICE_NAME, &device);
67+
if (status != 0) {
68+
return status;
69+
}
70+
71+
shm_physmap = SHM_START_ADDRESS;
72+
metal_io_init(&device->regions[0], (void *)SHM_START_ADDRESS, &shm_physmap,
73+
SHM_SIZE, -1, 0, NULL);
74+
75+
shm_io = metal_device_io_region(device, 0);
76+
if (shm_io == NULL) {
77+
return -1;
78+
}
79+
80+
/* Initialize resources table variables */
81+
resource_table_init(RPMsgRole, &rsc_tab_addr, &rsc_size);
82+
rsc_table = (struct shared_resource_table *)rsc_tab_addr;
83+
if (!rsc_table)
84+
{
85+
return -1;
86+
}
87+
88+
metal_io_init(&device->regions[1], rsc_table,
89+
(metal_phys_addr_t *)rsc_table, rsc_size, -1, 0, NULL);
90+
91+
rsc_io = metal_device_io_region(device, 1);
92+
if (rsc_io == NULL) {
93+
return -1;
94+
}
95+
96+
return 0;
97+
}
98+
99+
int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb)
100+
{
101+
struct fw_rsc_vdev_vring *vring_rsc;
102+
struct virtio_device *vdev;
103+
int status = 0;
104+
105+
MAILBOX_Init();
106+
107+
/* Libmetal Initilalization */
108+
status = OPENAMP_shmem_init(RPMsgRole);
109+
if(status)
110+
{
111+
return status;
112+
}
113+
114+
vdev = rproc_virtio_create_vdev(RPMsgRole, VDEV_ID, &rsc_table->vdev,
115+
rsc_io, NULL, MAILBOX_Notify, NULL);
116+
if (vdev == NULL)
117+
{
118+
return -1;
119+
}
120+
121+
rproc_virtio_wait_remote_ready(vdev);
122+
vring_rsc = &rsc_table->vring0;
123+
status = rproc_virtio_init_vring(vdev, 0, vring_rsc->notifyid,
124+
(void *)vring_rsc->da, shm_io,
125+
vring_rsc->num, vring_rsc->align);
126+
if (status != 0)
127+
{
128+
return status;
129+
}
130+
vring_rsc = &rsc_table->vring1;
131+
status = rproc_virtio_init_vring(vdev, 1, vring_rsc->notifyid,
132+
(void *)vring_rsc->da, shm_io,
133+
vring_rsc->num, vring_rsc->align);
134+
if (status != 0)
135+
{
136+
return status;
137+
}
138+
139+
rpmsg_virtio_init_shm_pool(&shpool, (void *)VRING_BUFF_ADDRESS,
140+
(size_t)SHM_SIZE);
141+
rpmsg_init_vdev(&rvdev, vdev, ns_bind_cb, shm_io, &shpool);
142+
143+
return 0;
144+
}
145+
146+
void OPENAMP_DeInit()
147+
{
148+
rpmsg_deinit_vdev(&rvdev);
149+
150+
metal_finish();
151+
}
152+
153+
void OPENAMP_init_ept(struct rpmsg_endpoint *ept)
154+
{
155+
rpmsg_init_ept(ept, "", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);
156+
}
157+
158+
int OPENAMP_create_endpoint(struct rpmsg_endpoint *ept, const char *name,
159+
uint32_t dest, rpmsg_ept_cb cb,
160+
rpmsg_ns_unbind_cb unbind_cb)
161+
{
162+
return rpmsg_create_ept(ept, &rvdev.rdev, name, RPMSG_ADDR_ANY, dest, cb,
163+
unbind_cb);
164+
}
165+
166+
void OPENAMP_check_for_message(void)
167+
{
168+
MAILBOX_Poll(rvdev.vdev);
169+
}
170+
171+
void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept)
172+
{
173+
while(!is_rpmsg_ept_ready(rp_ept))
174+
MAILBOX_Poll(rvdev.vdev);
175+
}
176+
177+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)