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/10/27 07:54:39 UTC

[GitHub] [incubator-nuttx] CV-Bowen opened a new pull request, #7442: rpmsgblk: rpmsg block device support

CV-Bowen opened a new pull request, #7442:
URL: https://github.com/apache/incubator-nuttx/pull/7442

   ## Summary
   Like rpmsgdev and rpmsgmtd, rpmsgblk allow the local cpu to access the block device in the remote cpu.
   
   ## Impact
   New feature
   
   ## Testing
   test with ramdisk and config sim:rpserver  and sim:rpproxy 
   


-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7442: rpmsgblk: rpmsg block device support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7442:
URL: https://github.com/apache/incubator-nuttx/pull/7442#discussion_r1006753965


##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -231,6 +236,16 @@ int sim_bringup(void)
     }
 #endif
 
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_BLK_RPMSG_SERVER)
+  ramdiskstart = (FAR uint8_t *)kmm_malloc(512 * 2048);

Review Comment:
   remove FAR



##########
drivers/misc/rpmsgblk.c:
##########
@@ -0,0 +1,1106 @@
+/****************************************************************************
+ * drivers/misc/rpmsgblk.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/fs/fs.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/fs/smart.h>
+#include <nuttx/mtd/smart.h>
+#include <nuttx/mutex.h>
+#include <nuttx/rptun/openamp.h>
+
+#include "rpmsgblk.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rpmsgblk_s
+{
+  struct block_operations blk;         /* Rpmsg-Block device operation */
+  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                 lock;        /* Lock for thread-safe */
+  struct geometry         geo;         /* block geomerty */
+  int                     refs;        /* refence count */
+};
+
+/* Rpmsg device cookie used to handle the response from the remote cpu */
+
+struct rpmsgblk_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 block operation functions */
+
+static int     rpmsgblk_open(FAR struct inode *inode);
+static int     rpmsgblk_close(FAR struct inode *inode);
+static ssize_t rpmsgblk_read(FAR struct inode *inode,
+                             FAR unsigned char *buffer,
+                             blkcnt_t start_sector, unsigned int nsectors);
+static ssize_t rpmsgblk_write(FAR struct inode *inode,
+                              FAR const unsigned char *buffer,
+                              blkcnt_t start_sector, unsigned int nsectors);
+static int     rpmsgblk_geometry(FAR struct inode *inode,
+                                 FAR struct geometry *geometry);
+static size_t  rpmsgblk_ioctl_arglen(int cmd);
+static int     rpmsgblk_ioctl(FAR struct inode *inode, int cmd,
+                              unsigned long arg);
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+static int     rpmsgblk_unlink(FAR struct inode *inode);
+#endif
+
+/* Functions for sending data to the remote cpu */
+
+static int     rpmsgblk_send_recv(FAR struct rpmsgblk_s *priv,
+                                  uint32_t command, bool copy,
+                                  FAR struct rpmsgblk_header_s *msg,
+                                  int len, FAR void *data);
+static FAR void *rpmsgblk_get_tx_payload_buffer(FAR struct rpmsgblk_s *priv,
+                                                FAR uint32_t *len);
+
+/* Functions handle the responses from the remote cpu */
+
+static int     rpmsgblk_default_handler(FAR struct rpmsg_endpoint *ept,
+                                        FAR void *data, size_t len,
+                                        uint32_t src, FAR void *priv);
+static int     rpmsgblk_read_handler(FAR struct rpmsg_endpoint *ept,
+                                     FAR void *data, size_t len,
+                                     uint32_t src, FAR void *priv);
+static int     rpmsgblk_geometry_handler(FAR struct rpmsg_endpoint *ept,
+                                         FAR void *data, size_t len,
+                                         uint32_t src, FAR void *priv);
+static int     rpmsgblk_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    rpmsgblk_device_created(struct rpmsg_device *rdev,
+                                       FAR void *priv_);
+static void    rpmsgblk_device_destroy(struct rpmsg_device *rdev,
+                                       FAR void *priv_);
+static int     rpmsgblk_ept_cb(FAR struct rpmsg_endpoint *ept,
+                               FAR void *data, size_t len, uint32_t src,
+                               FAR void *priv);
+static void    rpmsgblk_ns_bound(struct rpmsg_endpoint *ept);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Rpmsg device response handler table */
+
+static const rpmsg_ept_cb g_rpmsgblk_handler[] =
+{
+  [RPMSGBLK_OPEN]     = rpmsgblk_default_handler,
+  [RPMSGBLK_CLOSE]    = rpmsgblk_default_handler,
+  [RPMSGBLK_READ]     = rpmsgblk_read_handler,
+  [RPMSGBLK_WRITE]    = rpmsgblk_default_handler,
+  [RPMSGBLK_GEOMETRY] = rpmsgblk_geometry_handler,
+  [RPMSGBLK_IOCTL]    = rpmsgblk_ioctl_handler,
+  [RPMSGBLK_UNLINK]   = rpmsgblk_default_handler,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rpmsgblk_open
+ *
+ * Description:
+ *   Rpmsg-blk open operation
+ *
+ * Parameters:
+ *   inode
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int rpmsgblk_open(FAR struct inode *inode)
+{
+  FAR struct rpmsgblk_s *priv = (FAR struct rpmsgblk_s *)inode->i_private;
+  struct rpmsgblk_open_s msg;
+  int ret;
+
+  /* Sanity checks */
+
+  DEBUGASSERT(priv != NULL);
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+    {
+      ferr("lock failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* Check if this is the first time that the driver has been opened. */
+
+  if (priv->refs++ == 0)
+    {
+      /* Try to open the block device in the remote cpu */
+
+      ret = rpmsgblk_send_recv(priv, RPMSGBLK_OPEN, true, &msg.header,
+                               sizeof(msg), NULL);
+      if (ret < 0)
+        {
+          ferr("open failed, ret=%d\n", ret);
+          priv->refs--;
+        }
+    }
+
+  nxmutex_unlock(&priv->lock);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rpmsgblk_close
+ *
+ * Description:
+ *   Rpmsg-blk close operation
+ *
+ * Parameters:
+ *   inode
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int rpmsgblk_close(FAR struct inode *inode)
+{
+  FAR struct rpmsgblk_s *priv = (FAR struct rpmsgblk_s *)inode->i_private;
+  struct rpmsgblk_close_s msg;
+  int ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+    {
+      ferr("lock failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* There are no more references to the port */
+
+  if (--priv->refs == 0)
+    {
+      ret = rpmsgblk_send_recv(priv, RPMSGBLK_CLOSE, true, &msg.header,
+                               sizeof(msg), NULL);
+      if (ret < 0)
+        {
+          ferr("close failed, ret=%d\n", ret);
+          priv->refs++;
+        }
+    }
+
+  nxmutex_unlock(&priv->lock);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rpmsgblk_read
+ *
+ * Description:
+ *   Rpmsg-blk read operation
+ *
+ * Parameters:
+ *   dev    - the blk device
+ *   offset - read offset address in the blk device
+ *   nbytes - read number in bytes
+ *   buffer - read buffer
+ *
+ * Returned Values:
+ *   The positive non-zero number of bytes read on success, 0 on if an
+ *   end-of-file condition, or a negated errno value on any failure.
+ *
+ ****************************************************************************/
+
+static ssize_t rpmsgblk_read(FAR struct inode *inode,
+                             FAR unsigned char *buffer,
+                             blkcnt_t start_sector, unsigned int nsectors)
+{
+  FAR struct rpmsgblk_s *priv = (FAR struct rpmsgblk_s *)inode->i_private;
+  struct rpmsgblk_read_s msg;
+  struct iovec iov;
+  int ret;
+
+  if (buffer == NULL)
+    {
+      return -EINVAL;
+    }
+
+  ret = rpmsgblk_geometry(inode, &priv->geo);
+  if (ret < 0)
+    {
+      ferr("Get geometry failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* Sanity checks */
+
+  DEBUGASSERT(priv != NULL);

Review Comment:
   move before line 277



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #7442: rpmsgblk: rpmsg block device support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7442:
URL: https://github.com/apache/incubator-nuttx/pull/7442


-- 
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


[GitHub] [incubator-nuttx] CV-Bowen commented on a diff in pull request #7442: rpmsgblk: rpmsg block device support

Posted by GitBox <gi...@apache.org>.
CV-Bowen commented on code in PR #7442:
URL: https://github.com/apache/incubator-nuttx/pull/7442#discussion_r1006814314


##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -231,6 +236,16 @@ int sim_bringup(void)
     }
 #endif
 
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_BLK_RPMSG_SERVER)
+  ramdiskstart = (FAR uint8_t *)kmm_malloc(512 * 2048);

Review Comment:
   Done



##########
drivers/misc/rpmsgblk.c:
##########
@@ -0,0 +1,1106 @@
+/****************************************************************************
+ * drivers/misc/rpmsgblk.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/fs/fs.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/fs/smart.h>
+#include <nuttx/mtd/smart.h>
+#include <nuttx/mutex.h>
+#include <nuttx/rptun/openamp.h>
+
+#include "rpmsgblk.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rpmsgblk_s
+{
+  struct block_operations blk;         /* Rpmsg-Block device operation */
+  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                 lock;        /* Lock for thread-safe */
+  struct geometry         geo;         /* block geomerty */
+  int                     refs;        /* refence count */
+};
+
+/* Rpmsg device cookie used to handle the response from the remote cpu */
+
+struct rpmsgblk_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 block operation functions */
+
+static int     rpmsgblk_open(FAR struct inode *inode);
+static int     rpmsgblk_close(FAR struct inode *inode);
+static ssize_t rpmsgblk_read(FAR struct inode *inode,
+                             FAR unsigned char *buffer,
+                             blkcnt_t start_sector, unsigned int nsectors);
+static ssize_t rpmsgblk_write(FAR struct inode *inode,
+                              FAR const unsigned char *buffer,
+                              blkcnt_t start_sector, unsigned int nsectors);
+static int     rpmsgblk_geometry(FAR struct inode *inode,
+                                 FAR struct geometry *geometry);
+static size_t  rpmsgblk_ioctl_arglen(int cmd);
+static int     rpmsgblk_ioctl(FAR struct inode *inode, int cmd,
+                              unsigned long arg);
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+static int     rpmsgblk_unlink(FAR struct inode *inode);
+#endif
+
+/* Functions for sending data to the remote cpu */
+
+static int     rpmsgblk_send_recv(FAR struct rpmsgblk_s *priv,
+                                  uint32_t command, bool copy,
+                                  FAR struct rpmsgblk_header_s *msg,
+                                  int len, FAR void *data);
+static FAR void *rpmsgblk_get_tx_payload_buffer(FAR struct rpmsgblk_s *priv,
+                                                FAR uint32_t *len);
+
+/* Functions handle the responses from the remote cpu */
+
+static int     rpmsgblk_default_handler(FAR struct rpmsg_endpoint *ept,
+                                        FAR void *data, size_t len,
+                                        uint32_t src, FAR void *priv);
+static int     rpmsgblk_read_handler(FAR struct rpmsg_endpoint *ept,
+                                     FAR void *data, size_t len,
+                                     uint32_t src, FAR void *priv);
+static int     rpmsgblk_geometry_handler(FAR struct rpmsg_endpoint *ept,
+                                         FAR void *data, size_t len,
+                                         uint32_t src, FAR void *priv);
+static int     rpmsgblk_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    rpmsgblk_device_created(struct rpmsg_device *rdev,
+                                       FAR void *priv_);
+static void    rpmsgblk_device_destroy(struct rpmsg_device *rdev,
+                                       FAR void *priv_);
+static int     rpmsgblk_ept_cb(FAR struct rpmsg_endpoint *ept,
+                               FAR void *data, size_t len, uint32_t src,
+                               FAR void *priv);
+static void    rpmsgblk_ns_bound(struct rpmsg_endpoint *ept);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Rpmsg device response handler table */
+
+static const rpmsg_ept_cb g_rpmsgblk_handler[] =
+{
+  [RPMSGBLK_OPEN]     = rpmsgblk_default_handler,
+  [RPMSGBLK_CLOSE]    = rpmsgblk_default_handler,
+  [RPMSGBLK_READ]     = rpmsgblk_read_handler,
+  [RPMSGBLK_WRITE]    = rpmsgblk_default_handler,
+  [RPMSGBLK_GEOMETRY] = rpmsgblk_geometry_handler,
+  [RPMSGBLK_IOCTL]    = rpmsgblk_ioctl_handler,
+  [RPMSGBLK_UNLINK]   = rpmsgblk_default_handler,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rpmsgblk_open
+ *
+ * Description:
+ *   Rpmsg-blk open operation
+ *
+ * Parameters:
+ *   inode
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int rpmsgblk_open(FAR struct inode *inode)
+{
+  FAR struct rpmsgblk_s *priv = (FAR struct rpmsgblk_s *)inode->i_private;
+  struct rpmsgblk_open_s msg;
+  int ret;
+
+  /* Sanity checks */
+
+  DEBUGASSERT(priv != NULL);
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+    {
+      ferr("lock failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* Check if this is the first time that the driver has been opened. */
+
+  if (priv->refs++ == 0)
+    {
+      /* Try to open the block device in the remote cpu */
+
+      ret = rpmsgblk_send_recv(priv, RPMSGBLK_OPEN, true, &msg.header,
+                               sizeof(msg), NULL);
+      if (ret < 0)
+        {
+          ferr("open failed, ret=%d\n", ret);
+          priv->refs--;
+        }
+    }
+
+  nxmutex_unlock(&priv->lock);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rpmsgblk_close
+ *
+ * Description:
+ *   Rpmsg-blk close operation
+ *
+ * Parameters:
+ *   inode
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int rpmsgblk_close(FAR struct inode *inode)
+{
+  FAR struct rpmsgblk_s *priv = (FAR struct rpmsgblk_s *)inode->i_private;
+  struct rpmsgblk_close_s msg;
+  int ret;
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+    {
+      ferr("lock failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* There are no more references to the port */
+
+  if (--priv->refs == 0)
+    {
+      ret = rpmsgblk_send_recv(priv, RPMSGBLK_CLOSE, true, &msg.header,
+                               sizeof(msg), NULL);
+      if (ret < 0)
+        {
+          ferr("close failed, ret=%d\n", ret);
+          priv->refs++;
+        }
+    }
+
+  nxmutex_unlock(&priv->lock);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rpmsgblk_read
+ *
+ * Description:
+ *   Rpmsg-blk read operation
+ *
+ * Parameters:
+ *   dev    - the blk device
+ *   offset - read offset address in the blk device
+ *   nbytes - read number in bytes
+ *   buffer - read buffer
+ *
+ * Returned Values:
+ *   The positive non-zero number of bytes read on success, 0 on if an
+ *   end-of-file condition, or a negated errno value on any failure.
+ *
+ ****************************************************************************/
+
+static ssize_t rpmsgblk_read(FAR struct inode *inode,
+                             FAR unsigned char *buffer,
+                             blkcnt_t start_sector, unsigned int nsectors)
+{
+  FAR struct rpmsgblk_s *priv = (FAR struct rpmsgblk_s *)inode->i_private;
+  struct rpmsgblk_read_s msg;
+  struct iovec iov;
+  int ret;
+
+  if (buffer == NULL)
+    {
+      return -EINVAL;
+    }
+
+  ret = rpmsgblk_geometry(inode, &priv->geo);
+  if (ret < 0)
+    {
+      ferr("Get geometry failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* Sanity checks */
+
+  DEBUGASSERT(priv != NULL);

Review Comment:
   Done



-- 
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