1 /* 2 * Copyright (C) 2016 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 CHRE_PAL_VERSION_H_ 18 #define CHRE_PAL_VERSION_H_ 19 20 /** 21 * @file 22 * Shared definitions related to CHRE PAL versioning. 23 * 24 * Versioning guidelines 25 * 26 * Like the CHRE nanoapp API, CHRE PAL APIs are versioned by a 32-bit integer 27 * where the most significant byte represents the major version, the next most 28 * significant byte represents the minor version, and the two least significant 29 * bytes represent the implementation patch version in little endian order. 30 * 31 * Semantic versioning guidelines are followed, such that a new major version 32 * indicates a compatibility-breaking change was introduced, a new minor version 33 * indicates that new functionality was added in a backwards-compatible way, and 34 * a new patch version indicates bug fixes in the implementation. The patch 35 * version does not apply to the API itself, only a particular implementation of 36 * the API. 37 * 38 * Note that although the PALs are generally closely related to the CHRE API, 39 * they are versioned independently. For example, new features may be added to 40 * the PAL APIs to support CHRE core system requirements that do not impact the 41 * CHRE API directly. Also, a change may be made to the CHRE API that only 42 * results in a minor version change due to compatibility layers between CHRE 43 * nanoapps and the CHRE system, however this may require a major version bump 44 * to the PAL in order to implement it. In general, this is done to keep the PAL 45 * APIs simpler, as the components of the CHRE system are more tightly coupled 46 * than the apps that run on top of it and are typically updated at the same 47 * time. So we would want to ensure that a given nanoapp can run on multiple 48 * versions of the CHRE API, but it is less important for PAL modules to work 49 * with multiple versions of the core CHRE implementation, and vice versa. 50 */ 51 52 #include <stdint.h> 53 54 #ifdef __cplusplus 55 extern "C" { 56 #endif 57 58 /** 59 * Extracts only the API version component of a module version 60 */ 61 #define CHRE_PAL_GET_API_VERSION(moduleVersion) \ 62 ((moduleVersion)&UINT32_C(0xFFFF0000)) 63 64 /** 65 * Extracts only the major API version component of a module version 66 */ 67 #define CHRE_PAL_GET_API_MAJOR_VERSION(moduleVersion) \ 68 (((moduleVersion)&UINT32_C(0xFF000000)) >> 24) 69 70 /** 71 * Extracts only the module patch version of a module version 72 */ 73 #define CHRE_PAL_GET_PATCH_VERSION(moduleVersion) \ 74 ((moduleVersion)&UINT32_C(0x0000FFFF)) 75 76 /** 77 * Constructs an API version from major & minor patch versions 78 * 79 * @param major Major version, valid range 0-255 80 * @param minor Minor version, valid range 0-255 81 */ 82 #define CHRE_PAL_CREATE_API_VERSION(major, minor) \ 83 ((uint32_t)((((major)&0xFF) << 24) | (((minor)&0xFF) << 16))) 84 85 /** 86 * Constructs a module version from a complete API version and a module patch 87 * version 88 */ 89 #define CHRE_PAL_CREATE_MODULE_VERSION(apiVersion, patchVersion) \ 90 ((uint32_t)(CHRE_PAL_GET_API_VERSION(apiVersion) | \ 91 CHRE_PAL_GET_PATCH_VERSION(patchVersion))) 92 93 /** 94 * Determines if a requested CHRE API version is compatible with the supplied 95 * API version 96 */ 97 #define CHRE_PAL_VERSIONS_ARE_COMPATIBLE(apiVersion, requestedApiVersion) \ 98 (CHRE_PAL_GET_API_MAJOR_VERSION(apiVersion) == \ 99 CHRE_PAL_GET_API_MAJOR_VERSION(requestedApiVersion)) 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif // CHRE_VERSION_H_ 106