Skip to contentSkip to conversation

Add new board: Xen guest for ARM64

PATCH Superseded Anastasiia Lukianenko 5 participants 29 messages Jul 20, 2020 – Aug 7, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover 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

Changes since v1:
=================

1. Added test for new lib sscanf function
2. Fixed data cache maintenance process
3. Added more comments and explanations
4. Removed unnecessary code, which is not related to ARM64 architecture
5. Added board documentation
6. Coding style cleanup
7. Added MIT License

Anastasiia Lukianenko (7):
Add MIT License
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
doc: xen: Add Xen guest ARM64 board documentation

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

Oleksandr Andrushchenko (7):
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                                   |  18 +
 Licenses/README                           |   1 +
 Licenses/mit.txt                          |  20 +
 arch/arm/Kconfig                          |   9 +
 arch/arm/cpu/armv8/Makefile               |   1 +
 arch/arm/cpu/armv8/xen/Makefile           |   6 +
 arch/arm/cpu/armv8/xen/hypercall.S        |  79 ++
 arch/arm/cpu/armv8/xen/lowlevel_init.S    |  33 +
 arch/arm/include/asm/io.h                 |   4 +
 arch/arm/include/asm/xen.h                |   7 +
 arch/arm/include/asm/xen/hypercall.h      |  22 +
 arch/arm/include/asm/xen/system.h         |  88 +++
 board/xen/xenguest_arm64/Kconfig          |  12 +
 board/xen/xenguest_arm64/Makefile         |   5 +
 board/xen/xenguest_arm64/xenguest_arm64.c | 202 +++++
 cmd/Kconfig                               |   7 +
 cmd/Makefile                              |   1 +
 cmd/pvblock.c                             |  30 +
 common/board_r.c                          |  27 +
 configs/xenguest_arm64_defconfig          |  60 ++
 disk/part.c                               |   4 +
 doc/board/index.rst                       |   1 +
 doc/board/xen/index.rst                   |   9 +
 doc/board/xen/xenguest_arm64.rst          |  81 ++
 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               | 182 +++++
 drivers/xen/Kconfig                       |  10 +
 drivers/xen/Makefile                      |  10 +
 drivers/xen/events.c                      | 199 +++++
 drivers/xen/gnttab.c                      | 216 ++++++
 drivers/xen/hypervisor.c                  | 252 +++++++
 drivers/xen/pvblock.c                     | 867 ++++++++++++++++++++++
 drivers/xen/xenbus.c                      | 557 ++++++++++++++
 include/blk.h                             |   1 +
 include/configs/xenguest_arm64.h          |  52 ++
 include/dm/uclass-id.h                    |   1 +
 include/linux/compat.h                    |  54 ++
 include/pvblock.h                         |  17 +
 include/vsprintf.h                        |   8 +
 include/xen.h                             |  24 +
 include/xen/arm/interface.h               |  88 +++
 include/xen/events.h                      |  42 ++
 include/xen/gnttab.h                      |  24 +
 include/xen/hvm.h                         |  27 +
 include/xen/interface/event_channel.h     | 279 +++++++
 include/xen/interface/grant_table.h       | 565 ++++++++++++++
 include/xen/interface/hvm/hvm_op.h        |  55 ++
 include/xen/interface/hvm/params.h        | 116 +++
 include/xen/interface/io/blkif.h          | 701 +++++++++++++++++
 include/xen/interface/io/console.h        |  39 +
 include/xen/interface/io/protocols.h      |  28 +
 include/xen/interface/io/ring.h           | 462 ++++++++++++
 include/xen/interface/io/xenbus.h         |  64 ++
 include/xen/interface/io/xs_wire.h        | 134 ++++
 include/xen/interface/memory.h            | 332 +++++++++
 include/xen/interface/sched.h             | 171 +++++
 include/xen/interface/xen.h               | 208 ++++++
 include/xen/xenbus.h                      | 116 +++
 lib/Kconfig                               |   4 +
 lib/Makefile                              |   1 +
 lib/sscanf.c                              | 823 ++++++++++++++++++++
 test/lib/Makefile                         |   1 +
 test/lib/sscanf.c                         | 174 +++++
 67 files changed, 7644 insertions(+)
 create mode 100644 Licenses/mit.txt
 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 doc/board/xen/index.rst
 create mode 100644 doc/board/xen/xenguest_arm64.rst
 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
 create mode 100644 test/lib/sscanf.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/18 Add MIT License

From: Anastasiia Lukianenko <[email protected]>

---
 Licenses/README  |  1 +
 Licenses/mit.txt | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 Licenses/mit.txt
Licenses/README +1 -0
index 486e18d0d8..c23ad216fc 100644
@@ -149,5 +149,6 @@ BSD 3-clause "New" or "Revised" License		BSD-3-Clause	Y		bsd-3-clause.txt	http:/
 IBM PIBS (PowerPC Initialization and		IBM-pibs			ibm-pibs.txt
 	Boot Software) license
 ISC License					ISC		Y		isc.txt			https://spdx.org/licenses/ISC
+MIT License					MIT		Y		mit.txt			https://spdx.org/licenses/MIT.html
 SIL OPEN FONT LICENSE (OFL-1.1)			OFL-1.1		Y		OFL.txt			https://spdx.org/licenses/OFL-1.1.html
 X11 License					X11				x11.txt			https://spdx.org/licenses/X11.html
Licenses/mit.txt new file +20 -0
new file mode 100644
index 0000000000..25a55e054f
@@ -0,0 +1,20 @@
+MIT License
+Copyright (c) 2020 EPAM Systems Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 1/18 Add MIT License

Hello Simon,

Quoted 6 lines · Simon Glass
Quoted 2 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Please add commit message

Ok, will add.

Quoted 11 lines
Quoted 9 lines

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

---
 Licenses/README  |  1 +
 Licenses/mit.txt | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 Licenses/mit.txt

Regards,
Anastasiia

#4 lore raw

PATCH v2 2/18 Kconfig: Introduce CONFIG_XEN

In reply to Anastasiia Lukianenko

From: Peng Fan <[email protected]>

Introduce CONFIG_XEN to make U-Boot could be used as bootloader for a virtual machine.

Without bootloader, we could successfully boot up android on XEN, but we need need bootloader to support A/B, dm verify and etc.

---
 Kconfig | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Kconfig +18 -0
index 566ca72c92..9a33b3814d 100644
@@ -105,6 +105,24 @@ config CC_COVERAGE
 config CC_HAS_ASM_INLINE
 	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 
+config XEN
+	bool "Select U-Boot be run as a bootloader for XEN Virtual Machine"
+	help
+	  Enabling this option will make U-Boot be run as a bootloader
+	  for XEN [1] Virtual Machine.
+
+	  Xen is a virtual machine monitor (VMM) or a type-1 hypervisor with support
+	  for para-virtualization. Xen can organize the safe execution of several
+	  virtual machines on the same physical system with performance close to
+	  native. It is used as the basis for a number of different commercial and
+	  open source applications, such as: server virtualization, Infrastructure
+	  as a Service (IaaS), desktop virtualization, security applications,
+	  embedded and hardware appliances.
+	  Xen has a special VM called Domain-0 that runs the Dom0 kernel and allows
+	  Xen to use the device drivers for the Domain-0 kernel by default.
+
+	  [1] - https://xenproject.org/
+
 config DISTRO_DEFAULTS
 	bool "Select defaults suitable for booting general purpose Linux distributions"
 	select AUTO_COMPLETE
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 2/18 Kconfig: Introduce CONFIG_XEN

Hi Anastasiia,

Quoted 9 lines · Anastasiia Lukianenko

From: Peng Fan <[email protected]>

Introduce CONFIG_XEN to make U-Boot could be used as bootloader for a virtual machine.

Without bootloader, we could successfully boot up android on XEN, but we need need bootloader to support A/B, dm verify and etc.

Quoted 7 lines
---
 Kconfig | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

This is v2 but I don't see a change log?

Regards,
Simon

#6 lore raw

PATCH v2 2/18 Kconfig: Introduce CONFIG_XEN

Hello Simon,

Quoted 24 lines · Simon Glass

Hi Anastasiia,

Quoted 10 lines · Anastasiia Lukianenko

From: Peng Fan <[email protected]>

Introduce CONFIG_XEN to make U-Boot could be used as bootloader for a virtual machine.

Without bootloader, we could successfully boot up android on XEN, but
we need need bootloader to support A/B, dm verify and etc.

Quoted 9 lines
Signed-off-by Oleksandr Andrushchenko <

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

---
 Kconfig | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Quoted 1 line

This is v2 but I don't see a change log?

I listed main changes in the cover letter attached to this patch series.
Please find them in "Changes since v1" section in [PATCH v2 00/18] Add new board: Xen guest for ARM64

Quoted 3 lines

Regards,
Simon

Regards,
Anastasiia

#7 lore raw

PATCH v2 2/18 Kconfig: Introduce CONFIG_XEN

Hi Anastasiia,

Quoted 28 lines · Anastasiia Lukianenko

Hello Simon,

Quoted 24 lines · Simon Glass

Hi Anastasiia,

Quoted 19 lines · Anastasiia Lukianenko

From: Peng Fan <[email protected]>

Introduce CONFIG_XEN to make U-Boot could be used as bootloader for a virtual machine.

Without bootloader, we could successfully boot up android on XEN, but
we need need bootloader to support A/B, dm verify and etc.

Signed-off-by Oleksandr Andrushchenko <

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

---
 Kconfig | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Quoted 6 lines
Quoted 1 line

This is v2 but I don't see a change log?

I listed main changes in the cover letter attached to this patch series.
Please find them in "Changes since v1" section in [PATCH v2 00/18] Add new board: Xen guest for ARM64

I think it is much more useful to attach the changes to each patch as well. Have you tried using patman?

Regards,
Simon

#8 lore raw

PATCH v2 2/18 Kconfig: Introduce CONFIG_XEN

Hi Simon,

Quoted 35 lines · Simon Glass

Hi Anastasiia,

Quoted 31 lines · Anastasiia Lukianenko

Hello Simon,

Quoted 26 lines · Simon Glass

Hi Anastasiia,

Quoted 11 lines · Anastasiia Lukianenko

From: Peng Fan <[email protected]>

Introduce CONFIG_XEN to make U-Boot could be used as bootloader for a virtual machine.

Without bootloader, we could successfully boot up android on XEN,
but
we need need bootloader to support A/B, dm verify and etc.

Quoted 9 lines
Signed-off-by Oleksandr Andrushchenko <

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

---
 Kconfig | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

This is v2 but I don't see a change log?

Quoted 8 lines
Quoted 4 lines

I listed main changes in the cover letter attached to this patch series.
Please find them in "Changes since v1" section in [PATCH v2 00/18] Add new board: Xen guest for ARM64

I think it is much more useful to attach the changes to each patch as well. Have you tried using patman?

Yes. I agree with you. As the result, I resend the patch series with the changes attached to each patch.

Quoted 2 lines

Regards,
Simon

Regards,
Anastasiia

#9 lore raw

PATCH v2 3/18 xen: Add essential and required interface headers

In reply to Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Add essential and required Xen interface headers only taken from the stable Linux kernel stable/linux-5.7.y at commit 66dfe4522160 Linux 5.7.5.

These are better suited for U-boot than the original headers from Xen as they are the stripped versions of the same.

At the same time use public protocols from Xen RELEASE-4.13.1, at commit 6278553325a9 update Xen version to 4.13.1
as those have more comments in them.

---
 include/xen/arm/interface.h           |  88 ++++
 include/xen/interface/event_channel.h | 279 ++++++++++
 include/xen/interface/grant_table.h   | 565 +++++++++++++++++++++
 include/xen/interface/hvm/hvm_op.h    |  55 ++
 include/xen/interface/hvm/params.h    | 116 +++++
 include/xen/interface/io/blkif.h      | 701 ++++++++++++++++++++++++++
 include/xen/interface/io/console.h    |  39 ++
 include/xen/interface/io/protocols.h  |  28 +
 include/xen/interface/io/ring.h       | 462 +++++++++++++++++
 include/xen/interface/io/xenbus.h     |  64 +++
 include/xen/interface/io/xs_wire.h    | 134 +++++
 include/xen/interface/memory.h        | 332 ++++++++++++
 include/xen/interface/sched.h         | 171 +++++++
 include/xen/interface/xen.h           | 208 ++++++++
 14 files changed, 3242 insertions(+)
 create mode 100644 include/xen/arm/interface.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
include/xen/arm/interface.h new file +88 -0
new file mode 100644
index 0000000000..0dbc5876f3
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Guest OS interface to ARM Xen.
+ *
+ * Stefano Stabellini <[email protected]>, Citrix, 2012
+ */
+
+#ifndef _ASM_ARM_XEN_INTERFACE_H
+#define _ASM_ARM_XEN_INTERFACE_H
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#endif
+
+#define uint64_aligned_t u64 __attribute__((aligned(8)))
+
+#define __DEFINE_GUEST_HANDLE(name, type) \
+	typedef struct { union { type * p; uint64_aligned_t q; }; }  \
+		__guest_handle_ ## name
+
+#define DEFINE_GUEST_HANDLE_STRUCT(name) \
+	__DEFINE_GUEST_HANDLE(name, struct name)
+#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
+#define GUEST_HANDLE(name)        __guest_handle_ ## name
+
+#define set_xen_guest_handle(hnd, val)			\
+	do {						\
+		if (sizeof(hnd) == 8)			\
+			*(u64 *)&(hnd) = 0;	\
+		(hnd).p = val;				\
+	} while (0)
+
+#define __HYPERVISOR_platform_op_raw __HYPERVISOR_platform_op
+
+#ifndef __ASSEMBLY__
+/* Explicitly size integers that represent pfns in the interface with
+ * Xen so that we can have one ABI that works for 32 and 64 bit guests.
+ * Note that this means that the xen_pfn_t type may be capable of
+ * representing pfn's which the guest cannot represent in its own pfn
+ * type. However since pfn space is controlled by the guest this is
+ * fine since it simply wouldn't be able to create any sure pfns in
+ * the first place.
+ */
+typedef u64 xen_pfn_t;
+#define PRI_xen_pfn "llx"
+typedef u64 xen_ulong_t;
+#define PRI_xen_ulong "llx"
+typedef s64 xen_long_t;
+#define PRI_xen_long "llx"
+/* Guest handles for primitive C types. */
+__DEFINE_GUEST_HANDLE(uchar, unsigned char);
+__DEFINE_GUEST_HANDLE(uint,  unsigned int);
+DEFINE_GUEST_HANDLE(char);
+DEFINE_GUEST_HANDLE(int);
+DEFINE_GUEST_HANDLE(void);
+DEFINE_GUEST_HANDLE(u64);
+DEFINE_GUEST_HANDLE(u32);
+DEFINE_GUEST_HANDLE(xen_pfn_t);
+DEFINE_GUEST_HANDLE(xen_ulong_t);
+
+/* Maximum number of virtual CPUs in multi-processor guests. */
+#define MAX_VIRT_CPUS 1
+
+struct arch_vcpu_info { };
+struct arch_shared_info { };
+
+/* TODO: Move pvclock definitions some place arch independent */
+struct pvclock_vcpu_time_info {
+	u32   version;
+	u32   pad0;
+	u64   tsc_timestamp;
+	u64   system_time;
+	u32   tsc_to_system_mul;
+	s8    tsc_shift;
+	u8    flags;
+	u8    pad[2];
+} __attribute__((__packed__)); /* 32 bytes */
+
+/* It is OK to have a 12 bytes struct with no padding because it is packed */
+struct pvclock_wall_clock {
+	u32   version;
+	u32   sec;
+	u32   nsec;
+	u32   sec_hi;
+} __attribute__((__packed__));
+#endif
+
+#endif /* _ASM_ARM_XEN_INTERFACE_H */
include/xen/interface/event_channel.h new file +279 -0

279 lines not on this page · raw message

include/xen/interface/grant_table.h new file +565 -0

565 lines not on this page · raw message

include/xen/interface/hvm/hvm_op.h new file +55 -0

55 lines not on this page · raw message

include/xen/interface/hvm/params.h new file +116 -0

116 lines not on this page · raw message

include/xen/interface/io/blkif.h new file +701 -0

701 lines not on this page · raw message

include/xen/interface/io/console.h new file +39 -0
new file mode 100644
index 0000000000..d4dccc74af
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * console.h
+ *
+ * Console I/O interface for Xen guest OSes.
+ *
+ * Copyright (c) 2005, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_IO_CONSOLE_H__
+#define __XEN_PUBLIC_IO_CONSOLE_H__
+
+typedef u32 XENCONS_RING_IDX;
+
+#define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring) - 1))
+
+struct xencons_interface {
+	char in[1024];
+	char out[2048];
+	XENCONS_RING_IDX in_cons, in_prod;
+	XENCONS_RING_IDX out_cons, out_prod;
+};
+
+#ifdef XEN_WANT_FLEX_CONSOLE_RING
+#include "ring.h"
+DEFINE_XEN_FLEX_RING(xencons);
+#endif
+
+#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
include/xen/interface/io/protocols.h new file +28 -0
new file mode 100644
index 0000000000..5aa0aaa93b
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * protocols.h
+ *
+ * Copyright (c) 2008, Keir Fraser
+ *
+ * Xen protocols, which are used as ABI rules governing the format of all
+ * ring request and response structures.
+ */
+
+#ifndef __XEN_PROTOCOLS_H__
+#define __XEN_PROTOCOLS_H__
+
+#define XEN_IO_PROTO_ABI_X86_32     "x86_32-abi"
+#define XEN_IO_PROTO_ABI_X86_64     "x86_64-abi"
+#define XEN_IO_PROTO_ABI_ARM        "arm-abi"
+
+#if defined(__i386__)
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32
+#elif defined(__x86_64__)
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_64
+#elif defined(__arm__) || defined(__aarch64__)
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_ARM
+#else
+# error arch fixup needed here
+#endif
+
+#endif
include/xen/interface/io/ring.h new file +462 -0

462 lines not on this page · raw message

include/xen/interface/io/xenbus.h new file +64 -0

64 lines not on this page · raw message

include/xen/interface/io/xs_wire.h new file +134 -0

134 lines not on this page · raw message

include/xen/interface/memory.h new file +332 -0

332 lines not on this page · raw message

include/xen/interface/sched.h new file +171 -0

137 lines not on this page · raw message

include/xen/interface/xen.h new file +208 -0

208 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.17.1

Part of the diff is not shown here. View the raw message.

#10 lore raw

PATCH v2 4/18 board: Introduce xenguest_arm64 board

In reply to Anastasiia Lukianenko

From: Andrii Anisov <[email protected]>

Introduce a minimal Xen guest board running as a virtual machine under Xen Project's hypervisor [1], [2].

Part of the code is ported from Xen mini-os and also uses work initially done by different authors from NXP: please see relevant files for their copyrights.

[1] https://xenbits.xen.org
[2] https://wiki.xenproject.org/

---
 arch/arm/Kconfig                          |   7 +
 arch/arm/cpu/armv8/Makefile               |   1 +
 arch/arm/cpu/armv8/xen/Makefile           |   6 +
 arch/arm/cpu/armv8/xen/hypercall.S        |  79 +++++++++++
 arch/arm/cpu/armv8/xen/lowlevel_init.S    |  33 +++++
 arch/arm/include/asm/xen.h                |   7 +
 arch/arm/include/asm/xen/hypercall.h      |  22 ++++
 board/xen/xenguest_arm64/Kconfig          |  12 ++
 board/xen/xenguest_arm64/Makefile         |   5 +
 board/xen/xenguest_arm64/xenguest_arm64.c | 152 ++++++++++++++++++++++
 configs/xenguest_arm64_defconfig          |  56 ++++++++
 include/configs/xenguest_arm64.h          |  44 +++++++
 12 files changed, 424 insertions(+)
 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 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 configs/xenguest_arm64_defconfig
 create mode 100644 include/configs/xenguest_arm64.h
arch/arm/Kconfig +7 -0
index 86238524f7..4ea7891cd3 100644
@@ -1739,6 +1739,12 @@ config TARGET_PRESIDIO_ASIC
 	bool "Support Cortina Presidio ASIC Platform"
 	select ARM64
 
+config TARGET_XENGUEST_ARM64
+	bool "Xen guest ARM64"
+	select ARM64
+	select XEN
+	select OF_CONTROL
+	select LINUX_KERNEL_IMAGE_HEADER
 endchoice
 
 config ARCH_SUPPORT_TFABOOT
@@ -1939,6 +1945,7 @@ source "board/xilinx/Kconfig"
 source "board/xilinx/zynq/Kconfig"
 source "board/xilinx/zynqmp/Kconfig"
 source "board/phytium/durian/Kconfig"
+source "board/xen/xenguest_arm64/Kconfig"
 
 source "arch/arm/Kconfig.debug"
 
arch/arm/cpu/armv8/Makefile +1 -0
index 2e48df0eb9..dd6c354d19 100644
@@ -39,3 +39,4 @@ obj-$(CONFIG_S32V234) += s32v234/
 obj-$(CONFIG_TARGET_HIKEY) += hisilicon/
 obj-$(CONFIG_ARMV8_PSCI) += psci.o
 obj-$(CONFIG_ARCH_SUNXI) += lowlevel_init.o
+obj-$(CONFIG_XEN) += xen/
arch/arm/cpu/armv8/xen/Makefile new file +6 -0
new file mode 100644
index 0000000000..e3b4ae2bd4
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) 2018 NXP
+# (C) 2020 EPAM Systems Inc.
+
+obj-y += lowlevel_init.o hypercall.o
arch/arm/cpu/armv8/xen/hypercall.S new file +79 -0

79 lines not on this page · raw message

arch/arm/cpu/armv8/xen/lowlevel_init.S new file +33 -0
new file mode 100644
index 0000000000..760e32ed76
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2017 NXP
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided ATAG/FDT address can be found in r2/x0 */
+	adr	x1, rom_pointer
+	stp	x0, x2, [x1], #16
+	stp	x3, x4, [x1], #16
+
+	/* Returns */
+	b	save_boot_params_ret
+
+.global restore_boot_params
+restore_boot_params:
+	adr	x1, rom_pointer
+	ldp	x0, x2, [x1], #16
+	ldp	x3, x4, [x1], #16
+	ret
arch/arm/include/asm/xen.h new file +7 -0
new file mode 100644
index 0000000000..8e2ee3d64e
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+extern unsigned long rom_pointer[];
+
arch/arm/include/asm/xen/hypercall.h new file +22 -0
new file mode 100644
index 0000000000..a4fd077079
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * hypercall.h
+ *
+ * Linux-specific hypervisor handling.
+ *
+ * Stefano Stabellini <[email protected]>, Citrix, 2012
+ */
+
+#ifndef _ASM_ARM_XEN_HYPERCALL_H
+#define _ASM_ARM_XEN_HYPERCALL_H
+
+#include <xen/interface/xen.h>
+
+int HYPERVISOR_xen_version(int cmd, void *arg);
+int HYPERVISOR_console_io(int cmd, int count, char *str);
+int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
+int HYPERVISOR_sched_op(int cmd, void *arg);
+int HYPERVISOR_event_channel_op(int cmd, void *arg);
+unsigned long HYPERVISOR_hvm_op(int op, void *arg);
+int HYPERVISOR_memory_op(unsigned int cmd, void *arg);
+#endif /* _ASM_ARM_XEN_HYPERCALL_H */
board/xen/xenguest_arm64/Kconfig new file +12 -0
new file mode 100644
index 0000000000..cc131ed5b9
@@ -0,0 +1,12 @@
+if TARGET_XENGUEST_ARM64
+
+config SYS_BOARD
+	default "xenguest_arm64"
+
+config SYS_VENDOR
+	default "xen"
+
+config SYS_CONFIG_NAME
+	default "xenguest_arm64"
+
+endif
board/xen/xenguest_arm64/Makefile new file +5 -0
new file mode 100644
index 0000000000..1cf87a728f
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier:	GPL-2.0+
+#
+# (C) Copyright 2020 EPAM Systems Inc.
+
+obj-y	:= xenguest_arm64.o
board/xen/xenguest_arm64/xenguest_arm64.c new file +152 -0

152 lines not on this page · raw message

configs/xenguest_arm64_defconfig new file +56 -0

56 lines not on this page · raw message

include/configs/xenguest_arm64.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.17.1
#11 lore raw

PATCH v2 4/18 board: Introduce xenguest_arm64 board

Quoted 403 lines · Anastasiia Lukianenko

From: Andrii Anisov <[email protected]>

Introduce a minimal Xen guest board running as a virtual machine under Xen Project's hypervisor [1], [2].

Part of the code is ported from Xen mini-os and also uses work initially done by different authors from NXP: please see relevant files for their copyrights.

[1] https://xenbits.xen.org
[2] https://wiki.xenproject.org/

---
 arch/arm/Kconfig                          |   7 +
 arch/arm/cpu/armv8/Makefile               |   1 +
 arch/arm/cpu/armv8/xen/Makefile           |   6 +
 arch/arm/cpu/armv8/xen/hypercall.S        |  79 +++++++++++
 arch/arm/cpu/armv8/xen/lowlevel_init.S    |  33 +++++
 arch/arm/include/asm/xen.h                |   7 +
 arch/arm/include/asm/xen/hypercall.h      |  22 ++++
 board/xen/xenguest_arm64/Kconfig          |  12 ++
 board/xen/xenguest_arm64/Makefile         |   5 +
 board/xen/xenguest_arm64/xenguest_arm64.c | 152 ++++++++++++++++++++++
 configs/xenguest_arm64_defconfig          |  56 ++++++++
 include/configs/xenguest_arm64.h          |  44 +++++++
 12 files changed, 424 insertions(+)
 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 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 configs/xenguest_arm64_defconfig
 create mode 100644 include/configs/xenguest_arm64.h
arch/arm/Kconfig +7 -0
index 86238524f7..4ea7891cd3 100644
@@ -1739,6 +1739,12 @@ config TARGET_PRESIDIO_ASIC
 	bool "Support Cortina Presidio ASIC Platform"
 	select ARM64
 
+config TARGET_XENGUEST_ARM64
+	bool "Xen guest ARM64"
+	select ARM64
+	select XEN
+	select OF_CONTROL
+	select LINUX_KERNEL_IMAGE_HEADER
 endchoice
 
 config ARCH_SUPPORT_TFABOOT
@@ -1939,6 +1945,7 @@ source "board/xilinx/Kconfig"
 source "board/xilinx/zynq/Kconfig"
 source "board/xilinx/zynqmp/Kconfig"
 source "board/phytium/durian/Kconfig"
+source "board/xen/xenguest_arm64/Kconfig"
 
 source "arch/arm/Kconfig.debug"
 
arch/arm/cpu/armv8/Makefile +1 -0
index 2e48df0eb9..dd6c354d19 100644
@@ -39,3 +39,4 @@ obj-$(CONFIG_S32V234) += s32v234/
 obj-$(CONFIG_TARGET_HIKEY) += hisilicon/
 obj-$(CONFIG_ARMV8_PSCI) += psci.o
 obj-$(CONFIG_ARCH_SUNXI) += lowlevel_init.o
+obj-$(CONFIG_XEN) += xen/
arch/arm/cpu/armv8/xen/Makefile new file +6 -0
new file mode 100644
index 0000000000..e3b4ae2bd4
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) 2018 NXP
+# (C) 2020 EPAM Systems Inc.
+
+obj-y += lowlevel_init.o hypercall.o
arch/arm/cpu/armv8/xen/hypercall.S new file +79 -0
new file mode 100644
index 0000000000..731256b34e
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * hypercall.S
+ *
+ * Xen hypercall wrappers
+ *
+ * Stefano Stabellini <[email protected]>, Citrix, 2012
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation; or, when distributed
+ * separately from the Linux kernel or incorporated into other
+ * software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/*
+ * The Xen hypercall calling convention is very similar to the procedure
+ * call standard for the ARM 64-bit architecture: the first parameter is
+ * passed in x0, the second in x1, the third in x2, the fourth in x3 and
+ * the fifth in x4.
+ *
+ * The hypercall number is passed in x16.
+ *
+ * The return value is in x0.
+ *
+ * The hvc ISS is required to be 0xEA1, that is the Xen specific ARM
+ * hypercall tag.
+ *
+ * Parameter structs passed to hypercalls are laid out according to
+ * the ARM 64-bit EABI standard.
+ */
+
+#include <xen/interface/xen.h>
+
+#define XEN_HYPERCALL_TAG	0xEA1
+
+#define HYPERCALL_SIMPLE(hypercall)		\
+.globl HYPERVISOR_##hypercall;                  \
+.align 4,0x90;                                  \
+HYPERVISOR_##hypercall:				\
+	mov x16, #__HYPERVISOR_##hypercall;	\
+	hvc XEN_HYPERCALL_TAG;			\
+	ret;					\
+
+#define HYPERCALL0 HYPERCALL_SIMPLE
+#define HYPERCALL1 HYPERCALL_SIMPLE
+#define HYPERCALL2 HYPERCALL_SIMPLE
+#define HYPERCALL3 HYPERCALL_SIMPLE
+#define HYPERCALL4 HYPERCALL_SIMPLE
+#define HYPERCALL5 HYPERCALL_SIMPLE
+
+                .text
+
+HYPERCALL2(xen_version);
+HYPERCALL3(console_io);
+HYPERCALL3(grant_table_op);
+HYPERCALL2(sched_op);
+HYPERCALL2(event_channel_op);
+HYPERCALL2(hvm_op);
+HYPERCALL2(memory_op);
+
arch/arm/cpu/armv8/xen/lowlevel_init.S new file +33 -0
new file mode 100644
index 0000000000..760e32ed76
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2017 NXP
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided ATAG/FDT address can be found in r2/x0 */
+	adr	x1, rom_pointer
+	stp	x0, x2, [x1], #16
+	stp	x3, x4, [x1], #16
+
+	/* Returns */
+	b	save_boot_params_ret
+
+.global restore_boot_params
+restore_boot_params:
+	adr	x1, rom_pointer
+	ldp	x0, x2, [x1], #16
+	ldp	x3, x4, [x1], #16
+	ret
arch/arm/include/asm/xen.h new file +7 -0
new file mode 100644
index 0000000000..8e2ee3d64e
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+extern unsigned long rom_pointer[];
+
arch/arm/include/asm/xen/hypercall.h new file +22 -0
new file mode 100644
index 0000000000..a4fd077079
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * hypercall.h
+ *
+ * Linux-specific hypervisor handling.
+ *
+ * Stefano Stabellini <[email protected]>, Citrix, 2012
+ */
+
+#ifndef _ASM_ARM_XEN_HYPERCALL_H
+#define _ASM_ARM_XEN_HYPERCALL_H
+
+#include <xen/interface/xen.h>
+
+int HYPERVISOR_xen_version(int cmd, void *arg);
+int HYPERVISOR_console_io(int cmd, int count, char *str);
+int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
+int HYPERVISOR_sched_op(int cmd, void *arg);
+int HYPERVISOR_event_channel_op(int cmd, void *arg);
+unsigned long HYPERVISOR_hvm_op(int op, void *arg);
+int HYPERVISOR_memory_op(unsigned int cmd, void *arg);
+#endif /* _ASM_ARM_XEN_HYPERCALL_H */
board/xen/xenguest_arm64/Kconfig new file +12 -0
new file mode 100644
index 0000000000..cc131ed5b9
@@ -0,0 +1,12 @@
+if TARGET_XENGUEST_ARM64
+
+config SYS_BOARD
+	default "xenguest_arm64"
+
+config SYS_VENDOR
+	default "xen"
+
+config SYS_CONFIG_NAME
+	default "xenguest_arm64"
+
+endif
board/xen/xenguest_arm64/Makefile new file +5 -0
new file mode 100644
index 0000000000..1cf87a728f
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier:	GPL-2.0+
+#
+# (C) Copyright 2020 EPAM Systems Inc.
+
+obj-y	:= xenguest_arm64.o
board/xen/xenguest_arm64/xenguest_arm64.c new file +117 -0
new file mode 100644
index 0000000000..baebd353aa
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) 2013
+ * David Feng <[email protected]>
+ * Sharma Bhupesh <[email protected]>
+ *
+ * (C) 2020 EPAM Systems Inc
+ */
+
+#include <common.h>
+#include <cpu_func.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include <asm/io.h>
+#include <asm/armv8/mmu.h>
+#include <asm/xen.h>
+#include <asm/xen/hypercall.h>
+
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int board_init(void)
+{
+	return 0;
+}
+
+/*
+ * Use fdt provided by Xen: according to
+ * https://www.kernel.org/doc/Documentation/arm64/booting.txt
+ * x0 is the physical address of the device tree blob (dtb) in system RAM.
+ * This is stored in rom_pointer during low level init.
+ */
+void *board_fdt_blob_setup(void)
+{
+	if (fdt_magic(rom_pointer[0]) != FDT_MAGIC)
+		return NULL;
+	return (void *)rom_pointer[0];
+}
+
+#define MAX_MEM_MAP_REGIONS 5
+static struct mm_region xen_mem_map[MAX_MEM_MAP_REGIONS];
+struct mm_region *mem_map = xen_mem_map;
+
+static int get_next_memory_node(const void *blob, int mem)
+{
+	do {
+		mem = fdt_node_offset_by_prop_value(blob, mem,
+						    "device_type", "memory", 7);
+	} while (!fdtdec_get_is_enabled(blob, mem));
+
+	return mem;
+}
+
+static int setup_mem_map(void)
+{
+	int i, ret, mem, reg = 0;
+	struct fdt_resource res;
+	const void *blob = gd->fdt_blob;
+
+	mem = get_next_memory_node(blob, -1);
+	if (mem < 0) {
+		printf("%s: Missing /memory node\n", __func__);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) {
+		ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
+		if (ret == -FDT_ERR_NOTFOUND) {
+			reg = 0;
+			mem = get_next_memory_node(blob, mem);
+			if (mem == -FDT_ERR_NOTFOUND)
+				break;
+
+			ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
+			if (ret == -FDT_ERR_NOTFOUND)
+				break;
+		}
+		if (ret != 0) {
+			printf("No reg property for memory node\n");
+			return -EINVAL;
+		}
+
+		xen_mem_map[i].virt = (phys_addr_t)res.start;
+		xen_mem_map[i].phys = (phys_addr_t)res.start;
+		xen_mem_map[i].size = (phys_size_t)(res.end - res.start + 1);
+		xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+					PTE_BLOCK_INNER_SHARE);
+	}
+	return 0;
+}
+
+void enable_caches(void)
+{
+	/* Re-setup the memory map as BSS gets cleared after relocation. */
+	setup_mem_map();
+	icache_enable();
+	dcache_enable();
+}
+
+/* Read memory settings from the Xen provided device tree. */
+int dram_init(void)
+{
+	int ret;
+
+	ret = fdtdec_setup_mem_size_base();
+	if (ret < 0)
+		return ret;
+	/* Setup memory map, so MMU page table size can be estimated. */
+	return setup_mem_map();
+}
+
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();

board/xen/xenguest_arm64/xenguest_arm64.c line 127

Quoted 10 lines
board/xen/xenguest_arm64/xenguest_arm64.c new file +10 -0
+}
+
+/*
+ * Board specific reset that is system reset.
+ */
+void reset_cpu(ulong addr)
+{
+}
+
+int ft_system_setup(void *blob, bd_t *bd)

bd_t -> struct bd_info

board/xen/xenguest_arm64/xenguest_arm64.c line 132

Quoted 5 lines
board/xen/xenguest_arm64/xenguest_arm64.c new file +5 -0
+{
+	return 0;
+}
+
+int ft_board_setup(void *blob, bd_t *bd)

ditto.

Quoted 58 lines
board/xen/xenguest_arm64/xenguest_arm64.c new file +20 -0
+{
+	return 0;
+}
+
+int board_early_init_f(void)
+{
+	return 0;
+}
+
+int print_cpuinfo(void)
+{
+	printf("Xen virtual CPU\n");
+	return 0;
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+	return NULL;
+}
+
configs/xenguest_arm64_defconfig new file +32 -0
new file mode 100644
index 0000000000..f730799fc9
@@ -0,0 +1,56 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_SYS_TEXT_BASE=0x40080000
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_IDENT_STRING=" xenguest"
+CONFIG_TARGET_XENGUEST_ARM64=y
+CONFIG_BOOTDELAY=10
+
+CONFIG_SYS_PROMPT="xenguest# "
+
+CONFIG_CMD_NET=n
+CONFIG_CMD_BDI=n
+CONFIG_CMD_BOOTD=n
+CONFIG_CMD_BOOTEFI=n
+CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
+CONFIG_CMD_ELF=n
+CONFIG_CMD_GO=n
+CONFIG_CMD_RUN=n
+CONFIG_CMD_IMI=n
+CONFIG_CMD_IMLS=n
+CONFIG_CMD_XIMG=n
+CONFIG_CMD_EXPORTENV=n
+CONFIG_CMD_IMPORTENV=n
+CONFIG_CMD_EDITENV=n
+CONFIG_CMD_ENV_EXISTS=n
+CONFIG_CMD_MEMORY=y
+CONFIG_CMD_CRC32=n
+CONFIG_CMD_DM=n
+CONFIG_CMD_LOADB=n
+CONFIG_CMD_LOADS=n
+CONFIG_CMD_FLASH=n
+CONFIG_CMD_GPT=n

configs/xenguest_arm64_defconfig line 42

Quoted 10 lines
configs/xenguest_arm64_defconfig new file +10 -0
+CONFIG_CMD_FPGA=n
+CONFIG_CMD_ECHO=n
+CONFIG_CMD_ITEST=n
+CONFIG_CMD_SOURCE=n
+CONFIG_CMD_SETEXPR=n
+CONFIG_CMD_MISC=n
+CONFIG_CMD_UNZIP=n
+CONFIG_CMD_LZMADEC=n
+CONFIG_CMD_SAVEENV=n
+CONFIG_CMD_UMS=n

Try make savedefconfig to make this file minimal.

-Takahiro Akashi

Quoted 67 lines
configs/xenguest_arm64_defconfig new file +14 -0
+
+#CONFIG_USB=n
+# CONFIG_ISO_PARTITION is not set
+
+#CONFIG_EFI_PARTITION=y
+# CONFIG_EFI_LOADER is not set
+
+CONFIG_DM=y
+# CONFIG_MMC is not set
+# CONFIG_DM_SERIAL is not set
+# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
+
+CONFIG_OF_BOARD=y
+CONFIG_OF_LIBFDT=y
include/configs/xenguest_arm64.h new file +44 -0
new file mode 100644
index 0000000000..d8958cfe75
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) Copyright 2020 EPAM Systemc Inc.
+ */
+#ifndef __XENGUEST_ARM64_H
+#define __XENGUEST_ARM64_H
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#endif
+
+#define CONFIG_BOARD_EARLY_INIT_F
+
+#define CONFIG_EXTRA_ENV_SETTINGS
+
+#undef CONFIG_NR_DRAM_BANKS
+#undef CONFIG_SYS_SDRAM_BASE
+
+#define CONFIG_NR_DRAM_BANKS          1
+
+/*
+ * This can be any arbitrary address as we are using PIE, but
+ * please note, that CONFIG_SYS_TEXT_BASE must match the below.
+ */
+#define CONFIG_SYS_LOAD_ADDR                    0x40000000
+#define CONFIG_LNX_KRNL_IMG_TEXT_OFFSET_BASE    CONFIG_SYS_LOAD_ADDR
+
+/* Size of malloc() pool */
+#define CONFIG_SYS_MALLOC_LEN         (32 * 1024 * 1024)
+
+/* Monitor Command Prompt */
+#define CONFIG_SYS_PROMPT_HUSH_PS2    "> "
+#define CONFIG_SYS_CBSIZE             1024
+#define CONFIG_SYS_MAXARGS            64
+#define CONFIG_SYS_BARGSIZE           CONFIG_SYS_CBSIZE
+#define CONFIG_SYS_PBSIZE             (CONFIG_SYS_CBSIZE + \
+				      sizeof(CONFIG_SYS_PROMPT) + 16)
+
+#define CONFIG_OF_SYSTEM_SETUP
+
+#define CONFIG_CMDLINE_TAG            1
+#define CONFIG_INITRD_TAG             1
+
+#endif /* __XENGUEST_ARM64_H */
Signature · 1 line
2.17.1
#12 lore raw

PATCH v2 4/18 board: Introduce xenguest_arm64 board

Hello,

Quoted 456 lines · AKASHI Takahiro
Quoted 454 lines · Anastasiia Lukianenko

From: Andrii Anisov <[email protected]>

Introduce a minimal Xen guest board running as a virtual machine under Xen Project's hypervisor [1], [2].

Part of the code is ported from Xen mini-os and also uses work initially done by different authors from NXP: please see relevant files for their copyrights.

[1]
https://urldefense.com/v3/__https://xenbits.xen.org__;!!GF_29dbcQIUBPA!gaw-wWUzKCW3pH01GHBwBp2VNoIFA29fRgVe746mkWeGaSfDHaworQu-y_AWI0pB7MhjX40$
[xenbits[.]xen[.]org]
[2]
https://urldefense.com/v3/__https://wiki.xenproject.org/__;!!GF_29dbcQIUBPA!gaw-wWUzKCW3pH01GHBwBp2VNoIFA29fRgVe746mkWeGaSfDHaworQu-y_AWI0pBZ2fv9ts$
[wiki[.]xenproject[.]org]

Signed-off-by Oleksandr Andrushchenko <

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

---
 arch/arm/Kconfig                          |   7 +
 arch/arm/cpu/armv8/Makefile               |   1 +
 arch/arm/cpu/armv8/xen/Makefile           |   6 +
 arch/arm/cpu/armv8/xen/hypercall.S        |  79 +++++++++++
 arch/arm/cpu/armv8/xen/lowlevel_init.S    |  33 +++++
 arch/arm/include/asm/xen.h                |   7 +
 arch/arm/include/asm/xen/hypercall.h      |  22 ++++
 board/xen/xenguest_arm64/Kconfig          |  12 ++
 board/xen/xenguest_arm64/Makefile         |   5 +
 board/xen/xenguest_arm64/xenguest_arm64.c | 152
++++++++++++++++++++++
 configs/xenguest_arm64_defconfig          |  56 ++++++++
 include/configs/xenguest_arm64.h          |  44 +++++++
 12 files changed, 424 insertions(+)
 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 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 configs/xenguest_arm64_defconfig
 create mode 100644 include/configs/xenguest_arm64.h
arch/arm/Kconfig +7 -0
index 86238524f7..4ea7891cd3 100644
@@ -1739,6 +1739,12 @@ config TARGET_PRESIDIO_ASIC
 	bool "Support Cortina Presidio ASIC Platform"
 	select ARM64
 
+config TARGET_XENGUEST_ARM64
+	bool "Xen guest ARM64"
+	select ARM64
+	select XEN
+	select OF_CONTROL
+	select LINUX_KERNEL_IMAGE_HEADER
 endchoice
 
 config ARCH_SUPPORT_TFABOOT
@@ -1939,6 +1945,7 @@ source "board/xilinx/Kconfig"
 source "board/xilinx/zynq/Kconfig"
 source "board/xilinx/zynqmp/Kconfig"
 source "board/phytium/durian/Kconfig"
+source "board/xen/xenguest_arm64/Kconfig"
 
 source "arch/arm/Kconfig.debug"
 
arch/arm/cpu/armv8/Makefile +1 -0
index 2e48df0eb9..dd6c354d19 100644
@@ -39,3 +39,4 @@ obj-$(CONFIG_S32V234) += s32v234/
 obj-$(CONFIG_TARGET_HIKEY) += hisilicon/
 obj-$(CONFIG_ARMV8_PSCI) += psci.o
 obj-$(CONFIG_ARCH_SUNXI) += lowlevel_init.o
+obj-$(CONFIG_XEN) += xen/
arch/arm/cpu/armv8/xen/Makefile new file +6 -0
new file mode 100644
index 0000000000..e3b4ae2bd4
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) 2018 NXP
+# (C) 2020 EPAM Systems Inc.
+
+obj-y += lowlevel_init.o hypercall.o
arch/arm/cpu/armv8/xen/hypercall.S new file +7 -0
new file mode 100644
index 0000000000..731256b34e
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * hypercall.S
+ *
+ * Xen hypercall wrappers
+ *
+ * Stefano Stabellini <[email protected]>, Citrix,

2012
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation; or, when distributed
+ * separately from the Linux kernel or incorporated into other
+ * software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */

arch/arm/cpu/armv8/xen/hypercall.S new file +3 -0
+
+/*
+ * The Xen hypercall calling convention is very similar to the

procedure
+ * call standard for the ARM 64-bit architecture: the first parameter is
+ * passed in x0, the second in x1, the third in x2, the fourth in x3 and
+ * the fifth in x4.
+ *
+ * The hypercall number is passed in x16.
+ *
+ * The return value is in x0.
+ *
+ * The hvc ISS is required to be 0xEA1, that is the Xen specific ARM
+ * hypercall tag.
+ *
+ * Parameter structs passed to hypercalls are laid out according to
+ * the ARM 64-bit EABI standard.
+ */

arch/arm/cpu/armv8/xen/hypercall.S new file +30 -0
+
+#include <xen/interface/xen.h>
+
+#define XEN_HYPERCALL_TAG	0xEA1
+
+#define HYPERCALL_SIMPLE(hypercall)		\
+.globl HYPERVISOR_##hypercall;                  \
+.align 4,0x90;                                  \
+HYPERVISOR_##hypercall:				\
+	mov x16, #__HYPERVISOR_##hypercall;	\
+	hvc XEN_HYPERCALL_TAG;			\
+	ret;					\
+
+#define HYPERCALL0 HYPERCALL_SIMPLE
+#define HYPERCALL1 HYPERCALL_SIMPLE
+#define HYPERCALL2 HYPERCALL_SIMPLE
+#define HYPERCALL3 HYPERCALL_SIMPLE
+#define HYPERCALL4 HYPERCALL_SIMPLE
+#define HYPERCALL5 HYPERCALL_SIMPLE
+
+                .text
+
+HYPERCALL2(xen_version);
+HYPERCALL3(console_io);
+HYPERCALL3(grant_table_op);
+HYPERCALL2(sched_op);
+HYPERCALL2(event_channel_op);
+HYPERCALL2(hvm_op);
+HYPERCALL2(memory_op);
+
arch/arm/cpu/armv8/xen/lowlevel_init.S new file +20 -0
new file mode 100644
index 0000000000..760e32ed76
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2017 NXP
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided ATAG/FDT address can be found in r2/x0

*/

arch/arm/cpu/armv8/xen/lowlevel_init.S new file +13 -0
+	adr	x1, rom_pointer
+	stp	x0, x2, [x1], #16
+	stp	x3, x4, [x1], #16
+
+	/* Returns */
+	b	save_boot_params_ret
+
+.global restore_boot_params
+restore_boot_params:
+	adr	x1, rom_pointer
+	ldp	x0, x2, [x1], #16
+	ldp	x3, x4, [x1], #16
+	ret
arch/arm/include/asm/xen.h new file +7 -0
new file mode 100644
index 0000000000..8e2ee3d64e
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+extern unsigned long rom_pointer[];
+
arch/arm/include/asm/xen/hypercall.h new file +7 -0
new file mode 100644
index 0000000000..a4fd077079
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * hypercall.h
+ *
+ * Linux-specific hypervisor handling.
+ *
+ * Stefano Stabellini <[email protected]>, Citrix,

2012
+ */

arch/arm/include/asm/xen/hypercall.h new file +9 -0
+
+#ifndef _ASM_ARM_XEN_HYPERCALL_H
+#define _ASM_ARM_XEN_HYPERCALL_H
+
+#include <xen/interface/xen.h>
+
+int HYPERVISOR_xen_version(int cmd, void *arg);
+int HYPERVISOR_console_io(int cmd, int count, char *str);
+int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop,

unsigned int count);

arch/arm/include/asm/xen/hypercall.h new file +5 -0
+int HYPERVISOR_sched_op(int cmd, void *arg);
+int HYPERVISOR_event_channel_op(int cmd, void *arg);
+unsigned long HYPERVISOR_hvm_op(int op, void *arg);
+int HYPERVISOR_memory_op(unsigned int cmd, void *arg);
+#endif /* _ASM_ARM_XEN_HYPERCALL_H */
board/xen/xenguest_arm64/Kconfig new file +12 -0
new file mode 100644
index 0000000000..cc131ed5b9
@@ -0,0 +1,12 @@
+if TARGET_XENGUEST_ARM64
+
+config SYS_BOARD
+	default "xenguest_arm64"
+
+config SYS_VENDOR
+	default "xen"
+
+config SYS_CONFIG_NAME
+	default "xenguest_arm64"
+
+endif
board/xen/xenguest_arm64/Makefile new file +5 -0
new file mode 100644
index 0000000000..1cf87a728f
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier:	GPL-2.0+
+#
+# (C) Copyright 2020 EPAM Systems Inc.
+
+obj-y	:= xenguest_arm64.o
board/xen/xenguest_arm64/xenguest_arm64.c new file +32 -0
new file mode 100644
index 0000000000..baebd353aa
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) 2013
+ * David Feng <[email protected]>
+ * Sharma Bhupesh <[email protected]>
+ *
+ * (C) 2020 EPAM Systems Inc
+ */
+
+#include <common.h>
+#include <cpu_func.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include <asm/io.h>
+#include <asm/armv8/mmu.h>
+#include <asm/xen.h>
+#include <asm/xen/hypercall.h>
+
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int board_init(void)
+{
+	return 0;
+}
+
+/*
+ * Use fdt provided by Xen: according to
+ * 

https://urldefense.com/v3/__https://www.kernel.org/doc/Documentation/arm64/booting.txt__;!!GF_29dbcQIUBPA!gaw-wWUzKCW3pH01GHBwBp2VNoIFA29fRgVe746mkWeGaSfDHaworQu-y_AWI0pBf18zZOE$
[kernel[.]org]
+ * x0 is the physical address of the device tree blob (dtb) in system RAM.
+ * This is stored in rom_pointer during low level init.
+ */

board/xen/xenguest_arm64/xenguest_arm64.c new file +16 -0
+void *board_fdt_blob_setup(void)
+{
+	if (fdt_magic(rom_pointer[0]) != FDT_MAGIC)
+		return NULL;
+	return (void *)rom_pointer[0];
+}
+
+#define MAX_MEM_MAP_REGIONS 5
+static struct mm_region xen_mem_map[MAX_MEM_MAP_REGIONS];
+struct mm_region *mem_map = xen_mem_map;
+
+static int get_next_memory_node(const void *blob, int mem)
+{
+	do {
+		mem = fdt_node_offset_by_prop_value(blob, mem,
+						    "device_type",

"memory", 7);

board/xen/xenguest_arm64/xenguest_arm64.c new file +26 -0
+	} while (!fdtdec_get_is_enabled(blob, mem));
+
+	return mem;
+}
+
+static int setup_mem_map(void)
+{
+	int i, ret, mem, reg = 0;
+	struct fdt_resource res;
+	const void *blob = gd->fdt_blob;
+
+	mem = get_next_memory_node(blob, -1);
+	if (mem < 0) {
+		printf("%s: Missing /memory node\n", __func__);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) {
+		ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
+		if (ret == -FDT_ERR_NOTFOUND) {
+			reg = 0;
+			mem = get_next_memory_node(blob, mem);
+			if (mem == -FDT_ERR_NOTFOUND)
+				break;
+
+			ret = fdt_get_resource(blob, mem, "reg", reg++,

&res);

board/xen/xenguest_arm64/xenguest_arm64.c new file +21 -0
+			if (ret == -FDT_ERR_NOTFOUND)
+				break;
+		}
+		if (ret != 0) {
+			printf("No reg property for memory node\n");
+			return -EINVAL;
+		}
+
+		xen_mem_map[i].virt = (phys_addr_t)res.start;
+		xen_mem_map[i].phys = (phys_addr_t)res.start;
+		xen_mem_map[i].size = (phys_size_t)(res.end - res.start
+ 1);
+		xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+					PTE_BLOCK_INNER_SHARE);
+	}
+	return 0;
+}
+
+void enable_caches(void)
+{
+	/* Re-setup the memory map as BSS gets cleared after

relocation. */

board/xen/xenguest_arm64/xenguest_arm64.c new file +14 -0
+	setup_mem_map();
+	icache_enable();
+	dcache_enable();
+}
+
+/* Read memory settings from the Xen provided device tree. */
+int dram_init(void)
+{
+	int ret;
+
+	ret = fdtdec_setup_mem_size_base();
+	if (ret < 0)
+		return ret;
+	/* Setup memory map, so MMU page table size can be estimated.

*/

board/xen/xenguest_arm64/xenguest_arm64.c new file +10 -0
+	return setup_mem_map();
+}
+
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();
+}
+
+/*
+ * Board specific reset that is system reset.
Quoted 8 lines

board/xen/xenguest_arm64/xenguest_arm64.c line 127

Quoted 6 lines

+ */

board/xen/xenguest_arm64/xenguest_arm64.c new file +5 -0
+void reset_cpu(ulong addr)
+{
+}
+
+int ft_system_setup(void *blob, bd_t *bd)

bd_t -> struct bd_info

Ok, will change.

Quoted 72 lines

board/xen/xenguest_arm64/xenguest_arm64.c line 132

Quoted 6 lines
board/xen/xenguest_arm64/xenguest_arm64.c new file +5 -0
+{
+	return 0;
+}
+
+int ft_board_setup(void *blob, bd_t *bd)

ditto.

Quoted 63 lines
board/xen/xenguest_arm64/xenguest_arm64.c new file +20 -0
+{
+	return 0;
+}
+
+int board_early_init_f(void)
+{
+	return 0;
+}
+
+int print_cpuinfo(void)
+{
+	printf("Xen virtual CPU\n");
+	return 0;
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+	return NULL;
+}
+
configs/xenguest_arm64_defconfig new file +36 -0
new file mode 100644
index 0000000000..f730799fc9
@@ -0,0 +1,56 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_SYS_TEXT_BASE=0x40080000
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_IDENT_STRING=" xenguest"
+CONFIG_TARGET_XENGUEST_ARM64=y
+CONFIG_BOOTDELAY=10
+
+CONFIG_SYS_PROMPT="xenguest# "
+
+CONFIG_CMD_NET=n
+CONFIG_CMD_BDI=n
+CONFIG_CMD_BOOTD=n
+CONFIG_CMD_BOOTEFI=n
+CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n
+CONFIG_CMD_ELF=n
+CONFIG_CMD_GO=n
+CONFIG_CMD_RUN=n
+CONFIG_CMD_IMI=n
+CONFIG_CMD_IMLS=n
+CONFIG_CMD_XIMG=n
+CONFIG_CMD_EXPORTENV=n
+CONFIG_CMD_IMPORTENV=n
+CONFIG_CMD_EDITENV=n
+CONFIG_CMD_ENV_EXISTS=n
+CONFIG_CMD_MEMORY=y
+CONFIG_CMD_CRC32=n
+CONFIG_CMD_DM=n
+CONFIG_CMD_LOADB=n
+CONFIG_CMD_LOADS=n
+CONFIG_CMD_FLASH=n
+CONFIG_CMD_GPT=n
+CONFIG_CMD_FPGA=n
+CONFIG_CMD_ECHO=n
+CONFIG_CMD_ITEST=n
+CONFIG_CMD_SOURCE=n
Quoted 8 lines

configs/xenguest_arm64_defconfig line 42

Quoted 6 lines
configs/xenguest_arm64_defconfig new file +6 -0
+CONFIG_CMD_SETEXPR=n
+CONFIG_CMD_MISC=n
+CONFIG_CMD_UNZIP=n
+CONFIG_CMD_LZMADEC=n
+CONFIG_CMD_SAVEENV=n
+CONFIG_CMD_UMS=n

Try make savedefconfig to make this file minimal.

Ok.

Quoted 64 lines

-Takahiro Akashi

Quoted 61 lines
configs/xenguest_arm64_defconfig new file +14 -0
+
+#CONFIG_USB=n
+# CONFIG_ISO_PARTITION is not set
+
+#CONFIG_EFI_PARTITION=y
+# CONFIG_EFI_LOADER is not set
+
+CONFIG_DM=y
+# CONFIG_MMC is not set
+# CONFIG_DM_SERIAL is not set
+# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
+
+CONFIG_OF_BOARD=y
+CONFIG_OF_LIBFDT=y
include/configs/xenguest_arm64.h new file +26 -0
new file mode 100644
index 0000000000..d8958cfe75
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) Copyright 2020 EPAM Systemc Inc.
+ */
+#ifndef __XENGUEST_ARM64_H
+#define __XENGUEST_ARM64_H
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#endif
+
+#define CONFIG_BOARD_EARLY_INIT_F
+
+#define CONFIG_EXTRA_ENV_SETTINGS
+
+#undef CONFIG_NR_DRAM_BANKS
+#undef CONFIG_SYS_SDRAM_BASE
+
+#define CONFIG_NR_DRAM_BANKS          1
+
+/*
+ * This can be any arbitrary address as we are using PIE, but
+ * please note, that CONFIG_SYS_TEXT_BASE must match the below.
+ */
+#define CONFIG_SYS_LOAD_ADDR                    0x40000000
+#define

CONFIG_LNX_KRNL_IMG_TEXT_OFFSET_BASE CONFIG_SYS_LOAD_ADDR

include/configs/xenguest_arm64.h new file +13 -0
+
+/* Size of malloc() pool */
+#define CONFIG_SYS_MALLOC_LEN         (32 * 1024 * 1024)
+
+/* Monitor Command Prompt */
+#define CONFIG_SYS_PROMPT_HUSH_PS2    "> "
+#define CONFIG_SYS_CBSIZE             1024
+#define CONFIG_SYS_MAXARGS            64
+#define CONFIG_SYS_BARGSIZE           CONFIG_SYS_CBSIZE
+#define CONFIG_SYS_PBSIZE             (CONFIG_SYS_CBSIZE + \
+				      sizeof(CONFIG_SYS_PROMPT) + 16)
+
+#define CONFIG_OF_SYSTEM_SETUP
Quoted 8 lines
Quoted 8 lines
include/configs/xenguest_arm64.h new file +5 -0
+
+#define CONFIG_CMDLINE_TAG            1
+#define CONFIG_INITRD_TAG             1
+
+#endif /* __XENGUEST_ARM64_H */
Signature · 1 line
2.17.1

Regards,
Anastasiia

#13 lore raw

PATCH v2 5/18 xen: Port Xen hypervizor related code from mini-os

In reply to Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Port hypervizor related code from mini-os. Update essential arch code to support required bit operations, memory barriers etc.

Copyright for the bits ported belong to at least the following authors, please see related files for details:

Copyright (c) 2002-2003, K A Fraser
Copyright (c) 2005, Grzegorz Milos, gm281 at cam.ac.uk,Intel Research Cambridge Copyright (c) 2014, Karim Allah Ahmed <[email protected]>

---
 arch/arm/include/asm/io.h         |   4 +
 arch/arm/include/asm/xen/system.h |  88 +++++++++++
 common/board_r.c                  |  13 ++
 drivers/Makefile                  |   1 +
 drivers/xen/Makefile              |   5 +
 drivers/xen/hypervisor.c          | 240 ++++++++++++++++++++++++++++++
 include/xen.h                     |  15 ++
 include/xen/hvm.h                 |  27 ++++
 8 files changed, 393 insertions(+)
 create mode 100644 arch/arm/include/asm/xen/system.h
 create mode 100644 drivers/xen/Makefile
 create mode 100644 drivers/xen/hypervisor.c
 create mode 100644 include/xen.h
 create mode 100644 include/xen/hvm.h
arch/arm/include/asm/io.h +4 -0
index 8959749ad6..ade1401f3b 100644
@@ -110,9 +110,13 @@ static inline void __raw_readsl(unsigned long addr, void *data, int longlen)
  * have some advantages to use them instead of the simple one here.
  */
 #define mb()		dsb()
+#define rmb()		dsb()
+#define wmb()		dsb()
 #define __iormb()	dmb()
 #define __iowmb()	dmb()
 
+#define smp_processor_id()	0
+
 #define writeb(v,c)	({ u8  __v = v; __iowmb(); __arch_putb(__v,c); __v; })
 #define writew(v,c)	({ u16 __v = v; __iowmb(); __arch_putw(__v,c); __v; })
 #define writel(v,c)	({ u32 __v = v; __iowmb(); __arch_putl(__v,c); __v; })
arch/arm/include/asm/xen/system.h new file +88 -0

88 lines not on this page · raw message

common/board_r.c +13 -0
index 5e924322b2..c8a3a8665c 100644
@@ -56,6 +56,9 @@
 #include <timer.h>
 #include <trace.h>
 #include <watchdog.h>
+#ifdef CONFIG_XEN
+#include <xen.h>
+#endif
 #ifdef CONFIG_ADDR_MAP
 #include <asm/mmu.h>
 #endif
@@ -462,6 +465,13 @@ static int initr_mmc(void)
 }
 #endif
 
+#ifdef CONFIG_XEN
+static int initr_xen(void)
+{
+	xen_init();
+	return 0;
+}
+#endif
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -755,6 +765,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_MMC
 	initr_mmc,
+#endif
+#ifdef CONFIG_XEN
+	initr_xen,
 #endif
 	initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
drivers/Makefile +1 -0
index afd159e903..14ac35e907 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/
 obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm/
 obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC) += power/acpi_pmc/
 obj-$(CONFIG_$(SPL_)BOARD) += board/
+obj-$(CONFIG_XEN) += xen/
 
 ifndef CONFIG_TPL_BUILD
 ifdef CONFIG_SPL_BUILD
drivers/xen/Makefile new file +5 -0
new file mode 100644
index 0000000000..1211bf2386
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier:	GPL-2.0+
+#
+# (C) Copyright 2020 EPAM Systems Inc.
+
+obj-y += hypervisor.o
drivers/xen/hypervisor.c new file +240 -0

240 lines not on this page · raw message

include/xen.h new file +15 -0
new file mode 100644
index 0000000000..abc3546dd2
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * (C) 2020, EPAM Systems Inc.
+ */
+#ifndef __XEN_H__
+#define __XEN_H__
+
+/**
+ * xen_init() - Xen initialization
+ *
+ * Map Xen memory pages.
+ */
+void xen_init(void);
+
+#endif /* __XEN_H__ */
include/xen/hvm.h new file +27 -0
new file mode 100644
index 0000000000..f02c0798a6
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Simple wrappers around HVM functions
+ *
+ * Copyright (c) 2002-2003, K A Fraser
+ * Copyright (c) 2005, Grzegorz Milos, gm281 at cam.ac.uk,Intel Research Cambridge
+ * Copyright (c) 2020, EPAM Systems Inc.
+ */
+#ifndef XEN_HVM_H__
+#define XEN_HVM_H__
+
+#include <asm/xen/hypercall.h>
+#include <xen/interface/hvm/params.h>
+#include <xen/interface/xen.h>
+
+extern struct shared_info *HYPERVISOR_shared_info;
+
+int hvm_get_parameter(int idx, uint64_t *value);
+int hvm_get_parameter_maintain_dcache(int idx, uint64_t *value);
+
+struct shared_info *map_shared_info(void *p);
+void do_hypervisor_callback(struct pt_regs *regs);
+void mask_evtchn(uint32_t port);
+void unmask_evtchn(uint32_t port);
+void clear_evtchn(uint32_t port);
+
+#endif /* XEN_HVM_H__ */
Signature · 1 line
2.17.1
#14 lore raw

PATCH v2 6/18 xen: Port Xen event channel driver from mini-os

In reply to Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Make required updates to run on u-boot. Strip functionality not needed by U-boot.

---
 drivers/xen/Makefile     |   1 +
 drivers/xen/events.c     | 195 +++++++++++++++++++++++++++++++++++++++
 drivers/xen/hypervisor.c |   6 +-
 include/xen.h            |   2 +-
 include/xen/events.h     |  42 +++++++++
 5 files changed, 242 insertions(+), 4 deletions(-)
 create mode 100644 drivers/xen/events.c
 create mode 100644 include/xen/events.h
drivers/xen/Makefile +1 -0
index 1211bf2386..0ad35edefb 100644
@@ -3,3 +3,4 @@
 # (C) Copyright 2020 EPAM Systems Inc.
 
 obj-y += hypervisor.o
+obj-y += events.o
drivers/xen/events.c new file +195 -0

195 lines not on this page · raw message

drivers/xen/hypervisor.c +3 -3
index 108e9701d6..63fed6074f 100644
@@ -20,6 +20,7 @@
 #include <linux/bug.h>
 
 #include <xen/hvm.h>
+#include <xen/events.h>
 #include <xen/interface/memory.h>
 
 #define active_evtchns(cpu, sh, idx)	\
@@ -163,9 +164,7 @@ void do_hypervisor_callback(struct pt_regs *regs)
 			l2 &= ~(1UL << l2i);
 
 			port = (l1i * (sizeof(unsigned long) * 8)) + l2i;
-			/* TODO: handle new event: do_event(port, regs); */
-			/* Suppress -Wunused-but-set-variable */
-			(void)(port);
+			do_event(port, regs);
 		}
 	}
 
@@ -236,5 +235,6 @@ void xen_init(void)
 	debug("%s\n", __func__);
 
 	map_shared_info(NULL);
+	init_events();
 }
 
include/xen.h +1 -1
index abc3546dd2..64ed3f0654 100644
@@ -8,7 +8,7 @@
 /**
  * xen_init() - Xen initialization
  *
- * Map Xen memory pages.
+ * Map Xen memory pages, initialize event handler.
  */
 void xen_init(void);
 
include/xen/events.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.17.1
#15 lore raw

PATCH v2 7/18 serial: serial_xen: Add Xen PV serial driver

In reply to Anastasiia Lukianenko

From: Peng Fan <[email protected]>

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

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

---
 arch/arm/Kconfig                          |   1 +
 board/xen/xenguest_arm64/xenguest_arm64.c |  31 +++-
 configs/xenguest_arm64_defconfig          |   2 +-
 drivers/serial/Kconfig                    |   7 +
 drivers/serial/Makefile                   |   1 +
 drivers/serial/serial_xen.c               | 182 ++++++++++++++++++++++
 drivers/xen/events.c                      |   4 +
 7 files changed, 220 insertions(+), 8 deletions(-)
 create mode 100644 drivers/serial/serial_xen.c
arch/arm/Kconfig +1 -0
index 4ea7891cd3..124d3eb3aa 100644
@@ -1745,6 +1745,7 @@ config TARGET_XENGUEST_ARM64
 	select XEN
 	select OF_CONTROL
 	select LINUX_KERNEL_IMAGE_HEADER
+	select XEN_SERIAL
 endchoice
 
 config ARCH_SUPPORT_TFABOOT
board/xen/xenguest_arm64/xenguest_arm64.c +24 -7
index baebd353aa..488b238f02 100644
@@ -17,9 +17,12 @@
 #include <asm/armv8/mmu.h>
 #include <asm/xen.h>
 #include <asm/xen/hypercall.h>
+#include <asm/xen/system.h>
 
 #include <linux/compiler.h>
 
+#include <xen/hvm.h>
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
@@ -56,9 +59,28 @@ static int get_next_memory_node(const void *blob, int mem)
 
 static int setup_mem_map(void)
 {
-	int i, ret, mem, reg = 0;
+	int i = 0, ret, mem, reg = 0;
 	struct fdt_resource res;
 	const void *blob = gd->fdt_blob;
+	u64 gfn;
+
+	/*
+	 * Add "magic" region which is used by Xen to provide some essentials
+	 * for the guest: we need console.
+	 */
+	ret = hvm_get_parameter_maintain_dcache(HVM_PARAM_CONSOLE_PFN, &gfn);
+	if (ret < 0) {
+		printf("%s: Can't get HVM_PARAM_CONSOLE_PFN, ret %d\n",
+		       __func__, ret);
+		return -EINVAL;
+	}
+
+	xen_mem_map[i].virt = PFN_PHYS(gfn);
+	xen_mem_map[i].phys = PFN_PHYS(gfn);
+	xen_mem_map[i].size = PAGE_SIZE;
+	xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+				PTE_BLOCK_INNER_SHARE);
+	i++;
 
 	mem = get_next_memory_node(blob, -1);
 	if (mem < 0) {
@@ -66,7 +88,7 @@ static int setup_mem_map(void)
 		return -EINVAL;
 	}
 
-	for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) {
+	for (; i < MAX_MEM_MAP_REGIONS; i++) {
 		ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
 		if (ret == -FDT_ERR_NOTFOUND) {
 			reg = 0;
@@ -145,8 +167,3 @@ int print_cpuinfo(void)
 	return 0;
 }
 
-__weak struct serial_device *default_serial_console(void)
-{
-	return NULL;
-}
-
configs/xenguest_arm64_defconfig +1 -1
index f730799fc9..45559a161b 100644
@@ -49,7 +49,7 @@ CONFIG_CMD_UMS=n
 
 CONFIG_DM=y
 # CONFIG_MMC is not set
-# CONFIG_DM_SERIAL is not set
+CONFIG_DM_SERIAL=y
 # CONFIG_REQUIRE_SERIAL_CONSOLE is not set
 
 CONFIG_OF_BOARD=y
drivers/serial/Kconfig +7 -0
index 17d0e73623..33c989a66d 100644
@@ -821,6 +821,13 @@ config MPC8XX_CONS
 	depends on MPC8xx
 	default y
 
+config XEN_SERIAL
+	bool "XEN serial support"
+	depends on XEN
+	help
+	  If built without DM support, then requires Xen
+	  to be built with CONFIG_VERBOSE_DEBUG.
+
 choice
 	prompt "Console port"
 	default 8xx_CONS_SMC1
drivers/serial/Makefile +1 -0
index e4a92bbbb7..25f7f8d342 100644
@@ -70,6 +70,7 @@ obj-$(CONFIG_OWL_SERIAL) += serial_owl.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_MTK_SERIAL) += serial_mtk.o
 obj-$(CONFIG_SIFIVE_SERIAL) += serial_sifive.o
+obj-$(CONFIG_XEN_SERIAL) += serial_xen.o
 
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_USB_TTY) += usbtty.o
drivers/serial/serial_xen.c new file +182 -0

182 lines not on this page · raw message

drivers/xen/events.c +4 -0
index b4c84814c5..beaccded69 100644
@@ -23,6 +23,8 @@
 #include <xen/events.h>
 #include <xen/hvm.h>
 
+extern u32 console_evtchn;
+
 #define NR_EVS 1024
 
 /**
@@ -49,6 +51,8 @@ void unbind_all_ports(void)
 	struct vcpu_info *vcpu_info = &s->vcpu_info[cpu];
 
 	for (i = 0; i < NR_EVS; i++) {
+		if (i == console_evtchn)
+			continue;
 		if (test_and_clear_bit(i, bound_ports)) {
 			printf("port %d still bound!\n", i);
 			unbind_evtchn(i);
Signature · 1 line
2.17.1
#16 lore raw

PATCH v2 8/18 linux/compat.h: Add wait_event_timeout macro

In reply to Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Add wait_event_timeout - sleep until a condition gets true or a timeout elapses.

This is a stripped version of the same from Linux kernel with the following u-boot specific modifications:
- no wait queues supported
- use u-boot timer to detect timeouts
- check for Ctrl-C pressed during wait

---
 include/linux/compat.h | 54 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
include/linux/compat.h +54 -0
index 712eeaef4e..363b2b9425 100644
@@ -1,12 +1,20 @@
 #ifndef _LINUX_COMPAT_H_
 #define _LINUX_COMPAT_H_
 
+#include <console.h>
 #include <log.h>
 #include <malloc.h>
+
+#include <asm/processor.h>
+
 #include <linux/types.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
 
+#ifdef CONFIG_XEN
+#include <xen/events.h>
+#endif
+
 struct unused {};
 typedef struct unused unused_t;
 
@@ -122,6 +130,52 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep)
 #define add_wait_queue(...)	do { } while (0)
 #define remove_wait_queue(...)	do { } while (0)
 
+#ifndef CONFIG_XEN
+#define eventchn_poll()
+#endif
+
+#define __wait_event_timeout(condition, timeout, ret)		\
+({								\
+	ulong __ret = ret; /* explicit shadow */		\
+	ulong start = get_timer(0);				\
+	for (;;) {						\
+		eventchn_poll();				\
+		if (condition) {				\
+			__ret = 1;				\
+			break;					\
+	}							\
+	if ((get_timer(start) > timeout) || ctrlc()) {		\
+		__ret = 0;					\
+		break;						\
+	}							\
+	cpu_relax();						\
+	}							\
+	__ret;							\
+})
+
+/**
+ * wait_event_timeout() - Wait until the event occurs before the timeout.
+ * @wr_head: The wait queue to wait on.
+ * @condition: Expression for the event to wait for.
+ * @timeout: Maximum waiting time.
+ *
+ * We wait until the @condition evaluates to %true (succeed) or
+ * %false (@timeout elapsed).
+ *
+ * Return:
+ * 0 - if the @condition evaluated to %false after the @timeout elapsed
+ * 1 - if the @condition evaluated to %true
+ */
+#define wait_event_timeout(wq_head, condition, timeout)			\
+({									\
+	ulong __ret;							\
+	if (condition)							\
+		__ret = 1;						\
+	else								\
+		__ret = __wait_event_timeout(condition, timeout, __ret);\
+	__ret;								\
+})
+
 #define KERNEL_VERSION(a,b,c)	(((a) << 16) + ((b) << 8) + (c))
 
 /* This is also defined in ARMv8's mmu.h */
Signature · 1 line
2.17.1
#17 lore raw

PATCH v2 9/18 lib: sscanf: add sscanf implementation

In reply to Anastasiia Lukianenko

From: Andrii Anisov <[email protected]>

Port sscanf implementation from mini-os and introduce new Kconfig option to enable it: CONFIG_SSCANF. Disable by default.

---
 include/vsprintf.h |   8 +
 lib/Kconfig        |   4 +
 lib/Makefile       |   1 +
 lib/sscanf.c       | 823 +++++++++++++++++++++++++++++++++++++++++++++
 test/lib/Makefile  |   1 +
 test/lib/sscanf.c  | 174 ++++++++++
 6 files changed, 1011 insertions(+)
 create mode 100644 lib/sscanf.c
 create mode 100644 test/lib/sscanf.c
include/vsprintf.h +8 -0
index d9fb68add0..2290083eba 100644
@@ -234,4 +234,12 @@ char *strmhz(char *buf, unsigned long hz);
  */
 void str_to_upper(const char *in, char *out, size_t len);
 
+/**
+ * sscanf - Unformat a buffer into a list of arguments
+ * @buf:	input buffer
+ * @fmt:	formatting of buffer
+ * @...:	resulting arguments
+ */
+int sscanf(const char *buf, const char *fmt, ...);
+
 #endif
lib/Kconfig +4 -0
index 2142bd06e6..efd383ea88 100644
@@ -80,6 +80,10 @@ config SPL_SPRINTF
 config TPL_SPRINTF
 	bool
 
+config SSCANF
+	bool
+	default n
+
 config STRTO
 	bool
 	default y
lib/Makefile +1 -0
index 1dc06c57d5..0cd7bea282 100644
@@ -123,6 +123,7 @@ else
 # Main U-Boot always uses the full printf support
 obj-y += vsprintf.o strto.o
 obj-$(CONFIG_OID_REGISTRY) += oid_registry.o
+obj-$(CONFIG_SSCANF) += sscanf.o
 endif
 
 obj-y += date.o
lib/sscanf.c new file +823 -0

823 lines not on this page · raw message

test/lib/Makefile +1 -0
index 6ccc2c41bc..b6a0a208c5 100644
@@ -6,6 +6,7 @@ obj-y += cmd_ut_lib.o
 obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
 obj-y += hexdump.o
 obj-y += lmb.o
+obj-y += sscanf.o
 obj-y += string.o
 obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
 obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
test/lib/sscanf.c new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
2.17.1
#18 lore raw

PATCH v2 10/18 xen: Port Xen bus driver from mini-os

In reply to Anastasiia Lukianenko

From: Oleksandr Andrushchenko <[email protected]>

Make required updates to run on u-boot and strip test code.

---
 arch/arm/Kconfig                          |   1 +
 board/xen/xenguest_arm64/xenguest_arm64.c |  16 +-
 drivers/xen/Makefile                      |   1 +
 drivers/xen/hypervisor.c                  |   2 +
 drivers/xen/xenbus.c                      | 557 ++++++++++++++++++++++
 include/xen.h                             |   2 +-
 include/xen/xenbus.h                      | 116 +++++
 7 files changed, 693 insertions(+), 2 deletions(-)
 create mode 100644 drivers/xen/xenbus.c
 create mode 100644 include/xen/xenbus.h
arch/arm/Kconfig +1 -0
index 124d3eb3aa..497f540019 100644
@@ -1746,6 +1746,7 @@ config TARGET_XENGUEST_ARM64
 	select OF_CONTROL
 	select LINUX_KERNEL_IMAGE_HEADER
 	select XEN_SERIAL
+	select SSCANF
 endchoice
 
 config ARCH_SUPPORT_TFABOOT
board/xen/xenguest_arm64/xenguest_arm64.c +15 -1
index 488b238f02..18e12c404e 100644
@@ -66,7 +66,7 @@ static int setup_mem_map(void)
 
 	/*
 	 * Add "magic" region which is used by Xen to provide some essentials
-	 * for the guest: we need console.
+	 * for the guest: we need console and xenstore.
 	 */
 	ret = hvm_get_parameter_maintain_dcache(HVM_PARAM_CONSOLE_PFN, &gfn);
 	if (ret < 0) {
@@ -82,6 +82,20 @@ static int setup_mem_map(void)
 				PTE_BLOCK_INNER_SHARE);
 	i++;
 
+	ret = hvm_get_parameter_maintain_dcache(HVM_PARAM_STORE_PFN, &gfn);
+	if (ret < 0) {
+		printf("%s: Can't get HVM_PARAM_STORE_PFN, ret %d\n",
+		       __func__, ret);
+		return -EINVAL;
+	}
+
+	xen_mem_map[i].virt = PFN_PHYS(gfn);
+	xen_mem_map[i].phys = PFN_PHYS(gfn);
+	xen_mem_map[i].size = PAGE_SIZE;
+	xen_mem_map[i].attrs = (PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+				PTE_BLOCK_INNER_SHARE);
+	i++;
+
 	mem = get_next_memory_node(blob, -1);
 	if (mem < 0) {
 		printf("%s: Missing /memory node\n", __func__);
drivers/xen/Makefile +1 -0
index 0ad35edefb..9d0f604aaa 100644
@@ -4,3 +4,4 @@
 
 obj-y += hypervisor.o
 obj-y += events.o
+obj-y += xenbus.o
drivers/xen/hypervisor.c +2 -0
index 63fed6074f..1c7ae94bdf 100644
@@ -21,6 +21,7 @@
 
 #include <xen/hvm.h>
 #include <xen/events.h>
+#include <xen/xenbus.h>
 #include <xen/interface/memory.h>
 
 #define active_evtchns(cpu, sh, idx)	\
@@ -236,5 +237,6 @@ void xen_init(void)
 
 	map_shared_info(NULL);
 	init_events();
+	init_xenbus();
 }
 
drivers/xen/xenbus.c new file +557 -0

557 lines not on this page · raw message

include/xen.h +1 -1
index 64ed3f0654..6fe30b83a2 100644
@@ -8,7 +8,7 @@
 /**
  * xen_init() - Xen initialization
  *
- * Map Xen memory pages, initialize event handler.
+ * Map Xen memory pages, initialize event handler and xenbus.
  */
 void xen_init(void);
 
include/xen/xenbus.h new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
2.17.1
#19 lore raw

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

In reply to 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                      | 216 ++++++++++++++++++++++
 drivers/xen/hypervisor.c                  |   2 +
 include/xen.h                             |   3 +-
 include/xen/gnttab.h                      |  24 +++
 6 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 drivers/xen/gnttab.c
 create mode 100644 include/xen/gnttab.h
board/xen/xenguest_arm64/xenguest_arm64.c +13 -0
index 18e12c404e..9861edac33 100644
@@ -21,6 +21,7 @@
 
 #include <linux/compiler.h>
 
+#include <xen/gnttab.h>
 #include <xen/hvm.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -63,6 +64,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
@@ -96,6 +99,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 +216 -0

216 lines not on this page · raw message

drivers/xen/hypervisor.c +2 -0
index 1c7ae94bdf..58b0865e6a 100644
@@ -21,6 +21,7 @@
 
 #include <xen/hvm.h>
 #include <xen/events.h>
+#include <xen/gnttab.h>
 #include <xen/xenbus.h>
 #include <xen/interface/memory.h>
 
@@ -238,5 +239,6 @@ void xen_init(void)
 	map_shared_info(NULL);
 	init_events();
 	init_xenbus();
+	init_gnttab();
 }
 
include/xen.h +2 -1
index 6fe30b83a2..686b7148b5 100644
@@ -8,7 +8,8 @@
 /**
  * xen_init() - Xen initialization
  *
- * Map Xen memory pages, initialize event handler and xenbus.
+ * Map Xen memory pages, initialize event handler and xenbus,
+ * setup the grant table.
  */
 void xen_init(void);
 
include/xen/gnttab.h new file +24 -0
new file mode 100644
index 0000000000..db1d5361fe
@@ -0,0 +1,24 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * (C) 2006, Steven Smith <[email protected]>
+ * (C) 2006, Grzegorz Milos <[email protected]>
+ * (C) 2020, EPAM Systems Inc.
+ */
+#ifndef __GNTTAB_H__
+#define __GNTTAB_H__
+
+#include <xen/interface/grant_table.h>
+
+void init_gnttab(void);
+void fini_gnttab(void);
+
+grant_ref_t gnttab_alloc_and_grant(void **map);
+grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame,
+				int readonly);
+int gnttab_end_access(grant_ref_t ref);
+const char *gnttabop_error(int16_t status);
+
+void get_gnttab_base(phys_addr_t *gnttab_base, phys_size_t *gnttab_sz);
+
+#endif /* !__GNTTAB_H__ */
Signature · 1 line
2.17.1
#20 lore raw

PATCH v2 12/18 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                    |  30 ++++++++
 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            | 120 +++++++++++++++++++++++++++++++
 include/blk.h                    |   1 +
 include/configs/xenguest_arm64.h |   8 +++
 include/dm/uclass-id.h           |   1 +
 include/pvblock.h                |  17 +++++
 15 files changed, 223 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 bfe6c163dc..fb6ea58d6c 100644
@@ -1350,6 +1350,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 7952138dc2..f46c4a335d 100644
@@ -171,6 +171,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 +30 -0
new file mode 100644
index 0000000000..4e99b06122
@@ -0,0 +1,30 @@
+// 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 c8a3a8665c..6524891a9d 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>
@@ -472,6 +473,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.
  *
@@ -768,6 +779,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 7a839fa1aa..57f31f1c12 100644
@@ -134,6 +134,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 +120 -0

120 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 d8958cfe75..db3059a82c 100644
@@ -41,4 +41,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 +17 -0
new file mode 100644
index 0000000000..1023a6ab3b
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) 2020 EPAM Systems Inc.
+ */
+
+#ifndef _PVBLOCK_H
+#define _PVBLOCK_H
+
+/**
+ * pvblock_init() - Initialize para-virtual block device class driver
+ *
+ * Bind PV block to UCLASS_ROOT device and probe all UCLASS_PVBLOCK
+ * virtual block devices.
+ */
+void pvblock_init(void);
+
+#endif /* _PVBLOCK_H */
Signature · 1 line
2.17.1
#21 lore raw

PATCH v2 13/18 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 d2b616bb63..3ed62cac5d 100644
@@ -6,6 +6,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"
@@ -14,6 +18,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;
@@ -37,15 +45,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;
@@ -79,6 +112,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;
@@ -105,6 +200,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
#22 lore raw

PATCH v2 14/18 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 | 285 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 284 insertions(+), 1 deletion(-)
drivers/xen/pvblock.c +284 -1
index 3ed62cac5d..e247ce33a3 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
+ * (C) 2007-2008 Samuel Thibault.
  * (C) Copyright 2020 EPAM Systems Inc.
  */
 #include <blk.h>
@@ -9,26 +10,302 @@
 #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 - Struct representing blkfront device
+ * @dom: Domain id
+ * @ring: Front_ring structure
+ * @ring_ref: The grant reference, allowing us to grant access
+ *	      to the ring to the other end/domain
+ * @evtchn: Event channel used to signal ring events
+ * @handle: Events handle
+ * @nodename: Device XenStore path in format "device/vbd/" + @devid
+ * @backend: Backend XenStore path
+ * @info: Private data
+ * @devid: Device id
+ */
 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 && state < XenbusStateConnected)
+			msg = xenbus_wait_for_state_change(path, &state);
+		if (msg || 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 && 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 &&
+	       (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,
@@ -73,6 +350,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;
@@ -81,6 +359,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
#23 lore raw

PATCH v2 15/18 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 | 358 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 348 insertions(+), 12 deletions(-)
drivers/xen/events.c +1 -1
index beaccded69..c490f87b2f 100644
@@ -107,7 +107,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 +347 -11

424 lines not on this page · raw message

Signature · 1 line
2.17.1
#24 lore raw

PATCH v2 16/18 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 1284bc4cca..76e82fbf41 100644
@@ -793,6 +793,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;
@@ -815,6 +833,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
#25 lore raw

PATCH v2 17/18 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                             | 8 ++++++++
 3 files changed, 22 insertions(+)
board/xen/xenguest_arm64/xenguest_arm64.c +6 -0
index 9861edac33..927d87ae37 100644
@@ -12,6 +12,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <xen.h>
 
 #include <asm/io.h>
 #include <asm/armv8/mmu.h>
@@ -194,3 +195,8 @@ int print_cpuinfo(void)
 	return 0;
 }
 
+void board_cleanup_before_linux(void)
+{
+	xen_fini();
+}
+
drivers/xen/hypervisor.c +8 -0
index 58b0865e6a..178c206f5b 100644
@@ -242,3 +242,11 @@ void xen_init(void)
 	init_gnttab();
 }
 
+void xen_fini(void)
+{
+	debug("%s\n", __func__);
+
+	fini_gnttab();
+	fini_xenbus();
+	fini_events();
+}
include/xen.h +8 -0
index 686b7148b5..a952a2c84b 100644
@@ -13,4 +13,12 @@
  */
 void xen_init(void);
 
+/**
+ * xen_fini() - Board cleanup before Linux kernel start
+ *
+ * Unmap Xen memory pages the specified guest's pseudophysical
+ * address space and unbind all event channels.
+ */
+void xen_fini(void);
+
 #endif /* __XEN_H__ */
Signature · 1 line
2.17.1
#26 lore raw

PATCH v2 18/18 doc: xen: Add Xen guest ARM64 board documentation

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

---
 doc/board/index.rst              |  1 +
 doc/board/xen/index.rst          |  9 ++++
 doc/board/xen/xenguest_arm64.rst | 81 ++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+)
 create mode 100644 doc/board/xen/index.rst
 create mode 100644 doc/board/xen/xenguest_arm64.rst
doc/board/index.rst +1 -0
index 0a15899180..63935abcd7 100644
@@ -22,4 +22,5 @@ Board-specific doc
    st/index
    tbs/index
    toradex/index
+   xen/index
    xilinx/index
doc/board/xen/index.rst new file +9 -0
new file mode 100644
index 0000000000..e58fe9e351
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+XenGuestARM64
+=============
+
+.. toctree::
+   :maxdepth: 2
+
+   xenguest_arm64
doc/board/xen/xenguest_arm64.rst new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
2.17.1
#27 lore raw

v2 cover Add new board: Xen guest for ARM64

In reply to Anastasiia Lukianenko

Hi,

Quoted 4 lines · Anastasiia Lukianenko

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.

I would like to give a try at the support. Do you have a branch which contains the series and instruction how to use it?

Best regards,

Signature · 1 line
Julien Grall
#28 lore raw

v2 cover Add new board: Xen guest for ARM64

Hi Julien,

Quoted 5 lines · Julien Grall

Hi,

Quoted 2 lines · Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Quoted 8 lines
Quoted 3 lines

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

I would like to give a try at the support. Do you have a branch which
contains the series and instruction how to use it?

Thank you. I attached the branch with patch series below:
https://github.com/NastyaVicodin/u-boot/tree/pvblock_final

Steps to build:
make xenguest_arm64_defconfig
CROSS_COMPILE=aarch64-linux-gnu- make

Then copy u-boot.bin as /xt/domu/Image.

Also we have demo where you can see examples of usage of available pvblock commands:
https://www.youtube.com/watch?v=V8DGkSXQlQk

If you have any questions don't hesitate to ask me :)

Quoted 2 lines

Best regards,

Best regards,
Anastasiia