diff mbox series

[Xen-devel,09/17,v5] xen/arm: vpl011: Add a new vuart node in the xenstore

Message ID 1498117132-27139-10-git-send-email-bhupinder.thakur@linaro.org
State Superseded
Headers show
Series SBSA UART emulation support in Xen | expand

Commit Message

Bhupinder Thakur June 22, 2017, 7:38 a.m. UTC
Add a new vuart console node to xenstore. This node is added at

/local/domain/$DOMID/vuart/0.

The node contains information such as the ring-ref, event channel,
buffer limit and type of console.

Xenconsole reads the node information to setup the ring buffer and
event channel for sending/receiving vuart data.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
---
CC: Ian Jackson <ian.jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien.grall@arm.com>

Changes since v4:
-  vuart_device moved inside libxl__device_vuart_add() as a local variable.

Changes since v3:
- Added a backend node for vpl011.
- Removed libxl__device_vuart_add() for HVM guest. It is called only for PV guest.

 tools/libxl/libxl_console.c          | 44 ++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_create.c           | 10 +++++++-
 tools/libxl/libxl_device.c           |  9 ++++++--
 tools/libxl/libxl_internal.h         |  3 +++
 tools/libxl/libxl_types_internal.idl |  1 +
 5 files changed, 64 insertions(+), 3 deletions(-)

Comments

Stefano Stabellini June 22, 2017, 11:06 p.m. UTC | #1
On Thu, 22 Jun 2017, Bhupinder Thakur wrote:
> Add a new vuart console node to xenstore. This node is added at
> 
> /local/domain/$DOMID/vuart/0.
> 
> The node contains information such as the ring-ref, event channel,
> buffer limit and type of console.
> 
> Xenconsole reads the node information to setup the ring buffer and
> event channel for sending/receiving vuart data.
> 
> Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> CC: Ian Jackson <ian.jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien.grall@arm.com>
> 
> Changes since v4:
> -  vuart_device moved inside libxl__device_vuart_add() as a local variable.
> 
> Changes since v3:
> - Added a backend node for vpl011.
> - Removed libxl__device_vuart_add() for HVM guest. It is called only for PV guest.
> 
>  tools/libxl/libxl_console.c          | 44 ++++++++++++++++++++++++++++++++++++
>  tools/libxl/libxl_create.c           | 10 +++++++-
>  tools/libxl/libxl_device.c           |  9 ++++++--
>  tools/libxl/libxl_internal.h         |  3 +++
>  tools/libxl/libxl_types_internal.idl |  1 +
>  5 files changed, 64 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
> index 853be15..cdaf7fd 100644
> --- a/tools/libxl/libxl_console.c
> +++ b/tools/libxl/libxl_console.c
> @@ -344,6 +344,50 @@ out:
>      return rc;
>  }
>  
> +int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
> +                            libxl__device_console *console,
> +                            libxl__domain_build_state *state)
> +{
> +    libxl__device device;
> +    flexarray_t *ro_front;
> +    flexarray_t *back;
> +    int rc;
> +
> +    ro_front = flexarray_make(gc, 16, 1);
> +    back = flexarray_make(gc, 16, 1);
> +
> +    device.backend_devid = console->devid;
> +    device.backend_domid = console->backend_domid;
> +    device.backend_kind = LIBXL__DEVICE_KIND_VUART;
> +    device.devid = console->devid;
> +    device.domid = domid;
> +    device.kind = LIBXL__DEVICE_KIND_VUART;
> +
> +    flexarray_append(back, "frontend-id");
> +    flexarray_append(back, GCSPRINTF("%d", domid));
> +    flexarray_append(back, "online");
> +    flexarray_append(back, "1");
> +    flexarray_append(back, "state");
> +    flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising));
> +    flexarray_append(back, "protocol");
> +    flexarray_append(back, LIBXL_XENCONSOLE_PROTOCOL);
> +
> +    flexarray_append(ro_front, "port");
> +    flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
> +    flexarray_append(ro_front, "ring-ref");
> +    flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
> +    flexarray_append(ro_front, "limit");
> +    flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
> +    flexarray_append(ro_front, "type");
> +    flexarray_append(ro_front, "xenconsoled");
> +
> +    rc = libxl__device_generic_add(gc, XBT_NULL, &device,
> +                                   libxl__xs_kvs_of_flexarray(gc, back),
> +                                   NULL,
> +                                   libxl__xs_kvs_of_flexarray(gc, ro_front));
> +    return rc;
> +}
> +
>  int libxl__init_console_from_channel(libxl__gc *gc,
>                                       libxl__device_console *console,
>                                       int dev_num,
> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
> index bffbc45..cfd85ec 100644
> --- a/tools/libxl/libxl_create.c
> +++ b/tools/libxl/libxl_create.c
> @@ -1367,7 +1367,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
>      }
>      case LIBXL_DOMAIN_TYPE_PV:
>      {
> -        libxl__device_console console;
> +        libxl__device_console console, vuart;
>          libxl__device device;
>  
>          for (i = 0; i < d_config->num_vfbs; i++) {
> @@ -1375,6 +1375,14 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
>              libxl__device_vkb_add(gc, domid, &d_config->vkbs[i]);
>          }
>  
> +        if (d_config->b_info.arch_arm.vuart)
> +        {
> +            init_console_info(gc, &vuart, 0);
> +            vuart.backend_domid = state->console_domid;
> +            libxl__device_vuart_add(gc, domid, &vuart, state);
> +            libxl__device_console_dispose(&vuart);
> +        }
> +
>          init_console_info(gc, &console, 0);
>          console.backend_domid = state->console_domid;
>          libxl__device_console_add(gc, domid, &console, state, &device);
> diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
> index 00356af..3b10c58 100644
> --- a/tools/libxl/libxl_device.c
> +++ b/tools/libxl/libxl_device.c
> @@ -26,6 +26,9 @@ static char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
>      if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
>          return GCSPRINTF("%s/console", dom_path);
>  
> +    if (device->kind == LIBXL__DEVICE_KIND_VUART)
> +        return GCSPRINTF("%s/vuart/%d", dom_path, device->devid);
> +
>      return GCSPRINTF("%s/device/%s/%d", dom_path,
>                       libxl__device_kind_to_string(device->kind),
>                       device->devid);
> @@ -170,7 +173,8 @@ retry_transaction:
>           * historically contained other information, such as the
>           * vnc-port, which we don't want the guest fiddling with.
>           */
> -        if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
> +        if ((device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0) ||
> +            (device->kind == LIBXL__DEVICE_KIND_VUART))
>              xs_set_permissions(ctx->xsh, t, frontend_path,
>                                 ro_frontend_perms, ARRAY_SIZE(ro_frontend_perms));
>          else
> @@ -800,7 +804,8 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs)
>                  dev->domid = domid;
>                  dev->kind = kind;
>                  dev->devid = atoi(devs[j]);
> -                if (dev->backend_kind == LIBXL__DEVICE_KIND_CONSOLE) {
> +                if (dev->backend_kind == LIBXL__DEVICE_KIND_CONSOLE ||
> +                    dev->backend_kind == LIBXL__DEVICE_KIND_VUART) {
>                      /* Currently console devices can be destroyed
>                       * synchronously by just removing xenstore entries,
>                       * this is what libxl__device_destroy does.
> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> index d0d50c3..2b3f4e1 100644
> --- a/tools/libxl/libxl_internal.h
> +++ b/tools/libxl/libxl_internal.h
> @@ -1206,6 +1206,9 @@ _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
>                                        libxl__device_console *console,
>                                        libxl__domain_build_state *state,
>                                        libxl__device *device);
> +_hidden int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
> +                                    libxl__device_console *console,
> +                                    libxl__domain_build_state *state);
>  
>  /* Returns 1 if device exists, 0 if not, ERROR_* (<0) on error. */
>  _hidden int libxl__device_exists(libxl__gc *gc, xs_transaction_t t,
> diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl
> index 7dc4d0f..c463c33 100644
> --- a/tools/libxl/libxl_types_internal.idl
> +++ b/tools/libxl/libxl_types_internal.idl
> @@ -26,6 +26,7 @@ libxl__device_kind = Enumeration("device_kind", [
>      (9, "VUSB"),
>      (10, "QUSB"),
>      (11, "9PFS"),
> +    (12, "VUART"),
>      ])
>  
>  libxl__console_backend = Enumeration("console_backend", [
> -- 
> 2.7.4
>
Wei Liu June 28, 2017, 5:16 p.m. UTC | #2
On Thu, Jun 22, 2017 at 01:08:44PM +0530, Bhupinder Thakur wrote:
> Add a new vuart console node to xenstore. This node is added at
> 
> /local/domain/$DOMID/vuart/0.
> 
> The node contains information such as the ring-ref, event channel,
> buffer limit and type of console.
> 
> Xenconsole reads the node information to setup the ring buffer and
> event channel for sending/receiving vuart data.
> 
> Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>

Acked-by: Wei Liu <wei.liu2@citrix.com>

Only one nit below.

[...]
> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
> index bffbc45..cfd85ec 100644
> --- a/tools/libxl/libxl_create.c
> +++ b/tools/libxl/libxl_create.c
> @@ -1367,7 +1367,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
>      }
>      case LIBXL_DOMAIN_TYPE_PV:
>      {
> -        libxl__device_console console;
> +        libxl__device_console console, vuart;
>          libxl__device device;
>  
>          for (i = 0; i < d_config->num_vfbs; i++) {
> @@ -1375,6 +1375,14 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
>              libxl__device_vkb_add(gc, domid, &d_config->vkbs[i]);
>          }
>  
> +        if (d_config->b_info.arch_arm.vuart)
> +        {

Please move this to previous line.
diff mbox series

Patch

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 853be15..cdaf7fd 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -344,6 +344,50 @@  out:
     return rc;
 }
 
+int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
+                            libxl__device_console *console,
+                            libxl__domain_build_state *state)
+{
+    libxl__device device;
+    flexarray_t *ro_front;
+    flexarray_t *back;
+    int rc;
+
+    ro_front = flexarray_make(gc, 16, 1);
+    back = flexarray_make(gc, 16, 1);
+
+    device.backend_devid = console->devid;
+    device.backend_domid = console->backend_domid;
+    device.backend_kind = LIBXL__DEVICE_KIND_VUART;
+    device.devid = console->devid;
+    device.domid = domid;
+    device.kind = LIBXL__DEVICE_KIND_VUART;
+
+    flexarray_append(back, "frontend-id");
+    flexarray_append(back, GCSPRINTF("%d", domid));
+    flexarray_append(back, "online");
+    flexarray_append(back, "1");
+    flexarray_append(back, "state");
+    flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append(back, "protocol");
+    flexarray_append(back, LIBXL_XENCONSOLE_PROTOCOL);
+
+    flexarray_append(ro_front, "port");
+    flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
+    flexarray_append(ro_front, "ring-ref");
+    flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
+    flexarray_append(ro_front, "limit");
+    flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
+    flexarray_append(ro_front, "type");
+    flexarray_append(ro_front, "xenconsoled");
+
+    rc = libxl__device_generic_add(gc, XBT_NULL, &device,
+                                   libxl__xs_kvs_of_flexarray(gc, back),
+                                   NULL,
+                                   libxl__xs_kvs_of_flexarray(gc, ro_front));
+    return rc;
+}
+
 int libxl__init_console_from_channel(libxl__gc *gc,
                                      libxl__device_console *console,
                                      int dev_num,
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index bffbc45..cfd85ec 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1367,7 +1367,7 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
     }
     case LIBXL_DOMAIN_TYPE_PV:
     {
-        libxl__device_console console;
+        libxl__device_console console, vuart;
         libxl__device device;
 
         for (i = 0; i < d_config->num_vfbs; i++) {
@@ -1375,6 +1375,14 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
             libxl__device_vkb_add(gc, domid, &d_config->vkbs[i]);
         }
 
+        if (d_config->b_info.arch_arm.vuart)
+        {
+            init_console_info(gc, &vuart, 0);
+            vuart.backend_domid = state->console_domid;
+            libxl__device_vuart_add(gc, domid, &vuart, state);
+            libxl__device_console_dispose(&vuart);
+        }
+
         init_console_info(gc, &console, 0);
         console.backend_domid = state->console_domid;
         libxl__device_console_add(gc, domid, &console, state, &device);
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 00356af..3b10c58 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -26,6 +26,9 @@  static char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
     if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
         return GCSPRINTF("%s/console", dom_path);
 
+    if (device->kind == LIBXL__DEVICE_KIND_VUART)
+        return GCSPRINTF("%s/vuart/%d", dom_path, device->devid);
+
     return GCSPRINTF("%s/device/%s/%d", dom_path,
                      libxl__device_kind_to_string(device->kind),
                      device->devid);
@@ -170,7 +173,8 @@  retry_transaction:
          * historically contained other information, such as the
          * vnc-port, which we don't want the guest fiddling with.
          */
-        if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
+        if ((device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0) ||
+            (device->kind == LIBXL__DEVICE_KIND_VUART))
             xs_set_permissions(ctx->xsh, t, frontend_path,
                                ro_frontend_perms, ARRAY_SIZE(ro_frontend_perms));
         else
@@ -800,7 +804,8 @@  void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs)
                 dev->domid = domid;
                 dev->kind = kind;
                 dev->devid = atoi(devs[j]);
-                if (dev->backend_kind == LIBXL__DEVICE_KIND_CONSOLE) {
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_CONSOLE ||
+                    dev->backend_kind == LIBXL__DEVICE_KIND_VUART) {
                     /* Currently console devices can be destroyed
                      * synchronously by just removing xenstore entries,
                      * this is what libxl__device_destroy does.
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index d0d50c3..2b3f4e1 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1206,6 +1206,9 @@  _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
                                       libxl__device_console *console,
                                       libxl__domain_build_state *state,
                                       libxl__device *device);
+_hidden int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
+                                    libxl__device_console *console,
+                                    libxl__domain_build_state *state);
 
 /* Returns 1 if device exists, 0 if not, ERROR_* (<0) on error. */
 _hidden int libxl__device_exists(libxl__gc *gc, xs_transaction_t t,
diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl
index 7dc4d0f..c463c33 100644
--- a/tools/libxl/libxl_types_internal.idl
+++ b/tools/libxl/libxl_types_internal.idl
@@ -26,6 +26,7 @@  libxl__device_kind = Enumeration("device_kind", [
     (9, "VUSB"),
     (10, "QUSB"),
     (11, "9PFS"),
+    (12, "VUART"),
     ])
 
 libxl__console_backend = Enumeration("console_backend", [