LizardLad_1
Posts: 129
Joined: Sat Jan 13, 2018 12:29 am

LdB's mailbox_tag_message funtion usage

Sat Apr 13, 2019 11:33 pm

Hello it's been a while since I was last on here and I'm starting to get back into this after taking a break. I've gone back to my codebase and I've found that there are mixed forms of mailbox calls and I would like to try and standardise them within my code. I really like that LdB's function reduces the amount of code required to send a mailbox request so would someone please explain how to use the information provided on https://github.com/raspberrypi/document ... sARM-VC.md so that I can use it in this function defined here https://github.com/LdB-ECM/Raspberry-Pi ... artStart.c on line 571?

LdB
Posts: 1102
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's mailbox_tag_message funtion usage

Sun Apr 14, 2019 1:42 am

Most of that code at 571 does not actually deal with the specification that is still up to the data being entered in the variadic being correct. If you enter wrong data it would still fail.

As per a good suggestion from eco747 I have also amended the buffer line for size safety
The original code just assumed you did not enter massive tags taking up more than 32 entry values

Code: Select all

uint32_t __attribute__((aligned(16))) message[data_count+3];
This is the format the message must take from the specification
Buffer contents

u32: buffer size in bytes (including the header values, the end tag and padding)
u32: buffer request/response code
Request codes:
0x00000000: process request
All other values reserved
Response codes:
0x80000000: request successful
0x80000001: error parsing request buffer (partial response)
All other values reserved
u8...: sequence of concatenated tags
u32: 0x0 (end tag)
u8...: padding
The function does this
(1) Ensures the buffer for the transfer is 16 bit aligned
(2) Sets the header size is correct .... entry 0 in table above
(3) Zeros the request/response code ... entry 1 in table above as required to request
(4) Packs all the variadic data in order
(5) Places the "end tag" after the sequence data in table above

The data in the variadic is just a list of tag data one after another

So if you take a tag lets do the first "Get board model" the data you need would be
Tag Id: 0x00010001
Request length : 0x0
Response length: 0x4
response buffer: 0x0

So that is the 4 x uint32_t you need for that tag, which you would enter in the variadic
What you put in the response buffer doesn't matter the function takes no request data it is just where the response goes.
So to send that message and get the response back

Code: Select all

uint32_t buf[4];
mailbox_tag_message(&buf[0], 4, 0x00010001, 0x0, 0x4, 0x0);
There is no fixed size to the tags they go from 4 to 8 uint32_t, from what I remember.
As the tag lengths vary it makes simplifying the building of the complete structure more challenging.

You can tell all the tags worked in your call just by looking at what the VC4 put in entry 1, that is done inside the code
in returning success/failure.
0x80000000: request successful
0x80000001: error parsing request buffer (partial response)
Each tag response length entry is also overwritten with the same success or failure flag so if it fails you can actually
identify which tag failed. On the "Get board model" code above buf[2] should come back with that flag, your result is in buf[3]

There is not much more to it than that.

LizardLad_1
Posts: 129
Joined: Sat Jan 13, 2018 12:29 am

Re: LdB's mailbox_tag_message funtion usage

Wed Apr 17, 2019 12:26 am

Thanks that was quite helpful however I'm still stuck on more complex ones like fetching the EDID, fetching a framebuffer, and get clocks with tag id 0x00010007.

EDIT 1: What is the call get command line used for?

LdB
Posts: 1102
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's mailbox_tag_message funtion usage

Wed Apr 17, 2019 1:05 am

What is hard about 0x00010007 lets do 8 clocks you choose the clock data size you want and provide the buffer.

tag: 0x00010007
request length : 0x0
response length: 0x20 (Some buffer size you are prepared to take I have chosen 32 bytes which will be 8 clocks)
response buffer 0 : 0x0
response buffer 1 : 0x0
response buffer 2 : 0x0
response buffer 3 : 0x0
response buffer 4 : 0x0
response buffer 5 : 0x0
response buffer 6 : 0x0
response buffer 7 : 0x0
<Next tag will start here ... or a 0x00 end tag >

What is hard about that .. you choose a response length you create a buffer of that size.

EDID
tag: 0x00030020
Request length: 0x4
Repsonse length: 136 (34 uint32_t)
response buffer 0 : 0x1 some blockID you want (see request length) and will be response 0
response buffer 1 : 0x0
response buffer 2 : 0x0
.... blah blah until
response buffer 33 : 0x0
<Next tag will start here ... or a 0x00 end tag >
LizardLad_1 wrote:
Wed Apr 17, 2019 12:26 am
EDIT 1: What is the call get command line used for?
AFAIK it gets the config command line the Pi was kicked with ... AKA all that junk in config.txt if you booted as such

https://www.raspberrypi.org/documentati ... onfig-txt/
make a config.txt .. read it and find out :-)

leiradel
Posts: 31
Joined: Wed Feb 13, 2019 10:38 pm

Re: LdB's mailbox_tag_message funtion usage

Wed Apr 17, 2019 7:28 pm

LizardLad_1 wrote:
Wed Apr 17, 2019 12:26 am
Thanks that was quite helpful however I'm still stuck on more complex ones like fetching the EDID, fetching a framebuffer, and get clocks with tag id 0x00010007.

I use a more structured format for the messages, it's easier to see what's going on.

Here's my function that sends messages, and here you can see how I define and fill the messages. It uses C99, but it's easy enough to adapt.

Return to “Bare metal, Assembly language”