Vinay Kalia | 7b3d7a0 | 2018-11-01 11:57:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H |
| 18 | #define ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H |
| 19 | |
| 20 | #include <android/hardware/power/stats/1.0/IPowerStats.h> |
| 21 | #include <fmq/MessageQueue.h> |
| 22 | #include <hidl/MQDescriptor.h> |
| 23 | #include <hidl/Status.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace power { |
| 28 | namespace stats { |
| 29 | namespace V1_0 { |
| 30 | namespace implementation { |
| 31 | |
| 32 | using ::android::hardware::hidl_vec; |
| 33 | using ::android::hardware::kSynchronizedReadWrite; |
| 34 | using ::android::hardware::Return; |
| 35 | using ::android::hardware::Void; |
| 36 | using ::android::hardware::power::stats::V1_0::EnergyData; |
| 37 | using ::android::hardware::power::stats::V1_0::PowerEntityInfo; |
| 38 | using ::android::hardware::power::stats::V1_0::PowerEntityStateInfo; |
| 39 | using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyData; |
| 40 | using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult; |
| 41 | using ::android::hardware::power::stats::V1_0::PowerEntityStateSpace; |
| 42 | using ::android::hardware::power::stats::V1_0::PowerEntityType; |
| 43 | using ::android::hardware::power::stats::V1_0::RailInfo; |
| 44 | using ::android::hardware::power::stats::V1_0::Status; |
| 45 | |
| 46 | typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync; |
| 47 | struct RailData { |
| 48 | std::string devicePath; |
| 49 | uint32_t index; |
| 50 | std::string subsysName; |
| 51 | uint32_t samplingRate; |
| 52 | }; |
| 53 | |
| 54 | struct OnDeviceMmt { |
| 55 | std::mutex mLock; |
| 56 | bool hwEnabled; |
| 57 | std::vector<std::string> devicePaths; |
| 58 | std::map<std::string, RailData> railsInfo; |
| 59 | std::vector<EnergyData> reading; |
| 60 | std::unique_ptr<MessageQueueSync> fmqSynchronized; |
| 61 | }; |
| 62 | |
| 63 | struct PowerStats : public IPowerStats { |
| 64 | PowerStats(); |
| 65 | // Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow. |
| 66 | Return<void> getRailInfo(getRailInfo_cb _hidl_cb) override; |
| 67 | Return<void> getEnergyData(const hidl_vec<uint32_t>& railIndices, |
| 68 | getEnergyData_cb _hidl_cb) override; |
| 69 | Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate, |
| 70 | streamEnergyData_cb _hidl_cb) override; |
| 71 | Return<void> getPowerEntityInfo(getPowerEntityInfo_cb _hidl_cb) override; |
| 72 | Return<void> getPowerEntityStateInfo(const hidl_vec<uint32_t>& powerEntityIds, |
| 73 | getPowerEntityStateInfo_cb _hidl_cb) override; |
| 74 | Return<void> getPowerEntityStateResidencyData( |
| 75 | const hidl_vec<uint32_t>& powerEntityIds, |
| 76 | getPowerEntityStateResidencyData_cb _hidl_cb) override; |
| 77 | |
| 78 | private: |
| 79 | OnDeviceMmt mPm; |
| 80 | void findIioPowerMonitorNodes(); |
| 81 | size_t parsePowerRails(); |
| 82 | int parseIioEnergyNode(std::string devName); |
| 83 | Status parseIioEnergyNodes(); |
| 84 | }; |
| 85 | |
| 86 | } // namespace implementation |
| 87 | } // namespace V1_0 |
| 88 | } // namespace stats |
| 89 | } // namespace power |
| 90 | } // namespace hardware |
| 91 | } // namespace android |
| 92 | |
| 93 | #endif // ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H |