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

blackmagic decklink: init pkg and module at 12.2 #102512

Closed
wants to merge 5 commits into from

Conversation

hexchen
Copy link
Member

@hexchen hexchen commented Nov 2, 2020

Motivation for this change

There's currently no support for the Blackmagic Design Decklink hardware in nixos. The driver for these AV-interface cards is available from the manufacturer directly, but it only supports DEB and RPM-based distros natively. This PR adds in the required driver as well as one of the userspace services that are required to make the hardware work.

It does not include any of the userspace GUI tools that can be used to configure and monitor the capture cards, since those proprietary applications depend on QT and I have yet to repackage them for nix.

I'll leave the PR marked as a draft until I have tested the module on hardware with a Decklink card.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

boot.extraModulePackages = [ kernelPackages.decklink ];

# supporting service
systemd.services."DecklinkVideoHelper" = {
Copy link

Choose a reason for hiding this comment

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

can this run as non-root?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll have to check when testing on hardware.

Copy link
Member Author

Choose a reason for hiding this comment

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

the helper isn't needed at all.

Copy link
Member Author

@hexchen hexchen Apr 23, 2021

Choose a reason for hiding this comment

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

Correction, it actually is. I had it running from a previous test when writing that message. It also has to run as root.

Copy link

Choose a reason for hiding this comment

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

Really? What capabilities does it need? What files/devices does it access? I don't think a NixOS module should run some random proprietary binary as root service unless it absolutely has to.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can run an strace on it next time I have access to the hardware. It is unclear what it actually does, but without it running the device does not initialize. I assume it sends a bitstream to onboard FPGAs or something like that.

Copy link
Member

Choose a reason for hiding this comment

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

That would be great!

Copy link
Member Author

Choose a reason for hiding this comment

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

I've finally taken that strace, see https://gist.github.com/hexchen/cc39485001ba513e0cd9c970fd695f18

I am unsure on how to act on this though, as whatever it is doing only succeeds if run as root, and I am unable to figure out why from that strace.

nixos/modules/hardware/decklink.nix Outdated Show resolved Hide resolved
nixos/modules/hardware/decklink.nix Outdated Show resolved Hide resolved
nixos/modules/hardware/decklink.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Nov 2, 2020

Maybe changing the meta.maintainers attributes will fix OfBorg.

Please also change this to have three commits, one for the module and one for each package, all of them with commit messages that fit the contribution guidelines. They could look like this:

linuxPackages.decklink: init at 1.16
blackmagicDesktopVideo: init at 1.16
nixos/decklink: init

@hexchen hexchen force-pushed the module/decklink branch 3 times, most recently from edbc279 to 8422185 Compare November 2, 2020 19:41
@ghost
Copy link

ghost commented Nov 3, 2020

Building a system with hardware.decklink.enable = true; gives the following message:

  Checking that all programs called by relative paths in udev rules exist in /nix/store/7aa53389d52a35h5f5x79pph0qi7kchz-systemd-246.6/lib/udev... OK
  Checking that all programs called by absolute paths in udev rules exist... FAIL
  /usr/lib/blackmagic/DesktopVideo/DesktopVideoNotifier is called in udev rules but is not executable or does not exist

@hexchen hexchen force-pushed the module/decklink branch 2 times, most recently from 9bf1aaf to 70db49f Compare November 22, 2020 02:04
@hexchen hexchen force-pushed the module/decklink branch 2 times, most recently from 33f837b to 9bceda6 Compare November 29, 2020 18:07
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/tools/video/blackmagic-desktop-video/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/decklink/default.nix Outdated Show resolved Hide resolved
@hexchen hexchen force-pushed the module/decklink branch 2 times, most recently from d2e68be to 1d848bd Compare April 23, 2021 17:07
@hexchen
Copy link
Member Author

hexchen commented Apr 23, 2021

@SuperSandro2000 I've updated the commit to use ${version} in all places appropriate and the major version ${major} everywhere else.

@petabyteboy this has been tested on hardware and been verified to work.

@hexchen hexchen marked this pull request as ready for review April 23, 2021 17:09
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Other than my new comment on running the helper service as root, this looks good to me.

boot.extraModulePackages = [ kernelPackages.decklink ];

# supporting service
systemd.services."DecklinkVideoHelper" = {
Copy link

Choose a reason for hiding this comment

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

Really? What capabilities does it need? What files/devices does it access? I don't think a NixOS module should run some random proprietary binary as root service unless it absolutely has to.

nixos/modules/hardware/decklink.nix Outdated Show resolved Hide resolved
nixos/modules/hardware/decklink.nix Outdated Show resolved Hide resolved
boot.extraModulePackages = [ kernelPackages.decklink ];

# supporting service
systemd.services."DecklinkVideoHelper" = {
Copy link
Member

Choose a reason for hiding this comment

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

That would be great!

@hexchen hexchen force-pushed the module/decklink branch 2 times, most recently from 38f9b9b to d5314ef Compare June 16, 2021 20:38
@hexchen hexchen changed the title blackmagic decklink: init pkg and module at 11.6 blackmagic decklink: init pkg and module at 12.0 Jun 16, 2021
@hexchen
Copy link
Member Author

hexchen commented Jun 16, 2021

I updated to a more current version of the driver, since I was able to finally test that on hardware as well.

@hexchen
Copy link
Member Author

hexchen commented Nov 28, 2021

I updated the driver to version 12.2, feel free to test it. I should be able to get it tested on a Blackmagic Quad HDMI next week.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

Aside from this one change, the module looks great 👍

I'll leave the rest of the review and merge to @davidak because I don't have this hardware or the context around the software.

Thanks!

config = mkIf cfg.enable {
boot.kernelModules = [ "blackmagic" "blackmagic-io" "snd_blackmagic-io" ];
boot.extraModulePackages = [ kernelPackages.decklink ];
systemd.packages = [ pkgs.blackmagicDesktopVideo ];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
systemd.packages = [ pkgs.blackmagicDesktopVideo ];
systemd.packages = [ pkgs.blackmagicDesktopVideo ];
systemd.services.DecklinkVideoHelper.wantedBy = [ "multi-user.target" ];

See #81138 for details.

Copy link
Member

@davidak davidak Dec 1, 2021

Choose a reason for hiding this comment

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

It seem not to work yet.

[root@gaming:~]# lspci | grep Blackmagic
05:00.0 Multimedia video controller: Blackmagic Design Intensity Pro 4K
(this did work without the driver)
[root@gaming:~]# lsmod | grep blackmagic

[root@gaming:~]# systemctl status DecklinkVideoHelper
Unit DecklinkVideoHelper.service could not be found.

I do not see DesktopVideoHelper.service in /var/run/current-system/sw/lib/systemd/system:

[root@gaming:~]# ll /var/run/current-system/sw/lib/systemd/system | grep DesktopVideoHelper

I see the kernel modules in /var/run/current-system/kernel-modules/lib/modules/5.10.81/extra/:

[root@gaming:~]# ll /nix/store/x71rnsfknvga3hb7rhg3j889a0wc1cvn-nixos-system-gaming-22.05.git.aa691f07224/kernel-modules/lib/modules/5.10.81/extra/
total 1080
-r--r--r-- 1 root root 621372 Jan  1  1970 blackmagic-io.ko.xz
-r--r--r-- 1 root root 402860 Jan  1  1970 blackmagic.ko.xz
-r--r--r-- 1 root root  73992 Jan  1  1970 snd_blackmagic-io.ko.xz

src = requireFile {
name = "Blackmagic_Desktop_Video_Linux_${major}.tar.gz";
url = "https://www.blackmagicdesign.com/support/download/33abc1034cd54cf99101f9acd2edd93d/Linux";
sha256 = "62954a18b60d9040aa4a959dff30ac9c260218ef78d6a63cbb243788f7abc05f";
Copy link
Member

@davidak davidak Dec 1, 2021

Choose a reason for hiding this comment

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

Suggested change
sha256 = "62954a18b60d9040aa4a959dff30ac9c260218ef78d6a63cbb243788f7abc05f";
sha256 = "62954a18b60d9040aa4a959dff30ac9c260218ef78d6a63cbb243788f7abc05f";
message = ''
Please download the file manually from the developers website:
https://www.blackmagicdesign.com/support/download/33abc1034cd54cf99101f9acd2edd93d/Linux
They want you to register your product, but you can also download
the file without registration by clicking 'Download Only' in the
bottom left corner of the dialog.
Then add the downloaded file to the Nix store using:
nix-store --add-fixed sha256 Blackmagic_Desktop_Video_Linux_12.2.tar.gz
If you use Google Chrome or Chromium, you have to rename the
file to end with tar.gz first.
'';
# Chromium specific issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1275694
# Remove hint when fixed.

Those instructions seem helpful.

Copy link
Member

Choose a reason for hiding this comment

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

In https://github.com/NixOS/nixpkgs/pull/152113/files is a script to download files from blackmagicdesign.com. Maybe that would work here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

It indeed works. Thanks for the pointer, I was finally able to implement that 1.5 years later...

@davidak
Copy link
Member

davidak commented Dec 1, 2021

decklink does not build with latest mainline kernel:

boot.kernelPackages = pkgs.linuxPackages_latest;

Please exclude 5.15.x. Link to upstream issue would be perfect.

@davidak davidak changed the title blackmagic decklink: init pkg and module at 12.0 blackmagic decklink: init pkg and module at 12.2 Dec 1, 2021
@davidak davidak added this to In progress in Blackmagic Design Decklink support via automation Dec 1, 2021
Blackmagic Design Decklink support automation moved this from In progress to Review in progress Dec 1, 2021
Copy link
Member

@davidak davidak left a comment

Choose a reason for hiding this comment

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

Does not work. See comments.

@davidak
Copy link
Member

davidak commented Jan 22, 2022

@hexchen do you remember to check this?

@hexchen
Copy link
Member Author

hexchen commented Apr 28, 2022

Sorry about the delay. I'm going to look into it this weekend.

@reinismu
Copy link
Contributor

Awesome work!
I am currently looking at NixOS to help me organize my Linux images.
Having Decklink card support is an essential feature for me.

As I understand, the last issue is that Decklink doesn't support the newest Linux kernel?

@blitz
Copy link
Contributor

blitz commented Jan 10, 2023

I just tried this with 14.2.1 and Linux 5.15 and the driver tripped over itself. :(

My patches are here.

Jan 10 23:53:59 babylon kernel: blackmagic: module license 'Proprietary' taints kernel.
Jan 10 23:53:59 babylon kernel: Disabling lock debugging due to kernel taint
Jan 10 23:53:59 babylon kernel: blackmagic: Loading driver (version: 12.4.1a15)
Jan 10 23:53:59 babylon kernel: BlackmagicIO: Driver version 12.4.1a15 loading
Jan 10 23:53:59 babylon kernel: blackmagic-io 0000:04:00.0: enabling device (0000 -> 0002)
Jan 10 23:53:59 babylon kernel: BlackmagicIO: Enabled device "UltraStudio Recorder 3G" x1/5 GT/s (4988d840,5e0400) FW Date: 05-24 22:17
Jan 10 23:53:59 babylon kernel: blackmagic-io 0000:04:00.0: swiotlb buffer is full (sz: 3072000 bytes), total 32768 (slots), used 0 (slots)
Jan 10 23:53:59 babylon kernel: IOBufferMemoryDescriptor::busMap failed
Jan 10 23:53:59 babylon kernel: kIOMDDMAMap failed (0x3fe)
Jan 10 23:53:59 babylon kernel: BlackmagicIO: Failed to get physical address for segment (ret=0x3fe descLen=3072000 offset=0)
Jan 10 23:53:59 babylon kernel: BlackmagicIO: init[71]: Failed to configure DMA
Jan 10 23:53:59 babylon kernel: BlackmagicIO: configureEnginesAndInterfaces[195]: Failed to create audio input sample buffer
Jan 10 23:53:59 babylon kernel: BlackmagicIO: start[118]: Failed to configure DMA engines and A/V interfaces
Jan 10 23:53:59 babylon kernel: ------------[ cut here ]------------
Jan 10 23:53:59 babylon kernel: kernel BUG at drivers/pci/msi.c:369!
Jan 10 23:53:59 babylon kernel: invalid opcode: 0000 [#1] SMP NOPTI
Jan 10 23:53:59 babylon kernel: CPU: 7 PID: 717 Comm: systemd-modules Tainted: P           O      5.15.86 #1-NixOS
Jan 10 23:53:59 babylon kernel: Hardware name: TUXEDO TUXEDO Book XP14 Gen12/NV4XMB,ME,MZ, BIOS 1.07.14RTR1 08/24/2021
Jan 10 23:53:59 babylon kernel: RIP: 0010:free_msi_irqs+0x11c/0x140
Jan 10 23:53:59 babylon kernel: Code: cc 8b 43 14 85 c0 0f 84 32 ff ff ff 31 ed eb 0f 83 c5 01 39 6b 14 0f 86 22 ff ff ff 8b 7b 10 01 ef e8 88 3a c0 ff 84 c0 >
Jan 10 23:53:59 babylon kernel: RSP: 0018:ffffa18a806dbb80 EFLAGS: 00010202
Jan 10 23:53:59 babylon kernel: RAX: 0000000000000001 RBX: ffff8de9012c4400 RCX: 0000000000000000
Jan 10 23:53:59 babylon kernel: RDX: ffff8de901edd240 RSI: ffff8de901edd358 RDI: 000000000000009e
Jan 10 23:53:59 babylon kernel: RBP: 0000000000000000 R08: ffff8de94937ec00 R09: ffffffffa9138fe0
Jan 10 23:53:59 babylon kernel: R10: 0000000000000000 R11: 0000000000000000 R12: ffff8de909f8f2f0
Jan 10 23:53:59 babylon kernel: R13: ffff8de909f8f000 R14: ffff8de94b949d28 R15: ffffa18a806dbe78
Jan 10 23:53:59 babylon kernel: FS:  00007f6911bd1c40(0000) GS:ffff8df0915c0000(0000) knlGS:0000000000000000
Jan 10 23:53:59 babylon kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Jan 10 23:53:59 babylon kernel: CR2: 00007f7882203dcd CR3: 000000014b520004 CR4: 0000000000770ee0
Jan 10 23:53:59 babylon kernel: PKRU: 55555554
Jan 10 23:53:59 babylon kernel: Call Trace:
Jan 10 23:53:59 babylon kernel:  <TASK>
Jan 10 23:53:59 babylon kernel:  bm_pci_stop+0x20/0x30 [blackmagic_io]
Jan 10 23:53:59 babylon kernel:  _ZN11IOPCIDevice4stopEP9IOService+0x4f/0x70 [blackmagic_io]
Jan 10 23:53:59 babylon kernel:  ? bmio_device_init+0x15f/0x190 [blackmagic_io]
Jan 10 23:53:59 babylon kernel:  ? pci_scan_child_bus_extend+0x27d/0x2a0
Jan 10 23:53:59 babylon kernel:  ? bmio_device_alloc+0x67/0xb0 [blackmagic_io]
Jan 10 23:53:59 babylon kernel:  ? bmio_probe+0xa/0x20 [blackmagic_io]
Jan 10 23:53:59 babylon kernel:  ? local_pci_probe+0x3f/0x80
Jan 10 23:53:59 babylon kernel:  ? __cond_resched+0x16/0x50
Jan 10 23:53:59 babylon kernel:  ? pci_device_probe+0xfe/0x1c0
Jan 10 23:53:59 babylon kernel:  ? really_probe+0x1f6/0x3f0
Jan 10 23:53:59 babylon kernel:  ? __driver_probe_device+0x105/0x180
Jan 10 23:53:59 babylon kernel:  ? driver_probe_device+0x1e/0x90
Jan 10 23:53:59 babylon kernel:  ? __driver_attach+0x9d/0x1e0
Jan 10 23:53:59 babylon kernel:  ? __device_attach_driver+0x110/0x110
Jan 10 23:53:59 babylon kernel:  ? __device_attach_driver+0x110/0x110
Jan 10 23:53:59 babylon kernel:  ? bus_for_each_dev+0x75/0xc0
Jan 10 23:53:59 babylon kernel:  ? bus_add_driver+0x13a/0x200
Jan 10 23:53:59 babylon kernel:  ? driver_register+0x8f/0xf0
Jan 10 23:53:59 babylon kernel:  ? 0xffffffffc12cf000
Jan 10 23:53:59 babylon kernel:  ? bmio_init+0x48/0x1000 [blackmagic_io]
Jan 10 23:53:59 babylon kernel:  ? do_one_initcall+0x41/0x1d0
Jan 10 23:53:59 babylon kernel:  ? __cond_resched+0x16/0x50
Jan 10 23:53:59 babylon kernel:  ? kmem_cache_alloc_trace+0x44/0x3d0
Jan 10 23:53:59 babylon kernel:  ? do_init_module+0x4c/0x250
Jan 10 23:53:59 babylon kernel:  ? __do_sys_init_module+0x12e/0x1b0
Jan 10 23:53:59 babylon kernel:  ? do_syscall_64+0x38/0x90
Jan 10 23:53:59 babylon kernel:  ? entry_SYSCALL_64_after_hwframe+0x61/0xcb
Jan 10 23:53:59 babylon kernel:  </TASK>

@reinismu
Copy link
Contributor

I wonder if this is related https://forum.blackmagicdesign.com/viewtopic.php?p=895848#p895848

To the crash we notice

@blitz
Copy link
Contributor

blitz commented Apr 14, 2023

I wonder if this is related https://forum.blackmagicdesign.com/viewtopic.php?p=895848#p895848

To the crash we notice

No, that's a different issue.

@reinismu
Copy link
Contributor

I wonder if this is related https://forum.blackmagicdesign.com/viewtopic.php?p=895848#p895848
To the crash we notice

No, that's a different issue.

Have you managed to get it working? Know what could be the reason for errors?

@SuperSandro2000
Copy link
Member

Closing because this is stale for the last 1 or 2 years depending on how you count.

Blackmagic Design Decklink support automation moved this from Review in progress to Done Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

7 participants