• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2023 Intel Corporation
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 DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #include <stdint.h>
27 
28 #include "vulkan/vulkan_core.h"
29 #include "vk_sync.h"
30 
31 #include "dev/intel_device_info.h"
32 #include "dev/intel_kmd.h"
33 
34 struct anv_bo;
35 enum anv_bo_alloc_flags;
36 struct anv_cmd_buffer;
37 struct anv_device;
38 struct anv_queue;
39 struct anv_query_pool;
40 struct anv_utrace_submit;
41 struct anv_sparse_submission;
42 struct anv_trtt_batch_bo;
43 
44 enum anv_vm_bind_op {
45    /* bind vma specified in anv_vm_bind */
46    ANV_VM_BIND,
47    /* unbind vma specified in anv_vm_bind */
48    ANV_VM_UNBIND,
49    /* unbind all vmas of anv_vm_bind::bo, address and size fields must be set to 0 */
50    ANV_VM_UNBIND_ALL,
51 };
52 
53 struct anv_vm_bind {
54    struct anv_bo *bo;  /* Or NULL in case of a NULL binding. */
55    uint64_t address;   /* Includes the resource offset. */
56    uint64_t bo_offset; /* Also known as the memory offset. */
57    uint64_t size;
58    enum anv_vm_bind_op op;
59 };
60 
61 struct anv_kmd_backend {
62    /*
63     * Create a gem buffer.
64     * Return the gem handle in case of success otherwise returns 0.
65     */
66    uint32_t (*gem_create)(struct anv_device *device,
67                           const struct intel_memory_class_instance **regions,
68                           uint16_t num_regions, uint64_t size,
69                           enum anv_bo_alloc_flags alloc_flags,
70                           uint64_t *actual_size);
71    uint32_t (*gem_create_userptr)(struct anv_device *device, void *mem, uint64_t size);
72    void (*gem_close)(struct anv_device *device, struct anv_bo *bo);
73    /* Returns MAP_FAILED on error */
74    void *(*gem_mmap)(struct anv_device *device, struct anv_bo *bo,
75                      uint64_t offset, uint64_t size);
76    /* Bind things however you want. */
77    int (*vm_bind)(struct anv_device *device,
78                   struct anv_sparse_submission *submit);
79    /* Fully bind or unbind a BO. */
80    int (*vm_bind_bo)(struct anv_device *device, struct anv_bo *bo);
81    int (*vm_unbind_bo)(struct anv_device *device, struct anv_bo *bo);
82    VkResult (*execute_simple_batch)(struct anv_queue *queue,
83                                     struct anv_bo *batch_bo,
84                                     uint32_t batch_bo_size,
85                                     bool is_companion_rcs_batch);
86    VkResult (*execute_trtt_batch)(struct anv_sparse_submission *submit,
87                                   struct anv_trtt_batch_bo *trtt_bbo);
88    VkResult (*queue_exec_locked)(struct anv_queue *queue,
89                                  uint32_t wait_count,
90                                  const struct vk_sync_wait *waits,
91                                  uint32_t cmd_buffer_count,
92                                  struct anv_cmd_buffer **cmd_buffers,
93                                  uint32_t signal_count,
94                                  const struct vk_sync_signal *signals,
95                                  struct anv_query_pool *perf_query_pool,
96                                  uint32_t perf_query_pass,
97                                  struct anv_utrace_submit *utrace_submit);
98    VkResult (*queue_exec_trace)(struct anv_queue *queue,
99                                 struct anv_utrace_submit *submit);
100    uint32_t (*bo_alloc_flags_to_bo_flags)(struct anv_device *device,
101                                           enum anv_bo_alloc_flags alloc_flags);
102 };
103 
104 const struct anv_kmd_backend *anv_kmd_backend_get(enum intel_kmd_type type);
105 
106 /* Internal functions, should only be called by anv_kmd_backend_get() */
107 const struct anv_kmd_backend *anv_i915_kmd_backend_get(void);
108 const struct anv_kmd_backend *anv_xe_kmd_backend_get(void);
109 const struct anv_kmd_backend *anv_stub_kmd_backend_get(void);
110