<html><body><div><br></div><div>On Jun 23, 2015, at 07:15 AM, Gedare Bloom <gedare@rtems.org> wrote:<br> <br></div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span class="body-text-content"> <span class="body-text-content">On Tue, Jun 23, 2015 at 7:43 AM, QIAO YANG <<a onclick="return false;" href="mailto:yangqiao0505@me.com" data-mce-href="mailto:yangqiao0505@me.com">yangqiao0505@me.com</a>> wrote:<br> </span> </span><blockquote class="quoted-plain-text" type="cite">Hi,</blockquote><blockquote class="quoted-plain-text" type="cite"><br></blockquote><blockquote class="quoted-plain-text" type="cite">As suggested by gedare, I think using zero length array to represent the</blockquote><blockquote class="quoted-plain-text" type="cite">mailbox buffer and tag data is a good way, much readable, clearer to</blockquote><blockquote class="quoted-plain-text" type="cite">abstract the structure of mailbox buffer, tag.</blockquote><blockquote class="quoted-plain-text" type="cite">I've done an attemp, here is the scratch:</blockquote><blockquote class="quoted-plain-text" type="cite"><a href="https://github.com/yangqiao/rtems/commit/3ed7e9bde493bdc8e644fcefa285d99255201ada" data-mce-href="https://github.com/yangqiao/rtems/commit/3ed7e9bde493bdc8e644fcefa285d99255201ada">https://github.com/yangqiao/rtems/commit/3ed7e9bde493bdc8e644fcefa285d99255201ada</a></blockquote><blockquote class="quoted-plain-text" type="cite"><br></blockquote><blockquote class="quoted-plain-text" type="cite">The construction of a buffer is then decomposed by the following procedure:</blockquote><blockquote class="quoted-plain-text" type="cite">1. Calculate the total length of buffer</blockquote><blockquote class="quoted-plain-text" type="cite">2. Allocate and inite the buffer</blockquote><blockquote class="quoted-plain-text" type="cite">3. Pack the request data into buffer</blockquote><blockquote class="quoted-plain-text" type="cite">4. send the buffer by mailbox, then read the responce</blockquote><blockquote class="quoted-plain-text" type="cite">5. Unpack the responce data into variables</blockquote><blockquote class="quoted-plain-text" type="cite"><br></blockquote><blockquote class="quoted-plain-text" type="cite">I've tested it in userspace it works well but in kernel space I cannot</blockquote><blockquote class="quoted-plain-text" type="cite">allocate the memory by malloc. Is there any alternative way to let us use</blockquote><blockquote class="quoted-plain-text" type="cite">zero length array in the kernel driver?</blockquote><blockquote class="quoted-plain-text" type="cite"><br></blockquote><span class="body-text-content"> <span class="body-text-content">It depends. BSP code can use malloc, but care should be taken about<br>where you use it. An alternative would be to use a free list.</span> </span></div></div></blockquote><span> </span></div><div>I've retried to allocate zero-length-array statically and I've found some problems:</div><div>1. As described in GCC manual, the size of struct that contains an zero length array at the end, is determined by the size of the initializer's given array. But what I've found is that the the initializer don't initialize the zero length array. it has to be set afterward. I doubt that the problem comes from the cross compiler. Even if I don't give initializer for the array, I can get access to the elements. It's dangerous and it doesn't work as described in manual.</div><div><br></div><div>2. I'm afraid that a struct A that contains a zero length array of struct B, where struct B has a zero-length array, is not acceptable. As the second struct B2 doesn't know the length of B1, so the position of B2 would be shifted and override part of the structure B1.</div><div><br></div><div>So I propose to:</div><div>1. Don't queue the tags, we handle them one by one. one buffer , one tag.</div><div>2. Use the zero length array to define the structure of tag.</div><div>3. single function for each tag operation.</div><div>4. lock to ensure that only one function is in process to avoid mailbox conflict.</div><div><br></div><div><a href="https://github.com/yangqiao/rtems/commit/971d3ccdab04171494a3b73684f4f6f243e230b9" data-mce-href="https://github.com/yangqiao/rtems/commit/971d3ccdab04171494a3b73684f4f6f243e230b9">https://github.com/yangqiao/rtems/commit/971d3ccdab04171494a3b73684f4f6f243e230b9</a></div><div>I've only implement the function to get display size here. If it's ok I'll add some others.</div><div><br><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span class="body-text-content"> <span class="body-text-content"> <br> <br> </span> </span><blockquote class="quoted-plain-text" type="cite"><br></blockquote><blockquote class="quoted-plain-text" type="cite">Secondly, since part of functions in outch is considered sharable between</blockquote><blockquote class="quoted-plain-text" type="cite">bsps. If my implementation is acceptable, I'll push the refactor code for</blockquote><blockquote class="quoted-plain-text" type="cite">review. Here is my implementation</blockquote><blockquote class="quoted-plain-text" type="cite"><a href="https://github.com/yangqiao/rtems/commit/858a9b091025acc4bfe912f41d70c9a73b99d773" data-mce-href="https://github.com/yangqiao/rtems/commit/858a9b091025acc4bfe912f41d70c9a73b99d773">https://github.com/yangqiao/rtems/commit/858a9b091025acc4bfe912f41d70c9a73b99d773</a></blockquote><blockquote class="quoted-plain-text" type="cite"><br></blockquote><span class="body-text-content"> <span class="body-text-content">You still need to attribute the original source of that file.<br> <br> </span> </span><blockquote class="quoted-plain-text" type="cite">Thanks in advance.</blockquote></div></div></blockquote></div></body></html>