Re: [PATCH 07/17] serial: serial_xen: Add Xen PV serial driver

2020-07-03 Thread Anastasiia Lukianenko
Hello Simon,

On Thu, 2020-07-02 at 21:50 -0600, Simon Glass wrote:
> Hi Anastasiia,
> 
> On Wed, 1 Jul 2020 at 10:30, Anastasiia Lukianenko <
> vicooo...@gmail.com> wrote:
> > 
> > From: Peng Fan 
> > 
> > Add support for Xen para-virtualized serial driver. This
> > driver fully supports serial console for the virtual machine.
> > 
> > Please note that as the driver is initialized late, so no banner
> > nor memory size is visible.
> > 
> > Signed-off-by: Peng Fan 
> > Signed-off-by: Oleksandr Andrushchenko <
> > oleksandr_andrushche...@epam.com>
> > Signed-off-by: Anastasiia Lukianenko <
> > anastasiia_lukiane...@epam.com>
> > ---
> >  arch/arm/Kconfig  |   1 +
> >  board/xen/xenguest_arm64/xenguest_arm64.c |  31 +++-
> >  configs/xenguest_arm64_defconfig  |   4 +-
> >  drivers/serial/Kconfig|   7 +
> >  drivers/serial/Makefile   |   1 +
> >  drivers/serial/serial_xen.c   | 175
> > ++
> >  drivers/xen/events.c  |   4 +
> >  7 files changed, 214 insertions(+), 9 deletions(-)
> >  create mode 100644 drivers/serial/serial_xen.c
> 
> Reviewed-by: Simon Glass 
> 
> nits below
> 
> > 
> > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> > index c469863967..d4de1139aa 100644
> > --- a/arch/arm/Kconfig
> > +++ b/arch/arm/Kconfig
> > @@ -1723,6 +1723,7 @@ config TARGET_XENGUEST_ARM64
> > select XEN
> > select OF_CONTROL
> > select LINUX_KERNEL_IMAGE_HEADER
> > +   select XEN_SERIAL
> >  endchoice
> > 
> >  config ARCH_SUPPORT_TFABOOT
> > diff --git a/board/xen/xenguest_arm64/xenguest_arm64.c
> > b/board/xen/xenguest_arm64/xenguest_arm64.c
> > index 9e099f388f..fd10a002e9 100644
> > --- a/board/xen/xenguest_arm64/xenguest_arm64.c
> > +++ b/board/xen/xenguest_arm64/xenguest_arm64.c
> > @@ -18,9 +18,12 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > 
> >  #include 
> > 
> > +#include 
> > +
> >  DECLARE_GLOBAL_DATA_PTR;
> > 
> >  int board_init(void)
> > @@ -57,9 +60,28 @@ static int get_next_memory_node(const void
> > *blob, int mem)
> > 
> >  static int setup_mem_map(void)
> >  {
> > -   int i, ret, mem, reg = 0;
> > +   int i = 0, ret, mem, reg = 0;
> > struct fdt_resource res;
> > const void *blob = gd->fdt_blob;
> > +   u64 gfn;
> > +
> > +   /*
> > +* Add "magic" region which is used by Xen to provide some
> > essentials
> > +* for the guest: we need console.
> > +*/
> > +   ret =
> > hvm_get_parameter_maintain_dcache(HVM_PARAM_CONSOLE_PFN, );
> > +   if (ret < 0) {
> > +   printf("%s: Can't get HVM_PARAM_CONSOLE_PFN, ret
> > %d\n",
> > +  __func__, ret);
> > +   return -EINVAL;
> > +   }
> > +
> > +   xen_mem_map[i].virt = PFN_PHYS(gfn);
> > +   xen_mem_map[i].phys = PFN_PHYS(gfn);
> > +   xen_mem_map[i].size = PAGE_SIZE;
> > +   xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
> > +   PTE_BLOCK_INNER_SHARE);
> > +   i++;
> > 
> > mem = get_next_memory_node(blob, -1);
> > if (mem < 0) {
> > @@ -67,7 +89,7 @@ static int setup_mem_map(void)
> > return -EINVAL;
> > }
> > 
> > -   for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) {
> > +   for (; i < MAX_MEM_MAP_REGIONS; i++) {
> > ret = fdt_get_resource(blob, mem, "reg", reg++,
> > );
> > if (ret == -FDT_ERR_NOTFOUND) {
> > reg = 0;
> > @@ -146,8 +168,3 @@ int print_cpuinfo(void)
> > return 0;
> >  }
> > 
> > -__weak struct serial_device *default_serial_console(void)
> > -{
> > -   return NULL;
> > -}
> > -
> > diff --git a/configs/xenguest_arm64_defconfig
> > b/configs/xenguest_arm64_defconfig
> > index 2a8caf8647..45559a161b 100644
> > --- a/configs/xenguest_arm64_defconfig
> > +++ b/configs/xenguest_arm64_defconfig
> > @@ -47,9 +47,9 @@ CONFIG_CMD_UMS=n
> >  #CONFIG_EFI_PARTITION=y
> >  # CONFIG_EFI_LOADER is not set
> > 
> > -# CONFIG_DM is not set
> > +CONFIG_DM=y
> >  # CONFIG_MMC is not set
> > -# CONFIG_DM_SERIAL is not set
> > +CONFIG_DM_SERIAL=y
> >  # CONFIG_REQUIRE_SERIAL_CONSOLE is not set
> > 
> >  CONFIG_OF_BOARD=y
> > diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> > index 17d0e73623..33c989a66d 100644
> > --- a/drivers/serial/Kconfig
> > +++ b/drivers/serial/Kconfig
> > @@ -821,6 +821,13 @@ config MPC8XX_CONS
> > depends on MPC8xx
> > default y
> > 
> > +config XEN_SERIAL
> > +   bool "XEN serial support"
> > +   depends on XEN
> > +   help
> > + If built without DM support, then requires Xen
> > + to be built with CONFIG_VERBOSE_DEBUG.
> 
> Yes but what does it do? Also should probably not support non-DM at
> this point.
> 

This will be removed at all as only DM based drivers are added.

> > +
> >  choice
> > prompt "Console port"
> > 

Re: [PATCH 07/17] serial: serial_xen: Add Xen PV serial driver

2020-07-02 Thread Simon Glass
Hi Anastasiia,

On Wed, 1 Jul 2020 at 10:30, Anastasiia Lukianenko  wrote:
>
> From: Peng Fan 
>
> Add support for Xen para-virtualized serial driver. This
> driver fully supports serial console for the virtual machine.
>
> Please note that as the driver is initialized late, so no banner
> nor memory size is visible.
>
> Signed-off-by: Peng Fan 
> Signed-off-by: Oleksandr Andrushchenko 
> Signed-off-by: Anastasiia Lukianenko 
> ---
>  arch/arm/Kconfig  |   1 +
>  board/xen/xenguest_arm64/xenguest_arm64.c |  31 +++-
>  configs/xenguest_arm64_defconfig  |   4 +-
>  drivers/serial/Kconfig|   7 +
>  drivers/serial/Makefile   |   1 +
>  drivers/serial/serial_xen.c   | 175 ++
>  drivers/xen/events.c  |   4 +
>  7 files changed, 214 insertions(+), 9 deletions(-)
>  create mode 100644 drivers/serial/serial_xen.c

Reviewed-by: Simon Glass 

nits below

>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index c469863967..d4de1139aa 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1723,6 +1723,7 @@ config TARGET_XENGUEST_ARM64
> select XEN
> select OF_CONTROL
> select LINUX_KERNEL_IMAGE_HEADER
> +   select XEN_SERIAL
>  endchoice
>
>  config ARCH_SUPPORT_TFABOOT
> diff --git a/board/xen/xenguest_arm64/xenguest_arm64.c 
> b/board/xen/xenguest_arm64/xenguest_arm64.c
> index 9e099f388f..fd10a002e9 100644
> --- a/board/xen/xenguest_arm64/xenguest_arm64.c
> +++ b/board/xen/xenguest_arm64/xenguest_arm64.c
> @@ -18,9 +18,12 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>
> +#include 
> +
>  DECLARE_GLOBAL_DATA_PTR;
>
>  int board_init(void)
> @@ -57,9 +60,28 @@ static int get_next_memory_node(const void *blob, int mem)
>
>  static int setup_mem_map(void)
>  {
> -   int i, ret, mem, reg = 0;
> +   int i = 0, ret, mem, reg = 0;
> struct fdt_resource res;
> const void *blob = gd->fdt_blob;
> +   u64 gfn;
> +
> +   /*
> +* Add "magic" region which is used by Xen to provide some essentials
> +* for the guest: we need console.
> +*/
> +   ret = hvm_get_parameter_maintain_dcache(HVM_PARAM_CONSOLE_PFN, );
> +   if (ret < 0) {
> +   printf("%s: Can't get HVM_PARAM_CONSOLE_PFN, ret %d\n",
> +  __func__, ret);
> +   return -EINVAL;
> +   }
> +
> +   xen_mem_map[i].virt = PFN_PHYS(gfn);
> +   xen_mem_map[i].phys = PFN_PHYS(gfn);
> +   xen_mem_map[i].size = PAGE_SIZE;
> +   xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
> +   PTE_BLOCK_INNER_SHARE);
> +   i++;
>
> mem = get_next_memory_node(blob, -1);
> if (mem < 0) {
> @@ -67,7 +89,7 @@ static int setup_mem_map(void)
> return -EINVAL;
> }
>
> -   for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) {
> +   for (; i < MAX_MEM_MAP_REGIONS; i++) {
> ret = fdt_get_resource(blob, mem, "reg", reg++, );
> if (ret == -FDT_ERR_NOTFOUND) {
> reg = 0;
> @@ -146,8 +168,3 @@ int print_cpuinfo(void)
> return 0;
>  }
>
> -__weak struct serial_device *default_serial_console(void)
> -{
> -   return NULL;
> -}
> -
> diff --git a/configs/xenguest_arm64_defconfig 
> b/configs/xenguest_arm64_defconfig
> index 2a8caf8647..45559a161b 100644
> --- a/configs/xenguest_arm64_defconfig
> +++ b/configs/xenguest_arm64_defconfig
> @@ -47,9 +47,9 @@ CONFIG_CMD_UMS=n
>  #CONFIG_EFI_PARTITION=y
>  # CONFIG_EFI_LOADER is not set
>
> -# CONFIG_DM is not set
> +CONFIG_DM=y
>  # CONFIG_MMC is not set
> -# CONFIG_DM_SERIAL is not set
> +CONFIG_DM_SERIAL=y
>  # CONFIG_REQUIRE_SERIAL_CONSOLE is not set
>
>  CONFIG_OF_BOARD=y
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index 17d0e73623..33c989a66d 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -821,6 +821,13 @@ config MPC8XX_CONS
> depends on MPC8xx
> default y
>
> +config XEN_SERIAL
> +   bool "XEN serial support"
> +   depends on XEN
> +   help
> + If built without DM support, then requires Xen
> + to be built with CONFIG_VERBOSE_DEBUG.

Yes but what does it do? Also should probably not support non-DM at this point.

> +
>  choice
> prompt "Console port"
> default 8xx_CONS_SMC1
> diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> index e4a927..25f7f8d342 100644
> --- a/drivers/serial/Makefile
> +++ b/drivers/serial/Makefile
> @@ -70,6 +70,7 @@ obj-$(CONFIG_OWL_SERIAL) += serial_owl.o
>  obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
>  obj-$(CONFIG_MTK_SERIAL) += serial_mtk.o
>  obj-$(CONFIG_SIFIVE_SERIAL) += serial_sifive.o
> +obj-$(CONFIG_XEN_SERIAL) += serial_xen.o
>
>  ifndef CONFIG_SPL_BUILD
>  obj-$(CONFIG_USB_TTY) += usbtty.o
> diff --git a/drivers/serial/serial_xen.c 

[PATCH 07/17] serial: serial_xen: Add Xen PV serial driver

2020-07-02 Thread Anastasiia Lukianenko
From: Peng Fan 

Add support for Xen para-virtualized serial driver. This
driver fully supports serial console for the virtual machine.

Please note that as the driver is initialized late, so no banner
nor memory size is visible.

Signed-off-by: Peng Fan 
Signed-off-by: Oleksandr Andrushchenko 
Signed-off-by: Anastasiia Lukianenko 
---
 arch/arm/Kconfig  |   1 +
 board/xen/xenguest_arm64/xenguest_arm64.c |  31 +++-
 configs/xenguest_arm64_defconfig  |   4 +-
 drivers/serial/Kconfig|   7 +
 drivers/serial/Makefile   |   1 +
 drivers/serial/serial_xen.c   | 175 ++
 drivers/xen/events.c  |   4 +
 7 files changed, 214 insertions(+), 9 deletions(-)
 create mode 100644 drivers/serial/serial_xen.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c469863967..d4de1139aa 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1723,6 +1723,7 @@ config TARGET_XENGUEST_ARM64
select XEN
select OF_CONTROL
select LINUX_KERNEL_IMAGE_HEADER
+   select XEN_SERIAL
 endchoice
 
 config ARCH_SUPPORT_TFABOOT
diff --git a/board/xen/xenguest_arm64/xenguest_arm64.c 
b/board/xen/xenguest_arm64/xenguest_arm64.c
index 9e099f388f..fd10a002e9 100644
--- a/board/xen/xenguest_arm64/xenguest_arm64.c
+++ b/board/xen/xenguest_arm64/xenguest_arm64.c
@@ -18,9 +18,12 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
+#include 
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
@@ -57,9 +60,28 @@ static int get_next_memory_node(const void *blob, int mem)
 
 static int setup_mem_map(void)
 {
-   int i, ret, mem, reg = 0;
+   int i = 0, ret, mem, reg = 0;
struct fdt_resource res;
const void *blob = gd->fdt_blob;
+   u64 gfn;
+
+   /*
+* Add "magic" region which is used by Xen to provide some essentials
+* for the guest: we need console.
+*/
+   ret = hvm_get_parameter_maintain_dcache(HVM_PARAM_CONSOLE_PFN, );
+   if (ret < 0) {
+   printf("%s: Can't get HVM_PARAM_CONSOLE_PFN, ret %d\n",
+  __func__, ret);
+   return -EINVAL;
+   }
+
+   xen_mem_map[i].virt = PFN_PHYS(gfn);
+   xen_mem_map[i].phys = PFN_PHYS(gfn);
+   xen_mem_map[i].size = PAGE_SIZE;
+   xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+   PTE_BLOCK_INNER_SHARE);
+   i++;
 
mem = get_next_memory_node(blob, -1);
if (mem < 0) {
@@ -67,7 +89,7 @@ static int setup_mem_map(void)
return -EINVAL;
}
 
-   for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) {
+   for (; i < MAX_MEM_MAP_REGIONS; i++) {
ret = fdt_get_resource(blob, mem, "reg", reg++, );
if (ret == -FDT_ERR_NOTFOUND) {
reg = 0;
@@ -146,8 +168,3 @@ int print_cpuinfo(void)
return 0;
 }
 
-__weak struct serial_device *default_serial_console(void)
-{
-   return NULL;
-}
-
diff --git a/configs/xenguest_arm64_defconfig b/configs/xenguest_arm64_defconfig
index 2a8caf8647..45559a161b 100644
--- a/configs/xenguest_arm64_defconfig
+++ b/configs/xenguest_arm64_defconfig
@@ -47,9 +47,9 @@ CONFIG_CMD_UMS=n
 #CONFIG_EFI_PARTITION=y
 # CONFIG_EFI_LOADER is not set
 
-# CONFIG_DM is not set
+CONFIG_DM=y
 # CONFIG_MMC is not set
-# CONFIG_DM_SERIAL is not set
+CONFIG_DM_SERIAL=y
 # CONFIG_REQUIRE_SERIAL_CONSOLE is not set
 
 CONFIG_OF_BOARD=y
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 17d0e73623..33c989a66d 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -821,6 +821,13 @@ config MPC8XX_CONS
depends on MPC8xx
default y
 
+config XEN_SERIAL
+   bool "XEN serial support"
+   depends on XEN
+   help
+ If built without DM support, then requires Xen
+ to be built with CONFIG_VERBOSE_DEBUG.
+
 choice
prompt "Console port"
default 8xx_CONS_SMC1
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index e4a927..25f7f8d342 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_OWL_SERIAL) += serial_owl.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_MTK_SERIAL) += serial_mtk.o
 obj-$(CONFIG_SIFIVE_SERIAL) += serial_sifive.o
+obj-$(CONFIG_XEN_SERIAL) += serial_xen.o
 
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_USB_TTY) += usbtty.o
diff --git a/drivers/serial/serial_xen.c b/drivers/serial/serial_xen.c
new file mode 100644
index 00..dcd4b2df79
--- /dev/null
+++ b/drivers/serial/serial_xen.c
@@ -0,0 +1,175 @@
+/*
+ * SPDX-License-Identifier:GPL-2.0+
+ *
+ * (C) 2018 NXP
+ * (C) 2020 EPAM Systems Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+u32 console_evtchn;
+
+struct xen_uart_priv {
+   struct