17ec681f3Smrg/* 27ec681f3Smrg * Copyright (C) 2008 The Android Open Source Project 37ec681f3Smrg * 47ec681f3Smrg * Licensed under the Apache License, Version 2.0 (the "License"); 57ec681f3Smrg * you may not use this file except in compliance with the License. 67ec681f3Smrg * You may obtain a copy of the License at 77ec681f3Smrg * 87ec681f3Smrg * http://www.apache.org/licenses/LICENSE-2.0 97ec681f3Smrg * 107ec681f3Smrg * Unless required by applicable law or agreed to in writing, software 117ec681f3Smrg * distributed under the License is distributed on an "AS IS" BASIS, 127ec681f3Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137ec681f3Smrg * See the License for the specific language governing permissions and 147ec681f3Smrg * limitations under the License. 157ec681f3Smrg */ 167ec681f3Smrg 177ec681f3Smrg#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H 187ec681f3Smrg#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H 197ec681f3Smrg 207ec681f3Smrg#include <stdint.h> 217ec681f3Smrg#include <sys/cdefs.h> 227ec681f3Smrg 237ec681f3Smrg#include <cutils/native_handle.h> 247ec681f3Smrg#include <system/graphics.h> 257ec681f3Smrg 267ec681f3Smrg__BEGIN_DECLS 277ec681f3Smrg 287ec681f3Smrg/* 297ec681f3Smrg * Value for the hw_module_t.tag field 307ec681f3Smrg */ 317ec681f3Smrg 327ec681f3Smrg#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D)) 337ec681f3Smrg 347ec681f3Smrg#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T') 357ec681f3Smrg#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T') 367ec681f3Smrg 377ec681f3Smrg#define HARDWARE_MAKE_API_VERSION(maj,min) \ 387ec681f3Smrg ((((maj) & 0xff) << 8) | ((min) & 0xff)) 397ec681f3Smrg 407ec681f3Smrg#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \ 417ec681f3Smrg ((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff)) 427ec681f3Smrg#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000 437ec681f3Smrg#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff 447ec681f3Smrg 457ec681f3Smrg 467ec681f3Smrg/* 477ec681f3Smrg * The current HAL API version. 487ec681f3Smrg * 497ec681f3Smrg * All module implementations must set the hw_module_t.hal_api_version field 507ec681f3Smrg * to this value when declaring the module with HAL_MODULE_INFO_SYM. 517ec681f3Smrg * 527ec681f3Smrg * Note that previous implementations have always set this field to 0. 537ec681f3Smrg * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0 547ec681f3Smrg * to be 100% binary compatible. 557ec681f3Smrg * 567ec681f3Smrg */ 577ec681f3Smrg#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0) 587ec681f3Smrg 597ec681f3Smrg/* 607ec681f3Smrg * Helper macros for module implementors. 617ec681f3Smrg * 627ec681f3Smrg * The derived modules should provide convenience macros for supported 637ec681f3Smrg * versions so that implementations can explicitly specify module/device 647ec681f3Smrg * versions at definition time. 657ec681f3Smrg * 667ec681f3Smrg * Use this macro to set the hw_module_t.module_api_version field. 677ec681f3Smrg */ 687ec681f3Smrg#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min) 697ec681f3Smrg#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) 707ec681f3Smrg 717ec681f3Smrg/* 727ec681f3Smrg * Use this macro to set the hw_device_t.version field 737ec681f3Smrg */ 747ec681f3Smrg#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min) 757ec681f3Smrg#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) 767ec681f3Smrg 777ec681f3Smrgstruct hw_module_t; 787ec681f3Smrgstruct hw_module_methods_t; 797ec681f3Smrgstruct hw_device_t; 807ec681f3Smrg 817ec681f3Smrg/** 827ec681f3Smrg * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 837ec681f3Smrg * and the fields of this data structure must begin with hw_module_t 847ec681f3Smrg * followed by module specific information. 857ec681f3Smrg */ 867ec681f3Smrgtypedef struct hw_module_t { 877ec681f3Smrg /** tag must be initialized to HARDWARE_MODULE_TAG */ 887ec681f3Smrg uint32_t tag; 897ec681f3Smrg 907ec681f3Smrg /** 917ec681f3Smrg * The API version of the implemented module. The module owner is 927ec681f3Smrg * responsible for updating the version when a module interface has 937ec681f3Smrg * changed. 947ec681f3Smrg * 957ec681f3Smrg * The derived modules such as gralloc and audio own and manage this field. 967ec681f3Smrg * The module user must interpret the version field to decide whether or 977ec681f3Smrg * not to inter-operate with the supplied module implementation. 987ec681f3Smrg * For example, SurfaceFlinger is responsible for making sure that 997ec681f3Smrg * it knows how to manage different versions of the gralloc-module API, 1007ec681f3Smrg * and AudioFlinger must know how to do the same for audio-module API. 1017ec681f3Smrg * 1027ec681f3Smrg * The module API version should include a major and a minor component. 1037ec681f3Smrg * For example, version 1.0 could be represented as 0x0100. This format 1047ec681f3Smrg * implies that versions 0x0100-0x01ff are all API-compatible. 1057ec681f3Smrg * 1067ec681f3Smrg * In the future, libhardware will expose a hw_get_module_version() 1077ec681f3Smrg * (or equivalent) function that will take minimum/maximum supported 1087ec681f3Smrg * versions as arguments and would be able to reject modules with 1097ec681f3Smrg * versions outside of the supplied range. 1107ec681f3Smrg */ 1117ec681f3Smrg uint16_t module_api_version; 1127ec681f3Smrg#define version_major module_api_version 1137ec681f3Smrg /** 1147ec681f3Smrg * version_major/version_minor defines are supplied here for temporary 1157ec681f3Smrg * source code compatibility. They will be removed in the next version. 1167ec681f3Smrg * ALL clients must convert to the new version format. 1177ec681f3Smrg */ 1187ec681f3Smrg 1197ec681f3Smrg /** 1207ec681f3Smrg * The API version of the HAL module interface. This is meant to 1217ec681f3Smrg * version the hw_module_t, hw_module_methods_t, and hw_device_t 1227ec681f3Smrg * structures and definitions. 1237ec681f3Smrg * 1247ec681f3Smrg * The HAL interface owns this field. Module users/implementations 1257ec681f3Smrg * must NOT rely on this value for version information. 1267ec681f3Smrg * 1277ec681f3Smrg * Presently, 0 is the only valid value. 1287ec681f3Smrg */ 1297ec681f3Smrg uint16_t hal_api_version; 1307ec681f3Smrg#define version_minor hal_api_version 1317ec681f3Smrg 1327ec681f3Smrg /** Identifier of module */ 1337ec681f3Smrg const char *id; 1347ec681f3Smrg 1357ec681f3Smrg /** Name of this module */ 1367ec681f3Smrg const char *name; 1377ec681f3Smrg 1387ec681f3Smrg /** Author/owner/implementor of the module */ 1397ec681f3Smrg const char *author; 1407ec681f3Smrg 1417ec681f3Smrg /** Modules methods */ 1427ec681f3Smrg struct hw_module_methods_t* methods; 1437ec681f3Smrg 1447ec681f3Smrg /** module's dso */ 1457ec681f3Smrg void* dso; 1467ec681f3Smrg 1477ec681f3Smrg#ifdef __LP64__ 1487ec681f3Smrg uint64_t reserved[32-7]; 1497ec681f3Smrg#else 1507ec681f3Smrg /** padding to 128 bytes, reserved for future use */ 1517ec681f3Smrg uint32_t reserved[32-7]; 1527ec681f3Smrg#endif 1537ec681f3Smrg 1547ec681f3Smrg} hw_module_t; 1557ec681f3Smrg 1567ec681f3Smrgtypedef struct hw_module_methods_t { 1577ec681f3Smrg /** Open a specific device */ 1587ec681f3Smrg int (*open)(const struct hw_module_t* module, const char* id, 1597ec681f3Smrg struct hw_device_t** device); 1607ec681f3Smrg 1617ec681f3Smrg} hw_module_methods_t; 1627ec681f3Smrg 1637ec681f3Smrg/** 1647ec681f3Smrg * Every device data structure must begin with hw_device_t 1657ec681f3Smrg * followed by module specific public methods and attributes. 1667ec681f3Smrg */ 1677ec681f3Smrgtypedef struct hw_device_t { 1687ec681f3Smrg /** tag must be initialized to HARDWARE_DEVICE_TAG */ 1697ec681f3Smrg uint32_t tag; 1707ec681f3Smrg 1717ec681f3Smrg /** 1727ec681f3Smrg * Version of the module-specific device API. This value is used by 1737ec681f3Smrg * the derived-module user to manage different device implementations. 1747ec681f3Smrg * 1757ec681f3Smrg * The module user is responsible for checking the module_api_version 1767ec681f3Smrg * and device version fields to ensure that the user is capable of 1777ec681f3Smrg * communicating with the specific module implementation. 1787ec681f3Smrg * 1797ec681f3Smrg * One module can support multiple devices with different versions. This 1807ec681f3Smrg * can be useful when a device interface changes in an incompatible way 1817ec681f3Smrg * but it is still necessary to support older implementations at the same 1827ec681f3Smrg * time. One such example is the Camera 2.0 API. 1837ec681f3Smrg * 1847ec681f3Smrg * This field is interpreted by the module user and is ignored by the 1857ec681f3Smrg * HAL interface itself. 1867ec681f3Smrg */ 1877ec681f3Smrg uint32_t version; 1887ec681f3Smrg 1897ec681f3Smrg /** reference to the module this device belongs to */ 1907ec681f3Smrg struct hw_module_t* module; 1917ec681f3Smrg 1927ec681f3Smrg /** padding reserved for future use */ 1937ec681f3Smrg#ifdef __LP64__ 1947ec681f3Smrg uint64_t reserved[12]; 1957ec681f3Smrg#else 1967ec681f3Smrg uint32_t reserved[12]; 1977ec681f3Smrg#endif 1987ec681f3Smrg 1997ec681f3Smrg /** Close this device */ 2007ec681f3Smrg int (*close)(struct hw_device_t* device); 2017ec681f3Smrg 2027ec681f3Smrg} hw_device_t; 2037ec681f3Smrg 2047ec681f3Smrg#ifdef __cplusplus 2057ec681f3Smrg#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast<struct hw_device_t**>(x) 2067ec681f3Smrg#else 2077ec681f3Smrg#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x) 2087ec681f3Smrg#endif 2097ec681f3Smrg 2107ec681f3Smrg/** 2117ec681f3Smrg * Name of the hal_module_info 2127ec681f3Smrg */ 2137ec681f3Smrg#define HAL_MODULE_INFO_SYM HMI 2147ec681f3Smrg 2157ec681f3Smrg/** 2167ec681f3Smrg * Name of the hal_module_info as a string 2177ec681f3Smrg */ 2187ec681f3Smrg#define HAL_MODULE_INFO_SYM_AS_STR "HMI" 2197ec681f3Smrg 2207ec681f3Smrg/** 2217ec681f3Smrg * Get the module info associated with a module by id. 2227ec681f3Smrg * 2237ec681f3Smrg * @return: 0 == success, <0 == error and *module == NULL 2247ec681f3Smrg */ 2257ec681f3Smrgint hw_get_module(const char *id, const struct hw_module_t **module); 2267ec681f3Smrg 2277ec681f3Smrg/** 2287ec681f3Smrg * Get the module info associated with a module instance by class 'class_id' 2297ec681f3Smrg * and instance 'inst'. 2307ec681f3Smrg * 2317ec681f3Smrg * Some modules types necessitate multiple instances. For example audio supports 2327ec681f3Smrg * multiple concurrent interfaces and thus 'audio' is the module class 2337ec681f3Smrg * and 'primary' or 'a2dp' are module interfaces. This implies that the files 2347ec681f3Smrg * providing these modules would be named audio.primary.<variant>.so and 2357ec681f3Smrg * audio.a2dp.<variant>.so 2367ec681f3Smrg * 2377ec681f3Smrg * @return: 0 == success, <0 == error and *module == NULL 2387ec681f3Smrg */ 2397ec681f3Smrgint hw_get_module_by_class(const char *class_id, const char *inst, 2407ec681f3Smrg const struct hw_module_t **module); 2417ec681f3Smrg 2427ec681f3Smrg__END_DECLS 2437ec681f3Smrg 2447ec681f3Smrg#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */ 245