Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2008 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 ANDROID_INCLUDE_HARDWARE_HARDWARE_H
     18 #define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
     19 
     20 #include <stdint.h>
     21 #include <sys/cdefs.h>
     22 
     23 #include <cutils/native_handle.h>
     24 #include <system/graphics.h>
     25 
     26 __BEGIN_DECLS
     27 
     28 /*
     29  * Value for the hw_module_t.tag field
     30  */
     31 
     32 #define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
     33 
     34 #define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
     35 #define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
     36 
     37 struct hw_module_t;
     38 struct hw_module_methods_t;
     39 struct hw_device_t;
     40 
     41 /**
     42  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
     43  * and the fields of this data structure must begin with hw_module_t
     44  * followed by module specific information.
     45  */
     46 typedef struct hw_module_t {
     47     /** tag must be initialized to HARDWARE_MODULE_TAG */
     48     uint32_t tag;
     49 
     50     /** major version number for the module */
     51     uint16_t version_major;
     52 
     53     /** minor version number of the module */
     54     uint16_t version_minor;
     55 
     56     /** Identifier of module */
     57     const char *id;
     58 
     59     /** Name of this module */
     60     const char *name;
     61 
     62     /** Author/owner/implementor of the module */
     63     const char *author;
     64 
     65     /** Modules methods */
     66     struct hw_module_methods_t* methods;
     67 
     68     /** module's dso */
     69     void* dso;
     70 
     71     /** padding to 128 bytes, reserved for future use */
     72     uint32_t reserved[32-7];
     73 
     74 } hw_module_t;
     75 
     76 typedef struct hw_module_methods_t {
     77     /** Open a specific device */
     78     int (*open)(const struct hw_module_t* module, const char* id,
     79             struct hw_device_t** device);
     80 
     81 } hw_module_methods_t;
     82 
     83 /**
     84  * Every device data structure must begin with hw_device_t
     85  * followed by module specific public methods and attributes.
     86  */
     87 typedef struct hw_device_t {
     88     /** tag must be initialized to HARDWARE_DEVICE_TAG */
     89     uint32_t tag;
     90 
     91     /** version number for hw_device_t */
     92     uint32_t version;
     93 
     94     /** reference to the module this device belongs to */
     95     struct hw_module_t* module;
     96 
     97     /** padding reserved for future use */
     98     uint32_t reserved[12];
     99 
    100     /** Close this device */
    101     int (*close)(struct hw_device_t* device);
    102 
    103 } hw_device_t;
    104 
    105 /**
    106  * Name of the hal_module_info
    107  */
    108 #define HAL_MODULE_INFO_SYM         HMI
    109 
    110 /**
    111  * Name of the hal_module_info as a string
    112  */
    113 #define HAL_MODULE_INFO_SYM_AS_STR  "HMI"
    114 
    115 /**
    116  * Get the module info associated with a module by id.
    117  *
    118  * @return: 0 == success, <0 == error and *module == NULL
    119  */
    120 int hw_get_module(const char *id, const struct hw_module_t **module);
    121 
    122 /**
    123  * Get the module info associated with a module instance by class 'class_id'
    124  * and instance 'inst'.
    125  *
    126  * Some modules types necessitate multiple instances. For example audio supports
    127  * multiple concurrent interfaces and thus 'audio' is the module class
    128  * and 'primary' or 'a2dp' are module interfaces. This implies that the files
    129  * providing these modules would be named audio.primary.<variant>.so and
    130  * audio.a2dp.<variant>.so
    131  *
    132  * @return: 0 == success, <0 == error and *module == NULL
    133  */
    134 int hw_get_module_by_class(const char *class_id, const char *inst,
    135                            const struct hw_module_t **module);
    136 
    137 __END_DECLS
    138 
    139 #endif  /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
    140