Is something using DMA channel 0?
Craig McGeachie
slapdau at yahoo.com.au
Fri Nov 8 16:09:01 EST 2013
On 11/08/2013 10:32 PM, Philip Ashmore wrote:
> What I really wanted was an API (/proc or /sys?) place to lookup what
> DMA channels videocore uses that neither user programs nor the kernel
> should use.
If you want this, then it's likely you will have to write it yourself.
See links to information about mailbox and properties at the end.
> I don't know about mailboxes - can you provide a link?
Yes. See below [3,4,5,6]. There's not much but I don't think there is
much that is publicly known. I think most of it was deduced by Simon
Arlott and Stephen Warren. I have absolutely no idea how they did it.
> Progress in any direction is still progress.
> When I don't know something I ask. Is there someone I/we/you can ask?
I think the Linux kernel forum [1] at raspberrypi.org would be your best
bet.
>> It's also occurred to me to ask, if 0 is problematic, why don't you
>> simply try using another channel? I think 4 or 5 ought to be good.
> Until a new boot loader comes along and breaks things.
>
> Co-ordinating resources isn't a new thing in software development - once
> again this needs to be escalated and a formally agreed system used,
> otherwise we're just pi**ing in the wind hoping we're facing the right way.
>
> There's no use pretending otherwise.
>
> Your advice may be 100% correct at this time and be 100% wrong next month.
>
> Sorry to be frank, but I'd rather be developing code that had some
> chance of being future proof.
>
> To do otherwise is wasted effort or job security, depending on your view
> point.
Oh, I heartily agree. That being the case I think your best course of
action is as follows. Accept that the videocore has authority over
which channels are for it and which channels the ARM core will use. It
doesn't take requests or advice. At best, it makes this decision once,
up front, and doesn't need to be constantly asked. For the channels
usable by ARM code, the kernel DMA controller driver is in charge. The
current implementation (arch/arm/mach-bcm2708/dma.c from [2]) doesn't
let you nominate which channel you will use, but lets you ask for a
channel that meets criteria that you supply. Maybe. If there are no
channels available that meet your criteria, it will still allocate one
in the hope that it's good enough, which most of the time it will be.
Specifically there is bcm_dma_chan_alloc and bcm_dma_chan_free.
bcm_dma_chan_alloc will return the IO memory base for the channel to
you, and the associated Linux IRQ number. You would have to write your
own kernel driver to expose these functions to kernel space. The
possible designs for this are endless, but wet-finger-in-the-air, I
would guess that mmap on a character device file would be most robust,
but /sysfs files would be simplest to implement as a quick-and-dirty.
After you have been allocated a channel, you are then probably safe
enough using it through /dev/mem rather than with the routines provided
by arch/arm/mach-bcm2708/dma.c.
If you want to know more about the mailbox, then see the links below.
Also see the current raspberrypi.org implementation
(arch/arm/mach-bcm2708/vcio.c at [2]). Note, you can only get the
ARM-usable channels. You can't request/tell the videocore that a
channel is just for you. The information is exactly the same as
provided by dma.dmachans. If you have access to this parameter, using
the mailbox provides no benefit. If you use bcm_dma_chan_alloc and
bcm_dma_chan_free, they already make use of this information.
Personally, I don't believe there is currently any "proper" way of
sharing DMA channels without at least some kernel code. That Richard
Hist could reliably just use channel 0, and you couldn't, still baffles
the s**t out of me.
[1] http://www.raspberrypi.org/phpBB3/viewforum.php?f=71
[2] https://github.com/raspberrypi/linux
[3] https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes
[4]
https://github.com/hackerspace/rpi-linux/blob/lr-raspberry-pi/drivers/mailbox/bcm2835-ipc.c
[5] https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
[6] http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/screen01.html
More information about the linux-rpi-kernel
mailing list