Electron752
Posts: 142
Joined: Mon Mar 02, 2015 7:09 pm

Porting Linux VCHIQ Driver To 64 Bit

Tue Aug 09, 2016 6:08 am

Hi,

I've been tinkering with porting the foundation's custom Linux kernel to arm64 off and on for the last few months. I have just about everything working now including usb(dwc_otg), frame buffer video with dma acceleration, networking, mmc/sd, builtin bluetooth and wifi, and support for the foundation's lcd panel and touchscreen.

The only pieces I think I'm missing are vchiq, hdmi audio, and 3d video. I'm tinkering with vchiq now. I noticed that the arm cpus and video processor share a rather interesting data structure between them. One interesting feature I noticed is that the shared data has pointers to internal kernel synchronization data structures such as semaphores and events.

What I'm wondering is anybody knows if the video processor side actually pokes at these pointers, or if they are just data placeholders for the driver to put whatever in. I noticed that the synchronization structures are not allocated in the coherent dma space, so I don't see how direct poking could possibly work. But I just want to confirm this before I conclude that the port is hopeless.

I'm thinking I can simply change these pointers to u32 values which are just indexes into a mapping table to keep the data structure the same size and the fields at the same offsets. I think this should work as long as the video side doesn't actually access the values.

Some other issues I've noticed but that I think should be easy to fix:

1. The DMA mapping code for data is platform specific to arm(32). I'm going to change this to the more standard Linux driver design such as dma_map_single. I do realize this will have performance issues.

2. The ioctls from user mode pass a pointer to a data structure which contains pointers itself. Since the standard Linux ioctl numbering includes a size field, I think I can change the ioctl numbers between 32 bit and 64 bit and write a 32 bit compatibility layer.

Thanks and if the vchiq driver has already been ported to 64 bit, please let me know and I'll just use that port instead.

Electron752
Posts: 142
Joined: Mon Mar 02, 2015 7:09 pm

Re: Porting Linux VCHIQ Driver To 64 Bit

Tue Aug 09, 2016 9:09 am

OK, I did some more digging and it turns out those pointers are just locations to store stuff. I was able to change them to 32 bit offsets from the start of the state structure and everything is working.

I was able to make few lines of change to the audio driver(which uses vchiq) and now I have HDMI audio working in 64 bit.

The only issue I'm hitting is that since I'm using vanilla debian 64 arm64, I seeing a weird permission issue with audio. If I run applications like audacity as root, HDMI audio works great. If I run it as a normal user, it doesn't work.

I'm guessing raspbian has some rules that change the permissions of the audio device somewhere....

dwelch67
Posts: 1002
Joined: Sat May 26, 2012 5:32 pm

Re: Porting Linux VCHIQ Driver To 64 Bit

Tue Aug 09, 2016 10:32 am

this is a bare metal forum

fruitoftheloom
Posts: 25801
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Porting Linux VCHIQ Driver To 64 Bit

Tue Aug 09, 2016 10:46 am

Electron752 wrote:OK, I did some more digging and it turns out those pointers are just locations to store stuff. I was able to change them to 32 bit offsets from the start of the state structure and everything is working.

I was able to make few lines of change to the audio driver(which uses vchiq) and now I have HDMI audio working in 64 bit.

The only issue I'm hitting is that since I'm using vanilla debian 64 arm64, I seeing a weird permission issue with audio. If I run applications like audacity as root, HDMI audio works great. If I run it as a normal user, it doesn't work.

I'm guessing raspbian has some rules that change the permissions of the audio device somewhere....
Though it is not Debian, there is a Fedora Aarm64 Port

If you want run your rpi3 in 64bit mode go for the arm64 image which has both 64bit kernel and userspace.

https://www.kraxel.org/blog/2016/06/new ... s-uploaded


.
The information is out there....you just have to let it in.

My other Linux machines are a ChromeBox & Intel CoreDuo Desktop

mm7
Posts: 2
Joined: Tue Jul 12, 2016 1:58 pm

Re: Porting Linux VCHIQ Driver To 64 Bit

Wed Aug 10, 2016 7:29 am

Electron752 wrote:OK, I did some more digging and it turns out those pointers are just locations to store stuff. I was able to change them to 32 bit offsets from the start of the state structure and everything is working.

I was able to make few lines of change to the audio driver(which uses vchiq) and now I have HDMI audio working in 64 bit.

The only issue I'm hitting is that since I'm using vanilla debian 64 arm64, I seeing a weird permission issue with audio. If I run applications like audacity as root, HDMI audio works great. If I run it as a normal user, it doesn't work.

I'm guessing raspbian has some rules that change the permissions of the audio device somewhere....
Hi,

This is an attempt I did some days ago to get raspbian working on a 64 bits vchiq. (here's my work). The status of my port is:
  • vcgenmod version working
  • omxplayer works but the video is full of artifacts
Are you using 32 userland libs? I ask this because 32 libs can't ioctl a 64 bits vchiq. A "compat-ioctl" layer is needed. I implemented it (patch:line 633).

Viceversa if you are using 64 userland libs the compat layer is not needed, but userland libs should be patched. (I think that patching all the userland code is a way more difficult task than getting raspbian working on a 64 bits kernel)

Unfortunately I can't help you with HDMI audio stuffs (I don't have a HDMI monitor).
Hope this can help you anyway

Thank you
Sorry for my bad English

ktb
Posts: 1447
Joined: Fri Dec 26, 2014 7:53 pm

Re: Porting Linux VCHIQ Driver To 64 Bit

Sun Jan 29, 2017 8:42 pm

Hi mm7,

Thank you for posting that patch. I've been messing around with it.

I used the rpi-4.9.y branch with the vc4 pull request #1813 (has touch screen support) on top. I manually added in Electron752's additional vchiq and snd_bcm2835 arm64 fixes from the rpi-4.10.y branch (as well as a bunch of other changes so that those commits were compatible with 4.9). /dev/vchiq showed up and vcgencmd worked at that point using a limited 64-bit userland (cmake -DCMAKE_SKIP_RPATH=ON -DCMAKE_BUILD_TYPE=release -DARM64=ON ../).

Then I manually added in your patch on top of everything. The additional device nodes (/dev/vc_cma, , /dev/vcio, /dev/vc-mem and /dev/vcsm) showed up. I see a bunch of (expected) extra vchiq debug output in dmesg and the systemd journal which is interesting.

At this point I'm wondering if you've been able to get vcdbg working on arm64? Or perhaps you've found another way to get some of that information? A functioning edidparser would be interesting too, but not as useful as vcdbg.

How did you get omxplayer to build and work? I didn't get past the requirements for libWFC.so, libbcm_host.so and libopenmaxil.so. I suppose you're using an all 32 bit userland.

Thanks again,
KTB

EDIT: GitHub -- https://github.com/ktb83/linux

Return to “Linux Kernel”