xref: /aosp_15_r20/external/mesa3d/src/panfrost/vulkan/panvk_physical_device.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2021 Collabora Ltd.
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef PANVK_PHYSICAL_DEVICE_H
7 #define PANVK_PHYSICAL_DEVICE_H
8 
9 #include <stdint.h>
10 
11 #include "panvk_instance.h"
12 
13 #include "vk_physical_device.h"
14 #include "vk_sync.h"
15 #include "vk_util.h"
16 #include "wsi_common.h"
17 
18 #include "lib/kmod/pan_kmod.h"
19 
20 struct panfrost_model;
21 struct pan_blendable_format;
22 struct panfrost_format;
23 struct panvk_instance;
24 
25 struct panvk_physical_device {
26    struct vk_physical_device vk;
27 
28    struct {
29       struct pan_kmod_dev *dev;
30       struct pan_kmod_dev_props props;
31    } kmod;
32 
33    const struct panfrost_model *model;
34    struct {
35       const struct pan_blendable_format *blendable;
36       const struct panfrost_format *all;
37    } formats;
38 
39    char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
40    uint8_t cache_uuid[VK_UUID_SIZE];
41 
42    struct vk_sync_type drm_syncobj_type;
43    const struct vk_sync_type *sync_types[2];
44 
45    struct wsi_device wsi_device;
46 
47    int master_fd;
48 };
49 
50 VK_DEFINE_HANDLE_CASTS(panvk_physical_device, vk.base, VkPhysicalDevice,
51                        VK_OBJECT_TYPE_PHYSICAL_DEVICE)
52 
53 static inline struct panvk_physical_device *
to_panvk_physical_device(struct vk_physical_device * phys_dev)54 to_panvk_physical_device(struct vk_physical_device *phys_dev)
55 {
56    return container_of(phys_dev, struct panvk_physical_device, vk);
57 }
58 
59 static inline uint32_t
panvk_get_vk_version()60 panvk_get_vk_version()
61 {
62    const uint32_t version_override = vk_get_version_override();
63    if (version_override)
64       return version_override;
65 
66    return VK_MAKE_API_VERSION(0, 1, 0, VK_HEADER_VERSION);
67 }
68 
69 static inline VkResult
panvk_errno_to_vk_error(void)70 panvk_errno_to_vk_error(void)
71 {
72    switch (errno) {
73    case -ENOMEM:
74       return VK_ERROR_OUT_OF_HOST_MEMORY;
75    default:
76       return VK_ERROR_UNKNOWN;
77    }
78 }
79 
80 VkResult panvk_physical_device_init(struct panvk_physical_device *device,
81                                     struct panvk_instance *instance,
82                                     drmDevicePtr drm_device);
83 
84 void panvk_physical_device_finish(struct panvk_physical_device *device);
85 
86 #endif
87