From: "Jan Beulich" Subject: [PATCH v2] x86/EFI: allow reboot= overrides when running under EFI Date: Thu, 12 Mar 2015 16:32:03 +0000 Message-ID: <5501CD9302000078000694AB@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part10244993.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YW61n-0005HL-0g for xen-devel@lists.xenproject.org; Thu, 12 Mar 2015 16:32:07 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part10244993.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline By default we will always use EFI reboot mechanism when running under EFI platforms. However some EFI platforms are buggy and need to use the ACPI mechanism to reboot (such as Lenovo ThinkCentre M57). As such respect the 'reboot=3D' override and DMI overrides for EFI platforms. Signed-off-by: Konrad Rzeszutek Wilk - BOOT_INVALID is just zero - also consider acpi_disabled in BOOT_INVALID resolution - duplicate BOOT_INVALID resolution in machine_restart() - don't fall back from BOOT_ACPI to BOOT_EFI (if it was overridden, it surely was for a reason) - adjust doc change formatting Signed-off-by: Jan Beulich Reviewed-by: Konrad Rzeszutek Wilk --- v2: Update reboot_type prior to calling efi_reset_system(), as requested by Andrew. --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -1145,7 +1145,7 @@ The following resources are available: Technology. =20 ### reboot -> `=3D t[riple] | k[bd] | a[cpi] | p[ci] | n[o] [, [w]arm | [c]old]` +> `=3D t[riple] | k[bd] | a[cpi] | p[ci] | e[fi] | n[o] [, [w]arm | = [c]old]` =20 > Default: `0` =20 @@ -1165,6 +1165,9 @@ Specify the host reboot method. =20 `pci` instructs Xen to reboot the host using PCI reset register (port = CF9). =20 +'efi' instructs Xen to reboot using the EFI reboot call (in EFI mode by + default it will use that method first). + ### ro-hpet > `=3D ` =20 --- a/xen/arch/x86/shutdown.c +++ b/xen/arch/x86/shutdown.c @@ -28,16 +28,18 @@ #include =20 enum reboot_type { + BOOT_INVALID, BOOT_TRIPLE =3D 't', BOOT_KBD =3D 'k', BOOT_ACPI =3D 'a', BOOT_CF9 =3D 'p', + BOOT_EFI =3D 'e', }; =20 static int reboot_mode; =20 /* - * reboot=3Dt[riple] | k[bd] | a[cpi] | p[ci] | n[o] [, [w]arm | [c]old] + * reboot=3Dt[riple] | k[bd] | a[cpi] | p[ci] | n[o] | [e]fi [, [w]arm | = [c]old] * warm Don't set the cold reboot flag * cold Set the cold reboot flag * no Suppress automatic reboot after panics or crashes @@ -45,8 +47,9 @@ static int reboot_mode; * kbd Use the keyboard controller. cold reset (default) * acpi Use the RESET_REG in the FADT * pci Use the so-called "PCI reset register", CF9 + * efi Use the EFI reboot (if running under EFI) */ -static enum reboot_type reboot_type =3D BOOT_ACPI; +static enum reboot_type reboot_type =3D BOOT_INVALID; static void __init set_reboot_type(char *str) { for ( ; ; ) @@ -63,6 +66,7 @@ static void __init set_reboot_type(char=20 reboot_mode =3D 0x0; break; case 'a': + case 'e': case 'k': case 't': case 'p': @@ -106,6 +110,14 @@ void machine_halt(void) __machine_halt(NULL); } =20 +static void default_reboot_type(void) +{ + if ( reboot_type =3D=3D BOOT_INVALID ) + reboot_type =3D efi_enabled ? BOOT_EFI + : acpi_disabled ? BOOT_KBD + : BOOT_ACPI; +} + static int __init override_reboot(struct dmi_system_id *d) { enum reboot_type type =3D (long)d->driver_data; @@ -452,6 +464,7 @@ static struct dmi_system_id __initdata r =20 static int __init reboot_init(void) { + default_reboot_type(); dmi_check_system(reboot_dmi_table); return 0; } @@ -465,7 +478,7 @@ static void noreturn __machine_restart(v void machine_restart(unsigned int delay_millisecs) { unsigned int i, attempt; - enum reboot_type orig_reboot_type =3D reboot_type; + enum reboot_type orig_reboot_type; const struct desc_ptr no_idt =3D { 0 }; =20 watchdog_disable(); @@ -504,15 +517,20 @@ void machine_restart(unsigned int delay_ tboot_shutdown(TB_SHUTDOWN_REBOOT); } =20 - efi_reset_system(reboot_mode !=3D 0); + /* Just in case reboot_init() didn't run yet. */ + default_reboot_type(); + orig_reboot_type =3D reboot_type; =20 /* Rebooting needs to touch the page at absolute address 0. */ - *((unsigned short *)__va(0x472)) =3D reboot_mode; + if ( reboot_type !=3D BOOT_EFI ) + *((unsigned short *)__va(0x472)) =3D reboot_mode; =20 for ( attempt =3D 0; ; attempt++ ) { switch ( reboot_type ) { + case BOOT_INVALID: + ASSERT_UNREACHABLE(); case BOOT_KBD: /* Pulse the keyboard reset line. */ for ( i =3D 0; i < 100; i++ ) @@ -532,6 +550,11 @@ void machine_restart(unsigned int delay_ reboot_type =3D (((attempt =3D=3D 1) && (orig_reboot_type = =3D=3D BOOT_ACPI)) ? BOOT_ACPI : BOOT_TRIPLE); break; + case BOOT_EFI: + reboot_type =3D acpi_disabled ? BOOT_KBD : BOOT_ACPI; + efi_reset_system(reboot_mode !=3D 0); + *((unsigned short *)__va(0x472)) =3D reboot_mode; + break; case BOOT_TRIPLE: asm volatile ("lidt %0; int3" : : "m" (no_idt)); reboot_type =3D BOOT_KBD; --=__Part10244993.1__= Content-Type: text/plain; name="x86-EFI-reboot-override.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-EFI-reboot-override.patch" x86/EFI: allow reboot=3D overrides when running under EFI=0A=0ABy default = we will always use EFI reboot mechanism when=0Arunning under EFI platforms.= However some EFI platforms=0Aare buggy and need to use the ACPI mechanism = to=0Areboot (such as Lenovo ThinkCentre M57). As such=0Arespect the = 'reboot=3D' override and DMI overrides=0Afor EFI platforms.=0A=0ASigned-off= -by: Konrad Rzeszutek Wilk =0A=0A- BOOT_INVALID is = just zero=0A- also consider acpi_disabled in BOOT_INVALID resolution=0A- = duplicate BOOT_INVALID resolution in machine_restart()=0A- don't fall back = from BOOT_ACPI to BOOT_EFI (if it was overridden, it=0A surely was for a = reason)=0A- adjust doc change formatting=0A=0ASigned-off-by: Jan Beulich = =0AReviewed-by: Konrad Rzeszutek Wilk =0A---=0Av2: Update reboot_type prior to calling efi_reset_system(), = as=0A requested by Andrew.=0A=0A--- a/docs/misc/xen-command-line.markdow= n=0A+++ b/docs/misc/xen-command-line.markdown=0A@@ -1145,7 +1145,7 @@ The = following resources are available:=0A Technology.=0A =0A ### reboot=0A-> = `=3D t[riple] | k[bd] | a[cpi] | p[ci] | n[o] [, [w]arm | [c]old]`=0A+> = `=3D t[riple] | k[bd] | a[cpi] | p[ci] | e[fi] | n[o] [, [w]arm | = [c]old]`=0A =0A > Default: `0`=0A =0A@@ -1165,6 +1165,9 @@ Specify the = host reboot method.=0A =0A `pci` instructs Xen to reboot the host using = PCI reset register (port CF9).=0A =0A+'efi' instructs Xen to reboot using = the EFI reboot call (in EFI mode by=0A+ default it will use that method = first).=0A+=0A ### ro-hpet=0A > `=3D `=0A =0A--- a/xen/arch/x86/sh= utdown.c=0A+++ b/xen/arch/x86/shutdown.c=0A@@ -28,16 +28,18 @@=0A #include = =0A =0A enum reboot_type {=0A+ BOOT_INVALID,=0A = BOOT_TRIPLE =3D 't',=0A BOOT_KBD =3D 'k',=0A BOOT_ACPI =3D = 'a',=0A BOOT_CF9 =3D 'p',=0A+ BOOT_EFI =3D 'e',=0A };=0A = =0A static int reboot_mode;=0A =0A /*=0A- * reboot=3Dt[riple] | k[bd] | = a[cpi] | p[ci] | n[o] [, [w]arm | [c]old]=0A+ * reboot=3Dt[riple] | k[bd] = | a[cpi] | p[ci] | n[o] | [e]fi [, [w]arm | [c]old]=0A * warm Don't set = the cold reboot flag=0A * cold Set the cold reboot flag=0A * no = Suppress automatic reboot after panics or crashes=0A@@ -45,8 +47,9 @@ = static int reboot_mode;=0A * kbd Use the keyboard controller. cold = reset (default)=0A * acpi Use the RESET_REG in the FADT=0A * pci = Use the so-called "PCI reset register", CF9=0A+ * efi Use the EFI = reboot (if running under EFI)=0A */=0A-static enum reboot_type reboot_type= =3D BOOT_ACPI;=0A+static enum reboot_type reboot_type =3D BOOT_INVALID;=0A= static void __init set_reboot_type(char *str)=0A {=0A for ( ; ; = )=0A@@ -63,6 +66,7 @@ static void __init set_reboot_type(char =0A = reboot_mode =3D 0x0;=0A break;=0A case 'a':=0A+ = case 'e':=0A case 'k':=0A case 't':=0A case = 'p':=0A@@ -106,6 +110,14 @@ void machine_halt(void)=0A __machine_halt(N= ULL);=0A }=0A =0A+static void default_reboot_type(void)=0A+{=0A+ if ( = reboot_type =3D=3D BOOT_INVALID )=0A+ reboot_type =3D efi_enabled ? = BOOT_EFI=0A+ : acpi_disabled ? BOOT_KBD=0A= + : BOOT_ACPI;=0A+}=0A+=0A= static int __init override_reboot(struct dmi_system_id *d)=0A {=0A = enum reboot_type type =3D (long)d->driver_data;=0A@@ -452,6 +464,7 @@ = static struct dmi_system_id __initdata r=0A =0A static int __init = reboot_init(void)=0A {=0A+ default_reboot_type();=0A dmi_check_syste= m(reboot_dmi_table);=0A return 0;=0A }=0A@@ -465,7 +478,7 @@ static = void noreturn __machine_restart(v=0A void machine_restart(unsigned int = delay_millisecs)=0A {=0A unsigned int i, attempt;=0A- enum = reboot_type orig_reboot_type =3D reboot_type;=0A+ enum reboot_type = orig_reboot_type;=0A const struct desc_ptr no_idt =3D { 0 };=0A =0A = watchdog_disable();=0A@@ -504,15 +517,20 @@ void machine_restart(unsigned = int delay_=0A tboot_shutdown(TB_SHUTDOWN_REBOOT);=0A }=0A =0A- = efi_reset_system(reboot_mode !=3D 0);=0A+ /* Just in case reboot_init= () didn't run yet. */=0A+ default_reboot_type();=0A+ orig_reboot_type= =3D reboot_type;=0A =0A /* Rebooting needs to touch the page at = absolute address 0. */=0A- *((unsigned short *)__va(0x472)) =3D = reboot_mode;=0A+ if ( reboot_type !=3D BOOT_EFI )=0A+ *((unsigned= short *)__va(0x472)) =3D reboot_mode;=0A =0A for ( attempt =3D 0; ; = attempt++ )=0A {=0A switch ( reboot_type )=0A {=0A+ = case BOOT_INVALID:=0A+ ASSERT_UNREACHABLE();=0A = case BOOT_KBD:=0A /* Pulse the keyboard reset line. */=0A = for ( i =3D 0; i < 100; i++ )=0A@@ -532,6 +550,11 @@ void machine_re= start(unsigned int delay_=0A reboot_type =3D (((attempt =3D=3D = 1) && (orig_reboot_type =3D=3D BOOT_ACPI))=0A ? = BOOT_ACPI : BOOT_TRIPLE);=0A break;=0A+ case = BOOT_EFI:=0A+ reboot_type =3D acpi_disabled ? BOOT_KBD : = BOOT_ACPI;=0A+ efi_reset_system(reboot_mode !=3D 0);=0A+ = *((unsigned short *)__va(0x472)) =3D reboot_mode;=0A+ = break;=0A case BOOT_TRIPLE:=0A asm volatile ("lidt %0; = int3" : : "m" (no_idt));=0A reboot_type =3D BOOT_KBD;=0A --=__Part10244993.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part10244993.1__=--