From 5df041ca550544c1a380084af1aa4f40d8179292 Mon Sep 17 00:00:00 2001 From: zhuyanlin Date: Wed, 15 Dec 2021 12:11:39 +0800 Subject: [PATCH] ioe-rpmsg: bind server to diffent ept struture N/A Signed-off-by: zhuyanlin --- drivers/ioexpander/ioe_rpmsg.c | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/ioexpander/ioe_rpmsg.c b/drivers/ioexpander/ioe_rpmsg.c index bb6f63c0ac..ff5b1cfeae 100755 --- a/drivers/ioexpander/ioe_rpmsg.c +++ b/drivers/ioexpander/ioe_rpmsg.c @@ -115,8 +115,8 @@ struct ioe_rpmsg_cb_s uint64_t pendset; uint64_t cbfunc; uint64_t cbarg; - void *handler; - struct ioe_rpmsg_server_s *server; + FAR void *handler; + FAR struct rpmsg_endpoint *ept; struct work_s work; }; #endif @@ -125,7 +125,6 @@ struct ioe_rpmsg_server_s { FAR struct ioexpander_dev_s *ioe; FAR const char *name; - struct rpmsg_endpoint ept; #ifdef CONFIG_IOEXPANDER_INT_ENABLE struct ioe_rpmsg_cb_s cb[CONFIG_IOEXPANDER_RPMSG_INT_NCALLBACKS]; #endif @@ -457,14 +456,13 @@ static int ioe_rpmsg_readpin_handler(FAR struct rpmsg_endpoint *ept, static void ioe_rpmsg_irqworker(FAR void *priv_) { FAR struct ioe_rpmsg_cb_s *cb = priv_; - FAR struct ioe_rpmsg_server_s *priv = cb->server; struct ioe_rpmsg_irq_s msg; msg.pinset = cb->pendset; msg.cbfunc = cb->cbfunc; msg.cbarg = cb->cbarg; - ioe_rpmsg_sendrecv(&priv->ept, IOE_RPMSG_IRQ, + ioe_rpmsg_sendrecv(cb->ept, IOE_RPMSG_IRQ, (struct ioe_rpmsg_header_s *)&msg, sizeof(msg)); @@ -504,6 +502,7 @@ static int ioe_rpmsg_attach_handler(FAR struct rpmsg_endpoint *ept, { priv->cb[i].cbfunc = msg->cbfunc; priv->cb[i].cbarg = msg->cbarg; + priv->cb[i].ept = ept; msg->header.result = i; } @@ -528,8 +527,9 @@ static int ioe_rpmsg_detach_handler(FAR struct rpmsg_endpoint *ept, if (msg->header.result >= 0) { priv->cb[msg->cbidx].pendset = 0; - priv->cb[msg->cbidx].cbfunc = 0; - priv->cb[msg->cbidx].cbarg = 0; + priv->cb[msg->cbidx].cbfunc = 0; + priv->cb[msg->cbidx].cbarg = 0; + priv->cb[msg->cbidx].ept = NULL; } return rpmsg_send(ept, msg, len); @@ -612,6 +612,8 @@ static void ioe_rpmsg_client_destroy(FAR struct rpmsg_device *rdev, static void ioe_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept) { rpmsg_destroy_ept(ept); + + kmm_free(ept); } static void ioe_rpmsg_server_bind(FAR struct rpmsg_device *rdev, @@ -625,11 +627,19 @@ static void ioe_rpmsg_server_bind(FAR struct rpmsg_device *rdev, snprintf(eptname, RPMSG_NAME_SIZE, IOE_RPMSG_EPT_FORMAT, priv->name); - if (!strcmp(eptname, name)) + if (!strcmp(name, eptname)) { - priv->ept.priv = priv; + FAR struct rpmsg_endpoint *ept; - rpmsg_create_ept(&priv->ept, rdev, name, + ept = kmm_zalloc(sizeof(struct rpmsg_endpoint)); + if (!ept) + { + return; + } + + ept->priv = priv; + + rpmsg_create_ept(ept, rdev, name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, ioe_rpmsg_ept_cb, ioe_rpmsg_server_unbind); @@ -653,7 +663,6 @@ int ioe_rpmsg_server_initialize(FAR const char *name, { FAR struct ioe_rpmsg_server_s *priv; int ret; - int i; if (!name || !ioe) { @@ -669,13 +678,6 @@ int ioe_rpmsg_server_initialize(FAR const char *name, priv->name = name; priv->ioe = ioe; -#ifdef CONFIG_IOEXPANDER_INT_ENABLE - for (i = 0; i < CONFIG_IOEXPANDER_RPMSG_INT_NCALLBACKS; i++) - { - priv->cb[i].server = priv; - } -#endif - ret = rpmsg_register_callback(priv, NULL, NULL,