Repository navigation
Closed
Description
I'm trying to get TW6869 TV capture card running, but I'm seem to be stuck at a DMA allocation issue. I think this is related to DMA coherent allocations. I've increased coherent_pool=32M, but that did not help. Increasing CMA also does not help. Kernel config attached. I'd be grateful for any pointers on how to debug this.
[ 1.550499] brcm-pcie 47d500000.pcie: host bridge /scb/pcie@7d500000 ranges:
[ 1.550534] brcm-pcie 47d500000.pcie: No bus range found for /scb/pcie@7d500000, using [bus 00-ff]
[ 1.550608] brcm-pcie 47d500000.pcie: MEM 0x0600000000..0x063fffffff -> 0x00c0000000
[ 1.550688] brcm-pcie 47d500000.pcie: IB MEM 0x0000000000..0x00ffffffff -> 0x0400000000
[ 1.584131] brcm-pcie 47d500000.pcie: link up, 2.5 GT/s PCIe x1 (SSC)
[ 1.584319] brcm-pcie 47d500000.pcie: PCI host bridge to bus 0000:00
[ 1.584342] pci_bus 0000:00: root bus resource [bus 00-ff]
[ 1.584365] pci_bus 0000:00: root bus resource [mem 0x600000000-0x63fffffff] (bus address [0xc0000000-0xffffffff])
[ 1.584449] pci 0000:00:00.0: [14e4:2711] type 01 class 0x060400
[ 1.584683] pci 0000:00:00.0: PME# supported from D0 D3hot
[ 1.588387] pci 0000:00:00.0: bridge configuration invalid ([bus ff-ff]), reconfiguring
[ 1.588634] pci 0000:01:00.0: TW686x PCI class overridden (0x000000 -> 0x048001)
[ 1.588656] pci 0000:01:00.0: [1797:6869] type 00 class 0x048001
[ 1.588713] pci 0000:01:00.0: reg 0x10: [mem 0x00000000-0x00000fff pref]
[ 1.588847] pci 0000:01:00.0: enabling Extended Tags
[ 1.589049] pci 0000:01:00.0: PME# supported from D0 D3hot D3cold
[ 1.601400] pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
[ 1.601444] pci 0000:00:00.0: BAR 8: assigned [mem 0x600000000-0x6000fffff]
[ 1.601468] pci 0000:01:00.0: BAR 0: assigned [mem 0x600000000-0x600000fff pref]
[ 1.601495] pci 0000:00:00.0: PCI bridge to [bus 01]
[ 1.601520] pci 0000:00:00.0: bridge window [mem 0x600000000-0x6000fffff]
modprobe tw686x
[ 18.516474] ------------[ cut here ]------------
[ 18.521163] Failed to get suitable pool for 0000:01:00.0
[ 18.526585] WARNING: CPU: 2 PID: 490 at kernel/dma/pool.c:282 dma_alloc_from_pool+0x98/0x1c0
[ 18.535139] Modules linked in: tw686x(+) videobuf2_dma_sg hci_uart btbcm bluetooth ecdh_generic ecc ipv6 vcan brcmfmac brcmutil vc4 cec v3d drm_kms_helper gpu_sched drm cfg80211 drm_panel_orientation_quirks raspberrypi_hwmon bcm2835_isp(C) snd_soc_core bcm2835_codec(C) rfkill bcm2835_v4l2(C) snd_compress snd_pcm_dmaengine snd_pcm i2c_brcmstb bcm2835_mmal_vchiq(C) v4l2_mem2mem videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops videobuf2_v4l2 videobuf2_common snd_timer vc_sm_cma(C) videodev mc snd syscopyarea sysfillrect sysimgblt fb_sys_fops rpivid_mem backlight uio_pdrv_genirq uio
[ 18.587864] CPU: 2 PID: 490 Comm: modprobe Tainted: G WC 5.10.17-v8 #6
[ 18.595713] Hardware name: Raspberry Pi Compute Module 4 Rev 1.0 (DT)
[ 18.602241] pstate: 00000005 (nzcv daif -PAN -UAO -TCO BTYPE=--)
[ 18.608329] pc : dma_alloc_from_pool+0x98/0x1c0
[ 18.612917] lr : dma_alloc_from_pool+0x98/0x1c0
[ 18.617504] sp : ffffffc01e8eb5e0
[ 18.620857] x29: ffffffc01e8eb5e0 x28: ffffffc01e01a000
[ 18.626242] x27: ffffff8041056700 x26: ffffffc01e8eb6d0
[ 18.631626] x25: ffffff80410b30b0 x24: ffffffc0112e18f8
[ 18.637010] x23: fffffffeffe00000 x22: ffffffc0100bb880
[ 18.642393] x21: ffffffc010d148b0 x20: 0000000000001000
[ 18.647777] x19: 000000002ac01000 x18: 0000000000000010
[ 18.653160] x17: 000000000000016c x16: ffffffc015c59620
[ 18.658543] x15: ffffff804238df40 x14: ffffffffffffffff
[ 18.663926] x13: ffffffc09e8eb297 x12: ffffffc01e8eb29f
[ 18.669310] x11: 0000000000000001 x10: ffffffc011147950
[ 18.674694] x9 : ffffffc0100978e0 x8 : 0000000000000001
[ 18.680077] x7 : 0000000000017fe8 x6 : 0000000000000000
[ 18.685461] x5 : 0000000000000000 x4 : ffffff80ff79d818
[ 18.690844] x3 : ffffffc010e89000 x2 : 0000000000000001
[ 18.696228] x1 : d775422ddf87a300 x0 : 0000000000000000
[ 18.701612] Call trace:
[ 18.704086] dma_alloc_from_pool+0x98/0x1c0
[ 18.708323] dma_direct_alloc+0x278/0x330
[ 18.712382] dma_alloc_attrs+0x88/0x110
[ 18.716273] tw686x_sg_dma_alloc+0x144/0x1a0 [tw686x]
[ 18.721392] tw686x_set_format+0x258/0x2e0 [tw686x]
[ 18.726335] tw686x_video_init+0x134/0x640 [tw686x]
[ 18.731278] tw686x_probe+0x338/0x390 [tw686x]
[ 18.735781] pci_device_probe+0xc0/0x190
[ 18.739753] really_probe+0xec/0x3c0
[ 18.743371] driver_probe_device+0x60/0xc0
[ 18.747519] device_driver_attach+0x7c/0x90
[ 18.751754] __driver_attach+0x60/0xf0
[ 18.755550] bus_for_each_dev+0x78/0xd0
[ 18.759433] driver_attach+0x2c/0x40
[ 18.763052] bus_add_driver+0x158/0x200
[ 18.766935] driver_register+0x6c/0x130
[ 18.770818] __pci_register_driver+0x4c/0x60
[ 18.775145] tw686x_pci_driver_init+0x34/0x1000 [tw686x]
[ 18.780528] do_one_initcall+0x4c/0x2e0
[ 18.784412] do_init_module+0x60/0x260
[ 18.788207] load_module+0x20bc/0x2710
[ 18.792002] __do_sys_finit_module+0xb8/0x100
[ 18.796414] __arm64_sys_finit_module+0x28/0x40
[ 18.801004] el0_svc_common.constprop.0+0x84/0x1d0
[ 18.805857] do_el0_svc+0x2c/0xa0
[ 18.809215] el0_svc+0x20/0x30
[ 18.812305] el0_sync_handler+0xb0/0xc0
[ 18.816188] el0_sync+0x174/0x180
[ 18.819543] ---[ end trace d8b5a8764c3af7c7 ]---
[ 18.824254] tw686x 0000:01:00.0: dma0: unable to allocate P-buffer
[ 18.830631] tw686x 0000:01:00.0: can't register video
[ 18.835816] tw686x: probe of 0000:01:00.0 failed with error -12
trying loading module using dma_mode=contig: module loads, but when trying to launch gstreamer it fails with an allocation error.
[ 416.499577] tw6869: PCI 0000:01:00.0, IRQ 70, MMIO 0x600000000 (contig mode)
[ 416.515201] ALSA pcmC2D0c,0:tw686x PCM: cannot preallocate for size 65536
[ 416.524472] ALSA pcmC2D0c,1:tw686x PCM: cannot preallocate for size 65536
[ 416.531869] ALSA pcmC2D0c,2:tw686x PCM: cannot preallocate for size 65536
[ 416.539066] ALSA pcmC2D0c,3:tw686x PCM: cannot preallocate for size 65536
[ 431.177298] tw686x 0000:01:00.0: dma_alloc_coherent of size 692224 failed
cmdline
coherent_pool=32M 8250.nr_uarts=1 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 video=HDMI-A-1:1920x1080M@60 video=HDMI-A-2:1920x1080M@60 smsc95xx.macaddr=DC:A6:32:FE:BA:A4 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 console=ttyS0,115200 ip=none elevator=deadline panic=3 consoleblank=0
kernel config
config.txt
Metadata
Metadata
Assignees
Labels
No labels
Activity
6by9 commentedon Mar 9, 2021
There seems to be a common assumption with some drivers that they can set up a 32bit DMA mask and guarantee memory allocations.
https://elixir.bootlin.com/linux/latest/source/drivers/media/pci/tw686x/tw686x-core.c#L279
The PCIe window on the Pi is defined as being at 0x0600000000 - 0x063fffffff, which is at 6-7GB, and therefore not addressable via a 32bit mask.
pelwell commentedon Mar 9, 2021
0x6_00000000 is 24GB. That's the outbound window, i.e. where the PCIe bus appears in ARM space. The DMA mask is declaring the visibility of system memory to a bus master, in this case the PCIe device.
pelwell commentedon Mar 9, 2021
Note that with a recent firmware the PCIe inbound window (where system RAM appears in PCIe space) is at 0x4_00000000 (16GB).
6by9 commentedon Mar 9, 2021
Whoops - too many zeros 😭
walmis commentedon Mar 9, 2021
I've tried changing the mask to DMA_BIT_MASK(64) - no change.
I've added some debug printk's, what fails is pci_alloc_consistent.
0000000000000000 = pci_alloc_consistent len:691200 phys:00000000cb6a2066dev->mmio = 0000000041aa5229vianpl commentedon Mar 9, 2021
I had a quick look at the driver and it seems that the physical address registers the DMA protocol uses are only 32bits*, tough luck. The current inbound window setup will not work for that driver. It maybe makes sense to create an overlay to move the inbound window into the the 32bit address space at the expense of having to bounce buffers, as I'm sure more drivers will show up with this limitation.
walmis commentedon Mar 9, 2021
how about memcpy mode of the driver? the sg stuff is used when dma_mode=sg is selected when loading the module.
vianpl commentedon Mar 9, 2021
The same limitation applies 😞.
I attached a modified device tree that should hopefully do the trick for you (it bypasses firmware's PCIe inbound memory config). It should replace your current bcm2711-rpi-cm4.dtb file, which you'll probably find it in the /boot/ folder (make sure to backup the current one). bcm2711-rpi-cm4.zip
walmis commentedon Mar 9, 2021
I tried the dtb. Not much changes
I ran the diff between dtb's, can't see any changed addressses.
Could you point out which changes you made?
BTW, I'm running
Linux version 5.10.17-v8vianpl commentedon Mar 9, 2021
Yes, my patch didn't had the expected effect. Don't know why.
I got rid of the pcie0 DT alias, which is what firmware uses to edit into the pcie DT node.
Let's try again, this time I've prepared an overlay. I'll be simpler to work with it. I verified it works locally on my CM4 running the latest available firmware, specific kernel versions shouldn't matter as this is purely a firmware thing:
Here's the compiled version: pcie-32bit-dma.zip, extract it and copy it into /boot/overlays and append the following in /boot/config.txt:
dtoverlay=pcie-32bit-dma.After rebooting you should see this log:
[ 1.233849] brcm-pcie fd500000.pcie: IB MEM 0x0000000000..0x00bfffffff -> 0x0000000000walmis commentedon Mar 9, 2021
Success! tw686x got modprobe'd successfully. Thanks!
vianpl commentedon Mar 9, 2021
@pelwell My overlay is rather hacky, do you envision a cleaner way of fixing this?
vianpl commentedon Mar 15, 2021
@pelwell sorry for insisting, any comments?
pelwell commentedon Mar 15, 2021
There is currently no cleaner way of doing this. If you are asking whether such mechanism could be added then the answer is yes of course, but it would take months to roll out so doesn't really help you.
overlays: Add pcie-32bit-dma overlay
4 remaining items
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
vianpl commentedon Mar 24, 2021
With the addition of the
pcie-32bit-dmaDT overlay I think we can close this. 🙂overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay
overlays: Add pcie-32bit-dma overlay