| 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 |
* Authors: |
| 24 |
* Xu, Zhengguo <[email protected]> |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef __MOS_BUFMGR_XE__ |
| 28 |
#define __MOS_BUFMGR_XE__ |
| 29 |
|
| 30 |
#include <stdio.h> |
| 31 |
#include <stdint.h> |
| 32 |
#include <stdbool.h> |
| 33 |
#include <sys/mman.h> |
| 34 |
#include <sys/ioctl.h> |
| 35 |
#include <errno.h> |
| 36 |
#include <limits.h> |
| 37 |
#include <string.h> |
| 38 |
#include <map> |
| 39 |
#include <set> |
| 40 |
#include <string> |
| 41 |
|
| 42 |
#include "libdrm_macros.h" |
| 43 |
#include "xf86atomic.h" |
| 44 |
#include "drm.h" |
| 45 |
#include "xe_drm.h" |
| 46 |
|
| 47 |
#if defined(__cplusplus) |
| 48 |
extern "C" { |
| 49 |
#endif |
| 50 |
extern drm_export int drmIoctl(int fd, unsigned long request, void *arg); |
| 51 |
|
| 52 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 53 |
/** |
| 54 |
* use env "export INTEL_XE_BUFMGR_DEBUG = #XE_DEBUG_* to enable different log level in mos bufmgr; |
| 55 |
* the log only available in debug or release internal version." |
| 56 |
*/ |
| 57 |
static int64_t __xe_bufmgr_debug__; |
| 58 |
#define XE_DEBUG_SYNCHRONIZATION (1ull << 0) |
| 59 |
#define __XE_TEST_DEBUG(flags) (__xe_bufmgr_debug__ & flags) |
| 60 |
#endif |
| 61 |
|
| 62 |
#define XE_DEFAULT_ALIGNMENT 0x1000 |
| 63 |
#define XE_DEFAULT_ALIGNMENT_64K 0x10000 |
| 64 |
|
| 65 |
#define EXEC_OBJECT_READ_XE 0x1 |
| 66 |
#define EXEC_OBJECT_WRITE_XE 0x2 |
| 67 |
|
| 68 |
#define INVALID_HANDLE -1 |
| 69 |
|
| 70 |
#define memclear(s) memset(&s, 0, sizeof(s)) |
| 71 |
|
| 72 |
#define system_memory(__memory_regions) (__memory_regions & 0x1) |
| 73 |
#define vram_memory(__memory_regions, gt) (__memory_regions & (0x2 << gt)) |
| 74 |
#define vram_if_possible(__memory_regions, gt) \ |
| 75 |
(vram_memory(__memory_regions, gt) ? \ |
| 76 |
vram_memory(__memory_regions, gt) : \ |
| 77 |
system_memory(__memory_regions)) |
| 78 |
|
| 79 |
#define MOS_XE_SUCCESS MOS_STATUS_SUCCESS |
| 80 |
|
| 81 |
#define MOS_XE_SAFE_FREE(ptr) \ |
| 82 |
if(ptr != nullptr){ \ |
| 83 |
free(ptr); \ |
| 84 |
ptr = nullptr; \ |
| 85 |
} |
| 86 |
|
| 87 |
#define MOS_XE_GET_KEYS_FROM_MAP(map_datas, key_datas) \ |
| 88 |
for (auto &it : map_datas) \ |
| 89 |
{ \ |
| 90 |
key_datas.insert(it.first); \ |
| 91 |
} |
| 92 |
|
| 93 |
#define MOS_XE_GET_VALUES_FROM_MAP(map_datas, v_datas) \ |
| 94 |
for (auto &it : map_datas) \ |
| 95 |
{ \ |
| 96 |
v_datas.push_back(it.second); \ |
| 97 |
} |
| 98 |
|
| 99 |
enum ENV_KEYS { |
| 100 |
RESERVED_0 = 0, |
| 101 |
INTEL_TILE_INSTANCE = 1, |
| 102 |
INTEL_XE_BUFMGR_DEBUG = 2, |
| 103 |
RESERVED_3 = 3, |
| 104 |
INTEL_ENGINE_TIMESLICE=4, |
| 105 |
INTEL_ENV_COUNT, |
| 106 |
}; |
| 107 |
|
| 108 |
static std::map<uint32_t, std::string> ENV_VARIABLE_TABLE = { |
| 109 |
{INTEL_TILE_INSTANCE, "INTEL_TILE_INSTANCE"}, |
| 110 |
{INTEL_XE_BUFMGR_DEBUG, "INTEL_XE_BUFMGR_DEBUG"}, |
| 111 |
{INTEL_ENGINE_TIMESLICE, "INTEL_ENGINE_TIMESLICE"} |
| 112 |
}; |
| 113 |
|
| 114 |
/** |
| 115 |
* Initializes the GEM buffer manager, which uses the kernel to allocate, map, |
| 116 |
* and manage map buffer objections. |
| 117 |
* |
| 118 |
* \param fd File descriptor of the opened DRM device. |
| 119 |
*/ |
| 120 |
struct mos_bufmgr *mos_bufmgr_gem_init_xe(int fd, int batch_size); |
| 121 |
|
| 122 |
int mos_get_dev_id_xe(int fd, uint32_t *device_id); |
| 123 |
|
| 124 |
#if defined(__cplusplus) |
| 125 |
} |
| 126 |
#endif |
| 127 |
#endif /* __MOS_BUFMGR_XE__ */ |