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/03/14 11:41:17 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a change in pull request #5736: driver/uinput: add cross core control function

pkarashchenko commented on a change in pull request #5736:
URL: https://github.com/apache/incubator-nuttx/pull/5736#discussion_r825846624



##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};

Review comment:
       ```suggestion
   #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
     , NULL  /* unlink */
   #endif
   };
   ```

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)
+    {
+      fds->revents |= (fds->events & POLLIN);
+      if (fds->revents != 0)
+        {
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fds->sem, &semcount);
+          if (semcount < 1)
+            {
+              nxsem_post(fds->sem);
+            }
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: keyboard_open
+ ****************************************************************************/
+
+static int keyboard_open(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = NULL;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->open)
+    {
+      ret = upper->lower->open(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  opriv = kmm_zalloc(sizeof(FAR struct keyboard_opriv_s));
+  if (opriv == NULL)
+    {
+      ret = -ENOMEM;
+      goto out;
+    }
+
+  /* Initializes the buffer for each open file */
+
+  ret = circbuf_init(&opriv->circ, NULL, CONFIG_INPUT_KEYBOARD_BUFFSIZE);
+  if (ret < 0)
+    {
+      kmm_free(opriv);
+      goto out;
+    }
+
+  nxsem_init(&opriv->waitsem, 0, 0);
+  nxsem_init(&opriv->locksem, 0, 1);
+  nxsem_set_protocol(&opriv->waitsem, SEM_PRIO_NONE);
+  list_add_tail(&upper->head, &opriv->node);
+  filep->f_priv = opriv;
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_close
+ ****************************************************************************/
+
+static int keyboard_close(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = filep->f_priv;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->close)
+    {
+      ret = upper->lower->close(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  list_delete(&opriv->node);
+  circbuf_uninit(&opriv->circ);
+  nxsem_destroy(&opriv->waitsem);
+  nxsem_destroy(&opriv->locksem);
+  kmm_free(opriv);
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_read
+ ****************************************************************************/
+
+static ssize_t keyboard_read(FAR struct file *filep,
+                             FAR char *buff, size_t len)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  /* Make sure that we have exclusive access to the private data structure */
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Is there keyboard data now? */
+
+  while (circbuf_is_empty(&opriv->circ))
+    {
+      if (filep->f_oflags & O_NONBLOCK)

Review comment:
       ```suggestion
         if ((filep->f_oflags & O_NONBLOCK) != 0)
   ```

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)
+    {
+      fds->revents |= (fds->events & POLLIN);
+      if (fds->revents != 0)
+        {
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fds->sem, &semcount);
+          if (semcount < 1)
+            {
+              nxsem_post(fds->sem);
+            }
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: keyboard_open
+ ****************************************************************************/
+
+static int keyboard_open(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = NULL;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->open)
+    {
+      ret = upper->lower->open(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  opriv = kmm_zalloc(sizeof(FAR struct keyboard_opriv_s));
+  if (opriv == NULL)
+    {
+      ret = -ENOMEM;
+      goto out;
+    }
+
+  /* Initializes the buffer for each open file */
+
+  ret = circbuf_init(&opriv->circ, NULL, CONFIG_INPUT_KEYBOARD_BUFFSIZE);
+  if (ret < 0)
+    {
+      kmm_free(opriv);
+      goto out;
+    }
+
+  nxsem_init(&opriv->waitsem, 0, 0);
+  nxsem_init(&opriv->locksem, 0, 1);
+  nxsem_set_protocol(&opriv->waitsem, SEM_PRIO_NONE);
+  list_add_tail(&upper->head, &opriv->node);
+  filep->f_priv = opriv;
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_close
+ ****************************************************************************/
+
+static int keyboard_close(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = filep->f_priv;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->close)
+    {
+      ret = upper->lower->close(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  list_delete(&opriv->node);
+  circbuf_uninit(&opriv->circ);
+  nxsem_destroy(&opriv->waitsem);
+  nxsem_destroy(&opriv->locksem);
+  kmm_free(opriv);
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_read
+ ****************************************************************************/
+
+static ssize_t keyboard_read(FAR struct file *filep,
+                             FAR char *buff, size_t len)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  /* Make sure that we have exclusive access to the private data structure */
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Is there keyboard data now? */
+
+  while (circbuf_is_empty(&opriv->circ))
+    {
+      if (filep->f_oflags & O_NONBLOCK)
+        {
+          ret = -EAGAIN;
+          goto out;
+        }
+      else
+        {
+          nxsem_post(&opriv->locksem);
+          ret = nxsem_wait_uninterruptible(&opriv->waitsem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+
+          ret = nxsem_wait(&opriv->locksem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+        }
+    }
+
+  ret = circbuf_read(&opriv->circ, buff, len);
+
+out:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_poll
+ ****************************************************************************/
+
+static int keyboard_poll(FAR struct file *filep,
+                         FAR struct pollfd *fds, bool setup)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (setup)
+    {
+      if (opriv->fds == NULL)
+        {
+          opriv->fds = fds;
+          fds->priv  = &opriv->fds;
+        }
+      else
+        {
+          ret = -EBUSY;
+          goto errout;
+        }
+
+      if (!circbuf_is_empty(&opriv->circ))
+        {
+          keyboard_notify(opriv);
+        }
+    }
+  else if (fds->priv)
+    {
+      if (fds == opriv->fds)
+        {
+          opriv->fds = NULL;
+          fds->priv  = NULL;
+        }
+    }
+
+errout:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_write
+ ****************************************************************************/
+
+static ssize_t keyboard_write(FAR struct file *filep,
+                              FAR const char *buffer, size_t buflen)
+{
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  FAR struct keyboard_lowerhalf_s *lower = upper->lower;
+
+  if (!lower->write)
+    {
+      return -ENOSYS;
+    }
+
+  return lower->write(lower, buffer, buflen);

Review comment:
       ```suggestion
     if (lower->write)
       {
         return lower->write(lower, buffer, buflen);
       }
   
     return -ENOSYS;
   ```

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)
+    {
+      fds->revents |= (fds->events & POLLIN);
+      if (fds->revents != 0)
+        {
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fds->sem, &semcount);
+          if (semcount < 1)
+            {
+              nxsem_post(fds->sem);
+            }
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: keyboard_open
+ ****************************************************************************/
+
+static int keyboard_open(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = NULL;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->open)
+    {
+      ret = upper->lower->open(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  opriv = kmm_zalloc(sizeof(FAR struct keyboard_opriv_s));
+  if (opriv == NULL)
+    {
+      ret = -ENOMEM;
+      goto out;
+    }
+
+  /* Initializes the buffer for each open file */
+
+  ret = circbuf_init(&opriv->circ, NULL, CONFIG_INPUT_KEYBOARD_BUFFSIZE);
+  if (ret < 0)
+    {
+      kmm_free(opriv);
+      goto out;
+    }
+
+  nxsem_init(&opriv->waitsem, 0, 0);
+  nxsem_init(&opriv->locksem, 0, 1);
+  nxsem_set_protocol(&opriv->waitsem, SEM_PRIO_NONE);
+  list_add_tail(&upper->head, &opriv->node);
+  filep->f_priv = opriv;
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_close
+ ****************************************************************************/
+
+static int keyboard_close(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = filep->f_priv;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->close)
+    {
+      ret = upper->lower->close(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  list_delete(&opriv->node);
+  circbuf_uninit(&opriv->circ);
+  nxsem_destroy(&opriv->waitsem);
+  nxsem_destroy(&opriv->locksem);
+  kmm_free(opriv);
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_read
+ ****************************************************************************/
+
+static ssize_t keyboard_read(FAR struct file *filep,
+                             FAR char *buff, size_t len)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  /* Make sure that we have exclusive access to the private data structure */
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Is there keyboard data now? */
+
+  while (circbuf_is_empty(&opriv->circ))
+    {
+      if (filep->f_oflags & O_NONBLOCK)
+        {
+          ret = -EAGAIN;
+          goto out;
+        }
+      else
+        {
+          nxsem_post(&opriv->locksem);
+          ret = nxsem_wait_uninterruptible(&opriv->waitsem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+
+          ret = nxsem_wait(&opriv->locksem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+        }
+    }
+
+  ret = circbuf_read(&opriv->circ, buff, len);
+
+out:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_poll
+ ****************************************************************************/
+
+static int keyboard_poll(FAR struct file *filep,
+                         FAR struct pollfd *fds, bool setup)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (setup)
+    {
+      if (opriv->fds == NULL)
+        {
+          opriv->fds = fds;
+          fds->priv  = &opriv->fds;
+        }
+      else
+        {
+          ret = -EBUSY;
+          goto errout;
+        }
+
+      if (!circbuf_is_empty(&opriv->circ))
+        {
+          keyboard_notify(opriv);
+        }
+    }
+  else if (fds->priv)
+    {
+      if (fds == opriv->fds)
+        {
+          opriv->fds = NULL;
+          fds->priv  = NULL;
+        }
+    }
+
+errout:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_write
+ ****************************************************************************/
+
+static ssize_t keyboard_write(FAR struct file *filep,
+                              FAR const char *buffer, size_t buflen)
+{
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  FAR struct keyboard_lowerhalf_s *lower = upper->lower;
+
+  if (!lower->write)
+    {
+      return -ENOSYS;
+    }
+
+  return lower->write(lower, buffer, buflen);
+}
+
+/****************************************************************************
+ * Public Function
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_register
+ ****************************************************************************/
+
+int keyboard_register(FAR struct keyboard_lowerhalf_s *lower,
+                      FAR const char *path)
+{
+  FAR struct keyboard_upperhalf_s *upper;
+  int ret;
+
+  iinfo("Registering %s\n", path);
+  if (lower == NULL)
+    {
+      ierr("ERROR: invalid touchscreen device\n");
+      return -EINVAL;
+    }
+
+  upper = kmm_zalloc(sizeof(struct keyboard_upperhalf_s));
+  if (!upper)
+    {
+      ierr("ERROR: Failed to mem alloc!\n");
+      return -ENOMEM;
+    }
+
+  upper->lower = lower;
+  lower->priv  = upper;
+  list_initialize(&upper->head);
+  nxsem_init(&upper->exclsem, 0, 1);
+
+  ret = register_driver(path, &g_keyboard_fops, 0666, upper);
+  if (ret < 0)
+    {
+      goto out;
+    }
+
+  return ret;
+out:
+  nxsem_destroy(&upper->exclsem);
+  kmm_free(upper);
+  return ret;

Review comment:
       ```suggestion
     if (ret < 0)
       {
         nxsem_destroy(&upper->exclsem);
         kmm_free(upper);
       }
     return ret;
   ```

##########
File path: drivers/input/touchscreen_upper.c
##########
@@ -105,28 +101,25 @@ static const struct file_operations g_touch_fops =
  * Private Functions
  ****************************************************************************/
 
-static void touch_notify(FAR struct touch_upperhalf_s *upper,
+static void touch_notify(FAR struct touch_openpriv_s *openpriv,
                          pollevent_t eventset)
 {
-  FAR struct pollfd *fd;
+  FAR struct pollfd *fd = openpriv->fds;
   int i;
 
-  for (i = 0; i < CONFIG_INPUT_TOUCHSCREEN_NPOLLWAITERS; i++)
+  fd = openpriv->fds;
+  if (fd)
     {
-      fd = upper->fds[i];
-      if (fd)
+      fd->revents |= (fd->events & eventset);
+      if (fd->revents != 0)
         {
-          fd->revents |= (fd->events & eventset);
-          if (fd->revents != 0)
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fd->sem, &semcount);
+          if (semcount < 1)
             {
-              /* report event log */
-
-              int semcount;
-              nxsem_get_value(fd->sem, &semcount);
-              if (semcount < 1)
-                {
-                   nxsem_post(fd->sem);
-                }
+              nxsem_post(fd->sem);
             }

Review comment:
       ```suggestion
             nxsem_post(fd->sem);
   ```

##########
File path: drivers/input/uinput.c
##########
@@ -244,14 +543,79 @@ int uinput_button_initialize(FAR const char *name)
   ubtn_lower->lower.bl_enable    = uinput_button_enable;
   ubtn_lower->lower.bl_supported = uinput_button_supported;
   ubtn_lower->lower.bl_write     = uinput_button_write;
+#ifdef CONFIG_UINPUT_RPMSG
+  ubtn_lower->ctx.notify         = uinput_button_notify;
+#endif
 
   snprintf(devname, UINPUT_NAME_SIZE, "/dev/%s", name);
   ret = btn_register(devname, &ubtn_lower->lower);
   if (ret < 0)
     {
       kmm_free(ubtn_lower);
+      ierr("ERROR: uinput button initialize failed\n");
+      return ret;
     }
 
-  return ret;
+#ifdef CONFIG_UINPUT_RPMSG
+  uinput_rpmsg_initialize(&ubtn_lower->ctx, name);
+#endif
+
+  return 0;
 }
-#endif /* CONFIG_INPUT_BUTTONS */
+
+#endif /* CONFIG_UINPUT_BUTTONS */
+
+/****************************************************************************
+ * Name: uinput_keyboard_initialize
+ *
+ * Description:
+ *   Initialized the uinput keyboard device
+ *
+ * Input Parameters:
+ *   name: keyboard devices name
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_UINPUT_KEYBOARD
+
+int uinput_keyboard_initialize(FAR const char *name)
+{
+  char devname[UINPUT_NAME_SIZE];
+  FAR struct uinput_keyboard_lowerhalf_s *ukbd_lower;
+  int ret;
+
+  ukbd_lower = kmm_zalloc(sizeof(struct uinput_keyboard_lowerhalf_s));
+  if (!ukbd_lower)

Review comment:
       ```suggestion
     if (ukbd_lower == NULL)
   ```

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)

Review comment:
       ```suggestion
     if (fds != NULL)
   ```

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)
+    {
+      fds->revents |= (fds->events & POLLIN);
+      if (fds->revents != 0)
+        {
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fds->sem, &semcount);
+          if (semcount < 1)
+            {
+              nxsem_post(fds->sem);
+            }

Review comment:
       ```suggestion
             nxsem_post(fds->sem);
   ```

##########
File path: drivers/input/touchscreen_upper.c
##########
@@ -366,34 +350,40 @@ static int touch_poll(FAR struct file *filep,
 void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
 {
   FAR struct touch_upperhalf_s *upper = priv;
+  FAR struct touch_openpriv_s  *openpriv;
   int semcount;
 
   if (nxsem_wait(&upper->exclsem) < 0)
     {
       return;
     }
 
-  circbuf_overwrite(&upper->buffer, sample,
-                    SIZEOF_TOUCH_SAMPLE_S(sample->npoints));
-  touch_notify(upper, POLLIN);
-  nxsem_get_value(&upper->buffersem, &semcount);
-  if (semcount < 1)
+  list_for_every_entry(&upper->head, openpriv, struct touch_openpriv_s, node)
     {
-      nxsem_post(&upper->buffersem);
+      circbuf_overwrite(&openpriv->circbuf, sample,
+                        SIZEOF_TOUCH_SAMPLE_S(sample->npoints));
+
+      nxsem_get_value(&openpriv->waitsem, &semcount);
+      if (semcount < 1)

Review comment:
       why do we need check semaphore count value? can we `nxsem_post(&openpriv->waitsem);` without a check?

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)
+    {
+      fds->revents |= (fds->events & POLLIN);
+      if (fds->revents != 0)
+        {
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fds->sem, &semcount);
+          if (semcount < 1)
+            {
+              nxsem_post(fds->sem);
+            }
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: keyboard_open
+ ****************************************************************************/
+
+static int keyboard_open(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = NULL;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->open)
+    {
+      ret = upper->lower->open(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  opriv = kmm_zalloc(sizeof(FAR struct keyboard_opriv_s));
+  if (opriv == NULL)
+    {
+      ret = -ENOMEM;
+      goto out;
+    }
+
+  /* Initializes the buffer for each open file */
+
+  ret = circbuf_init(&opriv->circ, NULL, CONFIG_INPUT_KEYBOARD_BUFFSIZE);
+  if (ret < 0)
+    {
+      kmm_free(opriv);
+      goto out;
+    }
+
+  nxsem_init(&opriv->waitsem, 0, 0);
+  nxsem_init(&opriv->locksem, 0, 1);
+  nxsem_set_protocol(&opriv->waitsem, SEM_PRIO_NONE);
+  list_add_tail(&upper->head, &opriv->node);
+  filep->f_priv = opriv;
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_close
+ ****************************************************************************/
+
+static int keyboard_close(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = filep->f_priv;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->close)
+    {
+      ret = upper->lower->close(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  list_delete(&opriv->node);
+  circbuf_uninit(&opriv->circ);
+  nxsem_destroy(&opriv->waitsem);
+  nxsem_destroy(&opriv->locksem);
+  kmm_free(opriv);
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_read
+ ****************************************************************************/
+
+static ssize_t keyboard_read(FAR struct file *filep,
+                             FAR char *buff, size_t len)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  /* Make sure that we have exclusive access to the private data structure */
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Is there keyboard data now? */
+
+  while (circbuf_is_empty(&opriv->circ))
+    {
+      if (filep->f_oflags & O_NONBLOCK)
+        {
+          ret = -EAGAIN;
+          goto out;
+        }
+      else
+        {
+          nxsem_post(&opriv->locksem);
+          ret = nxsem_wait_uninterruptible(&opriv->waitsem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+
+          ret = nxsem_wait(&opriv->locksem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+        }
+    }
+
+  ret = circbuf_read(&opriv->circ, buff, len);
+
+out:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_poll
+ ****************************************************************************/
+
+static int keyboard_poll(FAR struct file *filep,
+                         FAR struct pollfd *fds, bool setup)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (setup)
+    {
+      if (opriv->fds == NULL)
+        {
+          opriv->fds = fds;
+          fds->priv  = &opriv->fds;
+        }
+      else
+        {
+          ret = -EBUSY;
+          goto errout;
+        }
+
+      if (!circbuf_is_empty(&opriv->circ))
+        {
+          keyboard_notify(opriv);
+        }
+    }
+  else if (fds->priv)
+    {
+      if (fds == opriv->fds)
+        {
+          opriv->fds = NULL;
+          fds->priv  = NULL;
+        }
+    }
+
+errout:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_write
+ ****************************************************************************/
+
+static ssize_t keyboard_write(FAR struct file *filep,
+                              FAR const char *buffer, size_t buflen)
+{
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  FAR struct keyboard_lowerhalf_s *lower = upper->lower;
+
+  if (!lower->write)
+    {
+      return -ENOSYS;
+    }
+
+  return lower->write(lower, buffer, buflen);
+}
+
+/****************************************************************************
+ * Public Function
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_register
+ ****************************************************************************/
+
+int keyboard_register(FAR struct keyboard_lowerhalf_s *lower,
+                      FAR const char *path)
+{
+  FAR struct keyboard_upperhalf_s *upper;
+  int ret;
+
+  iinfo("Registering %s\n", path);
+  if (lower == NULL)
+    {
+      ierr("ERROR: invalid touchscreen device\n");
+      return -EINVAL;
+    }
+
+  upper = kmm_zalloc(sizeof(struct keyboard_upperhalf_s));
+  if (!upper)

Review comment:
       ```suggestion
     if (upper == NULL)
   ```

##########
File path: drivers/input/keyboard_upper.c
##########
@@ -0,0 +1,445 @@
+/****************************************************************************
+ * drivers/input/keyboard_upper.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 <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include <nuttx/input/keyboard.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/list.h>
+#include <nuttx/mm/circbuf.h>
+#include <nuttx/semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct keyboard_opriv_s
+{
+  sem_t              waitsem;
+  sem_t              locksem;
+  struct circbuf_s   circ;
+  struct list_node   node;
+  FAR struct pollfd *fds;
+};
+
+/* This structure is for keyboard upper half driver */
+
+struct keyboard_upperhalf_s
+{
+  sem_t            exclsem; /* Manages exclusive access to this structure */
+  struct list_node head;    /* Head of list */
+  FAR struct keyboard_lowerhalf_s
+                  *lower;   /* A pointer of lower half instance */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int     keyboard_open(FAR struct file *filep);
+static int     keyboard_close(FAR struct file *filep);
+static ssize_t keyboard_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                             bool setup);
+static void    keyboard_notify(FAR struct keyboard_opriv_s *buffer);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_keyboard_fops =
+{
+  keyboard_open,  /* open */
+  keyboard_close, /* close */
+  keyboard_read,  /* read */
+  keyboard_write, /* write */
+  NULL,           /* seek */
+  NULL,           /* ioctl */
+  keyboard_poll   /* poll */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: keyboard_notify
+ ****************************************************************************/
+
+static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
+{
+  FAR struct pollfd *fds = opriv->fds;
+  if (fds)
+    {
+      fds->revents |= (fds->events & POLLIN);
+      if (fds->revents != 0)
+        {
+          /* report event log */
+
+          int semcount;
+          nxsem_get_value(fds->sem, &semcount);
+          if (semcount < 1)
+            {
+              nxsem_post(fds->sem);
+            }
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: keyboard_open
+ ****************************************************************************/
+
+static int keyboard_open(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = NULL;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->open)
+    {
+      ret = upper->lower->open(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  opriv = kmm_zalloc(sizeof(FAR struct keyboard_opriv_s));
+  if (opriv == NULL)
+    {
+      ret = -ENOMEM;
+      goto out;
+    }
+
+  /* Initializes the buffer for each open file */
+
+  ret = circbuf_init(&opriv->circ, NULL, CONFIG_INPUT_KEYBOARD_BUFFSIZE);
+  if (ret < 0)
+    {
+      kmm_free(opriv);
+      goto out;
+    }
+
+  nxsem_init(&opriv->waitsem, 0, 0);
+  nxsem_init(&opriv->locksem, 0, 1);
+  nxsem_set_protocol(&opriv->waitsem, SEM_PRIO_NONE);
+  list_add_tail(&upper->head, &opriv->node);
+  filep->f_priv = opriv;
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_close
+ ****************************************************************************/
+
+static int keyboard_close(FAR struct file *filep)
+{
+  FAR struct keyboard_opriv_s     *opriv = filep->f_priv;
+  FAR struct inode                *inode = filep->f_inode;
+  FAR struct keyboard_upperhalf_s *upper = inode->i_private;
+  int ret;
+
+  ret = nxsem_wait(&upper->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Perform the operations required by the lower level */
+
+  if (upper->lower->close)
+    {
+      ret = upper->lower->close(upper->lower);
+      if (ret < 0)
+        {
+          goto out;
+        }
+    }
+
+  list_delete(&opriv->node);
+  circbuf_uninit(&opriv->circ);
+  nxsem_destroy(&opriv->waitsem);
+  nxsem_destroy(&opriv->locksem);
+  kmm_free(opriv);
+
+out:
+  nxsem_post(&upper->exclsem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_read
+ ****************************************************************************/
+
+static ssize_t keyboard_read(FAR struct file *filep,
+                             FAR char *buff, size_t len)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  /* Make sure that we have exclusive access to the private data structure */
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Is there keyboard data now? */
+
+  while (circbuf_is_empty(&opriv->circ))
+    {
+      if (filep->f_oflags & O_NONBLOCK)
+        {
+          ret = -EAGAIN;
+          goto out;
+        }
+      else
+        {
+          nxsem_post(&opriv->locksem);
+          ret = nxsem_wait_uninterruptible(&opriv->waitsem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+
+          ret = nxsem_wait(&opriv->locksem);
+          if (ret < 0)
+            {
+              return ret;
+            }
+        }
+    }
+
+  ret = circbuf_read(&opriv->circ, buff, len);
+
+out:
+  nxsem_post(&opriv->locksem);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: keyboard_poll
+ ****************************************************************************/
+
+static int keyboard_poll(FAR struct file *filep,
+                         FAR struct pollfd *fds, bool setup)
+{
+  FAR struct keyboard_opriv_s *opriv = filep->f_priv;
+  int ret;
+
+  ret = nxsem_wait(&opriv->locksem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (setup)
+    {
+      if (opriv->fds == NULL)
+        {
+          opriv->fds = fds;
+          fds->priv  = &opriv->fds;
+        }
+      else
+        {
+          ret = -EBUSY;
+          goto errout;
+        }
+
+      if (!circbuf_is_empty(&opriv->circ))
+        {
+          keyboard_notify(opriv);
+        }
+    }
+  else if (fds->priv)

Review comment:
       ```suggestion
     else if (fds->priv != NULL)
   ```

##########
File path: drivers/input/touchscreen_upper.c
##########
@@ -297,65 +297,49 @@ static int touch_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
   return ret;
 }
 
-static int touch_poll(FAR struct file *filep,
-                      struct pollfd *fds, bool setup)
+static int touch_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
 {
-  FAR struct inode *inode = filep->f_inode;
-  FAR struct touch_upperhalf_s *upper = inode->i_private;
+  FAR struct touch_openpriv_s *openpriv = filep->f_priv;
   pollevent_t eventset = 0;
   int ret;
-  int i;
 
-  ret = nxsem_wait(&upper->exclsem);
+  ret = nxsem_wait(&openpriv->locksem);
   if (ret < 0)
     {
       return ret;
     }
 
   if (setup)
     {
-      for (i = 0; i < CONFIG_INPUT_TOUCHSCREEN_NPOLLWAITERS; i++)
+      if (openpriv->fds == NULL)
         {
-          if (NULL == upper->fds[i])
-            {
-              upper->fds[i] = fds;
-              fds->priv = &upper->fds[i];
-              break;
-            }
+          openpriv->fds = fds;
+          fds->priv   = &openpriv->fds;

Review comment:
       ```suggestion
             fds->priv     = &openpriv->fds;
   ```

##########
File path: drivers/input/uinput.c
##########
@@ -188,35 +476,45 @@ static void uinput_button_enable(FAR const struct btn_lowerhalf_s *lower,
  *
  ****************************************************************************/
 
-#ifdef CONFIG_INPUT_TOUCHSCREEN
+#ifdef CONFIG_UINPUT_TOUCHSCREEN
+
 int uinput_touch_initialize(FAR const char *name, int maxpoint, int buffnums)
 {
   char devname[UINPUT_NAME_SIZE];
-  FAR struct touch_lowerhalf_s *lower;
+  FAR struct uinput_touch_lowerhalf_s *utcs_lower;
   int ret;
 
-  lower = kmm_zalloc(sizeof(struct touch_lowerhalf_s));
-  if (!lower)
+  utcs_lower = kmm_zalloc(sizeof(struct uinput_touch_lowerhalf_s));
+  if (!utcs_lower)

Review comment:
       ```suggestion
     if (utcs_lower == NULL)
   ```

##########
File path: drivers/input/uinput.c
##########
@@ -21,42 +21,123 @@
 #include <nuttx/config.h>
 #include <sys/types.h>
 
+#include <assert.h>
+#include <debug.h>
 #include <errno.h>
 #include <stdio.h>
 
 #include <nuttx/input/buttons.h>
+#include <nuttx/input/keyboard.h>
 #include <nuttx/input/touchscreen.h>
 #include <nuttx/input/uinput.h>
 #include <nuttx/kmalloc.h>
 
+#ifdef CONFIG_UINPUT_RPMSG
+#include <nuttx/list.h>
+#include <nuttx/rptun/openamp.h>

Review comment:
       ```suggestion
   #  include <nuttx/list.h>
   #  include <nuttx/rptun/openamp.h>
   ```

##########
File path: drivers/input/touchscreen_upper.c
##########
@@ -366,34 +350,40 @@ static int touch_poll(FAR struct file *filep,
 void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
 {
   FAR struct touch_upperhalf_s *upper = priv;
+  FAR struct touch_openpriv_s  *openpriv;
   int semcount;
 
   if (nxsem_wait(&upper->exclsem) < 0)
     {
       return;
     }
 
-  circbuf_overwrite(&upper->buffer, sample,
-                    SIZEOF_TOUCH_SAMPLE_S(sample->npoints));
-  touch_notify(upper, POLLIN);
-  nxsem_get_value(&upper->buffersem, &semcount);
-  if (semcount < 1)
+  list_for_every_entry(&upper->head, openpriv, struct touch_openpriv_s, node)
     {
-      nxsem_post(&upper->buffersem);
+      circbuf_overwrite(&openpriv->circbuf, sample,
+                        SIZEOF_TOUCH_SAMPLE_S(sample->npoints));
+
+      nxsem_get_value(&openpriv->waitsem, &semcount);
+      if (semcount < 1)
+        {
+          nxsem_post(&openpriv->waitsem);
+        }
+
+      touch_notify(openpriv, POLLIN);
     }
 
   nxsem_post(&upper->exclsem);
 }
 
 int touch_register(FAR struct touch_lowerhalf_s *lower,
-                   FAR const char *path, uint8_t buff_nums)
+                   FAR const char *path, uint8_t nums)
 {
   FAR struct touch_upperhalf_s *upper;
   int ret;
 
   iinfo("Registering %s\n", path);
 
-  if (lower == NULL || !buff_nums)
+  if (lower == NULL || !nums)

Review comment:
       ```suggestion
     if (lower == NULL || nums == 0)
   ```




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