Skip to contentSkip to conversation

x86: real mode support: get EDD info

PATCH In review Jan Beulich 3 participants 5 messages Mar 2, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 x86: real mode support: get EDD info

Obtain EDD info from BIOS and pass it up to Dom0.

xen/arch/x86/Makefile +1 -1
Index: 2007-02-27/xen/arch/x86/Makefile
===================================================================
@@ -78,7 +78,7 @@ xen.lds: $(TARGET_SUBARCH)/xen.lds.S $(H
 boot/mkelf32: boot/mkelf32.c
 	$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
 
-boot/$(TARGET_SUBARCH).o: boot/realmode.S
+boot/$(TARGET_SUBARCH).o: boot/realmode.S boot/edd.S
 
 .PHONY: clean
 clean::
xen/arch/x86/boot/edd.S new file +217 -0

217 lines not on this page · raw message

xen/arch/x86/boot/realmode.S +23 -0
Index: 2007-02-27/xen/arch/x86/boot/realmode.S
===================================================================
@@ -118,3 +118,26 @@ cmd_line_ptr: .long 0
 .Lgdt:	.skip 2+4
 .Lidt:	.skip 2+4
 	.previous
+
+#define EDDNR			SYM_REAL(eddnr)
+#define EDDBUF			SYM_REAL(eddbuf)
+#define EDD_MBR_SIG_NR_BUF	SYM_REAL(edd_mbr_sig_nr_buf)
+#define EDD_MBR_SIG_BUF		SYM_REAL(edd_mbr_sig_buf)
+
+edd:
+#include "edd.S"
+	ret
+
+	.section .real.data
+	.globl eddnr, eddbuf, edd_mbr_sig_nr_buf, edd_mbr_sig_buf
+	.align 4
+eddbuf:			.skip EDDMAXNR * (EDDEXTSIZE + EDDPARMSIZE)
+#if EDDMAXNR * (EDDEXTSIZE + EDDPARMSIZE) < 512
+/* Must have space for a full 512-byte sector */
+			.skip 512 - EDDMAXNR * (EDDEXTSIZE + EDDPARMSIZE)
+#endif
+	.align 4
+edd_mbr_sig_buf:	.skip EDD_MBR_SIG_MAX * 4
+eddnr:			.skip 1
+edd_mbr_sig_nr_buf:	.skip 1
+	.previous
xen/arch/x86/boot/x86_32.S +3 -0
Index: 2007-02-27/xen/arch/x86/boot/x86_32.S
===================================================================
@@ -90,6 +90,9 @@ __start:
         lea     __PAGE_OFFSET(%ebx),%eax
         push    %eax
 
+        pushl   $SYM_PHYS(edd)
+        call    realmode
+
 #ifdef CONFIG_X86_PAE
         /* Initialize low and high mappings of all memory with 2MB pages */
         mov     $SYM_PHYS(idle_pg_table_l2),%edi
xen/arch/x86/boot/x86_64.S +2 -0
Index: 2007-02-27/xen/arch/x86/boot/x86_64.S
===================================================================
@@ -73,6 +73,8 @@ __start:
         mov     %ebx,SYM_PHYS(multiboot_ptr)
 
         lss     SYM_PHYS(.Lstack_start),%esp
+        pushl   $SYM_PHYS(edd)
+        call    realmode
 
         /* We begin by interrogating the CPU for the presence of long mode. */
         mov     $0x80000000,%eax
xen/arch/x86/platform_hypercall.c +87 -0

113 lines not on this page · raw message

xen/include/public/platform.h +30 -0
Index: 2007-02-27/xen/include/public/platform.h
===================================================================
@@ -114,6 +114,35 @@ struct xenpf_platform_quirk {
 typedef struct xenpf_platform_quirk xenpf_platform_quirk_t;
 DEFINE_XEN_GUEST_HANDLE(xenpf_platform_quirk_t);
 
+#define XENPF_firmware_info       50
+#define XEN_FW_DISK_INFO          1 /* from int 13 AH=08 */
+#define XEN_FW_EDD_INFO           2 /* from int 13 AH=41 */
+#define XEN_FW_EDD_PARAMS         3 /* from int 13 AH=48 */
+#define XEN_FW_MBR_SIGNATURE      4
+struct xenpf_firmware_info {
+    /* IN variables. */
+    uint32_t type;
+    uint32_t index;
+    /* OUT variables. */
+    union {
+        struct {
+            uint16_t max_cylinder;
+            uint8_t max_head;
+            uint8_t sectors_per_track;
+        } disk_info;
+        struct {
+            uint8_t device;
+            uint8_t version;
+            uint16_t interface;
+        } edd_info;
+        /* first uint16_t of buffer must be set to buffer size */
+        XEN_GUEST_HANDLE(void) edd_params;
+        uint32_t mbr_signature;
+    } u;
+};
+typedef struct xenpf_firmware_info xenpf_firmware_info_t;
+DEFINE_XEN_GUEST_HANDLE(xenpf_firmware_info_t);
+
 struct xen_platform_op {
     uint32_t cmd;
     uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
@@ -124,6 +153,7 @@ struct xen_platform_op {
         struct xenpf_read_memtype      read_memtype;
         struct xenpf_microcode_update  microcode;
         struct xenpf_platform_quirk    platform_quirk;
+        struct xenpf_firmware_info     firmware_info;
         uint8_t                        pad[128];
     } u;
 };
xen/include/xen/edd.h new file +193 -0

193 lines not on this page · raw message

linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c +3 -0
Index: 2007-02-27/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c
===================================================================
@@ -66,6 +66,7 @@
 #include <xen/interface/physdev.h>
 #include <xen/interface/memory.h>
 #include <xen/features.h>
+#include <xen/firmware.h>
 #include <xen/xencons.h>
 #include <setup_arch.h>
 #include <bios_ebda.h>
@@ -740,6 +741,7 @@ struct edd edd;
 #ifdef CONFIG_EDD_MODULE
 EXPORT_SYMBOL(edd);
 #endif
+#ifndef CONFIG_XEN
 /**
  * copy_edd() - Copy the BIOS EDD information
  *              from boot_params into a safe place.
@@ -752,6 +754,7 @@ static inline void copy_edd(void)
      edd.mbr_signature_nr = EDD_MBR_SIG_NR;
      edd.edd_info_nr = EDD_NR;
 }
+#endif
 #else
 static inline void copy_edd(void)
 {
linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c +3 -0
Index: 2007-02-27/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c
===================================================================
@@ -71,6 +71,7 @@
 #include <asm/hypervisor.h>
 #include <xen/interface/nmi.h>
 #include <xen/features.h>
+#include <xen/firmware.h>
 #include <xen/xencons.h>
 #define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
 #define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
@@ -534,6 +535,7 @@ struct edd edd;
 #ifdef CONFIG_EDD_MODULE
 EXPORT_SYMBOL(edd);
 #endif
+#ifndef CONFIG_XEN
 /**
  * copy_edd() - Copy the BIOS EDD information
  *              from boot_params into a safe place.
@@ -546,6 +548,7 @@ static inline void copy_edd(void)
      edd.mbr_signature_nr = EDD_MBR_SIG_NR;
      edd.edd_info_nr = EDD_NR;
 }
+#endif
 #else
 static inline void copy_edd(void)
 {
linux-2.6-xen-sparse/drivers/firmware/Kconfig +0 -1
Index: 2007-02-27/linux-2.6-xen-sparse/drivers/firmware/Kconfig
===================================================================
@@ -8,7 +8,6 @@ menu "Firmware Drivers"
 config EDD
 	tristate "BIOS Enhanced Disk Drive calls determine boot disk"
 	depends on !IA64
-	depends on !XEN
 	help
 	  Say Y or M here if you want to enable BIOS Enhanced Disk Drive
 	  Services real mode BIOS calls to determine which disk
linux-2.6-xen-sparse/drivers/xen/core/Makefile +1 -1
Index: 2007-02-27/linux-2.6-xen-sparse/drivers/xen/core/Makefile
===================================================================
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y := evtchn.o gnttab.o features.o
+obj-y := evtchn.o gnttab.o features.o firmware.o
 
 obj-$(CONFIG_PROC_FS)		+= xen_proc.o
 obj-$(CONFIG_SYSFS)		+= hypervisor_sysfs.o
linux-2.6-xen-sparse/drivers/xen/core/firmware.c new file +61 -0

61 lines not on this page · raw message

Index: 2007-02-27/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h
===================================================================
--- 2007-02-27.orig/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h 2007-02-21 16:57:23.000000000
+0100
+++ 2007-02-27/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h 2007-02-21 14:59:20.000000000 +0100
@@ -209,6 +209,14 @@ HYPERVISOR_dom0_op(
}

static inline int
+HYPERVISOR_platform_op(
+ xen_platform_op_t *platform_op)
+{
+ platform_op->interface_version = XENPF_INTERFACE_VERSION;
+ return _hypercall1(int, platform_op, platform_op);
+}
+
+static inline int
HYPERVISOR_set_debugreg(
int reg, unsigned long value)
{
Index: 2007-02-27/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h
===================================================================
--- 2007-02-27.orig/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h 2007-02-21 16:57:23.000000000
+0100
+++ 2007-02-27/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h 2007-02-21 15:01:06.000000000
+0100
@@ -212,6 +212,14 @@ HYPERVISOR_dom0_op(
}

static inline int
+HYPERVISOR_platform_op(
+ xen_platform_op_t *platform_op)
+{
+ platform_op->interface_version = XENPF_INTERFACE_VERSION;
+ return _hypercall1(int, platform_op, platform_op);
+}
+
+static inline int
HYPERVISOR_set_debugreg(
int reg, unsigned long value)
{

linux-2.6-xen-sparse/include/xen/firmware.h new file +6 -0
Index: 2007-02-27/linux-2.6-xen-sparse/include/xen/firmware.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef __XEN_FIRMWARE_H__
+#define __XEN_FIRMWARE_H__
+
+void copy_edd(void);
+
+#endif /* __XEN_FIRMWARE_H__ */
#1 lore raw
Quoted 1 line · Jan Beulich

Obtain EDD info from BIOS and pass it up to Dom0.

What data format are the EDD/EDID buffers filled with? The format is not defined in the public headers. Is it simply whatever Linux happens to be using internally?

I am still interested in trying out an interface to let dom0 request code to be run in various modes and on various CPUs. This would be attractive in this case, assuming that these BIOS calls could be made later than very early bootstrap, as it would avoid piling code into Xen, and assumptions about info data formats, just because of the environment that the interrogating code needs to be executed in. No doubt it is a larger initial amount of engineering effort up front though. Also I'm not sure if there would be any subtle gotchas to running this skanky BIOS code later in the boot sequence (I'd be optimistic that it'd just work though).

-- Keir

#2 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 02.03.07 12:15 >>>

Quoted 1 line · Jan Beulich

Obtain EDD info from BIOS and pass it up to Dom0.

What data format are the EDD/EDID buffers filled with? The format is not defined in the public headers. Is it simply whatever Linux happens to be using internally?

No, this is the BIOS format. Linux uses this directly. I specifically (based on past comment from you) avoided introducing Linux specifics.

Quoted 9 lines

I am still interested in trying out an interface to let dom0 request code to be run in various modes and on various CPUs. This would be attractive in this case, assuming that these BIOS calls could be made later than very early bootstrap, as it would avoid piling code into Xen, and assumptions about info data formats, just because of the environment that the interrogating code needs to be executed in. No doubt it is a larger initial amount of engineering effort up front though. Also I'm not sure if there would be any subtle gotchas to running this skanky BIOS code later in the boot sequence (I'd be optimistic that it'd just work though).

Possible, but especially on x86-64 undesirable in my opinion. Also, I'll want the base real mode stuff in anyway (regardless of EDD/EDID) in order to be able to set up a VESA frame buffer mode for the console. This clearly should be done by Xen in order to ensure it knows how to access the console in case it is allowed access past dom0 creation.

Jan

#3 lore raw
Quoted 1 line · Jan Beulich

Possible, but especially on x86-64 undesirable in my opinion.

It's certainly more of a pain to make the mode switch, but not impossible by any means.

Quoted 5 lines

Also, I'll want
the base real mode stuff in anyway (regardless of EDD/EDID) in order to be able to set up a VESA frame buffer mode for the console. This clearly should be done by Xen in order to ensure it knows how to access the console in case it is allowed access past dom0 creation.

Oh yes, we definitely want the mode-switching code in Xen. No doubt about that. The question is whether we pull in the EDD/EDID stuff as well. The fact that the data format is BIOS-defined does make the current approach plausible if not particularly tasteful architecturally speaking (but what BIOS stuff is? :-).

-- Keir

#4 lore raw
Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: 02 March 2007 11:36
To: Jan Beulich; [email protected]; Keir Fraser
Subject: Re: [Xen-devel] [PATCH 2/3] x86: real mode support:
get EDD info

Quoted 7 lines
Quoted 1 line · Jan Beulich

Possible, but especially on x86-64 undesirable in my opinion.

It's certainly more of a pain to make the mode switch, but not impossible by
any means.

It's not that much harder as long as you have some region of (below 1MB is probably best) memory that is 1:1 mapped that you can put the code into. Jump to a 32-bit segment (i.e. cs.attr.large-mode = 0) in low memory, turn off LME in EFER and PG in CR0, then turn off PE in CR0 and you're in real-mode. Of course to make the environment work for real-mode, there's a whole bunch of other stuff that needs to be done (interrupt vector table at address zero for example), but that should be the same whether you run 64- or 32-bit code in the first place.

--
Mats

Quoted 29 lines
Quoted 3 lines

Also, I'll want
the base real mode stuff in anyway (regardless of EDD/EDID)

in order to

Quoted 1 line

be able to set up a VESA frame buffer mode for the console.

This clearly

Quoted 2 lines

should be done by Xen in order to ensure it knows how to access the console in case it is allowed access past dom0 creation.

Oh yes, we definitely want the mode-switching code in Xen. No doubt about
that. The question is whether we pull in the EDD/EDID stuff as well. The
fact that the data format is BIOS-defined does make the current approach
plausible if not particularly tasteful architecturally speaking (but what
BIOS stuff is? :-).

-- Keir

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel