|
@ -52,11 +52,20 @@ |
|
|
|
|
|
|
|
|
#if MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE |
|
|
#if MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE |
|
|
#define VIRTIO_DEV_ID 0xFF |
|
|
#define VIRTIO_DEV_ID 0xFF |
|
|
|
|
|
#if MICROPY_PY_OPENAMP_HOST |
|
|
|
|
|
#define VIRTIO_DEV_ROLE RPMSG_HOST |
|
|
|
|
|
#else |
|
|
|
|
|
#define VIRTIO_DEV_ROLE RPMSG_REMOTE |
|
|
|
|
|
#endif // MICROPY_PY_OPENAMP_HOST
|
|
|
#define VIRTIO_DEV_FEATURES (1 << VIRTIO_RPMSG_F_NS) |
|
|
#define VIRTIO_DEV_FEATURES (1 << VIRTIO_RPMSG_F_NS) |
|
|
|
|
|
|
|
|
#define VRING0_ID 0 // VRING0 ID (host to remote) fixed to 0 for linux compatibility
|
|
|
#define VRING0_ID 0 // VRING0 ID (host to remote) fixed to 0 for linux compatibility
|
|
|
#define VRING1_ID 1 // VRING1 ID (remote to host) fixed to 1 for linux compatibility
|
|
|
#define VRING1_ID 1 // VRING1 ID (remote to host) fixed to 1 for linux compatibility
|
|
|
|
|
|
#if MICROPY_PY_OPENAMP_HOST |
|
|
#define VRING_NOTIFY_ID VRING0_ID |
|
|
#define VRING_NOTIFY_ID VRING0_ID |
|
|
|
|
|
#else |
|
|
|
|
|
#define VRING_NOTIFY_ID VRING1_ID |
|
|
|
|
|
#endif // MICROPY_PY_OPENAMP_HOST
|
|
|
|
|
|
|
|
|
#define VRING_COUNT 2 |
|
|
#define VRING_COUNT 2 |
|
|
#define VRING_ALIGNMENT 32 |
|
|
#define VRING_ALIGNMENT 32 |
|
@ -71,13 +80,15 @@ |
|
|
#define VRING_BUFF_ADDR (METAL_SHM_ADDR + 0x2000) |
|
|
#define VRING_BUFF_ADDR (METAL_SHM_ADDR + 0x2000) |
|
|
#define VRING_BUFF_SIZE (METAL_SHM_SIZE - 0x2000) |
|
|
#define VRING_BUFF_SIZE (METAL_SHM_SIZE - 0x2000) |
|
|
|
|
|
|
|
|
|
|
|
#if MICROPY_PY_OPENAMP_HOST |
|
|
static const char openamp_trace_buf[128]; |
|
|
static const char openamp_trace_buf[128]; |
|
|
#define MICROPY_PY_OPENAMP_TRACE_BUF ((uint32_t)openamp_trace_buf) |
|
|
#define MICROPY_PY_OPENAMP_TRACE_BUF ((uint32_t)openamp_trace_buf) |
|
|
#define MICROPY_PY_OPENAMP_TRACE_BUF_LEN sizeof(MICROPY_PY_OPENAMP_TRACE_BUF) |
|
|
#define MICROPY_PY_OPENAMP_TRACE_BUF_LEN sizeof(MICROPY_PY_OPENAMP_TRACE_BUF) |
|
|
|
|
|
#endif // MICROPY_PY_OPENAMP_HOST
|
|
|
|
|
|
|
|
|
#endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE
|
|
|
#endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE
|
|
|
|
|
|
|
|
|
#if MICROPY_PY_OPENAMP_REMOTEPROC |
|
|
#if MICROPY_PY_OPENAMP_HOST && MICROPY_PY_OPENAMP_REMOTEPROC |
|
|
extern mp_obj_type_t openamp_remoteproc_type; |
|
|
extern mp_obj_type_t openamp_remoteproc_type; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
@ -267,12 +278,11 @@ static void openamp_ns_callback(struct rpmsg_device *rdev, const char *name, uin |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE |
|
|
#if MICROPY_PY_OPENAMP_HOST && MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE |
|
|
// The shared resource table must be initialized manually by the host here,
|
|
|
// The shared resource table must be initialized manually by the host here,
|
|
|
// because it's not located in the data region, so the startup code doesn't
|
|
|
// because it's not located in the data region, so the startup code doesn't
|
|
|
// know about it.
|
|
|
// know about it.
|
|
|
static void openamp_rsc_table_init(openamp_rsc_table_t **rsc_table_out) { |
|
|
static void openamp_rsc_table_init(openamp_rsc_table_t *rsc_table) { |
|
|
openamp_rsc_table_t *rsc_table = METAL_RSC_ADDR; |
|
|
|
|
|
memset(rsc_table, 0, METAL_RSC_SIZE); |
|
|
memset(rsc_table, 0, METAL_RSC_SIZE); |
|
|
|
|
|
|
|
|
rsc_table->version = 1; |
|
|
rsc_table->version = 1; |
|
@ -299,9 +309,8 @@ static void openamp_rsc_table_init(openamp_rsc_table_t **rsc_table_out) { |
|
|
// Flush resource table.
|
|
|
// Flush resource table.
|
|
|
metal_cache_flush((uint32_t *)rsc_table, sizeof(openamp_rsc_table_t)); |
|
|
metal_cache_flush((uint32_t *)rsc_table, sizeof(openamp_rsc_table_t)); |
|
|
#endif |
|
|
#endif |
|
|
*rsc_table_out = rsc_table; |
|
|
|
|
|
} |
|
|
} |
|
|
#endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE
|
|
|
#endif // MICROPY_PY_OPENAMP_HOST && MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE
|
|
|
|
|
|
|
|
|
static mp_obj_t openamp_new_service_callback(mp_obj_t ns_callback) { |
|
|
static mp_obj_t openamp_new_service_callback(mp_obj_t ns_callback) { |
|
|
if (MP_STATE_PORT(virtio_device) == NULL) { |
|
|
if (MP_STATE_PORT(virtio_device) == NULL) { |
|
@ -342,8 +351,10 @@ void openamp_init(void) { |
|
|
metal_init(&metal_params); |
|
|
metal_init(&metal_params); |
|
|
|
|
|
|
|
|
// Initialize the shared resource table.
|
|
|
// Initialize the shared resource table.
|
|
|
openamp_rsc_table_t *rsc_table; |
|
|
openamp_rsc_table_t *rsc_table = METAL_RSC_ADDR; |
|
|
openamp_rsc_table_init(&rsc_table); |
|
|
#if MICROPY_PY_OPENAMP_HOST |
|
|
|
|
|
openamp_rsc_table_init(rsc_table); |
|
|
|
|
|
#endif // MICROPY_PY_OPENAMP_HOST
|
|
|
|
|
|
|
|
|
if (metal_register_generic_device(&shm_device) != 0) { |
|
|
if (metal_register_generic_device(&shm_device) != 0) { |
|
|
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to register metal device")); |
|
|
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to register metal device")); |
|
@ -368,7 +379,7 @@ void openamp_init(void) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Create virtio device.
|
|
|
// Create virtio device.
|
|
|
struct virtio_device *vdev = rproc_virtio_create_vdev(RPMSG_HOST, VIRTIO_DEV_ID, |
|
|
struct virtio_device *vdev = rproc_virtio_create_vdev(VIRTIO_DEV_ROLE, VIRTIO_DEV_ID, |
|
|
&rsc_table->vdev, rsc_io, NULL, metal_rproc_notify, NULL); |
|
|
&rsc_table->vdev, rsc_io, NULL, metal_rproc_notify, NULL); |
|
|
if (vdev == NULL) { |
|
|
if (vdev == NULL) { |
|
|
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to create virtio device")); |
|
|
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to create virtio device")); |
|
@ -389,8 +400,8 @@ void openamp_init(void) { |
|
|
// The remote processor detects that the virtio device is ready by polling
|
|
|
// The remote processor detects that the virtio device is ready by polling
|
|
|
// the status field in the resource table.
|
|
|
// the status field in the resource table.
|
|
|
rpmsg_virtio_init_shm_pool(&virtio_device->shm_pool, (void *)VRING_BUFF_ADDR, (size_t)VRING_BUFF_SIZE); |
|
|
rpmsg_virtio_init_shm_pool(&virtio_device->shm_pool, (void *)VRING_BUFF_ADDR, (size_t)VRING_BUFF_SIZE); |
|
|
rpmsg_init_vdev(&virtio_device->rvdev, vdev, openamp_ns_callback, shm_io, &virtio_device->shm_pool); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rpmsg_init_vdev(&virtio_device->rvdev, vdev, openamp_ns_callback, shm_io, &virtio_device->shm_pool); |
|
|
MP_STATE_PORT(virtio_device) = virtio_device; |
|
|
MP_STATE_PORT(virtio_device) = virtio_device; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -399,7 +410,7 @@ static const mp_rom_map_elem_t globals_dict_table[] = { |
|
|
{ MP_ROM_QSTR(MP_QSTR_ENDPOINT_ADDR_ANY), MP_ROM_INT(RPMSG_ADDR_ANY) }, |
|
|
{ MP_ROM_QSTR(MP_QSTR_ENDPOINT_ADDR_ANY), MP_ROM_INT(RPMSG_ADDR_ANY) }, |
|
|
{ MP_ROM_QSTR(MP_QSTR_new_service_callback), MP_ROM_PTR(&openamp_new_service_callback_obj) }, |
|
|
{ MP_ROM_QSTR(MP_QSTR_new_service_callback), MP_ROM_PTR(&openamp_new_service_callback_obj) }, |
|
|
{ MP_ROM_QSTR(MP_QSTR_Endpoint), MP_ROM_PTR(&endpoint_type) }, |
|
|
{ MP_ROM_QSTR(MP_QSTR_Endpoint), MP_ROM_PTR(&endpoint_type) }, |
|
|
#if MICROPY_PY_OPENAMP_REMOTEPROC |
|
|
#if MICROPY_PY_OPENAMP_HOST && MICROPY_PY_OPENAMP_REMOTEPROC |
|
|
{ MP_ROM_QSTR(MP_QSTR_RemoteProc), MP_ROM_PTR(&openamp_remoteproc_type) }, |
|
|
{ MP_ROM_QSTR(MP_QSTR_RemoteProc), MP_ROM_PTR(&openamp_remoteproc_type) }, |
|
|
#endif |
|
|
#endif |
|
|
}; |
|
|
}; |
|
|