[ipxe-devel] [RFC PATCH 1/8] add Hyper-V rom type

Roman Kagan rkagan at virtuozzo.com
Mon Jun 11 17:28:16 UTC 2018


Add a new ad-hoc rom type, to be used with a Hyper-V-enabled SeaBIOS.

It mostly looks like a traditional PnP (non-PCI) option ROM, with an
extra convention of passing the 16bit interger associated with the
device to be used, in %ax when calling the entry point.  (This is
similar to PCI option ROMs where this number is the PCI b:d:f.)

In case of Hyper-V this is the main VMBus channel number used for
communicating with the device: this number is unique and stable across
VMBus resets.

This allows the regular SeaBIOS bootorder machinery to work.

Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
 src/arch/x86/Makefile.pcbios       |  4 +++
 src/arch/x86/core/vmbus_autoboot.c | 47 ++++++++++++++++++++++++++++++
 src/interface/hyperv/vmbus.c       |  1 +
 src/arch/x86/prefix/hvromprefix.S  | 29 ++++++++++++++++++
 src/arch/x86/prefix/romprefix.S    | 41 ++++++++++++++++++++++++++
 5 files changed, 122 insertions(+)
 create mode 100644 src/arch/x86/core/vmbus_autoboot.c
 create mode 100644 src/arch/x86/prefix/hvromprefix.S

diff --git a/src/arch/x86/Makefile.pcbios b/src/arch/x86/Makefile.pcbios
index c44eefc1..b98bf231 100644
--- a/src/arch/x86/Makefile.pcbios
+++ b/src/arch/x86/Makefile.pcbios
@@ -22,6 +22,7 @@ MEDIA		+= rom
 MEDIA		+= mrom
 MEDIA		+= pcirom
 MEDIA		+= isarom
+MEDIA		+= hvrom
 MEDIA		+= pxe
 MEDIA		+= kpxe
 MEDIA		+= kkpxe
@@ -39,6 +40,7 @@ PAD_rom		= $(PERL) $(PADIMG) --blksize=512 --byte=0xff
 PAD_mrom	= $(PAD_rom)
 PAD_pcirom	= $(PAD_rom)
 PAD_isarom	= $(PAD_rom)
+PAD_hvrom	= $(PAD_rom)
 PAD_dsk		= $(PERL) $(PADIMG) --blksize=512
 PAD_hd		= $(PERL) $(PADIMG) --blksize=32768
 PAD_exe		= $(PERL) $(PADIMG) --blksize=512
@@ -49,6 +51,7 @@ FINALISE_rom	= $(PERL) $(FIXROM)
 FINALISE_mrom	= $(FINALISE_rom)
 FINALISE_pcirom	= $(FINALISE_rom)
 FINALISE_isarom	= $(FINALISE_rom)
+FINALISE_hvrom	= $(FINALISE_rom)
 
 # Use $(ROMS) rather than $(DRIVERS) for "allroms", "allmroms", etc.
 #
@@ -56,6 +59,7 @@ LIST_NAME_rom := ROMS
 LIST_NAME_mrom := ROMS
 LIST_NAME_pcirom := ROMS
 LIST_NAME_isarom := ROMS
+LIST_NAME_hvrom := ROMS
 
 # Locations of isolinux files
 #
diff --git a/src/arch/x86/core/vmbus_autoboot.c b/src/arch/x86/core/vmbus_autoboot.c
new file mode 100644
index 00000000..4bb59725
--- /dev/null
+++ b/src/arch/x86/core/vmbus_autoboot.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 Virtuozzo International GmbH.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/device.h>
+#include <ipxe/init.h>
+#include <realmode.h>
+#include <usr/autoboot.h>
+
+uint16_t __bss16 ( autoboot_chnno );
+#define autoboot_chnno __use_data16 ( autoboot_chnno )
+
+/**
+ * Initialise VMBus autoboot device
+ */
+static void vmbus_autoboot_init ( void ) {
+
+	if ( autoboot_chnno )
+		set_autoboot_busloc ( BUS_TYPE_HV, autoboot_chnno );
+}
+
+/** VMBus autoboot device initialisation function */
+struct init_fn vmbus_autoboot_init_fn __init_fn ( INIT_NORMAL ) = {
+	.initialise = vmbus_autoboot_init,
+};
diff --git a/src/interface/hyperv/vmbus.c b/src/interface/hyperv/vmbus.c
index 7cd4e95a..529b2bf8 100644
--- a/src/interface/hyperv/vmbus.c
+++ b/src/interface/hyperv/vmbus.c
@@ -1194,6 +1194,7 @@ static int vmbus_probe_channels ( struct hv_hypervisor *hv,
 			snprintf ( vmdev->dev.name, sizeof ( vmdev->dev.name ),
 				   "{%s}", uuid_ntoa ( &instance ) );
 			vmdev->dev.desc.bus_type = BUS_TYPE_HV;
+			vmdev->dev.desc.location = channel;
 			INIT_LIST_HEAD ( &vmdev->dev.children );
 			list_add_tail ( &vmdev->dev.siblings,
 					&parent->children );
diff --git a/src/arch/x86/prefix/hvromprefix.S b/src/arch/x86/prefix/hvromprefix.S
new file mode 100644
index 00000000..b6d9c829
--- /dev/null
+++ b/src/arch/x86/prefix/hvromprefix.S
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 Virtuozzo International GmbH.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
+
+#define BUSTYPE "VMBS"
+#define _rom_start _hvrom_start
+#include "romprefix.S"
diff --git a/src/arch/x86/prefix/romprefix.S b/src/arch/x86/prefix/romprefix.S
index 978b07b5..fe2e5543 100644
--- a/src/arch/x86/prefix/romprefix.S
+++ b/src/arch/x86/prefix/romprefix.S
@@ -179,6 +179,13 @@ prodstr_separator:
 prodstr_pci_id:
 	.ascii	"xx:xx.x)"		/* Filled in by init code */
 .endif	/* PCIR */
+.ifeqs	BUSTYPE, "VMBS"
+prodstr_separator:
+	.byte	0
+	.ascii	"(VMBus chn "
+prodstr_chn_no:
+	.ascii	"xxxx)"			/* Filled in by init code */
+.endif	/* VMBS */
 	.byte	0
 	.size prodstr, . - prodstr
 
@@ -262,6 +269,19 @@ init:
 	movb	$( ' ' ), prodstr_separator
 .endif
 
+	/* Store VMBus channel no. , print VMBus chn no, and add
+	 * VMBus chn no to product name string, if applicable.
+	 */
+.ifeqs	BUSTYPE, "VMBS"
+	xorw	%di, %di
+	call	print_space
+	movw	%ax, init_vmbus_chn_no
+	call	print_hex_word
+	movw	$prodstr_chn_no, %di
+	call	print_hex_word
+	movb	$( ' ' ), prodstr_separator
+.endif
+
 	/* Print segment address */
 	xorw	%di, %di
 	call	print_space
@@ -658,6 +678,15 @@ init_pci_busdevfn:
 	.size	init_pci_busdevfn, . - init_pci_busdevfn
 .endif	/* PCIR */
 
+/* VMBus chn no
+ *
+ */
+.ifeqs	BUSTYPE, "VMBS"
+init_vmbus_chn_no:
+	.word	0
+	.size	init_vmbus_chn_no, . - init_vmbus_chn_no
+.endif	/* VMBS */
+
 /* Image source area
  *
  * May be either zero (indicating to use option ROM space as source),
@@ -800,6 +829,11 @@ exec:	/* Set %ds = %cs */
 	movw	init_pci_busdevfn, %ax
 .endif
 
+	/* Retrieve VMBus chn no, if applicable */
+.ifeqs	BUSTYPE, "VMBS"
+	movw	init_vmbus_chn_no, %ax
+.endif
+
 	/* Set up %ds for access to .data16 */
 	movw	%bx, %ds
 
@@ -808,6 +842,13 @@ exec:	/* Set %ds = %cs */
 #ifdef AUTOBOOT_ROM_FILTER
 	movw	%ax, autoboot_busdevfn
 #endif /* AUTOBOOT_ROM_FILTER */
+.endif
+
+	/* Store VMBus chn no, if applicable */
+.ifeqs	BUSTYPE, "VMBS"
+#ifdef AUTOBOOT_ROM_FILTER
+	movw	%ax, autoboot_chnno
+#endif /* AUTOBOOT_ROM_FILTER */
 .endif
 
 	/* Run iPXE */
-- 
2.17.1




More information about the ipxe-devel mailing list