3131#include <nuttx/rptun/rptun.h>
3232#include <nuttx/streams.h>
3333#include <nuttx/virtio/virtio.h>
34+ #include <nuttx/vhost/vhost.h>
3435#include <sys/boardctl.h>
3536#include <sys/ioctl.h>
3637#include <sys/param.h>
@@ -1110,13 +1111,13 @@ int cmd_ulimit(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11101111 * Name: cmd_virtio_usage
11111112 ****************************************************************************/
11121113
1113- #if defined(CONFIG_DRIVERS_VIRTIO ) && !defined(CONFIG_NSH_DISABLE_VIRTIO )
1114- static int cmd_virtio_usage (FAR struct nsh_vtbl_s * vtbl ,
1115- FAR char * * argv )
1114+ #if (defined(CONFIG_DRIVERS_VIRTIO ) && !defined(CONFIG_NSH_DISABLE_VIRTIO )) \
1115+ || (defined(CONFIG_DRIVERS_VHOST ) && !defined(CONFIG_NSH_DISABLE_VHOST ))
1116+ static int cmd_virtio_common_usage (FAR struct nsh_vtbl_s * vtbl ,
1117+ FAR char * * argv )
11161118{
11171119 nsh_output (vtbl , "Usage:\n" );
1118- nsh_output (vtbl , " %s dump [type] - Dump VirtIO device info\n" ,
1119- argv [0 ]);
1120+ nsh_output (vtbl , " %s dump [type] - Dump device info\n" , argv [0 ]);
11201121 nsh_output (vtbl , " %s -h - Show this help message\n\n" ,
11211122 argv [0 ]);
11221123 nsh_output (vtbl , "Supported types:\n" );
@@ -1134,16 +1135,14 @@ static int cmd_virtio_usage(FAR struct nsh_vtbl_s *vtbl,
11341135 nsh_output (vtbl , " Sound - Sound devices\n" );
11351136 nsh_output (vtbl , " RPMB - RPMB devices\n\n" );
11361137 nsh_output (vtbl , "Description:\n" );
1137- nsh_output (vtbl , " Display information about registered VirtIO \n" );
1138+ nsh_output (vtbl , " Display information about registered %s \n" , argv [ 0 ] );
11381139 nsh_output (vtbl , " devices. Output is sent to syslog.\n" );
11391140 return OK ;
11401141}
11411142
1142- /****************************************************************************
1143- * Name: cmd_virtio
1144- ****************************************************************************/
1145-
1146- int cmd_virtio (FAR struct nsh_vtbl_s * vtbl , int argc , FAR char * * argv )
1143+ static int cmd_virtio_common (FAR struct nsh_vtbl_s * vtbl , int argc ,
1144+ FAR char * * argv , FAR const char * devpath ,
1145+ int ioc_cmd )
11471146{
11481147 FAR const char * dev_name = NULL ;
11491148 int fd ;
@@ -1156,7 +1155,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11561155 }
11571156 else if (strcmp (argv [1 ], "-h" ) == 0 )
11581157 {
1159- return cmd_virtio_usage (vtbl , argv );
1158+ return cmd_virtio_common_usage (vtbl , argv );
11601159 }
11611160 else if (strcmp (argv [1 ], "dump" ) != 0 )
11621161 {
@@ -1171,7 +1170,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11711170 dev_name = argv [2 ];
11721171 }
11731172
1174- fd = open ("/dev/virtio" , O_CLOEXEC );
1173+ fd = open (devpath , O_CLOEXEC );
11751174 if (fd < 0 )
11761175 {
11771176 nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "open" , NSH_ERRNO );
@@ -1180,7 +1179,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11801179
11811180 /* Pass type name string to kernel, kernel will parse it */
11821181
1183- ret = ioctl (fd , VIRTIOIOC_DUMP , (unsigned long )dev_name );
1182+ ret = ioctl (fd , ioc_cmd , (unsigned long )dev_name );
11841183 close (fd );
11851184
11861185 if (ret < 0 )
@@ -1192,3 +1191,25 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11921191 return OK ;
11931192}
11941193#endif
1194+
1195+ /****************************************************************************
1196+ * Name: cmd_virtio
1197+ ****************************************************************************/
1198+
1199+ #if defined(CONFIG_DRIVERS_VIRTIO ) && !defined(CONFIG_NSH_DISABLE_VIRTIO )
1200+ int cmd_virtio (FAR struct nsh_vtbl_s * vtbl , int argc , FAR char * * argv )
1201+ {
1202+ return cmd_virtio_common (vtbl , argc , argv , "/dev/virtio" , VIRTIOIOC_DUMP );
1203+ }
1204+ #endif
1205+
1206+ /****************************************************************************
1207+ * Name: cmd_vhost
1208+ ****************************************************************************/
1209+
1210+ #if defined(CONFIG_DRIVERS_VHOST ) && !defined(CONFIG_NSH_DISABLE_VHOST )
1211+ int cmd_vhost (FAR struct nsh_vtbl_s * vtbl , int argc , FAR char * * argv )
1212+ {
1213+ return cmd_virtio_common (vtbl , argc , argv , "/dev/vhost" , VHOSTIOC_DUMP );
1214+ }
1215+ #endif
0 commit comments