From: "Jan Beulich" Subject: [PATCH] x86/ACPI: allow CMOS RTC use even when ACPI says there is none Date: Fri, 25 Jul 2014 15:57:53 +0100 Message-ID: <53D28C91020000780002613E@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF8CA7461.1__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XAgwY-0001y9-Qh for xen-devel@lists.xenproject.org; Fri, 25 Jul 2014 14:57:59 +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 , Tim Deegan 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. --=__PartF8CA7461.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline HP is setting the ACPI_FADT_NO_CMOS_RTC flag on newer systems, regardless of whether they're being booted from UEFI. Add a command line option to allow probing for a working RTC in that case. Signed-off-by: Jan Beulich --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -218,6 +218,14 @@ If set, override Xen's calculation of th =20 If set, override Xen's default choice for the platform timer. =20 +### cmos-rtc-probe +> `=3D ` + +> Default: `false` + +Flag to indicate whether to probe for a CMOS Real Time Clock irrespective = of +ACPI indicating none to be there. + ### com1,com2 > `=3D [/][,[DPS][,[|pci|amt][,[][,[][,[]]]]]]` =20 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -654,37 +654,40 @@ mktime (unsigned int year, unsigned int=20 )*60 + sec; /* finally seconds */ } =20 -static unsigned long __get_cmos_time(void) -{ +struct rtc_time { unsigned int year, mon, day, hour, min, sec; +}; =20 - sec =3D CMOS_READ(RTC_SECONDS); - min =3D CMOS_READ(RTC_MINUTES); - hour =3D CMOS_READ(RTC_HOURS); - day =3D CMOS_READ(RTC_DAY_OF_MONTH); - mon =3D CMOS_READ(RTC_MONTH); - year =3D CMOS_READ(RTC_YEAR); +static void __get_cmos_time(struct rtc_time *rtc) +{ + rtc->sec =3D CMOS_READ(RTC_SECONDS); + rtc->min =3D CMOS_READ(RTC_MINUTES); + rtc->hour =3D CMOS_READ(RTC_HOURS); + rtc->day =3D CMOS_READ(RTC_DAY_OF_MONTH); + rtc->mon =3D CMOS_READ(RTC_MONTH); + rtc->year =3D CMOS_READ(RTC_YEAR); =20 if ( RTC_ALWAYS_BCD || !(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) ) { - BCD_TO_BIN(sec); - BCD_TO_BIN(min); - BCD_TO_BIN(hour); - BCD_TO_BIN(day); - BCD_TO_BIN(mon); - BCD_TO_BIN(year); + BCD_TO_BIN(rtc->sec); + BCD_TO_BIN(rtc->min); + BCD_TO_BIN(rtc->hour); + BCD_TO_BIN(rtc->day); + BCD_TO_BIN(rtc->mon); + BCD_TO_BIN(rtc->year); } =20 - if ( (year +=3D 1900) < 1970 ) - year +=3D 100; - - return mktime(year, mon, day, hour, min, sec); + if ( (rtc->year +=3D 1900) < 1970 ) + rtc->year +=3D 100; } =20 static unsigned long get_cmos_time(void) { unsigned long res, flags; - int i; + struct rtc_time rtc; + unsigned int seconds =3D 60; + static bool_t __read_mostly cmos_rtc_probe; + boolean_param("cmos-rtc-probe", cmos_rtc_probe); =20 if ( efi_enabled ) { @@ -693,23 +696,58 @@ static unsigned long get_cmos_time(void) return res; } =20 - if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) ) - panic("System without CMOS RTC must be booted from EFI"); - - spin_lock_irqsave(&rtc_lock, flags); - - /* read RTC exactly on falling edge of update flag */ - for ( i =3D 0 ; i < 1000000 ; i++ ) /* may take up to 1 second... */ - if ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) ) + if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC)) ) + cmos_rtc_probe =3D 0; + else if ( system_state < SYS_STATE_smp_boot && !cmos_rtc_probe ) + panic("System with no CMOS RTC advertised must be booted from = EFI" + " (or with command line option \"cmos-rtc-probe\")"); + + for ( ; ; ) + { + s_time_t start, t1, t2; + + spin_lock_irqsave(&rtc_lock, flags); + + /* read RTC exactly on falling edge of update flag */ + start =3D NOW(); + do { /* may take up to 1 second... */ + t1 =3D NOW() - start; + } while ( !(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && + t1 <=3D SECONDS(1) ); + + start =3D NOW(); + do { /* must try at least 2.228 ms */ + t2 =3D NOW() - start; + } while ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && + t2 < MILLISECS(3) ); + + __get_cmos_time(&rtc); + + spin_unlock_irqrestore(&rtc_lock, flags); + + if ( likely(!cmos_rtc_probe) || + t1 > SECONDS(1) || t2 >=3D MILLISECS(3) || + rtc.sec >=3D 60 || rtc.min >=3D 60 || rtc.hour >=3D 24 || + !rtc.day || rtc.day > 31 || + !rtc.mon || rtc.mon > 12 ) break; - for ( i =3D 0 ; i < 1000000 ; i++ ) /* must try at least 2.228 ms */ - if ( !(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) ) + + if ( seconds < 60 ) + { + if ( rtc.sec !=3D seconds ) + cmos_rtc_probe =3D 0; break; + } + + process_pending_softirqs(); + + seconds =3D rtc.sec; + } =20 - res =3D __get_cmos_time(); + if ( unlikely(cmos_rtc_probe) ) + panic("No CMOS RTC found - system must be booted from EFI"); =20 - spin_unlock_irqrestore(&rtc_lock, flags); - return res; + return mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, = rtc.sec); } =20 /*************************************************************************= ** --=__PartF8CA7461.1__= Content-Type: text/plain; name="x86-RTC-probe.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-RTC-probe.patch" x86/ACPI: allow CMOS RTC use even when ACPI says there is none=0A=0AHP is = setting the ACPI_FADT_NO_CMOS_RTC flag on newer systems,=0Aregardless of = whether they're being booted from UEFI. Add a command=0Aline option to = allow probing for a working RTC in that case.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/docs/misc/xen-command-line.markdown= =0A+++ b/docs/misc/xen-command-line.markdown=0A@@ -218,6 +218,14 @@ If = set, override Xen's calculation of th=0A =0A If set, override Xen's = default choice for the platform timer.=0A =0A+### cmos-rtc-probe=0A+> `=3D = `=0A+=0A+> Default: `false`=0A+=0A+Flag to indicate whether to = probe for a CMOS Real Time Clock irrespective of=0A+ACPI indicating none = to be there.=0A+=0A ### com1,com2=0A > `=3D [/][,[DPS][,[|pci|amt][,[][,[][,[]]]]]]`=0A =0A--- = a/xen/arch/x86/time.c=0A+++ b/xen/arch/x86/time.c=0A@@ -654,37 +654,40 @@ = mktime (unsigned int year, unsigned int =0A )*60 + sec; /* finally = seconds */=0A }=0A =0A-static unsigned long __get_cmos_time(void)=0A-{=0A+s= truct rtc_time {=0A unsigned int year, mon, day, hour, min, sec;=0A+};= =0A =0A- sec =3D CMOS_READ(RTC_SECONDS);=0A- min =3D CMOS_READ(RTC_= MINUTES);=0A- hour =3D CMOS_READ(RTC_HOURS);=0A- day =3D CMOS_READ(R= TC_DAY_OF_MONTH);=0A- mon =3D CMOS_READ(RTC_MONTH);=0A- year =3D = CMOS_READ(RTC_YEAR);=0A+static void __get_cmos_time(struct rtc_time = *rtc)=0A+{=0A+ rtc->sec =3D CMOS_READ(RTC_SECONDS);=0A+ rtc->min = =3D CMOS_READ(RTC_MINUTES);=0A+ rtc->hour =3D CMOS_READ(RTC_HOURS);=0A+ = rtc->day =3D CMOS_READ(RTC_DAY_OF_MONTH);=0A+ rtc->mon =3D = CMOS_READ(RTC_MONTH);=0A+ rtc->year =3D CMOS_READ(RTC_YEAR);=0A =0A = if ( RTC_ALWAYS_BCD || !(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) )=0A = {=0A- BCD_TO_BIN(sec);=0A- BCD_TO_BIN(min);=0A- = BCD_TO_BIN(hour);=0A- BCD_TO_BIN(day);=0A- BCD_TO_BIN(mon);= =0A- BCD_TO_BIN(year);=0A+ BCD_TO_BIN(rtc->sec);=0A+ = BCD_TO_BIN(rtc->min);=0A+ BCD_TO_BIN(rtc->hour);=0A+ = BCD_TO_BIN(rtc->day);=0A+ BCD_TO_BIN(rtc->mon);=0A+ = BCD_TO_BIN(rtc->year);=0A }=0A =0A- if ( (year +=3D 1900) < 1970 = )=0A- year +=3D 100;=0A-=0A- return mktime(year, mon, day, hour, = min, sec);=0A+ if ( (rtc->year +=3D 1900) < 1970 )=0A+ rtc->year = +=3D 100;=0A }=0A =0A static unsigned long get_cmos_time(void)=0A {=0A = unsigned long res, flags;=0A- int i;=0A+ struct rtc_time rtc;=0A+ = unsigned int seconds =3D 60;=0A+ static bool_t __read_mostly cmos_rtc_pr= obe;=0A+ boolean_param("cmos-rtc-probe", cmos_rtc_probe);=0A =0A if = ( efi_enabled )=0A {=0A@@ -693,23 +696,58 @@ static unsigned long = get_cmos_time(void)=0A return res;=0A }=0A =0A- if ( = unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) )=0A- = panic("System without CMOS RTC must be booted from EFI");=0A-=0A- = spin_lock_irqsave(&rtc_lock, flags);=0A-=0A- /* read RTC exactly on = falling edge of update flag */=0A- for ( i =3D 0 ; i < 1000000 ; i++ ) = /* may take up to 1 second... */=0A- if ( (CMOS_READ(RTC_FREQ_SELECT= ) & RTC_UIP) )=0A+ if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO= _CMOS_RTC)) )=0A+ cmos_rtc_probe =3D 0;=0A+ else if ( system_stat= e < SYS_STATE_smp_boot && !cmos_rtc_probe )=0A+ panic("System with = no CMOS RTC advertised must be booted from EFI"=0A+ " (or = with command line option \"cmos-rtc-probe\")");=0A+=0A+ for ( ; ; )=0A+ = {=0A+ s_time_t start, t1, t2;=0A+=0A+ spin_lock_irqsave(&r= tc_lock, flags);=0A+=0A+ /* read RTC exactly on falling edge of = update flag */=0A+ start =3D NOW();=0A+ do { /* may take up = to 1 second... */=0A+ t1 =3D NOW() - start;=0A+ } while = ( !(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) &&=0A+ t1 <=3D = SECONDS(1) );=0A+=0A+ start =3D NOW();=0A+ do { /* must try = at least 2.228 ms */=0A+ t2 =3D NOW() - start;=0A+ } = while ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) &&=0A+ t2 = < MILLISECS(3) );=0A+=0A+ __get_cmos_time(&rtc);=0A+=0A+ = spin_unlock_irqrestore(&rtc_lock, flags);=0A+=0A+ if ( likely(!cmos_= rtc_probe) ||=0A+ t1 > SECONDS(1) || t2 >=3D MILLISECS(3) = ||=0A+ rtc.sec >=3D 60 || rtc.min >=3D 60 || rtc.hour >=3D 24 = ||=0A+ !rtc.day || rtc.day > 31 ||=0A+ !rtc.mon || = rtc.mon > 12 )=0A break;=0A- for ( i =3D 0 ; i < 1000000 ; = i++ ) /* must try at least 2.228 ms */=0A- if ( !(CMOS_READ(RTC_FREQ= _SELECT) & RTC_UIP) )=0A+=0A+ if ( seconds < 60 )=0A+ {=0A+ = if ( rtc.sec !=3D seconds )=0A+ cmos_rtc_probe = =3D 0;=0A break;=0A+ }=0A+=0A+ process_pending_so= ftirqs();=0A+=0A+ seconds =3D rtc.sec;=0A+ }=0A =0A- res =3D = __get_cmos_time();=0A+ if ( unlikely(cmos_rtc_probe) )=0A+ = panic("No CMOS RTC found - system must be booted from EFI");=0A =0A- = spin_unlock_irqrestore(&rtc_lock, flags);=0A- return res;=0A+ return = mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec);=0A }=0A = =0A /**********************************************************************= *****=0A --=__PartF8CA7461.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 --=__PartF8CA7461.1__=--