qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Sergey Kambalin <serg.oker@gmail.com>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	 Sergey Kambalin <sergey.kambalin@auriga.com>
Subject: Re: [PATCH v6 00/41] Raspberry Pi 4B machine
Date: Tue, 27 Feb 2024 15:22:29 +0000	[thread overview]
Message-ID: <CAFEAcA_oSeqGAPNpemhbyVkuMYtwbr-TG2QNQ7=DSZv0s0h7XA@mail.gmail.com> (raw)
In-Reply-To: <20240226000259.2752893-1-sergey.kambalin@auriga.com>

On Mon, 26 Feb 2024 at 00:04, Sergey Kambalin <serg.oker@gmail.com> wrote:
>
> Introducing Raspberry Pi 4B model.
> It contains new BCM2838 SoC, PCIE subsystem,
> RNG200, Thermal sensor and Genet network controller.
>
> It can work with recent linux kernels 6.x.x.
> Two avocado tests was added to check that.
>
> Unit tests has been made as read/write operations
> via mailbox properties.
>
> Genet integration test is under development.
>
> Every single commit
> 1) builds without errors
> 2) passes regression tests
> 3) passes style check*
> *the only exception is bcm2838-mbox-property-test.c file
> containing heavy macros usage which cause a lot of
> false-positives of checkpatch.pl.

Hi; I had to drop the qtest patches from what I'm going to
apply upstream, because it turns out that they don't pass
if the host system is big-endian. This is because you read
out memory from the guest directly into a host struct:
that only works if the host happens to be the same endianness
(little) as the guest.

One possible way to deal with this would be the following:

+/*
+ * Read and write fields that are in little-endian order. Based on
+ * the linux-user/qemu.h __put_user_e and __get_user_e macros.
+ */
+#define put_guest_field(x, hptr)                                            \
+    do {                                                                    \
+        (__builtin_choose_expr(sizeof(*(hptr)) == 1, stb_p,                 \
+        __builtin_choose_expr(sizeof(*(hptr)) == 2, stw_le_p,               \
+        __builtin_choose_expr(sizeof(*(hptr)) == 4, stl_le_p,               \
+        __builtin_choose_expr(sizeof(*(hptr)) == 8, stq_le_p, abort))))     \
+            ((hptr), (x)), (void)0);                                        \
+    } while (0)
+
+#define get_guest_field(x, hptr)                                            \
+    do {                                                                    \
+        ((x) = (typeof(*hptr))(                                             \
+        __builtin_choose_expr(sizeof(*(hptr)) == 1, ldub_p,                 \
+        __builtin_choose_expr(sizeof(*(hptr)) == 2, lduw_le_p,              \
+        __builtin_choose_expr(sizeof(*(hptr)) == 4, ldl_le_p,               \
+        __builtin_choose_expr(sizeof(*(hptr)) == 8, ldq_le_p, abort))))     \
+            (hptr)), (void)0);                                              \
+    } while (0)
+
 /*----------------------------------------------------------------------------*/
 #define DECLARE_TEST_CASE(testname, ...)
         \
     __attribute__((weak))
         \
@@ -59,38 +82,41 @@ FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1)
         } mailbox_buffer = { 0 };
         \

         \
         QTestState *qts = qtest_init("-machine raspi4b");
         \
+        uint32_t req_resp_code, tag_id, size_stat, size, success;
         \

         \
-        mailbox_buffer.header.size = sizeof(mailbox_buffer);
         \
-        mailbox_buffer.header.req_resp_code = MBOX_PROCESS_REQUEST;
         \
+        put_guest_field(sizeof(mailbox_buffer),
&mailbox_buffer.header.size);  \
+        put_guest_field(MBOX_PROCESS_REQUEST,
         \
+                        &mailbox_buffer.header.req_resp_code);
         \

         \
-        mailbox_buffer.tag.id = TEST_TAG(testname);
         \
-        mailbox_buffer.tag.value_buffer_size = MAX(
         \
+        put_guest_field(TEST_TAG(testname), &mailbox_buffer.tag.id);
         \
+        put_guest_field(MAX(
         \
             sizeof(mailbox_buffer.tag.request.value),
         \
-            sizeof(mailbox_buffer.tag.response.value));
         \
-        mailbox_buffer.tag.request.zero = 0;
         \
+            sizeof(mailbox_buffer.tag.response.value)),
         \
+                        &mailbox_buffer.tag.value_buffer_size);
         \
+        put_guest_field(0, &mailbox_buffer.tag.request.zero);
         \

         \
-        mailbox_buffer.end_tag = RPI_FWREQ_PROPERTY_END;
         \
+        put_guest_field(RPI_FWREQ_PROPERTY_END,
&mailbox_buffer.end_tag);      \

         \
         if (SETUP_FN_NAME(testname, __VA_ARGS__)) {
         \
             SETUP_FN_NAME(testname,
__VA_ARGS__)(&mailbox_buffer.tag);         \
         }
         \

         \
         qtest_memwrite(qts, MBOX_TEST_MESSAGE_ADDRESS,
         \
-                    &mailbox_buffer, sizeof(mailbox_buffer));
         \
+                       &mailbox_buffer, sizeof(mailbox_buffer));
         \
         qtest_mbox1_write_message(qts, MBOX_CHANNEL_ID_PROPERTY,
         \
-                            MBOX_TEST_MESSAGE_ADDRESS);
         \
+                                  MBOX_TEST_MESSAGE_ADDRESS);
         \

         \
         qtest_mbox0_read_message(qts, MBOX_CHANNEL_ID_PROPERTY,
         \
-                            &mailbox_buffer, sizeof(mailbox_buffer));
         \
+                                 &mailbox_buffer,
sizeof(mailbox_buffer));     \

         \
-        g_assert_cmphex(mailbox_buffer.header.req_resp_code, ==,
MBOX_SUCCESS);\
+        get_guest_field(req_resp_code,
&mailbox_buffer.header.req_resp_code);  \
+        g_assert_cmphex(req_resp_code, ==, MBOX_SUCCESS);
         \
+        get_guest_field(tag_id, &mailbox_buffer.tag.id);
         \
+        g_assert_cmphex(tag_id, ==, TEST_TAG(testname));
         \

         \
-        g_assert_cmphex(mailbox_buffer.tag.id, ==,
TEST_TAG(testname));        \
-
         \
-        uint32_t size =
FIELD_EX32(mailbox_buffer.tag.response.size_stat,      \
-                                   MBOX_SIZE_STAT, SIZE);
         \
-        uint32_t success =
FIELD_EX32(mailbox_buffer.tag.response.size_stat,   \
-                                      MBOX_SIZE_STAT, SUCCESS);
         \
+        get_guest_field(size_stat,
&mailbox_buffer.tag.response.size_stat);    \
+        size = FIELD_EX32(size_stat, MBOX_SIZE_STAT, SIZE);
         \
+        success = FIELD_EX32(size_stat, MBOX_SIZE_STAT, SUCCESS);
         \
         g_assert_cmpint(size, ==,
sizeof(mailbox_buffer.tag.response.value));  \
         g_assert_cmpint(success, ==, 1);
         \

         \
@@ -110,7 +136,9 @@ FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1)

 /*----------------------------------------------------------------------------*/
 DECLARE_TEST_CASE(GET_FIRMWARE_REVISION) {
-    g_assert_cmpint(tag->response.value.revision, ==, FIRMWARE_REVISION);
+    uint32_t rev;
+    get_guest_field(rev, &tag->response.value.revision);
+    g_assert_cmpint(rev, ==, FIRMWARE_REVISION);
 }

which I have tested works for the one test case that I updated here.
(The field comparison part could probably be made less clunky.)
Or you could do something else.

The test also failed to link on Macos:
https://gitlab.com/qemu-project/qemu/-/jobs/6267744541

Undefined symbols for architecture arm64:
"_FRAMEBUFFER_GET_ALPHA_MODE__setup", referenced from:
_FRAMEBUFFER_GET_ALPHA_MODE__test in bcm2838-mbox-property-test.c.o
"_FRAMEBUFFER_GET_DEPTH__setup", referenced from:
_FRAMEBUFFER_GET_DEPTH__test in bcm2838-mbox-property-test.c.o
(etc)

I'm not sure why that is, but I would be suspicious that your
use of the __attribute__((weak)) for the setup functions is not
portable.

thanks
-- PMM


  parent reply	other threads:[~2024-02-27 15:24 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26  0:02 [PATCH v6 00/41] Raspberry Pi 4B machine Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 01/41] Split out common part of BCM283X classes Sergey Kambalin
2024-02-27  8:45   ` Philippe Mathieu-Daudé
2024-02-26  0:02 ` [PATCH v6 02/41] Split out common part of peripherals Sergey Kambalin
2024-02-27  8:58   ` Philippe Mathieu-Daudé
2024-02-26  0:02 ` [PATCH v6 03/41] Split out raspi machine common part Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 04/41] Introduce BCM2838 SoC Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 05/41] Add GIC-400 to " Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 06/41] Add BCM2838 GPIO stub Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 07/41] Implement BCM2838 GPIO functionality Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 08/41] Connect SD controller to BCM2838 GPIO Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 09/41] Add GPIO and SD to BCM2838 periph Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 10/41] Introduce Raspberry PI 4 machine Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 11/41] Temporarily disable unimplemented rpi4b devices Sergey Kambalin
2024-02-26 13:35   ` Philippe Mathieu-Daudé
2024-02-26 13:39     ` Peter Maydell
2024-02-26 16:06       ` Philippe Mathieu-Daudé
2024-02-26 16:41         ` Peter Maydell
2024-02-27  4:54           ` Kambalin, Sergey
2024-02-26  0:02 ` [PATCH v6 12/41] Add memory region for BCM2837 RPiVid ASB Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 13/41] Add BCM2838 PCIE Root Complex Sergey Kambalin
2024-02-26 13:25   ` Philippe Mathieu-Daudé
2024-02-26  0:02 ` [PATCH v6 14/41] Add BCM2838 PCIE host Sergey Kambalin
2024-02-26 16:28   ` Philippe Mathieu-Daudé
2024-02-26  0:02 ` [PATCH v6 15/41] Enable BCM2838 PCIE Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 16/41] Add RPi4 RNG200 Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 17/41] Implement BCM2838 thermal sensor Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 18/41] Add clock_isp stub Sergey Kambalin
2024-02-26 16:06   ` Philippe Mathieu-Daudé
2024-02-26 16:19   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 19/41] Add GENET stub Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 20/41] Add GENET register structs. Part 1 Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 21/41] Add GENET register structs. Part 2 Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 22/41] Add GENET register structs. Part 3 Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 23/41] Add GENET register structs. Part 4 Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 24/41] Add GENET register access macros Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 25/41] Implement GENET register ops Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 26/41] Implement GENET MDIO Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 27/41] Implement GENET TX path Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 28/41] Implement GENET RX path Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 29/41] Enable BCM2838 GENET controller Sergey Kambalin
2024-02-26  0:02 ` [PATCH v6 30/41] Add Rpi4b boot tests Sergey Kambalin
2024-02-26 16:40   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 31/41] Add mailbox test stub Sergey Kambalin
2024-02-26 16:21   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 32/41] Add mailbox test constants Sergey Kambalin
2024-02-26 16:23   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 33/41] Add mailbox tests tags. Part 1 Sergey Kambalin
2024-02-26 16:23   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 34/41] Add mailbox tests tags. Part 2 Sergey Kambalin
2024-02-26 16:23   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 35/41] Add mailbox tests tags. Part 3 Sergey Kambalin
2024-02-26 16:24   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 36/41] Add mailbox property tests. Part 1 Sergey Kambalin
2024-02-26 16:24   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 37/41] Add mailbox property tests. Part 2 Sergey Kambalin
2024-02-26 16:24   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 38/41] Add mailbox property tests. Part 3 Sergey Kambalin
2024-02-26 16:24   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 39/41] Add missed BCM2835 properties Sergey Kambalin
2024-02-26 16:25   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 40/41] Append added properties to mailbox test Sergey Kambalin
2024-02-26 16:25   ` Peter Maydell
2024-02-26  0:02 ` [PATCH v6 41/41] Add RPi4B to raspi.rst Sergey Kambalin
2024-02-26 16:42   ` Peter Maydell
2024-02-26 16:43     ` Peter Maydell
2024-02-26 16:52       ` Philippe Mathieu-Daudé
2024-02-26 16:54         ` Peter Maydell
2024-02-26 18:09 ` [PATCH v6 00/41] Raspberry Pi 4B machine Peter Maydell
2024-02-27 11:26   ` Peter Maydell
2024-02-27 15:22 ` Peter Maydell [this message]
2024-02-27 17:25   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFEAcA_oSeqGAPNpemhbyVkuMYtwbr-TG2QNQ7=DSZv0s0h7XA@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=serg.oker@gmail.com \
    --cc=sergey.kambalin@auriga.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).