Skip to contentSkip to conversation

Add new board: Xen guest for ARM64

PATCH Superseded Anastasiia Lukianenko 7 participants 57 messages Jul 1, 2020 – Jul 16, 2020 Page 2 of 2

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#35 lore raw

PATCH 11/17 xen: Port Xen grant table driver from mini-os

In reply to Anastasiia Lukianenko
Quoted 142 lines · Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Make required updates to run on u-boot.

---
  board/xen/xenguest_arm64/xenguest_arm64.c |  13 ++
  drivers/xen/Makefile                      |   1 +
  drivers/xen/gnttab.c                      | 258 ++++++++++++++++++++++
  drivers/xen/hypervisor.c                  |   2 +
  include/xen/gnttab.h                      |  25 +++
  5 files changed, 299 insertions(+)

create mode 100644 drivers/xen/gnttab.c
create mode 100644 include/xen/gnttab.h

board/xen/xenguest_arm64/xenguest_arm64.c +13 -0
index e8621f7174..b4e1650f99 100644
@@ -22,6 +22,7 @@
 
  #include <linux/compiler.h>
 
+#include <xen/gnttab.h>
  #include <xen/hvm.h>
 
  DECLARE_GLOBAL_DATA_PTR;
@@ -64,6 +65,8 @@ static int setup_mem_map(void)
  	struct fdt_resource res;
  	const void *blob = gd->fdt_blob;
  	u64 gfn;
+	phys_addr_t gnttab_base;
+	phys_size_t gnttab_sz;
 
  	/*
  	 * Add "magic" region which is used by Xen to provide some essentials
@@ -97,6 +100,16 @@ static int setup_mem_map(void)
  				PTE_BLOCK_INNER_SHARE);
  	i++;
 
+	/* Get Xen's suggested physical page assignments for the grant table. */
+	get_gnttab_base(&gnttab_base, &gnttab_sz);
+
+	xen_mem_map[i].virt = gnttab_base;
+	xen_mem_map[i].phys = gnttab_base;
+	xen_mem_map[i].size = gnttab_sz;
+	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) {
  		printf("%s: Missing /memory node\n", __func__);
drivers/xen/Makefile +1 -0
index 9d0f604aaa..243b13277a 100644
@@ -5,3 +5,4 @@
  obj-y += hypervisor.o
  obj-y += events.o
  obj-y += xenbus.o
+obj-y += gnttab.o
drivers/xen/gnttab.c new file +73 -0
new file mode 100644
index 0000000000..b18102e329
@@ -0,0 +1,258 @@
+/*
+ ****************************************************************************
+ * (C) 2006 - Cambridge University
+ * (C) 2020 - EPAM Systems Inc.
+ ****************************************************************************
+ *
+ *		File: gnttab.c
+ *	  Author: Steven Smith (sos22 at cam.ac.uk)
+ *	 Changes: Grzegorz Milos (gm281 at cam.ac.uk)
+ *
+ *		Date: July 2006
+ *
+ * Environment: Xen Minimal OS
+ * Description: Simple grant tables implementation. About as stupid as it's
+ *  possible to be and still work.
+ *
+ ****************************************************************************
+ */
+#include <common.h>
+#include <linux/compiler.h>
+#include <log.h>
+#include <malloc.h>
+
+#include <asm/armv8/mmu.h>
+#include <asm/io.h>
+#include <asm/xen/system.h>
+
+#include <linux/bug.h>
+
+#include <xen/gnttab.h>
+#include <xen/hvm.h>
+
+#include <xen/interface/memory.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define NR_RESERVED_ENTRIES 8
+
+/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
+#define NR_GRANT_FRAMES 1
+#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(struct grant_entry_v1))
+
+static struct grant_entry_v1 *gnttab_table;
+static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
+
+static void put_free_entry(grant_ref_t ref)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	gnttab_list[ref] = gnttab_list[0];
+	gnttab_list[0]  = ref;
+	local_irq_restore(flags);
+}
+
+static grant_ref_t get_free_entry(void)
+{
+	unsigned int ref;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	ref = gnttab_list[0];
+	BUG_ON(ref < NR_RESERVED_ENTRIES || ref >= NR_GRANT_ENTRIES);
+	gnttab_list[0] = gnttab_list[ref];
+	local_irq_restore(flags);
+	return ref;
+}
+
+grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame, int readonly)
+{
+	grant_ref_t ref;
+
+	ref = get_free_entry();

drivers/xen/gnttab.c line 83

Quoted 10 lines
drivers/xen/gnttab.c new file +10 -0
+	gnttab_table[ref].frame = frame;
+	gnttab_table[ref].domid = domid;
+	wmb();
+	readonly *= GTF_readonly;
+	gnttab_table[ref].flags = GTF_permit_access | readonly;
+
+	return ref;
+}
+
+grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn)

It is not possible to transfer grant on Arm. So I would suggest to remove the code related to it.

[...]

drivers/xen/gnttab.c line 115

Quoted 1 line
drivers/xen/gnttab.c new file +1 -0
+unsigned long gnttab_end_transfer(grant_ref_t ref)

likewise.

Quoted 102 lines
drivers/xen/gnttab.c new file +102 -0
+{
+	unsigned long frame;
+	u16 flags;
+
+	BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
+
+	while (!((flags = gnttab_table[ref].flags) & GTF_transfer_committed)) {
+		if (synch_cmpxchg(&gnttab_table[ref].flags, flags, 0) == flags) {
+			printf("Release unused transfer grant.\n");
+			put_free_entry(ref);
+			return 0;
+		}
+	}
+
+	/* If a transfer is in progress then wait until it is completed. */
+	while (!(flags & GTF_transfer_completed))
+		flags = gnttab_table[ref].flags;
+
+	/* Read the frame number /after/ reading completion status. */
+	rmb();
+	frame = gnttab_table[ref].frame;
+
+	put_free_entry(ref);
+
+	return frame;
+}
+
+grant_ref_t gnttab_alloc_and_grant(void **map)
+{
+	unsigned long mfn;
+	grant_ref_t gref;
+
+	*map = (void *)memalign(PAGE_SIZE, PAGE_SIZE);
+	mfn = virt_to_mfn(*map);
+	gref = gnttab_grant_access(0, mfn, 0);
+	return gref;
+}
+
+static const char * const gnttabop_error_msgs[] = GNTTABOP_error_msgs;
+
+const char *gnttabop_error(int16_t status)
+{
+	status = -status;
+	if (status < 0 || status >= ARRAY_SIZE(gnttabop_error_msgs))
+		return "bad status";
+	else
+		return gnttabop_error_msgs[status];
+}
+
+/* Get Xen's suggested physical page assignments for the grant table. */
+void get_gnttab_base(phys_addr_t *gnttab_base, phys_size_t *gnttab_sz)
+{
+	const void *blob = gd->fdt_blob;
+	struct fdt_resource res;
+	int mem;
+
+	mem = fdt_node_offset_by_compatible(blob, -1, "xen,xen");
+	if (mem < 0) {
+		printf("No xen,xen compatible found\n");
+		BUG();
+	}
+
+	mem = fdt_get_resource(blob, mem, "reg", 0, &res);
+	if (mem == -FDT_ERR_NOTFOUND) {
+		printf("No grant table base in the device tree\n");
+		BUG();
+	}
+
+	*gnttab_base = (phys_addr_t)res.start;
+	if (gnttab_sz)
+		*gnttab_sz = (phys_size_t)(res.end - res.start + 1);
+
+	debug("FDT suggests grant table base at %llx\n",
+	      *gnttab_base);
+}
+
+void init_gnttab(void)
+{
+	struct xen_add_to_physmap xatp;
+	struct gnttab_setup_table setup;
+	xen_pfn_t frames[NR_GRANT_FRAMES];
+	int i, rc;
+
+	debug("%s\n", __func__);
+
+	for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
+		put_free_entry(i);
+
+	get_gnttab_base((phys_addr_t *)&gnttab_table, NULL);
+
+	for (i = 0; i < NR_GRANT_FRAMES; i++) {
+		xatp.domid = DOMID_SELF;
+		xatp.size = 0;
+		xatp.space = XENMAPSPACE_grant_table;
+		xatp.idx = i;
+		xatp.gpfn = PFN_DOWN((unsigned long)gnttab_table) + i;
+		rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
+		if (rc)
+			printf("XENMEM_add_to_physmap failed; status = %d\n",
+			       rc);
+		BUG_ON(rc != 0);
+	}

drivers/xen/gnttab.c line 227

Quoted 10 lines
drivers/xen/gnttab.c new file +10 -0
+
+	setup.dom = DOMID_SELF;
+	setup.nr_frames = NR_GRANT_FRAMES;
+	set_xen_guest_handle(setup.frame_list, frames);
+	rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
+	if (rc || setup.status) {
+		printf("GNTTABOP_setup_table failed; status = %s\n",
+		       gnttabop_error(setup.status));
+		BUG();
+	}

GNTTAOP_grant_table_op is not needed on Arm.

Quoted 19 lines
drivers/xen/gnttab.c new file +19 -0
+}
+
+void fini_gnttab(void)
+{
+	struct xen_remove_from_physmap xrtp;
+	struct gnttab_setup_table setup;
+	int i, rc;
+
+	debug("%s\n", __func__);
+
+	for (i = 0; i < NR_GRANT_FRAMES; i++) {
+		xrtp.domid = DOMID_SELF;
+		xrtp.gpfn = PFN_DOWN((unsigned long)gnttab_table) + i;
+		rc = HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrtp);
+		if (rc)
+			printf("XENMEM_remove_from_physmap failed; status = %d\n",
+			       rc);
+		BUG_ON(rc != 0);
+	}

drivers/xen/gnttab.c line 256

Quoted 10 lines
drivers/xen/gnttab.c new file +10 -0
+
+	setup.dom = DOMID_SELF;
+	setup.nr_frames = 0;
+
+	HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
+	if (setup.status) {
+		printf("GNTTABOP_setup_table failed; status = %s\n",
+		       gnttabop_error(setup.status));
+		BUG();
+	}

The hypercall doesn't do any clean-up in Xen. So why are you calling this from fini_gnttab()?

Cheers,

Signature · 1 line
Julien Grall
#36 lore raw

PATCH 11/17 xen: Port Xen grant table driver from mini-os

Hi Julien,

Quoted 175 lines · Julien Grall
Quoted 168 lines · Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Make required updates to run on u-boot.

Signed-off-by: Oleksandr Andrushchenko <
oleksandr_andrushchenko at epam.com>
Signed-off-by: Anastasiia Lukianenko <
anastasiia_lukianenko at epam.com>

---
  board/xen/xenguest_arm64/xenguest_arm64.c |  13 ++
  drivers/xen/Makefile                      |   1 +
  drivers/xen/gnttab.c                      | 258
++++++++++++++++++++++
  drivers/xen/hypervisor.c                  |   2 +
  include/xen/gnttab.h                      |  25 +++
  5 files changed, 299 insertions(+)

create mode 100644 drivers/xen/gnttab.c
create mode 100644 include/xen/gnttab.h

board/xen/xenguest_arm64/xenguest_arm64.c +3 -0
index e8621f7174..b4e1650f99 100644
@@ -22,6 +22,7 @@
 
  #include <linux/compiler.h>
 
+#include <xen/gnttab.h>
  #include <xen/hvm.h>
 
  DECLARE_GLOBAL_DATA_PTR;
@@ -64,6 +65,8 @@ static int setup_mem_map(void)
  	struct fdt_resource res;
  	const void *blob = gd->fdt_blob;
  	u64 gfn;
+	phys_addr_t gnttab_base;
+	phys_size_t gnttab_sz;
 
  	/*
  	 * Add "magic" region which is used by Xen to provide some

essentials

board/xen/xenguest_arm64/xenguest_arm64.c +1 -0
@@ -97,6 +100,16 @@ static int setup_mem_map(void)
  				PTE_BLOCK_INNER_SHARE);
  	i++;
 
+	/* Get Xen's suggested physical page assignments for the grant

table. */

board/xen/xenguest_arm64/xenguest_arm64.c +9 -0
+	get_gnttab_base(&gnttab_base, &gnttab_sz);
+
+	xen_mem_map[i].virt = gnttab_base;
+	xen_mem_map[i].phys = gnttab_base;
+	xen_mem_map[i].size = gnttab_sz;
+	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) {
  		printf("%s: Missing /memory node\n", __func__);
drivers/xen/Makefile +1 -0
index 9d0f604aaa..243b13277a 100644
@@ -5,3 +5,4 @@
  obj-y += hypervisor.o
  obj-y += events.o
  obj-y += xenbus.o
+obj-y += gnttab.o
drivers/xen/gnttab.c new file +2 -0
new file mode 100644
index 0000000000..b18102e329
@@ -0,0 +1,258 @@
+/*
+

*******************************************************************
*********
+ * (C) 2006 - Cambridge University
+ * (C) 2020 - EPAM Systems Inc.
+
*******************************************************************
*********
+ *
+ * File: gnttab.c
+ * Author: Steven Smith (sos22 at cam.ac.uk)
+ * Changes: Grzegorz Milos (gm281 at cam.ac.uk)
+ *
+ * Date: July 2006
+ *
+ * Environment: Xen Minimal OS
+ * Description: Simple grant tables implementation. About as stupid as it's
+ * possible to be and still work.
+ *
+
*******************************************************************
*********
+ */

drivers/xen/gnttab.c new file +21 -0
+#include <common.h>
+#include <linux/compiler.h>
+#include <log.h>
+#include <malloc.h>
+
+#include <asm/armv8/mmu.h>
+#include <asm/io.h>
+#include <asm/xen/system.h>
+
+#include <linux/bug.h>
+
+#include <xen/gnttab.h>
+#include <xen/hvm.h>
+
+#include <xen/interface/memory.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define NR_RESERVED_ENTRIES 8
+
+/* NR_GRANT_FRAMES must be less than or equal to that configured

in Xen */

drivers/xen/gnttab.c new file +2 -0
+#define NR_GRANT_FRAMES 1
+#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE /

sizeof(struct grant_entry_v1))

drivers/xen/gnttab.c new file +28 -0
+
+static struct grant_entry_v1 *gnttab_table;
+static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
+
+static void put_free_entry(grant_ref_t ref)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	gnttab_list[ref] = gnttab_list[0];
+	gnttab_list[0]  = ref;
+	local_irq_restore(flags);
+}
+
+static grant_ref_t get_free_entry(void)
+{
+	unsigned int ref;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	ref = gnttab_list[0];
+	BUG_ON(ref < NR_RESERVED_ENTRIES || ref >= NR_GRANT_ENTRIES);
+	gnttab_list[0] = gnttab_list[ref];
+	local_irq_restore(flags);
+	return ref;
+}
+
+grant_ref_t gnttab_grant_access(domid_t domid, unsigned long

frame, int readonly)

drivers/xen/gnttab.c new file +14 -0
+{
+	grant_ref_t ref;
+
+	ref = get_free_entry();
+	gnttab_table[ref].frame = frame;
+	gnttab_table[ref].domid = domid;
+	wmb();
+	readonly *= GTF_readonly;
+	gnttab_table[ref].flags = GTF_permit_access | readonly;
+
+	return ref;
+}
+
+grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long
Quoted 1 line

pfn)

It is not possible to transfer grant on Arm. So I would suggest to remove the code related to it.

Quoted 1 line

[...]

Makes sense, will remove.

Quoted 4 lines
Quoted 2 lines

+unsigned long gnttab_end_transfer(grant_ref_t ref)

likewise.

Same above.

Quoted 116 lines
Quoted 116 lines
drivers/xen/gnttab.c new file +7 -0
+{
+	unsigned long frame;
+	u16 flags;
+
+	BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
+
+	while (!((flags = gnttab_table[ref].flags) &

GTF_transfer_committed)) {

drivers/xen/gnttab.c new file +1 -0
+		if (synch_cmpxchg(&gnttab_table[ref].flags, flags, 0)

== flags) {

drivers/xen/gnttab.c new file +7 -0
+			printf("Release unused transfer grant.\n");
+			put_free_entry(ref);
+			return 0;
+		}
+	}
+
+	/* If a transfer is in progress then wait until it is

completed. */

drivers/xen/gnttab.c new file +24 -0
+	while (!(flags & GTF_transfer_completed))
+		flags = gnttab_table[ref].flags;
+
+	/* Read the frame number /after/ reading completion status. */
+	rmb();
+	frame = gnttab_table[ref].frame;
+
+	put_free_entry(ref);
+
+	return frame;
+}
+
+grant_ref_t gnttab_alloc_and_grant(void **map)
+{
+	unsigned long mfn;
+	grant_ref_t gref;
+
+	*map = (void *)memalign(PAGE_SIZE, PAGE_SIZE);
+	mfn = virt_to_mfn(*map);
+	gref = gnttab_grant_access(0, mfn, 0);
+	return gref;
+}
+
+static const char * const gnttabop_error_msgs[] =

GNTTABOP_error_msgs;

drivers/xen/gnttab.c new file +11 -0
+
+const char *gnttabop_error(int16_t status)
+{
+	status = -status;
+	if (status < 0 || status >= ARRAY_SIZE(gnttabop_error_msgs))
+		return "bad status";
+	else
+		return gnttabop_error_msgs[status];
+}
+
+/* Get Xen's suggested physical page assignments for the grant

table. */
+void get_gnttab_base(phys_addr_t *gnttab_base, phys_size_t *gnttab_sz)

drivers/xen/gnttab.c new file +46 -0
+{
+	const void *blob = gd->fdt_blob;
+	struct fdt_resource res;
+	int mem;
+
+	mem = fdt_node_offset_by_compatible(blob, -1, "xen,xen");
+	if (mem < 0) {
+		printf("No xen,xen compatible found\n");
+		BUG();
+	}
+
+	mem = fdt_get_resource(blob, mem, "reg", 0, &res);
+	if (mem == -FDT_ERR_NOTFOUND) {
+		printf("No grant table base in the device tree\n");
+		BUG();
+	}
+
+	*gnttab_base = (phys_addr_t)res.start;
+	if (gnttab_sz)
+		*gnttab_sz = (phys_size_t)(res.end - res.start + 1);
+
+	debug("FDT suggests grant table base at %llx\n",
+	      *gnttab_base);
+}
+
+void init_gnttab(void)
+{
+	struct xen_add_to_physmap xatp;
+	struct gnttab_setup_table setup;
+	xen_pfn_t frames[NR_GRANT_FRAMES];
+	int i, rc;
+
+	debug("%s\n", __func__);
+
+	for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
+		put_free_entry(i);
+
+	get_gnttab_base((phys_addr_t *)&gnttab_table, NULL);
+
+	for (i = 0; i < NR_GRANT_FRAMES; i++) {
+		xatp.domid = DOMID_SELF;
+		xatp.size = 0;
+		xatp.space = XENMAPSPACE_grant_table;
+		xatp.idx = i;
+		xatp.gpfn = PFN_DOWN((unsigned long)gnttab_table) + i;
+		rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap,

&xatp);

drivers/xen/gnttab.c new file +2 -0
+		if (rc)
+			printf("XENMEM_add_to_physmap failed; status =

%d\n",

drivers/xen/gnttab.c new file +8 -0
+			       rc);
+		BUG_ON(rc != 0);
+	}
+
+	setup.dom = DOMID_SELF;
+	setup.nr_frames = NR_GRANT_FRAMES;
+	set_xen_guest_handle(setup.frame_list, frames);
+	rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup,
Quoted 9 lines

drivers/xen/gnttab.c line 227

Quoted 6 lines

1);

drivers/xen/gnttab.c new file +5 -0
+	if (rc || setup.status) {
+		printf("GNTTABOP_setup_table failed; status = %s\n",
+		       gnttabop_error(setup.status));
+		BUG();
+	}

GNTTAOP_grant_table_op is not needed on Arm.

Ok, will remove.

Quoted 26 lines
Quoted 26 lines
drivers/xen/gnttab.c new file +14 -0
+}
+
+void fini_gnttab(void)
+{
+	struct xen_remove_from_physmap xrtp;
+	struct gnttab_setup_table setup;
+	int i, rc;
+
+	debug("%s\n", __func__);
+
+	for (i = 0; i < NR_GRANT_FRAMES; i++) {
+		xrtp.domid = DOMID_SELF;
+		xrtp.gpfn = PFN_DOWN((unsigned long)gnttab_table) + i;
+		rc = HYPERVISOR_memory_op(XENMEM_remove_from_physmap,

&xrtp);

drivers/xen/gnttab.c new file +2 -0
+		if (rc)
+			printf("XENMEM_remove_from_physmap failed;

status = %d\n",

drivers/xen/gnttab.c new file +8 -0
+			       rc);
+		BUG_ON(rc != 0);
+	}
+
+	setup.dom = DOMID_SELF;
+	setup.nr_frames = 0;
+
+	HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
Quoted 8 lines

drivers/xen/gnttab.c line 256

Quoted 5 lines
drivers/xen/gnttab.c new file +5 -0
+	if (setup.status) {
+		printf("GNTTABOP_setup_table failed; status = %s\n",
+		       gnttabop_error(setup.status));
+		BUG();
+	}

The hypercall doesn't do any clean-up in Xen. So why are you calling this from fini_gnttab()?

Will remove.

Quoted 3 lines

Cheers,

Best regards,
Anastasiia

#37 lore raw

PATCH 12/17 xen: pvblock: Add initial support for para-virtualized block driver

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation.
Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices.
Add new interface type IF_TYPE_PVBLOCK.

Implement basic driver setup by reading XenStore configuration.

---
 cmd/Kconfig                      |   7 ++
 cmd/Makefile                     |   1 +
 cmd/pvblock.c                    |  31 ++++++++
 common/board_r.c                 |  14 ++++
 configs/xenguest_arm64_defconfig |   4 +
 disk/part.c                      |   4 +
 drivers/Kconfig                  |   2 +
 drivers/block/blk-uclass.c       |   2 +
 drivers/xen/Kconfig              |  10 +++
 drivers/xen/Makefile             |   2 +
 drivers/xen/pvblock.c            | 121 +++++++++++++++++++++++++++++++
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 ++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  12 +++
 15 files changed, 220 insertions(+)
 create mode 100644 cmd/pvblock.c
 create mode 100644 drivers/xen/Kconfig
 create mode 100644 drivers/xen/pvblock.c
 create mode 100644 include/pvblock.h
cmd/Kconfig +7 -0
index 192b3b262f..f28576947b 100644
@@ -1335,6 +1335,13 @@ config CMD_USB_MASS_STORAGE
 	help
 	  USB mass storage support
 
+config CMD_PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on XEN
+	select PVBLOCK
+	help
+	  Xen para-virtualized block device support
+
 config CMD_VIRTIO
 	bool "virtio"
 	depends on VIRTIO
cmd/Makefile +1 -0
index 974ad48b0a..117284a28c 100644
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
+obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
 
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
cmd/pvblock.c new file +31 -0
new file mode 100644
index 0000000000..7dbb243a74
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ *
+ * XEN para-virtualized block device support
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <command.h>
+
+/* Current I/O Device	*/
+static int pvblock_curr_device;
+
+int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+			      &pvblock_curr_device);
+}
+
+U_BOOT_CMD(pvblock, 5, 1, do_pvblock,
+	   "Xen para-virtualized block device",
+	   "info  - show available block devices\n"
+	   "pvblock device [dev] - show or set current device\n"
+	   "pvblock part [dev] - print partition table of one or all devices\n"
+	   "pvblock read  addr blk# cnt\n"
+	   "pvblock write addr blk# cnt - read/write `cnt'"
+	   " blocks starting at block `blk#'\n"
+	   "    to/from memory address `addr'");
+
common/board_r.c +14 -0
index fd36edb4e5..40cd0e5d3c 100644
@@ -49,6 +49,7 @@
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -470,6 +471,16 @@ static int initr_xen(void)
 	return 0;
 }
 #endif
+
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+	puts("PVBLOCK: ");
+	pvblock_init();
+	return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -780,6 +791,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_XEN
 	initr_xen,
+#endif
+#ifdef CONFIG_PVBLOCK
+	initr_pvblock,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
configs/xenguest_arm64_defconfig +4 -0
index 45559a161b..46473c251d 100644
@@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n
 CONFIG_CMD_BOOTEFI=n
 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
 CONFIG_CMD_ELF=n
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
 CONFIG_CMD_GO=n
 CONFIG_CMD_RUN=n
 CONFIG_CMD_IMI=n
@@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n
 CONFIG_CMD_SAVEENV=n
 CONFIG_CMD_UMS=n
 
+CONFIG_CMD_PVBLOCK=y
+
 #CONFIG_USB=n
 # CONFIG_ISO_PARTITION is not set
 
disk/part.c +4 -0
index f6a31025dc..b69fd345f3 100644
@@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc)
 	case IF_TYPE_MMC:
 	case IF_TYPE_USB:
 	case IF_TYPE_NVME:
+	case IF_TYPE_PVBLOCK:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -288,6 +289,9 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)
 	case IF_TYPE_NVME:
 		puts ("NVMe");
 		break;
+	case IF_TYPE_PVBLOCK:
+		puts("PV BLOCK");
+		break;
 	case IF_TYPE_VIRTIO:
 		puts("VirtIO");
 		break;
drivers/Kconfig +2 -0
index e34a22708c..65076aab03 100644
@@ -132,6 +132,8 @@ source "drivers/w1-eeprom/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/xen/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/block/blk-uclass.c +2 -0
index b19375cbc8..6cfabbca24 100644
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= "nvme",
 	[IF_TYPE_EFI]		= "efi",
 	[IF_TYPE_VIRTIO]	= "virtio",
+	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
@@ -43,6 +44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= UCLASS_NVME,
 	[IF_TYPE_EFI]		= UCLASS_EFI,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
+	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 
 static enum if_type if_typename_to_iftype(const char *if_typename)
drivers/xen/Kconfig new file +10 -0
new file mode 100644
index 0000000000..6ad2a93668
@@ -0,0 +1,10 @@
+config PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on DM
+	select BLK
+	select HAVE_BLOCK_DEVICE
+	help
+	  This driver implements the front-end of the Xen virtual
+	  block device driver. It communicates with a back-end driver
+	  in another domain which drives the actual block device.
+
drivers/xen/Makefile +2 -0
index 243b13277a..87157df69b 100644
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
 obj-y += events.o
 obj-y += xenbus.o
 obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
drivers/xen/pvblock.c new file +121 -0

121 lines not on this page · raw message

include/blk.h +1 -0
index abcd4bedbb..9ee10fb80e 100644
@@ -33,6 +33,7 @@ enum if_type {
 	IF_TYPE_HOST,
 	IF_TYPE_NVME,
 	IF_TYPE_EFI,
+	IF_TYPE_PVBLOCK,
 	IF_TYPE_VIRTIO,
 
 	IF_TYPE_COUNT,			/* Number of interface types */
include/configs/xenguest_arm64.h +8 -0
index 467dabf1e5..2c0d3d64fb 100644
@@ -42,4 +42,12 @@
 #define CONFIG_CMDLINE_TAG            1
 #define CONFIG_INITRD_TAG             1
 
+#define CONFIG_CMD_RUN
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \
+	"pvblockboot=run loadimage;" \
+		"booti 0x90000000 - 0x88000000;\0"
+
 #endif /* __XENGUEST_ARM64_H */
include/dm/uclass-id.h +1 -0
index 7837d459f1..4bf7501204 100644
@@ -121,6 +121,7 @@ enum uclass_id {
 	UCLASS_W1,		/* Dallas 1-Wire bus */
 	UCLASS_W1_EEPROM,	/* one-wire EEPROMs */
 	UCLASS_WDT,		/* Watchdog Timer driver */
+	UCLASS_PVBLOCK,		/* Xen virtual block device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/pvblock.h new file +12 -0
new file mode 100644
index 0000000000..e3bb8ff9a7
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
Signature · 1 line
2.17.1
#38 lore raw

PATCH 12/17 xen: pvblock: Add initial support for para-virtualized block driver

Quoted 10 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation.
Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices.
Add new interface type IF_TYPE_PVBLOCK.

Implement basic driver setup by reading XenStore configuration.

Please, add documenation for the board in doc/board/.

Quoted 62 lines
---
 cmd/Kconfig                      |   7 ++
 cmd/Makefile                     |   1 +
 cmd/pvblock.c                    |  31 ++++++++
 common/board_r.c                 |  14 ++++
 configs/xenguest_arm64_defconfig |   4 +
 disk/part.c                      |   4 +
 drivers/Kconfig                  |   2 +
 drivers/block/blk-uclass.c       |   2 +
 drivers/xen/Kconfig              |  10 +++
 drivers/xen/Makefile             |   2 +
 drivers/xen/pvblock.c            | 121 +++++++++++++++++++++++++++++++
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 ++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  12 +++
 15 files changed, 220 insertions(+)
 create mode 100644 cmd/pvblock.c
 create mode 100644 drivers/xen/Kconfig
 create mode 100644 drivers/xen/pvblock.c
 create mode 100644 include/pvblock.h
cmd/Kconfig +7 -0
index 192b3b262f..f28576947b 100644
@@ -1335,6 +1335,13 @@ config CMD_USB_MASS_STORAGE
 	help
 	  USB mass storage support
 
+config CMD_PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on XEN
+	select PVBLOCK
+	help
+	  Xen para-virtualized block device support
+
 config CMD_VIRTIO
 	bool "virtio"
 	depends on VIRTIO
cmd/Makefile +1 -0
index 974ad48b0a..117284a28c 100644
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
+obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
 
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
cmd/pvblock.c new file +0 -0
new file mode 100644
index 0000000000..7dbb243a74

cmd/pvblock.c line 2

Quoted 2 lines
cmd/pvblock.c new file +2 -0
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

SPDX should be in first line and formatted as described in

https://www.kernel.org/doc/html/latest/process/license-rules.html#license-identifier-syntax

Quoted 345 lines
cmd/pvblock.c new file +29 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ *
+ * XEN para-virtualized block device support
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <command.h>
+
+/* Current I/O Device	*/
+static int pvblock_curr_device;
+
+int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+			      &pvblock_curr_device);
+}
+
+U_BOOT_CMD(pvblock, 5, 1, do_pvblock,
+	   "Xen para-virtualized block device",
+	   "info  - show available block devices\n"
+	   "pvblock device [dev] - show or set current device\n"
+	   "pvblock part [dev] - print partition table of one or all devices\n"
+	   "pvblock read  addr blk# cnt\n"
+	   "pvblock write addr blk# cnt - read/write `cnt'"
+	   " blocks starting at block `blk#'\n"
+	   "    to/from memory address `addr'");
+
common/board_r.c +14 -0
index fd36edb4e5..40cd0e5d3c 100644
@@ -49,6 +49,7 @@
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -470,6 +471,16 @@ static int initr_xen(void)
 	return 0;
 }
 #endif
+
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+	puts("PVBLOCK: ");
+	pvblock_init();
+	return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -780,6 +791,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_XEN
 	initr_xen,
+#endif
+#ifdef CONFIG_PVBLOCK
+	initr_pvblock,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
configs/xenguest_arm64_defconfig +4 -0
index 45559a161b..46473c251d 100644
@@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n
 CONFIG_CMD_BOOTEFI=n
 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
 CONFIG_CMD_ELF=n
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
 CONFIG_CMD_GO=n
 CONFIG_CMD_RUN=n
 CONFIG_CMD_IMI=n
@@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n
 CONFIG_CMD_SAVEENV=n
 CONFIG_CMD_UMS=n
 
+CONFIG_CMD_PVBLOCK=y
+
 #CONFIG_USB=n
 # CONFIG_ISO_PARTITION is not set
 
disk/part.c +4 -0
index f6a31025dc..b69fd345f3 100644
@@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc)
 	case IF_TYPE_MMC:
 	case IF_TYPE_USB:
 	case IF_TYPE_NVME:
+	case IF_TYPE_PVBLOCK:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -288,6 +289,9 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)
 	case IF_TYPE_NVME:
 		puts ("NVMe");
 		break;
+	case IF_TYPE_PVBLOCK:
+		puts("PV BLOCK");
+		break;
 	case IF_TYPE_VIRTIO:
 		puts("VirtIO");
 		break;
drivers/Kconfig +2 -0
index e34a22708c..65076aab03 100644
@@ -132,6 +132,8 @@ source "drivers/w1-eeprom/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/xen/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/block/blk-uclass.c +2 -0
index b19375cbc8..6cfabbca24 100644
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= "nvme",
 	[IF_TYPE_EFI]		= "efi",
 	[IF_TYPE_VIRTIO]	= "virtio",
+	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
@@ -43,6 +44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= UCLASS_NVME,
 	[IF_TYPE_EFI]		= UCLASS_EFI,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
+	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 
 static enum if_type if_typename_to_iftype(const char *if_typename)
drivers/xen/Kconfig new file +10 -0
new file mode 100644
index 0000000000..6ad2a93668
@@ -0,0 +1,10 @@
+config PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on DM
+	select BLK
+	select HAVE_BLOCK_DEVICE
+	help
+	  This driver implements the front-end of the Xen virtual
+	  block device driver. It communicates with a back-end driver
+	  in another domain which drives the actual block device.
+
drivers/xen/Makefile +2 -0
index 243b13277a..87157df69b 100644
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
 obj-y += events.o
 obj-y += xenbus.o
 obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
drivers/xen/pvblock.c new file +121 -0
new file mode 100644
index 0000000000..057add9753
@@ -0,0 +1,121 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ */
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+
+#define DRV_NAME	"pvblock"
+#define DRV_NAME_BLK	"pvblock_blk"
+
+struct blkfront_dev {
+	char dummy;
+};
+
+static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
+{
+	return 0;
+}
+
+static void shutdown_blkfront(struct blkfront_dev *dev)
+{
+}
+
+ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
+		       void *buffer)
+{
+	return 0;
+}
+
+ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
+			const void *buffer)
+{
+	return 0;
+}
+
+static int pvblock_blk_bind(struct udevice *udev)
+{
+	return 0;
+}
+
+static int pvblock_blk_probe(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+	int ret;
+
+	ret = init_blkfront(0, blk_dev);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
+static int pvblock_blk_remove(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+
+	shutdown_blkfront(blk_dev);
+	return 0;
+}
+
+static const struct blk_ops pvblock_blk_ops = {
+	.read	= pvblock_blk_read,
+	.write	= pvblock_blk_write,
+};
+
+U_BOOT_DRIVER(pvblock_blk) = {
+	.name			= DRV_NAME_BLK,
+	.id			= UCLASS_BLK,
+	.ops			= &pvblock_blk_ops,
+	.bind			= pvblock_blk_bind,
+	.probe			= pvblock_blk_probe,
+	.remove			= pvblock_blk_remove,
+	.priv_auto_alloc_size	= sizeof(struct blkfront_dev),
+	.flags			= DM_FLAG_OS_PREPARE,
+};
+
+/*******************************************************************************
+ * Para-virtual block device class
+ *******************************************************************************/
+
+void pvblock_init(void)
+{
+	struct driver_info info;
+	struct udevice *udev;
+	struct uclass *uc;
+	int ret;
+
+	/*
+	 * At this point Xen drivers have already initialized,
+	 * so we can instantiate the class driver and enumerate
+	 * virtual block devices.
+	 */
+	info.name = DRV_NAME;
+	ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
+	if (ret < 0)
+		printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
+
+	/* Bootstrap virtual block devices class driver */
+	ret = uclass_get(UCLASS_PVBLOCK, &uc);
+	if (ret)
+		return;
+	uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
+}
+
+static int pvblock_probe(struct udevice *udev)
+{
+	return 0;
+}
+
+U_BOOT_DRIVER(pvblock_drv) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+	.probe		= pvblock_probe,
+};
+
+UCLASS_DRIVER(pvblock) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+};
include/blk.h +1 -0
index abcd4bedbb..9ee10fb80e 100644
@@ -33,6 +33,7 @@ enum if_type {
 	IF_TYPE_HOST,
 	IF_TYPE_NVME,
 	IF_TYPE_EFI,
+	IF_TYPE_PVBLOCK,
 	IF_TYPE_VIRTIO,
 
 	IF_TYPE_COUNT,			/* Number of interface types */
include/configs/xenguest_arm64.h +8 -0
index 467dabf1e5..2c0d3d64fb 100644
@@ -42,4 +42,12 @@
 #define CONFIG_CMDLINE_TAG            1
 #define CONFIG_INITRD_TAG             1
 
+#define CONFIG_CMD_RUN
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \
+	"pvblockboot=run loadimage;" \
+		"booti 0x90000000 - 0x88000000;\0"
+
 #endif /* __XENGUEST_ARM64_H */
include/dm/uclass-id.h +1 -0
index 7837d459f1..4bf7501204 100644
@@ -121,6 +121,7 @@ enum uclass_id {
 	UCLASS_W1,		/* Dallas 1-Wire bus */
 	UCLASS_W1_EEPROM,	/* one-wire EEPROMs */
 	UCLASS_WDT,		/* Watchdog Timer driver */
+	UCLASS_PVBLOCK,		/* Xen virtual block device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/pvblock.h new file +0 -0
new file mode 100644
index 0000000000..e3bb8ff9a7

include/pvblock.h line 2

Quoted 2 lines
include/pvblock.h new file +2 -0
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

see above

Please, use scripts/checkpatch.pl before submitting patches.

Best regards

Heinrich

Quoted 11 lines
include/pvblock.h new file +10 -0
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
#39 lore raw

PATCH 12/17 xen: pvblock: Add initial support for para-virtualized block driver

Hi Heinrich,

Quoted 10 lines · Heinrich Schuchardt
Quoted 9 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation.
Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices.
Add new interface type IF_TYPE_PVBLOCK.

Quoted 3 lines
Quoted 1 line

Implement basic driver setup by reading XenStore configuration.

Please, add documenation for the board in doc/board/.

Ok, will add.

Quoted 58 lines
Quoted 58 lines
Signed-off-by Anastasiia Lukianenko <

anastasiia_lukianenko at epam.com>
Signed-off-by: Oleksandr Andrushchenko <
oleksandr_andrushchenko at epam.com>

---
 cmd/Kconfig                      |   7 ++
 cmd/Makefile                     |   1 +
 cmd/pvblock.c                    |  31 ++++++++
 common/board_r.c                 |  14 ++++
 configs/xenguest_arm64_defconfig |   4 +
 disk/part.c                      |   4 +
 drivers/Kconfig                  |   2 +
 drivers/block/blk-uclass.c       |   2 +
 drivers/xen/Kconfig              |  10 +++
 drivers/xen/Makefile             |   2 +
 drivers/xen/pvblock.c            | 121
+++++++++++++++++++++++++++++++
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 ++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  12 +++
 15 files changed, 220 insertions(+)
 create mode 100644 cmd/pvblock.c
 create mode 100644 drivers/xen/Kconfig
 create mode 100644 drivers/xen/pvblock.c
 create mode 100644 include/pvblock.h
cmd/Kconfig +7 -0
index 192b3b262f..f28576947b 100644
@@ -1335,6 +1335,13 @@ config CMD_USB_MASS_STORAGE
 	help
 	  USB mass storage support
 
+config CMD_PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on XEN
+	select PVBLOCK
+	help
+	  Xen para-virtualized block device support
+
 config CMD_VIRTIO
 	bool "virtio"
 	depends on VIRTIO
cmd/Makefile +1 -0
index 974ad48b0a..117284a28c 100644
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
+obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
 
Quoted 14 lines

cmd/pvblock.c line 2

Quoted 10 lines
cmd/Makefile +0 -0
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
cmd/pvblock.c new file +2 -0
new file mode 100644
index 0000000000..7dbb243a74
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

SPDX should be in first line and formatted as described in

https://urldefense.com/v3/__https://www.kernel.org/doc/html/latest/process/license-rules.html*license-identifier-syntax__;Iw!!GF_29dbcQIUBPA!l97PRX7YWb0RSRfrhKECVdFblqlOu73YTMPut6YwlXMfrLzvQrqF56fQO2MjT5c6kJT1Mqk$

Quoted 1 line

Ok, will fix.

Quoted 367 lines
Quoted 362 lines
cmd/pvblock.c new file +14 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ *
+ * XEN para-virtualized block device support
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <command.h>
+
+/* Current I/O Device	*/
+static int pvblock_curr_device;
+
+int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char

*const argv[])

cmd/pvblock.c new file +10 -0
+{
+	return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+			      &pvblock_curr_device);
+}
+
+U_BOOT_CMD(pvblock, 5, 1, do_pvblock,
+	   "Xen para-virtualized block device",
+	   "info  - show available block devices\n"
+	   "pvblock device [dev] - show or set current device\n"
+	   "pvblock part [dev] - print partition table of one or all

devices\n"

cmd/pvblock.c new file +5 -0
+	   "pvblock read  addr blk# cnt\n"
+	   "pvblock write addr blk# cnt - read/write `cnt'"
+	   " blocks starting at block `blk#'\n"
+	   "    to/from memory address `addr'");
+
common/board_r.c +14 -0
index fd36edb4e5..40cd0e5d3c 100644
@@ -49,6 +49,7 @@
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -470,6 +471,16 @@ static int initr_xen(void)
 	return 0;
 }
 #endif
+
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+	puts("PVBLOCK: ");
+	pvblock_init();
+	return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -780,6 +791,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_XEN
 	initr_xen,
+#endif
+#ifdef CONFIG_PVBLOCK
+	initr_pvblock,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
configs/xenguest_arm64_defconfig +4 -0
index 45559a161b..46473c251d 100644
@@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n
 CONFIG_CMD_BOOTEFI=n
 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
 CONFIG_CMD_ELF=n
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
 CONFIG_CMD_GO=n
 CONFIG_CMD_RUN=n
 CONFIG_CMD_IMI=n
@@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n
 CONFIG_CMD_SAVEENV=n
 CONFIG_CMD_UMS=n
 
+CONFIG_CMD_PVBLOCK=y
+
 #CONFIG_USB=n
 # CONFIG_ISO_PARTITION is not set
 
disk/part.c +4 -0
index f6a31025dc..b69fd345f3 100644
@@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc)
 	case IF_TYPE_MMC:
 	case IF_TYPE_USB:
 	case IF_TYPE_NVME:
+	case IF_TYPE_PVBLOCK:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -288,6 +289,9 @@ static void print_part_header(const char *type,
 struct blk_desc *dev_desc)
 	case IF_TYPE_NVME:
 		puts ("NVMe");
 		break;
+	case IF_TYPE_PVBLOCK:
+		puts("PV BLOCK");
+		break;
 	case IF_TYPE_VIRTIO:
 		puts("VirtIO");
disk/part.c +0 -0
 		break;
drivers/Kconfig +2 -0
index e34a22708c..65076aab03 100644
@@ -132,6 +132,8 @@ source "drivers/w1-eeprom/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/xen/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/block/blk- renamed from drivers/block/blk-uclass.c +0 -0

uclass.c
index b19375cbc8..6cfabbca24 100644

drivers/block/blk-uclass.c +1 -0
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT]
 = {
 	[IF_TYPE_NVME]		= "nvme",
 	[IF_TYPE_EFI]		= "efi",
 	[IF_TYPE_VIRTIO]	= "virtio",
+	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 

static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {

drivers/block/blk-uclass.c +1 -0
@@ -43,6 +44,7 @@ static enum uclass_id
 if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= UCLASS_NVME,
 	[IF_TYPE_EFI]		= UCLASS_EFI,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
+	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 

static enum if_type if_typename_to_iftype(const char *if_typename)

drivers/xen/Kconfig new file +10 -0
new file mode 100644
index 0000000000..6ad2a93668
@@ -0,0 +1,10 @@
+config PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on DM
+	select BLK
+	select HAVE_BLOCK_DEVICE
+	help
+	  This driver implements the front-end of the Xen virtual
+	  block device driver. It communicates with a back-end driver
+	  in another domain which drives the actual block device.
+
drivers/xen/Makefile +2 -0
index 243b13277a..87157df69b 100644
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
 obj-y += events.o
 obj-y += xenbus.o
 obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
drivers/xen/pvblock.c new file +18 -0
new file mode 100644
index 0000000000..057add9753
@@ -0,0 +1,121 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ */
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+
+#define DRV_NAME	"pvblock"
+#define DRV_NAME_BLK	"pvblock_blk"
+
+struct blkfront_dev {
+	char dummy;
+};
+
+static int init_blkfront(unsigned int devid, struct blkfront_dev

*dev)

drivers/xen/pvblock.c new file +9 -0
+{
+	return 0;
+}
+
+static void shutdown_blkfront(struct blkfront_dev *dev)
+{
+}
+
+ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr,

lbaint_t blkcnt,

drivers/xen/pvblock.c new file +6 -0
+		       void *buffer)
+{
+	return 0;
+}
+
+ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr,

lbaint_t blkcnt,

drivers/xen/pvblock.c new file +46 -0
+			const void *buffer)
+{
+	return 0;
+}
+
+static int pvblock_blk_bind(struct udevice *udev)
+{
+	return 0;
+}
+
+static int pvblock_blk_probe(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+	int ret;
+
+	ret = init_blkfront(0, blk_dev);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
+static int pvblock_blk_remove(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+
+	shutdown_blkfront(blk_dev);
+	return 0;
+}
+
+static const struct blk_ops pvblock_blk_ops = {
+	.read	= pvblock_blk_read,
+	.write	= pvblock_blk_write,
+};
+
+U_BOOT_DRIVER(pvblock_blk) = {
+	.name			= DRV_NAME_BLK,
+	.id			= UCLASS_BLK,
+	.ops			= &pvblock_blk_ops,
+	.bind			= pvblock_blk_bind,
+	.probe			= pvblock_blk_probe,
+	.remove			= pvblock_blk_remove,
+	.priv_auto_alloc_size	= sizeof(struct blkfront_dev),
+	.flags			= DM_FLAG_OS_PREPARE,
+};
+
+/*****************************************************************

**************
+ * Para-virtual block device class
+
*******************************************************************
************/

drivers/xen/pvblock.c new file +40 -0
+
+void pvblock_init(void)
+{
+	struct driver_info info;
+	struct udevice *udev;
+	struct uclass *uc;
+	int ret;
+
+	/*
+	 * At this point Xen drivers have already initialized,
+	 * so we can instantiate the class driver and enumerate
+	 * virtual block devices.
+	 */
+	info.name = DRV_NAME;
+	ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
+	if (ret < 0)
+		printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
+
+	/* Bootstrap virtual block devices class driver */
+	ret = uclass_get(UCLASS_PVBLOCK, &uc);
+	if (ret)
+		return;
+	uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
+}
+
+static int pvblock_probe(struct udevice *udev)
+{
+	return 0;
+}
+
+U_BOOT_DRIVER(pvblock_drv) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+	.probe		= pvblock_probe,
+};
+
+UCLASS_DRIVER(pvblock) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+};
include/blk.h +1 -0
index abcd4bedbb..9ee10fb80e 100644
@@ -33,6 +33,7 @@ enum if_type {
 	IF_TYPE_HOST,
 	IF_TYPE_NVME,
 	IF_TYPE_EFI,
+	IF_TYPE_PVBLOCK,
 	IF_TYPE_VIRTIO,
 
 	IF_TYPE_COUNT,			/* Number of interface

types */

include/configs/xenguest_arm64.h +8 -0
index 467dabf1e5..2c0d3d64fb 100644
@@ -42,4 +42,12 @@
 #define CONFIG_CMDLINE_TAG            1
 #define CONFIG_INITRD_TAG             1
 
+#define CONFIG_CMD_RUN
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \
+	"pvblockboot=run loadimage;" \
+		"booti 0x90000000 - 0x88000000;\0"
+
 #endif /* __XENGUEST_ARM64_H */
include/dm/uclass-id.h +1 -0
index 7837d459f1..4bf7501204 100644
@@ -121,6 +121,7 @@ enum uclass_id {
 	UCLASS_W1,		/* Dallas 1-Wire bus */
 	UCLASS_W1_EEPROM,	/* one-wire EEPROMs */
 	UCLASS_WDT,		/* Watchdog Timer driver */
+	UCLASS_PVBLOCK,		/* Xen virtual block device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/pvblock.h new file +0 -0
new file mode 100644
index 0000000000..e3bb8ff9a7

include/pvblock.h line 2

Quoted 2 lines
include/pvblock.h new file +2 -0
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

see above

Quoted 1 line

Please, use scripts/checkpatch.pl before submitting patches.

We used it, but did not know when to stop :)

Quoted 4 lines

Best regards

Heinrich

Best regards,
Anastasiia

Quoted 14 lines
Quoted 12 lines
include/pvblock.h new file +10 -0
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
#40 lore raw

PATCH 12/17 xen: pvblock: Add initial support for para-virtualized block driver

In reply to Anastasiia Lukianenko
Quoted 7 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation.
Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices.

We already have virtual block devices: virtio_blk, efi_blk.

They work fine using the exising UCLASS_BLK. Why do we need a new uclass?

Quoted 65 lines

Add new interface type IF_TYPE_PVBLOCK.

Implement basic driver setup by reading XenStore configuration.

---
 cmd/Kconfig                      |   7 ++
 cmd/Makefile                     |   1 +
 cmd/pvblock.c                    |  31 ++++++++
 common/board_r.c                 |  14 ++++
 configs/xenguest_arm64_defconfig |   4 +
 disk/part.c                      |   4 +
 drivers/Kconfig                  |   2 +
 drivers/block/blk-uclass.c       |   2 +
 drivers/xen/Kconfig              |  10 +++
 drivers/xen/Makefile             |   2 +
 drivers/xen/pvblock.c            | 121 +++++++++++++++++++++++++++++++
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 ++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  12 +++
 15 files changed, 220 insertions(+)
 create mode 100644 cmd/pvblock.c
 create mode 100644 drivers/xen/Kconfig
 create mode 100644 drivers/xen/pvblock.c
 create mode 100644 include/pvblock.h
cmd/Kconfig +7 -0
index 192b3b262f..f28576947b 100644
@@ -1335,6 +1335,13 @@ config CMD_USB_MASS_STORAGE
 	help
 	  USB mass storage support
 
+config CMD_PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on XEN
+	select PVBLOCK
+	help
+	  Xen para-virtualized block device support
+
 config CMD_VIRTIO
 	bool "virtio"
 	depends on VIRTIO
cmd/Makefile +1 -0
index 974ad48b0a..117284a28c 100644
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
+obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
 
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
cmd/pvblock.c new file +0 -0
new file mode 100644
index 0000000000..7dbb243a74

cmd/pvblock.c line 2

Quoted 2 lines
cmd/pvblock.c new file +2 -0
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

Please, correct the formatting.

https://www.kernel.org/doc/html/latest/process/license-rules.html#license-identifier-syntax

Quoted 177 lines
cmd/pvblock.c new file +29 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ *
+ * XEN para-virtualized block device support
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <command.h>
+
+/* Current I/O Device	*/
+static int pvblock_curr_device;
+
+int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+			      &pvblock_curr_device);
+}
+
+U_BOOT_CMD(pvblock, 5, 1, do_pvblock,
+	   "Xen para-virtualized block device",
+	   "info  - show available block devices\n"
+	   "pvblock device [dev] - show or set current device\n"
+	   "pvblock part [dev] - print partition table of one or all devices\n"
+	   "pvblock read  addr blk# cnt\n"
+	   "pvblock write addr blk# cnt - read/write `cnt'"
+	   " blocks starting at block `blk#'\n"
+	   "    to/from memory address `addr'");
+
common/board_r.c +14 -0
index fd36edb4e5..40cd0e5d3c 100644
@@ -49,6 +49,7 @@
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -470,6 +471,16 @@ static int initr_xen(void)
 	return 0;
 }
 #endif
+
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+	puts("PVBLOCK: ");
+	pvblock_init();
+	return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -780,6 +791,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_XEN
 	initr_xen,
+#endif
+#ifdef CONFIG_PVBLOCK
+	initr_pvblock,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
configs/xenguest_arm64_defconfig +4 -0
index 45559a161b..46473c251d 100644
@@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n
 CONFIG_CMD_BOOTEFI=n
 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
 CONFIG_CMD_ELF=n
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
 CONFIG_CMD_GO=n
 CONFIG_CMD_RUN=n
 CONFIG_CMD_IMI=n
@@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n
 CONFIG_CMD_SAVEENV=n
 CONFIG_CMD_UMS=n
 
+CONFIG_CMD_PVBLOCK=y
+
 #CONFIG_USB=n
 # CONFIG_ISO_PARTITION is not set
 
disk/part.c +4 -0
index f6a31025dc..b69fd345f3 100644
@@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc)
 	case IF_TYPE_MMC:
 	case IF_TYPE_USB:
 	case IF_TYPE_NVME:
+	case IF_TYPE_PVBLOCK:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -288,6 +289,9 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)
 	case IF_TYPE_NVME:
 		puts ("NVMe");
 		break;
+	case IF_TYPE_PVBLOCK:
+		puts("PV BLOCK");
+		break;
 	case IF_TYPE_VIRTIO:
 		puts("VirtIO");
 		break;
drivers/Kconfig +2 -0
index e34a22708c..65076aab03 100644
@@ -132,6 +132,8 @@ source "drivers/w1-eeprom/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/xen/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/block/blk-uclass.c +2 -0
index b19375cbc8..6cfabbca24 100644
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= "nvme",
 	[IF_TYPE_EFI]		= "efi",
 	[IF_TYPE_VIRTIO]	= "virtio",
+	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
@@ -43,6 +44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= UCLASS_NVME,
 	[IF_TYPE_EFI]		= UCLASS_EFI,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
+	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 
 static enum if_type if_typename_to_iftype(const char *if_typename)
drivers/xen/Kconfig new file +10 -0
new file mode 100644
index 0000000000..6ad2a93668
@@ -0,0 +1,10 @@
+config PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on DM
+	select BLK
+	select HAVE_BLOCK_DEVICE
+	help
+	  This driver implements the front-end of the Xen virtual
+	  block device driver. It communicates with a back-end driver
+	  in another domain which drives the actual block device.
+
drivers/xen/Makefile +2 -0
index 243b13277a..87157df69b 100644
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
 obj-y += events.o
 obj-y += xenbus.o
 obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
drivers/xen/pvblock.c new file +0 -0
new file mode 100644
index 0000000000..057add9753

drivers/xen/pvblock.c line 2

Quoted 2 lines
drivers/xen/pvblock.c new file +2 -0
@@ -0,0 +1,121 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

See above.

Quoted 166 lines
drivers/xen/pvblock.c new file +119 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ */
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+
+#define DRV_NAME	"pvblock"
+#define DRV_NAME_BLK	"pvblock_blk"
+
+struct blkfront_dev {
+	char dummy;
+};
+
+static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
+{
+	return 0;
+}
+
+static void shutdown_blkfront(struct blkfront_dev *dev)
+{
+}
+
+ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
+		       void *buffer)
+{
+	return 0;
+}
+
+ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
+			const void *buffer)
+{
+	return 0;
+}
+
+static int pvblock_blk_bind(struct udevice *udev)
+{
+	return 0;
+}
+
+static int pvblock_blk_probe(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+	int ret;
+
+	ret = init_blkfront(0, blk_dev);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
+static int pvblock_blk_remove(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+
+	shutdown_blkfront(blk_dev);
+	return 0;
+}
+
+static const struct blk_ops pvblock_blk_ops = {
+	.read	= pvblock_blk_read,
+	.write	= pvblock_blk_write,
+};
+
+U_BOOT_DRIVER(pvblock_blk) = {
+	.name			= DRV_NAME_BLK,
+	.id			= UCLASS_BLK,
+	.ops			= &pvblock_blk_ops,
+	.bind			= pvblock_blk_bind,
+	.probe			= pvblock_blk_probe,
+	.remove			= pvblock_blk_remove,
+	.priv_auto_alloc_size	= sizeof(struct blkfront_dev),
+	.flags			= DM_FLAG_OS_PREPARE,
+};
+
+/*******************************************************************************
+ * Para-virtual block device class
+ *******************************************************************************/
+
+void pvblock_init(void)
+{
+	struct driver_info info;
+	struct udevice *udev;
+	struct uclass *uc;
+	int ret;
+
+	/*
+	 * At this point Xen drivers have already initialized,
+	 * so we can instantiate the class driver and enumerate
+	 * virtual block devices.
+	 */
+	info.name = DRV_NAME;
+	ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
+	if (ret < 0)
+		printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
+
+	/* Bootstrap virtual block devices class driver */
+	ret = uclass_get(UCLASS_PVBLOCK, &uc);
+	if (ret)
+		return;
+	uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
+}
+
+static int pvblock_probe(struct udevice *udev)
+{
+	return 0;
+}
+
+U_BOOT_DRIVER(pvblock_drv) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+	.probe		= pvblock_probe,
+};
+
+UCLASS_DRIVER(pvblock) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+};
include/blk.h +1 -0
index abcd4bedbb..9ee10fb80e 100644
@@ -33,6 +33,7 @@ enum if_type {
 	IF_TYPE_HOST,
 	IF_TYPE_NVME,
 	IF_TYPE_EFI,
+	IF_TYPE_PVBLOCK,
 	IF_TYPE_VIRTIO,
 
 	IF_TYPE_COUNT,			/* Number of interface types */
include/configs/xenguest_arm64.h +8 -0
index 467dabf1e5..2c0d3d64fb 100644
@@ -42,4 +42,12 @@
 #define CONFIG_CMDLINE_TAG            1
 #define CONFIG_INITRD_TAG             1
 
+#define CONFIG_CMD_RUN
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \
+	"pvblockboot=run loadimage;" \
+		"booti 0x90000000 - 0x88000000;\0"
+
 #endif /* __XENGUEST_ARM64_H */
include/dm/uclass-id.h +1 -0
index 7837d459f1..4bf7501204 100644
@@ -121,6 +121,7 @@ enum uclass_id {
 	UCLASS_W1,		/* Dallas 1-Wire bus */
 	UCLASS_W1_EEPROM,	/* one-wire EEPROMs */
 	UCLASS_WDT,		/* Watchdog Timer driver */
+	UCLASS_PVBLOCK,		/* Xen virtual block device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/pvblock.h new file +0 -0
new file mode 100644
index 0000000000..e3bb8ff9a7

include/pvblock.h line 2

Quoted 2 lines
include/pvblock.h new file +2 -0
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

See above.

scripts/checkpatch.pl is your friend.

include/pvblock.h line 9

Quoted 7 lines
include/pvblock.h new file +7 -0
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+

Document you functions as described in

https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation

Include the documentation in the HTML documentation generated by

make htmldocs.

Best regards

Heinrich

Quoted 4 lines
include/pvblock.h new file +3 -0
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
#41 lore raw

PATCH 12/17 xen: pvblock: Add initial support for para-virtualized block driver

Quoted 6 lines

Subject: Re: [PATCH 12/17] xen: pvblock: Add initial support for para-virtualized block driver

Quoted 2 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Quoted 7 lines
Quoted 5 lines

Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation.
Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices.

We already have virtual block devices: virtio_blk, efi_blk.

XEN has its own paravirtualization block, not virtio or efi.

Regards,
Peng.

Quoted 465 lines

They work fine using the exising UCLASS_BLK. Why do we need a new uclass?

Quoted 8 lines

Add new interface type IF_TYPE_PVBLOCK.

Implement basic driver setup by reading XenStore configuration.

Signed-off-by Oleksandr Andrushchenko

<[email protected]>

Quoted 12 lines
---
 cmd/Kconfig                      |   7 ++
 cmd/Makefile                     |   1 +
 cmd/pvblock.c                    |  31 ++++++++
 common/board_r.c                 |  14 ++++
 configs/xenguest_arm64_defconfig |   4 +
 disk/part.c                      |   4 +
 drivers/Kconfig                  |   2 +
 drivers/block/blk-uclass.c       |   2 +
 drivers/xen/Kconfig              |  10 +++
 drivers/xen/Makefile             |   2 +
 drivers/xen/pvblock.c            | 121

+++++++++++++++++++++++++++++++

Quoted 44 lines
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 ++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  12 +++
 15 files changed, 220 insertions(+)
 create mode 100644 cmd/pvblock.c
 create mode 100644 drivers/xen/Kconfig  create mode 100644

drivers/xen/pvblock.c create mode 100644 include/pvblock.h

cmd/Kconfig index 192b3b262f..f28576947b renamed from cmd/Kconfig +0 -0

100644

cmd/Kconfig +7 -0
@@ -1335,6 +1335,13 @@ config CMD_USB_MASS_STORAGE
 	help
 	  USB mass storage support
 
+config CMD_PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on XEN
+	select PVBLOCK
+	help
+	  Xen para-virtualized block device support
+
 config CMD_VIRTIO
 	bool "virtio"
 	depends on VIRTIO
cmd/Makefile index 974ad48b0a..117284a28c renamed from cmd/Makefile +0 -0

100644

cmd/Makefile +1 -0
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
+obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
 
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
cmd/pvblock.c new file mode 100644 index renamed from cmd/pvblock.c +0 -0

0000000000..7dbb243a74

cmd/pvblock.c line 2

Quoted 2 lines
cmd/pvblock.c new file +2 -0
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

Please, correct the formatting.

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.
kernel.org%2Fdoc%2Fhtml%2Flatest%2Fprocess%2Flicense-rules.html%23lic ense-identifier-syntax&amp;data=02%7C01%7Cpeng.fan%40nxp.com%7C766 8aea23aa24f9cefe408d81e4086bc%7C686ea1d3bc2b4c6fa92cd99c5c30163 5%7C0%7C0%7C637292609781573766&amp;sdata=q8BMngBAzhdf9KmswU AEqp47ciZqJzHSo2mjiIWMQOM%3D&amp;reserved=0

configs/xenguest_arm64_defconfig CONFIG_CMD_LZMADEC=n

Quoted 81 lines
cmd/pvblock.c new file +28 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ *
+ * XEN para-virtualized block device support */
+
+#include <blk.h>
+#include <common.h>
+#include <command.h>
+
+/* Current I/O Device	*/
+static int pvblock_curr_device;
+
+int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const
+argv[]) {
+	return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+			      &pvblock_curr_device);
+}
+
+U_BOOT_CMD(pvblock, 5, 1, do_pvblock,
+	   "Xen para-virtualized block device",
+	   "info  - show available block devices\n"
+	   "pvblock device [dev] - show or set current device\n"
+	   "pvblock part [dev] - print partition table of one or all devices\n"
+	   "pvblock read  addr blk# cnt\n"
+	   "pvblock write addr blk# cnt - read/write `cnt'"
+	   " blocks starting at block `blk#'\n"
+	   "    to/from memory address `addr'");
+
common/board_r.c index renamed from common/board_r.c +0 -0

fd36edb4e5..40cd0e5d3c 100644

common/board_r.c +14 -0
@@ -49,6 +49,7 @@
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -470,6 +471,16 @@ static int initr_xen(void)
 	return 0;
 }
 #endif
+
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+	puts("PVBLOCK: ");
+	pvblock_init();
+	return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -780,6 +791,9 @@ static init_fnc_t init_sequence_r[] = {  #endif
 #ifdef CONFIG_XEN
 	initr_xen,
+#endif
+#ifdef CONFIG_PVBLOCK
+	initr_pvblock,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
configs/xenguest_arm64_defconfig +2 -0
index 45559a161b..46473c251d 100644
@@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n
 CONFIG_CMD_BOOTEFI=n
 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
 CONFIG_CMD_ELF=n
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
 CONFIG_CMD_GO=n
 CONFIG_CMD_RUN=n
 CONFIG_CMD_IMI=n
@@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n

CONFIG_CMD_SAVEENV=n

disk/part.c static void print_part_header(const char *type,

Quoted 20 lines

CONFIG_CMD_UMS=n

configs/xenguest_arm64_defconfig +2 -0
+CONFIG_CMD_PVBLOCK=y
+
 #CONFIG_USB=n
 # CONFIG_ISO_PARTITION is not set
disk/part.c index f6a31025dc..b69fd345f3 renamed from disk/part.c +0 -0

100644

disk/part.c +1 -0
@@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc)
 	case IF_TYPE_MMC:
 	case IF_TYPE_USB:
 	case IF_TYPE_NVME:
+	case IF_TYPE_PVBLOCK:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -288,6 +289,9 @@ static void print_part_header(const char *type,

struct blk_desc *dev_desc)

drivers/block/blk-uclass.c static const char *if_typename_str[IF_TYPE_COUNT]

Quoted 27 lines
disk/part.c +3 -0
 	case IF_TYPE_NVME:
 		puts ("NVMe");
 		break;
+	case IF_TYPE_PVBLOCK:
+		puts("PV BLOCK");
+		break;
 	case IF_TYPE_VIRTIO:
 		puts("VirtIO");
 		break;
drivers/Kconfig index renamed from drivers/Kconfig +0 -0

e34a22708c..65076aab03 100644

drivers/Kconfig +2 -0
@@ -132,6 +132,8 @@ source "drivers/w1-eeprom/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/xen/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/block/blk-uclass.c +0 -0
index b19375cbc8..6cfabbca24 100644
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT]

= {

Quoted 45 lines
drivers/block/blk-uclass.c +3 -0
 	[IF_TYPE_NVME]		= "nvme",
 	[IF_TYPE_EFI]		= "efi",
 	[IF_TYPE_VIRTIO]	= "virtio",
+	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = { @@ -43,6
+44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= UCLASS_NVME,
 	[IF_TYPE_EFI]		= UCLASS_EFI,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
+	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 
 static enum if_type if_typename_to_iftype(const char *if_typename)
drivers/xen/Kconfig new file mode renamed from drivers/xen/Kconfig +0 -0

100644 index 0000000000..6ad2a93668

drivers/xen/Kconfig new file +10 -0
@@ -0,0 +1,10 @@
+config PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on DM
+	select BLK
+	select HAVE_BLOCK_DEVICE
+	help
+	  This driver implements the front-end of the Xen virtual
+	  block device driver. It communicates with a back-end driver
+	  in another domain which drives the actual block device.
+
drivers/xen/Makefile index renamed from drivers/xen/Makefile +0 -0

243b13277a..87157df69b 100644

drivers/xen/Makefile +2 -0
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
 obj-y += events.o
 obj-y += xenbus.o
 obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
drivers/xen/pvblock.c new file renamed from drivers/xen/pvblock.c +0 -0

mode 100644 index 0000000000..057add9753

drivers/xen/pvblock.c line 2

Quoted 2 lines
drivers/xen/pvblock.c new file +2 -0
@@ -0,0 +1,121 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

See above.

Quoted 13 lines
drivers/xen/pvblock.c new file +13 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ */
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+
+#define DRV_NAME	"pvblock"
+#define DRV_NAME_BLK	"pvblock_blk"
+
+struct blkfront_dev {
+	char dummy;

drivers/xen/pvblock.c

Quoted 10 lines
drivers/xen/pvblock.c new file +10 -0
+};
+
+static int init_blkfront(unsigned int devid, struct blkfront_dev
+*dev) {
+	return 0;
+}
+
+static void shutdown_blkfront(struct blkfront_dev *dev) { }
+
+ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t

blkcnt,

drivers/xen/pvblock.c

Quoted 6 lines
drivers/xen/pvblock.c new file +6 -0
+		       void *buffer)
+{
+	return 0;
+}
+
+ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t

blkcnt,

Quoted 33 lines
drivers/xen/pvblock.c new file +32 -0
+			const void *buffer)
+{
+	return 0;
+}
+
+static int pvblock_blk_bind(struct udevice *udev) {
+	return 0;
+}
+
+static int pvblock_blk_probe(struct udevice *udev) {
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+	int ret;
+
+	ret = init_blkfront(0, blk_dev);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
+static int pvblock_blk_remove(struct udevice *udev) {
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+
+	shutdown_blkfront(blk_dev);
+	return 0;
+}
+
+static const struct blk_ops pvblock_blk_ops = {
+	.read	= pvblock_blk_read,
+	.write	= pvblock_blk_write,
+};
+
+U_BOOT_DRIVER(pvblock_blk) = {

drivers/xen/pvblock.c line 78

Quoted 10 lines
drivers/xen/pvblock.c new file +10 -0
+	.name			= DRV_NAME_BLK,
+	.id			= UCLASS_BLK,
+	.ops			= &pvblock_blk_ops,
+	.bind			= pvblock_blk_bind,
+	.probe			= pvblock_blk_probe,
+	.remove			= pvblock_blk_remove,
+	.priv_auto_alloc_size	= sizeof(struct blkfront_dev),
+	.flags			= DM_FLAG_OS_PREPARE,
+};
+

+/************************************************************
********

drivers/xen/pvblock.c line 82

Quoted 4 lines
drivers/xen/pvblock.c new file +3 -0
+***********
+ * Para-virtual block device class
+

+*************************************************************
********

Quoted 86 lines
drivers/xen/pvblock.c new file +39 -0
+**********/
+
+void pvblock_init(void)
+{
+	struct driver_info info;
+	struct udevice *udev;
+	struct uclass *uc;
+	int ret;
+
+	/*
+	 * At this point Xen drivers have already initialized,
+	 * so we can instantiate the class driver and enumerate
+	 * virtual block devices.
+	 */
+	info.name = DRV_NAME;
+	ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
+	if (ret < 0)
+		printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
+
+	/* Bootstrap virtual block devices class driver */
+	ret = uclass_get(UCLASS_PVBLOCK, &uc);
+	if (ret)
+		return;
+	uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev); }
+
+static int pvblock_probe(struct udevice *udev) {
+	return 0;
+}
+
+U_BOOT_DRIVER(pvblock_drv) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+	.probe		= pvblock_probe,
+};
+
+UCLASS_DRIVER(pvblock) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+};
include/blk.h index renamed from include/blk.h +0 -0

abcd4bedbb..9ee10fb80e 100644

include/blk.h +1 -0
@@ -33,6 +33,7 @@ enum if_type {
 	IF_TYPE_HOST,
 	IF_TYPE_NVME,
 	IF_TYPE_EFI,
+	IF_TYPE_PVBLOCK,
 	IF_TYPE_VIRTIO,
 
 	IF_TYPE_COUNT,			/* Number of interface types */
include/configs/xenguest_arm64.h +8 -0
index 467dabf1e5..2c0d3d64fb 100644
@@ -42,4 +42,12 @@
 #define CONFIG_CMDLINE_TAG            1
 #define CONFIG_INITRD_TAG             1
 
+#define CONFIG_CMD_RUN
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \
+	"pvblockboot=run loadimage;" \
+		"booti 0x90000000 - 0x88000000;\0"
+
 #endif /* __XENGUEST_ARM64_H */
include/dm/uclass-id.h index renamed from include/dm/uclass-id.h +0 -0

7837d459f1..4bf7501204 100644

include/dm/uclass-id.h +1 -0
@@ -121,6 +121,7 @@ enum uclass_id {
 	UCLASS_W1,		/* Dallas 1-Wire bus */
 	UCLASS_W1_EEPROM,	/* one-wire EEPROMs */
 	UCLASS_WDT,		/* Watchdog Timer driver */
+	UCLASS_PVBLOCK,		/* Xen virtual block device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/pvblock.h new file mode renamed from include/pvblock.h +0 -0

100644 index 0000000000..e3bb8ff9a7

include/pvblock.h line 2

Quoted 2 lines
include/pvblock.h new file +2 -0
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

See above.

scripts/checkpatch.pl is your friend.

include/pvblock.h line 9

Quoted 7 lines
include/pvblock.h new file +7 -0
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+

Document you functions as described in

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.
kernel.org%2Fdoc%2Fhtml%2Flatest%2Fdoc-guide%2Fkernel-doc.html%23fu nction-documentation&amp;data=02%7C01%7Cpeng.fan%40nxp.com%7C76 68aea23aa24f9cefe408d81e4086bc%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C637292609781573766&amp;sdata=lMTLJLCWplR12spHSKs hcNUzWZ1Ce%2BNBSVHZX%2BgvSCk%3D&amp;reserved=0

Include the documentation in the HTML documentation generated by

make htmldocs.

Best regards

Heinrich

Quoted 4 lines
include/pvblock.h new file +3 -0
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
#42 lore raw

PATCH 12/17 xen: pvblock: Add initial support for para-virtualized block driver

In reply to Heinrich Schuchardt

Hi Heinrich,

Quoted 9 lines · Heinrich Schuchardt
Quoted 7 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation.
Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices.

Quoted 5 lines

We already have virtual block devices: virtio_blk, efi_blk.

They work fine using the exising UCLASS_BLK. Why do we need a new uclass?

During the implementation we had a discussion with Simon Glass on that [1]. PVBLOCK could be just a UCLASS_BLK driver with the parent being gd->dm_root, but in this case most of the file system/block device commands fail to work as those expect that pvblock driver must be a parent device and pvblock blk device must be its child to comply to U-boot driver architecture.

When we bind a new driver [2], we need to specify it's parent. There is no UCLASS_BLK device available at that moment, therefore it is possible to use only a UCLASS_ROOT device, but parent and child interface types must be the same [3].

So, then we need interface to be defined as [IF_TYPE_PVBLOCK] = UCLASS_ROOT which doesn't seem to be right. Thereby, we created a new UCLASS_PVBLOCK class for para-virtual block devices [4].

The driver class provides methods for accessing the "bus" and actually implements the ops for reading and writing. But, we don't have a "bus" or a common transport as virtio has, so we are a bit different with that respect from the drivers you mentioned.

[1] - https://www.mail-archive.com/u-boot at lists.denx.de/msg371956.html
[2] -
https://github.com/xen-troops/u-boot/blob/master/drivers/xen/pvblock.c#L697
[3] -
https://github.com/xen-troops/u-boot/blob/master/drivers/block/blk-uclass.c#L124
[4] -
https://github.com/xen-troops/u-boot/blob/master/drivers/block/blk-uclass.c#L47

Quoted 60 lines
Quoted 60 lines

Add new interface type IF_TYPE_PVBLOCK.

Implement basic driver setup by reading XenStore configuration.

Signed-off-by Anastasiia Lukianenko <

anastasiia_lukianenko at epam.com>
Signed-off-by: Oleksandr Andrushchenko <
oleksandr_andrushchenko at epam.com>

---
 cmd/Kconfig                      |   7 ++
 cmd/Makefile                     |   1 +
 cmd/pvblock.c                    |  31 ++++++++
 common/board_r.c                 |  14 ++++
 configs/xenguest_arm64_defconfig |   4 +
 disk/part.c                      |   4 +
 drivers/Kconfig                  |   2 +
 drivers/block/blk-uclass.c       |   2 +
 drivers/xen/Kconfig              |  10 +++
 drivers/xen/Makefile             |   2 +
 drivers/xen/pvblock.c            | 121
+++++++++++++++++++++++++++++++
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 ++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  12 +++
 15 files changed, 220 insertions(+)
 create mode 100644 cmd/pvblock.c
 create mode 100644 drivers/xen/Kconfig
 create mode 100644 drivers/xen/pvblock.c
 create mode 100644 include/pvblock.h
cmd/Kconfig +7 -0
index 192b3b262f..f28576947b 100644
@@ -1335,6 +1335,13 @@ config CMD_USB_MASS_STORAGE
 	help
 	  USB mass storage support
 
+config CMD_PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on XEN
+	select PVBLOCK
+	help
+	  Xen para-virtualized block device support
+
 config CMD_VIRTIO
 	bool "virtio"
 	depends on VIRTIO
cmd/Makefile +1 -0
index 974ad48b0a..117284a28c 100644
@@ -169,6 +169,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
+obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
 
Quoted 14 lines

cmd/pvblock.c line 2

Quoted 10 lines
cmd/Makefile +0 -0
 # Power
 obj-$(CONFIG_CMD_PMIC) += pmic.o
cmd/pvblock.c new file +2 -0
new file mode 100644
index 0000000000..7dbb243a74
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

Please, correct the formatting.

https://urldefense.com/v3/__https://www.kernel.org/doc/html/latest/process/license-rules.html*license-identifier-syntax__;Iw!!GF_29dbcQIUBPA!jxsFCyOKmFzfwm6JpWhcYhyr_qGk_okiGw-S0zzuQwWAleeoT0qjgG6bmf0_OfcJMo3d-dM$

Quoted 2 lines

Ok.

Quoted 180 lines
Quoted 180 lines
cmd/pvblock.c new file +14 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ *
+ * XEN para-virtualized block device support
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <command.h>
+
+/* Current I/O Device	*/
+static int pvblock_curr_device;
+
+int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char

*const argv[])

cmd/pvblock.c new file +10 -0
+{
+	return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+			      &pvblock_curr_device);
+}
+
+U_BOOT_CMD(pvblock, 5, 1, do_pvblock,
+	   "Xen para-virtualized block device",
+	   "info  - show available block devices\n"
+	   "pvblock device [dev] - show or set current device\n"
+	   "pvblock part [dev] - print partition table of one or all

devices\n"

cmd/pvblock.c new file +5 -0
+	   "pvblock read  addr blk# cnt\n"
+	   "pvblock write addr blk# cnt - read/write `cnt'"
+	   " blocks starting at block `blk#'\n"
+	   "    to/from memory address `addr'");
+
common/board_r.c +14 -0
index fd36edb4e5..40cd0e5d3c 100644
@@ -49,6 +49,7 @@
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -470,6 +471,16 @@ static int initr_xen(void)
 	return 0;
 }
 #endif
+
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+	puts("PVBLOCK: ");
+	pvblock_init();
+	return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -780,6 +791,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_XEN
 	initr_xen,
+#endif
+#ifdef CONFIG_PVBLOCK
+	initr_pvblock,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
configs/xenguest_arm64_defconfig +4 -0
index 45559a161b..46473c251d 100644
@@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n
 CONFIG_CMD_BOOTEFI=n
 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
 CONFIG_CMD_ELF=n
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_FAT=y
 CONFIG_CMD_GO=n
 CONFIG_CMD_RUN=n
 CONFIG_CMD_IMI=n
@@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n
 CONFIG_CMD_SAVEENV=n
 CONFIG_CMD_UMS=n
 
+CONFIG_CMD_PVBLOCK=y
+
 #CONFIG_USB=n
 # CONFIG_ISO_PARTITION is not set
 
disk/part.c +4 -0
index f6a31025dc..b69fd345f3 100644
@@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc)
 	case IF_TYPE_MMC:
 	case IF_TYPE_USB:
 	case IF_TYPE_NVME:
+	case IF_TYPE_PVBLOCK:
 		printf ("Vendor: %s Rev: %s Prod: %s\n",
 			dev_desc->vendor,
 			dev_desc->revision,
@@ -288,6 +289,9 @@ static void print_part_header(const char *type,
 struct blk_desc *dev_desc)
 	case IF_TYPE_NVME:
 		puts ("NVMe");
 		break;
+	case IF_TYPE_PVBLOCK:
+		puts("PV BLOCK");
+		break;
 	case IF_TYPE_VIRTIO:
 		puts("VirtIO");
disk/part.c +0 -0
 		break;
drivers/Kconfig +2 -0
index e34a22708c..65076aab03 100644
@@ -132,6 +132,8 @@ source "drivers/w1-eeprom/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/xen/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/block/blk- renamed from drivers/block/blk-uclass.c +0 -0

uclass.c
index b19375cbc8..6cfabbca24 100644

drivers/block/blk-uclass.c +1 -0
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT]
 = {
 	[IF_TYPE_NVME]		= "nvme",
 	[IF_TYPE_EFI]		= "efi",
 	[IF_TYPE_VIRTIO]	= "virtio",
+	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 

static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {

drivers/block/blk-uclass.c +1 -0
@@ -43,6 +44,7 @@ static enum uclass_id
 if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_NVME]		= UCLASS_NVME,
 	[IF_TYPE_EFI]		= UCLASS_EFI,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
+	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 

static enum if_type if_typename_to_iftype(const char *if_typename)

drivers/xen/Kconfig new file +10 -0
new file mode 100644
index 0000000000..6ad2a93668
@@ -0,0 +1,10 @@
+config PVBLOCK
+	bool "Xen para-virtualized block device"
+	depends on DM
+	select BLK
+	select HAVE_BLOCK_DEVICE
+	help
+	  This driver implements the front-end of the Xen virtual
+	  block device driver. It communicates with a back-end driver
+	  in another domain which drives the actual block device.
+
drivers/xen/Makefile +2 -0
index 243b13277a..87157df69b 100644
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
 obj-y += events.o
 obj-y += xenbus.o
 obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
drivers/xen/pvblock.c new file +0 -0
new file mode 100644
Quoted 9 lines

drivers/xen/pvblock.c line 2

Quoted 6 lines

index 0000000000..057add9753

drivers/xen/pvblock.c new file +2 -0
@@ -0,0 +1,121 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

See above.

Ok, will fix.

Quoted 181 lines
Quoted 174 lines
drivers/xen/pvblock.c new file +16 -0
+ *
+ * (C) Copyright 2020 EPAM Systems Inc.
+ */
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+
+#define DRV_NAME	"pvblock"
+#define DRV_NAME_BLK	"pvblock_blk"
+
+struct blkfront_dev {
+	char dummy;
+};
+
+static int init_blkfront(unsigned int devid, struct blkfront_dev

*dev)

drivers/xen/pvblock.c new file +9 -0
+{
+	return 0;
+}
+
+static void shutdown_blkfront(struct blkfront_dev *dev)
+{
+}
+
+ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr,

lbaint_t blkcnt,

drivers/xen/pvblock.c new file +6 -0
+		       void *buffer)
+{
+	return 0;
+}
+
+ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr,

lbaint_t blkcnt,

drivers/xen/pvblock.c new file +46 -0
+			const void *buffer)
+{
+	return 0;
+}
+
+static int pvblock_blk_bind(struct udevice *udev)
+{
+	return 0;
+}
+
+static int pvblock_blk_probe(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+	int ret;
+
+	ret = init_blkfront(0, blk_dev);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
+static int pvblock_blk_remove(struct udevice *udev)
+{
+	struct blkfront_dev *blk_dev = dev_get_priv(udev);
+
+	shutdown_blkfront(blk_dev);
+	return 0;
+}
+
+static const struct blk_ops pvblock_blk_ops = {
+	.read	= pvblock_blk_read,
+	.write	= pvblock_blk_write,
+};
+
+U_BOOT_DRIVER(pvblock_blk) = {
+	.name			= DRV_NAME_BLK,
+	.id			= UCLASS_BLK,
+	.ops			= &pvblock_blk_ops,
+	.bind			= pvblock_blk_bind,
+	.probe			= pvblock_blk_probe,
+	.remove			= pvblock_blk_remove,
+	.priv_auto_alloc_size	= sizeof(struct blkfront_dev),
+	.flags			= DM_FLAG_OS_PREPARE,
+};
+
+/*****************************************************************

**************
+ * Para-virtual block device class
+
*******************************************************************
************/

drivers/xen/pvblock.c new file +40 -0
+
+void pvblock_init(void)
+{
+	struct driver_info info;
+	struct udevice *udev;
+	struct uclass *uc;
+	int ret;
+
+	/*
+	 * At this point Xen drivers have already initialized,
+	 * so we can instantiate the class driver and enumerate
+	 * virtual block devices.
+	 */
+	info.name = DRV_NAME;
+	ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
+	if (ret < 0)
+		printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
+
+	/* Bootstrap virtual block devices class driver */
+	ret = uclass_get(UCLASS_PVBLOCK, &uc);
+	if (ret)
+		return;
+	uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
+}
+
+static int pvblock_probe(struct udevice *udev)
+{
+	return 0;
+}
+
+U_BOOT_DRIVER(pvblock_drv) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+	.probe		= pvblock_probe,
+};
+
+UCLASS_DRIVER(pvblock) = {
+	.name		= DRV_NAME,
+	.id		= UCLASS_PVBLOCK,
+};
include/blk.h +1 -0
index abcd4bedbb..9ee10fb80e 100644
@@ -33,6 +33,7 @@ enum if_type {
 	IF_TYPE_HOST,
 	IF_TYPE_NVME,
 	IF_TYPE_EFI,
+	IF_TYPE_PVBLOCK,
 	IF_TYPE_VIRTIO,
 
 	IF_TYPE_COUNT,			/* Number of interface

types */

include/configs/xenguest_arm64.h +8 -0
index 467dabf1e5..2c0d3d64fb 100644
@@ -42,4 +42,12 @@
 #define CONFIG_CMDLINE_TAG            1
 #define CONFIG_INITRD_TAG             1
 
+#define CONFIG_CMD_RUN
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+	"loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \
+	"pvblockboot=run loadimage;" \
+		"booti 0x90000000 - 0x88000000;\0"
+
 #endif /* __XENGUEST_ARM64_H */
include/dm/uclass-id.h +1 -0
index 7837d459f1..4bf7501204 100644
@@ -121,6 +121,7 @@ enum uclass_id {
 	UCLASS_W1,		/* Dallas 1-Wire bus */
 	UCLASS_W1_EEPROM,	/* one-wire EEPROMs */
 	UCLASS_WDT,		/* Watchdog Timer driver */
+	UCLASS_PVBLOCK,		/* Xen virtual block device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/pvblock.h new file +0 -0
new file mode 100644
index 0000000000..e3bb8ff9a7

include/pvblock.h line 2

Quoted 2 lines
include/pvblock.h new file +2 -0
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+

See above.

scripts/checkpatch.pl is your friend.

Quoted 11 lines

include/pvblock.h line 9

Quoted 7 lines
include/pvblock.h new file +7 -0
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+

Document you functions as described in

https://urldefense.com/v3/__https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html*function-documentation__;Iw!!GF_29dbcQIUBPA!jxsFCyOKmFzfwm6JpWhcYhyr_qGk_okiGw-S0zzuQwWAleeoT0qjgG6bmf0_OfcJcWTT8IY$

Quoted 6 lines

Include the documentation in the HTML documentation generated by

make htmldocs.

Ok, will add.

Quoted 5 lines

Best regards

Heinrich

Best regards,
Anastasiia

Quoted 6 lines
Quoted 4 lines
include/pvblock.h new file +3 -0
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
#43 lore raw

PATCH 13/17 xen: pvblock: Enumerate virtual block devices

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Enumerate Xen virtual block devices found in XenStore and instantiate pvblock devices.

---
 drivers/xen/pvblock.c | 112 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 110 insertions(+), 2 deletions(-)
drivers/xen/pvblock.c +110 -2
index 057add9753..6ce0ae97c3 100644
@@ -7,6 +7,10 @@
 #include <common.h>
 #include <dm.h>
 #include <dm/device-internal.h>
+#include <malloc.h>
+#include <part.h>
+
+#include <xen/xenbus.h>
 
 #define DRV_NAME	"pvblock"
 #define DRV_NAME_BLK	"pvblock_blk"
@@ -15,6 +19,10 @@ struct blkfront_dev {
 	char dummy;
 };
 
+struct blkfront_platdata {
+	unsigned int devid;
+};
+
 static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
 {
 	return 0;
@@ -38,15 +46,40 @@ ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
 
 static int pvblock_blk_bind(struct udevice *udev)
 {
+	struct blk_desc *desc = dev_get_uclass_platdata(udev);
+	int devnum;
+
+	desc->if_type = IF_TYPE_PVBLOCK;
+	/*
+	 * Initialize the devnum to -ENODEV. This is to make sure that
+	 * blk_next_free_devnum() works as expected, since the default
+	 * value 0 is a valid devnum.
+	 */
+	desc->devnum = -ENODEV;
+	devnum = blk_next_free_devnum(IF_TYPE_PVBLOCK);
+	if (devnum < 0)
+		return devnum;
+	desc->devnum = devnum;
+	desc->part_type = PART_TYPE_UNKNOWN;
+	desc->bdev = udev;
+
+	strncpy(desc->vendor, "Xen", sizeof(desc->vendor));
+	strncpy(desc->revision, "1", sizeof(desc->revision));
+	strncpy(desc->product, "Virtual disk", sizeof(desc->product));
+
 	return 0;
 }
 
 static int pvblock_blk_probe(struct udevice *udev)
 {
 	struct blkfront_dev *blk_dev = dev_get_priv(udev);
-	int ret;
+	struct blkfront_platdata *platdata = dev_get_platdata(udev);
+	int ret, devid;
 
-	ret = init_blkfront(0, blk_dev);
+	devid = platdata->devid;
+	free(platdata);
+
+	ret = init_blkfront(devid, blk_dev);
 	if (ret < 0)
 		return ret;
 	return 0;
@@ -80,6 +113,68 @@ U_BOOT_DRIVER(pvblock_blk) = {
  * Para-virtual block device class
  *******************************************************************************/
 
+typedef int (*enum_vbd_callback)(struct udevice *parent, unsigned int devid);
+
+static int on_new_vbd(struct udevice *parent, unsigned int devid)
+{
+	struct driver_info info;
+	struct udevice *udev;
+	struct blkfront_platdata *platdata;
+	int ret;
+
+	debug("New " DRV_NAME_BLK ", device ID %d\n", devid);
+
+	platdata = malloc(sizeof(struct blkfront_platdata));
+	if (!platdata) {
+		printf("Failed to allocate platform data\n");
+		return -ENOMEM;
+	}
+
+	platdata->devid = devid;
+
+	info.name = DRV_NAME_BLK;
+	info.platdata = platdata;
+
+	ret = device_bind_by_name(parent, false, &info, &udev);
+	if (ret < 0) {
+		printf("Failed to bind " DRV_NAME_BLK " to device with ID %d, ret: %d\n",
+		       devid, ret);
+		free(platdata);
+	}
+	return ret;
+}
+
+static int xenbus_enumerate_vbd(struct udevice *udev, enum_vbd_callback clb)
+{
+	char **dirs, *msg;
+	int i, ret;
+
+	msg = xenbus_ls(XBT_NIL, "device/vbd", &dirs);
+	if (msg) {
+		printf("Failed to read device/vbd directory: %s\n", msg);
+		free(msg);
+		return -ENODEV;
+	}
+
+	for (i = 0; dirs[i]; i++) {
+		int devid;
+
+		sscanf(dirs[i], "%d", &devid);
+		ret = clb(udev, devid);
+		if (ret < 0)
+			goto fail;
+
+		free(dirs[i]);
+	}
+	ret = 0;
+
+fail:
+	for (; dirs[i]; i++)
+		free(dirs[i]);
+	free(dirs);
+	return ret;
+}
+
 void pvblock_init(void)
 {
 	struct driver_info info;
@@ -106,6 +201,19 @@ void pvblock_init(void)
 
 static int pvblock_probe(struct udevice *udev)
 {
+	struct uclass *uc;
+	int ret;
+
+	if (xenbus_enumerate_vbd(udev, on_new_vbd) < 0)
+		return -ENODEV;
+
+	ret = uclass_get(UCLASS_BLK, &uc);
+	if (ret)
+		return ret;
+	uclass_foreach_dev_probe(UCLASS_BLK, udev) {
+		if (_ret)
+			return _ret;
+	};
 	return 0;
 }
 
Signature · 1 line
2.17.1
#44 lore raw

PATCH 13/17 xen: pvblock: Enumerate virtual block devices

Quoted 11 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Enumerate Xen virtual block devices found in XenStore and instantiate pvblock devices.

---
 drivers/xen/pvblock.c | 112 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 110 insertions(+), 2 deletions(-)
#45 lore raw

PATCH 14/17 xen: pvblock: Read XenStore configuration and initialize

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Read essential virtual block device configuration data from XenStore, initialize front ring and event channel.
Update block device description with actual block size.

Use code for XenStore from mini-os.

---
 drivers/xen/pvblock.c | 272 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 271 insertions(+), 1 deletion(-)
drivers/xen/pvblock.c +271 -1
index 6ce0ae97c3..9ed18be633 100644
@@ -1,6 +1,7 @@
 /*
  * SPDX-License-Identifier:	GPL-2.0+
  *
+ * (C) 2007-2008 Samuel Thibault.
  * (C) Copyright 2020 EPAM Systems Inc.
  */
 #include <blk.h>
@@ -10,26 +11,289 @@
 #include <malloc.h>
 #include <part.h>
 
+#include <asm/armv8/mmu.h>
+#include <asm/io.h>
+#include <asm/xen/system.h>
+
+#include <linux/compat.h>
+
+#include <xen/events.h>
+#include <xen/gnttab.h>
+#include <xen/hvm.h>
 #include <xen/xenbus.h>
 
+#include <xen/interface/io/ring.h>
+#include <xen/interface/io/blkif.h>
+#include <xen/interface/io/protocols.h>
+
 #define DRV_NAME	"pvblock"
 #define DRV_NAME_BLK	"pvblock_blk"
 
+#define O_RDONLY	00
+#define O_RDWR		02
+
+struct blkfront_info {
+	u64 sectors;
+	unsigned int sector_size;
+	int mode;
+	int info;
+	int barrier;
+	int flush;
+};
+
 struct blkfront_dev {
-	char dummy;
+	domid_t dom;
+
+	struct blkif_front_ring ring;
+	grant_ref_t ring_ref;
+	evtchn_port_t evtchn;
+	blkif_vdev_t handle;
+
+	char *nodename;
+	char *backend;
+	struct blkfront_info info;
+	unsigned int devid;
 };
 
 struct blkfront_platdata {
 	unsigned int devid;
 };
 
+static void free_blkfront(struct blkfront_dev *dev)
+{
+	mask_evtchn(dev->evtchn);
+	free(dev->backend);
+
+	gnttab_end_access(dev->ring_ref);
+	free(dev->ring.sring);
+
+	unbind_evtchn(dev->evtchn);
+
+	free(dev->nodename);
+	free(dev);
+}
+
+static void blkfront_handler(evtchn_port_t port, struct pt_regs *regs,
+			     void *data)
+{
+	printf("%s [Port %d] - event received\n", __func__, port);
+}
+
 static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
 {
+	xenbus_transaction_t xbt;
+	char *err = NULL;
+	char *message = NULL;
+	struct blkif_sring *s;
+	int retry = 0;
+	char *msg = NULL;
+	char *c;
+	char nodename[32];
+	char path[ARRAY_SIZE(nodename) + strlen("/backend-id") + 1];
+
+	sprintf(nodename, "device/vbd/%d", devid);
+
+	memset(dev, 0, sizeof(*dev));
+	dev->nodename = strdup(nodename);
+	dev->devid = devid;
+
+	snprintf(path, sizeof(path), "%s/backend-id", nodename);
+	dev->dom = xenbus_read_integer(path);
+	evtchn_alloc_unbound(dev->dom, blkfront_handler, dev, &dev->evtchn);
+
+	s = (struct blkif_sring *)memalign(PAGE_SIZE, PAGE_SIZE);
+	if (!s) {
+		printf("Failed to allocate shared ring\n");
+		goto error;
+	}
+
+	SHARED_RING_INIT(s);
+	FRONT_RING_INIT(&dev->ring, s, PAGE_SIZE);
+
+	dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_pfn(s), 0);
+
+again:
+	err = xenbus_transaction_start(&xbt);
+	if (err) {
+		printf("starting transaction\n");
+		free(err);
+	}
+
+	err = xenbus_printf(xbt, nodename, "ring-ref", "%u", dev->ring_ref);
+	if (err) {
+		message = "writing ring-ref";
+		goto abort_transaction;
+	}
+	err = xenbus_printf(xbt, nodename, "event-channel", "%u", dev->evtchn);
+	if (err) {
+		message = "writing event-channel";
+		goto abort_transaction;
+	}
+	err = xenbus_printf(xbt, nodename, "protocol", "%s",
+			    XEN_IO_PROTO_ABI_NATIVE);
+	if (err) {
+		message = "writing protocol";
+		goto abort_transaction;
+	}
+
+	snprintf(path, sizeof(path), "%s/state", nodename);
+	err = xenbus_switch_state(xbt, path, XenbusStateConnected);
+	if (err) {
+		message = "switching state";
+		goto abort_transaction;
+	}
+
+	err = xenbus_transaction_end(xbt, 0, &retry);
+	free(err);
+	if (retry) {
+		goto again;
+		printf("completing transaction\n");
+	}
+
+	goto done;
+
+abort_transaction:
+	free(err);
+	err = xenbus_transaction_end(xbt, 1, &retry);
+	printf("Abort transaction %s\n", message);
+	goto error;
+
+done:
+	snprintf(path, sizeof(path), "%s/backend", nodename);
+	msg = xenbus_read(XBT_NIL, path, &dev->backend);
+	if (msg) {
+		printf("Error %s when reading the backend path %s\n",
+		       msg, path);
+		goto error;
+	}
+
+	dev->handle = strtoul(strrchr(nodename, '/') + 1, NULL, 0);
+
+	{
+		XenbusState state;
+		char path[strlen(dev->backend) +
+			strlen("/feature-flush-cache") + 1];
+
+		snprintf(path, sizeof(path), "%s/mode", dev->backend);
+		msg = xenbus_read(XBT_NIL, path, &c);
+		if (msg) {
+			printf("Error %s when reading the mode\n", msg);
+			goto error;
+		}
+		if (*c == 'w')
+			dev->info.mode = O_RDWR;
+		else
+			dev->info.mode = O_RDONLY;
+		free(c);
+
+		snprintf(path, sizeof(path), "%s/state", dev->backend);
+
+		msg = NULL;
+		state = xenbus_read_integer(path);
+		while (msg == NULL && state < XenbusStateConnected)
+			msg = xenbus_wait_for_state_change(path, &state);
+		if (msg != NULL || state != XenbusStateConnected) {
+			printf("backend not available, state=%d\n", state);
+			goto error;
+		}
+
+		snprintf(path, sizeof(path), "%s/info", dev->backend);
+		dev->info.info = xenbus_read_integer(path);
+
+		snprintf(path, sizeof(path), "%s/sectors", dev->backend);
+		/*
+		 * FIXME: read_integer returns an int, so disk size
+		 * limited to 1TB for now
+		 */
+		dev->info.sectors = xenbus_read_integer(path);
+
+		snprintf(path, sizeof(path), "%s/sector-size", dev->backend);
+		dev->info.sector_size = xenbus_read_integer(path);
+
+		snprintf(path, sizeof(path), "%s/feature-barrier",
+			 dev->backend);
+		dev->info.barrier = xenbus_read_integer(path);
+
+		snprintf(path, sizeof(path), "%s/feature-flush-cache",
+			 dev->backend);
+		dev->info.flush = xenbus_read_integer(path);
+	}
+	unmask_evtchn(dev->evtchn);
+
+	debug("%llu sectors of %u bytes\n",
+	      dev->info.sectors, dev->info.sector_size);
+
 	return 0;
+
+error:
+	free(msg);
+	free(err);
+	free_blkfront(dev);
+	return -ENODEV;
 }
 
 static void shutdown_blkfront(struct blkfront_dev *dev)
 {
+	char *err = NULL, *err2;
+	XenbusState state;
+
+	char path[strlen(dev->backend) + strlen("/state") + 1];
+	char nodename[strlen(dev->nodename) + strlen("/event-channel") + 1];
+
+	debug("Close " DRV_NAME ", device ID %d\n", dev->devid);
+
+	snprintf(path, sizeof(path), "%s/state", dev->backend);
+	snprintf(nodename, sizeof(nodename), "%s/state", dev->nodename);
+
+	if ((err = xenbus_switch_state(XBT_NIL, nodename,
+				       XenbusStateClosing)) != NULL) {
+		printf("%s: error changing state to %d: %s\n", __func__,
+		       XenbusStateClosing, err);
+		goto close;
+	}
+
+	state = xenbus_read_integer(path);
+	while (err == NULL && state < XenbusStateClosing)
+		err = xenbus_wait_for_state_change(path, &state);
+	free(err);
+
+	if ((err = xenbus_switch_state(XBT_NIL, nodename,
+				       XenbusStateClosed)) != NULL) {
+		printf("%s: error changing state to %d: %s\n", __func__,
+		       XenbusStateClosed, err);
+		goto close;
+	}
+
+	state = xenbus_read_integer(path);
+	while (state < XenbusStateClosed) {
+		err = xenbus_wait_for_state_change(path, &state);
+		free(err);
+	}
+
+	if ((err = xenbus_switch_state(XBT_NIL, nodename,
+				       XenbusStateInitialising)) != NULL) {
+		printf("%s: error changing state to %d: %s\n", __func__,
+		       XenbusStateInitialising, err);
+		goto close;
+	}
+
+	state = xenbus_read_integer(path);
+	while (err == NULL &&
+	       (state < XenbusStateInitWait || state >= XenbusStateClosed))
+		err = xenbus_wait_for_state_change(path, &state);
+
+close:
+	free(err);
+
+	snprintf(nodename, sizeof(nodename), "%s/ring-ref", dev->nodename);
+	err2 = xenbus_rm(XBT_NIL, nodename);
+	free(err2);
+	snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename);
+	err2 = xenbus_rm(XBT_NIL, nodename);
+	free(err2);
+
+	if (!err)
+		free_blkfront(dev);
 }
 
 ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
@@ -74,6 +338,7 @@ static int pvblock_blk_probe(struct udevice *udev)
 {
 	struct blkfront_dev *blk_dev = dev_get_priv(udev);
 	struct blkfront_platdata *platdata = dev_get_platdata(udev);
+	struct blk_desc *desc = dev_get_uclass_platdata(udev);
 	int ret, devid;
 
 	devid = platdata->devid;
@@ -82,6 +347,11 @@ static int pvblock_blk_probe(struct udevice *udev)
 	ret = init_blkfront(devid, blk_dev);
 	if (ret < 0)
 		return ret;
+
+	desc->blksz = blk_dev->info.sector_size;
+	desc->lba = blk_dev->info.sectors;
+	desc->log2blksz = LOG2(blk_dev->info.sector_size);
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#46 lore raw

PATCH 14/17 xen: pvblock: Read XenStore configuration and initialize

Hi Anastasiia,

Quoted 64 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Read essential virtual block device configuration data from XenStore, initialize front ring and event channel.
Update block device description with actual block size.

Use code for XenStore from mini-os.

---
 drivers/xen/pvblock.c | 272 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 271 insertions(+), 1 deletion(-)
drivers/xen/pvblock.c +27 -1
index 6ce0ae97c3..9ed18be633 100644
@@ -1,6 +1,7 @@
 /*
  * SPDX-License-Identifier:    GPL-2.0+
  *
+ * (C) 2007-2008 Samuel Thibault.
  * (C) Copyright 2020 EPAM Systems Inc.
  */
 #include <blk.h>
@@ -10,26 +11,289 @@
 #include <malloc.h>
 #include <part.h>
 
+#include <asm/armv8/mmu.h>
+#include <asm/io.h>
+#include <asm/xen/system.h>
+
+#include <linux/compat.h>
+
+#include <xen/events.h>
+#include <xen/gnttab.h>
+#include <xen/hvm.h>
 #include <xen/xenbus.h>
 
+#include <xen/interface/io/ring.h>
+#include <xen/interface/io/blkif.h>
+#include <xen/interface/io/protocols.h>
+
 #define DRV_NAME       "pvblock"
 #define DRV_NAME_BLK   "pvblock_blk"
 
+#define O_RDONLY       00
+#define O_RDWR         02
+
+struct blkfront_info {
+       u64 sectors;
+       unsigned int sector_size;
+       int mode;
+       int info;
+       int barrier;
+       int flush;
+};
+
 struct blkfront_dev {
-       char dummy;
+       domid_t dom;

drivers/xen/pvblock.c line 55

Quoted 10 lines
drivers/xen/pvblock.c +10 -0
+
+       struct blkif_front_ring ring;
+       grant_ref_t ring_ref;
+       evtchn_port_t evtchn;
+       blkif_vdev_t handle;
+
+       char *nodename;
+       char *backend;
+       struct blkfront_info info;
+       unsigned int devid;

How about some comments?

Regards,
Simon

#47 lore raw

PATCH 14/17 xen: pvblock: Read XenStore configuration and initialize

Quoted 76 lines · Simon Glass

Hi Anastasiia,

Quoted 72 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Read essential virtual block device configuration data from XenStore,
initialize front ring and event channel.
Update block device description with actual block size.

Use code for XenStore from mini-os.

Signed-off-by: Oleksandr Andrushchenko <
oleksandr_andrushchenko at epam.com>
Signed-off-by: Anastasiia Lukianenko <
anastasiia_lukianenko at epam.com>

---
 drivers/xen/pvblock.c | 272
+++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 271 insertions(+), 1 deletion(-)
drivers/xen/pvblock.c +31 -1
index 6ce0ae97c3..9ed18be633 100644
@@ -1,6 +1,7 @@
 /*
  * SPDX-License-Identifier:    GPL-2.0+
  *
+ * (C) 2007-2008 Samuel Thibault.
  * (C) Copyright 2020 EPAM Systems Inc.
  */
 #include <blk.h>
@@ -10,26 +11,289 @@
 #include <malloc.h>
 #include <part.h>
 
+#include <asm/armv8/mmu.h>
+#include <asm/io.h>
+#include <asm/xen/system.h>
+
+#include <linux/compat.h>
+
+#include <xen/events.h>
+#include <xen/gnttab.h>
+#include <xen/hvm.h>
 #include <xen/xenbus.h>
 
+#include <xen/interface/io/ring.h>
+#include <xen/interface/io/blkif.h>
+#include <xen/interface/io/protocols.h>
+
 #define DRV_NAME       "pvblock"
 #define DRV_NAME_BLK   "pvblock_blk"
 
+#define O_RDONLY       00
+#define O_RDWR         02
+
+struct blkfront_info {
+       u64 sectors;
+       unsigned int sector_size;
+       int mode;
+       int info;
+       int barrier;
+       int flush;
+};
+
 struct blkfront_dev {
-       char dummy;
+       domid_t dom;
+
+       struct blkif_front_ring ring;
+       grant_ref_t ring_ref;
+       evtchn_port_t evtchn;
Quoted 9 lines

drivers/xen/pvblock.c line 55

Quoted 6 lines
drivers/xen/pvblock.c +6 -0
+       blkif_vdev_t handle;
+
+       char *nodename;
+       char *backend;
+       struct blkfront_info info;
+       unsigned int devid;

How about some comments?

Ok, will add.

Quoted 2 lines

Regards,
Simon

Regards,
Anastasiia

#48 lore raw

PATCH 15/17 xen: pvblock: Implement front-back protocol and do IO

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Implement Xen para-virtual frontend to backend communication and actually read/write disk data.

This is based on mini-os implementation of the para-virtual block frontend driver.

---
 drivers/xen/events.c  |   2 +-
 drivers/xen/pvblock.c | 311 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 301 insertions(+), 12 deletions(-)
drivers/xen/events.c +1 -1
index a1b36a2196..192b290c02 100644
@@ -104,7 +104,7 @@ void unbind_evtchn(evtchn_port_t port)
 	int rc;
 
 	if (ev_actions[port].handler == default_handler)
-		printf("WARN: No handler for port %d when unbinding\n", port);
+		debug("Default handler for port %d when unbinding\n", port);
 	mask_evtchn(port);
 	clear_evtchn(port);
 
drivers/xen/pvblock.c +300 -11

377 lines not on this page · raw message

Signature · 1 line
2.17.1
#49 lore raw

PATCH 15/17 xen: pvblock: Implement front-back protocol and do IO

Quoted 9 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Implement Xen para-virtual frontend to backend communication and actually read/write disk data.

This is based on mini-os implementation of the para-virtual block frontend driver.

Quoted 6 lines
---
 drivers/xen/events.c  |   2 +-
 drivers/xen/pvblock.c | 311 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 301 insertions(+), 12 deletions(-)

Please can you comment structs and non-trival functions?

#50 lore raw

PATCH 15/17 xen: pvblock: Implement front-back protocol and do IO

Quoted 21 lines · Simon Glass
Quoted 13 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Implement Xen para-virtual frontend to backend communication and actually read/write disk data.

This is based on mini-os implementation of the para-virtual block frontend driver.

Signed-off-by: Oleksandr Andrushchenko <
oleksandr_andrushchenko at epam.com>
Signed-off-by: Anastasiia Lukianenko <
anastasiia_lukianenko at epam.com>

Quoted 5 lines
---
 drivers/xen/events.c  |   2 +-
 drivers/xen/pvblock.c | 311
++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 301 insertions(+), 12 deletions(-)
Quoted 1 line

Please can you comment structs and non-trival functions?

Sure.

Regards,
Anastasiia

#51 lore raw

PATCH 16/17 xen: pvblock: Print found devices indices

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

---
 drivers/xen/pvblock.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/xen/pvblock.c +20 -0
index a23afc2cb2..8b102b181d 100644
@@ -734,6 +734,24 @@ fail:
 	return ret;
 }
 
+static void print_pvblock_devices(void)
+{
+	struct udevice *udev;
+	bool first = true;
+	const char *class_name;
+
+	class_name = uclass_get_name(UCLASS_PVBLOCK);
+	for (blk_first_device(IF_TYPE_PVBLOCK, &udev); udev;
+	     blk_next_device(&udev), first = false) {
+		struct blk_desc *desc = dev_get_uclass_platdata(udev);
+
+		if (!first)
+			puts(", ");
+		printf("%s: %d", class_name, desc->devnum);
+	}
+	printf("\n");
+}
+
 void pvblock_init(void)
 {
 	struct driver_info info;
@@ -756,6 +774,8 @@ void pvblock_init(void)
 	if (ret)
 		return;
 	uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
+
+	print_pvblock_devices();
 }
 
 static int pvblock_probe(struct udevice *udev)
Signature · 1 line
2.17.1
#53 lore raw

PATCH 17/17 board: xen: De-initialize before jumping to Linux

In reply to Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Free resources used by Xen board before jumping to Linux kernel.

---
 board/xen/xenguest_arm64/xenguest_arm64.c | 6 ++++++
 drivers/xen/hypervisor.c                  | 8 ++++++++
 include/xen.h                             | 1 +
 3 files changed, 15 insertions(+)
board/xen/xenguest_arm64/xenguest_arm64.c +6 -0
index b4e1650f99..76a18bea8b 100644
@@ -13,6 +13,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <xen.h>
 
 #include <asm/io.h>
 #include <asm/armv8/mmu.h>
@@ -195,3 +196,8 @@ int print_cpuinfo(void)
 	return 0;
 }
 
+void board_cleanup_before_linux(void)
+{
+	xen_fini();
+}
+
drivers/xen/hypervisor.c +8 -0
index f3c2504d72..8d7d320839 100644
@@ -279,3 +279,11 @@ void xen_init(void)
 	init_gnttab();
 }
 
+void xen_fini(void)
+{
+	debug("%s\n", __func__);
+
+	fini_gnttab();
+	fini_xenbus();
+	fini_events();
+}
include/xen.h +1 -0
index 1d6f74cc92..327d7e132b 100644
@@ -7,5 +7,6 @@
 #define __XEN_H__
 
 void xen_init(void);
+void xen_fini(void);
 
 #endif /* __XEN_H__ */
Signature · 1 line
2.17.1
#54 lore raw

PATCH 17/17 board: xen: De-initialize before jumping to Linux

Quoted 5 lines · Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Free resources used by Xen board before jumping to Linux kernel.

Quoted 7 lines
---
 board/xen/xenguest_arm64/xenguest_arm64.c | 6 ++++++
 drivers/xen/hypervisor.c                  | 8 ++++++++
 include/xen.h                             | 1 +
 3 files changed, 15 insertions(+)
Quoted 43 lines
board/xen/xenguest_arm64/xenguest_arm64.c +6 -0
index b4e1650f99..76a18bea8b 100644
@@ -13,6 +13,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <xen.h>
 
 #include <asm/io.h>
 #include <asm/armv8/mmu.h>
@@ -195,3 +196,8 @@ int print_cpuinfo(void)
        return 0;
 }
 
+void board_cleanup_before_linux(void)
+{
+       xen_fini();
+}
+
drivers/xen/hypervisor.c +8 -0
index f3c2504d72..8d7d320839 100644
@@ -279,3 +279,11 @@ void xen_init(void)
        init_gnttab();
 }
 
+void xen_fini(void)
+{
+       debug("%s\n", __func__);
+
+       fini_gnttab();
+       fini_xenbus();
+       fini_events();
+}
include/xen.h +0 -0
index 1d6f74cc92..327d7e132b 100644

include/xen.h line 10

Quoted 4 lines
include/xen.h +1 -0
@@ -7,5 +7,6 @@
 #define __XEN_H__
 
 void xen_init(void);
+void xen_fini(void);

Comment? What does this do?

Quoted 5 lines
include/xen.h +0 -1
 #endif /* __XEN_H__ */
--

2.17.1

- SImon

#55 lore raw

PATCH 17/17 board: xen: De-initialize before jumping to Linux

Quoted 67 lines · Simon Glass
Quoted 9 lines · Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Free resources used by Xen board before jumping to Linux kernel.

Signed-off-by: Oleksandr Andrushchenko <
oleksandr_andrushchenko at epam.com>
Signed-off-by: Anastasiia Lukianenko <
anastasiia_lukianenko at epam.com>

Quoted 5 lines
---
 board/xen/xenguest_arm64/xenguest_arm64.c | 6 ++++++
 drivers/xen/hypervisor.c                  | 8 ++++++++
 include/xen.h                             | 1 +
 3 files changed, 15 insertions(+)
Quoted 46 lines
board/xen/xenguest_arm64/xenguest_arm64.c +6 -0
index b4e1650f99..76a18bea8b 100644
@@ -13,6 +13,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <xen.h>
 
 #include <asm/io.h>
 #include <asm/armv8/mmu.h>
@@ -195,3 +196,8 @@ int print_cpuinfo(void)
        return 0;
 }
 
+void board_cleanup_before_linux(void)
+{
+       xen_fini();
+}
+
drivers/xen/hypervisor.c +8 -0
index f3c2504d72..8d7d320839 100644
@@ -279,3 +279,11 @@ void xen_init(void)
        init_gnttab();
 }
 
+void xen_fini(void)
+{
+       debug("%s\n", __func__);
+
+       fini_gnttab();
+       fini_xenbus();
+       fini_events();
+}
include/xen.h +0 -0
index 1d6f74cc92..327d7e132b 100644
@@ -7,5 +7,6 @@
 #define __XEN_H__
 
Quoted 5 lines

include/xen.h line 10

Quoted 2 lines
include/xen.h +1 -0
 void xen_init(void);
+void xen_fini(void);

Comment? What does this do?

Ok, will add.

Quoted 8 lines
Quoted 6 lines
include/xen.h +0 -1
 #endif /* __XEN_H__ */
--

2.17.1

- SImon

Regards,
Anastasiia

#56 lore raw

cover Add new board: Xen guest for ARM64

In reply to Anastasiia Lukianenko

Sorry for top posting, but please note, that there is a dependency on the following patch being upstreamed:
http://u-boot.10912.n7.nabble.com/PATCH-v2-arm64-issue-ISB-after-updating-system-registers-td417392.html#none
For Xen guests with RAM less than 129MB one will also need:
http://u-boot.10912.n7.nabble.com/PATCH-common-board-f-Respect-original-FDT-size-while-relocating-td416963.html#none

Regards,
Anastasiia

From: Anastasiia Lukianenko <[email protected]>
Sent: 01 July 2020 19:29
To: u-boot at lists.denx.de <[email protected]>; sjg at chromium.org <[email protected]>; ye.li at nxp.com <[email protected]>; bmeng.cn at gmail.com <[email protected]>; xypron.glpk at gmx.de <[email protected]>
Cc: julien at xen.org <[email protected]>; sstabellini at kernel.org <[email protected]>; peng.fan at nxp.com <[email protected]>; roman at zededa.com <[email protected]>; Volodymyr Babchuk <[email protected]>; Anastasiia Lukianenko <[email protected]>
Subject: [PATCH 00/17] Add new board: Xen guest for ARM64
?
From: Anastasiia Lukianenko <[email protected]>

This work introduces Xen [1] guest ARM64 board support in U-Boot with para-virtualized (PV) [2] block and serial drivers: xenguest_arm64.

This board is to be run as a virtual Xen guest with U-boot as its primary bootloader. The rationale behind introducing this board is a better and simpler decoupling of the guest from the initial privileged domain which starts a guest?s virtual machine: there are cross dependencies between the guest OS and initial privileged domain (Domain-0) such as Domain-0 needs guest's kernel and may need its device tree to boot it. These dependencies interfere if the kernel or guest OS needs to be updated, thus having a unified bootloader in Domain-0 allows resolving this:
1. U-boot boot scripts, which are stored on the guest?s virtual disk, are guest specific, so any change in the guest?s configuration can be handled by the guest itself.
2. Guest OS? kernel can be updated if OS? needs that without any help from Domain-0.
3. Using the Device Tree Overlay mechanism it is possible to customize the device tree entries yet at bootloader stage inside the guest itself, so the base device tree provided by Xen can be customized.

Xen support for U-boot was implemented by introducing a new Xen guest ARM64 board and porting essential drivers from MiniOS [3] as well as some of the work previously done by NXP [4]:
1. PV block device front driver with XenStore based device enumeration, new UCLASS_PVBLOCK;
2. PV serial console device front driver;
3. Xen hypervisor support with minimal set of the essential headers adapted from Linux kernel;
4. grant table support;
5. event channel support, without IRQ support, but polling;
6. xenbus support;
7. dynamic RAM size as defined in the device tree instead of statically defined values;
8. position-independent pre-relocation code is used as we cannot statically define any start addresses at compile time which is up to Xen to choose at run-time;
9. new defconfig introduced: xenguest_arm64_defconfig.

Please note, that due to the fact that para-virtualized serial driver requires some of the Xen functionality available late not all the printouts are available at the very start including U-Boot banner, memory size etc.

All the above was tested with block driver related commands (info/part/read/write), FAT and ext4 operations work properly, the Linux kernel can start.

Thank you in advance,
Anastasiia Lukianenko,
Oleksandr Andrushchenko

[1] - https://urldefense.com/v3/__https://xenproject.org/__;!!GF_29dbcQIUBPA!nXu3bp3MaWPZ4Ea_kBwDZfiCgeuk2evQq7UQocVVU3TGUNkR19P1n19d1aVHLdKqJASr7wA$
[2] - https://urldefense.com/v3/__https://wiki.xenproject.org/wiki/Paravirtualization_(PV)__;!!GF_29dbcQIUBPA!nXu3bp3MaWPZ4Ea_kBwDZfiCgeuk2evQq7UQocVVU3TGUNkR19P1n19d1aVHLdKqPFADqbk$
[3] - https://urldefense.com/v3/__https://wiki.xenproject.org/wiki/Mini-OS__;!!GF_29dbcQIUBPA!nXu3bp3MaWPZ4Ea_kBwDZfiCgeuk2evQq7UQocVVU3TGUNkR19P1n19d1aVHLdKq9Oab5y0$
[4] - https://urldefense.com/v3/__https://source.codeaurora.org/external/imx/uboot-imx/tree/?h=imx_v2018.03_4.14.98_2.0.0_ga__;!!GF_29dbcQIUBPA!nXu3bp3MaWPZ4Ea_kBwDZfiCgeuk2evQq7UQocVVU3TGUNkR19P1n19d1aVHLdKqMVZz7ZU$

Anastasiia Lukianenko (5):
? xen: pvblock: Add initial support for para-virtualized block driver ? xen: pvblock: Enumerate virtual block devices
? xen: pvblock: Read XenStore configuration and initialize ? xen: pvblock: Implement front-back protocol and do IO
? xen: pvblock: Print found devices indices

Andrii Anisov (2):
? board: Introduce xenguest_arm64 board
? lib: sscanf: add sscanf implementation

Oleksandr Andrushchenko (8):
? armv8: Fix SMCC and ARM_PSCI_FW dependencies ? xen: Add essential and required interface headers ? xen: Port Xen hypervizor related code from mini-os ? xen: Port Xen event channel driver from mini-os ? linux/compat.h: Add wait_event_timeout macro ? xen: Port Xen bus driver from mini-os
? xen: Port Xen grant table driver from mini-os ? board: xen: De-initialize before jumping to Linux

Peng Fan (2):
? Kconfig: Introduce CONFIG_XEN
? serial: serial_xen: Add Xen PV serial driver

?Kconfig?????????????????????????????????? |?? 7 +
?arch/arm/Kconfig????????????????????????? |? 10 +-
?arch/arm/cpu/armv8/Kconfig??????????????? |?? 2 +
?arch/arm/cpu/armv8/Makefile?????????????? |?? 1 +
?arch/arm/cpu/armv8/xen/Makefile?????????? |?? 6 +
?arch/arm/cpu/armv8/xen/hypercall.S??????? |? 78 ++
?arch/arm/cpu/armv8/xen/lowlevel_init.S??? |? 34 +
?arch/arm/include/asm/xen.h??????????????? |?? 8 +
?arch/arm/include/asm/xen/hypercall.h????? |? 45 ++
?arch/arm/include/asm/xen/system.h???????? |? 96 +++
?board/xen/xenguest_arm64/Kconfig????????? |? 12 +
?board/xen/xenguest_arm64/Makefile???????? |?? 5 +
?board/xen/xenguest_arm64/xenguest_arm64.c | 203 +++++
?cmd/Kconfig?????????????????????????????? |?? 7 +
?cmd/Makefile????????????????????????????? |?? 1 +
?cmd/pvblock.c???????????????????????????? |? 31 +
?common/board_r.c????????????????????????? |? 25 +
?configs/xenguest_arm64_defconfig????????? |? 60 ++
?disk/part.c?????????????????????????????? |?? 4 +
?drivers/Kconfig?????????????????????????? |?? 2 +
?drivers/Makefile????????????????????????? |?? 1 +
?drivers/block/blk-uclass.c??????????????? |?? 2 +
?drivers/serial/Kconfig??????????????????? |?? 7 +
?drivers/serial/Makefile?????????????????? |?? 1 +
?drivers/serial/serial_xen.c?????????????? | 175 +++++
?drivers/xen/Kconfig?????????????????????? |? 10 +
?drivers/xen/Makefile????????????????????? |? 10 +
?drivers/xen/events.c????????????????????? | 181 +++++
?drivers/xen/gnttab.c????????????????????? | 258 +++++++
?drivers/xen/hypervisor.c????????????????? | 289 +++++++
?drivers/xen/pvblock.c???????????????????? | 808 ++++++++++++++++++++
?drivers/xen/xenbus.c????????????????????? | 547 ++++++++++++++
?include/blk.h???????????????????????????? |?? 1 +
?include/configs/xenguest_arm64.h????????? |? 53 ++
?include/dm/uclass-id.h??????????????????? |?? 1 +
?include/linux/compat.h??????????????????? |? 45 ++
?include/pvblock.h???????????????????????? |? 12 +
?include/vsprintf.h??????????????????????? |?? 8 +
?include/xen.h???????????????????????????? |? 12 +
?include/xen/arm/interface.h?????????????? |? 88 +++
?include/xen/events.h????????????????????? |? 47 ++
?include/xen/gnttab.h????????????????????? |? 25 +
?include/xen/hvm.h???????????????????????? |? 30 +
?include/xen/interface/event_channel.h???? | 281 +++++++
?include/xen/interface/grant_table.h?????? | 582 ++++++++++++++
?include/xen/interface/hvm/hvm_op.h??????? |? 69 ++
?include/xen/interface/hvm/params.h??????? | 127 ++++
?include/xen/interface/io/blkif.h????????? | 726 ++++++++++++++++++
?include/xen/interface/io/console.h??????? |? 56 ++
?include/xen/interface/io/protocols.h????? |? 42 +
?include/xen/interface/io/ring.h?????????? | 479 ++++++++++++
?include/xen/interface/io/xenbus.h???????? |? 81 ++
?include/xen/interface/io/xs_wire.h??????? | 151 ++++
?include/xen/interface/memory.h??????????? | 332 ++++++++
?include/xen/interface/sched.h???????????? | 188 +++++
?include/xen/interface/xen.h?????????????? | 225 ++++++
?include/xen/xenbus.h????????????????????? |? 86 +++
?lib/Kconfig?????????????????????????????? |?? 4 +
?lib/Makefile????????????????????????????? |?? 1 +
?lib/sscanf.c????????????????????????????? | 883 ++++++++++++++++++++++

?60 files changed, 7560 insertions(+), 1 deletion(-) ?create mode 100644 arch/arm/cpu/armv8/xen/Makefile ?create mode 100644 arch/arm/cpu/armv8/xen/hypercall.S ?create mode 100644 arch/arm/cpu/armv8/xen/lowlevel_init.S ?create mode 100644 arch/arm/include/asm/xen.h ?create mode 100644 arch/arm/include/asm/xen/hypercall.h ?create mode 100644 arch/arm/include/asm/xen/system.h ?create mode 100644 board/xen/xenguest_arm64/Kconfig ?create mode 100644 board/xen/xenguest_arm64/Makefile ?create mode 100644 board/xen/xenguest_arm64/xenguest_arm64.c ?create mode 100644 cmd/pvblock.c
?create mode 100644 configs/xenguest_arm64_defconfig ?create mode 100644 drivers/serial/serial_xen.c ?create mode 100644 drivers/xen/Kconfig
?create mode 100644 drivers/xen/Makefile
?create mode 100644 drivers/xen/events.c
?create mode 100644 drivers/xen/gnttab.c
?create mode 100644 drivers/xen/hypervisor.c ?create mode 100644 drivers/xen/pvblock.c
?create mode 100644 drivers/xen/xenbus.c
?create mode 100644 include/configs/xenguest_arm64.h ?create mode 100644 include/pvblock.h
?create mode 100644 include/xen.h
?create mode 100644 include/xen/arm/interface.h ?create mode 100644 include/xen/events.h
?create mode 100644 include/xen/gnttab.h
?create mode 100644 include/xen/hvm.h
?create mode 100644 include/xen/interface/event_channel.h ?create mode 100644 include/xen/interface/grant_table.h ?create mode 100644 include/xen/interface/hvm/hvm_op.h ?create mode 100644 include/xen/interface/hvm/params.h ?create mode 100644 include/xen/interface/io/blkif.h ?create mode 100644 include/xen/interface/io/console.h ?create mode 100644 include/xen/interface/io/protocols.h ?create mode 100644 include/xen/interface/io/ring.h ?create mode 100644 include/xen/interface/io/xenbus.h ?create mode 100644 include/xen/interface/io/xs_wire.h ?create mode 100644 include/xen/interface/memory.h ?create mode 100644 include/xen/interface/sched.h ?create mode 100644 include/xen/interface/xen.h ?create mode 100644 include/xen/xenbus.h
?create mode 100644 lib/sscanf.c

Signature · 1 line
2.17.1