Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
- Fix some memory leaks
- Direct ACPI messaging
  • Loading branch information
hieplpvip committed Jun 11, 2019
1 parent cb026c0 commit 7964f1b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 49 deletions.
12 changes: 6 additions & 6 deletions AsusSMC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MODULE_VERSION = 1.1;
MODULE_VERSION = 1.1.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -622,7 +622,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MODULE_VERSION = 1.1;
MODULE_VERSION = 1.1.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand All @@ -633,7 +633,7 @@
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.1;
CURRENT_PROJECT_VERSION = 1.1.1;
GCC_PREPROCESSOR_DEFINITIONS = (
"MODULE_VERSION=$(MODULE_VERSION)",
"PRODUCT_NAME=$(PRODUCT_NAME)",
Expand All @@ -651,7 +651,7 @@
MODULE_NAME = com.hieplpvip.AsusSMC;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.1;
MODULE_VERSION = 1.1.1;
OTHER_CPLUSPLUSFLAGS = "-Wno-inconsistent-missing-override";
PRODUCT_BUNDLE_IDENTIFIER = com.hieplpvip.AsusSMC;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -663,7 +663,7 @@
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.1;
CURRENT_PROJECT_VERSION = 1.1.1;
GCC_PREPROCESSOR_DEFINITIONS = (
"MODULE_VERSION=$(MODULE_VERSION)",
"PRODUCT_NAME=$(PRODUCT_NAME)",
Expand All @@ -681,7 +681,7 @@
MODULE_NAME = com.hieplpvip.AsusSMC;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.1;
MODULE_VERSION = 1.1.1;
OTHER_CPLUSPLUSFLAGS = "-Wno-inconsistent-missing-override";
PRODUCT_BUNDLE_IDENTIFIER = com.hieplpvip.AsusSMC;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
67 changes: 29 additions & 38 deletions AsusSMC/AsusSMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,16 @@ bool AsusSMC::start(IOService *provider) {
}

atkDevice = (IOACPIPlatformDevice *) provider;
atkDevice->evaluateObject("INIT", NULL, NULL, NULL);

OSNumber *arg = OSNumber::withNumber(1, 8);
atkDevice->evaluateObject("INIT", NULL, (OSObject**)&arg, 1);
arg->release();

SYSLOG("atk", "Found WMI Device %s", atkDevice->getName());

parse_wdg(properties);

checkKBALS();
checkATK();

initVirtualKeyboard();

Expand Down Expand Up @@ -297,37 +300,20 @@ IOReturn AsusSMC::setPowerState(unsigned long powerStateOrdinal, IOService *what

IOReturn AsusSMC::message(UInt32 type, IOService *provider, void *argument) {
if (type == kIOACPIMessageDeviceNotification) {
OSObject *wed;
UInt32 event = *((UInt32 *) argument);
OSNumber *number = OSNumber::withNumber(event, 32);
atkDevice->evaluateObject("_WED", &wed, (OSObject**)&number, 1);
number->release();
number = OSDynamicCast(OSNumber, wed);
if (!number) {
// try a package
OSArray *array = OSDynamicCast(OSArray, wed);
if (!array) {
// try a buffer
OSData *data = OSDynamicCast(OSData, wed);
if ((!data) || (data->getLength() == 0)) {
DBGLOG("atk", "Fail to cast _WED returned objet %s", wed->getMetaClass()->getClassName());
return kIOReturnError;
}
const char *bytes = (const char *) data->getBytesNoCopy();
number = OSNumber::withNumber(bytes[0],32);
} else {
number = OSDynamicCast(OSNumber, array->getObject(0));
if (!number) {
DBGLOG("atk", "Fail to cast _WED returned 1st objet in array %s", array->getObject(0)->getMetaClass()->getClassName());
return kIOReturnError;
}
}
}
if (directACPImessaging) {
handleMessage(*((UInt32 *) argument));
} else {
UInt32 event = *((UInt32 *) argument);
OSNumber *arg = OSNumber::withNumber(event, sizeof(event) * 8);
UInt32 res;
atkDevice->evaluateInteger("_WED", &res, (OSObject**)&arg, 1);
arg->release();

handleMessage(number->unsigned32BitValue());
}
else
handleMessage(res);
}
} else {
DBGLOG("atk", "Unexpected message: %u Type %x Provider %s", *((UInt32 *) argument), uint(type), provider->getName());
}

return kIOReturnSuccess;
}
Expand Down Expand Up @@ -439,7 +425,13 @@ void AsusSMC::handleMessage(int code) {
DBGLOG("atk", "Received key %d(0x%x)", code, code);
}

void AsusSMC::checkKBALS() {
void AsusSMC::checkATK() {
// Check direct ACPI messaging support
if (atkDevice->validateObject("DMES") == kIOReturnSuccess) {
DBGLOG("atk", "Direct ACPI message is supported");
directACPImessaging = true;
}

// Check keyboard backlight support
if (atkDevice->validateObject("SKBV") == kIOReturnSuccess) {
SYSLOG("atk", "Keyboard backlight is supported");
Expand All @@ -465,15 +457,14 @@ void AsusSMC::checkKBALS() {
}

void AsusSMC::toggleALS(bool state) {
OSObject *params[1];
params[0] = OSNumber::withNumber(state, 8);

UInt32 res;
if (atkDevice->evaluateInteger("ALSC", &res, params, 1) == kIOReturnSuccess)
OSNumber *arg = OSNumber::withNumber(state, sizeof(state) * 8);
if (atkDevice->evaluateInteger("ALSC", &res, (OSObject**)&arg, 1) == kIOReturnSuccess)
DBGLOG("atk", "ALS has been %s (ALSC ret %d)", state ? "enabled" : "disabled", res);
else
DBGLOG("atk", "Failed to call ALSC");
setProperty("IsALSEnabled", state);
arg->release();
}

int AsusSMC::checkBacklightEntry() {
Expand Down Expand Up @@ -561,7 +552,7 @@ void AsusSMC::initVirtualKeyboard() {
_virtualKBrd = new VirtualHIDKeyboard;

if (!_virtualKBrd || !_virtualKBrd->init() || !_virtualKBrd->attach(this) || !_virtualKBrd->start(this)) {
_virtualKBrd->release();
OSSafeReleaseNULL(_virtualKBrd);
SYSLOG("virtkbrd", "Failed to init VirtualHIDKeyboard");
} else
_virtualKBrd->setCountryCode(0);
Expand Down Expand Up @@ -662,7 +653,7 @@ void AsusSMC::dispatchMessage(int message, void *data) {
}

#pragma mark -
#pragma mark VirtualSMC plugin
#pragma mark VirtualSMC plugin - Ported from SMCLightSensor
#pragma mark -

void AsusSMC::registerVSMC() {
Expand Down
9 changes: 8 additions & 1 deletion AsusSMC/AsusSMC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ class EXPORT AsusSMC : public IOService {
*/
bool hasKeybrdBLight {false};

/**
* Direct ACPI messaging support
* Originally, receiving ACPI messages takes several unnecessary steps (thanks, ASUS!)
* By patching method IANE in DSDT, we can avoid those steps
*/
bool directACPImessaging {false};

/**
* ALS availability
*/
Expand All @@ -200,7 +207,7 @@ class EXPORT AsusSMC : public IOService {
/**
* Check ALS and keyboard backlight availability
*/
void checkKBALS();
void checkATK();

/**
* Enable/Disable ALS sensor
Expand Down
7 changes: 3 additions & 4 deletions AsusSMC/KeyImplementations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ SMC_RESULT SMCKBrdBLightValue::update(const SMC_DATA *src) {
uint16_t tval = (value->val1 << 4) | (value->val2 >> 4);
DBGLOG("kbrdblight", "LKSB update %d", tval);
tval = tval / 16;
OSObject *params[1];
OSObject *ret = NULL;
params[0] = OSNumber::withNumber(tval, sizeof(tval) * 8);

atkDevice->evaluateObject("SKBV", &ret, params, 1);
OSNumber *arg = OSNumber::withNumber(tval, sizeof(tval) * 8);
atkDevice->evaluateObject("SKBV", NULL, (OSObject**)&arg, 1);
arg->release();
}
delete value;

Expand Down

0 comments on commit 7964f1b

Please sign in to comment.