-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Add the Raspberry Pi firmware driver #1026
Conversation
This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Signed-off-by: Eric Anholt <eric at anholt.net> [rebased on 4.0] Signed-off-by: Noralf Trønnes <[email protected]>
This is done in 4.1 as part of a commit. Signed-off-by: Noralf Trønnes <[email protected]>
Make the firmware driver work with bcm2708-vcio so we can start to use the new API. Signed-off-by: Noralf Trønnes <[email protected]>
Signed-off-by: Noralf Trønnes <[email protected]>
Signed-off-by: Noralf Trønnes <[email protected]>
I have looked closer at the cpufreq driver and it isn't as complicated as I first thought, so I can try and get it upstream. |
Setting clocks will always have to go through the gpu (there are a lot of complicated dependencies between common plls and divisors that the gpu is master so it wouldn't be safe for the arm to mess with them without interaction with gpu), so cpufreq will have to use the mailbox. The temperature sensor may be accessible from arm, but again there may be locking issues (the gpu also accesses it). |
It will take a few weeks to get the drivers accepted into mainline (Stephen Warren going on vacation) and I understand we will switch to 4.0 soon, so maybe we should defer this PR to rpi-4.1.y? What do you think? |
Sure. We do have an early 4.1 port in this repo. Currently not hugely tested - please give it a try. |
Eric Anholt has made a clock driver that inlcudes the arm clock: [PATCH v3 1/7] dt/bindings: Add binding for the Raspberry Pi clock provider
Most of the work I have done is transitional and will probably be gone whithin a year when we're using ARCH_BCM2835 and more mainline drivers (I'm optimistic), but I'm honoured to see that you have added me in the Main bcm2708/bcm2709 linux port commit message. |
The patches are certainly appreciated. It now looks like moving to ARCH_BCM2835 is not too far away. We would be a lot further away without your help. |
BTW, I'm hoping to bump rpi-update kernel to 4.0 soon (maybe this weekend), with apt-get and raspbian images to follow. So 3.18 updates will stop. 4.1 will be the new experimental tree, so any patches moving us towards upstream can happen there. I'll leave 4.0 tree unsquashed, so the history is available, and as it will be the new stable tree, I will merge upstream updates rather than rebase them. 4.1 may be rebased. |
I have updated the status page: https://github.com/raspberrypi/linux/wiki/Upstreaming |
@popcornmix I'm trying to understand the mailbox interface and in particular reading. This is my understanding about the returned register value when reading, based on the wiki:
Actual value is:
What kind of error is it if the returned value is wrong? bcm2708-vcio: What purpose does the reading serve here? Wait for completion? The returned is value is not checked. extern int bcm_mailbox_property(void *data, int size)
{
...
wmb();
s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
if (s == 0)
s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
if (s == 0) {
/* copy the response */
rmb(); bcm2708_fb checks for zero: static int bcm2708_fb_set_par(struct fb_info *info)
{
...
/* ensure last write to fbinfo is visible to GPU */
wmb();
/* inform vc about new framebuffer */
bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
/* TODO: replace fb driver with vchiq version */
/* wait for response */
bcm_mailbox_read(MBOX_CHAN_FB, &val);
/* ensure GPU writes are visible to us */
rmb();
if (val == 0) {
... vchiq has no reading int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
{
...
/* Send the base address of the slots to VideoCore */
dsb(); /* Ensure all writes have completed */
err = bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)slot_phys);
if (err) {
dev_err(dev, "mailbox write failed\n");
return err;
} bcm2708-power checks the returned value: int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
{
...
/* Send a request to VideoCore */
bcm_mailbox_write(MBOX_CHAN_POWER, global_request << 4);
/* Wait for a response during power-up */
if (global_request & ~g_state.global_request) {
rc = bcm_mailbox_read(MBOX_CHAN_POWER, &actual);
actual >>= 4;
...
if (rc == 0) {
if (actual != global_request) {
printk(KERN_ERR |
Is it as simple as this: The written value should match the read value, unless MBOX_CHAN_FB which should be zero? What happens if I send a bogus address to the mailbox? Or are all addresses valid? |
There isn't a general protocol for what the mailbox return value is. Each channel returns something useful. Looking at firmware code:
To be honest, the channels other than PROPERTY are really legacy. The PROPERTY interface can handle the POWER and FB commands, and it wouldn't be hard to add the VCHIQ message to the PROPERTY interface. |
Would it be possible to add MBOX_CHAN_FB to the property interface as well? I now have vchiq and bcm2708_fb working through the firmware driver: https://gist.github.com/notro/d747deac1e916764a1e6 Next to do is the power driver and then I will see if I can switch to bcm2835-mailbox. I'm beginning to suspect that this is possible. |
The methods are slightly different, but I belive all that is possible through the FB interface is possible through property interface. There are a lot of framebuffer set/test/get calls in property mailbox interface. |
I have the bcm2708_fb driver working with property tags: https://gist.github.com/notro/6cdadc27fe39aed0b45e fbinfo.base |= 0x40000000; Can you check the firmware to see if the two methods/channels return the same address? Do you know how I can test setcolreg and the ioctl? I have also added a function to the firmware driver that turns on USB power. |
Chuckie Egg is my test program for palletised modes: (just building a firmware with VCHIQ support on property channel) |
|
Can you try: https://dl.dropboxusercontent.com/u/3669512/temp/firmware_vchiqmbox.zip VCHIQ Init |
I think there is a bug on the firmware that makes:
necessary. Just building an updated version that should make this unnecessary. |
Updated last firmware to include fix for fbinfo.base: |
The framebuffer address is correct now, but I can't get vchiq to work with the property channel. vchiq_platform_init(): Send address: printk("%s: slot_phys=%pad\n", __func__, &slot_phys);
channelbase = slot_phys;
printk("%s: channelbase=0x%x\n", __func__, channelbase);
err = rpi_firmware_property(fw, RPI_FIRMWARE_VCHIQ_INIT,
&channelbase, sizeof(channelbase));
printk("%s: channelbase=0x%x\n", __func__, channelbase); vcgencmd hangs:
|
Do you have a complete patch?
but fw is NULL. |
This is the firmware driver: https://gist.github.com/notro/dfcef441d6b527423bbd Applied on rpi-4.1.y |
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module kernel: config: Enable 8250 serial port See: raspberrypi/linux#1008 kernel: config: Enable POWER_RESET_GPIO See: raspberrypi/linux#1031 firmware: arm_display: Fix fb_base alias returned from mailbox property interface See: raspberrypi/linux#1026 firmware: mem_unlock - prevent decrementing lock count below 0 firmware: camera: Support multi-channel raw image capture firmware: camera: write_raw copies input frame if HDR is enabled firmware: camera: Write correct camera mode from write_raw_md_stage firmware: AGC tuner: Correction to setting default digital gain to x1.0
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module kernel: config: Enable 8250 serial port See: raspberrypi/linux#1008 kernel: config: Enable POWER_RESET_GPIO See: raspberrypi/linux#1031 firmware: arm_display: Fix fb_base alias returned from mailbox property interface See: raspberrypi/linux#1026 firmware: mem_unlock - prevent decrementing lock count below 0 firmware: camera: Support multi-channel raw image capture firmware: camera: write_raw copies input frame if HDR is enabled firmware: camera: Write correct camera mode from write_raw_md_stage firmware: AGC tuner: Correction to setting default digital gain to x1.0
VCHIQ is working now, thanks. I have been able to use bcm2835-mailbox, the firmware driver and then put the legacy mailbox API (bcm_mailbox_*) on top of that. The legacy API can be removed (except for /dev/vcio) when all drivers have been converted. What do you think about this approach? |
Sounds okay to me. I assume hello_fft (and similar mailbox apps) still works? |
At first I moved the legacy API to the firmware driver, but then I remembered the /dev/vcio stuff so I just kept it in the bcm2708-vcio module, since it is 200+ lines. The mailbox driver will land in 4.2, but the firmware driver is yet to have entered any tree I can find. How do you feel about me making a PR before it is verified entering a for-mainline tree? |
I'm okay with that on rpi-4.1.y. This tree is for testing future changes. It it changes before it reaches mainline then we'll have to keep track of that. |
Why does it take so long (0.5s) to turn on USB power?
It's the same with the bcm2708-power driver:
The documentation indicates that bit 1 should make a difference, but setting it doesn't change how long it takes.
Half a second is a big part of the kernel boot time before userspace takes over. |
Good question. I stepped through the firmware code and sure enough it takes 500ms.
That will be in next firmware update. |
Does this mean that the documentation is wrong about the wait bit? |
The wait bit is only a hint. We do the power switch from the mailbox thread. |
While testing my PR I've discovered that hello_fft.bin does not work on Pi2 without Device Tree.
I have some instrumentation in my new code, and I can see that only 3 of the 6 messages are sent:
Don't know if this matters though. |
kernel: bcm2708-spi: Don't use static pin configuration with DT kernel: bcm2708-i2s: Don't use static pin configuration with DT kernel: gpio-poweroff: Allow it to work on Raspberry Pi See: raspberrypi/linux#1031 kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost kernel: BCM270X_DT: Add overlay to enable uart1 See: raspberrypi/linux#1008 kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING See: Hexxeh/rpi-firmware#85 firmware: arm_loader: Support initialising vchiq through mailbox property interface See: raspberrypi/linux#1026 firmware: drivers/usb: Reduce busy-wait to sensible timeout See: raspberrypi/linux#1026 firmware: video_encode: Initialise headers for video_bitrate See: #163 firmware: arm_loader: Use the new core_freq DT parameter if present firmware: arm_loader: Set the uart1_clkrate DT property from core_freq firmware: arm_cursor: Better handling of a second app requesting a cursor firmware: arm: Tidy up setting of arm_control and arm_bash
kernel: bcm2708-spi: Don't use static pin configuration with DT kernel: bcm2708-i2s: Don't use static pin configuration with DT kernel: gpio-poweroff: Allow it to work on Raspberry Pi See: raspberrypi/linux#1031 kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost kernel: BCM270X_DT: Add overlay to enable uart1 See: raspberrypi/linux#1008 kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING See: #85 firmware: arm_loader: Support initialising vchiq through mailbox property interface See: raspberrypi/linux#1026 firmware: drivers/usb: Reduce busy-wait to sensible timeout See: raspberrypi/linux#1026 firmware: video_encode: Initialise headers for video_bitrate See: raspberrypi/firmware#163 firmware: arm_loader: Use the new core_freq DT parameter if present firmware: arm_loader: Set the uart1_clkrate DT property from core_freq firmware: arm_cursor: Better handling of a second app requesting a cursor firmware: arm: Tidy up setting of arm_control and arm_bash
Faster USB power on and VCHIQ init through mailbox should be in latest rpi-update firmware. |
The binary download links are dead. This one gives a blank screen and I can't quit:
I also tried this, but it also gives me a blank screen. Can quit with 'q'.
Do you have a binary or how do you build it? |
The blank screen is caused by an SDL bug (it assumes framebuffer base address won't change when changing framebuffer resolution/depth). Install the deb package from here: I used this version (http://marklomas.net/ch-egg/native/native.htm). The build script needed "-lm" and a tweak to the path of the bbcb library, but it otherwise works okay. Ping @XECDesign - can we get this into raspbian as a default? Lots of packages are broken due to this currently. |
Sure, will get that sorted tomorrow. |
@XECDesign thanks. |
@popcornmix Thanks, it's working now. However when I use the property channel I get wrong colours. |
I realised that I can get the palette as well (patch). This is what I get:
|
You are submitting 32bpp palette numbers as 16bpp. This should fix it: There was also a bug in reading the palette which I've got a fix for. |
Thanks, that's better. |
kernel: BCM270X_DT: I2S needs function Alt2 See: raspberrypi/linux#1046 kernel: vchiq_arm: Two cacheing fixes See: #443 kernel: BCM270X_DT: Overlay for the Fen Logic VGA666 board firmware: arm_loader: Increase stack and ensure icache flush is done before threads in execute multi firmware: arm_loader: Switch to vpu queues and more profile logging firmware: clocks: Allow arm to be overclocked to 1.6GHz firmware: gpioman: Don't force all pin pulls to their defaults firmware: arm_loader: Fix length on get palette mailbox call See: raspberrypi/linux#1026 firmware: vchiq: Better error handling firmware: vchiq: Make fragment size vary with cache line size See: #443
kernel: BCM270X_DT: I2S needs function Alt2 See: raspberrypi/linux#1046 kernel: vchiq_arm: Two cacheing fixes See: raspberrypi/firmware#443 kernel: BCM270X_DT: Overlay for the Fen Logic VGA666 board firmware: arm_loader: Increase stack and ensure icache flush is done before threads in execute multi firmware: arm_loader: Switch to vpu queues and more profile logging firmware: clocks: Allow arm to be overclocked to 1.6GHz firmware: gpioman: Don't force all pin pulls to their defaults firmware: arm_loader: Fix length on get palette mailbox call See: raspberrypi/linux#1026 firmware: vchiq: Better error handling firmware: vchiq: Make fragment size vary with cache line size See: raspberrypi/firmware#443
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module kernel: config: Enable 8250 serial port See: raspberrypi/linux#1008 kernel: config: Enable POWER_RESET_GPIO See: raspberrypi/linux#1031 firmware: arm_display: Fix fb_base alias returned from mailbox property interface See: raspberrypi/linux#1026 firmware: mem_unlock - prevent decrementing lock count below 0 firmware: camera: Support multi-channel raw image capture firmware: camera: write_raw copies input frame if HDR is enabled firmware: camera: Write correct camera mode from write_raw_md_stage firmware: AGC tuner: Correction to setting default digital gain to x1.0
kernel: bcm2708-spi: Don't use static pin configuration with DT kernel: bcm2708-i2s: Don't use static pin configuration with DT kernel: gpio-poweroff: Allow it to work on Raspberry Pi See: raspberrypi/linux#1031 kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost kernel: BCM270X_DT: Add overlay to enable uart1 See: raspberrypi/linux#1008 kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING See: Hexxeh/rpi-firmware#85 firmware: arm_loader: Support initialising vchiq through mailbox property interface See: raspberrypi/linux#1026 firmware: drivers/usb: Reduce busy-wait to sensible timeout See: raspberrypi/linux#1026 firmware: video_encode: Initialise headers for video_bitrate See: raspberrypi#163 firmware: arm_loader: Use the new core_freq DT parameter if present firmware: arm_loader: Set the uart1_clkrate DT property from core_freq firmware: arm_cursor: Better handling of a second app requesting a cursor firmware: arm: Tidy up setting of arm_control and arm_bash
kernel: BCM270X_DT: I2S needs function Alt2 See: raspberrypi/linux#1046 kernel: vchiq_arm: Two cacheing fixes See: raspberrypi#443 kernel: BCM270X_DT: Overlay for the Fen Logic VGA666 board firmware: arm_loader: Increase stack and ensure icache flush is done before threads in execute multi firmware: arm_loader: Switch to vpu queues and more profile logging firmware: clocks: Allow arm to be overclocked to 1.6GHz firmware: gpioman: Don't force all pin pulls to their defaults firmware: arm_loader: Fix length on get palette mailbox call See: raspberrypi/linux#1026 firmware: vchiq: Better error handling firmware: vchiq: Make fragment size vary with cache line size See: raspberrypi#443
Detail: s/BCMVideo - Apparently the long-standing behaviour of the mailbox property interface returning an ARM physical address for the framebuffer is a bug (raspberrypi/linux#1026 (comment)), and so recent firmwares have been changed to return a GPU address instead. We want an ARM address, so detect what type we're given and offset appropriately. Admin: Tested on Raspberry Pi 1 & 2, on old (February) and new (today) firmware Version 0.32. Tagged as 'BCMVideo-0_32'
Detail: s/BCMVideo - Apparently the long-standing behaviour of the mailbox property interface returning an ARM physical address for the framebuffer is a bug (raspberrypi/linux#1026 (comment)), and so recent firmwares have been changed to return a GPU address instead. We want an ARM address, so detect what type we're given and offset appropriately. Admin: Tested on Raspberry Pi 1 & 2, on old (February) and new (today) firmware Version 0.32. Tagged as 'BCMVideo-0_32'
Detail: s/BCMVideo - Apparently the long-standing behaviour of the mailbox property interface returning an ARM physical address for the framebuffer is a bug (raspberrypi/linux#1026 (comment)), and so recent firmwares have been changed to return a GPU address instead. We want an ARM address, so detect what type we're given and offset appropriately. Admin: Tested on Raspberry Pi 1 & 2, on old (February) and new (today) firmware Version 0.32. Tagged as 'BCMVideo-0_32'
The firmware driver will land in v4.2, but this PR backports it to 4.0 and makes it work with the legacy mailbox API (bcm2708-vcio). The driver provides a new API that replaces the bcm_mailbox_property() function. It does not support the other mailbox channels used by vchiq and bcm2708_fb.
These drivers use the mailbox property channel:
I have rewritten the driver and will send it upstream when the firmware driver lands in linux-next (probably after the 4.2 merge window).
This needs to be turned it into a device driver so deferred probing works, since the firmware driver is loaded later in the boot process. I haven't got the necessary knowledge to send it upstream and face technical questions.
This one is easy to fix, but I don't have any hardware to test with. I can make a PR, but someone else has to test it.
Tested on Pi1 and Pi2 with and without Device Tree + ARCH_BCM2835.