Bug 207419 - Add ACPI support for RTC/CMOS device
Summary: Add ACPI support for RTC/CMOS device
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Vladimir Kondratyev
URL: https://reviews.freebsd.org/D19314
Keywords: feature
Depends on:
Blocks: 213039
  Show dependency treegraph
 
Reported: 2016-02-22 16:16 UTC by Anthony Jenkins
Modified: 2019-03-30 03:06 UTC (History)
4 users (show)

See Also:
koobs: mfc-stable12+
koobs: mfc-stable11+


Attachments
Impl. of ACPI RTC/CMOS interface. (5.68 KB, patch)
2016-02-22 16:16 UTC, Anthony Jenkins
no flags Details | Diff
Impl. of ACPI RTC/CMOS interface with bus/core separation. (19.44 KB, patch)
2016-02-22 16:19 UTC, Anthony Jenkins
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Jenkins 2016-02-22 16:16:32 UTC
Created attachment 167301 [details]
Impl. of ACPI RTC/CMOS interface.

FreeBSD base system does not provide an ACPI handler for the PC/AT RTC/CMOS device with PnP ID PNP0B00; on recent HP Envy laptops, the absence of this handler causes suspend/resume and poweroff(8) to hang/fail, emitting e.g.

ACPI Error: No handler for Region [RCM0] (0xfffff80005796480) [SystemCMOS] (20150818/evregion-176)
ACPI Error: Region SystemCMOS (ID=5) has no handler (20150818/exfldio-317)

These HP laptops have BIOSes which attempt to query the RTC date/time registers via ACPI before suspending/powering off.

ACPI-5.0 specification section 9.15 describes the ACPI interface to the RTC/CMOS device (atrtc(4) in FreeBSD).

I have implemented this ACPI handler; adding this allows poweroff and suspend/resume to occur.  At a FreeBSD committer's request, I've also implemented the same patch with additional changes to atrtc(4) to separate the bus functionality from the core functionality.
Comment 1 Anthony Jenkins 2016-02-22 16:19:29 UTC
Created attachment 167302 [details]
Impl. of ACPI RTC/CMOS interface with bus/core separation.

This version of the patch was requested by a FreeBSD committer.  I personally prefer the previous patch to this one; instead the separation should be performed as a new bug.
Comment 2 Jung-uk Kim freebsd_committer 2016-02-22 18:04:08 UTC
Please note the upstream received a CMOS handler implementation and the patch was posted here:

https://lists.acpica.org/pipermail/devel/2015-May/000698.html

Unfortunately, it is still not resolved.

https://lists.acpica.org/pipermail/devel/2016-February/000872.html
https://lists.acpica.org/pipermail/devel/2016-February/000873.html
https://lists.acpica.org/pipermail/devel/2016-February/000874.html

If possible, please participate in the discussion.
Comment 3 Anthony Jenkins 2016-02-22 19:32:47 UTC
The upstream thread actually mirrors the evolution of my OSPM patch.  I first tried adding code to the ACPICA code, then, based on some helpful suggestions from acpi@, moved it to the atrtc(4) driver.  I agree with the last thread post (https://lists.acpica.org/pipermail/devel/2016-February/000874.html) - that support for RTC/CMOS devices belongs in the OSPM, not in the ACPICA.  If you look closely at the OP's proposed ACPICA patch, the AcpiOs(Read|Write)Cmos() handlers are no-ops (Read returns 0, Write does nothing).

I mean I can toss my $0.02 into the thread, but it'll be little more than "I agree this shouldn't be added to ACPICA"...
Comment 4 Jung-uk Kim freebsd_committer 2016-02-22 19:48:24 UTC
(In reply to Anthony Jenkins from comment #3)
> If you look closely at the OP's proposed ACPICA patch, the
> AcpiOs(Read|Write)Cmos() handlers are no-ops (Read returns 0, Write does
> nothing).

Actually, those are stubs for userland tools, i.e., acpiexec.  FYI, OSPM must provide AcpiOsReadCmos() and AcpiOsWriteCmos().  See sys/dev/acpica/Osd/OsdMemory.c, for example.
Comment 5 Jung-uk Kim freebsd_committer 2016-02-22 20:03:58 UTC
BTW, these functions must be MD.  So, it should be placed in sys/x86/acpica (please see OsdEnvironment.c) and/or sys/x86/isa/atrtc.c.  If the upstream does not want them as official API, then your patch is good.

FYI, the official ACPICA API is documented here:

https://acpica.org/sites/acpica/files/acpica-reference_17.pdf
Comment 6 Jung-uk Kim freebsd_committer 2016-02-22 20:33:22 UTC
(In reply to Anthony Jenkins from comment #1)
FYI, the separation is important because ACPI is not mandatory for i386.
Comment 7 Anthony Jenkins 2016-02-25 05:06:23 UTC
(In reply to Jung-uk Kim from comment #6)

Ahh, okay I think that makes sense; seemed an arbitrary request before.

My bus-separation patch could probably use some work, but it builds and works on my amd64.
Comment 8 Anthony Jenkins 2018-07-31 01:47:34 UTC
I just assumed this was dropped for lack of interest.  What are my next steps?
Comment 9 Vladimir Kondratyev freebsd_committer 2019-02-24 09:58:09 UTC
https://reviews.freebsd.org/D19314
Comment 10 commit-hook freebsd_committer 2019-03-10 20:20:42 UTC
A commit references this bug:

Author: wulf
Date: Sun Mar 10 20:19:44 UTC 2019
New revision: 344982
URL: https://svnweb.freebsd.org/changeset/base/344982

Log:
  atrtc(4): install ACPI RTC/CMOS operation region handler

  FreeBSD base system does not provide an ACPI handler for the PC/AT RTC/CMOS
  device with PnP ID PNP0B00; on some HP laptops, the absence of this handler
  causes suspend/resume and poweroff(8) to hang or fail [1], [2]. On these
  laptops EC _REG method queries the RTC date/time registers via ACPI
  before suspending/powering off. The handler should be registered before
  acpi_ec driver is loaded.

  This change adds handler to access CMOS RTC operation region described in
  section 9.15 of ACPI-6.2 specification [3]. It is installed only for ACPI
  version of atrtc(4) so it should not affect old ACPI-less i386 systems.

  It is possible to disable the handler with loader tunable:
  debug.acpi.disabled=atrtc

  Informational debugging printf can be enabled by setting hw.acpi.verbose=1
  in loader.conf

  [1] https://wiki.freebsd.org/Laptops/HP_Envy_6Z-1100
  [2] https://wiki.freebsd.org/Laptops/HP_Notebook_15-af104ur
  [3] https://uefi.org/sites/default/files/resources/ACPI_6_2.pdf

  PR:		207419, 213039
  Submitted by:	Anthony Jenkins <Scoobi_doo@yahoo.com>
  Reviewed by:	ian
  Discussed on:	acpi@, 2013-2015, several threads
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D19314

Changes:
  head/sys/x86/isa/atrtc.c
Comment 11 commit-hook freebsd_committer 2019-03-27 19:16:39 UTC
A commit references this bug:

Author: wulf
Date: Wed Mar 27 19:16:04 UTC 2019
New revision: 345589
URL: https://svnweb.freebsd.org/changeset/base/345589

Log:
  MFC: r344982, r345022

  atrtc(4): install ACPI RTC/CMOS operation region handler

  FreeBSD base system does not provide an ACPI handler for the PC/AT RTC/CMOS
  device with PnP ID PNP0B00; on some HP laptops, the absence of this handler
  causes suspend/resume and poweroff(8) to hang or fail [1], [2]. On these
  laptops EC _REG method queries the RTC date/time registers via ACPI
  before suspending/powering off. The handler should be registered before
  acpi_ec driver is loaded.

  This change adds handler to access CMOS RTC operation region described in
  section 9.15 of ACPI-6.2 specification [3]. It is installed only for ACPI
  version of atrtc(4) so it should not affect old ACPI-less i386 systems.

  It is possible to disable the handler with loader tunable:
  debug.acpi.disabled=atrtc

  Informational debugging printf can be enabled by setting hw.acpi.verbose=1
  in loader.conf

  [1] https://wiki.freebsd.org/Laptops/HP_Envy_6Z-1100
  [2] https://wiki.freebsd.org/Laptops/HP_Notebook_15-af104ur
  [3] https://uefi.org/sites/default/files/resources/ACPI_6_2.pdf

  PR:		207419, 213039
  Submitted by:	Anthony Jenkins <Scoobi_doo@yahoo.com>
  Reviewed by:	ian
  Discussed on:	acpi@, 2013-2015, several threads
  Differential Revision:	https://reviews.freebsd.org/D19314

Changes:
_U  stable/12/
  stable/12/sys/x86/isa/atrtc.c
Comment 12 commit-hook freebsd_committer 2019-03-27 19:18:45 UTC
A commit references this bug:

Author: wulf
Date: Wed Mar 27 19:17:43 UTC 2019
New revision: 345590
URL: https://svnweb.freebsd.org/changeset/base/345590

Log:
  MFC: r344982, r345022

  atrtc(4): install ACPI RTC/CMOS operation region handler

  FreeBSD base system does not provide an ACPI handler for the PC/AT RTC/CMOS
  device with PnP ID PNP0B00; on some HP laptops, the absence of this handler
  causes suspend/resume and poweroff(8) to hang or fail [1], [2]. On these
  laptops EC _REG method queries the RTC date/time registers via ACPI
  before suspending/powering off. The handler should be registered before
  acpi_ec driver is loaded.

  This change adds handler to access CMOS RTC operation region described in
  section 9.15 of ACPI-6.2 specification [3]. It is installed only for ACPI
  version of atrtc(4) so it should not affect old ACPI-less i386 systems.

  It is possible to disable the handler with loader tunable:
  debug.acpi.disabled=atrtc

  Informational debugging printf can be enabled by setting hw.acpi.verbose=1
  in loader.conf

  [1] https://wiki.freebsd.org/Laptops/HP_Envy_6Z-1100
  [2] https://wiki.freebsd.org/Laptops/HP_Notebook_15-af104ur
  [3] https://uefi.org/sites/default/files/resources/ACPI_6_2.pdf

  PR:		207419, 213039
  Submitted by:	Anthony Jenkins <Scoobi_doo@yahoo.com>
  Reviewed by:	ian
  Discussed on:	acpi@, 2013-2015, several threads
  Differential Revision:	https://reviews.freebsd.org/D19314

Changes:
_U  stable/11/
  stable/11/sys/x86/isa/atrtc.c
Comment 13 Vladimir Kondratyev freebsd_committer 2019-03-27 19:27:30 UTC
Committed, thanks!