2018-03-15 12:53:05 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-03 13:20:06 -08:00
|
|
|
#ifndef INTEL_GEM_H
|
|
|
|
|
#define INTEL_GEM_H
|
2018-03-15 12:53:05 -07:00
|
|
|
|
2022-09-30 10:18:13 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-07-07 14:27:12 -05:00
|
|
|
#include "drm-uapi/i915_drm.h"
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2019-07-25 10:50:36 -07:00
|
|
|
#include <errno.h>
|
2020-04-29 13:47:57 -07:00
|
|
|
#include <stdbool.h>
|
2018-07-28 19:11:56 +01:00
|
|
|
#include <stdint.h>
|
2021-07-07 14:27:12 -05:00
|
|
|
#include <stdlib.h>
|
intel/common: include unistd.h for ioctl() prototype on Solaris
Fixes build errors of:
In file included from ../src/intel/vulkan/anv_private.h:48,
from ../src/intel/vulkan/genX_blorp_exec.c:26:
../src/intel/common/gen_gem.h: In function ‘gen_ioctl’:
../src/intel/common/gen_gem.h:68:15: error: implicit declaration of function ‘ioctl’ [-Werror=implicit-function-declaration]
68 | ret = ioctl(fd, request, arg);
| ^~~~~
In file included from ../include/c11/threads_posix.h:35,
from ../include/c11/threads.h:66,
from ../src/mesa/main/mtypes.h:39,
from ../src/intel/compiler/brw_compiler.h:30,
from ../src/intel/vulkan/anv_private.h:51,
from ../src/intel/vulkan/genX_blorp_exec.c:26:
/usr/include/unistd.h: At top level:
/usr/include/unistd.h:471:12: error: conflicting types for ‘ioctl’
471 | extern int ioctl(int, int, ...);
| ^~~~~
/usr/include/unistd.h:471:1: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
471 | extern int ioctl(int, int, ...);
| ^~~~~~
In file included from ../src/intel/vulkan/anv_private.h:48,
from ../src/intel/vulkan/genX_blorp_exec.c:26:
../src/intel/common/gen_gem.h:68:15: note: previous implicit declaration of ‘ioctl’ was here
68 | ret = ioctl(fd, request, arg);
| ^~~~~
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Acked-by: Eric Engestrom <eric.engestrom@intel.com>
2019-10-08 15:36:48 -07:00
|
|
|
#include <unistd.h>
|
2019-07-25 10:50:36 -07:00
|
|
|
#include <sys/ioctl.h>
|
2018-07-28 19:11:56 +01:00
|
|
|
|
2022-08-08 11:25:26 -07:00
|
|
|
#include "intel_engine.h"
|
2022-10-27 09:55:39 -07:00
|
|
|
#include "util/macros.h"
|
2022-08-08 11:25:26 -07:00
|
|
|
|
2018-03-15 12:53:05 -07:00
|
|
|
static inline uint64_t
|
2021-03-03 13:49:18 -08:00
|
|
|
intel_canonical_address(uint64_t v)
|
2018-03-15 12:53:05 -07:00
|
|
|
{
|
|
|
|
|
/* From the Broadwell PRM Vol. 2a, MI_LOAD_REGISTER_MEM::MemoryAddress:
|
|
|
|
|
*
|
|
|
|
|
* "This field specifies the address of the memory location where the
|
|
|
|
|
* register value specified in the DWord above will read from. The
|
|
|
|
|
* address specifies the DWord location of the data. Range =
|
|
|
|
|
* GraphicsVirtualAddress[63:2] for a DWord register GraphicsAddress
|
|
|
|
|
* [63:48] are ignored by the HW and assumed to be in correct
|
|
|
|
|
* canonical form [63:48] == [47]."
|
|
|
|
|
*/
|
|
|
|
|
const int shift = 63 - 47;
|
|
|
|
|
return (int64_t)(v << shift) >> shift;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-30 20:00:37 -07:00
|
|
|
/**
|
|
|
|
|
* This returns a 48-bit address with the high 16 bits zeroed.
|
|
|
|
|
*
|
2021-03-03 13:49:18 -08:00
|
|
|
* It's the opposite of intel_canonicalize_address.
|
2018-05-30 20:00:37 -07:00
|
|
|
*/
|
|
|
|
|
static inline uint64_t
|
2021-03-03 13:49:18 -08:00
|
|
|
intel_48b_address(uint64_t v)
|
2018-05-30 20:00:37 -07:00
|
|
|
{
|
|
|
|
|
const int shift = 63 - 47;
|
|
|
|
|
return (uint64_t)(v << shift) >> shift;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 10:50:36 -07:00
|
|
|
/**
|
2022-06-22 18:31:08 +02:00
|
|
|
* Call ioctl, restarting if it is interrupted
|
2019-07-25 10:50:36 -07:00
|
|
|
*/
|
|
|
|
|
static inline int
|
2021-03-03 13:49:18 -08:00
|
|
|
intel_ioctl(int fd, unsigned long request, void *arg)
|
2019-07-25 10:50:36 -07:00
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
ret = ioctl(fd, request, arg);
|
|
|
|
|
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 14:27:12 -05:00
|
|
|
/**
|
|
|
|
|
* A wrapper around DRM_IOCTL_I915_QUERY
|
|
|
|
|
*
|
|
|
|
|
* Unfortunately, the error semantics of this ioctl are rather annoying so
|
|
|
|
|
* it's better to have a common helper.
|
|
|
|
|
*/
|
|
|
|
|
static inline int
|
2021-07-07 15:05:46 -05:00
|
|
|
intel_i915_query_flags(int fd, uint64_t query_id, uint32_t flags,
|
|
|
|
|
void *buffer, int32_t *buffer_len)
|
2021-07-07 14:27:12 -05:00
|
|
|
{
|
|
|
|
|
struct drm_i915_query_item item = {
|
|
|
|
|
.query_id = query_id,
|
|
|
|
|
.length = *buffer_len,
|
2021-07-07 15:05:46 -05:00
|
|
|
.flags = flags,
|
2021-07-07 14:27:12 -05:00
|
|
|
.data_ptr = (uintptr_t)buffer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct drm_i915_query args = {
|
|
|
|
|
.num_items = 1,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
.items_ptr = (uintptr_t)&item,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int ret = intel_ioctl(fd, DRM_IOCTL_I915_QUERY, &args);
|
|
|
|
|
if (ret != 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
else if (item.length < 0)
|
|
|
|
|
return item.length;
|
|
|
|
|
|
|
|
|
|
*buffer_len = item.length;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 15:05:46 -05:00
|
|
|
static inline int
|
|
|
|
|
intel_i915_query(int fd, uint64_t query_id, void *buffer,
|
|
|
|
|
int32_t *buffer_len)
|
|
|
|
|
{
|
|
|
|
|
return intel_i915_query_flags(fd, query_id, 0, buffer, buffer_len);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 14:27:12 -05:00
|
|
|
/**
|
|
|
|
|
* Query for the given data, allocating as needed
|
|
|
|
|
*
|
|
|
|
|
* The caller is responsible for freeing the returned pointer.
|
|
|
|
|
*/
|
|
|
|
|
static inline void *
|
2021-10-30 03:25:09 -07:00
|
|
|
intel_i915_query_alloc(int fd, uint64_t query_id, int32_t *query_length)
|
2021-07-07 14:27:12 -05:00
|
|
|
{
|
2021-10-30 03:25:09 -07:00
|
|
|
if (query_length)
|
|
|
|
|
*query_length = 0;
|
|
|
|
|
|
2021-07-07 14:27:12 -05:00
|
|
|
int32_t length = 0;
|
|
|
|
|
int ret = intel_i915_query(fd, query_id, NULL, &length);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
void *data = calloc(1, length);
|
|
|
|
|
assert(data != NULL); /* This shouldn't happen in practice */
|
|
|
|
|
if (data == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ret = intel_i915_query(fd, query_id, data, &length);
|
|
|
|
|
assert(ret == 0); /* We should have caught the error above */
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
free(data);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-30 03:25:09 -07:00
|
|
|
if (query_length)
|
|
|
|
|
*query_length = length;
|
|
|
|
|
|
2021-07-07 14:27:12 -05:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
bool intel_gem_supports_syncobj_wait(int fd);
|
2020-04-29 13:47:57 -07:00
|
|
|
|
2022-10-05 08:20:47 -07:00
|
|
|
bool intel_gem_create_context(int fd, uint32_t *context_id);
|
2022-10-05 08:49:26 -07:00
|
|
|
bool intel_gem_destroy_context(int fd, uint32_t context_id);
|
2022-10-05 08:20:07 -07:00
|
|
|
bool
|
|
|
|
|
intel_gem_create_context_engines(int fd,
|
|
|
|
|
const struct intel_query_engine_info *info,
|
|
|
|
|
int num_engines, enum intel_engine_class *engine_classes,
|
|
|
|
|
uint32_t *context_id);
|
2021-08-31 02:22:44 -07:00
|
|
|
|
2022-09-30 10:18:13 -07:00
|
|
|
bool intel_gem_read_render_timestamp(int fd, uint64_t *value);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-10-27 09:55:39 -07:00
|
|
|
enum intel_gem_create_context_flags {
|
|
|
|
|
INTEL_GEM_CREATE_CONTEXT_EXT_RECOVERABLE_FLAG = BITFIELD_BIT(0),
|
|
|
|
|
INTEL_GEM_CREATE_CONTEXT_EXT_PROTECTED_FLAG = BITFIELD_BIT(1),
|
|
|
|
|
};
|
|
|
|
|
bool intel_gem_create_context_ext(int fd, enum intel_gem_create_context_flags flags,
|
|
|
|
|
uint32_t *ctx_id);
|
2020-12-16 14:09:55 +02:00
|
|
|
bool intel_gem_supports_protected_context(int fd);
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
intel_gem_add_ext(__u64 *ptr, uint32_t ext_name,
|
|
|
|
|
struct i915_user_extension *ext)
|
|
|
|
|
{
|
|
|
|
|
__u64 *iter = ptr;
|
|
|
|
|
|
|
|
|
|
while (*iter != 0) {
|
|
|
|
|
iter = (__u64 *) &((struct i915_user_extension *)(uintptr_t)*iter)->next_extension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ext->name = ext_name;
|
|
|
|
|
|
|
|
|
|
*iter = (uintptr_t) ext;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 13:20:06 -08:00
|
|
|
#endif /* INTEL_GEM_H */
|