From c1875b5a3364f679a4ae482dfe5bdc4f3538e207 Mon Sep 17 00:00:00 2001 From: John Stultz Date: Tue, 20 Nov 2018 16:15:20 -0800 Subject: HiKey/HiKey960: Rework HiKey PowerHAL to use power@1.1 interface This reworks the old power.hikey[960].so poewrHAL library to implement the power@1.1-service interface. Much of this change is taken from the marlin implementation. Change-Id: I7cc4068a28dfb48348b18024b00ff53526e189af Signed-off-by: John Stultz --- device-common.mk | 5 +- manifest.xml | 4 +- power/Android.mk | 27 ++++-- power/Power.cpp | 97 ++++++++++++++++++++++ power/Power.h | 61 ++++++++++++++ ...roid.hardware.power@1.1-service.hikey-common.rc | 4 + power/power-helper.h | 46 ++++++++++ power/power_hikey.c | 91 ++++---------------- power/service.cpp | 67 +++++++++++++++ sepolicy/file_contexts | 2 + sepolicy/hal_power.te | 9 ++ 11 files changed, 328 insertions(+), 85 deletions(-) create mode 100644 power/Power.cpp create mode 100644 power/Power.h create mode 100644 power/android.hardware.power@1.1-service.hikey-common.rc create mode 100644 power/power-helper.h create mode 100644 power/service.cpp create mode 100644 sepolicy/hal_power.te diff --git a/device-common.mk b/device-common.mk index 40cb0e39..12d3d0ef 100644 --- a/device-common.mk +++ b/device-common.mk @@ -95,7 +95,9 @@ PRODUCT_PACKAGES += android.hardware.bluetooth@1.0-service.btlinux endif # PowerHAL -PRODUCT_PACKAGES += android.hardware.power@1.0-impl +PRODUCT_PACKAGES += \ + android.hardware.power@1.1-impl \ + android.hardware.power@1.1-service.hikey-common #GNSS HAL PRODUCT_PACKAGES += \ @@ -228,7 +230,6 @@ PRODUCT_PACKAGES += \ android.hardware.graphics.allocator@2.0.vndk-sp\ android.hardware.graphics.mapper@2.0.vndk-sp\ android.hardware.graphics.common@1.0.vndk-sp\ - android.hardware.power@1.0.vndk-sp\ libvndksupport.vndk-sp\ libbinder.vndk-sp\ libhwbinder.vndk-sp\ diff --git a/manifest.xml b/manifest.xml index 4c5d3423..84d82e98 100644 --- a/manifest.xml +++ b/manifest.xml @@ -122,8 +122,8 @@ android.hardware.power - passthrough - 1.0 + hwbinder + 1.1 IPower default diff --git a/power/Android.mk b/power/Android.mk index 53e464ec..ca184db3 100644 --- a/power/Android.mk +++ b/power/Android.mk @@ -19,13 +19,28 @@ LOCAL_PATH := $(call my-dir) # hw/..so include $(CLEAR_VARS) -LOCAL_SHARED_LIBRARIES := liblog libcutils -LOCAL_SRC_FILES := power_hikey.c - LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_TAGS := optional + +LOCAL_MODULE := android.hardware.power@1.1-service.hikey-common +LOCAL_INIT_RC := android.hardware.power@1.1-service.hikey-common.rc +LOCAL_SRC_FILES := service.cpp Power.cpp power_hikey.c + +#LOCAL_MODULE := power.$(TARGET_BOARD_PLATFORM) +#LOCAL_SRC_FILES := power_hikey.c LOCAL_HEADER_LIBRARIES += libhardware_headers -LOCAL_MODULE := power.$(TARGET_BOARD_PLATFORM) -LOCAL_MODULE_TAGS := optional -include $(BUILD_SHARED_LIBRARY) + +LOCAL_SHARED_LIBRARIES := liblog libcutils + +LOCAL_SHARED_LIBRARIES := \ + libbase \ + libcutils \ + libhidlbase \ + libhidltransport \ + liblog \ + libutils \ + android.hardware.power@1.1 \ + +include $(BUILD_EXECUTABLE) diff --git a/power/Power.cpp b/power/Power.cpp new file mode 100644 index 00000000..28f096af --- /dev/null +++ b/power/Power.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.power@1.1-service.hikey-common" + +#include +#include + +#include + +#include "Power.h" +#include "power-helper.h" + +enum subsystem_type { + //Don't add any lines after that line + SUBSYSTEM_COUNT +}; + + +namespace android { +namespace hardware { +namespace power { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::power::V1_0::Feature; +using ::android::hardware::power::V1_0::PowerHint; +using ::android::hardware::power::V1_0::PowerStatePlatformSleepState; +using ::android::hardware::power::V1_0::Status; +using ::android::hardware::power::V1_1::PowerStateSubsystem; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; + +Power::Power() { + power_init(); +} + +// Methods from ::android::hardware::power::V1_0::IPower follow. +Return Power::setInteractive(bool interactive) { + power_set_interactive(interactive ? 1 : 0); + return Void(); +} + +Return Power::powerHint(PowerHint hint, int32_t data) { + power_hint(static_cast(hint), data ? (&data) : NULL); + return Void(); +} + +Return Power::setFeature(Feature /*feature*/, bool /*activate*/) { + return Void(); +} + +Return Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) { + + hidl_vec states; + + _hidl_cb(states, Status::SUCCESS); + return Void(); +} + + +Return Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) { + + hidl_vec subsystems; + subsystems.resize(subsystem_type::SUBSYSTEM_COUNT); + + //Add query for other subsystems here + + _hidl_cb(subsystems, Status::SUCCESS); + return Void(); +} + +Return Power::powerHintAsync(PowerHint hint, int32_t data) { + // just call the normal power hint in this oneway function + return powerHint(hint, data); + return Void(); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace power +} // namespace hardware +} // namespace android diff --git a/power/Power.h b/power/Power.h new file mode 100644 index 00000000..2676b7d3 --- /dev/null +++ b/power/Power.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_POWER_V1_1_POWER_H +#define ANDROID_HARDWARE_POWER_V1_1_POWER_H + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace power { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::power::V1_0::Feature; +using ::android::hardware::power::V1_0::PowerHint; +using ::android::hardware::power::V1_1::IPower; +using ::android::hardware::Return; +using ::android::hardware::Void; + +struct Power : public IPower { + // Methods from ::android::hardware::power::V1_0::IPower follow. + + Power(); + + Return setInteractive(bool interactive) override; + Return powerHint(PowerHint hint, int32_t data) override; + Return setFeature(Feature feature, bool activate) override; + Return getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) override; + + // Methods from ::android::hardware::power::V1_1::IPower follow. + Return getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) override; + Return powerHintAsync(PowerHint hint, int32_t data) override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. + +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace power +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_POWER_V1_1_POWER_H diff --git a/power/android.hardware.power@1.1-service.hikey-common.rc b/power/android.hardware.power@1.1-service.hikey-common.rc new file mode 100644 index 00000000..4a1e1e15 --- /dev/null +++ b/power/android.hardware.power@1.1-service.hikey-common.rc @@ -0,0 +1,4 @@ +service vendor.power-hal-1-1 /vendor/bin/hw/android.hardware.power@1.1-service.hikey-common + class hal + user system + group system diff --git a/power/power-helper.h b/power/power-helper.h new file mode 100644 index 00000000..1c3ae980 --- /dev/null +++ b/power/power-helper.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __POWER_HELPER_H__ +#define __POWER_HELPER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void power_init(void); +void power_hint(power_hint_t hint, void *data); +void power_set_interactive(int on); + +#ifdef __cplusplus +} +#endif + +#endif //__POWER_HELPER_H__ diff --git a/power/power_hikey.c b/power/power_hikey.c index f9a3ddb6..a2eb3732 100644 --- a/power/power_hikey.c +++ b/power/power_hikey.c @@ -36,6 +36,8 @@ #include #include +#include "power-helper.h" + #define SCHEDTUNE_BOOST_PATH "/dev/stune/top-app/schedtune.boost" #define SCHEDTUNE_BOOST_VAL_PROP "ro.config.schetune.touchboost.value" #define SCHEDTUNE_BOOST_TIME_PROP "ro.config.schetune.touchboost.time_ns" @@ -79,6 +81,8 @@ struct hikey_power_module { sem_t signal_lock; }; +struct hikey_power_module this_power_module; + static bool low_power_mode = false; @@ -248,7 +252,7 @@ static void hikey_devfreq_init(struct hikey_power_module __unused *hikey) /*[schedtune functions]*******************************************************/ -int schedtune_sysfs_boost(struct hikey_power_module *hikey, char* booststr) +static int schedtune_sysfs_boost(struct hikey_power_module *hikey, char* booststr) { char buf[80]; int len; @@ -348,7 +352,7 @@ static void schedtune_power_init(struct hikey_power_module *hikey) /*[generic functions]*********************************************************/ -static void hikey_cpufreq_set_interactive(struct power_module __unused *module, int on) +void power_set_interactive(int on) { int i; @@ -396,10 +400,14 @@ static void hikey_cpufreq_init(struct hikey_power_module __unused *hikey) max_clusters = i; } -static void hikey_power_init(struct power_module __unused *module) +void power_init(void) { - struct hikey_power_module *hikey = container_of(module, - struct hikey_power_module, base); + struct hikey_power_module *hikey = &this_power_module; + memset(hikey, 0, sizeof(struct hikey_power_module)); + pthread_mutex_init(&hikey->lock, NULL); + hikey->boostpulse_fd = -1; + hikey->boostpulse_warned = 0; + hikey_cpufreq_init(hikey); hikey_devfreq_init(hikey); interactive_power_init(hikey); @@ -416,11 +424,9 @@ static void hikey_hint_interaction(struct hikey_power_module *mod) return; } -static void hikey_power_hint(struct power_module *module, power_hint_t hint, - void *data) +void power_hint(power_hint_t hint, void *data) { - struct hikey_power_module *hikey = container_of(module, - struct hikey_power_module, base); + struct hikey_power_module *hikey = &this_power_module; pthread_mutex_lock(&hikey->lock); switch (hint) { @@ -433,7 +439,7 @@ static void hikey_power_hint(struct power_module *module, power_hint_t hint, case POWER_HINT_LOW_POWER: low_power_mode = data; - hikey_cpufreq_set_interactive(module, 1); + power_set_interactive(1); break; default: @@ -441,68 +447,3 @@ static void hikey_power_hint(struct power_module *module, power_hint_t hint, } pthread_mutex_unlock(&hikey->lock); } - -static void set_feature(struct power_module __unused *module, - feature_t feature, int state) -{ - switch (feature) { - default: - ALOGW("Error setting the feature %d and state %d, it doesn't exist\n", - feature, state); - break; - } -} - -static int power_open(const hw_module_t* __unused module, const char* name, - hw_device_t** device) -{ - int retval = 0; /* 0 is ok; -1 is error */ - ALOGD("%s: enter; name=%s", __FUNCTION__, name); - - if (strcmp(name, POWER_HARDWARE_MODULE_ID) == 0) { - struct hikey_power_module *dev = (struct hikey_power_module *)calloc(1, - sizeof(struct hikey_power_module)); - - if (dev) { - /* Common hw_device_t fields */ - dev->base.common.tag = HARDWARE_DEVICE_TAG; - dev->base.common.module_api_version = POWER_MODULE_API_VERSION_0_5; - dev->base.common.hal_api_version = HARDWARE_HAL_API_VERSION; - - dev->base.init = hikey_power_init; - dev->base.powerHint = hikey_power_hint; - dev->base.setInteractive = hikey_cpufreq_set_interactive; - dev->base.setFeature = set_feature; - - pthread_mutex_init(&dev->lock, NULL); - dev->boostpulse_fd = -1; - dev->boostpulse_warned = 0; - - *device = (hw_device_t*)&dev->base; - } else - retval = -ENOMEM; - } else { - retval = -EINVAL; - } - - ALOGD("%s: exit %d", __FUNCTION__, retval); - return retval; -} - -static struct hw_module_methods_t power_module_methods = { - .open = power_open, -}; - -struct hikey_power_module HAL_MODULE_INFO_SYM = { - .base = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .module_api_version = POWER_MODULE_API_VERSION_0_2, - .hal_api_version = HARDWARE_HAL_API_VERSION, - .id = POWER_HARDWARE_MODULE_ID, - .name = "HiKey Power HAL", - .author = "The Android Open Source Project", - .methods = &power_module_methods, - }, - }, -}; diff --git a/power/service.cpp b/power/service.cpp new file mode 100644 index 00000000..3cb0b687 --- /dev/null +++ b/power/service.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.power@1.1-service.hikey-common" + +#include +#include +#include +#include "Power.h" + +using android::sp; +using android::status_t; +using android::OK; + +// libhwbinder: +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +// Generated HIDL files +using android::hardware::power::V1_1::IPower; +using android::hardware::power::V1_1::implementation::Power; + +int main() { + + status_t status; + android::sp service = nullptr; + + ALOGI("Power HAL Service 1.1 for HiKey-common is starting."); + + service = new Power(); + if (service == nullptr) { + ALOGE("Can not create an instance of Power HAL Iface, exiting."); + + goto shutdown; + } + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + status = service->registerAsService(); + if (status != OK) { + ALOGE("Could not register service for Power HAL Iface (%d).", status); + goto shutdown; + } + + ALOGI("Power Service is ready"); + joinRpcThreadpool(); + //Should not pass this line + +shutdown: + // In normal operation, we don't expect the thread pool to exit + + ALOGE("Power Service is shutting down"); + return 1; +} diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index dacdb9f4..52a29e50 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -34,6 +34,8 @@ /dev/block/platform/soc/f723d000\.dwmmc0/by-name/userdata u:object_r:userdata_block_device:s0 +/vendor/bin/hw/android\.hardware\.power@1\.1-service\.hikey-common u:object_r:hal_power_default_exec:s0 + /vendor/lib(64)?/libRSDriverArm\.so u:object_r:same_process_hal_file:s0 /vendor/lib64/libbccArm\.so u:object_r:same_process_hal_file:s0 /vendor/lib64/libbcc\.so u:object_r:same_process_hal_file:s0 diff --git a/sepolicy/hal_power.te b/sepolicy/hal_power.te new file mode 100644 index 00000000..476a6037 --- /dev/null +++ b/sepolicy/hal_power.te @@ -0,0 +1,9 @@ +typeattribute hal_power_default data_between_core_and_vendor_violators; + +allow hal_power_default cgroup:dir search; +allow hal_power_default cgroup:file rw_file_perms; + +allow hal_power_default sysfs_devices_system_cpu:file rw_file_perms; +allow hal_power_default sysfs_power:file rw_file_perms; + + -- cgit v1.2.3