Basic SeaBIOS support for Xen HVM
cover Basic SeaBIOS support for Xen HVM
As you may know we (the Xen project) are hoping to transition to SeaBIOS at the same time as we transition to the recently upstreamed qemu support for Xen.
The following patches add very basic support for running SeaBIOS as the BIOS for a Xen HVM (fully virtualised) guest.
These patches really do very little but they are sufficient to allow me to boot an HVM Linux guest to a prompt. SeaBIOS boots indirectly as an hvmloader payload with the first patch and directly if using the second (this second case requires a short patch series on the Xen side, see [0]).
This is presented more as a proof of concept since it's not obvious yet which approach will be best from either Xen or SeaBIOS's point of view.
I'm generally leaning towards the second option since much of the setup currently done in hvmloader appears to be more down to the limitations of ROMBIOS than any particular design decision. For example SeaBIOS is perfectly happy loading option ROMS from the appropriate BAR so that aspect of hvmloader goes away entirely, similarly with building ACPI, SMBIOS, MP tables etc. I'd be glad to hear any opinions from either side on the matter.
One problem I have with the first patch is that I'm lacking the vocabulary to describe the configuration which is currently represented by COREBOOT=n. I wanted to switch the coreboot option to a Kconfig choice (so I can add XEN as another option) so I needed a name for the other option. I went with GENERIC but I've no idea if that is accurate. Is "EMULATOR" more accurate? Suggestions welcome.
FWIW I expect (however naive it might be to make such predictions) the majority of the work to integrate SeaBIOS into Xen (other than test, test and more test with different OSes) will be to understand he differences in the various BIOS tables and figure out what is "just because", what represents real bug fixes on one side or the other, what is actually down to implementation details in Xen and what is down to differences between the old qemu-xen and upstream qemu. Having worked through all that I hope that actually finding a clean way to integrate the differences with SeaBIOS (or possibly qemu) will be comparatively trivial...
Ian.
[0]
http://lists.xensource.com/archives/html/xen-devel/2011-05/msg00770.html
PATCH 1/2 Kconfig: Add option to enable support for running as a Xen HVM guests BIOS
Do this by subsuming the existing COREBOOT boolean into a choice option of COREBOOT, XEN and GENERIC.
--- src/Kconfig | 17 ++++++++++++++++- src/shadow.c | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-)
src/Kconfig +16 -1
@@ -4,12 +4,27 @@ mainmenu "SeaBIOS Configuration" menu "General Features" + choice + prompt "Select target environment" + default GENERIC + config COREBOOT bool "Build for coreboot" - default n help Configure as a coreboot payload. + config XEN + bool "Build for Xen HVM" + help + Configure to be used by xen hvmloader, for a HVM guest. + + config GENERIC + bool "Build for generic target environment" + help + Configure to be used in a generic target environment. + + endchoice + config THREADS bool "Parallelize hardware init" default y
src/shadow.c +2 -2
@@ -102,7 +102,7 @@ static const struct pci_device_id dram_controller_make_writable_tbl[] = {void make_bios_writable (void ) { -if (CONFIG_COREBOOT ) +if (CONFIG_COREBOOT ||CONFIG_XEN )return ;dprintf (3 ,"enabling shadow ram\n" );
@@ -127,7 +127,7 @@ static const struct pci_device_id dram_controller_make_readonly_tbl[] = {void make_bios_readonly (void ) { -if (CONFIG_COREBOOT ) +if (CONFIG_COREBOOT ||CONFIG_XEN )return ;dprintf (3 ,"locking shadow ram\n" );
Signature · 1 line
1.7.2.5
PATCH 2/2 Basic support for booting directly as Xen HVM firmware.
In reply to Ian CampbellThis allows a guest to be booted using SeaBIOS directly as its firmware rather than being loaded indirectly via hvmloader. This is presented as a proof of concept since it's not obvious yet which the best approach will be from either Xen or SeaBIOS's point of view.
--- Makefile | 2 +- src/post.c | 5 ++ src/xen.c | 93 ++++++++++++++++++++++++++++++++++++++++++ src/xen.h | 26 ++++++++++++ src/xen/hvm/hvm_info_table.h | 75 +++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+), 1 deletions(-) create mode 100644 src/xen.c create mode 100644 src/xen.h create mode 100644 src/xen/hvm/hvm_info_table.h
Makefile +1 -1
@@ -20,7 +20,7 @@ SRC16=$(SRCBOTH) system.c disk.c font.c SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \ lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \ - pci_region.c + pci_region.c xen.c SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
src/post.c +5 -0
@@ -23,6 +23,7 @@#include "usb.h" // usb_setup #include "smbios.h" // smbios_init #include "paravirt.h" // qemu_cfg_port_probe +#include "xen.h" // xen_probe_hvm_info #include "ps2port.h" // ps2port_setup #include "virtio-blk.h" // virtio_blk_setup
@@ -123,6 +124,9 @@ ram_probe(void)/* reserve 256KB BIOS area at the end of 4 GB */ add_e820 (0xfffc0000 ,256 *1024 ,E820_RESERVED ); + +if (xen_reserved_size) +add_e820 (0x100000000ull -xen_reserved_size, xen_reserved_size,E820_RESERVED ); }// Don't declare any memory between 0xa0000 and 0x100000
@@ -329,6 +333,7 @@ post(void) {// Detect ram and setup internal malloc. qemu_cfg_port_probe (); +xen_probe_hvm_info ();ram_probe ();malloc_setup ();
src/xen.c new file +93 -0
93 lines not on this page · raw message
src/xen.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __XEN_H +#define __XEN_H + +#ifdef CONFIG_XEN + +#include "util.h" + +#include "xen/hvm/hvm_info_table.h" + +void xen_probe_hvm_info (void ); + +extern u32 xen_reserved_size; +extern u32 xen_nr_vcpus; + +extern struct hvm_info_table *xen_hvm_info; + +#else + +static voic xen_probe_hvm_info (void ) {} + +#define xen_reserved_size 0 +#define xen_nr_vcpus 0 + +#endif + +#endif
src/xen/hvm/hvm_info_table.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH 2/2] Basic support for booting directly as Xen HVM firmware.
Quoted 4 lines · Ian Campbell
This allows a guest to be booted using SeaBIOS directly as its firmware rather than being loaded indirectly via hvmloader. This is presented as a proof of concept since it's not obvious yet which the best approach will be from either Xen or SeaBIOS's point of view.
Thanks. See my comments below.
[...]
Quoted 3 lines
src/xen.c new file +0
-0@@ -0,0 +1,93 @@
[...]
Quoted 3 lines
src/xen.c new file +3
-0+/* Replace possibly erroneous memory-size CMOS fields with correct values. */ +static void cmos_write_memory_size (u32 low_mem_pgend,u32 high_mem_pgend) +{
[...]
src/xen.c line 53
Quoted 7 lines
src/xen.c new file +7
-0+/* All BIOSes: conventional memory (CMOS *always* reports 640kB). */ +outb_cmos ((u8)(base_mem >>0 ),0x15 ); +outb_cmos ((u8)(base_mem >>8 ),0x16 ); + +/* All BIOSes: extended memory (1kB chunks above 1MB). */ +outb_cmos ((u8)( ext_mem >>0 ),CMOS_MEM_EXTMEM_LOW ); +outb_cmos ((u8)( ext_mem >>8 ),CMOS_MEM_EXTMEM_HIGH );
[...]
These cmos variables (all of them) are just a communication mechanism between Bochs and rombios - there's no need to set them. With SeaBIOS, just set the global variables RamSize and RamSizeOver4G and make sure the appropriate add_e820 calls are made.
[...]
src/xen.h line 4
Quoted 7 lines
src/xen.h new file +4
-0@@ -0,0 +1,26 @@ +#ifndef __XEN_H +#define __XEN_H + +#ifdef CONFIG_XEN
Just a style note - I'd prefer to avoid #ifdefs in the code. Just declare the variables/code unconditionally and add an "if (!CONFIG_XEN) return;" to the top of any externally called functions. SeaBIOS uses gcc's -fwhole-program and linker scripts to weed out unneeded code and variables.
[...]
src/xen/hvm/hvm_info_table.h line 7
Quoted 10 lines
src/xen/hvm/hvm_info_table.h new file +7
-0@@ -0,0 +1,75 @@ +/****************************************************************************** +* hvm/hvm_info_table.h +* +* HVM parameter and information table, written into guest memory map. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to
[...]
That's a big copyright statement for one little struct.
-Kevin
Re: [PATCH 2/2] Basic support for booting directly as Xen HVM firmware.
Quoted 24 lines · Kevin O'Connor
Quoted 4 lines · Ian Campbell
This allows a guest to be booted using SeaBIOS directly as its firmware rather than being loaded indirectly via hvmloader. This is presented as a proof of concept since it's not obvious yet which the best approach will be from either Xen or SeaBIOS's point of view.
Thanks. See my comments below.
[...]
Quoted 3 lines
src/xen.c new file +0
-0@@ -0,0 +1,93 @@[...]
Quoted 3 lines
src/xen.c new file +3
-0+/* Replace possibly erroneous memory-size CMOS fields with correct values. */ +static void cmos_write_memory_size (u32 low_mem_pgend,u32 high_mem_pgend) +{[...]
src/xen.c line 53
Quoted 7 lines
src/xen.c new file +7
-0+/* All BIOSes: conventional memory (CMOS *always* reports 640kB). */ +outb_cmos ((u8)(base_mem >>0 ),0x15 ); +outb_cmos ((u8)(base_mem >>8 ),0x16 ); + +/* All BIOSes: extended memory (1kB chunks above 1MB). */ +outb_cmos ((u8)( ext_mem >>0 ),CMOS_MEM_EXTMEM_LOW ); +outb_cmos ((u8)( ext_mem >>8 ),CMOS_MEM_EXTMEM_HIGH );
Quoted 4 lines
[...]
These cmos variables (all of them) are just a communication mechanism between Bochs and rombios - there's no need to set them.
I wasn't sure if these CMOS addresses were well defined enough that DOS applications etc might look at them. Sounds like you are saying they are not so I'll remove this bit.
Quoted 3 lines
With
SeaBIOS, just set the global variables RamSize and RamSizeOver4G and make sure the appropriateadd_e820calls are made.
So would it be best to add a new case to ram_probe()?
Quoted 14 lines
[...]
src/xen.h line 4
Quoted 7 lines
src/xen.h new file +4
-0@@ -0,0 +1,26 @@ +#ifndef __XEN_H +#define __XEN_H + +#ifdef CONFIG_XEN Just a style note - I'd prefer to avoid #ifdefs in the code. Just declare the variables/code unconditionally and add an "if (!CONFIG_XEN) return;" to the top of any externally called functions. SeaBIOS uses gcc's -fwhole-program and linker scripts to weed out unneeded code and variables.
OK. I'll do that.
Quoted 13 lines
[...]
Quoted 10 lines
src/xen/hvm/hvm_info_table.h new file +7
-0@@ -0,0 +1,75 @@ +/****************************************************************************** +* hvm/hvm_info_table.h +* +* HVM parameter and information table, written into guest memory map. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to [...]
Quoted 1 line
That's a big copyright statement for one little struct.
This file was taken verbatim (except s/uint([0-9]*_t/u\1/g) from the public headers provided by Xen, which have this permissive license to allow them to be incorporated into other projects as necessary.
I think (although I should check first) that as long as we only ever expect changes to flow from the Xen headers into SeaBIOS it would be permissible under the terms of this license to subsume this file under SeaBIOS's GPLv3 license, if you would prefer to do it that way.
There's likely to be a smallish number of other interface headers required in this way (e.g. xenstore and pv block interfaces for pv driver support, a small number of hypercall interfaces etc). Is the general approach of importing these headers as required ok or shall I look into a mechanism for supplying SeaBIOS with an out-of-tree set of headers to use?
Ian.
Quoted 6 lines · Ian Campbell
As you may know we (the Xen project) are hoping to transition to SeaBIOS at the same time as we transition to the recently upstreamed qemu support for Xen.
The following patches add very basic support for running SeaBIOS as the BIOS for a Xen HVM (fully virtualised) guest.
Just so I understand, is this needed for Xen pre-qemu integration, post-qemu integration, or both?
Quoted 5 lines
These patches really do very little but they are sufficient to allow me to boot an HVM Linux guest to a prompt. SeaBIOS boots indirectly as an hvmloader payload with the first patch and directly if using the second (this second case requires a short patch series on the Xen side, see [0]).
So, patch 1 in this thread is needed for indirect, and patch 1+2 in this thread is needed for direct?
Quoted 10 lines
This is presented more as a proof of concept since it's not obvious yet which approach will be best from either Xen or SeaBIOS's point of view.
I'm generally leaning towards the second option since much of the setup currently done in hvmloader appears to be more down to the limitations of ROMBIOS than any particular design decision. For example SeaBIOS is perfectly happy loading option ROMS from the appropriate BAR so that aspect of hvmloader goes away entirely, similarly with building ACPI, SMBIOS, MP tables etc. I'd be glad to hear any opinions from either side on the matter.
I'm okay with the second option. This is reminiscent of the seabios+coreboot integration - there used to be an assembler loader (called ADLO) that would do all sorts of weird things to get rombios to load. One of my goals with SeaBIOS was to make that unnecessary.
Quoted 6 lines
One problem I have with the first patch is that I'm lacking the vocabulary to describe the configuration which is currently represented by COREBOOT=n. I wanted to switch the coreboot option to a
Kconfigchoice (so I can add XEN as another option) so I needed a name for the other option. I went with GENERIC but I've no idea if that is accurate. Is "EMULATOR" more accurate? Suggestions welcome.
The preferred approach would be to autodetect Xen at runtime and use that to control the code flow. A CONFIG_XEN option would then only be used to reduce the overall code size for those that do not need Xen support and want a smaller binary.
Admittedly, CONFIG_COREBOOT doesn't do this today, but that's only because I haven't gotten around to fixing it. (Ideally, there'd be something like a CONFIG_EMULATORS (for qemu/kvm/bochs) and a CONFIG_COREBOOT, and everything would be auto-detected if both were enabled at the same time.
Quoted 10 lines
FWIW I expect (however naive it might be to make such predictions) the majority of the work to integrate SeaBIOS into Xen (other than test, test and more test with different OSes) will be to understand he differences in the various BIOS tables and figure out what is "just because", what represents real bug fixes on one side or the other, what is actually down to implementation details in Xen and what is down to differences between the old qemu-xen and upstream qemu. Having worked through all that I hope that actually finding a clean way to integrate the differences with SeaBIOS (or possibly qemu) will be comparatively trivial...
Sounds good.
-Kevin
Quoted 10 lines · Kevin O'Connor
Quoted 6 lines · Ian Campbell
As you may know we (the Xen project) are hoping to transition to SeaBIOS at the same time as we transition to the recently upstreamed qemu support for Xen.
The following patches add very basic support for running SeaBIOS as the BIOS for a Xen HVM (fully virtualised) guest.
Just so I understand, is this needed for Xen pre-qemu integration, post-qemu integration, or both?
We'd like to have all the pieces in place for the Xen 4.2 release, which isn't really planned out yet, but I think the late end of this year would be a reasonable bet. I think we can be flexible around the order integration happens in, we simply won't flip the default until everything is in place.
Is that what you meant by post/pre-qemu integration?
Quoted 8 lines
These patches really do very little but they are sufficient to allow me
Quoted 4 lines
to boot an HVM Linux guest to a prompt. SeaBIOS boots indirectly as an hvmloader payload with the first patch and directly if using the second (this second case requires a short patch series on the Xen side, see [0]).
So, patch 1 in this thread is needed for indirect, and patch 1+2 in this thread is needed for direct?
Correct.
Quoted 23 lines
Quoted 10 lines
This is presented more as a proof of concept since it's not obvious yet which approach will be best from either Xen or SeaBIOS's point of view.
I'm generally leaning towards the second option since much of the setup currently done in hvmloader appears to be more down to the limitations of ROMBIOS than any particular design decision. For example SeaBIOS is perfectly happy loading option ROMS from the appropriate BAR so that aspect of hvmloader goes away entirely, similarly with building ACPI, SMBIOS, MP tables etc. I'd be glad to hear any opinions from either side on the matter.
I'm okay with the second option. This is reminiscent of the seabios+coreboot integration - there used to be an assembler loader (called ADLO) that would do all sorts of weird things to get rombios to load. One of my goals with SeaBIOS was to make that unnecessary.
Quoted 6 lines
One problem I have with the first patch is that I'm lacking the vocabulary to describe the configuration which is currently represented by COREBOOT=n. I wanted to switch the coreboot option to a
Kconfigchoice (so I can add XEN as another option) so I needed a name for the other option. I went with GENERIC but I've no idea if that is accurate. Is "EMULATOR" more accurate? Suggestions welcome.
Quoted 4 lines
The preferred approach would be to autodetect Xen at runtime and use that to control the code flow. A
CONFIG_XENoption would then only be used to reduce the overall code size for those that do not need Xen support and want a smaller binary.
Sure. I'll change things to do it that way then.
As well as CONFIG_XEN should I be adding a xen_present variable which is set dynamically and used as appropriate? If so then is a #ifdef to define it to 0 in the !CONFIG_XEN case (to allow the dead code to be eliminated) necessary? Or is gcc's whole program optimisation smart enough to spot when a global variable is never set != 0 and eliminate code as necessary?
Quoted 20 lines
Admittedly,
CONFIG_COREBOOTdoesn't do this today, but that's only because I haven't gotten around to fixing it. (Ideally, there'd be something like aCONFIG_EMULATORS(for qemu/kvm/bochs) and aCONFIG_COREBOOT, and everything would be auto-detected if both were enabled at the same time.Quoted 10 lines
FWIW I expect (however naive it might be to make such predictions) the majority of the work to integrate SeaBIOS into Xen (other than test, test and more test with different OSes) will be to understand he differences in the various BIOS tables and figure out what is "just because", what represents real bug fixes on one side or the other, what is actually down to implementation details in Xen and what is down to differences between the old qemu-xen and upstream qemu. Having worked through all that I hope that actually finding a clean way to integrate the differences with SeaBIOS (or possibly qemu) will be comparatively trivial...
Sounds good.
-Kevin
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Kevin O'Connor
Quoted 3 lines · Ian Campbell
As you may know we (the Xen project) are hoping to transition to SeaBIOS at the same time as we transition to the recently upstreamed qemu support for Xen.
[...]
Quoted 10 lines
Quoted 2 lines
Just so I understand, is this needed for Xen pre-qemu integration, post-qemu integration, or both?
We'd like to have all the pieces in place for the Xen 4.2 release, which isn't really planned out yet, but I think the late end of this year would be a reasonable bet. I think we can be flexible around the order integration happens in, we simply won't flip the default until everything is in place.
Is that what you meant by post/pre-qemu integration?
I was referring to your statement above about "transition to SeaBIOS at the same time as we transition to the recently upstreamed qemu support for Xen". I wasn't sure if your patches are tied to that "upstreamed qemu" work or not.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
One problem I have with the first patch is that I'm lacking the vocabulary to describe the configuration which is currently represented by COREBOOT=n. I wanted to switch the coreboot option to a
Kconfigchoice (so I can add XEN as another option) so I needed a name for the other option. I went with GENERIC but I've no idea if that is accurate. Is "EMULATOR" more accurate? Suggestions welcome.The preferred approach would be to autodetect Xen at runtime and use that to control the code flow. A
CONFIG_XENoption would then only be used to reduce the overall code size for those that do not need Xen support and want a smaller binary.
Quoted 6 lines
Sure. I'll change things to do it that way then.
As well as
CONFIG_XENshould I be adding axen_presentvariable which is set dynamically and used as appropriate? If so then is a #ifdef to define it to 0 in the !CONFIG_XEN case (to allow the dead code to be eliminated) necessary?
Thanks.
I'd suggest something like a "int usingXen(void)" inline which reads "xen_present". The first couple of lines of usingXen() could do a "if (!CONFIG_XEN) return 0". Though - if the code is as simple as the patches you've already sent - then you can leave it on permanently for emulators (ie, do "if (CONFIG_COREBOOT)") - I'm not worried about a few extra bytes for Xen in the emulator case.
Quoted 3 lines
Or is gcc's whole program optimisation smart
enough to spot when a global variable is never set != 0 and eliminate code as necessary?
I don't think it's that smart.
-Kevin
Quoted 8 lines · Kevin O'Connor
Quoted 6 lines · Ian Campbell
Sure. I'll change things to do it that way then.
As well as
CONFIG_XENshould I be adding axen_presentvariable which is set dynamically and used as appropriate? If so then is a #ifdef to define it to 0 in the !CONFIG_XEN case (to allow the dead code to be eliminated) necessary?
Quoted 5 lines
Thanks.
I'd suggest something like a "int usingXen(void)" inline which reads "
xen_present". The first couple of lines ofusingXen()could do a "if (!CONFIG_XEN) return 0".
I've done this, although rather than check a xen_present variable I just check whether or not the xen_hvm_info ptr is NULL. I also needed to move the call to xen_probe_hvm_info sooner.
Quoted 4 lines
Though - if the code is as simple as the
patches you've already sent - then you can leave it on permanently for emulators (ie, do "if (CONFIG_COREBOOT)") - I'm not worried about a few extra bytes for Xen in the emulator case.
I think once we get a xenbus client and some PV drivers etc it will be an amount worth saving in the !Xen case.
The following implements all your feedback (I hope). I have squashed it down into a single commit which supports direct boot.
Ian.
Quoted 1 line
From
25fdf95c608c73a00a72f0aa1bc72cbd9c03d4ceMon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Tue, 17 May 2011 16:43:34 +0100
Subject: [PATCH] Kconfig: Add basic support for booting directly as Xen HVM firmware
This allows a guest to be booted using SeaBIOS directly as its firmware rather than being loaded indirectly via hvmloader.
--- Makefile | 2 +- src/Kconfig | 6 +++ src/post.c | 19 ++++++++++ src/shadow.c | 5 ++- src/xen.c | 57 ++++++++++++++++++++++++++++++++ src/xen.h | 18 ++++++++++ src/xen/hvm/hvm_info_table.h | 75 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 src/xen.c create mode 100644 src/xen.h create mode 100644 src/xen/hvm/hvm_info_table.h
Makefile +1 -1
@@ -20,7 +20,7 @@ SRC16=$(SRCBOTH) system.c disk.c font.c SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \ lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \ - pci_region.c + pci_region.c xen.c SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
src/Kconfig +6 -0
@@ -10,6 +10,12 @@ menu "General Features" help Configure as a coreboot payload. + config XEN + bool "Build for Xen HVM" + default n + help + Configure to be used by xen hvmloader, for a HVM guest. + config THREADS bool "Parallelize hardware init" default y
src/post.c +19 -0
@@ -23,6 +23,7 @@#include "usb.h" // usb_setup #include "smbios.h" // smbios_init #include "paravirt.h" // qemu_cfg_port_probe +#include "xen.h" // xen_probe_hvm_info #include "ps2port.h" // ps2port_setup #include "virtio-blk.h" // virtio_blk_setup
@@ -101,6 +102,22 @@ ram_probe(void)dprintf (3 ,"Find memory size\n" );if (CONFIG_COREBOOT ) {coreboot_setup (); + }else if (usingXen ()) { + RamSize = xen_hvm_info->low_mem_pgend <<12 ; + +add_e820 (0 , RamSize,E820_RAM ); +if (xen_hvm_info->high_mem_pgend) { + RamSizeOver4G = ((u64 )xen_hvm_info->high_mem_pgend -0x100000ull ) <<12ull ; +add_e820 (0x100000000ull , RamSizeOver4G,E820_RAM ); + }else { + RamSizeOver4G =0 ; + } + +if (xen_hvm_info->reserved_mem_pgstart) { +u32 reserved_base = xen_hvm_info->reserved_mem_pgstart<<12 ; +u64 reserved_size =0x100000000ull - reserved_base; +add_e820 (reserved_base, reserved_size,E820_RESERVED ); + } }else {// On emulators, get memory size from nvram. u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)
@@ -380,6 +397,8 @@ _start(void)// This is a soft reboot - invoke a hard reboot. tryReboot (); +xen_probe_hvm_info (); +// Allow writes to modify bios area (0xf0000) make_bios_writable (); HaveRunPost =1 ;
src/shadow.c +3 -2
@@ -10,6 +10,7 @@#include "config.h" // CONFIG_* #include "pci_ids.h" // PCI_VENDOR_ID_INTEL #include "dev-i440fx.h" +#include "xen.h" // usingXen // On the emulators, the bios at 0xf0000 is also at 0xffff0000 #define BIOS_SRC_OFFSET 0xfff00000
@@ -102,7 +103,7 @@ static const struct pci_device_id dram_controller_make_writable_tbl[] = {void make_bios_writable (void ) { -if (CONFIG_COREBOOT ) +if (CONFIG_COREBOOT ||usingXen ())return ;dprintf (3 ,"enabling shadow ram\n" );
@@ -127,7 +128,7 @@ static const struct pci_device_id dram_controller_make_readonly_tbl[] = {void make_bios_readonly (void ) { -if (CONFIG_COREBOOT ) +if (CONFIG_COREBOOT ||usingXen ())return ;dprintf (3 ,"locking shadow ram\n" );
src/xen.c new file +57 -0
57 lines not on this page · raw message
src/xen.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef __XEN_H +#define __XEN_H + +#include "util.h" + +#include "xen/hvm/hvm_info_table.h" + +void xen_probe_hvm_info (void ); + +extern struct hvm_info_table *xen_hvm_info; + +static inline int usingXen (void ) { +if (!CONFIG_XEN ) +return 0 ; +return (xen_hvm_info !=NULL ); +} + +#endif
src/xen/hvm/hvm_info_table.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Quoted 2 lines · Ian Campbell
The following implements all your feedback (I hope). I have squashed it down into a single commit which supports direct boot.
I've gotten all the PCI setup and ACPI stuff etc etc working but, frankly, the patch to SeaBIOS is getting to be pretty enormous and intrusive.
The more I look at it the more I am coming to the conclusion that it would be better to have hvmloader setup all this platform level stuff and pass details onto SeaBIOS as necessary, following the model used with coreboot->SeaBIOS rather than the emulator's way of doing things. hvmloader basically already fulfils the same role for Xen HVM guests as coreboot does for physical hardware so I think that makes a certain amount of sense.
I'm going to try reworking things in that direction and see how they look.
Cheers,
Ian.
Quoted 3 lines · Ian Campbell
Quoted 2 lines · Ian Campbell
The following implements all your feedback (I hope). I have squashed it down into a single commit which supports direct boot.
BTW, in general, the above patch looks okay to me.
Quoted 3 lines
I've gotten all the PCI setup and ACPI stuff etc etc working but, frankly, the patch to SeaBIOS is getting to be pretty enormous and intrusive.
Is that due to incompleteness / innacuracies in the current SeaBIOS code, or due to requirements specific to Xen?
If you have test code, I'd be curious to see a patch on the mailing list - it may help later to understand the use cases for SeaBIOS.
Quoted 7 lines
The more I look at it the more I am coming to the conclusion that it would be better to have hvmloader setup all this platform level stuff and pass details onto SeaBIOS as necessary, following the model used with
coreboot->SeaBIOSrather than the emulator's way of doing things. hvmloader basically already fulfils the same role for Xen HVM guests as coreboot does for physical hardware so I think that makes a certain amount of sense.
I'm okay with that approach as well - there are pros and cons to each method. (At various points, it's been discussed whether SeaBIOS should generate ACPI tables for coreboot, and it has also been discussed if QEmu should just pass in ACPI tables to SeaBIOS..)
-Kevin
Quoted 5 lines · Kevin O'Connor
Quoted 3 lines · Ian Campbell
Quoted 2 lines · Ian Campbell
The following implements all your feedback (I hope). I have squashed it down into a single commit which supports direct boot.
Quoted 8 lines
BTW, in general, the above patch looks okay to me.
Quoted 3 lines
I've gotten all the PCI setup and ACPI stuff etc etc working but, frankly, the patch to SeaBIOS is getting to be pretty enormous and intrusive.
Is that due to incompleteness / innacuracies in the current SeaBIOS code, or due to requirements specific to Xen?
A mixture of both but mainly requirements specific to Xen, I think.
PCI setup is one of the main things, the interrupt routing in particular is different which has knock on effects on chipset setup (e.g. legacy PCI ISA IRQ routing) and the BIOS tables (e.g. ACPI _PRT entries). This strikes me as being highly "mainboard" specific, IOW the stuff I would expect to find in coreboot rather than SeaBIOS.
Another difference is that the existing hvmloader tables are ACPI 2.0 while SeaBIOS only creates 1.0 tables, I'm not sure that strictly speaking counts as a incompleteness in SeaBIOS since it's not obvious that Xen actually needs/uses any of the functionality of 2.0. Also it might be something SeaBIOS would like to grow in any case.
Quoted 2 lines
If you have test code, I'd be curious to see a patch on the mailing list - it may help later to understand the use cases for SeaBIOS.
It's in a pretty embarrassing state at the moment, but OK. Please note that I was nowhere near suggesting this patch was in any way suitable to be applied or even near to becoming an RFC!
I initially took a rather gung-ho approach in the interests of matching as closely as possible how hvmloader+rombios sets things up, rather than evaluating the actual useful meaning of the differences. Having made things match my intention was to go back and evaluate each change and attempt to get rid of it unless there was an extremely pressing reason not to, but I didn't reach that phase yet. So I think this is an upper bound (possibly by a large-ish order of magnitude) on the level of change.
I hardcoded a few things here and there too (e.g. numbers of CPUs), in the interests of getting something working before going back and cleaning it up.
The diff (vs. the patches I already posted) is attached, it's diffstat is:
src/Kconfig | 34 + src/acpi-dsdt.dsl | 9482 +++++++++++++++++++++++++++++++++++++++++++++----- src/acpi-dsdt.hex | 9331 +++++++++++++++++++++++++++++++++++++++++++------- src/acpi.c | 152 +- src/acpi.h | 93 + src/config.h | 6 +- src/dev-i440fx.c | 16 +- src/pciinit.c | 6 +- src/pmm.c | 5 +- src/post.c | 5 + src/util.h | 5 + src/xen.c | 128 +- src/xen.h | 3 + src/xen/hvm/hvm_op.h | 245 ++ src/xen/hvm/params.h | 145 + src/xen/version.h | 94 + src/xen/xen.h | 739 ++++ src/xen_hypercall.h | 187 + 18 files changed, 18591 insertions(+), 2085 deletions(-)
The DSDT change rather dominates, dropping it gives a more sensible:
11 files changed, 414 insertions(+), 39 deletions(-)
I just ripped the DSDT out of hvmloader, I'm sure with analysis the changes could be reduced to something much more sane, although I have a feeling it would still end up as a subtly different variant of the table (_PRT and such).
Quoted 9 lines
Quoted 7 lines
The more I look at it the more I am coming to the conclusion that it would be better to have hvmloader setup all this platform level stuff and pass details onto SeaBIOS as necessary, following the model used with
coreboot->SeaBIOSrather than the emulator's way of doing things. hvmloader basically already fulfils the same role for Xen HVM guests as coreboot does for physical hardware so I think that makes a certain amount of sense.I'm okay with that approach as well
The SeaBIOS patch for this approach seems likely to be an awful lot smaller. Basically most "if (COREBOOT)" become effectively "if (COREBOOT||XEN)" + a Xen equivalent to coreboot_copy_biostable and coreboot_fill_map.
Quoted 1 line
- there are pros and cons to each method.
Apart from avoiding bloating SeaBIOS with a load of Xen specific stuff (which would be duplicated in hvmloader and also needed by the tianocore firmware variant etc) I think the big thing pulling me towards this approach is the idea that the BIOS tables describe the hardware, and since the "hardware" in this case is defined by Xen the tables ought to be supplied by Xen. I don't know if that's a distinction which people who really know about things at this level actually make though.
Quoted 2 lines
(At various points, it's been discussed whether SeaBIOS
should generate ACPI tables for coreboot,
Would that involve pulling a bunch of mainboard specific stuff from coreboot into SeaBIOS?
Quoted 2 lines
and it has also been
discussed if QEmu should just pass in ACPI tables to SeaBIOS..)
That sounds plausible to me, at least based on my current understanding of what I think is going on ;-)
Ian.
_______________________________________________
SeaBIOS mailing list
[email protected]
http://www.seabios.org/mailman/listinfo/seabios
Hi,
Quoted 5 lines
PCI setup is one of the main things, the interrupt routing in particular is different which has knock on effects on chipset setup (e.g. legacy PCI ISA IRQ routing) and the BIOS tables (e.g. ACPI
_PRTentries). This strikes me as being highly "mainboard" specific, IOW the stuff I would expect to find in coreboot rather than SeaBIOS.
There is q35 emulation support in for qemu in the pipeline, which has simliar requirements, especially it needs a different dsdt table too. So a solution is needed here anyway. One option is to just pass the table from qemu, another one is to have multiple tables compiled in and have seabios pick one at runtime depending on the hardware it detects.
Quoted 5 lines
Another difference is that the existing hvmloader tables are ACPI 2.0 while SeaBIOS only creates 1.0 tables, I'm not sure that strictly speaking counts as a incompleteness in SeaBIOS since it's not obvious that Xen actually needs/uses any of the functionality of 2.0. Also it might be something SeaBIOS would like to grow in any case.
Indeed, I don't see that as a xen specific thing.
cheers,
Gerd
Quoted 5 lines · Ian Campbell
Quoted 2 lines · Kevin O'Connor
If you have test code, I'd be curious to see a patch on the mailing list - it may help later to understand the use cases for SeaBIOS.
The diff (vs. the patches I already posted) is attached, it's diffstat is:
Thanks. I understand it's just test code.
Quoted 5 lines
Quoted 2 lines
(At various points, it's been discussed whether SeaBIOS
should generate ACPI tables for coreboot,Would that involve pulling a bunch of mainboard specific stuff from coreboot into SeaBIOS?
The idea - when it was last raised - was to provide raw info in a coreboot specific manor (via the "coreboot tables"), and then have SeaBIOS populate ACPI/SMBIOS/MPTable/etc. from that info. It was never pursued.
-Kevin
Quoted 8 lines · Kevin O'Connor
Quoted 2 lines · Ian Campbell
Would that involve pulling a bunch of mainboard specific stuff from coreboot into SeaBIOS?
The idea - when it was last raised - was to provide raw info in a coreboot specific manor (via the "coreboot tables"), and then have SeaBIOS populate ACPI/SMBIOS/MPTable/etc. from that info. It was never pursued.
Speaking of coreboot tables... I also need to pass some start of day info into seabios (ACPI tables, e820 etc). Currently I just used a little ad-hoc data structure at a known physical address but I wonder if perhaps I should/could reuse the coreboot table datastructures? They are existing and well defined and I suppose they are pretty static, but I don't want to add any additional compatibility burden if you guys would rather avoid it.
FWIW my current patch for hvmloader->seabios (rather than direct SeaBIOS boot) is attached. Things I'd like to address before submitting it properly are putting the hypercall pages somewhere saner (and reserved etc) and using coreboot tables if desired (or at the very least do something better than commenting out the "static"...). I also attached the patches for hvmloader.
Ian.
Quoted 1 line
From
c2f5909e835903f7678f77b0a1626b9a974ef3aaMon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Thu, 26 May 2011 16:10:25 +0100
Subject: [PATCH] Add basic support for use as Xen HVM BIOS.
SeaBIOS is called by Xen's hvmloader which does the basic platform setup and provides various BIOS tables. Therefore avoid re-doing that setup and copy out the tables as necessary.
Establish the basic infrastructure to make hypercalls.
XXX TODO put hypercall page at a safe location.
XXX TODO consider re-using coreboot table datastructure instead of ad-hoc.
--- Makefile | 2 +- src/Kconfig | 6 ++ src/coreboot.c | 4 +- src/mtrr.c | 3 +- src/pciinit.c | 5 +- src/post.c | 11 +++ src/shadow.c | 5 +- src/xen.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/xen.h | 56 ++++++++++++++ 9 files changed, 315 insertions(+), 8 deletions(-) create mode 100644 src/xen.c create mode 100644 src/xen.h
Makefile +1 -1
@@ -20,7 +20,7 @@ SRC16=$(SRCBOTH) system.c disk.c font.c SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \ lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \ - pci_region.c + pci_region.c xen.c SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
src/Kconfig +6 -0
@@ -10,6 +10,12 @@ menu "General Features" help Configure as a coreboot payload. + config XEN + bool "Build for Xen HVM" + default n + help + Configure to be used by xen hvmloader, for a HVM guest. + config THREADS bool "Parallelize hardware init" default y
src/coreboot.c +2 -2
@@ -216,7 +216,7 @@ copy_pir(void *pos) PirOffset = (u32 )newpos -BUILD_BIOS_ADDR ; } -static void +/*static*/ void copy_mptable (void *pos) {struct mptable_floating_s *p = pos;
@@ -240,7 +240,7 @@ copy_mptable(void *pos)memcpy ((void *)newpos + length, (void *)p->physaddr, mpclength); } -static void +/*static*/ void copy_acpi_rsdp (void *pos) {if (RsdpAddr)
src/mtrr.c +2 -1
@@ -6,6 +6,7 @@#include "util.h" // dprintf #include "biosvar.h" // GET_EBDA +#include "xen.h" // usingXen #define MSR_MTRRcap 0x000000fe#define MSR_MTRRfix64K_00000 0x00000250
@@ -32,7 +33,7 @@void mtrr_setup (void ) { -if (!CONFIG_MTRR_INIT ||CONFIG_COREBOOT ) +if (!CONFIG_MTRR_INIT ||CONFIG_COREBOOT ||usingXen ())return ;u32 eax, ebx, ecx, edx, cpuid_features;
src/pciinit.c +3 -2
@@ -11,6 +11,7 @@#include "pci_ids.h" // PCI_VENDOR_ID_INTEL #include "pci_regs.h" // PCI_COMMAND #include "dev-i440fx.h" +#include "xen.h" // usingXen #define PCI_ROM_SLOT 6#define PCI_NUM_REGIONS 7
@@ -396,8 +397,8 @@ pci_bios_init_bus(void)void pci_setup (void ) { -if (CONFIG_COREBOOT ) -// Already done by coreboot. +if (CONFIG_COREBOOT ||usingXen ()) +// Already done by coreboot or Xen. return ;dprintf (3 ,"pci setup\n" );
src/post.c +11 -0
@@ -23,6 +23,7 @@#include "usb.h" // usb_setup #include "smbios.h" // smbios_init #include "paravirt.h" // qemu_cfg_port_probe +#include "xen.h" // xen_probe_hvm_info #include "ps2port.h" // ps2port_setup #include "virtio-blk.h" // virtio_blk_setup
@@ -101,6 +102,8 @@ ram_probe(void)dprintf (3 ,"Find memory size\n" );if (CONFIG_COREBOOT ) {coreboot_setup (); + }else if (usingXen ()) { +xen_setup (); }else {// On emulators, get memory size from nvram. u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)
@@ -158,6 +161,10 @@ init_bios_tables(void)coreboot_copy_biostable ();return ; } +if (usingXen ()) { +xen_copy_biostable (); +return ; + }create_pirtable ();
@@ -329,6 +336,7 @@ post(void) {// Detect ram and setup internal malloc. qemu_cfg_port_probe (); +xen_probe_hvm_info ();ram_probe ();malloc_setup ();
@@ -380,6 +388,9 @@ _start(void)// This is a soft reboot - invoke a hard reboot. tryReboot (); +// Check if we are running under Xen. +xen_probe (); +// Allow writes to modify bios area (0xf0000) make_bios_writable (); HaveRunPost =1 ;
src/shadow.c +3 -2
@@ -10,6 +10,7 @@#include "config.h" // CONFIG_* #include "pci_ids.h" // PCI_VENDOR_ID_INTEL #include "dev-i440fx.h" +#include "xen.h" // usingXen // On the emulators, the bios at 0xf0000 is also at 0xffff0000 #define BIOS_SRC_OFFSET 0xfff00000
@@ -102,7 +103,7 @@ static const struct pci_device_id dram_controller_make_writable_tbl[] = {void make_bios_writable (void ) { -if (CONFIG_COREBOOT ) +if (CONFIG_COREBOOT ||usingXen ())return ;dprintf (3 ,"enabling shadow ram\n" );
@@ -127,7 +128,7 @@ static const struct pci_device_id dram_controller_make_readonly_tbl[] = {void make_bios_readonly (void ) { -if (CONFIG_COREBOOT ) +if (CONFIG_COREBOOT ||usingXen ())return ;dprintf (3 ,"locking shadow ram\n" );
src/xen.c new file +231 -0
231 lines not on this page · raw message
src/xen.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.2.5
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1306422697 -3600
# Node ID 9b32ecfdffae7b92f7e4d7698416f05bc5778515 # Parent 71a3a138138bb1499a4e11eaea35b66e5cb1924f
hvmloader: allow per-BIOS decision on loading option ROMS
SeaBIOS has functionality to load ROMs from the PCI device directly, it makes sense to use this when it is available.
tools/firmware/hvmloader/config-seabios.h +0 -3
@@ -1,9 +1,6 @@#ifndef __HVMLOADER_CONFIG_SEABIOS_H__#define __HVMLOADER_CONFIG_SEABIOS_H__ -#define OPTIONROM_PHYSICAL_ADDRESS 0x000C8000 -#define OPTIONROM_PHYSICAL_END 0x000E0000 -#define SEABIOS_PHYSICAL_ADDRESS 0x000E0000#endif /* __HVMLOADER_CONFIG_SEABIOS_H__ */
tools/firmware/hvmloader/config.h +4 -1
@@ -19,7 +19,10 @@ struct bios_config {/* SMBIOS */ unsigned int smbios_start, smbios_end; -/* Option ROMs */ +/* ROMS */ +int load_vgabios; +int load_etherboot; +int load_option_roms;unsigned int optionrom_start, optionrom_end;/* ACPI tables */
tools/firmware/hvmloader/hvmloader.c +36 -27
75 lines not on this page · raw message
tools/firmware/hvmloader/rombios.c +4 -0
@@ -372,6 +372,10 @@ struct bios_config rombios_config = { .smbios_start = SMBIOS_PHYSICAL_ADDRESS, .smbios_end = SMBIOS_PHYSICAL_END, + .load_vgabios = 1, + .load_etherboot = 1, + .load_option_roms = 1, + .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS, .optionrom_end = OPTIONROM_PHYSICAL_END,
tools/firmware/hvmloader/seabios.c +6 -2
@@ -46,8 +46,12 @@ struct bios_config seabios_config = { .smbios_start = 0, .smbios_end = 0, - .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS, - .optionrom_end = OPTIONROM_PHYSICAL_END, + .load_vgabios = 0, + .load_etherboot = 0, + .load_option_roms = 0, + + .optionrom_start = 0, + .optionrom_end = 0, .acpi_start = 0,
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306422697 -3600
# Node ID ff9f86ef7be234c46afc1072f5191428bf66a9cd # Parent 67d262e901a8fea9ac38fb106ccd7e2573e9506e
hvmloader: further support for SeaBIOS
Build the various BIOS tables and arrange for them to be passed to SeaBIOS. We define an ad-hoc structure at a known physical address for this purpose.
Also add a simple "scratch allocator" returning memory which is passed to SeaBIOS but can be reused once the contents is consumed. SeaBIOS copies various supplied tables to its own buffers during init.
XXX TODO refactor pci_setup and apic_setup into common location. XXX TODO consider re-using coreboot table datastructure instead of ad-hoc.
tools/firmware/hvmloader/config-seabios.h +2 -0
@@ -1,6 +1,8 @@#ifndef __HVMLOADER_CONFIG_SEABIOS_H__#define __HVMLOADER_CONFIG_SEABIOS_H__ +#define BIOS_INFO_PHYSICAL_ADDRESS 0x00001000 +#define SEABIOS_PHYSICAL_ADDRESS 0x000E0000#endif /* __HVMLOADER_CONFIG_SEABIOS_H__ */
tools/firmware/hvmloader/config.h +3 -4
@@ -25,9 +25,6 @@ struct bios_config {int load_option_roms;unsigned int optionrom_start, optionrom_end; -/* ACPI tables */ -unsigned int acpi_start; -void (*apic_setup)(void );void (*pci_setup)(void );void (*smp_setup)(void );
@@ -38,7 +35,7 @@ struct bios_config {void (*vm86_setup)(void );void (*e820_setup)(void ); -void (*acpi_build_tables)(unsigned int physical); +void (*acpi_build_tables)(void );void (*create_mp_tables)(void ); };
@@ -73,6 +70,8 @@ extern unsigned long pci_mem_start, pci_#define VGABIOS_PHYSICAL_ADDRESS 0x000C0000#define HVMLOADER_PHYSICAL_ADDRESS 0x00100000 +extern unsigned long scratch_start; +#endif /* __HVMLOADER_CONFIG_H__ */ /*
tools/firmware/hvmloader/hvmloader.c +7 -3
@@ -112,6 +112,8 @@ asm (unsigned long pci_mem_start =PCI_MEM_START ;unsigned long pci_mem_end =PCI_MEM_END ; +unsigned long scratch_start =SCRATCH_PHYSICAL_ADDRESS ; +enum virtual_vga virtual_vga = VGA_none;static void init_hypercalls (void )
@@ -401,8 +403,7 @@ int main(void)if (bios->smbios_start) {printf ("Writing SMBIOS tables ...\n" ); - smbios_sz =hvm_write_smbios_tables (SCRATCH_PHYSICAL_ADDRESS , - bios->smbios_start, + smbios_sz =hvm_write_smbios_tables (bios->smbios_start, bios->smbios_end); }
@@ -470,7 +471,7 @@ int main(void)if ( bios->acpi_build_tables ) {printf ("Loading ACPI ...\n" ); - bios->acpi_build_tables (bios->acpi_start); + bios->acpi_build_tables (); }hypercall_hvm_op (HVMOP_set_param, &p); }
@@ -481,6 +482,9 @@ int main(void)cmos_write_memory_size ();printf ("BIOS map:\n" ); +if (SCRATCH_PHYSICAL_ADDRESS != scratch_start ) +printf (" %05x-%05lx: Scratch space\n" , +SCRATCH_PHYSICAL_ADDRESS , scratch_start);if ( vgabios_sz ) printf(" %05x-%05x: VGA BIOS\n", VGABIOS_PHYSICAL_ADDRESS,
tools/firmware/hvmloader/mp_tables.c +7 -3
@@ -260,11 +260,12 @@ static void fill_mpfps(struct mp_floatin }/* create_mp_tables - creates MP tables for the guest based upon config data */ -void create_mp_tables (void *mp_table_base) +unsigned long create_mp_tables (void *mp_table_base) {char *p;int vcpu_nr, i, length;struct mp_io_intr_entry *mpiie; +struct mp_floating_pointer_struct *mpfps; vcpu_nr = hvm_info->nr_vcpus;
@@ -313,9 +314,12 @@ void create_mp_tables(void *mp_table_bas/* find the next 16-byte boundary to place the mp floating pointer */ while ( (unsigned long )p &0xF ) p++; + mpfps = (struct mp_floating_pointer_struct *)p; + p +=sizeof (struct mp_floating_pointer_struct ); -fill_mpfps ((struct mp_floating_pointer_struct *)p, - (uint32_t )mp_table_base); +fill_mpfps (mpfps, (uint32_t )mp_table_base);fill_mp_config_table ((struct mp_config_table *)mp_table_base, length); + +return (unsigned long )mpfps; }
tools/firmware/hvmloader/rombios.c +11 -6
@@ -84,7 +84,8 @@ static void rombios_setup_bios_info(uint bios_info->bios32_entry = bioshigh; } -static void rombios_apic_setup (void ) +/*XXX this should be common*/ +/*static*/ void rombios_apic_setup (void ) {/* Set the IOAPIC ID to the static value used in the MP/ACPI tables. */ ioapic_write (0x00 ,IOAPIC_ID );
@@ -99,7 +100,8 @@ static void rombios_apic_setup(void)ioapic_write (0x11 ,SET_APIC_ID (LAPIC_ID (0 ))); } -static void rombios_pci_setup (void ) +/*XXX this should be common*/ +/*static*/ void rombios_pci_setup (void ) {uint32_t base, devfn, bar_reg, bar_data, bar_sz, cmd, mmio_total =0 ;uint16_t class, vendor_id, device_id;
@@ -113,7 +115,7 @@ static void rombios_pci_setup(void)/* Create a list of device BARs in descending order of size. */ struct bars {uint32_t devfn, bar_reg, bar_sz; - } *bars = (struct bars *)SCRATCH_PHYSICAL_ADDRESS ; + } *bars = (struct bars *)scratch_start;unsigned int i, nr_bars =0 ;/* Program PCI-ISA bridge with appropriate link routes. */
@@ -343,6 +345,11 @@ static void reset_bios_checksum(void) *((uint8_t *)(ROMBIOS_BEGIN +ROMBIOS_MAXOFFSET )) = -checksum; } +static void rombios_acpi_build_tables (void ) +{ +acpi_build_tables (ACPI_PHYSICAL_ADDRESS ); +} +static void rombios_create_mp_tables (void ) {/* Find the 'safe' place in ROMBIOS for the MP tables. */
@@ -379,8 +386,6 @@ struct bios_config rombios_config = { .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS, .optionrom_end = OPTIONROM_PHYSICAL_END, - .acpi_start = ACPI_PHYSICAL_ADDRESS, - .apic_setup = rombios_apic_setup, .pci_setup = rombios_pci_setup, .smp_setup = smp_initialise,
@@ -391,7 +396,7 @@ struct bios_config rombios_config = { .vm86_setup = rombios_init_vm86_tss, .e820_setup = rombios_setup_e820, - .acpi_build_tables = acpi_build_tables, + .acpi_build_tables = rombios_acpi_build_tables, .create_mp_tables = rombios_create_mp_tables, };
tools/firmware/hvmloader/seabios.c +69 -8
100 lines not on this page · raw message
tools/firmware/hvmloader/smbios.c +4 -4
@@ -162,7 +162,7 @@ get_memsize(void) }int -hvm_write_smbios_tables (unsigned long scratch,unsigned long smbios_start,unsigned long smbios_end) +hvm_write_smbios_tables (unsigned long smbios_start,unsigned long smbios_end) {xen_domain_handle_t uuid;uint16_t xen_major_version, xen_minor_version;
@@ -221,15 +221,15 @@ hvm_write_smbios_tables(unsigned long sc xen_version_str[sizeof (xen_version_str)-1 ] ='\0' ; -/* SCRATCH_PHYSICAL_ADDRESS is a safe large memory area for scratch. */ - len =write_smbios_tables ((void *)scratch, smbios_start, +/* scratch_start is a safe large memory area for scratch. */ + len =write_smbios_tables ((void *)scratch_start, smbios_start, hvm_info->nr_vcpus,get_memsize (), uuid, xen_version_str, xen_major_version, xen_minor_version);if ( smbios_start + len > smbios_end ) goto error_out;/* Okay, not too large: copy out of scratch to final location. */ -memcpy ((void *)smbios_start, (void *)scratch, len); +memcpy ((void *)smbios_start, (void *)scratch_start, len);return len;
tools/firmware/hvmloader/util.c +18 -0
@@ -362,6 +362,24 @@ void *mem_alloc(uint32_t size, uint32_treturn (void *)(unsigned long )s; } +void *scratch_alloc (uint32_t size,uint32_t align) +{ +uint32_t s, e; + +/* Align to at least one kilobyte. */ +if ( align <1024 ) + align =1024 ; + + s = (scratch_start + align -1 ) & ~(align -1 ); + e = s + size -1 ; + +BUG_ON (e < s); + + scratch_start = e; + +return (void *)(unsigned long )s; +} +uint32_t ioapic_read (uint32_t reg) { *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS +0x00 ) = reg;
tools/firmware/hvmloader/util.h +5 -3
@@ -168,6 +168,9 @@ int vprintf(const char *fmt, va_list ap)void *mem_alloc (uint32_t size,uint32_t align);#define virt_to_phys (v) ((unsigned long)(v)) +/* Allocate memory in a scratch region */ +void *scratch_alloc (uint32_t size,uint32_t align); +/* Connect our xenbus client to the backend. * Call once, before any other xenbus actions. */ void xenbus_setup (void );
@@ -185,9 +188,8 @@ uint32_t rombios_highbios_setup(void);/* Miscellaneous. */ void cacheattr_init (void ); -void create_mp_tables (void *table); -int hvm_write_smbios_tables (unsigned long scratch, -unsigned long smbios_start, +unsigned long create_mp_tables (void *table); +int hvm_write_smbios_tables (unsigned long smbios_start,unsigned long smbios_end);void smp_initialise (void );
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Kevin O'Connor
Quoted 2 lines · Ian Campbell
Would that involve pulling a bunch of mainboard specific stuff from coreboot into SeaBIOS?
The idea - when it was last raised - was to provide raw info in a coreboot specific manor (via the "coreboot tables"), and then have SeaBIOS populate ACPI/SMBIOS/MPTable/etc. from that info. It was never pursued.
Quoted 7 lines
Speaking of coreboot tables... I also need to pass some start of day info into seabios (ACPI tables, e820 etc). Currently I just used a little ad-hoc data structure at a known physical address but I wonder if perhaps I should/could reuse the coreboot table datastructures? They are existing and well defined and I suppose they are pretty static, but I don't want to add any additional compatibility burden if you guys would rather avoid it.
Will Xen support the fw_cfg interface? If so, passing this info should be possible through that interface. Another thing to consider would be if coreboot+SeaBIOS in place of hvmloader would be a fit. (I don't have a good feel for what hvmloader does to judge that.)
Using the coreboot tables in Xen seems a bit odd, but I can't say it would cause a problem.
-Kevin
Quoted 19 lines · Kevin O'Connor
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Kevin O'Connor
Quoted 2 lines · Ian Campbell
Would that involve pulling a bunch of mainboard specific stuff from coreboot into SeaBIOS?
The idea - when it was last raised - was to provide raw info in a coreboot specific manor (via the "coreboot tables"), and then have SeaBIOS populate ACPI/SMBIOS/MPTable/etc. from that info. It was never pursued.
Quoted 7 lines
Speaking of coreboot tables... I also need to pass some start of day info into seabios (ACPI tables, e820 etc). Currently I just used a little ad-hoc data structure at a known physical address but I wonder if perhaps I should/could reuse the coreboot table datastructures? They are existing and well defined and I suppose they are pretty static, but I don't want to add any additional compatibility burden if you guys would rather avoid it.
Quoted 1 line
Will Xen support the
fw_cfginterface?
I don't think so, at least not in general. (fw_cfg is the qemu thing on ports 0x510/511, right?)
I don't think the qemu instance in a Xen domain has all the info it would need in order to provide the tables.
Quoted 3 lines
Another thing to consider
would be if coreboot+SeaBIOS in place of hvmloader would be a fit. (I don't have a good feel for what hvmloader does to judge that.)
I think hvmloader contains a subset of coreboot's functionality. I've wondered about possibly using coreboot in the future, but I think that would be a separate project.
Quoted 2 lines
Using the coreboot tables in Xen seems a bit odd, but I can't say it would cause a problem.
The existing ad-hoc structure I've defined is:
struct xen_seabios_info {
char signature[14]; /* XenHVMSeaBIOS\0 */
u16 length;
u32 acpi_rsdp;
u32 mptable;
u32 e820_nr;
struct e820entry e820[128];
u8 checksum;
};so I was mainly thinking of e.g. CB_TAG_MEMORY along with CB_MEM_TABLE.
I think I'll stick with defining a structure myself, these things are all discoverable via signatures so we can always transition in the future.
Ian.
Quoted 4 lines · Ian Campbell
Quoted 1 line · Kevin O'Connor
Will Xen support the
fw_cfginterface?I don't think so, at least not in general. (
fw_cfgis the qemu thing on ports 0x510/511, right?)
Yes - 0x510/0x511.
[...]
Quoted 10 lines
The existing ad-hoc structure I've defined is:
struct xen_seabios_info { char signature[14]; /* XenHVMSeaBIOS\0 */ u16 length; u32 acpi_rsdp; u32 mptable; u32 e820_nr; struct e820entry e820[128]; u8 checksum; };
Quoted 5 lines
so I was mainly thinking of e.g.
CB_TAG_MEMORYalong withCB_MEM_TABLE.I think I'll stick with defining a structure myself, these things are all discoverable via signatures so we can always transition in the future.
At some point, Xen will likely need "romfile" support (see src/paravirt.h) in order to support pulling in non-device option roms and things like "bootorder" support. The "romfile" stuff just uses a list of ("name", size, data) 3-tuples to pass in arbitrary data to SeaBIOS. You may wish to consider supporting an interface like that from the start.
-Kevin
Quoted 21 lines · Kevin O'Connor
Quoted 4 lines · Ian Campbell
Quoted 1 line · Kevin O'Connor
Will Xen support the
fw_cfginterface?I don't think so, at least not in general. (
fw_cfgis the qemu thing on ports 0x510/511, right?)Yes - 0x510/0x511.
[...]
Quoted 12 lines
The existing ad-hoc structure I've defined is:
struct xen_seabios_info { char signature[14]; /* XenHVMSeaBIOS\0 */ u16 length; u32 acpi_rsdp; u32 mptable; u32 e820_nr; struct e820entry e820[128]; u8 checksum; };so I was mainly thinking of e.g.
CB_TAG_MEMORYalong withCB_MEM_TABLE.
Quoted 6 lines
Quoted 3 lines
I think I'll stick with defining a structure myself, these things are all discoverable via signatures so we can always transition in the future.
At some point, Xen will likely need "romfile" support (see
src/paravirt.h) in order to support pulling in non-device option roms
What sorts of things live in those?
Quoted 4 lines
and things like "bootorder" support. The "romfile" stuff just uses a list of ("name", size, data) 3-tuples to pass in arbitrary data to SeaBIOS. You may wish to consider supporting an interface like that from the start.
The datastructure I'm proposing above would only be used to propagate information hvmloader itself has created (BIOS tables) through to SeaBios. hvmloader doesn't have any insight into things like bootorder etc so it wouldn't be able to create tables of that type.
The other stuff sounds like the sort of thing Xen would normally communicate from the toolstack to the guest using xenstore, unless the payloads are huge? The fw_cfg remains an option for this sort of data too, if that turns out to make sense.
I'll be posting the next version of the patch shortly.
Thanks,
Ian.