blob: fb2c6a8ce58e05dfe8a465fe56a96f7519828422 [file] [log] [blame]
Vinay Kalia7b3d7a02018-11-01 11:57:40 -07001/*
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
25namespace android {
26namespace hardware {
27namespace power {
28namespace stats {
29namespace V1_0 {
30namespace implementation {
31
32using ::android::hardware::hidl_vec;
33using ::android::hardware::kSynchronizedReadWrite;
34using ::android::hardware::Return;
35using ::android::hardware::Void;
36using ::android::hardware::power::stats::V1_0::EnergyData;
37using ::android::hardware::power::stats::V1_0::PowerEntityInfo;
38using ::android::hardware::power::stats::V1_0::PowerEntityStateInfo;
39using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyData;
40using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult;
41using ::android::hardware::power::stats::V1_0::PowerEntityStateSpace;
42using ::android::hardware::power::stats::V1_0::PowerEntityType;
43using ::android::hardware::power::stats::V1_0::RailInfo;
44using ::android::hardware::power::stats::V1_0::Status;
45
46typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync;
47struct RailData {
48 std::string devicePath;
49 uint32_t index;
50 std::string subsysName;
51 uint32_t samplingRate;
52};
53
54struct 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
63struct 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