libports: libdrm-2.4.105 update

Support for iris and etnvaviv

* entaviv:
  - libdrm on FreeBSD is not prepared for !PCI (and libc our is missing
    <sys/pciio.h>
  - missing <sys/types.h> include in xf86drmMode.c
  - etnaviv relies on linux header files - dummy in $(INC_DIR)
  - IOCTL FreeBSD ↔ Linux have swapped IO/OUT bit
  - O_CLOEXEC differs between FreeBSD ↔ Linux

issue #4254
This commit is contained in:
Josef Söntgen 2021-07-05 17:44:45 +02:00 committed by Christian Helmuth
parent c26c50e59b
commit dd90424129
26 changed files with 2301 additions and 4 deletions

View File

@ -0,0 +1,3 @@
include $(REP_DIR)/lib/import/import-libdrm.inc
INC_DIR += $(DRM_SRC_DIR) $(addprefix $(DRM_SRC_DIR)/,iris)

View File

@ -0,0 +1,9 @@
ifeq ($(CONTRIB_DIR),)
DRM_SRC_DIR = $(realpath $(call select_from_repositories,include/drm)/../..)
else
DRM_SRC_DIR = $(call select_from_ports,libdrm)/src/lib/libdrm
endif
INC_DIR += $(DRM_SRC_DIR)
INC_DIR += $(addprefix $(DRM_SRC_DIR)/,include/drm include)
INC_DIR += $(addprefix $(DRM_SRC_DIR)/,etnaviv)

View File

@ -0,0 +1,33 @@
LIB_DIR := $(REP_DIR)/src/lib/libdrm
# include before to shadow libdrm_macros.h
INC_DIR += $(LIB_DIR)/include
LIBDRM_PORT_DIR := $(call select_from_ports,libdrm)/src/lib/libdrm
REP_INC_DIR += include/drm
LIBS := libc
SHARED_LIB := yes
SRC_C := xf86drm.c \
xf86drmHash.c \
xf86drmMode.c \
xf86drmRandom.c \
xf86drmSL.c
SRC_C += dummies.c
CC_OPT = -DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1 -DHAVE_SYS_SYSCTL_H=1
#
# We rename 'ioctl' calls to 'genode_ioctl' calls, this way we are not required
# to write a libc plugin for libdrm.
#
CC_C_OPT += -Dioctl=genode_ioctl
vpath %.c $(LIBDRM_PORT_DIR)
vpath %.c $(LIB_DIR)
vpath %.cc $(LIB_DIR)
CC_CXX_WARN_STRICE :=

View File

@ -0,0 +1,5 @@
include $(REP_DIR)/lib/mk/libdrm.inc
include $(call select_from_repositories,lib/import/import-libdrm.mk)
SRC_CC := ioctl_dummy.cc

View File

@ -0,0 +1,8 @@
include $(REP_DIR)/lib/mk/libdrm.inc
include $(call select_from_repositories,lib/import/import-libdrm.mk)
#
# Enable when GPU multiplexer is available for Vivante
#
#SRC_CC := ioctl_etnaviv.cc

View File

@ -0,0 +1,5 @@
include $(REP_DIR)/lib/mk/libdrm.inc
include $(call select_from_repositories,lib/import/import-libdrm-iris.mk)
SRC_CC := ioctl_iris.cc

View File

@ -0,0 +1,321 @@
# core symbols
drmAddBufs T
drmAddContextPrivateMapping T
drmAddContextTag T
drmAddMap T
drmAgpAcquire T
drmAgpAlloc T
drmAgpBase T
drmAgpBind T
drmAgpDeviceId T
drmAgpEnable T
drmAgpFree T
drmAgpGetMode T
drmAgpMemoryAvail T
drmAgpMemoryUsed T
drmAgpRelease T
drmAgpSize T
drmAgpUnbind T
drmAgpVendorId T
drmAgpVersionMajor T
drmAgpVersionMinor T
drmAuthMagic T
drmAvailable T
drmCheckModesettingSupported T
drmClose T
drmCloseOnce T
drmCommandNone T
drmCommandRead T
drmCommandWrite T
drmCommandWriteRead T
drmCreateContext T
drmCreateDrawable T
drmCrtcGetSequence T
drmCrtcQueueSequence T
drmCtlInstHandler T
drmCtlUninstHandler T
drmDelContextTag T
drmDestroyContext T
drmDestroyDrawable T
drmDevicesEqual T
drmDMA T
drmDropMaster T
drmError T
drmFinish T
drmFree T
drmFreeBufs T
drmFreeBusid T
drmFreeDevice T
drmFreeDevices T
drmFreeReservedContextList T
drmFreeVersion T
drmGetBufInfo T
drmGetBusid T
drmGetCap T
drmGetClient T
drmGetContextFlags T
drmGetContextPrivateMapping T
drmGetContextTag T
drmGetDevice T
drmGetDevice2 T
drmGetDeviceNameFromFd T
drmGetDeviceNameFromFd2 T
drmGetDevices T
drmGetDevices2 T
drmGetEntry T
drmGetHashTable T
drmGetInterruptFromBusID T
drmGetLibVersion T
drmGetLock T
drmGetMagic T
drmGetMap T
drmGetNodeTypeFromFd T
drmGetPrimaryDeviceNameFromFd T
drmGetRenderDeviceNameFromFd T
drmGetReservedContextList T
drmGetStats T
drmGetVersion T
drmHandleEvent T
drmHashCreate T
drmHashDelete T
drmHashDestroy T
drmHashFirst T
drmHashInsert T
drmHashLookup T
drmHashNext T
drmIoctl T
drmIsKMS T
drmIsMaster T
drmMalloc T
drmMap T
drmMapBufs T
drmMarkBufs T
drmModeAddFB T
drmModeAddFB2 T
drmModeAddFB2WithModifiers T
drmModeAtomicAddProperty T
drmModeAtomicAlloc T
drmModeAtomicCommit T
drmModeAtomicDuplicate T
drmModeAtomicFree T
drmModeAtomicGetCursor T
drmModeAtomicMerge T
drmModeAtomicSetCursor T
drmModeAttachMode T
drmModeConnectorSetProperty T
drmModeCreateLease T
drmModeCreatePropertyBlob T
drmModeCrtcGetGamma T
drmModeCrtcSetGamma T
drmModeDestroyPropertyBlob T
drmModeDetachMode T
drmModeDirtyFB T
drmModeFreeConnector T
drmModeFreeCrtc T
drmModeFreeEncoder T
drmModeFreeFB T
drmModeFreeFB2 T
drmModeFreeModeInfo T
drmModeFreeObjectProperties T
drmModeFreePlane T
drmModeFreePlaneResources T
drmModeFreeProperty T
drmModeFreePropertyBlob T
drmModeFreeResources T
drmModeGetConnector T
drmModeGetConnectorCurrent T
drmModeGetCrtc T
drmModeGetEncoder T
drmModeGetFB T
drmModeGetFB2 T
drmModeGetLease T
drmModeGetPlane T
drmModeGetPlaneResources T
drmModeGetProperty T
drmModeGetPropertyBlob T
drmModeGetResources T
drmModeListLessees T
drmModeMoveCursor T
drmModeObjectGetProperties T
drmModeObjectSetProperty T
drmModePageFlip T
drmModePageFlipTarget T
drmModeRevokeLease T
drmModeRmFB T
drmModeSetCrtc T
drmModeSetCursor T
drmModeSetCursor2 T
drmModeSetPlane T
drmMsg T
drmOpen T
drmOpenControl T
drmOpenOnce T
drmOpenOnceWithType T
drmOpenRender T
drmOpenWithType T
drmPrimeFDToHandle T
drmPrimeHandleToFD T
drmRandom T
drmRandomCreate T
drmRandomDestroy T
drmRandomDouble T
drmRmMap T
drmScatterGatherAlloc T
drmScatterGatherFree T
drmSetBusid T
drmSetClientCap T
drmSetContextFlags T
drmSetInterfaceVersion T
drmSetMaster T
drmSetServerInfo T
drmSLCreate T
drmSLDelete T
drmSLDestroy T
drmSLDump T
drmSLFirst T
drmSLInsert T
drmSLLookup T
drmSLLookupNeighbors T
drmSLNext T
drmSwitchToContext T
drmSyncobjCreate T
drmSyncobjDestroy T
drmSyncobjExportSyncFile T
drmSyncobjFDToHandle T
drmSyncobjHandleToFD T
drmSyncobjImportSyncFile T
drmSyncobjQuery T
drmSyncobjQuery2 T
drmSyncobjReset T
drmSyncobjSignal T
drmSyncobjTimelineSignal T
drmSyncobjTimelineWait T
drmSyncobjTransfer T
drmSyncobjWait T
drmUnlock T
drmUnmap T
drmUnmapBufs T
drmUpdateDrawableInfo T
drmWaitVBlank T
# Etnaviv symbols
etna_device_new T
etna_device_new_dup T
etna_device_ref T
etna_device_del T
etna_device_fd T
etna_gpu_new T
etna_gpu_del T
etna_gpu_get_param T
etna_pipe_new T
etna_pipe_del T
etna_pipe_wait T
etna_pipe_wait_ns T
etna_bo_new T
etna_bo_from_name T
etna_bo_from_dmabuf T
etna_bo_ref T
etna_bo_del T
etna_bo_get_name T
etna_bo_handle T
etna_bo_dmabuf T
etna_bo_size T
etna_bo_map T
etna_bo_cpu_prep T
etna_bo_cpu_fini T
etna_cmd_stream_new T
etna_cmd_stream_del T
etna_cmd_stream_timestamp T
etna_cmd_stream_flush T
etna_cmd_stream_flush2 T
etna_cmd_stream_finish T
etna_cmd_stream_perf T
etna_cmd_stream_reloc T
etna_perfmon_create T
etna_perfmon_del T
etna_perfmon_get_dom_by_name T
etna_perfmon_get_sig_by_name T
# Intel symbols
drm_intel_bo_alloc T
drm_intel_bo_alloc_for_render T
drm_intel_bo_alloc_tiled T
drm_intel_bo_alloc_userptr T
drm_intel_bo_busy T
drm_intel_bo_disable_reuse T
drm_intel_bo_emit_reloc T
drm_intel_bo_emit_reloc_fence T
drm_intel_bo_exec T
drm_intel_bo_fake_alloc_static T
drm_intel_bo_fake_disable_backing_store T
drm_intel_bo_flink T
drm_intel_bo_gem_create_from_name T
drm_intel_bo_gem_create_from_prime T
drm_intel_bo_gem_export_to_prime T
drm_intel_bo_get_subdata T
drm_intel_bo_get_tiling T
drm_intel_bo_is_reusable T
drm_intel_bo_madvise T
drm_intel_bo_map T
drm_intel_bo_mrb_exec T
drm_intel_bo_pin T
drm_intel_bo_reference T
drm_intel_bo_references T
drm_intel_bo_set_softpin_offset T
drm_intel_bo_set_tiling T
drm_intel_bo_subdata T
drm_intel_bo_unmap T
drm_intel_bo_unpin T
drm_intel_bo_unreference T
drm_intel_bo_use_48b_address_range T
drm_intel_bo_wait_rendering T
drm_intel_bufmgr_check_aperture_space T
drm_intel_bufmgr_destroy T
drm_intel_bufmgr_fake_contended_lock_take T
drm_intel_bufmgr_fake_evict_all T
drm_intel_bufmgr_fake_init T
drm_intel_bufmgr_fake_set_exec_callback T
drm_intel_bufmgr_fake_set_fence_callback T
drm_intel_bufmgr_fake_set_last_dispatch T
drm_intel_bufmgr_gem_can_disable_implicit_sync T
drm_intel_bufmgr_gem_enable_fenced_relocs T
drm_intel_bufmgr_gem_enable_reuse T
drm_intel_bufmgr_gem_get_devid T
drm_intel_bufmgr_gem_init T
drm_intel_bufmgr_gem_set_aub_annotations T
drm_intel_bufmgr_gem_set_aub_dump T
drm_intel_bufmgr_gem_set_aub_filename T
drm_intel_bufmgr_gem_set_vma_cache_size T
drm_intel_bufmgr_set_debug T
drm_intel_decode T
drm_intel_decode_context_alloc T
drm_intel_decode_context_free T
drm_intel_decode_set_batch_pointer T
drm_intel_decode_set_dump_past_end T
drm_intel_decode_set_head_tail T
drm_intel_decode_set_output_file T
drm_intel_gem_bo_aub_dump_bmp T
drm_intel_gem_bo_clear_relocs T
drm_intel_gem_bo_context_exec T
drm_intel_gem_bo_disable_implicit_sync T
drm_intel_gem_bo_enable_implicit_sync T
drm_intel_gem_bo_fence_exec T
drm_intel_gem_bo_get_reloc_count T
drm_intel_gem_bo_map__cpu T
drm_intel_gem_bo_map__gtt T
drm_intel_gem_bo_map__wc T
drm_intel_gem_bo_map_gtt T
drm_intel_gem_bo_map_unsynchronized T
drm_intel_gem_bo_start_gtt_access T
drm_intel_gem_bo_unmap_gtt T
drm_intel_gem_bo_wait T
drm_intel_gem_context_create T
drm_intel_gem_context_destroy T
drm_intel_gem_context_get_id T
drm_intel_get_aperture_sizes T
drm_intel_get_eu_total T
drm_intel_get_min_eu_in_pool T
drm_intel_get_pipe_from_crtc_id T
drm_intel_get_pooled_eu T
drm_intel_get_reset_stats T
drm_intel_get_subslice_total T

View File

@ -1 +1 @@
c1cce0579aca9e31ade000bfa8ba58826b56cc43
b9c5f6ab814f107e5eb743892281c6ef0e80d860

View File

@ -1,7 +1,14 @@
LICENSE := MIT
VERSION := 2.4.21
VERSION := 2.4.105
DOWNLOADS := libdrm.archive
URL(libdrm) := http://dri.freedesktop.org/libdrm/libdrm-$(VERSION).tar.bz2
SHA(libdrm) := 4e1b612ba3b6b1deae4a8c14946099283e7a00e48a5ab002eaf4312f5a8ba14b
URL(libdrm) := https://dri.freedesktop.org/libdrm/libdrm-$(VERSION).tar.xz
SHA(libdrm) := 1d1d024b7cadc63e2b59cddaca94f78864940ab440843841113fbac6afaf2a46
DIR(libdrm) := src/lib/libdrm
FILE_LIST := $(REP_DIR)/src/lib/libdrm/files.list
TAR_OPT(libdrm) := --strip-components=1 --files-from $(FILE_LIST)
HASH_INPUT += $(FILE_LIST)
PATCHES := $(wildcard $(REP_DIR)/src/lib/libdrm/patches/*.patch)
PATCH_OPT := -p1

View File

@ -0,0 +1,27 @@
MIRROR_FROM_REP_DIR := lib/import/import-libdrm.mk \
lib/symbols/libdrm
content: $(MIRROR_FROM_REP_DIR)
$(MIRROR_FROM_REP_DIR):
$(mirror_from_rep_dir)
PORT_DIR := $(call port_dir,$(REP_DIR)/ports/libdrm)
content: include
include:
mkdir -p $@
cp -r $(PORT_DIR)/src/lib/libdrm/*.h $@
mkdir -p $@/drm
cp -r $(PORT_DIR)/src/lib/libdrm/include/drm/*.h $@/drm
mkdir -p $@/intel
cp -r $(PORT_DIR)/src/lib/libdrm/intel/*.h $@/intel
mkdir -p $@/etnaviv
cp -r $(PORT_DIR)/src/lib/libdrm/etnaviv/*.h $@/etnaviv
content: LICENSE
LICENSE:
echo "MIT, see header files" > $@

View File

@ -0,0 +1 @@
2021-08-23-i 96aa4ff0161eea571aa94734fa699e1715607b94

View File

@ -0,0 +1 @@
libdrm

View File

@ -0,0 +1,39 @@
MIRROR_FROM_REP_DIR := lib/mk/libdrm.mk \
lib/mk/libdrm.inc \
lib/mk/spec/arm_v8/libdrm.mk \
lib/mk/spec/x86_64/libdrm.mk \
src/lib/libdrm/include \
src/lib/libdrm/dummies.c \
src/lib/libdrm/ioctl_dummy.cc \
src/lib/libdrm/ioctl_iris.cc \
src/lib/libdrm/ioctl_etnaviv.cc \
content: $(MIRROR_FROM_REP_DIR) src/lib/libdrm/target.mk
$(MIRROR_FROM_REP_DIR):
$(mirror_from_rep_dir)
src/lib/libdrm/target.mk:
mkdir -p $(dir $@)
echo "LIBS = libdrm" > $@
PORT_DIR := $(call port_dir,$(REP_DIR)/ports/libdrm)
MIRROR_FROM_PORT_DIR := $(addprefix src/lib/libdrm/,\
xf86drm.c \
xf86drmHash.c \
xf86drmMode.c \
xf86drmRandom.c \
xf86drmSL.c)
content: $(MIRROR_FROM_PORT_DIR)
$(MIRROR_FROM_PORT_DIR):
mkdir -p $(dir $@)
cp -r $(PORT_DIR)/$@ $(dir $@)
content: LICENSE
LICENSE:
echo "MIT, see header files" > $@

View File

@ -0,0 +1 @@
2021-08-22-b 42aee82ddfd7aefca1086c92a4a50f6d49b7d797

View File

@ -0,0 +1,3 @@
base
gpu_session
libc

View File

@ -0,0 +1,6 @@
#include <sys/types.h>
char *devname_r(dev_t dev, mode_t type, char *buf, int len)
{
return (void*)0;
}

View File

@ -0,0 +1,42 @@
libdrm-2.4.105/etnaviv/etnaviv_bo.c
libdrm-2.4.105/etnaviv/etnaviv_bo_cache.c
libdrm-2.4.105/etnaviv/etnaviv_cmd_stream.c
libdrm-2.4.105/etnaviv/etnaviv_device.c
libdrm-2.4.105/etnaviv/etnaviv_drm.h
libdrm-2.4.105/etnaviv/etnaviv_drmif.h
libdrm-2.4.105/etnaviv/etnaviv_gpu.c
libdrm-2.4.105/etnaviv/etnaviv_perfmon.c
libdrm-2.4.105/etnaviv/etnaviv_pipe.c
libdrm-2.4.105/etnaviv/etnaviv_priv.h
libdrm-2.4.105/include/drm/drm.h
libdrm-2.4.105/include/drm/drm_mode.h
libdrm-2.4.105/include/drm/i915_drm.h
libdrm-2.4.105/intel/i915_pciids.h
libdrm-2.4.105/intel/intel_aub.h
libdrm-2.4.105/intel/intel_bufmgr.c
libdrm-2.4.105/intel/intel_bufmgr.h
libdrm-2.4.105/intel/intel_bufmgr_fake.c
libdrm-2.4.105/intel/intel_bufmgr_gem.c
libdrm-2.4.105/intel/intel_bufmgr_priv.h
libdrm-2.4.105/intel/intel_chipset.c
libdrm-2.4.105/intel/intel_chipset.h
libdrm-2.4.105/intel/intel_debug.h
libdrm-2.4.105/intel/intel_decode.c
libdrm-2.4.105/intel/mm.c
libdrm-2.4.105/intel/mm.h
libdrm-2.4.105/intel/test_decode.c
libdrm-2.4.105/intel/uthash.h
libdrm-2.4.105/libdrm_lists.h
libdrm-2.4.105/libsync.h
libdrm-2.4.105/util_double_list.h
libdrm-2.4.105/util_math.h
libdrm-2.4.105/xf86atomic.h
libdrm-2.4.105/xf86drm.c
libdrm-2.4.105/xf86drm.h
libdrm-2.4.105/xf86drmHash.c
libdrm-2.4.105/xf86drmHash.h
libdrm-2.4.105/xf86drmMode.c
libdrm-2.4.105/xf86drmMode.h
libdrm-2.4.105/xf86drmRandom.c
libdrm-2.4.105/xf86drmRandom.h
libdrm-2.4.105/xf86drmSL.c

View File

@ -0,0 +1,9 @@
#ifndef _INCLUDE__GENODE_TYPES_H_
#define _INCLUDE__GENODE_TYPES_H_
#include <base/fixed_stdint.h>
typedef genode_uint32_t uint32_t;
typedef __SIZE_TYPE__ size_t;
#endif /* _INCLUDE__GENODE_TYPES_H_ */

View File

@ -0,0 +1,18 @@
#ifndef _INCLUDE__LIBDRM_MACROS_H_
#define _INCLUDE__LIBDRM_MACROS_H_
#if HAVE_VISIBILITY
# define drm_private __attribute__((visibility("hidden")))
# define drm_public __attribute__((visibility("default")))
#else
# define drm_private
# define drm_public
#endif
#include <sys/mman.h>
void *drm_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
int drm_munmap(void *addr, size_t length);
#endif /* _INCLUDE__LIBDRM_MACROS_H_ */

View File

@ -0,0 +1,56 @@
/*
* \brief DRM ioctl backend dummy
* \author Josef Soentgen
* \date 2021-07-05
*/
/*
* Copyright (C) 2021 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
/* Genode includes */
#include <base/log.h>
extern "C" {
#include <drm.h>
#include <libdrm_macros.h>
}
extern "C" int genode_ioctl(int fd, unsigned long request, void *arg)
{
(void)fd;
(void)request;
(void)arg;
Genode::warning(__func__, ": not implemented yet");
return -1;
}
void *drm_mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
(void)addr;
(void)length;
(void)prot;
(void)flags;
(void)fd;
(void)offset;
Genode::warning(__func__, ": not implemented yet");
return (void*)0;
}
int drm_munmap(void *addr, size_t length)
{
(void)addr;
(void)length;
Genode::warning(__func__, ": not implemented yet");
return -1;
}

View File

@ -0,0 +1,488 @@
/*
* \brief DRM ioctl backend
* \author Sebastian Sumpf
* \author Josef Soentgen
* \date 2017-05-10
*/
/*
* Copyright (C) 2017-2021 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
/* Genode includes */
#include <base/heap.h>
#include <base/log.h>
#include <base/debug.h>
#include <gpu/connection.h>
#include <util/string.h>
extern "C" {
#include <fcntl.h>
#include <drm.h>
#include <etnaviv_drm.h>
#include <libdrm_macros.h>
}
enum { verbose_ioctl = false };
/**
* Get DRM command number
*/
static unsigned long constexpr command_number(unsigned long request)
{
return request & 0xffu;
}
/**
* Get device specific command number
*/
static unsigned long device_number(unsigned long request)
{
return command_number(request) - DRM_COMMAND_BASE;
}
/**
* Check if request is device command
*/
static bool device_ioctl(unsigned long request)
{
long const cmd = command_number(request);
return cmd >= DRM_COMMAND_BASE && cmd < DRM_COMMAND_END;
}
/**
* Return name of DRM command
*/
const char *command_name(unsigned long request)
{
if (IOCGROUP(request) != DRM_IOCTL_BASE)
return "<non-DRM>";
if (!device_ioctl(request)) {
switch (command_number(request)) {
case command_number(DRM_IOCTL_VERSION): return "DRM_IOCTL_VERSION";
case command_number(DRM_IOCTL_GEM_CLOSE): return "DRM_IOCTL_GEM_CLOSE";
case command_number(DRM_IOCTL_GEM_FLINK): return "DRM_IOCTL_GEM_FLINK";
case command_number(DRM_IOCTL_GEM_OPEN): return "DRM_IOCTL_GEM_OPEN";
case command_number(DRM_IOCTL_GET_CAP): return "DRM_IOCTL_GET_CAP";
case command_number(DRM_IOCTL_PRIME_HANDLE_TO_FD): return "DRM_IOCTL_PRIME_HANDLE_TO_FD";
case command_number(DRM_IOCTL_PRIME_FD_TO_HANDLE): return "DRM_IOCTL_PRIME_FD_TO_HANDLE";
default: return "<unknown drm>";
}
}
switch (device_number(request)) {
case DRM_ETNAVIV_GET_PARAM: return "DRM_ETNAVIV_GET_PARAM";
case DRM_ETNAVIV_GEM_NEW: return "DRM_ETNAVIV_GEM_NEW";
case DRM_ETNAVIV_GEM_INFO: return "DRM_ETNAVIV_GEM_INFO";
case DRM_ETNAVIV_GEM_CPU_PREP: return "DRM_ETNAVIV_GEM_CPU_PREP";
case DRM_ETNAVIV_GEM_CPU_FINI: return "DRM_ETNAVIV_GEM_CPU_FINI";
case DRM_ETNAVIV_GEM_SUBMIT: return "DRM_ETNAVIV_GEM_SUBMIT";
case DRM_ETNAVIV_WAIT_FENCE: return "DRM_ETNAVIV_WAIT_FENCE";
case DRM_ETNAVIV_GEM_USERPTR: return "DRM_ETNAVIV_GEM_USERPTR";
case DRM_ETNAVIV_GEM_WAIT: return "DRM_ETNAVIV_GEM_WAIT";
case DRM_ETNAVIV_PM_QUERY_DOM: return "DRM_ETNAVIV_PM_QUERY_DOM";
case DRM_ETNAVIV_PM_QUERY_SIG: return "DRM_ETNAVIV_PM_QUERY_SIG";
case DRM_ETNAVIV_NUM_IOCTLS: return "DRM_ETNAVIV_NUM_IOCTLS";
default:
return "<unknown driver>";
}
}
/**
* Check if request is OUT
*/
static bool constexpr req_out(unsigned long request)
{
return (request & IOC_OUT);
}
/**
* Check if request is IN
*/
static bool constexpr req_in(unsigned long request)
{
return (request & IOC_IN);
}
/**
* Convert FreeBSD (libc) I/O control to Linux (DRM driver)
*/
static unsigned long to_linux(unsigned long request)
{
/*
* FreeBSD and Linux have swapped IN/OUT values.
*/
unsigned long lx = request & 0x0fffffffu;
if (req_out(request)) { lx |= IOC_IN; }
if (req_in (request)) { lx |= IOC_OUT; }
return lx;
}
namespace Drm {
size_t get_payload_size(drm_etnaviv_gem_submit const &submit);
// XXX better implement as 'size_t for_each_object(T const *t, unsigned len, FN const &fn, char *dst)'
template <typename FN, typename T> void for_each_object(T const *t, unsigned len, FN const &fn)
{
for (unsigned i = 0; i < len; i++) {
T const *obj = &t[i];
fn(obj);
}
}
void serialize(drm_etnaviv_gem_submit *submit, char *content);
size_t get_payload_size(drm_version const &version);
void serialize(drm_version *version, char *content);
void deserialize(drm_version *version, char *content);
} /* anonymous namespace */
size_t Drm::get_payload_size(drm_etnaviv_gem_submit const &submit)
{
size_t size = 0;
size += sizeof (drm_etnaviv_gem_submit_reloc) * submit.nr_relocs;
size += sizeof (drm_etnaviv_gem_submit_bo) * submit.nr_bos;
size += sizeof (drm_etnaviv_gem_submit_pmr) * submit.nr_pmrs;
return size;
}
void Drm::serialize(drm_etnaviv_gem_submit *submit, char *content)
{
size_t offset = 0;
/* leave place for object itself first */
offset += sizeof (*submit);
/* next are the buffer-objects */
if (submit->nr_bos) {
size_t const new_start = offset;
auto copy_bos = [&] (drm_etnaviv_gem_submit_bo const *bo) {
char * const dst = content + offset;
Genode::memcpy(dst, bo, sizeof (*bo));
offset += sizeof (*bo);
};
for_each_object((drm_etnaviv_gem_submit_bo*)submit->bos,
submit->nr_bos, copy_bos);
submit->bos = reinterpret_cast<__u64>(new_start);
}
/* next are the relocs */
if (submit->nr_relocs) {
size_t const new_start = offset;
auto copy_relocs = [&] (drm_etnaviv_gem_submit_reloc const *reloc) {
char * const dst = content + offset;
Genode::memcpy(dst, reloc, sizeof (*reloc));
offset += sizeof (*reloc);
};
for_each_object((drm_etnaviv_gem_submit_reloc*)submit->relocs,
submit->nr_relocs, copy_relocs);
submit->relocs = reinterpret_cast<__u64>(new_start);
}
/* next are the pmrs */
if (submit->nr_pmrs) {
size_t const new_start = offset;
auto copy_pmrs = [&] (drm_etnaviv_gem_submit_pmr const *pmr) {
char * const dst = content + offset;
Genode::memcpy(dst, pmr, sizeof (*pmr));
offset += sizeof (*pmr);
};
for_each_object((drm_etnaviv_gem_submit_pmr*)submit->pmrs,
submit->nr_pmrs, copy_pmrs);
submit->pmrs = reinterpret_cast<__u64>(new_start);
}
/* next is the cmd stream */
{
size_t const new_start = offset;
char * const dst = content + offset;
Genode::memcpy(dst, reinterpret_cast<void const*>(submit->stream), submit->stream_size);
offset += submit->stream_size;
submit->stream = reinterpret_cast<__u64>(new_start);
}
/* copy submit object last but into the front */
Genode::memcpy(content, submit, sizeof (*submit));
}
size_t Drm::get_payload_size(drm_version const &version)
{
size_t size = 0;
size += version.name_len;
size += version.date_len;
size += version.desc_len;
return size;
}
void Drm::serialize(drm_version *version, char *content)
{
size_t offset = 0;
char *start = 0;
offset += sizeof (*version);
start = (char*)offset;
version->name = start;
offset += version->name_len;
start = (char*)offset;
version->date = start;
offset += version->date_len;
start = (char*)offset;
version->desc = start;
offset += version->desc_len;
Genode::memcpy(content, version, sizeof (*version));
}
void Drm::deserialize(drm_version *version, char *content)
{
drm_version *cversion = reinterpret_cast<drm_version*>(content);
version->version_major = cversion->version_major;
version->version_minor = cversion->version_minor;
version->version_patchlevel = cversion->version_patchlevel;
version->name += (unsigned long)version;
version->date += (unsigned long)version;
version->desc += (unsigned long)version;
cversion->name += (unsigned long)cversion;
cversion->date += (unsigned long)cversion;
cversion->desc += (unsigned long)cversion;
Genode::copy_cstring(version->name, cversion->name, cversion->name_len);
Genode::copy_cstring(version->date, cversion->date, cversion->date_len);
Genode::copy_cstring(version->desc, cversion->desc, cversion->desc_len);
}
class Drm_call
{
private:
Genode::Env &_env;
Genode::Heap _heap { _env.ram(), _env.rm() };
Genode::Allocator_avl _drm_alloc { &_heap };
Drm::Connection _drm_session { _env, &_drm_alloc, 1024*1024 };
public:
Drm_call(Genode::Env &env) : _env(env) { }
int ioctl(unsigned long request, void *arg)
{
size_t size = IOCPARM_LEN(request);
bool const in = req_in(request);
bool const out = req_out(request);
unsigned long const lx_request = to_linux(request);
/*
* Adjust packet size for flatten arrays.
*/
if (command_number(request) == DRM_ETNAVIV_GEM_SUBMIT) {
/* account for the arrays */
drm_etnaviv_gem_submit *submit =
reinterpret_cast<drm_etnaviv_gem_submit*>(arg);
size_t const payload_size = Drm::get_payload_size(*submit);
size += payload_size;
} else
/*
* Adjust packet size for user pointer storage.
*/
if (command_number(request) == command_number(DRM_IOCTL_VERSION)) {
drm_version *version =
reinterpret_cast<drm_version*>(arg);
size_t const payload_size = Drm::get_payload_size(*version);
size += payload_size;
}
Drm::Session::Tx::Source &src = *_drm_session.tx();
Drm::Packet_descriptor p { src.alloc_packet(size), lx_request };
/*
* Copy each array flat to the packet buffer and adjust the
* addresses in the submit object.
*/
if (device_number(request) == DRM_ETNAVIV_GEM_SUBMIT) {
drm_etnaviv_gem_submit *submit =
reinterpret_cast<drm_etnaviv_gem_submit*>(arg);
char *content = src.packet_content(p);
Drm::serialize(submit, content);
} else
/*
* Copy and adjust user pointer in DRM version object.
*/
if (command_number(request) == command_number(DRM_IOCTL_VERSION)) {
drm_version *version =
reinterpret_cast<drm_version*>(arg);
char *content = src.packet_content(p);
Drm::serialize(version, content);
} else
/*
* The remaining ioctls get the memcpy treament. Hopefully there
* are no user pointers left...
*/
if (in) {
Genode::memcpy(src.packet_content(p), arg, size);
}
/*
* For the moment we perform a "blocking" packetstream operation
* which could be time-consuming but is easier to debug. Eventually
* it should be replace by a asynchronous operation.
*/
src.submit_packet(p);
p = src.get_acked_packet();
if (out && arg) {
/*
* Adjust user pointers back to make the client happy.
*/
if (command_number(request) == command_number(DRM_IOCTL_VERSION)) {
drm_version *version =
reinterpret_cast<drm_version*>(arg);
char *content = src.packet_content(p);
Drm::deserialize(version, content);
} else {
// XXX handle unserializaton in a better way
Genode::memcpy(arg, src.packet_content(p), size);
}
}
src.release_packet(p);
return p.error();
}
void *mmap(unsigned long offset, unsigned long size)
{
Genode::Ram_dataspace_capability cap = _drm_session.object_dataspace(offset, size);
if (!cap.valid()) {
return (void *)-1;
}
try {
return _env.rm().attach(cap);
} catch (...) { }
return (void *)-1;
}
void munmap(void *addr)
{
_env.rm().detach(addr);
}
};
static Genode::Constructible<Drm_call> _drm;
void drm_init(Genode::Env &env)
{
_drm.construct(env);
}
void drm_complete()
{
Genode::error(__func__, ": called, not implemented yet");
}
/**
* Dump I/O control request to LOG
*/
static void dump_ioctl(unsigned long request)
{
using namespace Genode;
log("ioctl(request=", Hex(request),
(request & 0xe0000000u) == IOC_OUT ? " out" :
(request & 0xe0000000u) == IOC_IN ? " in" :
(request & 0xe0000000u) == IOC_INOUT ? " inout" : " void",
" len=", IOCPARM_LEN(request),
" cmd=", command_name(request), " (", Hex(command_number(request)), ")");
}
/**
* Perfom I/O control request
*/
extern "C" int genode_ioctl(int /* fd */, unsigned long request, void *arg)
{
if (verbose_ioctl)
dump_ioctl(request);
try {
int ret = _drm->ioctl(request, arg);
if (verbose_ioctl)
Genode::log("returned ", ret);
return ret;
} catch (...) { }
return -1;
}
/**
* Map DRM buffer-object
*/
void *drm_mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
(void)addr;
(void)prot;
(void)flags;
(void)fd;
return _drm->mmap(offset, length);
}
/**
* Unmap DRM buffer-object
*/
int drm_munmap(void *addr, size_t length)
{
(void)length;
_drm->munmap(addr);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
The libc <machine/param.h> header contains a different ALIGN
macro.
--- a/src/lib/libdrm/util_math.h
+++ b/src/lib/libdrm/util_math.h
@@ -29,6 +29,9 @@
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
#define __align_mask(value, mask) (((value) + (mask)) & ~(mask))
+#ifdef ALIGN
+#undef ALIGN
+#endif
#define ALIGN(value, alignment) __align_mask(value, (__typeof__(value))((alignment) - 1))
#endif /*_UTIL_MATH_H_*/

View File

@ -0,0 +1,11 @@
The <sys/sysctl.h> neads 'u_int' that is pulled in via <sys/types.h>
--- a/src/lib/libdrm/xf86drmMode.c
+++ b/src/lib/libdrm/xf86drmMode.c
@@ -37,6 +37,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <sys/ioctl.h>
+#include <sys/types.h>
#if HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif