xref: /aosp_15_r20/external/mesa3d/src/broadcom/vulkan/v3dv_android.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2017, Google Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include "v3dv_private.h"
25 
26 #include <vndk/hardware_buffer.h>
27 #include <hardware/hardware.h>
28 #include <hardware/hwvulkan.h>
29 
30 #include <vulkan/vk_icd.h>
31 
32 #include "vk_android.h"
33 #include "vk_enum_defines.h"
34 
35 #include "util/libsync.h"
36 #include "util/log.h"
37 #include "util/os_file.h"
38 #include "util/u_gralloc/u_gralloc.h"
39 
40 static int
41 v3dv_hal_open(const struct hw_module_t *mod,
42               const char *id,
43               struct hw_device_t **dev);
44 static int
45 v3dv_hal_close(struct hw_device_t *dev);
46 
47 static_assert(HWVULKAN_DISPATCH_MAGIC == ICD_LOADER_MAGIC, "");
48 
49 PUBLIC struct hwvulkan_module_t HAL_MODULE_INFO_SYM = {
50    .common =
51      {
52        .tag = HARDWARE_MODULE_TAG,
53        .module_api_version = HWVULKAN_MODULE_API_VERSION_0_1,
54        .hal_api_version = HARDWARE_MAKE_API_VERSION(1, 0),
55        .id = HWVULKAN_HARDWARE_MODULE_ID,
56        .name = "Broadcom Vulkan HAL",
57        .author = "Mesa3D",
58        .methods =
59          &(hw_module_methods_t) {
60            .open = v3dv_hal_open,
61          },
62      },
63 };
64 
65 static int
v3dv_hal_open(const struct hw_module_t * mod,const char * id,struct hw_device_t ** dev)66 v3dv_hal_open(const struct hw_module_t *mod,
67               const char *id,
68               struct hw_device_t **dev)
69 {
70    assert(mod == &HAL_MODULE_INFO_SYM.common);
71    assert(strcmp(id, HWVULKAN_DEVICE_0) == 0);
72 
73    hwvulkan_device_t *hal_dev = malloc(sizeof(*hal_dev));
74    if (!hal_dev)
75       return -1;
76 
77    *hal_dev = (hwvulkan_device_t){
78       .common =
79         {
80           .tag = HARDWARE_DEVICE_TAG,
81           .version = HWVULKAN_DEVICE_API_VERSION_0_1,
82           .module = &HAL_MODULE_INFO_SYM.common,
83           .close = v3dv_hal_close,
84         },
85      .EnumerateInstanceExtensionProperties =
86         v3dv_EnumerateInstanceExtensionProperties,
87      .CreateInstance = v3dv_CreateInstance,
88      .GetInstanceProcAddr = v3dv_GetInstanceProcAddr,
89    };
90 
91    mesa_logi("v3dv: Warning: Android Vulkan implementation is experimental");
92 
93    *dev = &hal_dev->common;
94    return 0;
95 }
96 
97 static int
v3dv_hal_close(struct hw_device_t * dev)98 v3dv_hal_close(struct hw_device_t *dev)
99 {
100    /* hwvulkan.h claims that hw_device_t::close() is never called. */
101    return -1;
102 }
103