[PATCH] Naive implementation of AcpiExCmosSpaceHandler()

2014-06-07 Thread Anthony Jenkins
I'm testing on FreeBSD 11.0-CURRENT #18 r266756M on an HP Envy Sleekbook 
6z-1100 (AMD A-10).  This is a naive implementation of 
AcpiExCmosSpaceHandler(), it simply uses I/O ports 0x70 and 0x71 to read/write 
CMOS registers using AcpiHwWritePort()/AcpiHwReadPort() calls. I'm new(ish) to 
the ACPICA subsystem and I'm probably not going about this the right way - I 
think I should implement an actual FreeBSD CMOS RTC device which handles the 
three PNP IDs that represent those hardware devices, but this was good enough 
for what I was trying to do.

This fixes my HP Envy 6z-1100 laptop's suspend/resume (except video fails to 
resume, but I believe that's due to backlight handling from my research). 
Before, initiating a suspend (zzz(8)) caused the laptop to suspend and 
immediately resume. Now trying to track down the backlight issue. I implemented 
a missing _BQC method which returns a single value from the _BCL listj; I think 
Linux does some kind of vendor backlight control method if this method is 
missing.

Suggestions on the patch or backlight issue welcome.
Anthony Jenkins

diff --git a/source/components/events/evhandler.c 
b/source/components/events/evhandler.c
index d17411e..4f341ca 100644
--- a/source/components/events/evhandler.c
+++ b/source/components/events/evhandler.c
@@ -142,6 +142,7 @@ UINT8
AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
 ACPI_ADR_SPACE_SYSTEM_MEMORY,
 ACPI_ADR_SPACE_SYSTEM_IO,
 ACPI_ADR_SPACE_PCI_CONFIG,
+ACPI_ADR_SPACE_CMOS,
 ACPI_ADR_SPACE_DATA_TABLE
 };
 
@@ -451,9 +452,12 @@ AcpiEvInstallSpaceHandler (
  */
 if ((Node-Type != ACPI_TYPE_DEVICE) 
 (Node-Type != ACPI_TYPE_PROCESSOR)  
+(Node-Type != ACPI_TYPE_REGION) 
 (Node-Type != ACPI_TYPE_THERMAL)
 (Node != AcpiGbl_RootNode))
 {
+ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
+Device %p not a DEVICE, PROCESSOR, REGION, THERMAL type or root 
node.\n, Node));
 Status = AE_BAD_PARAMETER;
 goto UnlockAndExit;
 }
diff --git a/source/components/executer/exregion.c 
b/source/components/executer/exregion.c
index ea10a01..bfdd721 100644
--- a/source/components/executer/exregion.c
+++ b/source/components/executer/exregion.c
@@ -521,6 +521,20 @@ AcpiExPciConfigSpaceHandler (
 return_ACPI_STATUS (Status);
 }
 
+static UINT8 AcpiExCmosRead(ACPI_PHYSICAL_ADDRESS Address)
+{
+UINT32 Value32;
+
+AcpiHwWritePort((ACPI_IO_ADDRESS) 0x70, (UINT32) Address, 8);
+AcpiHwReadPort ((ACPI_IO_ADDRESS) 0x71, Value32, 8);
+return Value32  0xFF;
+}
+
+static void AcpiExCmosWrite(ACPI_PHYSICAL_ADDRESS Address, UINT8 Value)
+{
+AcpiHwWritePort((ACPI_IO_ADDRESS) 0x70, (UINT32) Address, 8);
+AcpiHwWritePort((ACPI_IO_ADDRESS) 0x71, (UINT32) Value, 8);
+}
 
 
/***
  *
@@ -545,7 +559,7 @@ AcpiExCmosSpaceHandler (
 UINT32  Function,
 ACPI_PHYSICAL_ADDRESS   Address,
 UINT32  BitWidth,
-UINT64  *Value,
+UINT64  *Value64,
 void*HandlerContext,
 void*RegionContext)
 {
@@ -554,7 +568,23 @@ AcpiExCmosSpaceHandler (
 
 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
 
-
+if (Address  0x80 
+(Function == ACPI_READ || Function == ACPI_WRITE) 
+BitWidth = 64)
+{
+UINT32 i;
+UINT8 *Value = (UINT8 *)Value64;
+
+for (i = 0; i  (BitWidth + 7) / 8; ++i, ++Address, ++Value) {
+if (Function == ACPI_READ) {
+*Value = AcpiExCmosRead(Address);
+} else {
+AcpiExCmosWrite(Address, *Value);
+}
+}
+} else {
+Status = AE_BAD_PARAMETER;
+}
 return_ACPI_STATUS (Status);
 }
 
diff --git a/source/include/acconfig.h b/source/include/acconfig.h
index 6b34484..7fe2eac 100644
--- a/source/include/acconfig.h
+++ b/source/include/acconfig.h
@@ -270,7 +270,7 @@
 /* Maximum SpaceIds for Operation Regions */
 
 #define ACPI_MAX_ADDRESS_SPACE  255
-#define ACPI_NUM_DEFAULT_SPACES 4
+#define ACPI_NUM_DEFAULT_SPACES 5
 
 /* Array sizes. Used for range checking also */
 
___
freebsd-acpi@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to freebsd-acpi-unsubscr...@freebsd.org


Re: Investigating failed suspend/resume T61

2014-06-07 Thread Edward Tomasz Napierała
With modem enabled?  I don't know; I don't see anything related to hdac0
during resume.  With modem disabled resuming is completely broken - it
fails _very_ early, by failing to return from acpi_machdep_sleep() iirc.

On 0607T1221, Adrian Chadd wrote:
 That's odd. Is it still trying to resume hdac0 ?
 
 
 -a
 
 
 On 6 June 2014 03:57, Edward Tomasz Napierała tr...@freebsd.org wrote:
  The difference in dmesg with (-) and without (+) the modem looks like this:
 
  --- dmesg.modem 2014-06-06 09:46:02.0 +0200
  +++ dmesg.bez   2014-06-06 09:52:45.0 +0200
  @@ -48,7 +48,7 @@ Event timer HPET1 frequency 14318180 H
   Event timer HPET2 frequency 14318180 Hz quality 440
   atrtc0: AT realtime clock port 0x70-0x71 irq 8 on acpi0
   Event timer RTC frequency 32768 Hz quality 0
  -Timecounter ACPI-fast frequency 3579545 Hz quality 900
  +Timecounter ACPI-safe frequency 3579545 Hz quality 850
   acpi_timer0: 24-bit timer at 3.579545MHz port 0x1008-0x100b on acpi0
   acpi_lid0: Control Method Lid Switch on acpi0
   acpi_button0: Sleep Button on acpi0
  @@ -157,12 +157,13 @@ est0: Enhanced SpeedStep Frequency Cont
   coretemp1: CPU On-Die Thermal Sensors on cpu1
   est1: Enhanced SpeedStep Frequency Control on cpu1
   Timecounters tick every 1.000 msec
  +hdac0: Command timeout on address 1
  +hdac0: Command timeout on address 1
  +hdac0: CODEC is not responding!
   hdacc0: Analog Devices AD1984 HDA CODEC at cad 0 on hdac0
   hdaa0: Analog Devices AD1984 Audio Function Group at nid 1 on hdacc0
   pcm0: Analog Devices AD1984 (Analog 2.0+HP/2.0) at nid 18,17 and 
  28,20,21 on hdaa0
   pcm1: Analog Devices AD1984 (Ext-Rear Digital) at nid 27 on hdaa0
  -hdacc1: Conexant (0x2bfa) HDA CODEC at cad 1 on hdac0
  -unknown: Conexant (0x2bfa) HDA CODEC Modem Function Group at nid 2 on 
  hdacc1 (no driver attached)
   random: unblocking device.
   usbus0: 12Mbps Full Speed USB v1.0
   usbus1: 12Mbps Full Speed USB v1.0
 
  Note that with modem disabled, it's not suspend that fails - it's the
  resuming.
 
  On 0605T2152, Adrian Chadd wrote:
  ok so when you disable the modem, does it still think there's a modem
  there? Is it still trying to power the device off via ACPI even though
  it's not probed?
 
 
  -a
 
 
  On 5 June 2014 10:50, Sean Bruno sbr...@ignoranthack.me wrote:
   On Wed, 2014-06-04 at 15:32 -0700, Adrian Chadd wrote:
   Hi,
  
   Please also document why it is/isn't working. It's only documented as
   suspend/resume doesn't work :)
  
  
   -a
  
  
   Well there's this that trasz updated to indicate that it works:
   https://wiki.freebsd.org/SuspendResume
  
   I just updated this to indicate the same information:
   https://wiki.freebsd.org/Laptops/Thinkpad_T61
  
   sean
  
___
freebsd-acpi@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to freebsd-acpi-unsubscr...@freebsd.org