You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/09/08 13:55:37 UTC

[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7042: Add rpmsgmtd support

anchao commented on code in PR #7042:
URL: https://github.com/apache/incubator-nuttx/pull/7042#discussion_r966003112


##########
drivers/mtd/rpmsgmtd.c:
##########
@@ -0,0 +1,1135 @@
+/****************************************************************************
+ * drivers/mtd/rpmsgmtd.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/mtd/mtd.h>
+#include <nuttx/mutex.h>
+#include <nuttx/rptun/openamp.h>
+
+#include "rpmsgmtd.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rpmsgmtd_s
+{
+  struct mtd_dev_s      mtd;         /* MTD device */
+  struct rpmsg_endpoint ept;         /* Rpmsg endpoint */
+  FAR const char       *remotecpu;   /* The server cpu name */
+  FAR const char       *remotepath;  /* The device path in the server cpu */
+  sem_t                 wait;        /* Wait sem, used for preventing any
+                                      * opreation until the connection
+                                      * between two cpu established.
+                                      */
+  mutex_t               geoexcl;     /* Get mtd geometry operation mutex */
+  struct mtd_geometry_s geo;         /* MTD geomerty */
+};
+
+/* Rpmsg device cookie used to handle the response from the remote cpu */
+
+struct rpmsgmtd_cookie_s
+{
+  sem_t     sem;     /* Semaphore used fo rpmsg */
+  int       result;  /* The return value of the remote call */
+  FAR void *data;    /* The return data buffer of the remote call */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* The mtd operation functions */
+
+static int     rpmsgmtd_erase(FAR struct mtd_dev_s *dev, off_t startblock,
+                              size_t nblocks);
+static int     rpmsgmtd_get_geometry(FAR struct rpmsgmtd_s *dev);
+static ssize_t rpmsgmtd_bread(FAR struct mtd_dev_s *dev, off_t startblock,
+                              size_t nblocks, FAR uint8_t *buffer);
+static ssize_t rpmsgmtd_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
+                               size_t nblocks, FAR const uint8_t *buffer);
+static ssize_t rpmsgmtd_read(FAR struct mtd_dev_s *dev, off_t offset,
+                             size_t nbytes, FAR uint8_t *buffer);
+#ifdef CONFIG_MTD_BYTE_WRITE
+static ssize_t rpmsgmtd_write(FAR struct mtd_dev_s *dev, off_t offset,
+                              size_t nbytes, FAR const uint8_t *buffer);
+#endif
+static size_t  rpmsgmtd_ioctl_arglen(int cmd);
+static int     rpmsgmtd_ioctl(FAR struct mtd_dev_s *dev, int cmd,
+                              unsigned long arg);
+
+/* Functions for sending data to the remote cpu */
+
+static int     rpmsgmtd_send_recv(FAR struct rpmsgmtd_s *priv,
+                                  uint32_t command, bool copy,
+                                  FAR struct rpmsgmtd_header_s *msg,
+                                  int len, FAR void *data);
+static FAR void *rpmsgmtd_get_tx_payload_buffer(FAR struct rpmsgmtd_s *priv,
+                                                FAR uint32_t *len);
+
+/* Functions handle the responses from the remote cpu */
+
+static int     rpmsgmtd_default_handler(FAR struct rpmsg_endpoint *ept,
+                                        FAR void *data, size_t len,
+                                        uint32_t src, FAR void *priv);
+static int     rpmsgmtd_bread_handler(FAR struct rpmsg_endpoint *ept,
+                                      FAR void *data, size_t len,
+                                      uint32_t src, FAR void *priv);
+static int     rpmsgmtd_read_handler(FAR struct rpmsg_endpoint *ept,
+                                     FAR void *data, size_t len,
+                                     uint32_t src, FAR void *priv);
+static int     rpmsgmtd_ioctl_handler(FAR struct rpmsg_endpoint *ept,
+                                      FAR void *data, size_t len,
+                                      uint32_t src, FAR void *priv);
+
+/* Functions for creating communication with remote cpu */
+
+static void    rpmsgmtd_device_created(struct rpmsg_device *rdev,
+                                       FAR void *priv_);
+static void    rpmsgmtd_device_destroy(struct rpmsg_device *rdev,
+                                       FAR void *priv_);
+static int     rpmsgmtd_ept_cb(FAR struct rpmsg_endpoint *ept,
+                               FAR void *data, size_t len, uint32_t src,
+                               FAR void *priv);
+static void    rpmsgmtd_ns_bound(struct rpmsg_endpoint *ept);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Rpmsg device response handler table */
+
+static const rpmsg_ept_cb g_rpmsgmtd_handler[] =
+{
+  [RPMSGMTD_ERASE]  = rpmsgmtd_default_handler,
+  [RPMSGMTD_BREAD]  = rpmsgmtd_bread_handler,
+  [RPMSGMTD_BWRITE] = rpmsgmtd_default_handler,
+  [RPMSGMTD_READ]   = rpmsgmtd_read_handler,
+  [RPMSGMTD_WRITE]  = rpmsgmtd_default_handler,
+  [RPMSGMTD_IOCTL]  = rpmsgmtd_ioctl_handler,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rpmsgmtd_erase
+ *
+ * Description:
+ *   Rpmsg-mtd erase operation
+ *
+ * Parameters:
+ *   dev        - the mtd device
+ *   startblock - erase start block
+ *   nblocks    - erase block number
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int rpmsgmtd_erase(FAR struct mtd_dev_s *dev, off_t startblock,
+                          size_t nblocks)
+{
+  FAR struct rpmsgmtd_s *priv = (FAR struct rpmsgmtd_s *)dev;
+  struct rpmsgmtd_erase_s msg;
+  int ret;
+
+  /* Sanity checks */
+
+  DEBUGASSERT(priv != NULL);
+
+  msg.startblock = startblock;
+  msg.nblocks    = nblocks;
+  ret = rpmsgmtd_send_recv(priv, RPMSGMTD_ERASE, true, &msg.header,

Review Comment:
   remove ret



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org