Linux kernel 5.10 on XU3/4

Test and fix the Kernel 5.4 features
Paullo612
Posts: 12
Joined: Tue Sep 02, 2014 4:58 am
languages_spoken: english
ODROIDs: ODROID XU3
Has thanked: 0
Been thanked: 7 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by Paullo612 »

MastaG wrote:
Fri Jun 24, 2022 8:08 pm
Does Gnome Wayland on panfrost work correctly?
Yes, it should work without any visual artifacts. Haven't tried any GL stuff inside Wayland session, as never applied https://lore.kernel.org/dri-devel/YMMxF ... l.local/t/ myself. But this patch is a kinda hack. Here is related Mesa issue.

Paullo612
Posts: 12
Joined: Tue Sep 02, 2014 4:58 am
languages_spoken: english
ODROIDs: ODROID XU3
Has thanked: 0
Been thanked: 7 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by Paullo612 »

chewitt wrote:
Sat Jun 25, 2022 9:19 pm
Software decoded 1080p media seems to work okay.
I've tested MFC from raw terminal without any graphical sessions started using

Code: Select all

ffplay -vcodec h264_v4l2m2m <path_to_your_favorite_video>
And it worked fine.

~80% cpu load for video playing using MFC vs ~130% cpu load for software decoder.

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

Yep I can also confirm with your patches the h264_v4l2m2m decoder still works when using it with Kodi.
I also applied your hack for always passing V4L2_MEMORY_FLAG_NON_COHERENT (because I statically linked ffmpeg into Kodi and didn't feel like rebuilding everything from scratch):

Code: Select all

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 6edf4508c636..ae11392aa192 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -704,7 +704,7 @@ static void validate_memory_flags(struct vb2_queue *q,
                *flags = 0;
        } else {
                /* Clear all unknown flags. */
-               *flags &= V4L2_MEMORY_FLAG_NON_COHERENT;
+               *flags |= V4L2_MEMORY_FLAG_NON_COHERENT;
        }
 }
Image

This is on vanilla 5.18.6 with only your patches and the above hack.
This patch was already merged btw: https://patchwork.freedesktop.org/patch/469763/

I'm still using the mali blob though.
Will try Panfrost later this week to see how it compares to the blob when running RetroArch and other things.

Thanks a lot bro!

chewitt
Posts: 191
Joined: Mon Aug 12, 2019 12:27 pm
languages_spoken: english
Has thanked: 4 times
Been thanked: 134 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by chewitt »

@MastaG are you patching Kodi at all?

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

chewitt wrote:
Sun Jun 26, 2022 7:53 pm
@MastaG are you patching Kodi at all?
Yes, with the patches put together by memeka and AreaScout and some changes by myself (e.g. disable DRM PRIME by default, don't advertise support for GBM_BO_(UN)MAP, don't use DMA renderer for RetroPlayer etc).

Code: Select all

diff --git a/cmake/modules/FindGBM.cmake b/cmake/modules/FindGBM.cmake
index 37a26a7bc4..53cc04663e 100644
--- a/cmake/modules/FindGBM.cmake
+++ b/cmake/modules/FindGBM.cmake
@@ -51,12 +51,12 @@ if(GBM_FOUND)
   set(GBM_LIBRARIES ${GBM_LIBRARY})
   set(GBM_INCLUDE_DIRS ${GBM_INCLUDE_DIR})
   set(GBM_DEFINITIONS -DHAVE_GBM=1)
-  if(GBM_HAS_BO_MAP)
-    list(APPEND GBM_DEFINITIONS -DHAS_GBM_BO_MAP=1)
-  endif()
-  if(GBM_HAS_MODIFIERS)
-    list(APPEND GBM_DEFINITIONS -DHAS_GBM_MODIFIERS=1)
-  endif()
+  #if(GBM_HAS_BO_MAP)
+  #  list(APPEND GBM_DEFINITIONS -DHAS_GBM_BO_MAP=1)
+  #endif()
+  #if(GBM_HAS_MODIFIERS)
+  #  list(APPEND GBM_DEFINITIONS -DHAS_GBM_MODIFIERS=1)
+  #endif()
   if(NOT TARGET GBM::GBM)
     add_library(GBM::GBM UNKNOWN IMPORTED)
     set_target_properties(GBM::GBM PROPERTIES
diff --git a/system/settings/linux.xml b/system/settings/linux.xml
index 6d1fb9cd49..167ffef752 100644
--- a/system/settings/linux.xml
+++ b/system/settings/linux.xml
@@ -165,7 +165,7 @@
             </dependency>
           </dependencies>
           <level>3</level>
-          <default>true</default>
+          <default>false</default>
           <control type="toggle" />
         </setting>
         <setting id="videoplayer.useprimerenderer" type="integer" label="13462" help="13463">
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
index 1a98610eaa..e86a2c9ae6 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
@@ -43,6 +43,17 @@ extern "C" {
 #define RINT lrint
 #endif
 
+/* define what FFMPEG codecs to use */
+/* leave empty string for autodetect */
+#define MPEG2TS_FFMPEG_CODEC "mpeg2_v4l2m2m"
+#define H263_FFMPEG_CODEC    "h263_v4l2m2m"
+#define H264_FFMPEG_CODEC    "h264_v4l2m2m"
+#define MPEG4_FFMPEG_CODEC   "mpeg4_v4l2m2m"
+#define MPEG1_FFMPEG_CODEC   "mpeg1_v4l2m2m"
+#define MPEG2_FFMPEG_CODEC   "mpeg2_v4l2m2m"
+#define VC1_FFMPEG_CODEC     "vc1_v4l2m2m"
+#define VP8_FFMPEG_CODEC     "vp8_v4l2m2m"
+
 enum DecoderState
 {
   STATE_NONE,
@@ -328,7 +339,7 @@ bool CDVDVideoCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
   m_hints = hints;
   m_options = options;
 
-  AVCodec* pCodec;
+  AVCodec* pCodec = nullptr;
 
   m_iOrientation = hints.orientation;
 
@@ -338,7 +349,42 @@ bool CDVDVideoCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
   m_processInfo.SetSwDeinterlacingMethods();
   m_processInfo.SetVideoInterlaced(false);
 
-  pCodec = avcodec_find_decoder(hints.codec);
+  if(!m_useSoftDecoder)
+  {
+    switch(hints.codec)
+    {
+      case AV_CODEC_ID_MPEG4:
+        pCodec = avcodec_find_decoder_by_name(MPEG4_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_MPEG2TS:
+        pCodec = avcodec_find_decoder_by_name(MPEG2TS_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_H263:
+        pCodec = avcodec_find_decoder_by_name(H263_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_H264:
+        pCodec = avcodec_find_decoder_by_name(H264_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_MPEG1VIDEO:
+        pCodec = avcodec_find_decoder_by_name(MPEG1_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_MPEG2VIDEO:
+        pCodec = avcodec_find_decoder_by_name(MPEG2_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_VC1:
+        pCodec = avcodec_find_decoder_by_name(VC1_FFMPEG_CODEC);
+        break;
+      case AV_CODEC_ID_VP8:
+        pCodec = avcodec_find_decoder_by_name(VP8_FFMPEG_CODEC);
+        break;
+      default:
+        pCodec = avcodec_find_decoder(hints.codec);
+        break;
+    }
+  }
+
+  if(pCodec == NULL)
+    pCodec = avcodec_find_decoder(hints.codec);
 
   if(pCodec == NULL)
   {
@@ -438,7 +484,7 @@ bool CDVDVideoCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
   }
 
   UpdateName();
-  const char* pixFmtName = av_get_pix_fmt_name(m_pCodecContext->pix_fmt);
+  const char* pixFmtName = av_get_pix_fmt_name(GetFormat(m_pCodecContext, &m_pCodecContext->pix_fmt));
   m_processInfo.SetVideoDimensions(m_pCodecContext->coded_width, m_pCodecContext->coded_height);
   m_processInfo.SetVideoPixelFormat(pixFmtName ? pixFmtName : "");
 
@@ -516,15 +562,23 @@ void CDVDVideoCodecFFmpeg::SetFilters()
 
 void CDVDVideoCodecFFmpeg::UpdateName()
 {
+  bool isHW = false;
   if(m_pCodecContext->codec->name)
+  {
     m_name = std::string("ff-") + m_pCodecContext->codec->name;
+    if(strstr(m_pCodecContext->codec->name, "v4l2m2m") != NULL)
+      isHW = true;
+  }
   else
     m_name = "ffmpeg";
 
   if(m_pHardware)
+  {
     m_name += "-" + m_pHardware->Name();
+    isHW = true;
+  }
 
-  m_processInfo.SetVideoDecoderName(m_name, m_pHardware ? true : false);
+  m_processInfo.SetVideoDecoderName(m_name, isHW ? true : false);
 
   CLog::Log(LOGDEBUG, "CDVDVideoCodecFFmpeg - Updated codec: %s", m_name.c_str());
 }
@@ -748,8 +802,14 @@ CDVDVideoCodec::VCReturn CDVDVideoCodecFFmpeg::GetPicture(VideoPicture* pVideoPi
   if (m_pDecodedFrame->interlaced_frame)
     m_interlaced = true;
   else
+  {
     m_interlaced = false;
-
+    if (m_useSoftDecoder)
+    {
+      m_useSoftDecoder = false;
+      return VC_REOPEN;
+    }
+  }
   if (!m_processInfo.GetVideoInterlaced() && m_interlaced)
     m_processInfo.SetVideoInterlaced(m_interlaced);
 
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h
index 4f2407c0a3..a337f0e1cd 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h
@@ -95,6 +95,7 @@ protected:
   bool m_requestSkipDeint = false;
   int m_codecControlFlags = 0;
   bool m_interlaced = false;
+  bool m_useSoftDecoder = true;
   double m_DAR = 1.0;
   CDVDStreamInfo m_hints;
   CDVDCodecOptions m_options;
diff --git a/xbmc/windowing/Resolution.cpp b/xbmc/windowing/Resolution.cpp
index af36e6e5c8..77e813da69 100644
--- a/xbmc/windowing/Resolution.cpp
+++ b/xbmc/windowing/Resolution.cpp
@@ -70,6 +70,8 @@ float RESOLUTION_INFO::DisplayRatio() const
 
 RESOLUTION CResolutionUtils::ChooseBestResolution(float fps, int width, int height, bool is3D)
 {
+  fps = static_cast<float>(std::round(fps));
+
   RESOLUTION res = CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution();
   float weight;
 
diff --git a/xbmc/windowing/gbm/GBMUtils.cpp b/xbmc/windowing/gbm/GBMUtils.cpp
index cf6ee7df4a..edc47e349e 100644
--- a/xbmc/windowing/gbm/GBMUtils.cpp
+++ b/xbmc/windowing/gbm/GBMUtils.cpp
@@ -74,24 +74,29 @@ CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurface(gbm_surface* surface) : m_surfac
 {
 }
 
+#define MAX_SURFACE_BUFFERS 3
 CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurfaceBuffer* CGBMUtils::CGBMDevice::CGBMSurface::
     LockFrontBuffer()
 {
-  m_buffers.emplace(std::make_unique<CGBMSurfaceBuffer>(m_surface));
 
-  if (!static_cast<bool>(gbm_surface_has_free_buffers(m_surface)))
+ /* Fix for ODROID XU4, gbm_surface_has_free_buffers doesn't seem to report if there
+  * are no buffers available instead GEM buffers are running out, so we manually empty
+  * the buffers here for a maximum of three
+  */
+  std::call_once(
+     flag, [this]() { CLog::Log(LOGDEBUG, "CGBMUtils - using {} buffers", MAX_SURFACE_BUFFERS); });
+
+  if (m_buffers.size() >= MAX_SURFACE_BUFFERS)
   {
-    /*
-     * We want to use call_once here because we want it to be logged the first time that
-     * we have to release buffers. This means that the maximum amount of buffers had been reached.
-     * For mesa this should be 4 buffers but it may vary accross other implementations.
-     */
-    std::call_once(
-        flag, [this]() { CLog::Log(LOGDEBUG, "CGBMUtils - using {} buffers", m_buffers.size()); });
-
-    m_buffers.pop();
+      while (!m_buffers.empty())
+      {
+        m_buffers.front();
+        m_buffers.pop();
+      }
   }
 
+  m_buffers.emplace(std::make_unique<CGBMSurfaceBuffer>(m_surface));
+
   return m_buffers.back().get();
 }
 
diff --git a/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp b/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp
index d8d775dcad..d3088ecec0 100644
--- a/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp
+++ b/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp
@@ -23,7 +23,7 @@ bool CWinSystemGbmEGLContext::InitWindowSystemEGL(EGLint renderableType, EGLint
     return false;
   }
 
-  if (!m_eglContext.CreatePlatformDisplay(m_GBM->GetDevice()->Get(), m_GBM->GetDevice()->Get()))
+  if (!m_eglContext.CreatePlatformDisplay(m_GBM->GetDevice()->Get(), reinterpret_cast<EGLNativeDisplayType>(m_GBM->GetDevice()->Get())))
   {
     return false;
   }
@@ -87,7 +87,7 @@ bool CWinSystemGbmEGLContext::CreateNewWindow(const std::string& name,
 
   if (!m_eglContext.CreatePlatformSurface(
           m_GBM->GetDevice()->GetSurface()->Get(),
-          reinterpret_cast<khronos_uintptr_t>(m_GBM->GetDevice()->GetSurface()->Get())))
+          reinterpret_cast<EGLNativeWindowType>(m_GBM->GetDevice()->GetSurface()->Get())))
   {
     return false;
   }
diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp
index d07092ba78..077a9f3a85 100644
--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp
+++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp
@@ -34,7 +34,7 @@
 using namespace KODI::WINDOWING::GBM;
 
 CWinSystemGbmGLESContext::CWinSystemGbmGLESContext()
-: CWinSystemGbmEGLContext(EGL_PLATFORM_GBM_MESA, "EGL_MESA_platform_gbm")
+: CWinSystemGbmEGLContext(EGL_PLATFORM_GBM_MESA, "EGL_KHR_platform_gbm")
 {}
 
 void CWinSystemGbmGLESContext::Register()
@@ -53,7 +53,7 @@ bool CWinSystemGbmGLESContext::InitWindowSystem()
   CDVDFactoryCodec::ClearHWAccels();
   CLinuxRendererGLES::Register();
   RETRO::CRPProcessInfoGbm::Register();
-  RETRO::CRPProcessInfoGbm::RegisterRendererFactory(new RETRO::CRendererFactoryDMA);
+  /* RETRO::CRPProcessInfoGbm::RegisterRendererFactory(new RETRO::CRendererFactoryDMA); */
   RETRO::CRPProcessInfoGbm::RegisterRendererFactory(new RETRO::CRendererFactoryOpenGLES);
 
   if (!CWinSystemGbmEGLContext::InitWindowSystemEGL(EGL_OPENGL_ES2_BIT, EGL_OPENGL_ES_API))
diff --git a/xbmc/windowing/gbm/drm/DRMUtils.cpp b/xbmc/windowing/gbm/drm/DRMUtils.cpp
index 85fc266fd2..f38736ca3b 100644
--- a/xbmc/windowing/gbm/drm/DRMUtils.cpp
+++ b/xbmc/windowing/gbm/drm/DRMUtils.cpp
@@ -187,7 +187,7 @@ bool CDRMUtils::FindPlanes()
     auto videoPlane = std::find_if(m_planes.begin(), m_planes.end(), [&i](auto& plane) {
       if (plane->GetPossibleCrtcs() & (1 << i))
       {
-        return plane->SupportsFormat(DRM_FORMAT_NV12);
+        return (plane->SupportsFormat(DRM_FORMAT_NV12) || plane->SupportsFormat(DRM_FORMAT_XRGB8888));
       }
       return false;
     });
diff --git a/xbmc/windowing/wayland/WinSystemWaylandEGLContextGLES.cpp b/xbmc/windowing/wayland/WinSystemWaylandEGLContextGLES.cpp
index 1827da1d9a..8d2b251f86 100644
--- a/xbmc/windowing/wayland/WinSystemWaylandEGLContextGLES.cpp
+++ b/xbmc/windowing/wayland/WinSystemWaylandEGLContextGLES.cpp
@@ -47,7 +47,7 @@ bool CWinSystemWaylandEGLContextGLES::InitWindowSystem()
   CDVDVideoCodecDRMPRIME::Register();
   CRendererDRMPRIMEGLES::Register();
 
-  RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryDMA);
+  /* RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryDMA); */
   RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryOpenGLES);
 
   bool general, deepColor;
This will make it work fine with GBM and Wayland, including RetroPlayer support and under GBM it will use two planes without needing to patch the kernel.
I'm using vanilla FFmpeg though.

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

So I also gave Panfrost a try by building a patched mesa release.
I must say it runs really well, beyond my expectations.
For example GTA Vice City runs even better compared to the old blob.
Everything is really smooth and I can even enable the triple buffering feature in gnome-shell.
Image

Chromium wayland also seems to be fully accelerated and smooth but it's constantly logging:

Code: Select all

ERROR:gl_surface_egl.cc(837)] EGL Driver message (Error) eglCreateContext: dri2_create_context
libEGL debug: EGL user error 0x3009 (EGL_BAD_MATCH) in eglCreateContext: dri2_create_context
I've opened an issue here: https://github.com/OSSystems/meta-browser/issues/644
@Paullo612 any ideas why dri2 is failing with EGL errors?

I also noticed the panfrost driver alone will not light up the screen by itself, it still requires the exynosdrm driver for display output to work.

I've attached all of the patches I've applied to get it running on 5.18.6, including the mali_kbase driver which needed a few workarounds to successfully build.
I've also uploaded the mali binary drivers patched by the rockchip linux libmali project (both mali-wayland-r12p0-04rel0 and mali-x11-r17p-01rel0): https://mega.nz/file/z9kyVbQS#kpdl8PRqy ... fGmTV9fTjw
They include the injector for missing gbm symbols, proper soname and I've hex-edited them to rename: EGL_KHR_platform_gbm to EGL_MESA_platform_gbm
My config might be a bit overkill for most distros as it also enables Fedora specific stuff such as SElinux support.
Just make sure to build both the mali_kbase and panfrost drivers as external modules, because you cannot use them together.
(e.g. only load mali_kbase if you plan on using the mali binary driver).
Attachments
config-5.18.6.txt
(166.36 KiB) Downloaded 37 times
5.18.6.zip
(489.14 KiB) Downloaded 43 times
These users thanked the author MastaG for the post:
odroid (Tue Jun 28, 2022 9:26 am)

chewitt
Posts: 191
Joined: Mon Aug 12, 2019 12:27 pm
languages_spoken: english
Has thanked: 4 times
Been thanked: 134 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by chewitt »

Panfrost is a GPU driver. All it does is write triangles to the GLES context of a DRM surface which is rendered to an HDMI output device (or something like that). In the ARM world these are all discrete bits of the video pipeline (and you need DRM); only in the x86_64 world do you have 'graphics drivers" that combine things.

What ffmpeg sources are you using with Kodi? .. because with DRMPRIME disabled I can see ffmpeg trying to engage the hardware decoder, but for me it throws errors and I don't see anything playing (only with software decoding). I'm trying to use the same sources that LE uses for RPi/Amlogic though.

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

chewitt wrote:
Tue Jun 28, 2022 10:04 am
Panfrost is a GPU driver. All it does is write triangles to the GLES context of a DRM surface which is rendered to an HDMI output device (or something like that). In the ARM world these are all discrete bits of the video pipeline (and you need DRM); only in the x86_64 world do you have 'graphics drivers" that combine things.

What ffmpeg sources are you using with Kodi? .. because with DRMPRIME disabled I can see ffmpeg trying to engage the hardware decoder, but for me it throws errors and I don't see anything playing (only with software decoding). I'm trying to use the same sources that LE uses for RPi/Amlogic though.
I built ffmpeg from here: https://github.com/xbmc/FFmpeg/tree/release/4.3-kodi

Code: Select all

ffmpeg version 4.3.1-Matrix-Beta1-Kodi Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 11 (GCC)
  configuration: --enable-neon --enable-gpl --enable-version3 --enable-nonfree --prefix=/usr/local --bindir=/usr/local/bin --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --incdir=/usr/local/include/ffmpeg --libdir=/usr/local/lib --mandir=/usr/local/share/man --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --disable-opencl --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-debug --shlibdir=/usr/local/lib --disable-runtime-cpudetect --arch=arm --cpu=cortex-a15 --enable-vfpv3 --enable-v4l2-m2m --extra-ldexeflags=-static --pkg-config-flags=--static --enable-pic --enable-openssl --enable-libzimg --extra-libs='-lpthread -lm -lz -ldl -fopenmp' --extra-cflags=-fopenmp --enable-librtmp
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
But afaik vanilla ffmpeg would work just as well, as long as it's being compiled with --enable-v4l2-m2m.
It could be that more recent versions of ffmpeg broke the v4l2-m2m decoder (that happened before I believe).
Other than that make sure you enabled the s5p-mfc kernel module and have the correct firmware installed.
Then just disable prime in Kodi and use the v4l2m2m decoders for the supported codecs, like I posted in the patch before.

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

I'm trying to build the midgard kernel module against 5.19.1 but it seems they did some upstream refactoring of dma fences again.
If anybody with some more knowledge of C and the kernel abi has some free time on his hands, please give me a hand :D
I've attached the patch which works up to 5.18.x and here's the changes I made so far based on upstream Linux graphics drivers.

Code: Select all

--- linux-5.19.1/drivers/gpu/arm/midgard/mali_kbase_dma_fence.c	2022-08-14 15:09:00.417714924 +0200
+++ linux-5.19.1.patched/drivers/gpu/arm/midgard/mali_kbase_dma_fence.c	2022-08-14 14:51:14.564952988 +0200
@@ -223,7 +223,10 @@
 					 struct dma_resv *resv,
 					 bool exclusive)
 {
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
+	enum dma_resv_usage usage;
+        struct dma_fence **shared_fences = NULL;
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0))
 	struct fence *excl_fence = NULL;
 	struct fence **shared_fences = NULL;
 #else
@@ -233,21 +236,26 @@
 	unsigned int shared_count = 0;
 	int err, i;
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
-	err = dma_resv_get_fences(resv,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
+	err = dma_resv_get_fences(resv, usage,
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+	err = dma_resv_get_fences(resv, &excl_fence,
 #else
-	err = dma_resv_get_fences_rcu(resv,
+	err = dma_resv_get_fences_rcu(resv, &excl_fence,
 #endif
-						&excl_fence,
 						&shared_count,
 						&shared_fences);
 	if (err)
 		return err;
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0))
 	if (excl_fence) {
 		err = kbase_fence_add_callback(katom,
 						excl_fence,
 						kbase_dma_fence_cb);
+#else
+	err = kbase_fence_add_callback(katom, usage, kbase_dma_fence_cb); (WRONG)
+#endif
 
 		/* Release our reference, taken by reservation_object_get_fences_rcu(),
 		 * to the fence. We have set up our callback (if that was possible),
@@ -346,7 +354,11 @@
 		struct dma_resv *obj = info->resv_objs[i];
 
 		if (!test_bit(i, info->dma_fence_excl_bitmap)) {
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0))
 			err = dma_resv_reserve_shared(obj, 1);
+#else
+			err = dma_resv_reserve_fences(obj, 1);
+#endif
 			if (err) {
 				dev_err(katom->kctx->kbdev->dev,
 					"Error %d reserving space for shared fence.\n", err);
@@ -360,7 +372,11 @@
 				goto end;
 			}
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0))
 			dma_resv_add_shared_fence(obj, fence);
+#else
+			dma_resv_add_fence(obj, fence, DMA_RESV_USAGE_READ);
+#endif
 		} else {
 			err = kbase_dma_fence_add_reservation_callback(katom, obj, true);
 			if (err) {
@@ -369,7 +385,11 @@
 				goto end;
 			}
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0))
 			dma_resv_add_excl_fence(obj, fence);
+#else
+			dma_resv_add_fence(obj, fence, DMA_RESV_USAGE_WRITE);
+#endif
 		}
 	}
 
I got most of it sorted out.
But I'm struggling a bit with the "dma_resv_get_fences" which now requires a "usage" parameter instead of "&excl_fence".
However a few lines below "kbase_fence_add_callback" requires "&excl_fence" again.

Any help would be greatly appreciated :)
Attachments
mali_kbase_5.18.zip
(462.75 KiB) Downloaded 25 times

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

Paullo612 wrote:
Tue Jun 07, 2022 1:14 am
Finally managed to fix Panfrost + MFC on recent kernels

Just applying attached paches and those two
https://patchwork.freedesktop.org/patch/469763/
https://lore.kernel.org/dri-devel/YMMxF ... l.local/t/

make it all work. Tested against vanilla v5.17.

Panfrost also requires Mesa patch. The bad news is that we now have to patch ffmpeg to pass V4L2_MEMORY_FLAG_NON_COHERENT flag to MFC queues.

Those are screenshots of default Kodi from Debian repository running on GBM.
Image

Image

Here is GNOME 3 on Wayland.
Image
Hi @Paullo612,

Did you happen to try this on 5.19?
Because it seems something broke again, because my videos seem to play in slowmotion.
I've basically built: https://github.com/chewitt/linux/commits/samsung-5.19.y
Which contains all of the above.

Panfrost works fine for everything, I can't find any errors either:

Code: Select all

[    0.000000] Kernel command line: s5p_mfc.mem=16M console=tty1 console=ttySAC2,115200n8 mitigations=off root=UUID=af796ed8-68ea-43f1-8f51-62e61db0b554 ro rhgb quiet psi=1  HPD=true vout=hdmi usbhid.quirks=0x0eef:0x0005:0x0004 smsc95xx.macaddr=00:1e:06:61:7a:39 false
[    6.161020] exynos-bus: new bus device registered: soc:bus-mfc ( 83250 KHz ~ 333000 KHz)
[   31.412793] s5p-mfc 11000000.codec: Adding to iommu group 6
[   31.428328] s5p-mfc 11000000.codec: preallocated 16 MiB buffer for the firmware and context buffers
[   31.526084] s5p-mfc 11000000.codec: decoder registered as /dev/video0
[   31.567638] s5p-mfc 11000000.codec: encoder registered as /dev/video1
It worked fine on 5.18.6.

Any ideas?

AreaScout
Posts: 1896
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: german, english
ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
N1, Go, VU5A, Show2, CloudShell2,
H2, N2, VU7A, VuShell, Go2, C4
Has thanked: 152 times
Been thanked: 421 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by AreaScout »

@MastaG

No it works on 5.19 but I had the same issue as you with slow videos on Kernel 5.4, I build a Armbian image with kernel 5.4 and there it works

Regards,
Daniel

MastaG
Posts: 441
Joined: Mon Aug 26, 2013 6:05 pm
languages_spoken: english
Has thanked: 54 times
Been thanked: 78 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by MastaG »

@AreaScout

But I'm using the same Fedora 36 image, with the same Kodi 19.4.
If I boot into 5.18.6 with @Paullo612's patchset, the movies play fine using the h264_v4l2m2m decoder.
When I switch to 5.19.1 with the same patches, they play in slowmotion again (just like everything after 5.8).
So I must have missed something for 5.19.1.

I've attached the logs, but they don't show anything going wrong.
Attachments
dmesg.txt.zip
(17.24 KiB) Downloaded 19 times
kodi.txt.zip
(8.06 KiB) Downloaded 20 times

AreaScout
Posts: 1896
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: german, english
ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
N1, Go, VU5A, Show2, CloudShell2,
H2, N2, VU7A, VuShell, Go2, C4
Has thanked: 152 times
Been thanked: 421 times
Contact:

Re: Linux kernel 5.10 on XU3/4

Post by AreaScout »

    Well maybe it's a kernel config thing

    MastaG
    Posts: 441
    Joined: Mon Aug 26, 2013 6:05 pm
    languages_spoken: english
    Has thanked: 54 times
    Been thanked: 78 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by MastaG »

    At first I thought that too, but I rebuilt it with the 5.18.6 .config and still the video plays in slow motion.
    So https://github.com/chewitt/linux/commits/samsung-5.19.y must be missing something which keeps the v4l2m2m video decoder from working.
    I went through Paullo612's post, but all patches are there.

    EDIT: Now I realise @Chewitt was also having trouble with 5.19-rc3.. so something must have changed between 5.18.6 and 5.19 which causes it to stop working.

    EDIT2: think I found it:
    https://github.com/chewitt/linux/commit ... 9c8fab7f01

    It should have been:

    Code: Select all

    @@ -704,7 +704,7 @@
     		*flags = 0;
     	} else {
     		/* Clear all unknown flags. */
    -		*flags != V4L2_MEMORY_FLAG_NON_COHERENT;
    +		*flags |= V4L2_MEMORY_FLAG_NON_COHERENT;
     	}
     }
     
    These users thanked the author MastaG for the post (total 2):
    chewitt (Sun Aug 21, 2022 8:29 pm) • odroid (Mon Aug 22, 2022 10:06 am)

    User avatar
    mad_ady
    Posts: 10956
    Joined: Wed Jul 15, 2015 5:00 pm
    languages_spoken: english
    ODROIDs: XU4 (HC1, HC2), C1+, C2, C4 (HC4), N1, N2, H2, Go, Go Advance, M1
    Location: Bucharest, Romania
    Has thanked: 647 times
    Been thanked: 996 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by mad_ady »

    Seeing the difference between ! and | in all the kernel code requires superhuman skills!
    These users thanked the author mad_ady for the post (total 2):
    AreaScout (Sun Aug 21, 2022 1:14 pm) • MastaG (Mon Aug 22, 2022 7:32 am)

    chewitt
    Posts: 191
    Joined: Mon Aug 12, 2019 12:27 pm
    languages_spoken: english
    Has thanked: 4 times
    Been thanked: 134 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by chewitt »

    @MastaG I need an eyeball upgrade - that does indeed fix the issue that I was seeing with my LE image. Nice catch :)

    For anyone else interested I've pushed a rebased branch for Linux 5.19.2 https://github.com/chewitt/linux/commits/samsung-5.19.y - also has patches needed when using the lastest binutils that won't be needed with less bleeding edge distros. Kodi patches (last one in this branch) are here: https://github.com/chewitt/xbmc/commits/samsung-nexus

    https://chewitt.libreelec.tv/testing/Li ... xu4.img.gz <= XU4 image based on LE11 (development) with recent Kodi Nexus (K20)
    https://chewitt.libreelec.tv/testing/Li ... xu3.img.gz <= XU3 image (ditto)
    These users thanked the author chewitt for the post:
    MastaG (Mon Aug 22, 2022 7:32 am)

    MastaG
    Posts: 441
    Joined: Mon Aug 26, 2013 6:05 pm
    languages_spoken: english
    Has thanked: 54 times
    Been thanked: 78 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by MastaG »

    Very nice!
    Also I noticed on XU4, there's two patches that addresses the ethernet adapter being stuck on a hot reboot, mainly:
    https://github.com/LibreELEC/LibreELEC. ... to-p.patch
    https://github.com/LibreELEC/LibreELEC. ... t-in.patch

    But I think it's a good idea to just push all of the missing ones, as they all seem to apply.

    chewitt
    Posts: 191
    Joined: Mon Aug 12, 2019 12:27 pm
    languages_spoken: english
    Has thanked: 4 times
    Been thanked: 134 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by chewitt »

    Sadly one of the common traits of this forum is people authoring patches and never making an attempt to upstream them and get issues properly (and permanently) fixed. So unless I see actual user reports of Ethernet issues, for my LE/Kodi use-case, I won't be adding more patches (more unexplained technical debt) into the branch. If I get time I plan to experiment and see what patches can be removed without breaking basic function, because as a maintainer I loathe working with prehistoric collections of accumulated patches that only have subject-line explanations of their content, i.e. no proper explanations of what the patch does and/or why it's needed.

    AreaScout
    Posts: 1896
    Joined: Sun Jul 07, 2013 3:05 am
    languages_spoken: german, english
    ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
    N1, Go, VU5A, Show2, CloudShell2,
    H2, N2, VU7A, VuShell, Go2, C4
    Has thanked: 152 times
    Been thanked: 421 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by AreaScout »

    chewitt wrote:
    Mon Aug 22, 2022 3:44 pm
    Sadly one of the common traits of this forum is people authoring patches and never making an attempt to upstream them and get issues properly (and permanently) fixed.
    Your statement is way too flat-rated, which peoples are you targeting at ? name please, if you think about the v4l2_m2m changes on KODI, they would never be excepted by mainline because it's too board specific, here are just a view upstream affords from me https://github.com/moonlight-stream/moo ... pe=commits https://github.com/hrydgard/ppsspp/sear ... pe=commits and I was two times member of team KODI, XBMP and XBMC to be more precisely, so it can't be me

    Regards,
    Daniel
    These users thanked the author AreaScout for the post:
    MastaG (Tue Aug 23, 2022 3:06 am)

    MastaG
    Posts: 441
    Joined: Mon Aug 26, 2013 6:05 pm
    languages_spoken: english
    Has thanked: 54 times
    Been thanked: 78 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by MastaG »

    Well for the Ethernet port on the XU4 it happened quite some times that after rebooting it would say something like:
    'USB: can't assign requested address'
    And then networking would simply be unavailable until I cold boot it again.

    The two mentioned patches are small and just add the shutdown function, so the controller works after rebooting the system.
    I don't know if there was any attempt to upstream them though.

    The other patches are mainly for thermal stuff which I didn't look into that much to be honest, so I guess they can be skipped.

    There's also my patch which sets the default volume for the analog headphone jack on the XU3 to 75%.
    That's because alsa would always reset it back to 0 after each reboot in older kernel releases.
    For some reason alsa-state would never save it.

    But my XU3 is in its final resting place, running from an iSCSI lun building packages like glibc and mesa for the Fedora repo and also serving as a VirtualHere server for my main rig.
    So I won't be testing out the headphone jack any longer :p

    But like I said, the two mentioned patches are definitely required for the XU4's Ethernet adapter.

    chewitt
    Posts: 191
    Joined: Mon Aug 12, 2019 12:27 pm
    languages_spoken: english
    Has thanked: 4 times
    Been thanked: 134 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by chewitt »

    @AreaScout I'm not targetting specific people and naming names. I just look at the kernels HK have been shipping for years. Those are full of patches from many contributors that "fix" things, most of which have never been properly documented or submitted upstream, so the long-term maintainability of the codebase is poor. RE Kodi changes; sure Kodi won't accept current hacks needed for XU4 support, because Kodi is the wrong place to fix most of the issues. That's the entire point of the GBM/V4L2 direction in Kodi - drop the hacks. The correct place for most changes is the kernel; if the presentation of VDEC devices and capabilities is sorted out the hacks aren't needed. NB: I am a moaning old git when it comes to upstreaming. I'm a maintainer. I care that people keep working on the technical debt of the codebase(s) that I work with, else the debt only grows and becomes a problem. Kodi and kernel keep moving forwards, so the saying "If you stand still; in reality you're moving backwards" applies.

    @MastaG thanks for the context on the Ethernet patches.

    chewitt
    Posts: 191
    Joined: Mon Aug 12, 2019 12:27 pm
    languages_spoken: english
    Has thanked: 4 times
    Been thanked: 134 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by chewitt »

    I found the upstream submission and rejection (due to poor testing and implementation) of the Ethernet patches in 2015 (and no attempt since) so I will leave those out of my branch unless I see actual user reports of issues - I haven't noticed any shutdown or reboot problems myself.

    AreaScout
    Posts: 1896
    Joined: Sun Jul 07, 2013 3:05 am
    languages_spoken: german, english
    ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
    N1, Go, VU5A, Show2, CloudShell2,
    H2, N2, VU7A, VuShell, Go2, C4
    Has thanked: 152 times
    Been thanked: 421 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by AreaScout »

    chewitt wrote:
    Wed Aug 24, 2022 1:13 am
    @AreaScout I'm not targetting specific people and naming names. I just look at the kernels HK have been shipping for years. Those are full of patches from many contributors that "fix" things, most of which have never been properly documented or submitted upstream, so the long-term maintainability of the codebase is poor. RE Kodi changes; sure Kodi won't accept current hacks needed for XU4 support, because Kodi is the wrong place to fix most of the issues. That's the entire point of the GBM/V4L2 direction in Kodi - drop the hacks. The correct place for most changes is the kernel; if the presentation of VDEC devices and capabilities is sorted out the hacks aren't needed. NB: I am a moaning old git when it comes to upstreaming. I'm a maintainer. I care that people keep working on the technical debt of the codebase(s) that I work with, else the debt only grows and becomes a problem. Kodi and kernel keep moving forwards, so the saying "If you stand still; in reality you're moving backwards" applies.

    @MastaG thanks for the context on the Ethernet patches.
    The GBM/V4L2 direction will not prevent manufacture/reseller from making patches for there SBC's, ODROID's always had more compatible patches to other SBC's than for example the RPi had, for the RPi the patches are huge, sure that changed with GBM/V4L2 and it got already better, but patches in general you will always have, just my two cents

    Regards,
    Daniel

    AreaScout
    Posts: 1896
    Joined: Sun Jul 07, 2013 3:05 am
    languages_spoken: german, english
    ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
    N1, Go, VU5A, Show2, CloudShell2,
    H2, N2, VU7A, VuShell, Go2, C4
    Has thanked: 152 times
    Been thanked: 421 times
    Contact:

    Re: Linux kernel 5.10 on XU3/4

    Post by AreaScout »

      @all

      Just for completion I added patches used for KODI 19.4 on my XU4 CloudShell2 NAS image, you can find it on my github page https://github.com/AreaScout/xbmc/commits/Matrix

      Regards,
      Daniel
      These users thanked the author AreaScout for the post (total 2):
      odroid (Thu Sep 01, 2022 9:05 pm) • meveric (Sun Sep 25, 2022 11:43 pm)

      Post Reply

      Return to “Linux Kernel 5.4 Development Party”

      Who is online

      Users browsing this forum: No registered users and 3 guests