Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD support #819

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,31 @@ script:
make -j8
- ccache -s
- ccache -z

jobs:
include:
- os: linux
- os: freebsd
compiler: clang
before_install:
- sudo pkg install -y meson pkgconf libdrm libXext libXfixes wayland
- sudo pkg install -y -x '^mesa($|-libs)'
install:
- sudo ln -sf /usr/local/libdata/pkgconfig /usr/local/lib/
- git clone https://github.com/intel/gmmlib.git
- | # Workaround until https://github.com/intel/gmmlib/pull/68 is merged
if ! fgrep -q freebsd gmmlib/.travis.yml; then
(cd gmmlib && git fetch origin pull/68/head:freebsd && git checkout freebsd)
fi
- (cd gmmlib && cmake -B _build -G Ninja && cmake --build _build && sudo cmake --install _build)
- git clone https://github.com/intel/libva.git
- (cd libva && meson _build && meson compile -C _build && sudo meson install -C _build)
script:
- ccache -s
- ccache -z
- cmake -B _build -G Ninja
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DBUILD_TYPE=Release -DBUILD_CMRTLIB=OFF -DMEDIA_RUN_TEST_SUITE=OFF
- cmake --build _build
- ccache -s
- ccache -z
2 changes: 1 addition & 1 deletion cmrtlib/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ set(CMRT_VERSION ${CMRT_VERSION_MAJOR}.${CMRT_VERSION_MINOR}.${CMRT_VERSION_PATC

set_target_properties(igfxcmrt PROPERTIES VERSION ${CMRT_VERSION})
set_target_properties(igfxcmrt PROPERTIES SOVERSION ${CMRT_VERSION_MAJOR})
target_link_libraries( igfxcmrt dl va rt ${GCC_SECURE_LINK_FLAGS})
target_link_libraries( igfxcmrt ${CMAKE_DL_LIBS} va rt ${GCC_SECURE_LINK_FLAGS})

include(GNUInstallDirs)

Expand Down
125 changes: 5 additions & 120 deletions cmrtlib/linux/hardware/drm_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@
#include <limits.h>
#include <signal.h>
#include <time.h>
#include <sys/sysmacros.h> //<sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#define stat_t struct stat
#include <sys/ioctl.h>
#include <sys/time.h>
#include <stdarg.h>
#ifdef MAJOR_IN_MKDEV
#ifdef __sun //#ifdef MAJOR_IN_MKDEV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change correct?

#include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#if defined(__GLIBC__) || defined(__linux__) //#ifdef MAJOR_IN_SYSMACROS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the bundled and patched libdrm is built via CMake and doesn't define MAJOR_IN_SYSMACROS. Instead always-true conditionals on Linux were expanded while the rest left as is. Are you suggesting to implement the macros via CMake?

Copy link
Author

@jbeich jbeich Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if CMake checks pass CI but 1 workflow awaiting approval.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I didn't realize this was a bundled libdrm file. Ugh.

Never mind then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, reverted CMake checks. GNU libc disables extensions by default, so it breaks configure checks without _GNU_SOURCE. Debugging without a Linux machine/VM maybe hard.

-- Looking for major
-- Looking for major - not found
-- Looking for major
-- Looking for major - not found
[...]
In file included from cmrtlib/linux/hardware/cm_device_os.cpp:24:
cmrtlib/linux/../linux/hardware/drm_device.h:1041:11: error: use of undeclared identifier 'major'
    maj = major(sbuf.st_rdev);
          ^
cmrtlib/linux/../linux/hardware/drm_device.h:1042:11: error: use of undeclared identifier 'minor'
    min = minor(sbuf.st_rdev);
          ^

https://github.com/jbeich/media-driver/runs/4452912703

#include <sys/sysmacros.h>
#endif
#include <math.h>
#include <string>
#include <cstring>

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

Expand Down Expand Up @@ -125,7 +124,7 @@ typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))

#define __align_mask(value, mask) (((value) + (mask)) & ~(mask))
#define ALIGN_CEIL(value, alignment) __align_mask(value, (__typeof__(value))((alignment) - 1))
#define ALIGN(value, alignment) __align_mask(value, (__typeof__(value))((alignment) - 1))
#define DRM_PLATFORM_DEVICE_NAME_LEN 512

typedef struct _drmPciBusInfo {
Expand Down Expand Up @@ -231,21 +230,6 @@ drm_device_validate_flags(uint32_t flags)
return (flags & ~DRM_DEVICE_GET_PCI_REVISION);
}

static bool
drm_device_has_rdev(drmDevicePtr device, dev_t find_rdev)
{
struct stat sbuf;

for (int i = 0; i < DRM_NODE_MAX; i++) {
if (device->available_nodes & 1 << i) {
if (stat(device->nodes[i], &sbuf) == 0 &&
sbuf.st_rdev == find_rdev)
return true;
}
}
return false;
}

static int drmGetMaxNodeName(void)
{
return sizeof(DRM_DIR_NAME) +
Expand Down Expand Up @@ -305,7 +289,7 @@ static drmDevicePtr drmDeviceAlloc(unsigned int type, const char *node,
unsigned int i;
char *ptr;

max_node_length = ALIGN_CEIL(drmGetMaxNodeName(), sizeof(void *));
max_node_length = ALIGN(drmGetMaxNodeName(), sizeof(void *));

extra = DRM_NODE_MAX * (sizeof(void *) + max_node_length);

Expand Down Expand Up @@ -1198,105 +1182,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
return drmGetDevices2(DRM_DEVICE_GET_PCI_REVISION, devices, max_devices);
}

/**
* Get information about the opened drm device
*
* \param fd file descriptor of the drm device
* \param flags feature/behaviour bitmask
* \param device the address of a drmDevicePtr where the information
* will be allocated in stored
*
* \return zero on success, negative error code otherwise.
*
* \note Unlike drmGetDevice it does not retrieve the pci device revision field
* unless the DRM_DEVICE_GET_PCI_REVISION \p flag is set.
*/
int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
{
drmDevicePtr local_devices[MAX_DRM_NODES];
drmDevicePtr d;
DIR *sysdir;
struct dirent *dent;
struct stat sbuf;
int subsystem_type;
int maj, min;
int ret, i, node_count;
dev_t find_rdev;

if (drm_device_validate_flags(flags))
return -EINVAL;

if (fd == -1 || device == NULL)
return -EINVAL;

if (fstat(fd, &sbuf))
return -errno;

find_rdev = sbuf.st_rdev;
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);

if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return -EINVAL;

subsystem_type = drmParseSubsystemType(maj, min);
if (subsystem_type < 0)
return subsystem_type;

sysdir = opendir(DRM_DIR_NAME);
if (!sysdir)
return -errno;

i = 0;
while ((dent = readdir(sysdir))) {
ret = process_device(&d, dent->d_name, subsystem_type, true, flags);
if (ret)
continue;

if (i >= MAX_DRM_NODES) {
fprintf(stderr, "More than %d drm nodes detected. "
"Please report a bug - that should not happen.\n"
"Skipping extra nodes\n", MAX_DRM_NODES);
break;
}
local_devices[i] = d;
i++;
}
node_count = i;

drmFoldDuplicatedDevices(local_devices, node_count);

*device = NULL;

for (i = 0; i < node_count; i++) {
if (!local_devices[i])
continue;

if (drm_device_has_rdev(local_devices[i], find_rdev))
*device = local_devices[i];
else
drmFreeDevice(&local_devices[i]);
}

closedir(sysdir);
if (*device == NULL)
return -ENODEV;
return 0;
}

/**
* Get information about the opened drm device
*
* \param fd file descriptor of the drm device
* \param device the address of a drmDevicePtr where the information
* will be allocated in stored
*
* \return zero on success, negative error code otherwise.
*/
int drmGetDevice(int fd, drmDevicePtr *device)
{
return drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, device);
}

static int32_t GetRendererFileDescriptor(char * drm_node)
{
Expand Down
6 changes: 3 additions & 3 deletions cmrtlib/linux/share/cm_def_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
#define Display unsigned int
#endif

#include <cstdlib>
#include <cstring>
#include "pthread.h"
#include <malloc.h>


////////////////////////////////////////////////////////////////////////////////////
// MS-specific defines/typedefs, which are absent under Linux but still used
////////////////////////////////////////////////////////////////////////////////////
#define _aligned_malloc(size, alignment) memalign(alignment, size)
#define _aligned_malloc(size, alignment) aligned_alloc(alignment, size)
#define _aligned_free(ptr) free(ptr)
typedef uint8_t BOOLEAN, *PBOOLEAN;
////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -101,7 +101,7 @@ typedef enum _VACMTEXTUREFILTERTYPE {

inline void * CM_ALIGNED_MALLOC(size_t size, size_t alignment)
{
return memalign(alignment, size);
return aligned_alloc(alignment, size);
}

inline void CM_ALIGNED_FREE(void * memory)
Expand Down
3 changes: 1 addition & 2 deletions cmrtlib/linux/share/cm_rt_def_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
Expand Down Expand Up @@ -175,7 +174,7 @@ template<> inline const char * CM_TYPE_NAME_UNMANGLED<double>() { return "double

inline void * CM_ALIGNED_MALLOC(size_t size, size_t alignment)
{
return memalign(alignment, size);
return aligned_alloc(alignment, size);
}

inline void CM_ALIGNED_FREE(void * memory)
Expand Down
1 change: 0 additions & 1 deletion media_driver/agnostic/ult/cm/buffer_up_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

#include "cm_test.h"
#include <malloc.h>

class BufferUPTest: public CmTest
{
Expand Down
1 change: 0 additions & 1 deletion media_driver/cmake/linux/media_compile_flags_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ endif()
if(NOT ${PLATFORM} STREQUAL "android")
set(MEDIA_COMPILER_FLAGS_COMMON
${MEDIA_COMPILER_FLAGS_COMMON}
-D__linux__
-fno-tree-pre
-fPIC
-Wl,--no-as-needed
Expand Down
21 changes: 21 additions & 0 deletions media_driver/linux/common/cm/hal/cm_innerdef_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@
#include "mos_os.h"
#include "media_libva_common.h"
#include <sys/types.h>
#if defined(__linux__)
#include <sys/syscall.h>
#elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h>
#elif defined(__NetBSD__)
#include <lwp.h>
#elif defined(__sun)
#include <thread.h>
#endif
#include <unistd.h>

//Require DRM VMAP patch,
Expand Down Expand Up @@ -95,5 +103,18 @@ inline void GetLocalTime(PSYSTEMTIME psystime)
#endif

#define CmGetCurProcessId() getpid()
#if defined(__linux__)
#define CmGetCurThreadId() syscall(SYS_gettid)
#elif defined(__DragonFly__) || defined(__FreeBSD__)
#define CmGetCurThreadId() pthread_getthreadid_np()
#elif defined(__NetBSD__)
#define CmGetCurThreadId() _lwp_self()
#elif defined(__OpenBSD__)
#define CmGetCurThreadId() getthrid()
#elif defined(__sun)
#define CmGetCurThreadId() thr_self()
#else
#warning "Cannot get kernel thread identifier on this platform."
#define CmGetCurThreadId() (uintptr_t)pthread_self()
#endif

3 changes: 3 additions & 0 deletions media_driver/linux/common/cm/hal/osservice/cm_mem_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <smmintrin.h>

typedef uintptr_t UINT_PTR;
#ifdef __fastcall
#undef __fastcall
#endif
#define __fastcall
#define __noop

Expand Down
35 changes: 34 additions & 1 deletion media_driver/linux/common/codec/ddi/media_libva_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,40 @@
#include <X11/Xutil.h>
#endif

#if defined(__linux__)
#include <linux/fb.h>
#define DEFAULT_FBDEV "/dev/graphics/fb0"
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__sun)
#include <sys/fbio.h>
# if defined(__sun)
#define DEFAULT_FBDEV "/dev/fb"
# else
#define DEFAULT_FBDEV "/dev/ttyv0"
# endif
#define FBIOGET_VSCREENINFO FBIOGTYPE
#define fb_var_screeninfo fbtype
#define xres fb_width
#define yres fb_height
#elif defined(__NetBSD__) || defined(__OpenBSD__)
#include <dev/wscons/wsconsio.h>
# if defined(__OpenBSD__)
#define DEFAULT_FBDEV "/dev/ttyC0"
# else
#define DEFAULT_FBDEV "/dev/ttyE0"
# endif
#define FBIOGET_VSCREENINFO WSDISPLAYIO_GINFO
#define fb_var_screeninfo wsdisplay_fbinfo
#define xres width
#define yres height
#else
#warning "Cannot query framebuffer properties on this platform."
#define DEFAULT_FBDEV "/dev/fb0"
#define FBIOGET_VSCREENINFO 0
struct fb_var_screeninfo {
uint32_t xres;
uint32_t yres;
};
#endif

typedef MediaDdiFactory<DdiMediaDecode, DDI_DECODE_CONFIG_ATTR> DdiDecodeFactory;

Expand Down Expand Up @@ -800,7 +833,7 @@ static int32_t DdiDecode_GetDisplayInfo(VADriverContextP ctx)
vsinfo.xres = 0;
vsinfo.yres = 0;

fd = open("/dev/graphics/fb0",O_RDONLY);
fd = open(DEFAULT_FBDEV,O_RDONLY);
if(fd > 0)
{
if(ioctl(fd, FBIOGET_VSCREENINFO, &vsinfo) < 0)
Expand Down
2 changes: 0 additions & 2 deletions media_driver/linux/common/ddi/media_libva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <X11/Xutil.h>
#endif

#include <linux/fb.h>

#include "media_libva.h"

#include "media_libva_util.h"
Expand Down
4 changes: 4 additions & 0 deletions media_driver/linux/common/os/i915/include/mos_bufmgr_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ struct mos_bufmgr {
bool has_full_vd = true;
};

#ifdef ALIGN
/* <sys/param.h> via <pthread_np.h> on FreeBSD also defines ALIGN */
#undef ALIGN
#endif
#define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
#define ROUND_UP_TO(x, y) (((x) + (y) - 1) / (y) * (y))
#define ROUND_UP_TO_MB(x) ROUND_UP_TO((x), 1024*1024)
Expand Down
Loading