1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ACELITE_CACHE_CONFIG_H 17 #define OHOS_ACELITE_CACHE_CONFIG_H 18 19 #include <cstdint> 20 21 namespace OHOS { 22 namespace ACELite { 23 /** 24 * The magic number used at the beginning of every cache memory area. 25 */ 26 constexpr uint8_t MAGIC_NUMBER_COUNT = 2; // will put one magic number at the begin and end of every buffer for each 27 constexpr uint8_t MAGIC_NUMBER_LENGTH = 4; // count in bytes 28 constexpr uint8_t MAGIC_NUMBER_TOTAL_LENGTH_FOR_EACH = MAGIC_NUMBER_LENGTH * MAGIC_NUMBER_COUNT; 29 constexpr uint32_t CACHE_MEM_MAGIC_NUMBER = 0xCCCCCCCC; 30 31 constexpr uint8_t ALIGNMENT_SIZE = 8; 32 33 constexpr uint8_t CACHE_USER_MAX_COUNT = 16; 34 35 /** 36 * Every cache user can not use more than the max length buffer. 37 * Count in KB. 38 */ 39 constexpr uint16_t CACHE_REQUIREMENT_MAX_KBS = 4096; // the cache max total size, 4M 40 constexpr uint8_t CACHE_UNIT_MAX_KBS = 128; // max 128KB 41 constexpr uint32_t CACHE_UNIT_MAX_BYTES = CACHE_UNIT_MAX_KBS * 1024; 42 43 /** 44 * Define the purpose of the specific cache memory range. 45 */ 46 enum CacheUser : uint8_t { 47 USER_LOCALIZATION, 48 USER_PAGE_FILE, 49 USER_MAX_COUNT 50 }; 51 52 /** 53 * Records the cache requester info. 54 */ 55 struct CacheUnit { 56 // the cache unit owner 57 CacheUser cacheUser_; 58 // the required min buffer length, count in KB 59 uint8_t minLength_; 60 // constructors CacheUnitCacheUnit61 CacheUnit() : cacheUser_(USER_MAX_COUNT), minLength_(CACHE_UNIT_MAX_KBS) {} CacheUnitCacheUnit62 CacheUnit(CacheUser user, uint8_t length) : cacheUser_(user), minLength_(length) {} 63 }; 64 } // namespace ACELite 65 } // namespace OHOS 66 #endif // OHOS_ACELITE_CACHE_CONFIG_H 67