diff --git a/drivers/rpmsg/rpmsg.c b/drivers/rpmsg/rpmsg.c index 132cdb87fc..ed35105ad5 100644 --- a/drivers/rpmsg/rpmsg.c +++ b/drivers/rpmsg/rpmsg.c @@ -183,6 +183,24 @@ int rpmsg_post(FAR struct rpmsg_endpoint *ept, FAR sem_t *sem) return rpmsg->ops->post(rpmsg, sem); } +FAR const char *rpmsg_get_local_cpuname(FAR struct rpmsg_device *rdev) +{ + FAR struct rpmsg_s *rpmsg = rpmsg_get_by_rdev(rdev); + FAR const char *cpuname = NULL; + + if (rpmsg == NULL) + { + return NULL; + } + + if (rpmsg->ops->get_local_cpuname) + { + cpuname = rpmsg->ops->get_local_cpuname(rpmsg); + } + + return cpuname && cpuname[0] ? cpuname : CONFIG_RPMSG_LOCAL_CPUNAME; +} + FAR const char *rpmsg_get_cpuname(FAR struct rpmsg_device *rdev) { FAR struct rpmsg_s *rpmsg = rpmsg_get_by_rdev(rdev); diff --git a/drivers/rpmsg/rpmsg_port.c b/drivers/rpmsg/rpmsg_port.c index 75483c73c1..be8c6789b7 100644 --- a/drivers/rpmsg/rpmsg_port.c +++ b/drivers/rpmsg/rpmsg_port.c @@ -44,6 +44,8 @@ * Private Function Prototypes ****************************************************************************/ +static FAR const char * +rpmsg_port_get_local_cpuname(FAR struct rpmsg_s *rpmsg); static FAR const char *rpmsg_port_get_cpuname(FAR struct rpmsg_s *rpmsg); static int rpmsg_port_get_tx_buffer_size(FAR struct rpmsg_s *rpmsg); static int rpmsg_port_get_rx_buffer_size(FAR struct rpmsg_s *rpmsg); @@ -59,6 +61,7 @@ static const struct rpmsg_ops_s g_rpmsg_port_ops = NULL, NULL, NULL, + rpmsg_port_get_local_cpuname, rpmsg_port_get_cpuname, rpmsg_port_get_tx_buffer_size, rpmsg_port_get_rx_buffer_size, @@ -512,6 +515,18 @@ static int rpmsg_port_ns_callback(FAR struct rpmsg_endpoint *ept, return RPMSG_SUCCESS; } +/**************************************************************************** + * Name: rpmsg_port_get_local_cpuname + ****************************************************************************/ + +static FAR const char * +rpmsg_port_get_local_cpuname(FAR struct rpmsg_s *rpmsg) +{ + FAR struct rpmsg_port_s *port = (FAR struct rpmsg_port_s *)rpmsg; + + return port->local_cpuname; +} + /**************************************************************************** * Name: rpmsg_port_get_cpuname ****************************************************************************/ @@ -709,11 +724,17 @@ void rpmsg_port_queue_add_buffer(FAR struct rpmsg_port_queue_s *queue, * Name: rpmsg_port_register ****************************************************************************/ -int rpmsg_port_register(FAR struct rpmsg_port_s *port) +int rpmsg_port_register(FAR struct rpmsg_port_s *port, + FAR const char *local_cpuname) { char name[64]; int ret; + if (local_cpuname) + { + strlcpy(port->local_cpuname, local_cpuname, RPMSG_NAME_SIZE); + } + snprintf(name, sizeof(name), "/dev/rpmsg/%s", port->cpuname); ret = rpmsg_register(name, &port->rpmsg, &g_rpmsg_port_ops); if (ret < 0) diff --git a/drivers/rpmsg/rpmsg_port.h b/drivers/rpmsg/rpmsg_port.h index 54dfcf12e6..a0f649a75e 100644 --- a/drivers/rpmsg/rpmsg_port.h +++ b/drivers/rpmsg/rpmsg_port.h @@ -115,6 +115,8 @@ struct rpmsg_port_s struct rpmsg_port_queue_s txq; /* Port tx queue */ struct rpmsg_port_queue_s rxq; /* Port rx queue */ + char local_cpuname[RPMSG_NAME_SIZE]; + /* Remote cpu name of this port connected to */ char cpuname[RPMSG_NAME_SIZE]; @@ -301,14 +303,16 @@ void rpmsg_port_uninitialize(FAR struct rpmsg_port_s *port); * two cpus has established. * * Input Parameters: - * port - The port has established a connection. + * port - The port has established a connection. + * local_cpuname - The local cpuname * * Returned Value: * Zero on success or an negative value on failure. * ****************************************************************************/ -int rpmsg_port_register(FAR struct rpmsg_port_s *port); +int rpmsg_port_register(FAR struct rpmsg_port_s *port, + FAR const char *local_cpuname); /**************************************************************************** * Name: rpmsg_port_unregister diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c index 6d66bd8eab..f923cf48e6 100644 --- a/drivers/rpmsg/rpmsg_port_spi.c +++ b/drivers/rpmsg/rpmsg_port_spi.c @@ -324,7 +324,7 @@ rpmsg_port_spi_process_packet(FAR struct rpmsg_port_spi_s *rpspi, else { rpspi->txavail = rxhdr->avail; - rpmsg_port_register(&rpspi->port); + rpmsg_port_register(&rpspi->port, NULL); } rpmsg_port_queue_return_buffer(&rpspi->port.rxq, rxhdr); diff --git a/drivers/rpmsg/rpmsg_router_edge.c b/drivers/rpmsg/rpmsg_router_edge.c index f94822c618..573145fab7 100644 --- a/drivers/rpmsg/rpmsg_router_edge.c +++ b/drivers/rpmsg/rpmsg_router_edge.c @@ -79,6 +79,8 @@ struct rpmsg_router_edge_s * Private Function Prototypes ****************************************************************************/ +static FAR const char * +rpmsg_router_edge_get_local_cpuname(FAR struct rpmsg_s *rpmsg); static FAR const char * rpmsg_router_edge_get_cpuname(FAR struct rpmsg_s *rpmsg); static int rpmsg_router_edge_get_tx_buffer_size(FAR struct rpmsg_s *rpmsg); @@ -95,6 +97,7 @@ static const struct rpmsg_ops_s g_rpmsg_router_edge_ops = NULL, NULL, NULL, + rpmsg_router_edge_get_local_cpuname, rpmsg_router_edge_get_cpuname, rpmsg_router_edge_get_tx_buffer_size, rpmsg_router_edge_get_rx_buffer_size, @@ -104,6 +107,16 @@ static const struct rpmsg_ops_s g_rpmsg_router_edge_ops = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: rpmsg_router_edge_get_local_cpuname + ****************************************************************************/ + +static FAR const char * +rpmsg_router_edge_get_local_cpuname(FAR struct rpmsg_s *rpmsg) +{ + return NULL; +} + /**************************************************************************** * Name: rpmsg_router_edge_get_cpuname ****************************************************************************/ diff --git a/drivers/rpmsg/rpmsg_virtio.c b/drivers/rpmsg/rpmsg_virtio.c index d047733b38..e192145b05 100644 --- a/drivers/rpmsg/rpmsg_virtio.c +++ b/drivers/rpmsg/rpmsg_virtio.c @@ -70,6 +70,8 @@ struct rpmsg_virtio_priv_s static int rpmsg_virtio_wait(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem); static int rpmsg_virtio_post(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem); static void rpmsg_virtio_dump(FAR struct rpmsg_s *rpmsg); +static FAR const char * +rpmsg_virtio_get_local_cpuname(FAR struct rpmsg_s *rpmsg); static FAR const char *rpmsg_virtio_get_cpuname(FAR struct rpmsg_s *rpmsg); static int rpmsg_virtio_get_tx_buffer_size(FAR struct rpmsg_s *rpmsg); static int rpmsg_virtio_get_rx_buffer_size_(FAR struct rpmsg_s *rpmsg); @@ -96,6 +98,7 @@ static const struct rpmsg_ops_s g_rpmsg_virtio_ops = .wait = rpmsg_virtio_wait, .post = rpmsg_virtio_post, .dump = rpmsg_virtio_dump, + .get_local_cpuname = rpmsg_virtio_get_local_cpuname, .get_cpuname = rpmsg_virtio_get_cpuname, .get_tx_buffer_size = rpmsg_virtio_get_tx_buffer_size, .get_rx_buffer_size = rpmsg_virtio_get_rx_buffer_size_, @@ -389,6 +392,15 @@ static void rpmsg_virtio_dump(FAR struct rpmsg_s *rpmsg) } #endif +static FAR const char * +rpmsg_virtio_get_local_cpuname(FAR struct rpmsg_s *rpmsg) +{ + FAR struct rpmsg_virtio_priv_s *priv = + (FAR struct rpmsg_virtio_priv_s *)rpmsg; + + return RPMSG_VIRTIO_GET_LOCAL_CPUNAME(priv->dev); +} + static FAR const char *rpmsg_virtio_get_cpuname(FAR struct rpmsg_s *rpmsg) { FAR struct rpmsg_virtio_priv_s *priv = diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index 82e60b076b..f80af91396 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -125,6 +125,7 @@ static int rptun_ioctl(FAR struct rpmsg_s *rpmsg, int cmd, unsigned long arg); static void rptun_panic_(FAR struct rpmsg_s *rpmsg); static void rptun_dump(FAR struct rpmsg_s *rpmsg); +static FAR const char *rptun_get_local_cpuname(FAR struct rpmsg_s *rpmsg); static FAR const char *rptun_get_cpuname(FAR struct rpmsg_s *rpmsg); static int rptun_get_tx_buffer_size(FAR struct rpmsg_s *rpmsg); static int rptun_get_rx_buffer_size(FAR struct rpmsg_s *rpmsg); @@ -162,6 +163,7 @@ static const struct rpmsg_ops_s g_rptun_rpmsg_ops = rptun_ioctl, rptun_panic_, rptun_dump, + rptun_get_local_cpuname, rptun_get_cpuname, rptun_get_tx_buffer_size, rptun_get_rx_buffer_size, @@ -616,6 +618,13 @@ static void rptun_dump(FAR struct rpmsg_s *rpmsg) #endif } +static FAR const char *rptun_get_local_cpuname(FAR struct rpmsg_s *rpmsg) +{ + FAR struct rptun_priv_s *priv = (FAR struct rptun_priv_s *)rpmsg; + + return RPTUN_GET_LOCAL_CPUNAME(priv->dev); +} + static FAR const char *rptun_get_cpuname(FAR struct rpmsg_s *rpmsg) { FAR struct rptun_priv_s *priv = (FAR struct rptun_priv_s *)rpmsg; diff --git a/include/nuttx/rpmsg/rpmsg.h b/include/nuttx/rpmsg/rpmsg.h index 1964a7fcb4..4926fac758 100644 --- a/include/nuttx/rpmsg/rpmsg.h +++ b/include/nuttx/rpmsg/rpmsg.h @@ -74,6 +74,7 @@ struct rpmsg_ops_s CODE int (*ioctl)(FAR struct rpmsg_s *rpmsg, int cmd, unsigned long arg); CODE void (*panic)(FAR struct rpmsg_s *rpmsg); CODE void (*dump)(FAR struct rpmsg_s *rpmsg); + CODE FAR const char *(*get_local_cpuname)(FAR struct rpmsg_s *rpmsg); CODE FAR const char *(*get_cpuname)(FAR struct rpmsg_s *rpmsg); CODE int (*get_tx_buffer_size)(FAR struct rpmsg_s *rpmsg); CODE int (*get_rx_buffer_size)(FAR struct rpmsg_s *rpmsg); @@ -103,6 +104,7 @@ extern "C" int rpmsg_wait(FAR struct rpmsg_endpoint *ept, FAR sem_t *sem); int rpmsg_post(FAR struct rpmsg_endpoint *ept, FAR sem_t *sem); +FAR const char *rpmsg_get_local_cpuname(FAR struct rpmsg_device *rdev); FAR const char *rpmsg_get_cpuname(FAR struct rpmsg_device *rdev); int rpmsg_get_tx_buffer_size(FAR struct rpmsg_device *rdev); diff --git a/include/nuttx/rpmsg/rpmsg_virtio.h b/include/nuttx/rpmsg/rpmsg_virtio.h index fcb4c29242..ff7d6be7c6 100644 --- a/include/nuttx/rpmsg/rpmsg_virtio.h +++ b/include/nuttx/rpmsg/rpmsg_virtio.h @@ -40,6 +40,23 @@ /* Access macros ************************************************************/ +/**************************************************************************** + * Name: RPMSG_VIRTIO_GET_LOCAL_CPUNAME + * + * Description: + * Get remote cpu name + * + * Input Parameters: + * dev - Device-specific state data + * + * Returned Value: + * Cpu name on success, NULL on failure. + * + ****************************************************************************/ + +#define RPMSG_VIRTIO_GET_LOCAL_CPUNAME(d) \ + ((d)->ops->get_local_cpuname ? (d)->ops->get_local_cpuname(d) : "") + /**************************************************************************** * Name: RPMSG_VIRTIO_GET_CPUNAME * @@ -148,6 +165,7 @@ struct aligned_data(8) rpmsg_virtio_rsc_s struct rpmsg_virtio_s; struct rpmsg_virtio_ops_s { + CODE FAR const char *(*get_local_cpuname)(FAR struct rpmsg_virtio_s *dev); CODE FAR const char *(*get_cpuname)(FAR struct rpmsg_virtio_s *dev); CODE FAR struct rpmsg_virtio_rsc_s * (*get_resource)(FAR struct rpmsg_virtio_s *dev); diff --git a/include/nuttx/rptun/rptun.h b/include/nuttx/rptun/rptun.h index aafe4476cb..32e62f58cf 100644 --- a/include/nuttx/rptun/rptun.h +++ b/include/nuttx/rptun/rptun.h @@ -48,6 +48,23 @@ /* Access macros ************************************************************/ +/**************************************************************************** + * Name: RPTUN_GET_LOCAL_CPUNAME + * + * Description: + * Get local cpu name + * + * Input Parameters: + * dev - Device-specific state data + * + * Returned Value: + * Cpu name on success, NULL on failure. + * + ****************************************************************************/ + +#define RPTUN_GET_LOCAL_CPUNAME(d) ((d)->ops->get_local_cpuname ? \ + (d)->ops->get_local_cpuname(d) : "") + /**************************************************************************** * Name: RPTUN_GET_CPUNAME * @@ -317,6 +334,7 @@ struct aligned_data(8) rptun_rsc_s struct rptun_dev_s; struct rptun_ops_s { + CODE FAR const char *(*get_local_cpuname)(FAR struct rptun_dev_s *dev); CODE FAR const char *(*get_cpuname)(FAR struct rptun_dev_s *dev); CODE FAR const char *(*get_firmware)(FAR struct rptun_dev_s *dev);