Re: [Xen-devel] [PATCH 06/25 v6] xen/arm: vpl011: Add a new domctl API to initialize vpl011

2017-07-18 Thread Stefano Stabellini
On Mon, 17 Jul 2017, Bhupinder Thakur wrote:
> Add a new domctl API to initialize vpl011. It takes the GFN and console
> backend domid as input and returns an event channel to be used for
> sending and receiving events from Xen.
> 
> Xen will communicate with xenconsole using GFN as the ring buffer and
> the event channel to transmit and receive pl011 data on the guest domain's
> behalf.
> 
> Signed-off-by: Bhupinder Thakur 
> ---
> CC: Ian Jackson 
> CC: Wei Liu 
> CC: Stefano Stabellini 
> CC: Julien Grall 
> 
> Changes since v5:
> - xc_dom_vpl011_init() will be compiled for both x86/arm architectures as 
> there
>   is nothing architecture specific in this function. This function will 
> return 
>   error when called for x86.
> - Fixed coding style issues in libxl.
> 
> Changes since v4:
> - Removed libxl__arch_domain_create_finish().
> - Added a new function libxl__arch_build_dom_finish(), which is called at the 
> last
>   in libxl__build_dom(). This function calls the vpl011 initialization 
> function now.
> 
> Changes since v3:
> - Added a new arch specific function libxl__arch_domain_create_finish(), which
>   calls the vpl011 initialization function. For x86 this function does not do
>   anything.
> - domain_vpl011_init() takes a pointer to a structure which contains all the 
>   required information such as console_domid, gfn instead of passing 
> parameters
>   separately.
> - Dropped a DOMCTL API defined for de-initializing vpl011 as that should be
>   taken care when the domain is destroyed (and not dependent on userspace 
>   libraries/applications).
> 
> Changes since v2:
> - Replaced the DOMCTL APIs defined for get/set of event channel and GFN with 
>   a set of DOMCTL APIs for initializing and de-initializing vpl011 emulation.
> 
>  tools/libxc/include/xenctrl.h | 18 ++
>  tools/libxc/xc_domain.c   | 24 
>  tools/libxl/libxl_arch.h  |  6 ++
>  tools/libxl/libxl_arm.c   | 20 
>  tools/libxl/libxl_dom.c   |  4 
>  tools/libxl/libxl_x86.c   |  8 
>  xen/arch/arm/domain.c |  5 +
>  xen/arch/arm/domctl.c | 37 +
>  xen/include/public/domctl.h   | 21 +
>  9 files changed, 143 insertions(+)
> 
> diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
> index c51bb3b..423c6f3 100644
> --- a/tools/libxc/include/xenctrl.h
> +++ b/tools/libxc/include/xenctrl.h
> @@ -886,6 +886,24 @@ int xc_vcpu_getcontext(xc_interface *xch,
> vcpu_guest_context_any_t *ctxt);
>  
>  /**
> + * This function initializes the vpl011 emulation and returns
> + * the event to be used by the backend for communicating with
> + * the emulation code.
> + *
> + * @parm xch a handle to an open hypervisor interface
> + * @parm domid the domain to get information from
> + * @parm console_domid the domid of the backend console
> + * @parm gfn the guest pfn to be used as the ring buffer
> + * @parm evtchn the event channel to be used for events
> + * @return 0 on success, negative error on failure
> + */
> +int xc_dom_vpl011_init(xc_interface *xch,
> +   domid_t domid,
> +   uint32_t console_domid,

Why is this uint32_t instead of domid_t?


> +   xen_pfn_t gfn,
> +   evtchn_port_t *evtchn);
> +
> +/**
>   * This function returns information about the XSAVE state of a particular
>   * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
>   * the call is considered a query to retrieve them and the buffer is not
> diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
> index 3bab4e8..fab3c5e 100644
> --- a/tools/libxc/xc_domain.c
> +++ b/tools/libxc/xc_domain.c
> @@ -343,6 +343,30 @@ int xc_domain_get_guest_width(xc_interface *xch, 
> uint32_t domid,
>  return 0;
>  }
>  
> +int xc_dom_vpl011_init(xc_interface *xch,
> +   domid_t domid,
> +   uint32_t console_domid,

same here of course


> +   xen_pfn_t gfn,
> +   evtchn_port_t *evtchn)
> +{
> +DECLARE_DOMCTL;
> +int rc = 0;
> +
> +domctl.cmd = XEN_DOMCTL_vuart_op;
> +domctl.domain = (domid_t)domid;
> +domctl.u.vuart_op.cmd = XEN_DOMCTL_VUART_OP_INIT;
> +domctl.u.vuart_op.type = XEN_DOMCTL_VUART_TYPE_VPL011;
> +domctl.u.vuart_op.console_domid = console_domid;
> +domctl.u.vuart_op.gfn = gfn;
> +
> +if ( (rc = do_domctl(xch, &domctl)) < 0 )
> +return rc;
> +
> +*evtchn = domctl.u.vuart_op.evtchn;
> +
> +return rc;
> +}
> +
>  int xc_domain_getinfo(xc_interface *xch,
>uint32_t first_domid,
>unsigned int max_doms,
> diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
> index 5e1fc60..118b92c 100644
> --- a/tools/libxl/libxl_arch.h
> +++ b/tools/libxl/libxl_arch.h
> @@ -44,6 +44,12

Re: [Xen-devel] [PATCH 06/25 v6] xen/arm: vpl011: Add a new domctl API to initialize vpl011

2017-07-17 Thread Julien Grall

Hi Bhupinder,

On 17/07/17 14:06, Bhupinder Thakur wrote:

Add a new domctl API to initialize vpl011. It takes the GFN and console
backend domid as input and returns an event channel to be used for
sending and receiving events from Xen.

Xen will communicate with xenconsole using GFN as the ring buffer and
the event channel to transmit and receive pl011 data on the guest domain's
behalf.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- xc_dom_vpl011_init() will be compiled for both x86/arm architectures as there
  is nothing architecture specific in this function. This function will return
  error when called for x86.
- Fixed coding style issues in libxl.

Changes since v4:
- Removed libxl__arch_domain_create_finish().
- Added a new function libxl__arch_build_dom_finish(), which is called at the 
last
  in libxl__build_dom(). This function calls the vpl011 initialization function 
now.

Changes since v3:
- Added a new arch specific function libxl__arch_domain_create_finish(), which
  calls the vpl011 initialization function. For x86 this function does not do
  anything.
- domain_vpl011_init() takes a pointer to a structure which contains all the
  required information such as console_domid, gfn instead of passing parameters
  separately.
- Dropped a DOMCTL API defined for de-initializing vpl011 as that should be
  taken care when the domain is destroyed (and not dependent on userspace
  libraries/applications).

Changes since v2:
- Replaced the DOMCTL APIs defined for get/set of event channel and GFN with
  a set of DOMCTL APIs for initializing and de-initializing vpl011 emulation.

 tools/libxc/include/xenctrl.h | 18 ++
 tools/libxc/xc_domain.c   | 24 
 tools/libxl/libxl_arch.h  |  6 ++
 tools/libxl/libxl_arm.c   | 20 
 tools/libxl/libxl_dom.c   |  4 
 tools/libxl/libxl_x86.c   |  8 
 xen/arch/arm/domain.c |  5 +
 xen/arch/arm/domctl.c | 37 +
 xen/include/public/domctl.h   | 21 +


You need to CC "THE REST" maintainers for this header.


 9 files changed, 143 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index c51bb3b..423c6f3 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -886,6 +886,24 @@ int xc_vcpu_getcontext(xc_interface *xch,
vcpu_guest_context_any_t *ctxt);

 /**
+ * This function initializes the vpl011 emulation and returns
+ * the event to be used by the backend for communicating with
+ * the emulation code.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm console_domid the domid of the backend console
+ * @parm gfn the guest pfn to be used as the ring buffer
+ * @parm evtchn the event channel to be used for events
+ * @return 0 on success, negative error on failure
+ */
+int xc_dom_vpl011_init(xc_interface *xch,
+   domid_t domid,
+   uint32_t console_domid,
+   xen_pfn_t gfn,
+   evtchn_port_t *evtchn);
+
+/**
  * This function returns information about the XSAVE state of a particular
  * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
  * the call is considered a query to retrieve them and the buffer is not
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 3bab4e8..fab3c5e 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -343,6 +343,30 @@ int xc_domain_get_guest_width(xc_interface *xch, uint32_t 
domid,
 return 0;
 }

+int xc_dom_vpl011_init(xc_interface *xch,


Do we really want to call this function xc_dom_vpl011_init? Would not it 
be future proof to call it xc_dom_vuart_init and add a type parameter?



+   domid_t domid,
+   uint32_t console_domid,
+   xen_pfn_t gfn,
+   evtchn_port_t *evtchn)
+{
+DECLARE_DOMCTL;
+int rc = 0;
+
+domctl.cmd = XEN_DOMCTL_vuart_op;
+domctl.domain = (domid_t)domid;
+domctl.u.vuart_op.cmd = XEN_DOMCTL_VUART_OP_INIT;
+domctl.u.vuart_op.type = XEN_DOMCTL_VUART_TYPE_VPL011;
+domctl.u.vuart_op.console_domid = console_domid;
+domctl.u.vuart_op.gfn = gfn;
+
+if ( (rc = do_domctl(xch, &domctl)) < 0 )
+return rc;
+
+*evtchn = domctl.u.vuart_op.evtchn;
+
+return rc;
+}
+
 int xc_domain_getinfo(xc_interface *xch,
   uint32_t first_domid,
   unsigned int max_doms,
diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 5e1fc60..118b92c 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -44,6 +44,12 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
   l

[Xen-devel] [PATCH 06/25 v6] xen/arm: vpl011: Add a new domctl API to initialize vpl011

2017-07-17 Thread Bhupinder Thakur
Add a new domctl API to initialize vpl011. It takes the GFN and console
backend domid as input and returns an event channel to be used for
sending and receiving events from Xen.

Xen will communicate with xenconsole using GFN as the ring buffer and
the event channel to transmit and receive pl011 data on the guest domain's
behalf.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- xc_dom_vpl011_init() will be compiled for both x86/arm architectures as there
  is nothing architecture specific in this function. This function will return 
  error when called for x86.
- Fixed coding style issues in libxl.

Changes since v4:
- Removed libxl__arch_domain_create_finish().
- Added a new function libxl__arch_build_dom_finish(), which is called at the 
last
  in libxl__build_dom(). This function calls the vpl011 initialization function 
now.

Changes since v3:
- Added a new arch specific function libxl__arch_domain_create_finish(), which
  calls the vpl011 initialization function. For x86 this function does not do
  anything.
- domain_vpl011_init() takes a pointer to a structure which contains all the 
  required information such as console_domid, gfn instead of passing parameters
  separately.
- Dropped a DOMCTL API defined for de-initializing vpl011 as that should be
  taken care when the domain is destroyed (and not dependent on userspace 
  libraries/applications).

Changes since v2:
- Replaced the DOMCTL APIs defined for get/set of event channel and GFN with 
  a set of DOMCTL APIs for initializing and de-initializing vpl011 emulation.

 tools/libxc/include/xenctrl.h | 18 ++
 tools/libxc/xc_domain.c   | 24 
 tools/libxl/libxl_arch.h  |  6 ++
 tools/libxl/libxl_arm.c   | 20 
 tools/libxl/libxl_dom.c   |  4 
 tools/libxl/libxl_x86.c   |  8 
 xen/arch/arm/domain.c |  5 +
 xen/arch/arm/domctl.c | 37 +
 xen/include/public/domctl.h   | 21 +
 9 files changed, 143 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index c51bb3b..423c6f3 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -886,6 +886,24 @@ int xc_vcpu_getcontext(xc_interface *xch,
vcpu_guest_context_any_t *ctxt);
 
 /**
+ * This function initializes the vpl011 emulation and returns
+ * the event to be used by the backend for communicating with
+ * the emulation code.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm console_domid the domid of the backend console
+ * @parm gfn the guest pfn to be used as the ring buffer
+ * @parm evtchn the event channel to be used for events
+ * @return 0 on success, negative error on failure
+ */
+int xc_dom_vpl011_init(xc_interface *xch,
+   domid_t domid,
+   uint32_t console_domid,
+   xen_pfn_t gfn,
+   evtchn_port_t *evtchn);
+
+/**
  * This function returns information about the XSAVE state of a particular
  * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
  * the call is considered a query to retrieve them and the buffer is not
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 3bab4e8..fab3c5e 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -343,6 +343,30 @@ int xc_domain_get_guest_width(xc_interface *xch, uint32_t 
domid,
 return 0;
 }
 
+int xc_dom_vpl011_init(xc_interface *xch,
+   domid_t domid,
+   uint32_t console_domid,
+   xen_pfn_t gfn,
+   evtchn_port_t *evtchn)
+{
+DECLARE_DOMCTL;
+int rc = 0;
+
+domctl.cmd = XEN_DOMCTL_vuart_op;
+domctl.domain = (domid_t)domid;
+domctl.u.vuart_op.cmd = XEN_DOMCTL_VUART_OP_INIT;
+domctl.u.vuart_op.type = XEN_DOMCTL_VUART_TYPE_VPL011;
+domctl.u.vuart_op.console_domid = console_domid;
+domctl.u.vuart_op.gfn = gfn;
+
+if ( (rc = do_domctl(xch, &domctl)) < 0 )
+return rc;
+
+*evtchn = domctl.u.vuart_op.evtchn;
+
+return rc;
+}
+
 int xc_domain_getinfo(xc_interface *xch,
   uint32_t first_domid,
   unsigned int max_doms,
diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 5e1fc60..118b92c 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -44,6 +44,12 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
   libxl_domain_build_info *info,
   struct xc_dom_image *dom);
 
+/* perform any pending hardware initialization */
+int libxl__arch_build_dom_finish(libxl__gc *gc,
+ libxl_domain_build_info *info,