Changeset 443


Ignore:
Timestamp:
Feb 20, 2019, 7:55:27 AM (6 years ago)
Author:
rlwalsh
Message:

acpih: add CPU temperature support; update battery support
patch from David Azarewicz

Location:
branches/branch-1-0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/include/helpers/acpih.h

    r429 r443  
    6666
    6767    VOID APIENTRY acpihClose(ACPI_API_HANDLE *phACPI);
     68    typedef APIRET APIENTRY ACPIHCLOSE(ACPI_API_HANDLE *phACPI);
     69    typedef ACPIHCLOSE *PACPIHCLOSE;
    6870
    6971    //@added V1.0.10 (2014-08-30) [dazarewicz]
     
    7476    typedef APIRET APIENTRY ACPIHGETPOWERSTATUS(PAPM, PBOOL);
    7577    typedef ACPIHGETPOWERSTATUS *PACPIHGETPOWERSTATUS;
     78
     79    ULONG APIENTRY acpihGetCpuTemp(ACPI_API_HANDLE *phACPI);
     80    typedef ULONG APIENTRY ACPIHGETCPUTEMP(ACPI_API_HANDLE *phACPI);
     81    typedef ACPIHGETCPUTEMP *PACPIHGETCPUTEMP;
    7682
    7783    BOOL acpihHasBattery(VOID);
  • branches/branch-1-0/src/helpers/acpih.c

    r438 r443  
    5454// @@added V1.0.9 (2012-02-20) [slevine]: additional ACPI support, code from David Azarewicz
    5555ACPI_HANDLE   G_ahAC = 0;
     56ACPI_HANDLE   G_ahTemp = 0;
     57ULONG         G_uiTempWalked = 0;
    5658#define MAX_BATTERY_COUNT 4
    57 ACPI_HANDLE   G_ahBat[MAX_BATTERY_COUNT];
     59struct _gahbat_ {
     60    ACPI_HANDLE ahBat;
     61    ULONG ulLastFull;
     62} G_Bat[MAX_BATTERY_COUNT];
    5863ULONG         G_uiBatteryCount = 0;
    5964ULONG         G_uiAlreadyWalked = 0;
     
    202207}
    203208
     209    // VAC 3.08 long long compatibility support
     210#ifdef INCL_LONGLONG // VAC 3.6.5 - compiler supports long long
     211#define OBJECT_VALUE(index)  (Object[index].Integer.Value)
     212#define OBJ_VALUE(index)  (pObj[index].Integer.Value)
     213#else // VAC 3.08 - compiler does not support long long
     214#define OBJECT_VALUE(index)  (Object[index].Integer.Value.ulLo)
     215#define OBJ_VALUE(index)  (pObj[index].Integer.Value.ulLo)
     216#endif
    204217
    205218/**
     
    214227{
    215228    ACPI_DEVICE_INFO *pDevInfo = NULL;
     229    ACPI_BUFFER Buffer;
     230    ACPI_OBJECT *pObj, Object[25];
    216231
    217232    if (pAcpiTkGetObjectInfoAlloc( ObjHandle, &pDevInfo ) != AE_OK)
     
    240255        { /* Smart battery */
    241256            if (G_uiBatteryCount < MAX_BATTERY_COUNT)
    242                 G_ahBat[G_uiBatteryCount++] = ObjHandle;
     257            {
     258                G_Bat[G_uiBatteryCount].ahBat = ObjHandle;
     259                G_Bat[G_uiBatteryCount].ulLastFull = 0xffffffff;
     260
     261                /* Get static battery inFormation */
     262                Buffer.Length = sizeof(Object);
     263                Buffer.Pointer = Object;
     264                if (pAcpiTkEvaluateObject(ObjHandle, "_BIX", NULL, &Buffer) == AE_OK)
     265                {
     266                    pObj = Buffer.Pointer;
     267                    pObj = (ACPI_OBJECT *)pObj[0].Package.Elements;
     268                    G_Bat[G_uiBatteryCount].ulLastFull = (UINT32)OBJ_VALUE(3);
     269                }
     270                else
     271                {
     272                    Buffer.Length = sizeof(Object);
     273                    Buffer.Pointer = Object;
     274                    if (pAcpiTkEvaluateObject(ObjHandle, "_BIF", NULL, &Buffer) == AE_OK)
     275                    {
     276                        pObj = Buffer.Pointer;
     277                        pObj = (ACPI_OBJECT *)pObj[0].Package.Elements;
     278                        G_Bat[G_uiBatteryCount].ulLastFull = (UINT32)OBJ_VALUE(2);
     279                    }
     280                }
     281
     282                G_uiBatteryCount++;
     283            }
    243284
    244285            break;
     
    265306    ACPI_STATUS Status;
    266307    ACPI_BUFFER Result;
    267     ACPI_OBJECT *Obj, Object[20];
     308    ACPI_OBJECT *pObj, Object[20];
    268309    UINT32 uiI;
    269     ULONG ulTmp, BRemaining, LastFull;
     310    ULONG ulTmp, BRemaining;
    270311    BOOL fChanged;
    271312
     
    292333    fChanged = FALSE;
    293334
    294     // VAC 3.08 long long compatibility support
    295 #ifdef INCL_LONGLONG // VAC 3.6.5 - compiler supports long long
    296 #define OBJECT_VALUE(index)  (Object[index].Integer.Value)
    297 #define OBJ_VALUE(index)  (Obj[index].Integer.Value)
    298 #else // VAC 3.08 - compiler does not support long long
    299 #define OBJECT_VALUE(index)  (Object[index].Integer.Value.ulLo)
    300 #define OBJ_VALUE(index)  (Obj[index].Integer.Value.ulLo)
    301 #endif
    302 
    303335    if (G_ahAC)
    304336    {
     
    323355    for (uiI=0; uiI < G_uiBatteryCount; uiI++)
    324356    {
    325         if (G_ahBat[uiI] == 0)
     357        if (G_Bat[uiI].ahBat == 0)
    326358            continue;
    327 
    328         Result.Length = sizeof(Object);
    329         Result.Pointer = Object;
    330         // Get battery info
    331         Status = pAcpiTkEvaluateObject(G_ahBat[uiI], "_BIF", NULL, &Result);
    332         if (Status != AE_OK)
    333         {
    334             G_ahBat[uiI] = 0;
     359        if (G_Bat[uiI].ulLastFull == 0xffffffff)
    335360            continue;
    336         }
    337 
    338         Obj = Result.Pointer;
    339         Obj = (ACPI_OBJECT *)Obj[0].Package.Elements;   // Battery info package
    340         LastFull = (UINT32)OBJ_VALUE(2);
    341361
    342362        Result.Length = sizeof(Object);
    343363        Result.Pointer = Object;
    344364        // Get battery status
    345         Status = pAcpiTkEvaluateObject(G_ahBat[uiI], "_BST", NULL, &Result);
     365        Status = pAcpiTkEvaluateObject(G_Bat[uiI].ahBat, "_BST", NULL, &Result);
    346366        if (Status != AE_OK)
    347367        {
    348             G_ahBat[uiI] = 0;
     368            G_Bat[uiI].ahBat = 0;
    349369            continue;
    350370        }
    351371
    352         Obj = Result.Pointer;
    353         Obj = (ACPI_OBJECT *)Obj[0].Package.Elements;   // Battery status package
     372        pObj = Result.Pointer;
     373        pObj = (ACPI_OBJECT *)pObj[0].Package.Elements;   // Battery status package
    354374        BRemaining = (UINT32)OBJ_VALUE(2);
    355375
    356376        // If battery units are mWh or mAh
    357377        // If not, it is a percentage
    358         if (    (LastFull != 0xffffffff)
    359              && (BRemaining != 0xffffffff)
    360            )
     378        if (BRemaining == 0xffffffff)
     379            continue;
     380
     381        if (BRemaining > (G_Bat[uiI].ulLastFull >> 1)) // > 50% is high. < 50% is low
     382            ulTmp = 1; // High
     383        else
     384            ulTmp = 2; // Low
     385
     386        if (OBJ_VALUE(0) & 4)
     387            ulTmp = 2; // Critical
     388
     389        // If battery charging - it can't be critical
     390        if (OBJ_VALUE(0) & 2)
     391            ulTmp = 3; // Charging
     392
     393        if (pApm->bBatteryStatus != ulTmp)
    361394        {
    362             if (BRemaining > (LastFull >> 1)) // > 50% is high. < 50% is low
    363                 ulTmp = 1; // High
    364             else
    365                 ulTmp = 2; // Low
    366 
    367             if (OBJ_VALUE(0) & 4)
    368                 ulTmp = 2; // Critical
    369 
    370             // If battery charging - it can't be critical
    371             if (OBJ_VALUE(0) & 2)
    372                 ulTmp = 3; // Charging
    373 
    374             if (pApm->bBatteryStatus != ulTmp)
    375             {
    376                 pApm->bBatteryStatus = (BYTE)ulTmp;
    377                 fChanged = TRUE;
    378             }
    379 
    380             ulTmp = 0;
    381             if (LastFull)
    382                 ulTmp = (BRemaining*100) / LastFull;
    383             if (ulTmp > 100)
    384                 ulTmp = 100;
    385 
    386             if (pApm->bBatteryLife != ulTmp)
    387             {
    388                 pApm->bBatteryLife = (BYTE) ulTmp;
    389                 fChanged = TRUE;
    390             }
     395            pApm->bBatteryStatus = (BYTE)ulTmp;
     396            fChanged = TRUE;
     397        }
     398
     399        ulTmp = 0;
     400        if (G_Bat[uiI].ulLastFull)
     401            ulTmp = (BRemaining*100) / G_Bat[uiI].ulLastFull;
     402        if (ulTmp > 100)
     403            ulTmp = 100;
     404
     405        if (pApm->bBatteryLife != ulTmp)
     406        {
     407            pApm->bBatteryLife = (BYTE) ulTmp;
     408            fChanged = TRUE;
    391409        }
    392410    }
     
    397415    pApm->fAlreadyRead = FALSE;
    398416    return 0;
     417}
    399418
    400419#undef OBJECT_VALUE
    401420#undef OBJ_VALUE
    402 }
    403421
    404422/*
     
    428446}
    429447
     448/**
     449 *@@ AcpiCallbackTemperature:
     450 *      ACPI callback helper for CPU Temperature
     451 *      Code provided by David Azarewicz
     452 */
     453
     454ACPI_STATUS APIENTRY AcpiCallbackTemperature( ACPI_HANDLE ObjHandle, UINT32 NestingLevel, void *Context, void **ReturnValue )
     455{
     456    if (G_ahTemp)
     457        return AE_OK;
     458
     459    if (pAcpiTkGetHandle(ObjHandle, "_TMP", &G_ahTemp))
     460        G_ahTemp = 0;
     461
     462    return AE_OK;
     463}
     464
     465/*
     466 *@@ acpihGetCpuTemp:
     467 *      Code provided by David Azarewicz.
     468 */
     469ULONG acpihGetCpuTemp(ACPI_API_HANDLE *phACPI)
     470{
     471    ACPI_STATUS Status;
     472    ACPI_BUFFER Result;
     473    ACPI_OBJECT Object;
     474    ULONG ulTemp = 0;
     475
     476    /* Make sure all the functions we need have valid pointers. */
     477    if (   (pAcpiTkWalkNamespace == NULL)
     478        || (pAcpiTkGetHandle == NULL)
     479        || (pAcpiTkEvaluateObject == NULL)
     480       )
     481        return 1;
     482
     483    if (!G_uiTempWalked)
     484    {
     485        Status = pAcpiTkWalkNamespace(ACPI_TYPE_THERMAL, ACPI_ROOT_OBJECT,
     486                                      ACPI_UINT32_MAX, AcpiCallbackTemperature,
     487                                      NULL, NULL);
     488        G_uiTempWalked = 1;
     489    }
     490
     491    if (G_ahTemp)
     492    {
     493        Result.Length = sizeof(Object);
     494        Result.Pointer = &Object;
     495        Status = pAcpiTkEvaluateObject(G_ahTemp, NULL, NULL, &Result);
     496        if (Status == AE_OK)
     497            ulTemp = (Object.Integer.Value - 2732) / 10;
     498    }
     499
     500    return ulTemp;
     501}
     502
Note: See TracChangeset for help on using the changeset viewer.