1 /* 2 * Copyright (C) 2022 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 #pragma once 18 19 #include <android/frameworks/stats/VendorAtom.h> 20 #include <lk/compiler.h> 21 #include <sys/types.h> 22 #include <atomic> 23 24 using namespace android::frameworks::stats; 25 26 #ifndef PAGE_SIZE 27 #define PAGE_SIZE 0x1000 28 #endif 29 #define TIME_OUT_INTERVAL_MS 10 30 #define MS_TO_NS(x) ((x)*1000000ULL) 31 32 #define SHM_CONTENT_VENDOR_ATOM_VALUES 16 33 #define SHM_CONTENT_VENDOR_ATOM_STR_SIZE 128 34 35 struct ShmVendorAtomValue { 36 union { 37 int32_t i; 38 int64_t l; 39 float f; 40 char s[SHM_CONTENT_VENDOR_ATOM_STR_SIZE]; 41 }; 42 VendorAtomValue::Tag tag; 43 uint32_t reserved; 44 }; 45 STATIC_ASSERT(sizeof(ShmVendorAtomValue) == 46 SHM_CONTENT_VENDOR_ATOM_STR_SIZE + 8); 47 48 struct ShmContent { 49 ShmVendorAtomValue vendor_atom_values[SHM_CONTENT_VENDOR_ATOM_VALUES]; 50 char reverse_domain_name[SHM_CONTENT_VENDOR_ATOM_STR_SIZE]; 51 std::atomic<bool> full; 52 int32_t atom_id; 53 uint32_t ureserved; 54 uint64_t reserved[PAGE_SIZE / 8 - 2 - SHM_CONTENT_VENDOR_ATOM_STR_SIZE / 8 - 55 17 * SHM_CONTENT_VENDOR_ATOM_VALUES]; 56 }; 57 STATIC_ASSERT(sizeof(ShmContent) == PAGE_SIZE); 58 59 enum ConsumerCtlCommand : uint32_t { 60 CONSUMER_CTL_REQ_SHIFT = 1, 61 62 CONSUMER_CTL_SHM_SHARE = (0 << CONSUMER_CTL_REQ_SHIFT), 63 CONSUMER_CTL_SHM_RECLAIM = (1 << CONSUMER_CTL_REQ_SHIFT), 64 }; 65 66 struct ConsumerCtlMsg { 67 uint32_t cmd; 68 uint32_t reserved; 69 }; 70