From nobody Wed Nov 27 04:55:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701650094; cv=none; d=zohomail.com; s=zohoarc; b=V+XP/VMQ9Cr0B0B3bdrrH1CVUh2rsgXb2HZSXAuC6vr5MPukOS3ddpzekzCAAXJyXANCJrRoARppnC975dEHWTE3RYMb2tvmKGzy78xbddts1VzsXZ41u0MS/1RXr6i1m8pMThV+3rVj9Gr/Vy+8ng/9So79T1clqV2Da1WXMsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701650094; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3uN6I/0hgCFTTQOiKlRUms5E1PdG9Gf9E46rNDtv+HU=; b=EzdgXX5uwTW+qDdHdhTSumOJFJTvVnHdHGfNDrLZWlaQlGNzf3nKPj51/oQaz2FbPfqeDq1m/Vi+VPQ4m/hgNKyEMH3TIx4zn6HKLlKeyWR9kcSz+csET3wc4ZewhNVDelql07bujXP8013/82gVsVcUrcDohvm6w6PzCVJ+k9Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701650094356652.340522389131; Sun, 3 Dec 2023 16:34:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9woO-0006g4-DE; Sun, 03 Dec 2023 19:27:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9wnn-0004mN-N8; Sun, 03 Dec 2023 19:27:11 -0500 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9wnm-0000Hz-00; Sun, 03 Dec 2023 19:27:11 -0500 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-59b5484fbe6so44198147b3.1; Sun, 03 Dec 2023 16:27:09 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id l63-20020a0de242000000b005d3e6ce07e7sm2443187ywe.6.2023.12.03.16.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 16:27:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701649628; x=1702254428; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3uN6I/0hgCFTTQOiKlRUms5E1PdG9Gf9E46rNDtv+HU=; b=iHIoJI/vWjWXZl6xrmg8Zkx88FdX813ngKtNX/4IQ35kdoz6V3sQl7nKp1d68sw4/5 coOZ0R6dlXsyme23FT+OryqD1sXG29154us8RLPFBlpulAU1Z9tMJcKsI9bJXGuesUZI x2pgHDnXdgkXpyybTYm3ULtBUPfsuMuEiOK+ekL8wmyD4SJ0zzf6ONyEjID7+Vacf4B2 iQ6qrbFa29qqFYiEGq1o/WTj4Pg/xKAn1pZNEC6wIAALYeiAVjeyXGH/iaXxdbB1oysb 4DF92czCZYjLM7uMhNvjQS4Tr9ayZlA2OzjgflijBES0qwLJrYENHH3GAC2fPJs1Nzhe IRqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701649628; x=1702254428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3uN6I/0hgCFTTQOiKlRUms5E1PdG9Gf9E46rNDtv+HU=; b=g5C9VGrOGsdkgSYJmyMf2J8/hunNWBjTqbIlQaVM8ENmTQJ9F+EOAk/0UFBM77U1y8 FyZzwmayocEpcjCm7ME13v9bq+zr0XPYed1CzEUP+Csz8TW8K6LKU9d9k9simdGKSQlP nhjhkqzQTvhzLt0EeKGGvcn5AhRar+y6O3oz+6zg6sV7f6gCWoiWQp0ZAr6SSIU89svH vAq0zcI6fBMRUc6VYXuiu3xO0UmpWBMzNvGkXCwa47dRkmM5gnj0PuhgQcBFbGHqysDw 3Za5q5/0ssQ6e0OnMGriVlgWzjVJL0qMvcL4YKDnjGERaXB294/8BcSHnpTu+DgramhZ mKdQ== X-Gm-Message-State: AOJu0YyoWXZzVB6FD8Tf9GSDMDgouDwfHL1TjJH/U1RB5xCtSqNacS5y pWPHXO/91Ry/l+lrwAn3lHwEH/GB6+hQJA== X-Google-Smtp-Source: AGHT+IFZGNraf5FqdXtE5nEBNQgbxZCAGdpBeLzzs3VClG++D4MUItyxfXApsDl4I7Xl5NlwRNbExw== X-Received: by 2002:a81:8485:0:b0:5d7:1940:b381 with SMTP id u127-20020a818485000000b005d71940b381mr2853019ywf.77.1701649628354; Sun, 03 Dec 2023 16:27:08 -0800 (PST) From: Sergey Kambalin X-Google-Original-From: Sergey Kambalin To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, Sergey Kambalin Subject: [PATCH v3 35/45] Add mailbox test stub Date: Sun, 3 Dec 2023 18:26:09 -0600 Message-Id: <20231204002619.1367044-36-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204002619.1367044-1-sergey.kambalin@auriga.com> References: <20231204002619.1367044-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1130; envelope-from=serg.oker@gmail.com; helo=mail-yw1-x1130.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1701650095783100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sergey Kambalin --- include/hw/arm/bcm2838_peripherals.h | 2 + tests/qtest/bcm2838-mailbox.c | 71 ++++++++++++++++++++++++++++ tests/qtest/bcm2838-mailbox.h | 46 ++++++++++++++++++ tests/qtest/meson.build | 1 + 4 files changed, 120 insertions(+) create mode 100644 tests/qtest/bcm2838-mailbox.c create mode 100644 tests/qtest/bcm2838-mailbox.h diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_= peripherals.h index cdeb892f04..2b97e55048 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -56,6 +56,8 @@ #define BCM2838_MPHI_OFFSET 0xb200 #define BCM2838_MPHI_SIZE 0x200 =20 +#define GENET_OFFSET 0x1580000 + #define TYPE_BCM2838_PERIPHERALS "bcm2838-peripherals" OBJECT_DECLARE_TYPE(BCM2838PeripheralState, BCM2838PeripheralClass, BCM2838_PERIPHERALS) diff --git a/tests/qtest/bcm2838-mailbox.c b/tests/qtest/bcm2838-mailbox.c new file mode 100644 index 0000000000..2edc24e15e --- /dev/null +++ b/tests/qtest/bcm2838-mailbox.c @@ -0,0 +1,71 @@ +/* + * Helper functions to work with BCM2838 mailbox via qtest interface. + * + * Copyright (c) 2023 Auriga LLC + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/registerfields.h" +#include "libqtest-single.h" +#include "bcm2838-mailbox.h" + + +static uint32_t qtest_mbox0_read_reg32(QTestState *s, uint32_t offset) +{ + return qtest_readl(s, MBOX0_BASE + offset); +} + +static void qtest_mbox1_write_reg32(QTestState *s, uint32_t offset, uint32= _t value) +{ + return qtest_writel(s, MBOX1_BASE + offset, value); +} + +static void qtest_mbox1_write(QTestState *s, uint8_t channel, uint32_t dat= a) +{ + uint32_t reg; + + reg =3D FIELD_DP32(reg, MBOX_WRITE_REG, CHANNEL, channel); + reg =3D FIELD_DP32(reg, MBOX_WRITE_REG, DATA, data); + qtest_mbox1_write_reg32(s, MBOX_REG_WRITE, reg); +} + +int qtest_mbox0_has_data(QTestState *s) { + return !(qtest_mbox0_read_reg32(s, MBOX_REG_STATUS) & MBOX_READ_EMPTY); +} + +int mbox0_has_data(void) { + return qtest_mbox0_has_data(global_qtest); +} + +void qtest_mbox0_read_message(QTestState *s, + uint8_t channel, + void *msgbuf, + size_t msgbuf_size) +{ + uint32_t reg; + uint32_t msgaddr; + + g_assert(qtest_mbox0_has_data(s)); + reg =3D qtest_mbox0_read_reg32(s, MBOX_REG_READ); + g_assert_cmphex(FIELD_EX32(reg, MBOX_WRITE_REG, CHANNEL), =3D=3D, chan= nel); + msgaddr =3D FIELD_EX32(reg, MBOX_WRITE_REG, DATA) << 4; + qtest_memread(s, msgaddr, msgbuf, msgbuf_size); +} + +void mbox0_read_message(uint8_t channel, void *msgbuf, size_t msgbuf_size)= { + qtest_mbox0_read_message(global_qtest, channel, msgbuf, msgbuf_size); +} + +void qtest_mbox1_write_message(QTestState *s, uint8_t channel, uint32_t ms= g_addr) +{ + qtest_mbox1_write(s, channel, msg_addr >> 4); +} + + +void mbox1_write_message(uint8_t channel, uint32_t msg_addr) +{ + qtest_mbox1_write_message(global_qtest, channel, msg_addr); +} diff --git a/tests/qtest/bcm2838-mailbox.h b/tests/qtest/bcm2838-mailbox.h new file mode 100644 index 0000000000..1d02ca9c2c --- /dev/null +++ b/tests/qtest/bcm2838-mailbox.h @@ -0,0 +1,46 @@ +/* + * Declarations for BCM2838 mailbox test. + * + * Copyright (c) 2023 Auriga LLC + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + + +REG32(MBOX_WRITE_REG, 0) +FIELD(MBOX_WRITE_REG, CHANNEL, 0, 4) +FIELD(MBOX_WRITE_REG, DATA, 4, 28) + +REG32(MBOX_SIZE_STAT, 0) +FIELD(MBOX_WRITE_REG, SIZE, 0, 30) +FIELD(MBOX_WRITE_REG, SUCCESS, 30, 1) + +typedef struct { + uint32_t size; + uint32_t req_resp_code; +} MboxBufHeader; + +#define DECLARE_TAG_TYPE(TypeName, RequestValueType, ResponseValueType) \ +typedef struct { \ + uint32_t id; \ + uint32_t value_buffer_size; \ + union { \ + struct { \ + uint32_t zero; \ + RequestValueType value; \ + } request; \ + struct { \ + uint32_t size_stat; \ + ResponseValueType value; \ + } response; \ + }; \ +} TypeName + + +int mbox0_has_data(void); +void mbox0_read_message(uint8_t channel, void *msgbuf, size_t msgbuf_size); +void mbox1_write_message(uint8_t channel, uint32_t msg_addr); +int qtest_mbox0_has_data(QTestState *s); +void qtest_mbox0_read_message(QTestState *s, uint8_t channel, void *msgbuf= , size_t msgbuf_size); +void qtest_mbox1_write_message(QTestState *s, uint8_t channel, uint32_t ms= g_addr); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 47dabf91d0..92eba5ac99 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -321,6 +321,7 @@ qtests =3D { 'virtio-net-failover': files('migration-helpers.c'), 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), 'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'), + 'bcm2838-mbox-property-test' : files('bcm2838-mailbox.c'), } =20 if vnc.found() --=20 2.34.1