Page 1 of 1

Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Sat Apr 06, 2024 7:49 pm
by coppice
Hi,
Fedora 39 just updated to Linux kernel 6.8.4. The blackmagic 12.8.1a1 module builds OK, but the related blackmagic-io module fails, with the compiler complaining that:
mutex_init(mutex)
mutex_lock(mutex)
mutex_trylock(mutex) and
mutex_unlock(mutex)
cannot be resolved. With Linux kernel 6.7.11 things were still OK.

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Mon Apr 08, 2024 9:00 am
by NVieville
hello,

Here is an attempt to fix this issue.

Code and patch file (as a zip file) provided for ease of use.

Code: Select all
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_locks.c ./blackmagic-io-12.8.1a1/bm_locks.c
--- ./blackmagic-io-12.8.1a1.orig/bm_locks.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_locks.c   2024-04-08 10:31:15.502799014 +0200
@@ -31,6 +31,9 @@
 #if KERNEL_VERSION_OR_LATER(4, 11, 0)
    #include <linux/sched/debug.h>
 #endif
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   #include <linux/mutex.h>
+#endif
 #include "bm_locks.h"
 #include "bm_util.h"
 
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_mm.c ./blackmagic-io-12.8.1a1/bm_mm.c
--- ./blackmagic-io-12.8.1a1.orig/bm_mm.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_mm.c   2024-04-08 10:42:57.193768026 +0200
@@ -237,7 +237,11 @@
 
 int bm_dma_sg_bus_map(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    if (unlikely(nents <= 0))
    {
       sg_free_table(sgTable);
@@ -254,7 +258,11 @@
 
 void bm_dma_sg_bus_unmap(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    bm_atomic_sub(&statistics.pages_mapped, sgTable->orig_nents);
    sg_free_table(sgTable);
    kfree(sgTable);
@@ -341,7 +349,11 @@
    bm_dma_subpage_t* subpage = kzalloc(sizeof(*subpage), GFP_KERNEL);
    if (! subpage)
       return NULL;
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, (enum dma_data_direction) dir);
+#else
    subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, dir);
+#endif
    if (dma_mapping_error(&pci->pdev->dev, subpage->busAddr))
    {
       kfree(subpage);
@@ -354,7 +366,11 @@
 
 void bm_dma_bus_unmap_kernel_subpage(bm_pci_device_t* pci, bm_dma_subpage_t* subpage, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, (enum dma_data_direction) dir);
+#else
    dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, dir);
+#endif
    bm_atomic_sub(&statistics.memory_mapped, subpage->size);
    kfree(subpage);
 }
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_util.c ./blackmagic-io-12.8.1a1/bm_util.c
--- ./blackmagic-io-12.8.1a1.orig/bm_util.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_util.c   2024-04-08 10:37:57.007781283 +0200
@@ -137,7 +137,11 @@
       alloc_size += align - 1;
    }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   if (get_order(alloc_size) < MAX_PAGE_ORDER)
+#else
    if (get_order(alloc_size) < MAX_ORDER)
+#endif
       mem = (vm_address_t)kmalloc(alloc_size, GFP_KERNEL);
 
    if (mem == 0 && (flags & BM_ALLOC_CONTIGUOUS) == 0)
@@ -532,7 +536,11 @@
       INIT_HLIST_HEAD(&event_table.events[i]);
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static bm_event_t* get_event(void* event, bool create)
+#else
 bm_event_t* get_event(void* event, bool create)
+#endif
 {
    bm_event_t* ev;
    unsigned idx = hash_ptr(event, EVENT_TABLE_BITS);
@@ -572,7 +580,11 @@
    return ev;
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static void put_event(bm_event_t* ev)
+#else
 void put_event(bm_event_t* ev)
+#endif
 {
    unsigned long flags;
    spin_lock_irqsave(&event_table.lock, flags);


Hope this will help.

Cordially,


--
NVieville

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Fri Apr 12, 2024 2:05 pm
by goldyfruit
NVieville wrote:hello,

Here is an attempt to fix this issue.

Code and patch file (as a zip file) provided for ease of use.

Code: Select all
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_locks.c ./blackmagic-io-12.8.1a1/bm_locks.c
--- ./blackmagic-io-12.8.1a1.orig/bm_locks.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_locks.c   2024-04-08 10:31:15.502799014 +0200
@@ -31,6 +31,9 @@
 #if KERNEL_VERSION_OR_LATER(4, 11, 0)
    #include <linux/sched/debug.h>
 #endif
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   #include <linux/mutex.h>
+#endif
 #include "bm_locks.h"
 #include "bm_util.h"
 
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_mm.c ./blackmagic-io-12.8.1a1/bm_mm.c
--- ./blackmagic-io-12.8.1a1.orig/bm_mm.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_mm.c   2024-04-08 10:42:57.193768026 +0200
@@ -237,7 +237,11 @@
 
 int bm_dma_sg_bus_map(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    if (unlikely(nents <= 0))
    {
       sg_free_table(sgTable);
@@ -254,7 +258,11 @@
 
 void bm_dma_sg_bus_unmap(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    bm_atomic_sub(&statistics.pages_mapped, sgTable->orig_nents);
    sg_free_table(sgTable);
    kfree(sgTable);
@@ -341,7 +349,11 @@
    bm_dma_subpage_t* subpage = kzalloc(sizeof(*subpage), GFP_KERNEL);
    if (! subpage)
       return NULL;
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, (enum dma_data_direction) dir);
+#else
    subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, dir);
+#endif
    if (dma_mapping_error(&pci->pdev->dev, subpage->busAddr))
    {
       kfree(subpage);
@@ -354,7 +366,11 @@
 
 void bm_dma_bus_unmap_kernel_subpage(bm_pci_device_t* pci, bm_dma_subpage_t* subpage, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, (enum dma_data_direction) dir);
+#else
    dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, dir);
+#endif
    bm_atomic_sub(&statistics.memory_mapped, subpage->size);
    kfree(subpage);
 }
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_util.c ./blackmagic-io-12.8.1a1/bm_util.c
--- ./blackmagic-io-12.8.1a1.orig/bm_util.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_util.c   2024-04-08 10:37:57.007781283 +0200
@@ -137,7 +137,11 @@
       alloc_size += align - 1;
    }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   if (get_order(alloc_size) < MAX_PAGE_ORDER)
+#else
    if (get_order(alloc_size) < MAX_ORDER)
+#endif
       mem = (vm_address_t)kmalloc(alloc_size, GFP_KERNEL);
 
    if (mem == 0 && (flags & BM_ALLOC_CONTIGUOUS) == 0)
@@ -532,7 +536,11 @@
       INIT_HLIST_HEAD(&event_table.events[i]);
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static bm_event_t* get_event(void* event, bool create)
+#else
 bm_event_t* get_event(void* event, bool create)
+#endif
 {
    bm_event_t* ev;
    unsigned idx = hash_ptr(event, EVENT_TABLE_BITS);
@@ -572,7 +580,11 @@
    return ev;
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static void put_event(bm_event_t* ev)
+#else
 void put_event(bm_event_t* ev)
+#endif
 {
    unsigned long flags;
    spin_lock_irqsave(&event_table.lock, flags);


Hope this will help.

Cordially,


--
NVieville

Your patch works well with kernel 6.8.5-301.fc40, thanks as usual!

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Sat Apr 13, 2024 3:04 am
by mrtooler
NVieville wrote:hello,

Here is an attempt to fix this issue.

Code and patch file (as a zip file) provided for ease of use.

Code: Select all
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_locks.c ./blackmagic-io-12.8.1a1/bm_locks.c
--- ./blackmagic-io-12.8.1a1.orig/bm_locks.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_locks.c   2024-04-08 10:31:15.502799014 +0200
@@ -31,6 +31,9 @@
 #if KERNEL_VERSION_OR_LATER(4, 11, 0)
    #include <linux/sched/debug.h>
 #endif
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   #include <linux/mutex.h>
+#endif
 #include "bm_locks.h"
 #include "bm_util.h"
 
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_mm.c ./blackmagic-io-12.8.1a1/bm_mm.c
--- ./blackmagic-io-12.8.1a1.orig/bm_mm.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_mm.c   2024-04-08 10:42:57.193768026 +0200
@@ -237,7 +237,11 @@
 
 int bm_dma_sg_bus_map(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    if (unlikely(nents <= 0))
    {
       sg_free_table(sgTable);
@@ -254,7 +258,11 @@
 
 void bm_dma_sg_bus_unmap(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    bm_atomic_sub(&statistics.pages_mapped, sgTable->orig_nents);
    sg_free_table(sgTable);
    kfree(sgTable);
@@ -341,7 +349,11 @@
    bm_dma_subpage_t* subpage = kzalloc(sizeof(*subpage), GFP_KERNEL);
    if (! subpage)
       return NULL;
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, (enum dma_data_direction) dir);
+#else
    subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, dir);
+#endif
    if (dma_mapping_error(&pci->pdev->dev, subpage->busAddr))
    {
       kfree(subpage);
@@ -354,7 +366,11 @@
 
 void bm_dma_bus_unmap_kernel_subpage(bm_pci_device_t* pci, bm_dma_subpage_t* subpage, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, (enum dma_data_direction) dir);
+#else
    dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, dir);
+#endif
    bm_atomic_sub(&statistics.memory_mapped, subpage->size);
    kfree(subpage);
 }
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_util.c ./blackmagic-io-12.8.1a1/bm_util.c
--- ./blackmagic-io-12.8.1a1.orig/bm_util.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_util.c   2024-04-08 10:37:57.007781283 +0200
@@ -137,7 +137,11 @@
       alloc_size += align - 1;
    }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   if (get_order(alloc_size) < MAX_PAGE_ORDER)
+#else
    if (get_order(alloc_size) < MAX_ORDER)
+#endif
       mem = (vm_address_t)kmalloc(alloc_size, GFP_KERNEL);
 
    if (mem == 0 && (flags & BM_ALLOC_CONTIGUOUS) == 0)
@@ -532,7 +536,11 @@
       INIT_HLIST_HEAD(&event_table.events[i]);
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static bm_event_t* get_event(void* event, bool create)
+#else
 bm_event_t* get_event(void* event, bool create)
+#endif
 {
    bm_event_t* ev;
    unsigned idx = hash_ptr(event, EVENT_TABLE_BITS);
@@ -572,7 +580,11 @@
    return ev;
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static void put_event(bm_event_t* ev)
+#else
 void put_event(bm_event_t* ev)
+#endif
 {
    unsigned long flags;
    spin_lock_irqsave(&event_table.lock, flags);


Hope this will help.

Cordially,


--
NVieville


Can confirm this is also required and works for desktopvideo 12.9a3 on kernel 6.8+ (Tested on Pop_OS 22.04 running 6.8.0)

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Sun Apr 14, 2024 7:47 pm
by coppice
blackmagic-io-12.9a3 still has the same problem, but the posted patch seems to work OK for that as well as version 12.8.1a1.

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Mon Apr 15, 2024 8:49 am
by NVieville
coppice wrote:blackmagic-io-12.9a3 still has the same problem, but the posted patch seems to work OK for that as well as version 12.8.1a1.


Thanks for this information.

In order to make it smoother, one can modify the downloaded patch to correspond to the 12.9a3 version, making a copy before.

Code: Select all
cp /path_to_your_patch_directory/blackmagic-io-12.8.1a1-001-fix_for_kernel_6.8.patch /path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch

sed -i -e 's%12\.8\.1a1%12\.9a3%g' /path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch


Then proceed as usual, in the right directory, first dry run, then patch:

Code: Select all
cd /usr/src/

patch -p1 --dry-run </path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch

patch -p1 </path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch


Cordially,


--
NVieville

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Fri May 10, 2024 5:20 pm
by alatteri
Any word from BMD on official support of kernel 6.8? Now that Ubuntu 24.04LTS is released, the drivers really should official support this.

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Sat May 11, 2024 7:21 am
by nilber
Thank you, NVieville. I used it to make a .deb version for AMD64 and was able to get my capture card running in OBS on Pop!_OS 22.04 under Kernel 6.8.

If anyone else needs a Desktop Video driver .deb file (x86-64) patched for kernel 6.8, here's a link to it - https://uploadnow.io/f/HWWTl3d

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Mon May 13, 2024 8:29 pm
by alatteri
Thank you.

nilber wrote:Thank you, NVieville. I used it to make a .deb version for AMD64 and was able to get my capture card running in OBS on Pop!_OS 22.04 under Kernel 6.8.

If anyone else needs a Desktop Video driver .deb file (x86-64) patched for kernel 6.8, here's a link to it - https://uploadnow.io/f/HWWTl3d

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Tue May 14, 2024 5:55 pm
by Dove333
nilber wrote:Thank you, NVieville. I used it to make a .deb version for AMD64 and was able to get my capture card running in OBS on Pop!_OS 22.04 under Kernel 6.8.

If anyone else needs a Desktop Video driver .deb file (x86-64) patched for kernel 6.8, here's a link to it - https://uploadnow.io/f/HWWTl3d

Would you be some kind to re-upload this deb. many thanx

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Tue May 14, 2024 9:34 pm
by nilber
Sorry it didn't work. I uploaded it again here:

https://www.mediafire.com/file/acehix1t ... d.deb/file

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Thu May 16, 2024 5:44 pm
by markhimsley
NVieville wrote:hello,

Here is an attempt to fix this issue.

Thanks NVieville. Using that patch worked on OpenSuse Tumbleweed.

The full process was:
patch the source
Code: Select all
$ cd /usr/src/blackmagic-io-12.9a3
$ sudo patch -p 2  < blackmagic-io-12.8.1a1-001-fix_for_kernel_6.8.patch

then, in order to make dkms do a thorough recompile, I had to delete remnants of old builds
Code: Select all
$ sudo rm -rf /var/lib/dkms/blackmagic/12.7a4
$ sudo rm -rf /var/lib/dkms/blackmagic-io/12.7a4/

then I could use the usual dkms rebuild process
Code: Select all
$ sudo dkms autoinstall -k $(uname -r)

Now MediaExpress sees my Blackmagic Design Intensity Pro 4K.
:D

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostPosted: Thu May 16, 2024 10:37 pm
by goldyfruit
markhimsley wrote:
NVieville wrote:hello,

Here is an attempt to fix this issue.

Thanks NVieville. Using that patch worked on OpenSuse Tumbleweed.

The full process was:
patch the source
Code: Select all
$ cd /usr/src/blackmagic-io-12.9a3
$ sudo patch -p 2  < blackmagic-io-12.8.1a1-001-fix_for_kernel_6.8.patch

then, in order to make dkms do a thorough recompile, I had to delete remnants of old builds
Code: Select all
$ sudo rm -rf /var/lib/dkms/blackmagic/12.7a4
$ sudo rm -rf /var/lib/dkms/blackmagic-io/12.7a4/

then I could use the usual dkms rebuild process
Code: Select all
$ sudo dkms autoinstall -k $(uname -r)

Now MediaExpress sees my Blackmagic Design Intensity Pro 4K.
:D

Tested as well on openSUSE Tumbleweed and all good!