diff mbox

Re: [RFC PATCH 04/14] ACPI: Add ACPI 5.0 Time and Alarm Device driver

Message ID 52CB929C.6050403@zytor.com
State Not Applicable
Headers show

Commit Message

H. Peter Anvin Jan. 7, 2014, 5:37 a.m. UTC
On 01/06/2014 12:58 AM, joeyli wrote:
> 於 二,2013-12-31 於 16:42 -0800,H. Peter Anvin 提到:
>> On 12/19/2013 09:41 PM, joeyli wrote:
>>>>
>>>> What platform do you have that has TAD support?  I am wondering how this
>>>> was tested.
>>>>
>>>
>>> It's a testing platform that's only support get/set time functions of
>>> ACPI TAD.
>>>
>>
>> It would be really, really good to get this into Qemu (either SeaBIOS or
>> OVMF, or ideally both) so we can have anyone test.
>>
>> 	-hpa
> 
> I will try to add to OVMF first.
> 

For the record, I posted a patch to Qemu about a year ago to store the
timezone in the CMOS, which might be useful for this implementation.  It
was rejected because of no firmware support, so if you implement it for
OVMF we can (update and) push this patch again.

	-hpa

Comments

joeyli Jan. 7, 2014, 10:40 a.m. UTC | #1
於 一,2014-01-06 於 21:37 -0800,H. Peter Anvin 提到:
> On 01/06/2014 12:58 AM, joeyli wrote:
> > 於 二,2013-12-31 於 16:42 -0800,H. Peter Anvin 提到:
> >> On 12/19/2013 09:41 PM, joeyli wrote:
> >>>>
> >>>> What platform do you have that has TAD support?  I am wondering how this
> >>>> was tested.
> >>>>
> >>>
> >>> It's a testing platform that's only support get/set time functions of
> >>> ACPI TAD.
> >>>
> >>
> >> It would be really, really good to get this into Qemu (either SeaBIOS or
> >> OVMF, or ideally both) so we can have anyone test.
> >>
> >> 	-hpa
> > 
> > I will try to add to OVMF first.
> > 
> 
> For the record, I posted a patch to Qemu about a year ago to store the
> timezone in the CMOS, which might be useful for this implementation.  It
> was rejected because of no firmware support, so if you implement it for
> OVMF we can (update and) push this patch again.
> 
> 	-hpa
> 

Thanks for your patch. 

Due to accessing CMOS through ASL need enable SMM support in OVMF, I am
looking Laszlo's OVMF S3 patches:

https://www.mail-archive.com/edk2-devel@lists.sourceforge.net/msg04969.html

Honestly I am not good on this area, I need to spend more time to
understand it.


Regards
Joey Lee
H. Peter Anvin Jan. 7, 2014, 4:35 p.m. UTC | #2
On 01/07/2014 02:40 AM, joeyli wrote:
> 
> Due to accessing CMOS through ASL need enable SMM support in OVMF,

Why?  The CMOS is its own ASL address space, and you need that anyway to
be able to access the RTC proper.  If you don't want to use it because
you don't want to export any indication of a legacy RTC you should be
able to just do I/O port references directly in your ASL.

	-hpa
joeyli Jan. 8, 2014, 2:59 p.m. UTC | #3
於 二,2014-01-07 於 08:35 -0800,H. Peter Anvin 提到:
> On 01/07/2014 02:40 AM, joeyli wrote:
> > 
> > Due to accessing CMOS through ASL need enable SMM support in OVMF,
> 
> Why?  The CMOS is its own ASL address space, and you need that anyway to
> be able to access the RTC proper.  If you don't want to use it because
> you don't want to export any indication of a legacy RTC you should be
> able to just do I/O port references directly in your ASL.
> 
> 	-hpa
> 
> 

ACPICA denied AML access RTC ports.

I tried to access 0x70, 0x71 ports in ASL on a real machine, ACPICA
denied AML access to those ports. I got the following dmesg:

hwvalid-0188 hw_validate_io_request: Denied AML access to port
0x0000000000000071/1


The code in acpica denied it:

linux/drivers/acpi/acpica/hwvalid.c

 * This provides ACPICA with the desired port protections and
 * Microsoft compatibility.
 *
 * Description of port entries:
[...]
 *  RTC:   Real-time clock
 *  CMOS:  Extended CMOS
[...]
 */
static const struct acpi_port_info acpi_protected_ports[] = {
[...]
        {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
        {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},


Document of Windows XP:
http://www.freelists.org/post/windows_errors/what-error-messages-really-mean-WinXP-IO-Ports-Blocked-from-Bios-AML-on-Windows-XP


If just for ACPI TAD testing, we can remove the port protection check of
RTC ports in hwvalid.c. I have read 0x70/0x71 port success after removed
the checking in acpica/hwvalid.c.

I will try to write RTC port in AML after remove acpica check, maybe
have other unpredictable situation.


Thanks a lot!
Joey Lee
H. Peter Anvin Jan. 8, 2014, 5:56 p.m. UTC | #4
On 01/08/2014 06:59 AM, joeyli wrote:
> 
> ACPICA denied AML access RTC ports.
> 
> I tried to access 0x70, 0x71 ports in ASL on a real machine, ACPICA
> denied AML access to those ports. I got the following dmesg:
> 
> hwvalid-0188 hw_validate_io_request: Denied AML access to port
> 0x0000000000000071/1
> 
> The code in acpica denied it:
> 
> linux/drivers/acpi/acpica/hwvalid.c
> 
>  * This provides ACPICA with the desired port protections and
>  * Microsoft compatibility.
>  *
>  * Description of port entries:
> [...]
>  *  RTC:   Real-time clock
>  *  CMOS:  Extended CMOS
> [...]
>  */
> static const struct acpi_port_info acpi_protected_ports[] = {
> [...]
>         {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
>         {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},
> 
> 
> Document of Windows XP:
> http://www.freelists.org/post/windows_errors/what-error-messages-really-mean-WinXP-IO-Ports-Blocked-from-Bios-AML-on-Windows-XP
> 
> If just for ACPI TAD testing, we can remove the port protection check of
> RTC ports in hwvalid.c. I have read 0x70/0x71 port success after removed
> the checking in acpica/hwvalid.c.
> 
> I will try to write RTC port in AML after remove acpica check, maybe
> have other unpredictable situation.
> 

Now *THERE* is a good use of the "no RTC bit".  In the case that bit is
set we should presumably remove these ports from the block list.

Otherwise we should use the CMOS address space, not the I/O port address
space.

	-hpa
joeyli Jan. 9, 2014, 3:47 a.m. UTC | #5
於 三,2014-01-08 於 09:56 -0800,H. Peter Anvin 提到:
[...]
> > Document of Windows XP:
> >
> http://www.freelists.org/post/windows_errors/what-error-messages-really-mean-WinXP-IO-Ports-Blocked-from-Bios-AML-on-Windows-XP
> > 
> > If just for ACPI TAD testing, we can remove the port protection
> check of
> > RTC ports in hwvalid.c. I have read 0x70/0x71 port success after
> removed
> > the checking in acpica/hwvalid.c.
> > 
> > I will try to write RTC port in AML after remove acpica check, maybe
> > have other unpredictable situation.
> > 
> 
> Now *THERE* is a good use of the "no RTC bit".  In the case that bit
> is
> set we should presumably remove these ports from the block list.

Thanks for your suggestion, I will put a testing patch on this.

> 
> Otherwise we should use the CMOS address space, not the I/O port
> address
> space.
> 
>         -hpa 

Unfortunately current acpica leaks the SystemCMOS handler:

ACPI Error: Region SystemCMOS (ID=5) has no handler (20131115/exfldio-299)


Regards
Joey Lee
H. Peter Anvin Jan. 9, 2014, 4 a.m. UTC | #6
On 01/08/2014 07:47 PM, joeyli wrote:
> 
> Unfortunately current acpica leaks the SystemCMOS handler:
> 
> ACPI Error: Region SystemCMOS (ID=5) has no handler (20131115/exfldio-299)
> 

I'm sorry, I can't parse either your statement or the error message...
sounds like there is a bug here, too.

	-hpa
Rafael J. Wysocki Jan. 9, 2014, 12:16 p.m. UTC | #7
On Thursday, January 09, 2014 11:47:39 AM joeyli wrote:
> 於 三,2014-01-08 於 09:56 -0800,H. Peter Anvin 提到:
> [...]
> > > Document of Windows XP:
> > >
> > http://www.freelists.org/post/windows_errors/what-error-messages-really-mean-WinXP-IO-Ports-Blocked-from-Bios-AML-on-Windows-XP
> > > 
> > > If just for ACPI TAD testing, we can remove the port protection
> > check of
> > > RTC ports in hwvalid.c. I have read 0x70/0x71 port success after
> > removed
> > > the checking in acpica/hwvalid.c.
> > > 
> > > I will try to write RTC port in AML after remove acpica check, maybe
> > > have other unpredictable situation.
> > > 
> > 
> > Now *THERE* is a good use of the "no RTC bit".  In the case that bit
> > is
> > set we should presumably remove these ports from the block list.
> 
> Thanks for your suggestion, I will put a testing patch on this.
> 
> > 
> > Otherwise we should use the CMOS address space, not the I/O port
> > address
> > space.
> > 
> >         -hpa 
> 
> Unfortunately current acpica leaks the SystemCMOS handler:
> 
> ACPI Error: Region SystemCMOS (ID=5) has no handler (20131115/exfldio-299)

This is not an ACPICA problem.  We have no CMOS address space handler in Linux
and arguably there should be one.  So I'd suggest implementing that to start
with or we risk conflicts between kernel code and AML accessing registers in
that space.

Thanks!
diff mbox

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2fb11f6..72541dd 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -681,6 +681,7 @@  static void rtc_set_date_from_host(ISADevice *dev)
 {
     RTCState *s = DO_UPCAST(RTCState, dev, dev);
     struct tm tm;
+    int minuteseast;
 
     qemu_get_timedate(&tm, 0);
 
@@ -690,6 +691,11 @@  static void rtc_set_date_from_host(ISADevice *dev)
 
     /* set the CMOS date */
     rtc_set_cmos(s, &tm);
+
+    /* Set the timezone information as a signed 16-bit number of minutes */
+    minuteseast = ((int64_t)s->base_rtc - (int64_t)mktime(&tm)) / 60;
+    s->cmos_data[RTC_TIMEZONE_L] = (uint8_t)(minuteseast);
+    s->cmos_data[RTC_TIMEZONE_H] = (uint8_t)(minuteseast >> 8);
 }
 
 static int rtc_post_load(void *opaque, int version_id)
diff --git a/hw/mc146818rtc_regs.h b/hw/mc146818rtc_regs.h
index ccdee42..7dd5e0d 100644
--- a/hw/mc146818rtc_regs.h
+++ b/hw/mc146818rtc_regs.h
@@ -47,6 +47,8 @@ 
 /* PC cmos mappings */
 #define RTC_CENTURY              0x32
 #define RTC_IBM_PS2_CENTURY_BYTE 0x37
+#define RTC_TIMEZONE_L           0x3e
+#define RTC_TIMEZONE_H           0x3f
 
 #define REG_A_UIP 0x80