Path: blob/21.2-virgl/include/android_stub/hardware/hardware.h
7130 views
/*1* Copyright (C) 2008 The Android Open Source Project2*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 at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* 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 and13* limitations under the License.14*/1516#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H17#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H1819#include <stdint.h>20#include <sys/cdefs.h>2122#include <cutils/native_handle.h>23#include <system/graphics.h>2425__BEGIN_DECLS2627/*28* Value for the hw_module_t.tag field29*/3031#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))3233#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')34#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')3536#define HARDWARE_MAKE_API_VERSION(maj,min) \37((((maj) & 0xff) << 8) | ((min) & 0xff))3839#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \40((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))41#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff000042#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff434445/*46* The current HAL API version.47*48* All module implementations must set the hw_module_t.hal_api_version field49* to this value when declaring the module with HAL_MODULE_INFO_SYM.50*51* Note that previous implementations have always set this field to 0.52* Therefore, libhardware HAL API will always consider versions 0.0 and 1.053* to be 100% binary compatible.54*55*/56#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)5758/*59* Helper macros for module implementors.60*61* The derived modules should provide convenience macros for supported62* versions so that implementations can explicitly specify module/device63* versions at definition time.64*65* Use this macro to set the hw_module_t.module_api_version field.66*/67#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)68#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)6970/*71* Use this macro to set the hw_device_t.version field72*/73#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)74#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)7576struct hw_module_t;77struct hw_module_methods_t;78struct hw_device_t;7980/**81* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM82* and the fields of this data structure must begin with hw_module_t83* followed by module specific information.84*/85typedef struct hw_module_t {86/** tag must be initialized to HARDWARE_MODULE_TAG */87uint32_t tag;8889/**90* The API version of the implemented module. The module owner is91* responsible for updating the version when a module interface has92* changed.93*94* The derived modules such as gralloc and audio own and manage this field.95* The module user must interpret the version field to decide whether or96* not to inter-operate with the supplied module implementation.97* For example, SurfaceFlinger is responsible for making sure that98* it knows how to manage different versions of the gralloc-module API,99* and AudioFlinger must know how to do the same for audio-module API.100*101* The module API version should include a major and a minor component.102* For example, version 1.0 could be represented as 0x0100. This format103* implies that versions 0x0100-0x01ff are all API-compatible.104*105* In the future, libhardware will expose a hw_get_module_version()106* (or equivalent) function that will take minimum/maximum supported107* versions as arguments and would be able to reject modules with108* versions outside of the supplied range.109*/110uint16_t module_api_version;111#define version_major module_api_version112/**113* version_major/version_minor defines are supplied here for temporary114* source code compatibility. They will be removed in the next version.115* ALL clients must convert to the new version format.116*/117118/**119* The API version of the HAL module interface. This is meant to120* version the hw_module_t, hw_module_methods_t, and hw_device_t121* structures and definitions.122*123* The HAL interface owns this field. Module users/implementations124* must NOT rely on this value for version information.125*126* Presently, 0 is the only valid value.127*/128uint16_t hal_api_version;129#define version_minor hal_api_version130131/** Identifier of module */132const char *id;133134/** Name of this module */135const char *name;136137/** Author/owner/implementor of the module */138const char *author;139140/** Modules methods */141struct hw_module_methods_t* methods;142143/** module's dso */144void* dso;145146#ifdef __LP64__147uint64_t reserved[32-7];148#else149/** padding to 128 bytes, reserved for future use */150uint32_t reserved[32-7];151#endif152153} hw_module_t;154155typedef struct hw_module_methods_t {156/** Open a specific device */157int (*open)(const struct hw_module_t* module, const char* id,158struct hw_device_t** device);159160} hw_module_methods_t;161162/**163* Every device data structure must begin with hw_device_t164* followed by module specific public methods and attributes.165*/166typedef struct hw_device_t {167/** tag must be initialized to HARDWARE_DEVICE_TAG */168uint32_t tag;169170/**171* Version of the module-specific device API. This value is used by172* the derived-module user to manage different device implementations.173*174* The module user is responsible for checking the module_api_version175* and device version fields to ensure that the user is capable of176* communicating with the specific module implementation.177*178* One module can support multiple devices with different versions. This179* can be useful when a device interface changes in an incompatible way180* but it is still necessary to support older implementations at the same181* time. One such example is the Camera 2.0 API.182*183* This field is interpreted by the module user and is ignored by the184* HAL interface itself.185*/186uint32_t version;187188/** reference to the module this device belongs to */189struct hw_module_t* module;190191/** padding reserved for future use */192#ifdef __LP64__193uint64_t reserved[12];194#else195uint32_t reserved[12];196#endif197198/** Close this device */199int (*close)(struct hw_device_t* device);200201} hw_device_t;202203#ifdef __cplusplus204#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast<struct hw_device_t**>(x)205#else206#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x)207#endif208209/**210* Name of the hal_module_info211*/212#define HAL_MODULE_INFO_SYM HMI213214/**215* Name of the hal_module_info as a string216*/217#define HAL_MODULE_INFO_SYM_AS_STR "HMI"218219/**220* Get the module info associated with a module by id.221*222* @return: 0 == success, <0 == error and *module == NULL223*/224int hw_get_module(const char *id, const struct hw_module_t **module);225226/**227* Get the module info associated with a module instance by class 'class_id'228* and instance 'inst'.229*230* Some modules types necessitate multiple instances. For example audio supports231* multiple concurrent interfaces and thus 'audio' is the module class232* and 'primary' or 'a2dp' are module interfaces. This implies that the files233* providing these modules would be named audio.primary.<variant>.so and234* audio.a2dp.<variant>.so235*236* @return: 0 == success, <0 == error and *module == NULL237*/238int hw_get_module_by_class(const char *class_id, const char *inst,239const struct hw_module_t **module);240241__END_DECLS242243#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */244245246