From patchwork Sun Dec 3 21:28:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ew7KUbkz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0WT3Vydz23n4 for ; Mon, 4 Dec 2023 08:37:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1e-0001Md-Rj; Sun, 03 Dec 2023 16:29:18 -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 1r9u1c-0001JF-Cx; Sun, 03 Dec 2023 16:29:16 -0500 Received: from mail-yb1-xb2c.google.com ([2607:f8b0:4864:20::b2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1Y-0005Mp-4b; Sun, 03 Dec 2023 16:29:16 -0500 Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-db3fa47c2f7so2142586276.0; Sun, 03 Dec 2023 13:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638950; x=1702243750; 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=DToKVpvlexd+YNhAs9MVA6EGWpl46MywNEXdi2wvJUE=; b=ew7KUbkzPr4t2ApPOquepFUXq/QOVTcbwAO5jOH/5a3foBmaSrDpaTuw2sqlImOkSO jy9UD5SgvFqFMAfzJmU9GEHu4DK9ku69VY7UgYyCE6BtQVkoOdRdxggIPEKMq/tLbgI1 gbDrP5x9gj1X7wS0+eOJUDwwzJeQUTlu+FxdXlQl/BbbWvpEuWbSqYhG7OjeHf7MaFCB ijsP6g/UW5FDh9mbph5nlzy6t7WmNaoQhi3khbJlaB21MjP+faDUTjUHtMxxMJ4eNkGU d51gccYDQ13HdJovxLYyI/CZAO99uDLJB9HrmkBXsoxuAwTSRJD58iTaS3QbEfF6H9zA OiaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638950; x=1702243750; 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=DToKVpvlexd+YNhAs9MVA6EGWpl46MywNEXdi2wvJUE=; b=bn7VzR6tYOmTiSqfrE+NBSDsdeXMUuv0Yi8XdSKYsK6i0ttDTeRml1bySByM1SCAen bmLbq+vlF5VAzTB0+PNiHnML/dsrO/2mGq5aIa05rRYj4Km7QKRzLzqVxG1/C9o77zqa GPJHXQqL6sYArvR33y255Lpx35DHk+k+a8JbACBp4iY1M2+Ymvt5XOVkS+V6/CuEuwRc 8nJrc1C59p8aVVvw04ToOylsnweIYFHTFHNgtA00sNdAI0hu/P5Z78tYpqp+Y3p/1G8y n4FD+1wwKFVzW+qobOyQdG8nipRU0ZAX8Vm8tgxhBQNHBTx3UhZimj4bbHr4AWxCgbs/ Dm5g== X-Gm-Message-State: AOJu0YzjNLrgcpIdqAQV6dg+F82iISdZy9TCxCKTm6I4Xm3lPBDwgxcf FSH/QqvXwb8RMi/eKFWHFqH/nT9ff7qIqQ== X-Google-Smtp-Source: AGHT+IEct+v3oCke6S5wvxFlQYDjJzgjZ2vbsu8yzRfsWHTZLcOhRpCzCTKme0yZ5b0U3a+BMuOdiw== X-Received: by 2002:a5b:4c1:0:b0:db7:dad0:60b8 with SMTP id u1-20020a5b04c1000000b00db7dad060b8mr1820995ybp.69.1701638950255; Sun, 03 Dec 2023 13:29:10 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:10 -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 01/45] Split out common part of BCM283X classes Date: Sun, 3 Dec 2023 15:28:21 -0600 Message-Id: <20231203212905.1364036-2-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-1-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2c; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2c.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Pre setup for BCM2838 introduction Signed-off-by: Sergey Kambalin --- hw/arm/bcm2836.c | 102 ++++++++++++++++++++++----------------- hw/arm/raspi.c | 2 +- include/hw/arm/bcm2836.h | 26 +++++++++- 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c index 166dc896c0..66a2b57b38 100644 --- a/hw/arm/bcm2836.c +++ b/hw/arm/bcm2836.c @@ -29,12 +29,12 @@ struct BCM283XClass { }; static Property bcm2836_enabled_cores_property = - DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0); + DEFINE_PROP_UINT32("enabled-cpus", BCM283XBaseState, enabled_cpus, 0); -static void bcm2836_init(Object *obj) +static void bcm283x_base_init(Object *obj) { - BCM283XState *s = BCM283X(obj); - BCM283XClass *bc = BCM283X_GET_CLASS(obj); + BCM283XBaseState *s = BCM283X_BASE(obj); + BCM283XBaseClass *bc = BCM283X_BASE_GET_CLASS(obj); int n; for (n = 0; n < bc->core_count; n++) { @@ -50,6 +50,11 @@ static void bcm2836_init(Object *obj) object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); } +} + +static void bcm283x_init(Object *obj) +{ + BCM283XState *s = BCM283X(obj); object_initialize_child(obj, "peripherals", &s->peripherals, TYPE_BCM2835_PERIPHERALS); @@ -61,10 +66,11 @@ static void bcm2836_init(Object *obj) "vcram-size"); } -static bool bcm283x_common_realize(DeviceState *dev, Error **errp) +bool bcm283x_common_realize(DeviceState *dev, Error **errp) { BCM283XState *s = BCM283X(dev); - BCM283XClass *bc = BCM283X_GET_CLASS(dev); + BCM283XBaseState *s_base = BCM283X_BASE(dev); + BCM283XBaseClass *bc = BCM283X_BASE_GET_CLASS(dev); Object *obj; /* common peripherals from bcm2835 */ @@ -77,96 +83,98 @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp) return false; } - object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals), - "sd-bus"); + object_property_add_alias(OBJECT(s_base), "sd-bus", + OBJECT(&s->peripherals), "sd-bus"); - sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, - bc->peri_base, 1); + sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), + 0, bc->peri_base, 1); return true; } static void bcm2835_realize(DeviceState *dev, Error **errp) { BCM283XState *s = BCM283X(dev); + BCM283XBaseState *s_base = BCM283X_BASE(dev); if (!bcm283x_common_realize(dev, errp)) { return; } - if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) { + if (!qdev_realize(DEVICE(&s_base->cpu[0].core), NULL, errp)) { return; } /* Connect irq/fiq outputs from the interrupt controller. */ sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, - qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ)); + qdev_get_gpio_in(DEVICE(&s_base->cpu[0].core), ARM_CPU_IRQ)); sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, - qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ)); + qdev_get_gpio_in(DEVICE(&s_base->cpu[0].core), ARM_CPU_FIQ)); } static void bcm2836_realize(DeviceState *dev, Error **errp) { - BCM283XState *s = BCM283X(dev); - BCM283XClass *bc = BCM283X_GET_CLASS(dev); int n; + BCM283XState *s = BCM283X(dev); + BCM283XBaseState *s_base = BCM283X_BASE(dev); + BCM283XBaseClass *bc = BCM283X_BASE_GET_CLASS(dev); if (!bcm283x_common_realize(dev, errp)) { return; } /* bcm2836 interrupt controller (and mailboxes, etc.) */ - if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { + if (!sysbus_realize(SYS_BUS_DEVICE(&s_base->control), errp)) { return; } - sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base); + sysbus_mmio_map(SYS_BUS_DEVICE(&s_base->control), 0, bc->ctrl_base); sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, - qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0)); + qdev_get_gpio_in_named(DEVICE(&s_base->control), "gpu-irq", 0)); sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, - qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-fiq", 0)); + qdev_get_gpio_in_named(DEVICE(&s_base->control), "gpu-fiq", 0)); for (n = 0; n < BCM283X_NCPUS; n++) { /* TODO: this should be converted to a property of ARM_CPU */ - s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n; + s_base->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n; /* set periphbase/CBAR value for CPU-local registers */ - if (!object_property_set_int(OBJECT(&s->cpu[n].core), "reset-cbar", + if (!object_property_set_int(OBJECT(&s_base->cpu[n].core), "reset-cbar", bc->peri_base, errp)) { return; } /* start powered off if not enabled */ - if (!object_property_set_bool(OBJECT(&s->cpu[n].core), + if (!object_property_set_bool(OBJECT(&s_base->cpu[n].core), "start-powered-off", - n >= s->enabled_cpus, + n >= s_base->enabled_cpus, errp)) { return; } - if (!qdev_realize(DEVICE(&s->cpu[n].core), NULL, errp)) { + if (!qdev_realize(DEVICE(&s_base->cpu[n].core), NULL, errp)) { return; } /* Connect irq/fiq outputs from the interrupt controller. */ - qdev_connect_gpio_out_named(DEVICE(&s->control), "irq", n, - qdev_get_gpio_in(DEVICE(&s->cpu[n].core), ARM_CPU_IRQ)); - qdev_connect_gpio_out_named(DEVICE(&s->control), "fiq", n, - qdev_get_gpio_in(DEVICE(&s->cpu[n].core), ARM_CPU_FIQ)); + qdev_connect_gpio_out_named(DEVICE(&s_base->control), "irq", n, + qdev_get_gpio_in(DEVICE(&s_base->cpu[n].core), ARM_CPU_IRQ)); + qdev_connect_gpio_out_named(DEVICE(&s_base->control), "fiq", n, + qdev_get_gpio_in(DEVICE(&s_base->cpu[n].core), ARM_CPU_FIQ)); /* Connect timers from the CPU to the interrupt controller */ - qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_PHYS, - qdev_get_gpio_in_named(DEVICE(&s->control), "cntpnsirq", n)); - qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_VIRT, - qdev_get_gpio_in_named(DEVICE(&s->control), "cntvirq", n)); - qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_HYP, - qdev_get_gpio_in_named(DEVICE(&s->control), "cnthpirq", n)); - qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_SEC, - qdev_get_gpio_in_named(DEVICE(&s->control), "cntpsirq", n)); + qdev_connect_gpio_out(DEVICE(&s_base->cpu[n].core), GTIMER_PHYS, + qdev_get_gpio_in_named(DEVICE(&s_base->control), "cntpnsirq", n)); + qdev_connect_gpio_out(DEVICE(&s_base->cpu[n].core), GTIMER_VIRT, + qdev_get_gpio_in_named(DEVICE(&s_base->control), "cntvirq", n)); + qdev_connect_gpio_out(DEVICE(&s_base->cpu[n].core), GTIMER_HYP, + qdev_get_gpio_in_named(DEVICE(&s_base->control), "cnthpirq", n)); + qdev_connect_gpio_out(DEVICE(&s_base->cpu[n].core), GTIMER_SEC, + qdev_get_gpio_in_named(DEVICE(&s_base->control), "cntpsirq", n)); } } -static void bcm283x_class_init(ObjectClass *oc, void *data) +static void bcm283x_base_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); @@ -177,7 +185,7 @@ static void bcm283x_class_init(ObjectClass *oc, void *data) static void bcm2835_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); - BCM283XClass *bc = BCM283X_CLASS(oc); + BCM283XBaseClass *bc = BCM283X_BASE_CLASS(oc); bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176"); bc->core_count = 1; @@ -188,7 +196,7 @@ static void bcm2835_class_init(ObjectClass *oc, void *data) static void bcm2836_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); - BCM283XClass *bc = BCM283X_CLASS(oc); + BCM283XBaseClass *bc = BCM283X_BASE_CLASS(oc); bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); bc->core_count = BCM283X_NCPUS; @@ -202,7 +210,7 @@ static void bcm2836_class_init(ObjectClass *oc, void *data) static void bcm2837_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); - BCM283XClass *bc = BCM283X_CLASS(oc); + BCM283XBaseClass *bc = BCM283X_BASE_CLASS(oc); bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); bc->core_count = BCM283X_NCPUS; @@ -230,11 +238,17 @@ static const TypeInfo bcm283x_types[] = { #endif }, { .name = TYPE_BCM283X, - .parent = TYPE_DEVICE, + .parent = TYPE_BCM283X_BASE, .instance_size = sizeof(BCM283XState), - .instance_init = bcm2836_init, - .class_size = sizeof(BCM283XClass), - .class_init = bcm283x_class_init, + .instance_init = bcm283x_init, + .abstract = true, + }, { + .name = TYPE_BCM283X_BASE, + .parent = TYPE_DEVICE, + .instance_size = sizeof(BCM283XBaseState), + .instance_init = bcm283x_base_init, + .class_size = sizeof(BCM283XBaseClass), + .class_init = bcm283x_base_class_init, .abstract = true, } }; diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index cc4c4ec9bf..af866ebce2 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -252,7 +252,7 @@ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, s->binfo.firmware_loaded = true; } - arm_load_kernel(&s->soc.cpu[0].core, machine, &s->binfo); + arm_load_kernel(&s->soc.parent_obj.cpu[0].core, machine, &s->binfo); } static void raspi_machine_init(MachineState *machine) diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h index 6f90cabfa3..5a6717ca91 100644 --- a/include/hw/arm/bcm2836.h +++ b/include/hw/arm/bcm2836.h @@ -17,8 +17,10 @@ #include "target/arm/cpu.h" #include "qom/object.h" +#define TYPE_BCM283X_BASE "bcm283x-base" +OBJECT_DECLARE_TYPE(BCM283XBaseState, BCM283XBaseClass, BCM283X_BASE) #define TYPE_BCM283X "bcm283x" -OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) +OBJECT_DECLARE_SIMPLE_TYPE(BCM283XState, BCM283X) #define BCM283X_NCPUS 4 @@ -30,7 +32,7 @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) #define TYPE_BCM2836 "bcm2836" #define TYPE_BCM2837 "bcm2837" -struct BCM283XState { +struct BCM283XBaseState { /*< private >*/ DeviceState parent_obj; /*< public >*/ @@ -41,7 +43,27 @@ struct BCM283XState { ARMCPU core; } cpu[BCM283X_NCPUS]; BCM2836ControlState control; +}; + +struct BCM283XBaseClass { + /*< private >*/ + DeviceClass parent_class; + /*< public >*/ + const char *name; + const char *cpu_type; + unsigned core_count; + hwaddr peri_base; /* Peripheral base address seen by the CPU */ + hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */ + int clusterid; +}; + +struct BCM283XState { + /*< private >*/ + BCM283XBaseState parent_obj; + /*< public >*/ BCM2835PeripheralState peripherals; }; +bool bcm283x_common_realize(DeviceState *dev, Error **errp); + #endif /* BCM2836_H */ From patchwork Sun Dec 3 21:28:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=e2Un879S; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Ww03DVz23mf for ; Mon, 4 Dec 2023 08:37:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1e-0001LN-50; Sun, 03 Dec 2023 16:29:18 -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 1r9u1b-0001In-LT; Sun, 03 Dec 2023 16:29:15 -0500 Received: from mail-yb1-xb2d.google.com ([2607:f8b0:4864:20::b2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1Z-0005Nd-0j; Sun, 03 Dec 2023 16:29:15 -0500 Received: by mail-yb1-xb2d.google.com with SMTP id 3f1490d57ef6-db539ab8e02so2184668276.0; Sun, 03 Dec 2023 13:29:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638951; x=1702243751; 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=SeehPYggDOCcHjfK2XNOqzeVs5Qppe8XOO7Nk1MU9CE=; b=e2Un879SnimrsYtYb1rOtdubFID1eImS69zJY4XIzuVq8i561anfTit9Ccla1Iw7KT 9Q1rIOa80n6wLySHrQGu/sN0TtYy6PapkIBEuJNHwYQZThD+SsfLpZiqcS4gzhKMiBjg yxnDaeRzN7kOed2LqlLalA6IHF9WkW9n/fY3ReZIxyJu6py8zDOodRs8PeGLArC1nEr2 WblIummu0Z6Hh/bBRAXg1X/zSu8M6GzP4CEIZDmEIfpJwuG8nx92VB7dFHk5nnHtoFDM nqbyRntdCZn76L0Wha+ZEhrWr5kFMP1ggO49/rFFIaqHCrNiri1CAVpEv2XXM9dhTNqb eqig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638951; x=1702243751; 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=SeehPYggDOCcHjfK2XNOqzeVs5Qppe8XOO7Nk1MU9CE=; b=AD9CQJtdRh81LO7NrASKjTpaKx1vTP50WDOuGHC4Wsb45A12VyWAUw1HvOMdbmGi/B mC0NHrFvp/e2FUJS0lByO9AhpJLQRGeCbckBELp80uvRllgWQNlLB0O//2mCuSaDOMhO 2SfVvmK+qIP9kEMV8k9lr9xo08alja9qbyoat/aoHhhCoXyi7wncM14Vk7GTuAZP2EF5 D9ntH8ET6c3CLJzMMjaRc8KJIo4gQfp4UjmEID96dMkl1eFU/0UbFwmBiHVmwbqivHRu DBN18JvdH7TqcWEMZxDp1bCNeA0jSQ9vxCO4RLIIpZJed2MByDnbXd+t58nX1vFYlCh0 u9Rw== X-Gm-Message-State: AOJu0YwGSx5i3LZAUsSOuY5pSux+oo175BT8Ox2ZV+WIu9rXK/KyZ4Eq r62exkEXUysBGOfmPTUZZh7radlp8dexxQ== X-Google-Smtp-Source: AGHT+IEaajntSxktWssXuEWv1/M5I/bf81+OIHpQXTnNZzCM1i4D1coLX1Yu3vGoxyOu4+As30e6jA== X-Received: by 2002:a25:fc3:0:b0:db0:6cde:3859 with SMTP id 186-20020a250fc3000000b00db06cde3859mr1535273ybp.41.1701638951403; Sun, 03 Dec 2023 13:29:11 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:11 -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 02/45] Split out common part of peripherals Date: Sun, 3 Dec 2023 15:28:22 -0600 Message-Id: <20231203212905.1364036-3-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-2-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2d; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2d.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Pre-setup for BCM2838 introduction Signed-off-by: Sergey Kambalin --- hw/arm/bcm2835_peripherals.c | 198 +++++++++++++++------------ hw/arm/bcm2836.c | 24 ++-- include/hw/arm/bcm2835_peripherals.h | 29 +++- include/hw/arm/bcm2836.h | 3 +- 4 files changed, 154 insertions(+), 100 deletions(-) diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index 0233038b95..fd70cde123 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -30,9 +30,9 @@ #define SEPARATE_DMA_IRQ_MAX 10 #define ORGATED_DMA_IRQ_COUNT 4 -static void create_unimp(BCM2835PeripheralState *ps, - UnimplementedDeviceState *uds, - const char *name, hwaddr ofs, hwaddr size) +void create_unimp(BCMSocPeripheralBaseState *ps, + UnimplementedDeviceState *uds, + const char *name, hwaddr ofs, hwaddr size) { object_initialize_child(OBJECT(ps), name, uds, TYPE_UNIMPLEMENTED_DEVICE); qdev_prop_set_string(DEVICE(uds), "name", name); @@ -45,9 +45,36 @@ static void create_unimp(BCM2835PeripheralState *ps, static void bcm2835_peripherals_init(Object *obj) { BCM2835PeripheralState *s = BCM2835_PERIPHERALS(obj); + BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(obj); + + /* Random Number Generator */ + object_initialize_child(obj, "rng", &s->rng, TYPE_BCM2835_RNG); + + /* Thermal */ + object_initialize_child(obj, "thermal", &s->thermal, TYPE_BCM2835_THERMAL); + + /* GPIO */ + object_initialize_child(obj, "gpio", &s->gpio, TYPE_BCM2835_GPIO); + + object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhci", + OBJECT(&s_base->sdhci.sdbus)); + object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhost", + OBJECT(&s_base->sdhost.sdbus)); + + /* Gated DMA interrupts */ + object_initialize_child(obj, "orgated-dma-irq", + &s_base->orgated_dma_irq, TYPE_OR_IRQ); + object_property_set_int(OBJECT(&s_base->orgated_dma_irq), "num-lines", + ORGATED_DMA_IRQ_COUNT, &error_abort); +} + +static void raspi_peripherals_base_init(Object *obj) +{ + BCMSocPeripheralBaseState *s = BCM_SOC_PERIPHERALS_BASE(obj); + BCMSocPeripheralBaseClass *bc = BCM_SOC_PERIPHERALS_BASE_GET_CLASS(obj); /* Memory region for peripheral devices, which we export to our parent */ - memory_region_init(&s->peri_mr, obj,"bcm2835-peripherals", 0x1000000); + memory_region_init(&s->peri_mr, obj, "bcm2835-peripherals", bc->peri_size); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_mr); /* Internal memory region for peripheral bus addresses (not exported) */ @@ -98,9 +125,6 @@ static void bcm2835_peripherals_init(Object *obj) object_property_add_const_link(OBJECT(&s->property), "dma-mr", OBJECT(&s->gpu_bus_mr)); - /* Random Number Generator */ - object_initialize_child(obj, "rng", &s->rng, TYPE_BCM2835_RNG); - /* Extended Mass Media Controller */ object_initialize_child(obj, "sdhci", &s->sdhci, TYPE_SYSBUS_SDHCI); @@ -110,25 +134,9 @@ static void bcm2835_peripherals_init(Object *obj) /* DMA Channels */ object_initialize_child(obj, "dma", &s->dma, TYPE_BCM2835_DMA); - object_initialize_child(obj, "orgated-dma-irq", - &s->orgated_dma_irq, TYPE_OR_IRQ); - object_property_set_int(OBJECT(&s->orgated_dma_irq), "num-lines", - ORGATED_DMA_IRQ_COUNT, &error_abort); - object_property_add_const_link(OBJECT(&s->dma), "dma-mr", OBJECT(&s->gpu_bus_mr)); - /* Thermal */ - object_initialize_child(obj, "thermal", &s->thermal, TYPE_BCM2835_THERMAL); - - /* GPIO */ - object_initialize_child(obj, "gpio", &s->gpio, TYPE_BCM2835_GPIO); - - object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhci", - OBJECT(&s->sdhci.sdbus)); - object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhost", - OBJECT(&s->sdhost.sdbus)); - /* Mphi */ object_initialize_child(obj, "mphi", &s->mphi, TYPE_BCM2835_MPHI); @@ -148,7 +156,72 @@ static void bcm2835_peripherals_init(Object *obj) static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) { + MemoryRegion *mphi_mr; BCM2835PeripheralState *s = BCM2835_PERIPHERALS(dev); + BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(dev); + int n; + + bcm_soc_peripherals_common_realize(dev, errp); + + /* Extended Mass Media Controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->sdhci), 0, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), BCM2835_IC_GPU_IRQ, + INTERRUPT_ARASANSDIO)); + + /* Connect DMA 0-12 to the interrupt controller */ + for (n = 0; n <= SEPARATE_DMA_IRQ_MAX; n++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), n, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + INTERRUPT_DMA0 + n)); + } + + if (!qdev_realize(DEVICE(&s_base->orgated_dma_irq), NULL, errp)) { + return; + } + for (n = 0; n < ORGATED_DMA_IRQ_COUNT; n++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), + SEPARATE_DMA_IRQ_MAX + 1 + n, + qdev_get_gpio_in(DEVICE(&s_base->orgated_dma_irq), n)); + } + qdev_connect_gpio_out(DEVICE(&s_base->orgated_dma_irq), 0, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + INTERRUPT_DMA0 + SEPARATE_DMA_IRQ_MAX + 1)); + + /* Random Number Generator */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->rng), errp)) { + return; + } + memory_region_add_subregion( + &s_base->peri_mr, RNG_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng), 0)); + + /* THERMAL */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->thermal), errp)) { + return; + } + memory_region_add_subregion(&s_base->peri_mr, THERMAL_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->thermal), 0)); + + /* Map MPHI to the peripherals memory map */ + mphi_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s_base->mphi), 0); + memory_region_add_subregion(&s_base->peri_mr, MPHI_OFFSET, mphi_mr); + + /* GPIO */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { + return; + } + memory_region_add_subregion( + &s_base->peri_mr, GPIO_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gpio), 0)); + + object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->gpio), "sd-bus"); +} + +void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp) +{ + BCMSocPeripheralBaseState *s = BCM_SOC_PERIPHERALS_BASE(dev); Object *obj; MemoryRegion *ram; Error *err = NULL; @@ -281,14 +354,6 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->property), 0, qdev_get_gpio_in(DEVICE(&s->mboxes), MBOX_CHAN_PROPERTY)); - /* Random Number Generator */ - if (!sysbus_realize(SYS_BUS_DEVICE(&s->rng), errp)) { - return; - } - - memory_region_add_subregion(&s->peri_mr, RNG_OFFSET, - sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng), 0)); - /* Extended Mass Media Controller * * Compatible with: @@ -311,9 +376,6 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) memory_region_add_subregion(&s->peri_mr, EMMC1_OFFSET, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->sdhci), 0)); - sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0, - qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ, - INTERRUPT_ARASANSDIO)); /* SDHOST */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->sdhost), errp)) { @@ -336,49 +398,11 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) memory_region_add_subregion(&s->peri_mr, DMA15_OFFSET, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dma), 1)); - for (n = 0; n <= SEPARATE_DMA_IRQ_MAX; n++) { - sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), n, - qdev_get_gpio_in_named(DEVICE(&s->ic), - BCM2835_IC_GPU_IRQ, - INTERRUPT_DMA0 + n)); - } - if (!qdev_realize(DEVICE(&s->orgated_dma_irq), NULL, errp)) { - return; - } - for (n = 0; n < ORGATED_DMA_IRQ_COUNT; n++) { - sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), - SEPARATE_DMA_IRQ_MAX + 1 + n, - qdev_get_gpio_in(DEVICE(&s->orgated_dma_irq), n)); - } - qdev_connect_gpio_out(DEVICE(&s->orgated_dma_irq), 0, - qdev_get_gpio_in_named(DEVICE(&s->ic), - BCM2835_IC_GPU_IRQ, - INTERRUPT_DMA0 + SEPARATE_DMA_IRQ_MAX + 1)); - - /* THERMAL */ - if (!sysbus_realize(SYS_BUS_DEVICE(&s->thermal), errp)) { - return; - } - memory_region_add_subregion(&s->peri_mr, THERMAL_OFFSET, - sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->thermal), 0)); - - /* GPIO */ - if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { - return; - } - - memory_region_add_subregion(&s->peri_mr, GPIO_OFFSET, - sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gpio), 0)); - - object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->gpio), "sd-bus"); - /* Mphi */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->mphi), errp)) { return; } - memory_region_add_subregion(&s->peri_mr, MPHI_OFFSET, - sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mphi), 0)); sysbus_connect_irq(SYS_BUS_DEVICE(&s->mphi), 0, qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ, INTERRUPT_HOSTPORT)); @@ -421,21 +445,27 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) static void bcm2835_peripherals_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); + BCMSocPeripheralBaseClass *bc = BCM_SOC_PERIPHERALS_BASE_CLASS(oc); + bc->peri_size = 0x1000000; dc->realize = bcm2835_peripherals_realize; } -static const TypeInfo bcm2835_peripherals_type_info = { - .name = TYPE_BCM2835_PERIPHERALS, - .parent = TYPE_SYS_BUS_DEVICE, - .instance_size = sizeof(BCM2835PeripheralState), - .instance_init = bcm2835_peripherals_init, - .class_init = bcm2835_peripherals_class_init, +static const TypeInfo bcm2835_peripherals_types[] = { + { + .name = TYPE_BCM2835_PERIPHERALS, + .parent = TYPE_BCM_SOC_PERIPHERALS_BASE, + .instance_size = sizeof(BCM2835PeripheralState), + .instance_init = bcm2835_peripherals_init, + .class_init = bcm2835_peripherals_class_init, + }, { + .name = TYPE_BCM_SOC_PERIPHERALS_BASE, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(BCMSocPeripheralBaseState), + .instance_init = raspi_peripherals_base_init, + .class_size = sizeof(BCMSocPeripheralBaseClass), + .abstract = true, + } }; -static void bcm2835_peripherals_register_types(void) -{ - type_register_static(&bcm2835_peripherals_type_info); -} - -type_init(bcm2835_peripherals_register_types) +DEFINE_TYPES(bcm2835_peripherals_types) diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c index 66a2b57b38..18675c896c 100644 --- a/hw/arm/bcm2836.c +++ b/hw/arm/bcm2836.c @@ -66,10 +66,10 @@ static void bcm283x_init(Object *obj) "vcram-size"); } -bool bcm283x_common_realize(DeviceState *dev, Error **errp) +bool bcm283x_common_realize(DeviceState *dev, BCMSocPeripheralBaseState *ps, + Error **errp) { - BCM283XState *s = BCM283X(dev); - BCM283XBaseState *s_base = BCM283X_BASE(dev); + BCM283XBaseState *s = BCM283X_BASE(dev); BCM283XBaseClass *bc = BCM283X_BASE_GET_CLASS(dev); Object *obj; @@ -77,17 +77,15 @@ bool bcm283x_common_realize(DeviceState *dev, Error **errp) obj = object_property_get_link(OBJECT(dev), "ram", &error_abort); - object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj); + object_property_add_const_link(OBJECT(ps), "ram", obj); - if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) { + if (!sysbus_realize(SYS_BUS_DEVICE(ps), errp)) { return false; } - object_property_add_alias(OBJECT(s_base), "sd-bus", - OBJECT(&s->peripherals), "sd-bus"); + object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(ps), "sd-bus"); - sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), - 0, bc->peri_base, 1); + sysbus_mmio_map_overlap(SYS_BUS_DEVICE(ps), 0, bc->peri_base, 1); return true; } @@ -95,8 +93,10 @@ static void bcm2835_realize(DeviceState *dev, Error **errp) { BCM283XState *s = BCM283X(dev); BCM283XBaseState *s_base = BCM283X_BASE(dev); + BCMSocPeripheralBaseState *ps_base + = BCM_SOC_PERIPHERALS_BASE(&s->peripherals); - if (!bcm283x_common_realize(dev, errp)) { + if (!bcm283x_common_realize(dev, ps_base, errp)) { return; } @@ -117,8 +117,10 @@ static void bcm2836_realize(DeviceState *dev, Error **errp) BCM283XState *s = BCM283X(dev); BCM283XBaseState *s_base = BCM283X_BASE(dev); BCM283XBaseClass *bc = BCM283X_BASE_GET_CLASS(dev); + BCMSocPeripheralBaseState *ps_base + = BCM_SOC_PERIPHERALS_BASE(&s->peripherals); - if (!bcm283x_common_realize(dev, errp)) { + if (!bcm283x_common_realize(dev, ps_base, errp)) { return; } diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h index d724a2fc28..2644735d52 100644 --- a/include/hw/arm/bcm2835_peripherals.h +++ b/include/hw/arm/bcm2835_peripherals.h @@ -34,10 +34,13 @@ #include "hw/misc/unimp.h" #include "qom/object.h" +#define TYPE_BCM_SOC_PERIPHERALS_BASE "bcm-soc-peripherals-base" +OBJECT_DECLARE_TYPE(BCMSocPeripheralBaseState, BCMSocPeripheralBaseClass, + BCM_SOC_PERIPHERALS_BASE) #define TYPE_BCM2835_PERIPHERALS "bcm2835-peripherals" OBJECT_DECLARE_SIMPLE_TYPE(BCM2835PeripheralState, BCM2835_PERIPHERALS) -struct BCM2835PeripheralState { +struct BCMSocPeripheralBaseState { /*< private >*/ SysBusDevice parent_obj; /*< public >*/ @@ -59,12 +62,9 @@ struct BCM2835PeripheralState { OrIRQState orgated_dma_irq; BCM2835ICState ic; BCM2835PropertyState property; - BCM2835RngState rng; BCM2835MboxState mboxes; SDHCIState sdhci; BCM2835SDHostState sdhost; - BCM2835GpioState gpio; - Bcm2835ThermalState thermal; UnimplementedDeviceState i2s; UnimplementedDeviceState spi[1]; UnimplementedDeviceState i2c[3]; @@ -78,4 +78,25 @@ struct BCM2835PeripheralState { UnimplementedDeviceState sdramc; }; +struct BCMSocPeripheralBaseClass { + /*< private >*/ + SysBusDeviceClass parent_class; + /*< public >*/ + uint64_t peri_size; /* Peripheral range size */ +}; + +struct BCM2835PeripheralState { + /*< private >*/ + BCMSocPeripheralBaseState parent_obj; + /*< public >*/ + BCM2835RngState rng; + Bcm2835ThermalState thermal; + BCM2835GpioState gpio; +}; + +void create_unimp(BCMSocPeripheralBaseState *ps, + UnimplementedDeviceState *uds, + const char *name, hwaddr ofs, hwaddr size); +void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp); + #endif /* BCM2835_PERIPHERALS_H */ diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h index 5a6717ca91..918fb3bf14 100644 --- a/include/hw/arm/bcm2836.h +++ b/include/hw/arm/bcm2836.h @@ -64,6 +64,7 @@ struct BCM283XState { BCM2835PeripheralState peripherals; }; -bool bcm283x_common_realize(DeviceState *dev, Error **errp); +bool bcm283x_common_realize(DeviceState *dev, BCMSocPeripheralBaseState *ps, + Error **errp); #endif /* BCM2836_H */ From patchwork Sun Dec 3 21:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UhGA4AB8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0X70wNYz23p6 for ; Mon, 4 Dec 2023 08:37:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1g-0001Nc-6V; Sun, 03 Dec 2023 16:29:20 -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 1r9u1d-0001Kl-8O; Sun, 03 Dec 2023 16:29:17 -0500 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1a-0005Nn-4f; Sun, 03 Dec 2023 16:29:16 -0500 Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-daf26d84100so2053518276.3; Sun, 03 Dec 2023 13:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638952; x=1702243752; 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=7mb12SLyYKgE+GLLI/c9J/vANlZ3FBQt3OE84lYGKOg=; b=UhGA4AB8anW1u8R8meNxTTy/afA5gabU6+8iWVxAWUkHjKCmT4ZwAJlNYZX5LORV+p qBFfZTGoplYEwp0i1eNTZlhsQDlyzCRzfWgHfIE9k5b4VFXPriXBRwaQeA7Mjix6tPH0 WCpRQMlSdHG8HCGyU/N4Ax7MAF9CyA65l3LwzmB2FgPSsoDHg3qIxB77BFGwTTBjH0TM k21rjrAhabRhGf3Ijj0aLCRmKZh5rkqVx8QcIg2i++97TLuT01GcGTYcZe8WFbLyhJbT /WRA94PpgVl+d0F3zQrAOBcWCQYdXlJrYl+pQ1Z9p55/Utdo4FHItncV4Hah8xF+NEsq dDHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638952; x=1702243752; 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=7mb12SLyYKgE+GLLI/c9J/vANlZ3FBQt3OE84lYGKOg=; b=WASUX4QeXDEZ1axROvPON7RzQNs1u42LWAFW0GRibQbweZPWWIQvGlzuYM/tfiBD7Y DL6HMKJKMQStroE022XvODe8GzaiTnJlNWn1OvG72p7bu/Zl88di5BrW0GAGF6hZKpJs tn590XBUavttmLwtjFwa4teLy9HD6oDLEwYeK7aLaqKGw7n6Gsjh2Veo6HE3GMZ7bS+D Ak5r87W3S3K9+TQLYiKOKn+rcnrmC/tUH54VPNI+Qxu6hUNaKYnl5Z3Cvp3Wwt/wIjod ALub5W6cMaebPatyPcydM8TaghGODjV5qmjwq0JIReZL+U1Dcxa7yRHhtD+cUfNLkJIy 0DOw== X-Gm-Message-State: AOJu0Yx9K3jeA0h9Y3l0SYr0lXUzHBOqYhmEuEGvZ/qGFKumuqGuebVo QHEIi4gflWAzQU/WWZiGtAWIisWhzGoceA== X-Google-Smtp-Source: AGHT+IGFdoggnCgJeNgkIcOZyECZ5WFnhfuInQZ+sk5X/LARptDyge8ZXsAmZHPsgOA6S6fNf8FWRg== X-Received: by 2002:a25:f44d:0:b0:d9a:e397:3b4 with SMTP id p13-20020a25f44d000000b00d9ae39703b4mr25888106ybe.46.1701638952414; Sun, 03 Dec 2023 13:29:12 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:12 -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 03/45] Split out raspi machine common part Date: Sun, 3 Dec 2023 15:28:23 -0600 Message-Id: <20231203212905.1364036-4-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-3-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2e; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2e.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Pre-setup for raspberry pi 4 introduction Signed-off-by: Sergey Kambalin --- hw/arm/raspi.c | 112 ++++++++++++++++++-------------- include/hw/arm/raspi_platform.h | 21 ++++++ 2 files changed, 85 insertions(+), 48 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index af866ebce2..7d04734cd2 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "hw/arm/boot.h" #include "hw/arm/bcm2836.h" +#include "hw/arm/raspi_platform.h" #include "hw/registerfields.h" #include "qemu/error-report.h" #include "hw/boards.h" @@ -25,6 +26,9 @@ #include "hw/arm/boot.h" #include "qom/object.h" +#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") +OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE) + #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */ #define MVBAR_ADDR 0x400 /* secure vectors */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ @@ -37,25 +41,10 @@ struct RaspiMachineState { /*< private >*/ - MachineState parent_obj; + RaspiBaseMachineState parent_obj; /*< public >*/ BCM283XState soc; - struct arm_boot_info binfo; -}; -typedef struct RaspiMachineState RaspiMachineState; - -struct RaspiMachineClass { - /*< private >*/ - MachineClass parent_obj; - /*< public >*/ - uint32_t board_rev; }; -typedef struct RaspiMachineClass RaspiMachineClass; - -#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") -DECLARE_OBJ_CHECKERS(RaspiMachineState, RaspiMachineClass, - RASPI_MACHINE, TYPE_RASPI_MACHINE) - /* * Board revision codes: @@ -83,6 +72,11 @@ static const struct { [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, }; +static void raspi_base_machine_init(MachineState *machine, + BCM283XBaseState *soc); +static void raspi_machine_class_common_init(MachineClass *mc, + uint32_t board_rev); + static uint64_t board_ram_size(uint32_t board_rev) { assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ @@ -200,13 +194,12 @@ static void reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) cpu_set_pc(cs, info->smp_loader_start); } -static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, - size_t ram_size) +static void setup_boot(MachineState *machine, ARMCPU *cpu, + RaspiProcessorId processor_id, size_t ram_size) { - RaspiMachineState *s = RASPI_MACHINE(machine); + RaspiBaseMachineState *s = RASPI_BASE_MACHINE(machine); int r; - s->binfo.board_id = MACH_TYPE_BCM2708; s->binfo.ram_size = ram_size; if (processor_id <= PROCESSOR_ID_BCM2836) { @@ -252,13 +245,13 @@ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, s->binfo.firmware_loaded = true; } - arm_load_kernel(&s->soc.parent_obj.cpu[0].core, machine, &s->binfo); + arm_load_kernel(cpu, machine, &s->binfo); } -static void raspi_machine_init(MachineState *machine) +static void raspi_base_machine_init(MachineState *machine, + BCM283XBaseState *soc) { - RaspiMachineClass *mc = RASPI_MACHINE_GET_CLASS(machine); - RaspiMachineState *s = RASPI_MACHINE(machine); + RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine); uint32_t board_rev = mc->board_rev; uint64_t ram_size = board_ram_size(board_rev); uint32_t vcram_size; @@ -279,19 +272,17 @@ static void raspi_machine_init(MachineState *machine) machine->ram, 0); /* Setup the SOC */ - object_initialize_child(OBJECT(machine), "soc", &s->soc, - board_soc_type(board_rev)); - object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(machine->ram)); - object_property_set_int(OBJECT(&s->soc), "board-rev", board_rev, + object_property_add_const_link(OBJECT(soc), "ram", OBJECT(machine->ram)); + object_property_set_int(OBJECT(soc), "board-rev", board_rev, &error_abort); - object_property_set_str(OBJECT(&s->soc), "command-line", + object_property_set_str(OBJECT(soc), "command-line", machine->kernel_cmdline, &error_abort); - qdev_realize(DEVICE(&s->soc), NULL, &error_fatal); + qdev_realize(DEVICE(soc), NULL, &error_fatal); /* Create and plug in the SD cards */ di = drive_get(IF_SD, 0, 0); blk = di ? blk_by_legacy_dinfo(di) : NULL; - bus = qdev_get_child_bus(DEVICE(&s->soc), "sd-bus"); + bus = qdev_get_child_bus(DEVICE(soc), "sd-bus"); if (bus == NULL) { error_report("No SD bus found in SOC object"); exit(1); @@ -300,19 +291,32 @@ static void raspi_machine_init(MachineState *machine) qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); qdev_realize_and_unref(carddev, bus, &error_fatal); - vcram_size = object_property_get_uint(OBJECT(&s->soc), "vcram-size", + vcram_size = object_property_get_uint(OBJECT(soc), "vcram-size", &error_abort); - setup_boot(machine, board_processor_id(mc->board_rev), + setup_boot(machine, &soc->cpu[0].core, board_processor_id(board_rev), machine->ram_size - vcram_size); } -static void raspi_machine_class_common_init(MachineClass *mc, - uint32_t board_rev) +static void raspi_machine_init(MachineState *machine) +{ + RaspiMachineState *s = RASPI_MACHINE(machine); + RaspiBaseMachineState *s_base = RASPI_BASE_MACHINE(machine); + RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine); + BCM283XState *soc = &s->soc; + + s_base->binfo.board_id = MACH_TYPE_BCM2708; + + object_initialize_child(OBJECT(machine), "soc", soc, + board_soc_type(mc->board_rev)); + raspi_base_machine_init(machine, &soc->parent_obj); +} + +void raspi_machine_class_common_init(MachineClass *mc, + uint32_t board_rev) { mc->desc = g_strdup_printf("Raspberry Pi %s (revision 1.%u)", board_type(board_rev), FIELD_EX32(board_rev, REV_CODE, REVISION)); - mc->init = raspi_machine_init; mc->block_default_type = IF_SD; mc->no_parallel = 1; mc->no_floppy = 1; @@ -322,50 +326,57 @@ static void raspi_machine_class_common_init(MachineClass *mc, mc->default_ram_id = "ram"; }; +static void raspi_machine_class_init(MachineClass *mc, + uint32_t board_rev) +{ + raspi_machine_class_common_init(mc, board_rev); + mc->init = raspi_machine_init; +}; + static void raspi0_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc); rmc->board_rev = 0x920092; /* Revision 1.2 */ - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc); rmc->board_rev = 0x900021; /* Revision 1.1 */ - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; static void raspi2b_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc); rmc->board_rev = 0xa21041; - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; #ifdef TARGET_AARCH64 static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc); rmc->board_rev = 0x9020e0; /* Revision 1.0 */ - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; static void raspi3b_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc); rmc->board_rev = 0xa02082; - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; #endif /* TARGET_AARCH64 */ @@ -394,9 +405,14 @@ static const TypeInfo raspi_machine_types[] = { #endif }, { .name = TYPE_RASPI_MACHINE, - .parent = TYPE_MACHINE, + .parent = TYPE_RASPI_BASE_MACHINE, .instance_size = sizeof(RaspiMachineState), - .class_size = sizeof(RaspiMachineClass), + .abstract = true, + }, { + .name = TYPE_RASPI_BASE_MACHINE, + .parent = TYPE_MACHINE, + .instance_size = sizeof(RaspiBaseMachineState), + .class_size = sizeof(RaspiBaseMachineClass), .abstract = true, } }; diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h index ede98e63c3..3018e8fcf3 100644 --- a/include/hw/arm/raspi_platform.h +++ b/include/hw/arm/raspi_platform.h @@ -28,6 +28,27 @@ #ifndef HW_ARM_RASPI_PLATFORM_H #define HW_ARM_RASPI_PLATFORM_H +#include "hw/boards.h" +#include "hw/arm/boot.h" + +#define TYPE_RASPI_BASE_MACHINE MACHINE_TYPE_NAME("raspi-base") +OBJECT_DECLARE_TYPE(RaspiBaseMachineState, RaspiBaseMachineClass, + RASPI_BASE_MACHINE) + +struct RaspiBaseMachineState { + /*< private >*/ + MachineState parent_obj; + /*< public >*/ + struct arm_boot_info binfo; +}; + +struct RaspiBaseMachineClass { + /*< private >*/ + MachineClass parent_obj; + /*< public >*/ + uint32_t board_rev; +}; + #define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */ #define CCPT_OFFSET 0x1000 /* Compact Camera Port 2 TX */ #define INTE_OFFSET 0x2000 /* VC Interrupt controller */ From patchwork Sun Dec 3 21:28:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DVhJEUe2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0XN4dkjz23mf for ; Mon, 4 Dec 2023 08:38:12 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1g-0001NM-2N; Sun, 03 Dec 2023 16:29:20 -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 1r9u1d-0001L2-MB; Sun, 03 Dec 2023 16:29:17 -0500 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1b-0005O6-Ks; Sun, 03 Dec 2023 16:29:17 -0500 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-db35caa1749so2058118276.2; Sun, 03 Dec 2023 13:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638953; x=1702243753; 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=I0abax01Jn7TA0fY2P1fUcZE3FFcwoH4EKqmrD+AUDY=; b=DVhJEUe2TMuEwQ7hSQEm/XiPpqEeSNw8eq7VIMdjRPgGF29EzWy77FC2yoBquIIyj2 SRy+eDB5gpJl22YhY50wzGYwvD6V+PZFlTUbQDU2N823Eqt4KWl1fN1re5oiPzESYETw /bitaaG8OormHqD6xNo9iGSWS6oKTP+3J/aC+GyjHBs6ydDFRJWbXlu5bmVl1NE7Vyb4 TFqqGzSaTEUH49mGGXtllfWMszfNp+ggFwTZ0qRvvxvPUfCs3GWXTLd8N0HqFF5kby6L CPG5e9MJfFZLI6JuhyEv8i54eBGmIwvG9C4Y7A7/XwdNvDFngaseKKkNA3wNWgtsa5S+ E3jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638953; x=1702243753; 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=I0abax01Jn7TA0fY2P1fUcZE3FFcwoH4EKqmrD+AUDY=; b=X9bhcOEvmr9dgP5tpCv1UV87+dGcjvVV+D+8VyV+dzVhubffxyK6V/olC940pn8FE6 wCgWi7EW/2SrK6x5se9FehzvX1ODu+jC8paYkpIiKe+5vtoiQcUGHYEuvMOcc9ESJ3tS IhmXG6m3XWhoxYZ01Vg8KJZuHm5dN7XK7yZb1AO8y6Cvy3gXC+Ai0BSO5Xh16KryAL4Z 6wrCjq6L4FgyfP5kMz91rjCdK1HhoxttoCNBsMsfqUon1sQnfSR1TlTwX/QHRei+Oz26 Tb1fME50I/AOOEDn3okBmabzg/l82xHXRHnpZnBHuvRbSMxJ+Wj4MSyFhk+jnVmLq8jx 7sCA== X-Gm-Message-State: AOJu0Yx/xwyaDKtoBPorbd6XXCRkkE/dzOqp1cXWGFs73qzSilzjvd7p xtoxCs5atoWCt4knTe1j1ZeOqV9ikB5I6Q== X-Google-Smtp-Source: AGHT+IGBzftwskuH7WegJKk+KDg2A63yMsQ6K4uXspAoOjuLuU+45r8tE+dNXTYs23xx5WM5Him5/A== X-Received: by 2002:a25:428c:0:b0:d9a:4ae7:ba2c with SMTP id p134-20020a25428c000000b00d9a4ae7ba2cmr1640799yba.22.1701638953439; Sun, 03 Dec 2023 13:29:13 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:13 -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 04/45] Introduce BCM2838 SoC Date: Sun, 3 Dec 2023 15:28:24 -0600 Message-Id: <20231203212905.1364036-5-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-4-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2f; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838.c | 100 +++++++++++++++++++++++++++ hw/arm/bcm2838_peripherals.c | 72 +++++++++++++++++++ hw/arm/meson.build | 2 + include/hw/arm/bcm2838.h | 29 ++++++++ include/hw/arm/bcm2838_peripherals.h | 36 ++++++++++ 5 files changed, 239 insertions(+) create mode 100644 hw/arm/bcm2838.c create mode 100644 hw/arm/bcm2838_peripherals.c create mode 100644 include/hw/arm/bcm2838.h create mode 100644 include/hw/arm/bcm2838_peripherals.h diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c new file mode 100644 index 0000000000..c61c59661b --- /dev/null +++ b/hw/arm/bcm2838.c @@ -0,0 +1,100 @@ +/* + * BCM2838 SoC emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "hw/arm/raspi_platform.h" +#include "hw/sysbus.h" +#include "hw/arm/bcm2838.h" +#include "trace.h" + +#define VIRTUAL_PMU_IRQ 7 + +static void bcm2838_init(Object *obj) +{ + BCM2838State *s = BCM2838(obj); + + object_initialize_child(obj, "peripherals", &s->peripherals, + TYPE_BCM2838_PERIPHERALS); + object_property_add_alias(obj, "board-rev", OBJECT(&s->peripherals), + "board-rev"); + object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals), + "vcram-size"); + object_property_add_alias(obj, "command-line", OBJECT(&s->peripherals), + "command-line"); +} + +static void bcm2838_realize(DeviceState *dev, Error **errp) +{ + int n; + BCM2838State *s = BCM2838(dev); + BCM283XBaseState *s_base = BCM283X_BASE(dev); + BCM283XBaseClass *bc_base = BCM283X_BASE_GET_CLASS(dev); + BCM2838PeripheralState *ps = BCM2838_PERIPHERALS(&s->peripherals); + BCMSocPeripheralBaseState *ps_base = + BCM_SOC_PERIPHERALS_BASE(&s->peripherals); + + if (!bcm283x_common_realize(dev, ps_base, errp)) { + return; + } + sysbus_mmio_map_overlap(SYS_BUS_DEVICE(ps), 1, BCM2838_PERI_LOW_BASE, 1); + + /* bcm2836 interrupt controller (and mailboxes, etc.) */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s_base->control), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s_base->control), 0, bc_base->ctrl_base); + + /* Create cores */ + for (n = 0; n < bc_base->core_count; n++) { + /* TODO: this should be converted to a property of ARM_CPU */ + s_base->cpu[n].core.mp_affinity = (bc_base->clusterid << 8) | n; + + /* start powered off if not enabled */ + if (!object_property_set_bool(OBJECT(&s_base->cpu[n].core), + "start-powered-off", + n >= s_base->enabled_cpus, + errp)) { + return; + } + + if (!qdev_realize(DEVICE(&s_base->cpu[n].core), NULL, errp)) { + return; + } + } +} + +static void bcm2838_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + BCM283XBaseClass *bc_base = BCM283X_BASE_CLASS(oc); + + bc_base->cpu_type = ARM_CPU_TYPE_NAME("cortex-a72"); + bc_base->core_count = BCM283X_NCPUS; + bc_base->peri_base = 0xfe000000; + bc_base->ctrl_base = 0xff800000; + bc_base->clusterid = 0x0; + dc->realize = bcm2838_realize; +} + +static const TypeInfo bcm2838_type = { + .name = TYPE_BCM2838, + .parent = TYPE_BCM283X_BASE, + .instance_size = sizeof(BCM2838State), + .instance_init = bcm2838_init, + .class_size = sizeof(BCM283XBaseClass), + .class_init = bcm2838_class_init, +}; + +static void bcm2838_register_types(void) +{ + type_register_static(&bcm2838_type); +} + +type_init(bcm2838_register_types); diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c new file mode 100644 index 0000000000..06110c724f --- /dev/null +++ b/hw/arm/bcm2838_peripherals.c @@ -0,0 +1,72 @@ +/* + * BCM2838 peripherals emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "hw/arm/raspi_platform.h" +#include "hw/arm/bcm2838_peripherals.h" + +/* Lower peripheral base address on the VC (GPU) system bus */ +#define BCM2838_VC_PERI_LOW_BASE 0x7c000000 + +static void bcm2838_peripherals_init(Object *obj) +{ + BCM2838PeripheralState *s = BCM2838_PERIPHERALS(obj); + BCM2838PeripheralClass *bc = BCM2838_PERIPHERALS_GET_CLASS(obj); + + /* Lower memory region for peripheral devices (exported to the Soc) */ + memory_region_init(&s->peri_low_mr, obj, "bcm2838-peripherals", + bc->peri_low_size); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_low_mr); + +} + +static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) +{ + BCM2838PeripheralState *s = BCM2838_PERIPHERALS(dev); + BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(dev); + + bcm_soc_peripherals_common_realize(dev, errp); + + /* Map lower peripherals into the GPU address space */ + memory_region_init_alias(&s->peri_low_mr_alias, OBJECT(s), + "bcm2838-peripherals", &s->peri_low_mr, 0, + memory_region_size(&s->peri_low_mr)); + memory_region_add_subregion_overlap(&s_base->gpu_bus_mr, + BCM2838_VC_PERI_LOW_BASE, + &s->peri_low_mr_alias, 1); + +} + +static void bcm2838_peripherals_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + BCM2838PeripheralClass *bc = BCM2838_PERIPHERALS_CLASS(oc); + BCMSocPeripheralBaseClass *bc_base = BCM_SOC_PERIPHERALS_BASE_CLASS(oc); + + bc->peri_low_size = 0x2000000; + bc_base->peri_size = 0x1800000; + dc->realize = bcm2838_peripherals_realize; +} + +static const TypeInfo bcm2838_peripherals_type_info = { + .name = TYPE_BCM2838_PERIPHERALS, + .parent = TYPE_BCM_SOC_PERIPHERALS_BASE, + .instance_size = sizeof(BCM2838PeripheralState), + .instance_init = bcm2838_peripherals_init, + .class_size = sizeof(BCM2838PeripheralClass), + .class_init = bcm2838_peripherals_class_init, +}; + +static void bcm2838_peripherals_register_types(void) +{ + type_register_static(&bcm2838_peripherals_type_info); +} + +type_init(bcm2838_peripherals_register_types) diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 68245d3ad1..551ab6abf5 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -39,6 +39,7 @@ arm_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10.c', 'cubi arm_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3.c', 'orangepi.c')) arm_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bananapi_m2u.c')) arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c')) +arm_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files('bcm2838.c')) arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c')) arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c')) arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c')) @@ -69,6 +70,7 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files('xen_arm.c')) system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c')) +system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c')) system_ss.add(when: 'CONFIG_TOSA', if_true: files('tosa.c')) hw_arch += {'arm': arm_ss} diff --git a/include/hw/arm/bcm2838.h b/include/hw/arm/bcm2838.h new file mode 100644 index 0000000000..bddc25ca9a --- /dev/null +++ b/include/hw/arm/bcm2838.h @@ -0,0 +1,29 @@ +/* + * BCM2838 SoC emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BCM2838_H +#define BCM2838_H + +#include "hw/arm/bcm2836.h" +#include "hw/arm/bcm2838_peripherals.h" + +#define BCM2838_PERI_LOW_BASE 0xfc000000 +#define BCM2838_GIC_BASE 0x40000 + +#define TYPE_BCM2838 "bcm2838" + +OBJECT_DECLARE_TYPE(BCM2838State, BCM2838Class, BCM2838) + +struct BCM2838State { + /*< private >*/ + BCM283XBaseState parent_obj; + /*< public >*/ + BCM2838PeripheralState peripherals; +}; + +#endif /* BCM2838_H */ diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h new file mode 100644 index 0000000000..7039b67cc9 --- /dev/null +++ b/include/hw/arm/bcm2838_peripherals.h @@ -0,0 +1,36 @@ +/* + * BCM2838 peripherals emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BCM2838_PERIPHERALS_H +#define BCM2838_PERIPHERALS_H + +#include "hw/arm/bcm2835_peripherals.h" + + +#define TYPE_BCM2838_PERIPHERALS "bcm2838-peripherals" +OBJECT_DECLARE_TYPE(BCM2838PeripheralState, BCM2838PeripheralClass, + BCM2838_PERIPHERALS) + +struct BCM2838PeripheralState { + /*< private >*/ + BCMSocPeripheralBaseState parent_obj; + + /*< public >*/ + MemoryRegion peri_low_mr; + MemoryRegion peri_low_mr_alias; + MemoryRegion mphi_mr_alias; +}; + +struct BCM2838PeripheralClass { + /*< private >*/ + BCMSocPeripheralBaseClass parent_class; + /*< public >*/ + uint64_t peri_low_size; /* Peripheral lower range size */ +}; + +#endif /* BCM2838_PERIPHERALS_H */ From patchwork Sun Dec 3 21:28:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iu3758lo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0W567Tvz23mf for ; Mon, 4 Dec 2023 08:37:05 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1h-0001OW-AT; Sun, 03 Dec 2023 16:29:21 -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 1r9u1f-0001Mi-6Y; Sun, 03 Dec 2023 16:29:19 -0500 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1d-0005OG-4Z; Sun, 03 Dec 2023 16:29:18 -0500 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-da41acaea52so2056686276.3; Sun, 03 Dec 2023 13:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638954; x=1702243754; 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=hfYRXu2++EiNfxFS//da1r77rkXtLqsXyrHlBY61ejo=; b=iu3758logwC6nUixi6EZAbImcmCo4o1Bt9jNgkSMo9my2teGyupdPYZ7fDROgR5zRw rnqZ5K+nbzfO4pkT8g1CEhR2Cb8bteXBUceBYB58wqAcI06Barbs9+ROYzckH3vy5LgP ZfwgDlu3RVoQLv+i+GwQF3yzU8fXWXeea870VwVNPQqwkWDBkkW4ffG82Sh4anklvaII 3M6bQc1HvL8LcZyS0/5jlHL5N/6+W+DHoEhVFztY2nw6BI5J3QbA9cYGApt823OdohUu zldG9gR+QUrBwEuzF0NyJlYXXgxNvhuRLS1HfdKcn9aUyTJyWr9ows8tnebY8hQbHVht PdmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638954; x=1702243754; 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=hfYRXu2++EiNfxFS//da1r77rkXtLqsXyrHlBY61ejo=; b=ZVpbOLu2MqjLtkDgzUl4twl5CMHEVkr+NTvpF+jUyGemGGxBZMBxgf2AmwSyzLBEvj WZaGjsbFlQkdCtjHLvVytgDfHa++oiOeEwxOalUdJSckW/EPEEBv0AyNPtg7MvWo2Iwj z9yqYz/p2lq8xnmCMCRk+vcVZ319ErqFYSkFiq6N3vlLFoSzecuwKNv7sERvAq1FBG+b e53ciWi/S30b51VYfRqEUu6rUDMZnhlzPHvr0K+UI9qKv0D7lQHxn5tJ4yhnQMuSeIMG /8nWPkXjFlqgTYZb5ljB7XEqJsDcZlf+oao4lTejbLUoPtkmQPB0k5h0GZxcnVm3RJpe 02Cg== X-Gm-Message-State: AOJu0YzcjnGagF69gjMspVhQeA2ecwo56gP/b+WrGGg9JklI45UIttZu n9Vcf+JC8slb4vNqNbRCVYLt+q2emS5qcw== X-Google-Smtp-Source: AGHT+IGTUIoG/oldoqkXPVSN4FkuO9FSXrtRxBrVK0dvAhmwVvtAKvswDzyM0SAGfLauvXVhqmndzQ== X-Received: by 2002:a5b:2c7:0:b0:db4:47e1:4083 with SMTP id h7-20020a5b02c7000000b00db447e14083mr1587816ybp.5.1701638954422; Sun, 03 Dec 2023 13:29:14 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:14 -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 05/45] Add GIC-400 to BCM2838 SoC Date: Sun, 3 Dec 2023 15:28:25 -0600 Message-Id: <20231203212905.1364036-6-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-5-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b30; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb30.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838.c | 167 +++++++++++++++++++++++++++ hw/arm/trace-events | 2 + include/hw/arm/bcm2838.h | 2 + include/hw/arm/bcm2838_peripherals.h | 39 +++++++ 4 files changed, 210 insertions(+) diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c index c61c59661b..042e543006 100644 --- a/hw/arm/bcm2838.c +++ b/hw/arm/bcm2838.c @@ -14,8 +14,36 @@ #include "hw/arm/bcm2838.h" #include "trace.h" +#define GIC400_MAINTAINANCE_IRQ 9 +#define GIC400_TIMER_NS_EL2_IRQ 10 +#define GIC400_TIMER_VIRT_IRQ 11 +#define GIC400_LEGACY_FIQ 12 +#define GIC400_TIMER_S_EL1_IRQ 13 +#define GIC400_TIMER_NS_EL1_IRQ 14 +#define GIC400_LEGACY_IRQ 15 + +/* Number of external interrupt lines to configure the GIC with */ +#define GIC_NUM_IRQS 192 + +#define PPI(cpu, irq) (GIC_NUM_IRQS + (cpu) * GIC_INTERNAL + GIC_NR_SGIS + irq) + +#define GIC_BASE_OFS 0x0000 +#define GIC_DIST_OFS 0x1000 +#define GIC_CPU_OFS 0x2000 +#define GIC_VIFACE_THIS_OFS 0x4000 +#define GIC_VIFACE_OTHER_OFS(cpu) (0x5000 + (cpu) * 0x200) +#define GIC_VCPU_OFS 0x6000 + #define VIRTUAL_PMU_IRQ 7 +static void bcm2838_gic_set_irq(void *opaque, int irq, int level) +{ + BCM2838State *s = (BCM2838State *)opaque; + + trace_bcm2838_gic_set_irq(irq, level); + qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level); +} + static void bcm2838_init(Object *obj) { BCM2838State *s = BCM2838(obj); @@ -28,11 +56,14 @@ static void bcm2838_init(Object *obj) "vcram-size"); object_property_add_alias(obj, "command-line", OBJECT(&s->peripherals), "command-line"); + + object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GIC); } static void bcm2838_realize(DeviceState *dev, Error **errp) { int n; + int int_n; BCM2838State *s = BCM2838(dev); BCM283XBaseState *s_base = BCM283X_BASE(dev); BCM283XBaseClass *bc_base = BCM283X_BASE_GET_CLASS(dev); @@ -56,6 +87,13 @@ static void bcm2838_realize(DeviceState *dev, Error **errp) /* TODO: this should be converted to a property of ARM_CPU */ s_base->cpu[n].core.mp_affinity = (bc_base->clusterid << 8) | n; + /* set periphbase/CBAR value for CPU-local registers */ + if (!object_property_set_int(OBJECT(&s_base->cpu[n].core), "reset-cbar", + bc_base->ctrl_base + BCM2838_GIC_BASE, + errp)) { + return; + } + /* start powered off if not enabled */ if (!object_property_set_bool(OBJECT(&s_base->cpu[n].core), "start-powered-off", @@ -68,6 +106,135 @@ static void bcm2838_realize(DeviceState *dev, Error **errp) return; } } + + if (!object_property_set_uint(OBJECT(&s->gic), "revision", 2, errp)) { + return; + } + + if (!object_property_set_uint(OBJECT(&s->gic), "num-cpu", BCM283X_NCPUS, + errp)) { + return; + } + + if (!object_property_set_uint(OBJECT(&s->gic), "num-irq", + GIC_NUM_IRQS + GIC_INTERNAL, errp)) { + return; + } + + if (!object_property_set_bool(OBJECT(&s->gic), + "has-virtualization-extensions", true, + errp)) { + return; + } + + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) { + return; + } + + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 0, + bc_base->ctrl_base + BCM2838_GIC_BASE + GIC_DIST_OFS); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 1, + bc_base->ctrl_base + BCM2838_GIC_BASE + GIC_CPU_OFS); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 2, + bc_base->ctrl_base + BCM2838_GIC_BASE + GIC_VIFACE_THIS_OFS); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 3, + bc_base->ctrl_base + BCM2838_GIC_BASE + GIC_VCPU_OFS); + + for (n = 0; n < BCM283X_NCPUS; n++) { + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 4 + n, + bc_base->ctrl_base + BCM2838_GIC_BASE + + GIC_VIFACE_OTHER_OFS(n)); + } + + DeviceState *gicdev = DEVICE(&s->gic); + + for (n = 0; n < BCM283X_NCPUS; n++) { + DeviceState *cpudev = DEVICE(&s_base->cpu[n]); + + /* Connect the GICv2 outputs to the CPU */ + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n, + qdev_get_gpio_in(cpudev, ARM_CPU_IRQ)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + BCM283X_NCPUS, + qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 2 * BCM283X_NCPUS, + qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 3 * BCM283X_NCPUS, + qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); + + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 4 * BCM283X_NCPUS, + qdev_get_gpio_in(gicdev, + PPI(n, GIC400_MAINTAINANCE_IRQ))); + + /* Connect timers from the CPU to the interrupt controller */ + qdev_connect_gpio_out(cpudev, GTIMER_PHYS, + qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_NS_EL1_IRQ))); + qdev_connect_gpio_out(cpudev, GTIMER_VIRT, + qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_VIRT_IRQ))); + qdev_connect_gpio_out(cpudev, GTIMER_HYP, + qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_NS_EL2_IRQ))); + qdev_connect_gpio_out(cpudev, GTIMER_SEC, + qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_S_EL1_IRQ))); + /* PMU interrupt */ + qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, + qdev_get_gpio_in(gicdev, PPI(n, VIRTUAL_PMU_IRQ))); + } + + /* Connect UART0 to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->uart0), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_UART0)); + + /* Connect AUX / UART1 to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->aux), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_AUX_UART1)); + + /* Connect VC mailbox to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->mboxes), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_MBOX)); + + /* Connect SD host to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->sdhost), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_SDHOST)); + + /* According to DTS, EMMC and EMMC2 share one irq */ + DeviceState *mmc_irq_orgate = DEVICE(&ps->mmc_irq_orgate); + + /* Connect EMMC and EMMC2 to the interrupt controller */ + qdev_connect_gpio_out(mmc_irq_orgate, 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_EMMC_EMMC2)); + + /* Connect USB OTG and MPHI to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->mphi), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_MPHI)); + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->dwc2), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_DWC2)); + + /* Connect DMA 0-6 to the interrupt controller */ + for (int_n = GIC_SPI_INTERRUPT_DMA_0; int_n <= GIC_SPI_INTERRUPT_DMA_6; + int_n++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->dma), + int_n - GIC_SPI_INTERRUPT_DMA_0, + qdev_get_gpio_in(gicdev, int_n)); + } + + /* According to DTS, DMA 7 and 8 share one irq */ + DeviceState *dma_7_8_irq_orgate = DEVICE(&ps->dma_7_8_irq_orgate); + + /* Connect DMA 7-8 to the interrupt controller */ + qdev_connect_gpio_out(dma_7_8_irq_orgate, 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_DMA_7_8)); + + /* According to DTS, DMA 9 and 10 share one irq */ + DeviceState *dma_9_10_irq_orgate = DEVICE(&ps->dma_9_10_irq_orgate); + + /* Connect DMA 9-10 to the interrupt controller */ + qdev_connect_gpio_out(dma_9_10_irq_orgate, 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_DMA_9_10)); + + /* Pass through inbound GPIO lines to the GIC */ + qdev_init_gpio_in(dev, bcm2838_gic_set_irq, GIC_NUM_IRQS); + + /* Pass through outbound IRQ lines from the GIC */ + qdev_pass_gpios(DEVICE(&s->gic), DEVICE(&s->peripherals), NULL); } static void bcm2838_class_init(ObjectClass *oc, void *data) diff --git a/hw/arm/trace-events b/hw/arm/trace-events index cdc1ea06a8..4f0167e638 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -55,3 +55,5 @@ smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64 +# bcm2838.c +bcm2838_gic_set_irq(int irq, int level) "gic irq:%d lvl:%d" diff --git a/include/hw/arm/bcm2838.h b/include/hw/arm/bcm2838.h index bddc25ca9a..e53c7bedf9 100644 --- a/include/hw/arm/bcm2838.h +++ b/include/hw/arm/bcm2838.h @@ -10,6 +10,7 @@ #define BCM2838_H #include "hw/arm/bcm2836.h" +#include "hw/intc/arm_gic.h" #include "hw/arm/bcm2838_peripherals.h" #define BCM2838_PERI_LOW_BASE 0xfc000000 @@ -24,6 +25,7 @@ struct BCM2838State { BCM283XBaseState parent_obj; /*< public >*/ BCM2838PeripheralState peripherals; + GICState gic; }; #endif /* BCM2838_H */ diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 7039b67cc9..5a72355183 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -11,6 +11,41 @@ #include "hw/arm/bcm2835_peripherals.h" +#define GENET_OFFSET 0x1580000 + +/* SPI */ +#define GIC_SPI_INTERRUPT_MBOX 33 +#define GIC_SPI_INTERRUPT_MPHI 40 +#define GIC_SPI_INTERRUPT_DWC2 73 +#define GIC_SPI_INTERRUPT_DMA_0 80 +#define GIC_SPI_INTERRUPT_DMA_6 86 +#define GIC_SPI_INTERRUPT_DMA_7_8 87 +#define GIC_SPI_INTERRUPT_DMA_9_10 88 +#define GIC_SPI_INTERRUPT_AUX_UART1 93 +#define GIC_SPI_INTERRUPT_SDHOST 120 +#define GIC_SPI_INTERRUPT_UART0 121 +#define GIC_SPI_INTERRUPT_RNG200 125 +#define GIC_SPI_INTERRUPT_EMMC_EMMC2 126 +#define GIC_SPI_INTERRUPT_PCI_INT_A 143 +#define GIC_SPI_INTERRUPT_GENET_A 157 +#define GIC_SPI_INTERRUPT_GENET_B 158 + + +/* GPU (legacy) DMA interrupts */ +#define GPU_INTERRUPT_DMA0 16 +#define GPU_INTERRUPT_DMA1 17 +#define GPU_INTERRUPT_DMA2 18 +#define GPU_INTERRUPT_DMA3 19 +#define GPU_INTERRUPT_DMA4 20 +#define GPU_INTERRUPT_DMA5 21 +#define GPU_INTERRUPT_DMA6 22 +#define GPU_INTERRUPT_DMA7_8 23 +#define GPU_INTERRUPT_DMA9_10 24 +#define GPU_INTERRUPT_DMA11 25 +#define GPU_INTERRUPT_DMA12 26 +#define GPU_INTERRUPT_DMA13 27 +#define GPU_INTERRUPT_DMA14 28 +#define GPU_INTERRUPT_DMA15 31 #define TYPE_BCM2838_PERIPHERALS "bcm2838-peripherals" OBJECT_DECLARE_TYPE(BCM2838PeripheralState, BCM2838PeripheralClass, @@ -24,6 +59,10 @@ struct BCM2838PeripheralState { MemoryRegion peri_low_mr; MemoryRegion peri_low_mr_alias; MemoryRegion mphi_mr_alias; + + OrIRQState mmc_irq_orgate; + OrIRQState dma_7_8_irq_orgate; + OrIRQState dma_9_10_irq_orgate; }; struct BCM2838PeripheralClass { From patchwork Sun Dec 3 21:28:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dBQjGMrX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Vm6dhyz23mf for ; Mon, 4 Dec 2023 08:36:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2C-0001oF-AW; Sun, 03 Dec 2023 16:29:52 -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 1r9u1j-0001Pp-FN; Sun, 03 Dec 2023 16:29:24 -0500 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1c-0005ON-SQ; Sun, 03 Dec 2023 16:29:23 -0500 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-da7ea62e76cso2173129276.3; Sun, 03 Dec 2023 13:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638955; x=1702243755; 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=imxvMsz0CNvo8nrzFvIRSqzHEH+HatWQq7mvnvZiPnw=; b=dBQjGMrXttcTFsobWstrHnUCSll784ruS/URLkmxEyhDKN1jYUxur8vlckbXhG9/KX GnfHsJHxZhT0ZuqB6TEgicMQIS6bw4s+HRe9KhR8BpK6nZMHMDRo8KVFL/kOslnB3ikG ihkgBmK6JbpPPnn+Z0tIZLb1cM/F5VLO2sEEJ7Fiicr9ZbNsAqp1viX5cAAfP1/dlyXc NOjCsLtuqsxBsJVe5HsVVN032grYfbaN2FQZNStaJQ1R4vOZCSrMSbDnBXMWc3j2B/3H NWFXhIdbCU2ii9G47ciXdQsgcFgaEc7wA77rctIPsO5yeBLz6eQhgNEgjPXBlY3iuSpg cAyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638955; x=1702243755; 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=imxvMsz0CNvo8nrzFvIRSqzHEH+HatWQq7mvnvZiPnw=; b=eeC/ugvT/8uk6Ii+fktx1epMJMcylcynNoqkou3MFEvk5ina5K8nHkfVix5AFbUOyc 0ftBd/ggyttI5gu9wRR0S/vWTX9/KJzlbKGkB3KBDMcSSlkfDoChImdrJylPKBlwRw9n 6jV+VNv9azMrzTBdfK28XlDmkKylOr3vyFS4yRp4FzGQyYTy+TXI9Vu8nDuwLcwn+LkT ozQqIY/wPFJTElqqQ5cw6hcmvp5eIxqRs6MdwDBdmBoXhSa87mWADMk4oBHzuW5OGxBe CHHx4LOr7iZwbHc+/EUpoS1TpmT86MzQjDH5X6vXRBjUcIedRMaekL+2ebIVFBrJ8Gcz Q5Og== X-Gm-Message-State: AOJu0YxPOV31LMHToaXWUZckm2AJg/R1nqNfmgKVyEhHTCemrQ0RcDEJ vPyJz5FaSVCMZ7gtoA+lOfU0HER9IEN64w== X-Google-Smtp-Source: AGHT+IGL/Gn1C5t08sUfoXHsbj2y5S8/NfX8yXQ2umFwEwclnYZBzFb3mH9IAsA1QC0MS6S9gTh0Rg== X-Received: by 2002:a25:3216:0:b0:db8:357:f042 with SMTP id y22-20020a253216000000b00db80357f042mr1343890yby.127.1701638955428; Sun, 03 Dec 2023 13:29:15 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:15 -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 06/45] Add BCM2838 GPIO stub Date: Sun, 3 Dec 2023 15:28:26 -0600 Message-Id: <20231203212905.1364036-7-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-6-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2f; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838.c | 4 +- hw/gpio/bcm2838_gpio.c | 152 +++++++++++++++++++++++++++ hw/gpio/meson.build | 5 +- include/hw/arm/bcm2838_peripherals.h | 2 - include/hw/gpio/bcm2838_gpio.h | 40 +++++++ 5 files changed, 198 insertions(+), 5 deletions(-) create mode 100644 hw/gpio/bcm2838_gpio.c create mode 100644 include/hw/gpio/bcm2838_gpio.h diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c index 042e543006..8925957c6c 100644 --- a/hw/arm/bcm2838.c +++ b/hw/arm/bcm2838.c @@ -14,7 +14,7 @@ #include "hw/arm/bcm2838.h" #include "trace.h" -#define GIC400_MAINTAINANCE_IRQ 9 +#define GIC400_MAINTENANCE_IRQ 9 #define GIC400_TIMER_NS_EL2_IRQ 10 #define GIC400_TIMER_VIRT_IRQ 11 #define GIC400_LEGACY_FIQ 12 @@ -163,7 +163,7 @@ static void bcm2838_realize(DeviceState *dev, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 4 * BCM283X_NCPUS, qdev_get_gpio_in(gicdev, - PPI(n, GIC400_MAINTAINANCE_IRQ))); + PPI(n, GIC400_MAINTENANCE_IRQ))); /* Connect timers from the CPU to the interrupt controller */ qdev_connect_gpio_out(cpudev, GTIMER_PHYS, diff --git a/hw/gpio/bcm2838_gpio.c b/hw/gpio/bcm2838_gpio.c new file mode 100644 index 0000000000..15b66cb559 --- /dev/null +++ b/hw/gpio/bcm2838_gpio.c @@ -0,0 +1,152 @@ +/* + * Raspberry Pi (BCM2838) GPIO Controller + * This implementation is based on bcm2835_gpio (hw/gpio/bcm2835_gpio.c) + * + * Copyright (c) 2022 Auriga LLC + * + * Authors: + * Lotosh, Aleksey + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qapi/error.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "hw/gpio/bcm2838_gpio.h" + +#define GPFSEL0 0x00 +#define GPFSEL1 0x04 +#define GPFSEL2 0x08 +#define GPFSEL3 0x0C +#define GPFSEL4 0x10 +#define GPFSEL5 0x14 +#define GPSET0 0x1C +#define GPSET1 0x20 +#define GPCLR0 0x28 +#define GPCLR1 0x2C +#define GPLEV0 0x34 +#define GPLEV1 0x38 +#define GPEDS0 0x40 +#define GPEDS1 0x44 +#define GPREN0 0x4C +#define GPREN1 0x50 +#define GPFEN0 0x58 +#define GPFEN1 0x5C +#define GPHEN0 0x64 +#define GPHEN1 0x68 +#define GPLEN0 0x70 +#define GPLEN1 0x74 +#define GPAREN0 0x7C +#define GPAREN1 0x80 +#define GPAFEN0 0x88 +#define GPAFEN1 0x8C + +#define GPIO_PUP_PDN_CNTRL_REG0 0xE4 +#define GPIO_PUP_PDN_CNTRL_REG1 0xE8 +#define GPIO_PUP_PDN_CNTRL_REG2 0xEC +#define GPIO_PUP_PDN_CNTRL_REG3 0xF0 + +#define RESET_VAL_CNTRL_REG0 0xAAA95555; +#define RESET_VAL_CNTRL_REG1 0xA0AAAAAA; +#define RESET_VAL_CNTRL_REG2 0x50AAA95A; +#define RESET_VAL_CNTRL_REG3 0x00055555; + +#define BYTES_IN_WORD 4 + +static uint64_t bcm2838_gpio_read(void *opaque, hwaddr offset, unsigned size) +{ + uint64_t value = 0; + + qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n", + TYPE_BCM2838_GPIO, __func__, offset); + + return value; +} + +static void bcm2838_gpio_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n", + TYPE_BCM2838_GPIO, __func__, offset); +} + +static void bcm2838_gpio_reset(DeviceState *dev) +{ + BCM2838GpioState *s = BCM2838_GPIO(dev); + + s->lev0 = 0; + s->lev1 = 0; + + s->pup_cntrl_reg[0] = RESET_VAL_CNTRL_REG0; + s->pup_cntrl_reg[1] = RESET_VAL_CNTRL_REG1; + s->pup_cntrl_reg[2] = RESET_VAL_CNTRL_REG2; + s->pup_cntrl_reg[3] = RESET_VAL_CNTRL_REG3; +} + +static const MemoryRegionOps bcm2838_gpio_ops = { + .read = bcm2838_gpio_read, + .write = bcm2838_gpio_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static const VMStateDescription vmstate_bcm2838_gpio = { + .name = "bcm2838_gpio", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8_ARRAY(fsel, BCM2838GpioState, BCM2838_GPIO_NUM), + VMSTATE_UINT32(lev0, BCM2838GpioState), + VMSTATE_UINT32(lev1, BCM2838GpioState), + VMSTATE_UINT8(sd_fsel, BCM2838GpioState), + VMSTATE_UINT32_ARRAY(pup_cntrl_reg, BCM2838GpioState, + GPIO_PUP_PDN_CNTRL_NUM), + VMSTATE_END_OF_LIST() + } +}; + +static void bcm2838_gpio_init(Object *obj) +{ + BCM2838GpioState *s = BCM2838_GPIO(obj); + DeviceState *dev = DEVICE(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + + memory_region_init_io(&s->iomem, obj, &bcm2838_gpio_ops, s, + "bcm2838_gpio", BCM2838_GPIO_REGS_SIZE); + sysbus_init_mmio(sbd, &s->iomem); + qdev_init_gpio_out(dev, s->out, BCM2838_GPIO_NUM); +} + +static void bcm2838_gpio_realize(DeviceState *dev, Error **errp) +{ + /* Temporary stub. Do nothing */ +} + +static void bcm2838_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->vmsd = &vmstate_bcm2838_gpio; + dc->realize = &bcm2838_gpio_realize; + dc->reset = &bcm2838_gpio_reset; +} + +static const TypeInfo bcm2838_gpio_info = { + .name = TYPE_BCM2838_GPIO, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(BCM2838GpioState), + .instance_init = bcm2838_gpio_init, + .class_init = bcm2838_gpio_class_init, +}; + +static void bcm2838_gpio_register_types(void) +{ + type_register_static(&bcm2838_gpio_info); +} + +type_init(bcm2838_gpio_register_types) diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build index 066ea96480..8a8d03d885 100644 --- a/hw/gpio/meson.build +++ b/hw/gpio/meson.build @@ -9,6 +9,9 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c')) system_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) -system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) +system_ss.add(when: 'CONFIG_RASPI', if_true: files( + 'bcm2835_gpio.c', + 'bcm2838_gpio.c' +)) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 5a72355183..d07831753a 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -11,8 +11,6 @@ #include "hw/arm/bcm2835_peripherals.h" -#define GENET_OFFSET 0x1580000 - /* SPI */ #define GIC_SPI_INTERRUPT_MBOX 33 #define GIC_SPI_INTERRUPT_MPHI 40 diff --git a/include/hw/gpio/bcm2838_gpio.h b/include/hw/gpio/bcm2838_gpio.h new file mode 100644 index 0000000000..06d48e0c19 --- /dev/null +++ b/include/hw/gpio/bcm2838_gpio.h @@ -0,0 +1,40 @@ +/* + * Raspberry Pi (BCM2838) GPIO Controller + * This implementation is based on bcm2835_gpio (hw/gpio/bcm2835_gpio.c) + * + * Copyright (c) 2022 Auriga LLC + * + * Authors: + * Lotosh, Aleksey + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef BCM2838_GPIO_H +#define BCM2838_GPIO_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_BCM2838_GPIO "bcm2838-gpio" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GpioState, BCM2838_GPIO) + +#define BCM2838_GPIO_REGS_SIZE 0x1000 +#define BCM2838_GPIO_NUM 58 +#define GPIO_PUP_PDN_CNTRL_NUM 4 + +struct BCM2838GpioState { + SysBusDevice parent_obj; + + MemoryRegion iomem; + + + uint8_t fsel[BCM2838_GPIO_NUM]; + uint32_t lev0, lev1; + uint8_t sd_fsel; + qemu_irq out[BCM2838_GPIO_NUM]; + uint32_t pup_cntrl_reg[GPIO_PUP_PDN_CNTRL_NUM]; +}; + +#endif From patchwork Sun Dec 3 21:28:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Oah9CitJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Vs44GYz23mf for ; Mon, 4 Dec 2023 08:36:53 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1h-0001Ok-Le; Sun, 03 Dec 2023 16:29:21 -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 1r9u1f-0001NJ-Rq; Sun, 03 Dec 2023 16:29:19 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1e-0005Ot-0k; Sun, 03 Dec 2023 16:29:19 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-db3a09e96daso2128170276.3; Sun, 03 Dec 2023 13:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638956; x=1702243756; 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=ceI73nY+WORMm25Lfb079HY3yTTZKu7+HhKvNA+xgeM=; b=Oah9CitJ13UctO801oTxnEqWVER/3t97+ofgoWHYh+tGj1gaUwCboryjM/xgNi7ebG mtkMQBIkFXgOwmP0gMEATjZc3GsDE84Bn6321ysB8Gla/BRwkOExjGfpRApGUbpsX11k 5SuMad2IxoyNE8ZT9TkRWVDWGX2LI2YyYBXFG/FwVsEOBk6SzDV5vsFtiJel22VnP3Rf P9zkkhUvpQ2V3m6zKcQa1QsJ2bUZK/0zdVXvtf8WrSyEelEudThVmqijLNnlMoTYqAFp WOcUfK6w2B0fp52mlnX2xz8nL7SgpRbW2ZMgpg1/E9HAlD7zRJ+MwhrHnLqBnk8AjA7h yIZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638956; x=1702243756; 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=ceI73nY+WORMm25Lfb079HY3yTTZKu7+HhKvNA+xgeM=; b=dpRRHVDgbhWnIYCHzxBbk3XeidfAPARuB20ODlfLxIjjY5Q5PvF82GHxJyS5aWZ3ik wY7R60915MViGM+clMmcAyuf1flZmRNGrbRTySAp7LQk8eigeJElqzYK6P+B0Zv57ONa LSwzHSINuzbG1kdrwx8emYxb1hRmlItJYalMjxzw9gdeDjWRfnJ4haPS0qp77tJKYOPR oiJ+2uEw7RLp4sRnyLyjHiyuX8T0BXYRWcof5mr+MWW7Q5bgubFTdsbScKRDqAxWr4aT fIdFeqteVshBF56ltqhq7oSULA4A9KRKD/VuSRD8OcbEs0mVG3XkxKk6B4muH7jOe3p0 g8lQ== X-Gm-Message-State: AOJu0YyCN4PBugk6QVbRXolrj/NS7RMo3OfZZraQB+V7nrFRx58kIetb iuLj0CLpjsPs/mx/CDW6fw805ThX1wH49g== X-Google-Smtp-Source: AGHT+IFDTfFgsk/TnUQ2S3RLz+B/nbiLOwS4odTaOMYc6UW0LumjJZ2c/YnhnXAYgyBlMbSQUUKkyQ== X-Received: by 2002:a05:6902:1008:b0:db7:dad0:60d8 with SMTP id w8-20020a056902100800b00db7dad060d8mr2269016ybt.101.1701638956524; Sun, 03 Dec 2023 13:29:16 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:16 -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 07/45] Implement BCM2838 GPIO functionality Date: Sun, 3 Dec 2023 15:28:27 -0600 Message-Id: <20231203212905.1364036-8-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-7-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/gpio/bcm2838_gpio.c | 192 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 3 deletions(-) diff --git a/hw/gpio/bcm2838_gpio.c b/hw/gpio/bcm2838_gpio.c index 15b66cb559..51eb55b00a 100644 --- a/hw/gpio/bcm2838_gpio.c +++ b/hw/gpio/bcm2838_gpio.c @@ -19,6 +19,7 @@ #include "hw/sysbus.h" #include "migration/vmstate.h" #include "hw/gpio/bcm2838_gpio.h" +#include "hw/irq.h" #define GPFSEL0 0x00 #define GPFSEL1 0x04 @@ -57,14 +58,139 @@ #define RESET_VAL_CNTRL_REG2 0x50AAA95A; #define RESET_VAL_CNTRL_REG3 0x00055555; +#define NUM_FSELN_IN_GPFSELN 10 +#define NUM_BITS_FSELN 3 +#define MASK_FSELN 0x7 + #define BYTES_IN_WORD 4 +static uint32_t gpfsel_get(BCM2838GpioState *s, uint8_t reg) +{ + int i; + uint32_t value = 0; + for (i = 0; i < NUM_FSELN_IN_GPFSELN; i++) { + uint32_t index = NUM_FSELN_IN_GPFSELN * reg + i; + if (index < sizeof(s->fsel)) { + value |= (s->fsel[index] & MASK_FSELN) << (NUM_BITS_FSELN * i); + } + } + return value; +} + +static void gpfsel_set(BCM2838GpioState *s, uint8_t reg, uint32_t value) +{ + int i; + for (i = 0; i < NUM_FSELN_IN_GPFSELN; i++) { + uint32_t index = NUM_FSELN_IN_GPFSELN * reg + i; + if (index < sizeof(s->fsel)) { + int fsel = (value >> (NUM_BITS_FSELN * i)) & MASK_FSELN; + s->fsel[index] = fsel; + } + } +} + +static int gpfsel_is_out(BCM2838GpioState *s, int index) +{ + if (index >= 0 && index < BCM2838_GPIO_NUM) { + return s->fsel[index] == 1; + } + return 0; +} + +static void gpset(BCM2838GpioState *s, uint32_t val, uint8_t start, + uint8_t count, uint32_t *lev) +{ + uint32_t changes = val & ~*lev; + uint32_t cur = 1; + + int i; + for (i = 0; i < count; i++) { + if ((changes & cur) && (gpfsel_is_out(s, start + i))) { + qemu_set_irq(s->out[start + i], 1); + } + cur <<= 1; + } + + *lev |= val; +} + +static void gpclr(BCM2838GpioState *s, uint32_t val, uint8_t start, + uint8_t count, uint32_t *lev) +{ + uint32_t changes = val & *lev; + uint32_t cur = 1; + + int i; + for (i = 0; i < count; i++) { + if ((changes & cur) && (gpfsel_is_out(s, start + i))) { + qemu_set_irq(s->out[start + i], 0); + } + cur <<= 1; + } + + *lev &= ~val; +} + static uint64_t bcm2838_gpio_read(void *opaque, hwaddr offset, unsigned size) { + BCM2838GpioState *s = (BCM2838GpioState *)opaque; uint64_t value = 0; - qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n", - TYPE_BCM2838_GPIO, __func__, offset); + switch (offset) { + case GPFSEL0: + case GPFSEL1: + case GPFSEL2: + case GPFSEL3: + case GPFSEL4: + case GPFSEL5: + value = gpfsel_get(s, offset / BYTES_IN_WORD); + break; + case GPSET0: + case GPSET1: + case GPCLR0: + case GPCLR1: + /* Write Only */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: Attempt reading from write only" + " register. %lu will be returned. Address 0x%"HWADDR_PRIx + ", size %u\n", TYPE_BCM2838_GPIO, __func__, value, offset, + size); + break; + case GPLEV0: + value = s->lev0; + break; + case GPLEV1: + value = s->lev1; + break; + case GPEDS0: + case GPEDS1: + case GPREN0: + case GPREN1: + case GPFEN0: + case GPFEN1: + case GPHEN0: + case GPHEN1: + case GPLEN0: + case GPLEN1: + case GPAREN0: + case GPAREN1: + case GPAFEN0: + case GPAFEN1: + /* Not implemented */ + qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n", + TYPE_BCM2838_GPIO, __func__, offset); + break; + case GPIO_PUP_PDN_CNTRL_REG0: + case GPIO_PUP_PDN_CNTRL_REG1: + case GPIO_PUP_PDN_CNTRL_REG2: + case GPIO_PUP_PDN_CNTRL_REG3: + value = s->pup_cntrl_reg[(offset - GPIO_PUP_PDN_CNTRL_REG0) + / sizeof(s->pup_cntrl_reg[0])]; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: bad offset %"HWADDR_PRIx"\n", + TYPE_BCM2838_GPIO, __func__, offset); + break; + } return value; } @@ -72,14 +198,74 @@ static uint64_t bcm2838_gpio_read(void *opaque, hwaddr offset, unsigned size) static void bcm2838_gpio_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { - qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n", + BCM2838GpioState *s = (BCM2838GpioState *)opaque; + + switch (offset) { + case GPFSEL0: + case GPFSEL1: + case GPFSEL2: + case GPFSEL3: + case GPFSEL4: + case GPFSEL5: + gpfsel_set(s, offset / BYTES_IN_WORD, value); + break; + case GPSET0: + gpset(s, value, 0, 32, &s->lev0); + break; + case GPSET1: + gpset(s, value, 32, 22, &s->lev1); + break; + case GPCLR0: + gpclr(s, value, 0, 32, &s->lev0); + break; + case GPCLR1: + gpclr(s, value, 32, 22, &s->lev1); + break; + case GPLEV0: + case GPLEV1: + /* Read Only */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: Attempt writing %lu to read " + "only register. Ignored. Address 0x%"HWADDR_PRIx", size " + "%u\n", TYPE_BCM2838_GPIO, __func__, value, offset, size); + break; + case GPEDS0: + case GPEDS1: + case GPREN0: + case GPREN1: + case GPFEN0: + case GPFEN1: + case GPHEN0: + case GPHEN1: + case GPLEN0: + case GPLEN1: + case GPAREN0: + case GPAREN1: + case GPAFEN0: + case GPAFEN1: + /* Not implemented */ + qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n", + TYPE_BCM2838_GPIO, __func__, offset); + break; + case GPIO_PUP_PDN_CNTRL_REG0: + case GPIO_PUP_PDN_CNTRL_REG1: + case GPIO_PUP_PDN_CNTRL_REG2: + case GPIO_PUP_PDN_CNTRL_REG3: + s->pup_cntrl_reg[(offset - GPIO_PUP_PDN_CNTRL_REG0) + / sizeof(s->pup_cntrl_reg[0])] = value; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: %s: bad offset %"HWADDR_PRIx"\n", TYPE_BCM2838_GPIO, __func__, offset); + } + return; } static void bcm2838_gpio_reset(DeviceState *dev) { BCM2838GpioState *s = BCM2838_GPIO(dev); + memset(s->fsel, 0, sizeof(s->fsel)); + s->lev0 = 0; s->lev1 = 0; From patchwork Sun Dec 3 21:28:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=P2Giw3Tq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Lt3Jylz23n4 for ; Mon, 4 Dec 2023 08:29:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u1l-0001Qv-U3; Sun, 03 Dec 2023 16:29:26 -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 1r9u1h-0001OJ-0Y; Sun, 03 Dec 2023 16:29:21 -0500 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1f-0005PI-8M; Sun, 03 Dec 2023 16:29:20 -0500 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-db549f869a3so2176768276.1; Sun, 03 Dec 2023 13:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638957; x=1702243757; 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=GKpCBrUqkr8L/zjThyY7FG08zFIoOF+cembaEspqQBk=; b=P2Giw3TquXOnOqA4YfpNLAjCy6PubxBk5B6lLRjZjyxoeLpFanYX6O157ShEfEh62p 57TqRJmZ4KLBDkFD8JbDlKq9R4Nkxqi06m/U28no/mSktPA1xXIMIR98Yxo2kfr2/Amd k2wXXAY0L0u+tUuXLvR+cQquknDLz8aBb5SCqKlUKGgDG3QTXE2knZo/ZzA75iR7YKyV Jp05x8oG8kfakXb5k36HH9ApWcKW0L93XByr46rqkBzSR8ycV5ler8j7c9VQUwDVM7O5 yEknmysMFzYmoYaA/kO7GNa6S5Nmchp6UEaZpqOcNCxwOQFkwZ1hZAr8cfJIefzABRbX Wh4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638957; x=1702243757; 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=GKpCBrUqkr8L/zjThyY7FG08zFIoOF+cembaEspqQBk=; b=Dq+wXxc5GcMZT5+4PQZ9870SxuMdBMMXmvIOQSR6lAFNvfuc2wGNPqa/gkgnnJl4qu ecZtPQx2RB9Qrw6cXG6ZFkIoKAn1t4vsr2YUL2OHCOYX6j4dmEWxqFvjUPWhQ4AigJhK SKFdrRvqRcXn11Nx/n60H8bQY0kIMGGbLI8xfLGJHvSEfsaR2ZrGzu5JVjaiYg19AZTb bhremHyvHxxI2x+5b8UzTyljiyE0/e0VjvsjdGvQts+G5OwjPM6zG9evQ6enai9NODLZ 3OcxAArPvQOMUMQBpKD3PUxMSzGu/HFAEClAoj+M/ZEwqU/ypJ0TLvwVWDdxIZmxvnsO 9OQg== X-Gm-Message-State: AOJu0Yz4r6q6h5cNuyKen1PIJobKqA5r0ZwAeo1e1kgIg61mnU/WEF+L ZyL8FiUb+jOEu23AEvVAQ6GOblzMzWmYPQ== X-Google-Smtp-Source: AGHT+IH0qhrIWMzmo8F2snR5JFbWFEO1dINK7hEYIGU2FMPgPqIi6Dj8mv9fsUsjbK0KC9KlXhiLvQ== X-Received: by 2002:a25:d10e:0:b0:db7:dacf:eda2 with SMTP id i14-20020a25d10e000000b00db7dacfeda2mr1784076ybg.131.1701638957687; Sun, 03 Dec 2023 13:29:17 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:17 -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 08/45] Connect SD controller to BCM2838 GPIO Date: Sun, 3 Dec 2023 15:28:28 -0600 Message-Id: <20231203212905.1364036-9-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-8-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2a; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/gpio/bcm2838_gpio.c | 59 +++++++++++++++++++++++++++++++--- include/hw/gpio/bcm2838_gpio.h | 5 +++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/hw/gpio/bcm2838_gpio.c b/hw/gpio/bcm2838_gpio.c index 51eb55b00a..f166ce7959 100644 --- a/hw/gpio/bcm2838_gpio.c +++ b/hw/gpio/bcm2838_gpio.c @@ -17,9 +17,10 @@ #include "qemu/timer.h" #include "qapi/error.h" #include "hw/sysbus.h" -#include "migration/vmstate.h" +#include "hw/sd/sd.h" #include "hw/gpio/bcm2838_gpio.h" #include "hw/irq.h" +#include "migration/vmstate.h" #define GPFSEL0 0x00 #define GPFSEL1 0x04 @@ -64,6 +65,16 @@ #define BYTES_IN_WORD 4 +/* bcm,function property */ +#define BCM2838_FSEL_GPIO_IN 0 +#define BCM2838_FSEL_GPIO_OUT 1 +#define BCM2838_FSEL_ALT5 2 +#define BCM2838_FSEL_ALT4 3 +#define BCM2838_FSEL_ALT0 4 +#define BCM2838_FSEL_ALT1 5 +#define BCM2838_FSEL_ALT2 6 +#define BCM2838_FSEL_ALT3 7 + static uint32_t gpfsel_get(BCM2838GpioState *s, uint8_t reg) { int i; @@ -87,6 +98,31 @@ static void gpfsel_set(BCM2838GpioState *s, uint8_t reg, uint32_t value) s->fsel[index] = fsel; } } + + /* SD controller selection (48-53) */ + if (s->sd_fsel != BCM2838_FSEL_GPIO_IN + && (s->fsel[48] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[49] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[50] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[51] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[52] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[53] == BCM2838_FSEL_GPIO_IN) + ) { + /* SDHCI controller selected */ + sdbus_reparent_card(s->sdbus_sdhost, s->sdbus_sdhci); + s->sd_fsel = BCM2838_FSEL_GPIO_IN; + } else if (s->sd_fsel != BCM2838_FSEL_ALT0 + && (s->fsel[48] == BCM2838_FSEL_ALT0) /* SD_CLK_R */ + && (s->fsel[49] == BCM2838_FSEL_ALT0) /* SD_CMD_R */ + && (s->fsel[50] == BCM2838_FSEL_ALT0) /* SD_DATA0_R */ + && (s->fsel[51] == BCM2838_FSEL_ALT0) /* SD_DATA1_R */ + && (s->fsel[52] == BCM2838_FSEL_ALT0) /* SD_DATA2_R */ + && (s->fsel[53] == BCM2838_FSEL_ALT0) /* SD_DATA3_R */ + ) { + /* SDHost controller selected */ + sdbus_reparent_card(s->sdbus_sdhci, s->sdbus_sdhost); + s->sd_fsel = BCM2838_FSEL_ALT0; + } } static int gpfsel_is_out(BCM2838GpioState *s, int index) @@ -266,6 +302,11 @@ static void bcm2838_gpio_reset(DeviceState *dev) memset(s->fsel, 0, sizeof(s->fsel)); + s->sd_fsel = 0; + + /* SDHCI is selected by default */ + sdbus_reparent_card(&s->sdbus, s->sdbus_sdhci); + s->lev0 = 0; s->lev1 = 0; @@ -302,15 +343,25 @@ static void bcm2838_gpio_init(Object *obj) DeviceState *dev = DEVICE(obj); SysBusDevice *sbd = SYS_BUS_DEVICE(obj); - memory_region_init_io(&s->iomem, obj, &bcm2838_gpio_ops, s, - "bcm2838_gpio", BCM2838_GPIO_REGS_SIZE); + qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(s), "sd-bus"); + + memory_region_init_io( + &s->iomem, obj, + &bcm2838_gpio_ops, s, "bcm2838_gpio", BCM2838_GPIO_REGS_SIZE); sysbus_init_mmio(sbd, &s->iomem); qdev_init_gpio_out(dev, s->out, BCM2838_GPIO_NUM); } static void bcm2838_gpio_realize(DeviceState *dev, Error **errp) { - /* Temporary stub. Do nothing */ + BCM2838GpioState *s = BCM2838_GPIO(dev); + Object *obj; + + obj = object_property_get_link(OBJECT(dev), "sdbus-sdhci", &error_abort); + s->sdbus_sdhci = SD_BUS(obj); + + obj = object_property_get_link(OBJECT(dev), "sdbus-sdhost", &error_abort); + s->sdbus_sdhost = SD_BUS(obj); } static void bcm2838_gpio_class_init(ObjectClass *klass, void *data) diff --git a/include/hw/gpio/bcm2838_gpio.h b/include/hw/gpio/bcm2838_gpio.h index 06d48e0c19..f2a57a697f 100644 --- a/include/hw/gpio/bcm2838_gpio.h +++ b/include/hw/gpio/bcm2838_gpio.h @@ -14,6 +14,7 @@ #ifndef BCM2838_GPIO_H #define BCM2838_GPIO_H +#include "hw/sd/sd.h" #include "hw/sysbus.h" #include "qom/object.h" @@ -29,6 +30,10 @@ struct BCM2838GpioState { MemoryRegion iomem; + /* SDBus selector */ + SDBus sdbus; + SDBus *sdbus_sdhci; + SDBus *sdbus_sdhost; uint8_t fsel[BCM2838_GPIO_NUM]; uint32_t lev0, lev1; From patchwork Sun Dec 3 21:28:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Vh1DYlcG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0MD1Tp1z23nJ for ; Mon, 4 Dec 2023 08:30:16 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u26-0001Ux-FO; Sun, 03 Dec 2023 16:29:46 -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 1r9u1j-0001Pj-59; Sun, 03 Dec 2023 16:29:24 -0500 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1g-0005Pg-Jn; Sun, 03 Dec 2023 16:29:22 -0500 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b8b56d51a6so824937b6e.2; Sun, 03 Dec 2023 13:29:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638958; x=1702243758; 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=eUhfHOrUd6d5xBzm5sqO9HHOnia+nQ7EbvYxlC8xMp8=; b=Vh1DYlcGmw1m3Y2SwsfLpISXs02QnREHsKiIqty51yHYo4fjQQBKBaNsccIPofnJih A+mp+biwwmNzhQB54bAFgSLRVIwddYImruuSfiPZiSjjMWCfe5i8b0erONFp1LmxNWrL KWOMcrbDE4M07khynhXk7u8MmEDtDUD1D2gOWFHFMBRLyAbyeaYUYIDpszUzkAITaWI5 3O02bWnnK63WyhHAyskcgk7Wm9IrFkGKw9ANbgV6rIn8eQEHwb7N1LbsbZFzAhgzcrWb YkIWdkO6k7yun3lyLidmFMafCQ2rdtJ9U+TfFe/3IO3+Rva/I5zplAEt1fp5YWGF8eRF GEYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638958; x=1702243758; 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=eUhfHOrUd6d5xBzm5sqO9HHOnia+nQ7EbvYxlC8xMp8=; b=aEVEdMYxAYfswjC46bYOHOVmBImnnrT+RfVmJ1o6JxKR2w5f9JqbwHHvBs6GV265tG eEVNhEdryg5MkG30Db8GykXe4iedItDTxAmv4MCMCNKrKjYJpB09LzVUAduXxk+qrQlc bghVaiqzrl8VFk4FFr9N+UKfH4k9NItMhZfOkTTput/Izb1UaWAnWTmssMvpfqCNPcJw pP2cxrNzbFvqTGw8Lc4eZR/zOobNYR8nvTf3GnfHF0Bf65+/ZizmCBhcSMAeaEVdiY+q eBTJF+ITiXOz9GY8RUcdlyPl4qO8cVwfx4fk+IJDTDys7AixihMGeWIJIvlbWolD7K92 aptw== X-Gm-Message-State: AOJu0YwM2UzDKkILwpggigNF84HUIZE7R4bGuFmBKsEMnCgOpsNDC8MO RJ2puqQ+owMWCdd7/n75IvpWQO2ZmOoW0w== X-Google-Smtp-Source: AGHT+IG0JvD1dQvaEU+moRyIRBsZuf3kg5SkuXIyuumChxRO0c4ghWdL6ZG3+5x8ErUGSeVtMe8lzQ== X-Received: by 2002:a05:6808:228f:b0:3b5:a58c:cca6 with SMTP id bo15-20020a056808228f00b003b5a58ccca6mr3222400oib.3.1701638958684; Sun, 03 Dec 2023 13:29:18 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:18 -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 09/45] Add GPIO and SD to BCM2838 periph Date: Sun, 3 Dec 2023 15:28:29 -0600 Message-Id: <20231203212905.1364036-10-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-9-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=serg.oker@gmail.com; helo=mail-oi1-x230.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 140 +++++++++++++++++++++++++++ include/hw/arm/bcm2838_peripherals.h | 9 ++ 2 files changed, 149 insertions(+) diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index 06110c724f..c147b6e453 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -15,22 +15,53 @@ /* Lower peripheral base address on the VC (GPU) system bus */ #define BCM2838_VC_PERI_LOW_BASE 0x7c000000 +/* Capabilities for SD controller: no DMA, high-speed, default clocks etc. */ +#define BCM2835_SDHC_CAPAREG 0x52134b4 + static void bcm2838_peripherals_init(Object *obj) { BCM2838PeripheralState *s = BCM2838_PERIPHERALS(obj); BCM2838PeripheralClass *bc = BCM2838_PERIPHERALS_GET_CLASS(obj); + RaspiPeripheralBaseState *s_base = RASPI_PERIPHERALS_BASE(obj); /* Lower memory region for peripheral devices (exported to the Soc) */ memory_region_init(&s->peri_low_mr, obj, "bcm2838-peripherals", bc->peri_low_size); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_low_mr); + /* Extended Mass Media Controller 2 */ + object_initialize_child(obj, "emmc2", &s->emmc2, TYPE_SYSBUS_SDHCI); + + /* GPIO */ + object_initialize_child(obj, "gpio", &s->gpio, TYPE_BCM2838_GPIO); + + object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhci", + OBJECT(&s_base->sdhci.sdbus)); + object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhost", + OBJECT(&s_base->sdhost.sdbus)); + + object_initialize_child(obj, "mmc_irq_orgate", &s->mmc_irq_orgate, + TYPE_OR_IRQ); + object_property_set_int(OBJECT(&s->mmc_irq_orgate), "num-lines", 2, + &error_abort); + + object_initialize_child(obj, "dma_7_8_irq_orgate", &s->dma_7_8_irq_orgate, + TYPE_OR_IRQ); + object_property_set_int(OBJECT(&s->dma_7_8_irq_orgate), "num-lines", 2, + &error_abort); + + object_initialize_child(obj, "dma_9_10_irq_orgate", &s->dma_9_10_irq_orgate, + TYPE_OR_IRQ); + object_property_set_int(OBJECT(&s->dma_9_10_irq_orgate), "num-lines", 2, + &error_abort); } static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) { + MemoryRegion *mphi_mr; BCM2838PeripheralState *s = BCM2838_PERIPHERALS(dev); BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(dev); + int n; bcm_soc_peripherals_common_realize(dev, errp); @@ -42,6 +73,115 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) BCM2838_VC_PERI_LOW_BASE, &s->peri_low_mr_alias, 1); + /* Extended Mass Media Controller 2 */ + object_property_set_uint(OBJECT(&s->emmc2), "sd-spec-version", 3, + &error_abort); + object_property_set_uint(OBJECT(&s->emmc2), "capareg", + BCM2835_SDHC_CAPAREG, &error_abort); + object_property_set_bool(OBJECT(&s->emmc2), "pending-insert-quirk", true, + &error_abort); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->emmc2), errp)) { + return; + } + + memory_region_add_subregion( + &s_base->peri_mr, EMMC2_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->emmc2), 0)); + + /* According to DTS, EMMC and EMMC2 share one irq */ + if (!qdev_realize(DEVICE(&s->mmc_irq_orgate), NULL, errp)) { + return; + } + + DeviceState *mmc_irq_orgate = DEVICE(&s->mmc_irq_orgate); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->emmc2), 0, + qdev_get_gpio_in(mmc_irq_orgate, 0)); + + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->sdhci), 0, + qdev_get_gpio_in(mmc_irq_orgate, 1)); + + /* Connect EMMC and EMMC2 to the interrupt controller */ + qdev_connect_gpio_out(mmc_irq_orgate, 0, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + INTERRUPT_ARASANSDIO)); + + /* Connect DMA 0-6 to the interrupt controller */ + for (n = 0; n < 7; n++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), n, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + GPU_INTERRUPT_DMA0 + n)); + } + + /* According to DTS, DMA 7 and 8 share one irq */ + if (!qdev_realize(DEVICE(&s->dma_7_8_irq_orgate), NULL, errp)) { + return; + } + DeviceState *dma_7_8_irq_orgate = DEVICE(&s->dma_7_8_irq_orgate); + + /* Connect DMA 7-8 to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), 7, + qdev_get_gpio_in(dma_7_8_irq_orgate, 0)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), 8, + qdev_get_gpio_in(dma_7_8_irq_orgate, 1)); + + qdev_connect_gpio_out(dma_7_8_irq_orgate, 0, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + GPU_INTERRUPT_DMA7_8)); + + /* According to DTS, DMA 9 and 10 share one irq */ + if (!qdev_realize(DEVICE(&s->dma_9_10_irq_orgate), NULL, errp)) { + return; + } + DeviceState *dma_9_10_irq_orgate = DEVICE(&s->dma_9_10_irq_orgate); + + /* Connect DMA 9-10 to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), 9, + qdev_get_gpio_in(dma_9_10_irq_orgate, 0)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), 10, + qdev_get_gpio_in(dma_9_10_irq_orgate, 1)); + + qdev_connect_gpio_out(dma_9_10_irq_orgate, 0, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + GPU_INTERRUPT_DMA9_10)); + + /* Connect DMA 11-14 to the interrupt controller */ + for (n = 11; n < 15; n++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), n, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + GPU_INTERRUPT_DMA11 + n + - 11)); + } + + /* + * Connect DMA 15 to the interrupt controller, it is physically removed + * from other DMA channels and exclusively used by the GPU + */ + sysbus_connect_irq(SYS_BUS_DEVICE(&s_base->dma), 15, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, + GPU_INTERRUPT_DMA15)); + + /* Map MPHI to BCM2838 memory map */ + mphi_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s_base->mphi), 0); + memory_region_init_alias(&s->mphi_mr_alias, OBJECT(s), "mphi", mphi_mr, 0, + BCM2838_MPHI_SIZE); + memory_region_add_subregion(&s_base->peri_mr, BCM2838_MPHI_OFFSET, + &s->mphi_mr_alias); + + /* GPIO */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { + return; + } + memory_region_add_subregion( + &s_base->peri_mr, GPIO_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gpio), 0)); + + object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->gpio), "sd-bus"); } static void bcm2838_peripherals_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index d07831753a..0a87645e01 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -10,6 +10,8 @@ #define BCM2838_PERIPHERALS_H #include "hw/arm/bcm2835_peripherals.h" +#include "hw/sd/sdhci.h" +#include "hw/gpio/bcm2838_gpio.h" /* SPI */ #define GIC_SPI_INTERRUPT_MBOX 33 @@ -45,6 +47,9 @@ #define GPU_INTERRUPT_DMA14 28 #define GPU_INTERRUPT_DMA15 31 +#define BCM2838_MPHI_OFFSET 0xb200 +#define BCM2838_MPHI_SIZE 0x200 + #define TYPE_BCM2838_PERIPHERALS "bcm2838-peripherals" OBJECT_DECLARE_TYPE(BCM2838PeripheralState, BCM2838PeripheralClass, BCM2838_PERIPHERALS) @@ -58,6 +63,10 @@ struct BCM2838PeripheralState { MemoryRegion peri_low_mr_alias; MemoryRegion mphi_mr_alias; + SDHCIState emmc2; + UnimplementedDeviceState clkisp; + BCM2838GpioState gpio; + OrIRQState mmc_irq_orgate; OrIRQState dma_7_8_irq_orgate; OrIRQState dma_9_10_irq_orgate; From patchwork Sun Dec 3 21:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871114 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OBNaZe72; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0X15mYzz23mf for ; Mon, 4 Dec 2023 08:37:53 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2D-0001uO-8j; Sun, 03 Dec 2023 16:29:53 -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 1r9u1m-0001R8-Vx; Sun, 03 Dec 2023 16:29:27 -0500 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1h-0005Ps-7M; Sun, 03 Dec 2023 16:29:26 -0500 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5d3d5b10197so28732387b3.2; Sun, 03 Dec 2023 13:29:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638959; x=1702243759; 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=UfD0K0aibjreKo4OGd+o7D2cWSxh06lmc6TQmHfOTns=; b=OBNaZe721Zqn1RZ/WAfuLoVS2yDbJSfOhkcLdmCc2qNqvePgw1VjsjD0IwQle7FXBY Ct/bBbfFIy9O3geGiMJdW4SMBoJ4lcXWVVLrUn88oqSNusqNCpxfCfIpP+iJLiy6kLL0 1W7PP7iQ9xN4HJn7ptpUQWPrQgs7Lg27Ohg9YmH8wT7q4Oi6GnzPelh39/fpnEOWoXi3 T78O8eaS9764jMS3kOByHl/5kKlO5QejEDVhB2gksBBZ1DF1+LfI6KqleIwGtS1iNTbo 3SgxVJ8kK+WtLEVi/5v4A3LPZx4Y75peWobl1l76YjEsho9/UJziZ7DI7J8/TqPxWLgM LpcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638959; x=1702243759; 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=UfD0K0aibjreKo4OGd+o7D2cWSxh06lmc6TQmHfOTns=; b=uMXZJaT4CvmgrJCuqfvw3CvqumAekRaejJidrnyJlRf+EewpHzKwYqmuYo9v7kphAN tuki0R8gx6FsDtBag5K0nBouqp/G4z2ItpGDWN9dHM2u/A2nw55fcBtx4pUl8f/yulDO fQAXNFdkwsBJRFCRA8/ReBB7jBZFm6jJQoblpnWxBGnw8cSKrTg9XJYP1z5IGC9eonLL CwQW1M8vv95m9HAh7Ub9GgzRqZEXKDB3djWH0zlPfQdXU55IBiKIT+zWFgaNkKckq1TS R378U9Weras1XNLDnQTresoSyrHDKZPTlXJk78VHdlu1WCJ7kNpgnR2uAVZXqqj9bzOF HcrA== X-Gm-Message-State: AOJu0YziUAdK/IuvdBaUjrOA4SuCLlrIdyQziYMqCnj73uor6LRMcpnp 29uuR5E/SmK6idLe8hgHyHA9D3UNZxmI+A== X-Google-Smtp-Source: AGHT+IGkE8/VRs/Wj4mHXt8H5ZY+WcihPqz0qbwPu8WTMatpihzLAxZ72UE6P37e2cdyuqMxfEoi1Q== X-Received: by 2002:a25:8446:0:b0:db5:4586:c210 with SMTP id r6-20020a258446000000b00db54586c210mr1688355ybm.16.1701638959624; Sun, 03 Dec 2023 13:29:19 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:19 -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 10/45] Add BCM2838 checkpoint support Date: Sun, 3 Dec 2023 15:28:30 -0600 Message-Id: <20231203212905.1364036-11-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-10-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1134; envelope-from=serg.oker@gmail.com; helo=mail-yw1-x1134.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index c147b6e453..196fb890a2 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -22,7 +22,7 @@ static void bcm2838_peripherals_init(Object *obj) { BCM2838PeripheralState *s = BCM2838_PERIPHERALS(obj); BCM2838PeripheralClass *bc = BCM2838_PERIPHERALS_GET_CLASS(obj); - RaspiPeripheralBaseState *s_base = RASPI_PERIPHERALS_BASE(obj); + BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(obj); /* Lower memory region for peripheral devices (exported to the Soc) */ memory_region_init(&s->peri_low_mr, obj, "bcm2838-peripherals", From patchwork Sun Dec 3 21:28:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YRjzkg1m; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Qb5xTjz23nJ for ; Mon, 4 Dec 2023 08:33:11 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2E-0001zu-IP; Sun, 03 Dec 2023 16:29:54 -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 1r9u1m-0001R4-A6; Sun, 03 Dec 2023 16:29:26 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1j-0005Q9-9D; Sun, 03 Dec 2023 16:29:25 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-db4422fff15so1575133276.1; Sun, 03 Dec 2023 13:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638960; x=1702243760; 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=Mb+gBOAGJHmc0xq2NNLfwE4TknnwiidC5qQtn1CrDao=; b=YRjzkg1mV8ML7lQLQ9N2SkA0v2N2D5UuKESXGcHs6UW/AW7scfDknU94IMzO9el/6C lrVLuxp8YJkZRcIXlw5U+9QMI2xzhheeyScWiBOYZNzn9gQ/jKpXVEMIo97OVE8aRU5J tm7b7A316SC9+dyQgv+jGbjyJMYwuw6PzD0MqVhIzlans8UwL8buPVsYvLi/cKqP9DfQ t+515waCs2e2TMHt9U/yVkj6lZscKzE7L/hnR1iIblbjgAiKTBaZ7GLKChhDjUL9goZD jfjmy4j6AfrvP7JTM+4fEKZnbhSvNC+/uSBrhVyu+1oaS6EUx3gzlMdDp1YredSQa2np PCCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638960; x=1702243760; 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=Mb+gBOAGJHmc0xq2NNLfwE4TknnwiidC5qQtn1CrDao=; b=DyMW8IM+TbZb5s5hixdlx1uPOSbXlXjFbnOPPM8UdHp1j0XczYOd1gbbk3jeNhw4wY DjsPb+O74IB6kSKpVFx998QA6JmxqpKr950mBrWo65IY9Psw7BTMo+82t0IavzdlIvdO Y1TIOYGM751OWbkwUgwNTjB8CpJAkH81N9vc9tLq1spSs46jPjf+qJbyvuyzsPmwnH28 OEDJ1wh/XlAjVeXwFnpTQTnVCrYa3ZOnxKZIoeSarqH8jmTTP7oRxF73DiPjix9qhACO KM+WIcNZ7S6Z0DnCpKdT9kD+d8awoX7mRzIJI44bqEAWpLJ7UYu+emG8e1LwvubK31OI PXBg== X-Gm-Message-State: AOJu0YyWkQTdvdUPPs9i5lMxeHBEcqo4gvh4YkbuGW3cZI8GZG8Ojri/ U7Kc5SPYBtdWAv4FkLApaH6JTqQ3WAm7tw== X-Google-Smtp-Source: AGHT+IGazyBuuZjhDYkeAVfl+SE9eAD3Lm/FprZIt1+hOP/nYZSZo4o/0BHTiWo3Cmk1pP4Ec2uorw== X-Received: by 2002:a25:f414:0:b0:db7:dad0:76b1 with SMTP id q20-20020a25f414000000b00db7dad076b1mr1218770ybd.77.1701638960634; Sun, 03 Dec 2023 13:29:20 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:20 -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 11/45] Introduce Raspberry PI 4 machine Date: Sun, 3 Dec 2023 15:28:31 -0600 Message-Id: <20231203212905.1364036-12-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-11-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2835_peripherals.c | 20 +++++++-- hw/arm/bcm2836.c | 2 + hw/arm/bcm2838.c | 2 + hw/arm/meson.build | 2 +- hw/arm/raspi.c | 28 ++++++++----- hw/arm/raspi4b.c | 72 +++++++++++++++++++++++++++++++++ include/hw/arm/raspi_platform.h | 11 +++++ include/hw/display/bcm2835_fb.h | 2 + 8 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 hw/arm/raspi4b.c diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index fd70cde123..ae8117961e 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -108,6 +108,7 @@ static void raspi_peripherals_base_init(Object *obj) /* Framebuffer */ object_initialize_child(obj, "fb", &s->fb, TYPE_BCM2835_FB); object_property_add_alias(obj, "vcram-size", OBJECT(&s->fb), "vcram-size"); + object_property_add_alias(obj, "vcram-base", OBJECT(&s->fb), "vcram-base"); object_property_add_const_link(OBJECT(&s->fb), "dma-mr", OBJECT(&s->gpu_bus_mr)); @@ -225,7 +226,7 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp) Object *obj; MemoryRegion *ram; Error *err = NULL; - uint64_t ram_size, vcram_size; + uint64_t ram_size, vcram_size, vcram_base; int n; obj = object_property_get_link(OBJECT(dev), "ram", &error_abort); @@ -329,11 +330,24 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp) return; } - if (!object_property_set_uint(OBJECT(&s->fb), "vcram-base", - ram_size - vcram_size, errp)) { + vcram_base = object_property_get_uint(OBJECT(s), "vcram-base", &err); + if (err) { + error_propagate(errp, err); return; } + if (vcram_base == 0) { + vcram_base = (ram_size > UPPER_RAM_BASE ? UPPER_RAM_BASE : ram_size) + - vcram_size; + } else { + if (vcram_base + vcram_size > UPPER_RAM_BASE) { + vcram_base = UPPER_RAM_BASE - vcram_size; + } + } + if (!object_property_set_uint(OBJECT(&s->fb), "vcram-base", vcram_base, + errp)) { + return; + } if (!sysbus_realize(SYS_BUS_DEVICE(&s->fb), errp)) { return; } diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c index 18675c896c..ee890f3d35 100644 --- a/hw/arm/bcm2836.c +++ b/hw/arm/bcm2836.c @@ -64,6 +64,8 @@ static void bcm283x_init(Object *obj) "command-line"); object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals), "vcram-size"); + object_property_add_alias(obj, "vcram-base", OBJECT(&s->peripherals), + "vcram-base"); } bool bcm283x_common_realize(DeviceState *dev, BCMSocPeripheralBaseState *ps, diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c index 8925957c6c..89cd9d5d8c 100644 --- a/hw/arm/bcm2838.c +++ b/hw/arm/bcm2838.c @@ -54,6 +54,8 @@ static void bcm2838_init(Object *obj) "board-rev"); object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals), "vcram-size"); + object_property_add_alias(obj, "vcram-base", OBJECT(&s->peripherals), + "vcram-base"); object_property_add_alias(obj, "command-line", OBJECT(&s->peripherals), "command-line"); diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 551ab6abf5..27e6797de2 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -39,7 +39,7 @@ arm_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10.c', 'cubi arm_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3.c', 'orangepi.c')) arm_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bananapi_m2u.c')) arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c')) -arm_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files('bcm2838.c')) +arm_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files('bcm2838.c', 'raspi4b.c')) arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c')) arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c')) arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c')) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 7d04734cd2..da1e9e7c13 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "hw/arm/boot.h" #include "hw/arm/bcm2836.h" +#include "hw/arm/bcm2838.h" #include "hw/arm/raspi_platform.h" #include "hw/registerfields.h" #include "qemu/error-report.h" @@ -61,6 +62,7 @@ typedef enum RaspiProcessorId { PROCESSOR_ID_BCM2835 = 0, PROCESSOR_ID_BCM2836 = 1, PROCESSOR_ID_BCM2837 = 2, + PROCESSOR_ID_BCM2838 = 3, } RaspiProcessorId; static const struct { @@ -70,13 +72,9 @@ static const struct { [PROCESSOR_ID_BCM2835] = {TYPE_BCM2835, 1}, [PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, + [PROCESSOR_ID_BCM2838] = {TYPE_BCM2838, BCM283X_NCPUS}, }; -static void raspi_base_machine_init(MachineState *machine, - BCM283XBaseState *soc); -static void raspi_machine_class_common_init(MachineClass *mc, - uint32_t board_rev); - static uint64_t board_ram_size(uint32_t board_rev) { assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ @@ -93,7 +91,7 @@ static RaspiProcessorId board_processor_id(uint32_t board_rev) return proc_id; } -static const char *board_soc_type(uint32_t board_rev) +const char *board_soc_type(uint32_t board_rev) { return soc_property[board_processor_id(board_rev)].type; } @@ -248,13 +246,14 @@ static void setup_boot(MachineState *machine, ARMCPU *cpu, arm_load_kernel(cpu, machine, &s->binfo); } -static void raspi_base_machine_init(MachineState *machine, +void raspi_base_machine_init(MachineState *machine, BCM283XBaseState *soc) { RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine); uint32_t board_rev = mc->board_rev; uint64_t ram_size = board_ram_size(board_rev); - uint32_t vcram_size; + uint32_t vcram_base, vcram_size; + size_t boot_ram_size; DriveInfo *di; BlockBackend *blk; BusState *bus; @@ -293,11 +292,20 @@ static void raspi_base_machine_init(MachineState *machine, vcram_size = object_property_get_uint(OBJECT(soc), "vcram-size", &error_abort); + vcram_base = object_property_get_uint(OBJECT(soc), "vcram-base", + &error_abort); + if (!vcram_base) { + boot_ram_size = (ram_size > UPPER_RAM_BASE ? UPPER_RAM_BASE : ram_size) + - vcram_size; + } else { + boot_ram_size = (vcram_base + vcram_size > UPPER_RAM_BASE ? + UPPER_RAM_BASE - vcram_size : vcram_base); + } setup_boot(machine, &soc->cpu[0].core, board_processor_id(board_rev), - machine->ram_size - vcram_size); + boot_ram_size); } -static void raspi_machine_init(MachineState *machine) +void raspi_machine_init(MachineState *machine) { RaspiMachineState *s = RASPI_MACHINE(machine); RaspiBaseMachineState *s_base = RASPI_BASE_MACHINE(machine); diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c new file mode 100644 index 0000000000..2d33861c57 --- /dev/null +++ b/hw/arm/raspi4b.c @@ -0,0 +1,72 @@ +/* + * Raspberry Pi 4B emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/cutils.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "hw/arm/raspi_platform.h" +#include "hw/display/bcm2835_fb.h" +#include "hw/registerfields.h" +#include "qemu/error-report.h" +#include "sysemu/device_tree.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "hw/arm/boot.h" +#include "qom/object.h" +#include "hw/arm/bcm2838.h" + +#define TYPE_RASPI4B_MACHINE MACHINE_TYPE_NAME("raspi4b-2g") +OBJECT_DECLARE_SIMPLE_TYPE(Raspi4bMachineState, RASPI4B_MACHINE) + +struct Raspi4bMachineState { + /*< private >*/ + RaspiBaseMachineState parent_obj; + /*< public >*/ + BCM2838State soc; +}; + +static void raspi4b_machine_init(MachineState *machine) +{ + Raspi4bMachineState *s = RASPI4B_MACHINE(machine); + RaspiBaseMachineState *s_base = RASPI_BASE_MACHINE(machine); + RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine); + BCM2838State *soc = &s->soc; + + s_base->binfo.board_id = mc->board_rev; + + object_initialize_child(OBJECT(machine), "soc", soc, + board_soc_type(mc->board_rev)); + + raspi_base_machine_init(machine, &soc->parent_obj); +} + +static void raspi4b_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc); + + rmc->board_rev = 0xb03115; /* Revision 1.5, 2 Gb RAM */ + raspi_machine_class_common_init(mc, rmc->board_rev); + mc->init = raspi4b_machine_init; +} + +static const TypeInfo raspi4b_machine_type = { + .name = TYPE_RASPI4B_MACHINE, + .parent = TYPE_RASPI_BASE_MACHINE, + .instance_size = sizeof(Raspi4bMachineState), + .class_init = raspi4b_machine_class_init, +}; + +static void raspi4b_machine_register_type(void) +{ + type_register_static(&raspi4b_machine_type); +} + +type_init(raspi4b_machine_register_type) diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h index 3018e8fcf3..45003e2425 100644 --- a/include/hw/arm/raspi_platform.h +++ b/include/hw/arm/raspi_platform.h @@ -49,6 +49,17 @@ struct RaspiBaseMachineClass { uint32_t board_rev; }; +/* Common functions for raspberry pi machines */ +const char *board_soc_type(uint32_t board_rev); +void raspi_machine_init(MachineState *machine); + +typedef struct BCM283XBaseState BCM283XBaseState; +void raspi_base_machine_init(MachineState *machine, + BCM283XBaseState *soc); + +void raspi_machine_class_common_init(MachineClass *mc, + uint32_t board_rev); + #define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */ #define CCPT_OFFSET 0x1000 /* Compact Camera Port 2 TX */ #define INTE_OFFSET 0x2000 /* VC Interrupt controller */ diff --git a/include/hw/display/bcm2835_fb.h b/include/hw/display/bcm2835_fb.h index 38671afffd..49541bf08f 100644 --- a/include/hw/display/bcm2835_fb.h +++ b/include/hw/display/bcm2835_fb.h @@ -16,6 +16,8 @@ #include "ui/console.h" #include "qom/object.h" +#define UPPER_RAM_BASE 0x40000000 + #define TYPE_BCM2835_FB "bcm2835-fb" OBJECT_DECLARE_SIMPLE_TYPE(BCM2835FBState, BCM2835_FB) From patchwork Sun Dec 3 21:28:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OX8bAMhP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0W56jTcz23n4 for ; Mon, 4 Dec 2023 08:37:05 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2K-0002GO-DJ; Sun, 03 Dec 2023 16:30:00 -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 1r9u1o-0001RU-7G; Sun, 03 Dec 2023 16:29:30 -0500 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1k-0005QI-Dp; Sun, 03 Dec 2023 16:29:27 -0500 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b8b4670c78so930730b6e.1; Sun, 03 Dec 2023 13:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638961; x=1702243761; 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=Wmi1AJ5sdVkVMe4G4xOT7WMN2sIuUaWUGckgKMqr68s=; b=OX8bAMhP1Eb7F7P+Cu40g/cbrJxMm+Gnxble+hzlKnumOBeK1oeLrVO4NrmQAlgdny WWPf4KvSJ28OHyBQXpHlqyENMyyONg+QFJ7Y0ZPx1tAYtVIQCiq9Hb5RxuIKwtXbKN4q xLBhk7bp47PEYllh1d9JH42qz/MCh2GtGCflXaH4Bi2dY4/q2ZNJZ8o1mK5rk2APcMr2 oqjrSDKzxE6K9v5Wa3YMCdOHIreOUMw6RF2QeaqBMLrVurRGElPxyJZYVofx1puX9je+ jD6cxarZj5YxtexdlL6rLPBx650uBh6pn9gUkvnJEpAlUdmMixrOJUXiPzvAPxUFTLO+ rkvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638961; x=1702243761; 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=Wmi1AJ5sdVkVMe4G4xOT7WMN2sIuUaWUGckgKMqr68s=; b=EeA/DOMmN1TvABwG7NaUx8C9hRhwSM3LvXPRwlC8FtnlWh36b4CbXLB+dL3EjiOVAc KHlSCrXhkhqOGJxvWvHlSMh5uCGh0+u2oRfJF7wzQcxsxscLyvoLQ2nR6gsI5rE9I8p7 eZ52Pe7lXtSYvHBvzuAT6m585ZGHhZQRwdyKGSvgdDLaox+wOsx+Itm83N7oqDZkHBT7 gOhrm5Czesni6mH+4frp6chgzOwxHlzsgh/kA3eFqSubPncMu2kg8wzqkXd/iHgiVIBu 4hwsL8YFfqJyXRNIblZ4Ak+TtnphJW7tovBw1ozH1/gUpvliDBDNy0kB7is81k9WzbEb Bnew== X-Gm-Message-State: AOJu0YwPEh8uNubsYKefsOg6GVtc+NpzJePRuBYA7+mweBZAHZoWKMTH rvHfRNnnkcXtf5XV555E7CbRBnPNptAQYg== X-Google-Smtp-Source: AGHT+IGtRc4yC4yqWtlXX1kySSNWJfK13e4te+VxafAsfnl/A+e/ReCVCC17KHgR9scDcSOlvCECXw== X-Received: by 2002:a05:6808:ecb:b0:3b8:3ea1:1cec with SMTP id q11-20020a0568080ecb00b003b83ea11cecmr2974750oiv.50.1701638961600; Sun, 03 Dec 2023 13:29:21 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:21 -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 12/45] Temporarily disable unimplemented rpi4b devices Date: Sun, 3 Dec 2023 15:28:32 -0600 Message-Id: <20231203212905.1364036-13-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-12-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=serg.oker@gmail.com; helo=mail-oi1-x236.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This commit adds RPi4B device tree modifications: - disable pcie, rng200, thermal sensor and genet devices (they're going to be re-enabled in the following commits) - create additional memory region in device tree if RAM amount exceeds VC base address. Signed-off-by: Sergey Kambalin --- hw/arm/raspi.c | 5 +-- hw/arm/raspi4b.c | 60 +++++++++++++++++++++++++++++++++ include/hw/arm/raspi_platform.h | 4 +++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index da1e9e7c13..895c305122 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -37,9 +37,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE) #define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ -/* Registered machine type (matches RPi Foundation bootloader and U-Boot) */ -#define MACH_TYPE_BCM2708 3138 - struct RaspiMachineState { /*< private >*/ RaspiBaseMachineState parent_obj; @@ -75,7 +72,7 @@ static const struct { [PROCESSOR_ID_BCM2838] = {TYPE_BCM2838, BCM283X_NCPUS}, }; -static uint64_t board_ram_size(uint32_t board_rev) +uint64_t board_ram_size(uint32_t board_rev) { assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ return 256 * MiB << FIELD_EX32(board_rev, REV_CODE, MEMORY_SIZE); diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c index 2d33861c57..10376b62dc 100644 --- a/hw/arm/raspi4b.c +++ b/hw/arm/raspi4b.c @@ -21,6 +21,7 @@ #include "hw/arm/boot.h" #include "qom/object.h" #include "hw/arm/bcm2838.h" +#include #define TYPE_RASPI4B_MACHINE MACHINE_TYPE_NAME("raspi4b-2g") OBJECT_DECLARE_SIMPLE_TYPE(Raspi4bMachineState, RASPI4B_MACHINE) @@ -32,6 +33,64 @@ struct Raspi4bMachineState { BCM2838State soc; }; +/* Add second memory region if board RAM amount exceeds VC base address + * (see https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf + * 1.2 Address Map) + */ +static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) +{ + int ret; + uint32_t acells, scells; + char *nodename = g_strdup_printf("/memory@%" PRIx64, mem_base); + + acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells", + NULL, &error_fatal); + scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells", + NULL, &error_fatal); + if (acells == 0 || scells == 0) { + fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n"); + ret = -1; + } else { + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory"); + ret = qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", + acells, mem_base, + scells, mem_len); + } + + g_free(nodename); + return ret; +} + +static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt) +{ + + /* Temporarily disable following devices until they are implemented*/ + const char *to_be_removed_from_dt_as_wa[] = { + "brcm,bcm2711-pcie", + "brcm,bcm2711-rng200", + "brcm,bcm2711-thermal", + "brcm,bcm2711-genet-v5", + }; + + for (int i = 0; i < ARRAY_SIZE(to_be_removed_from_dt_as_wa); i++) { + const char *dev_str = to_be_removed_from_dt_as_wa[i]; + + int offset = fdt_node_offset_by_compatible(fdt, -1, dev_str); + if (offset >= 0) { + if (!fdt_nop_node(fdt, offset)) { + warn_report("bcm2711 dtc: %s has been disabled!", dev_str); + } + } + } + + uint64_t ram_size = board_ram_size(info->board_id); + + if (info->ram_size > UPPER_RAM_BASE) { + raspi_add_memory_node(fdt, UPPER_RAM_BASE, ram_size - UPPER_RAM_BASE); + } +} + static void raspi4b_machine_init(MachineState *machine) { Raspi4bMachineState *s = RASPI4B_MACHINE(machine); @@ -39,6 +98,7 @@ static void raspi4b_machine_init(MachineState *machine) RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine); BCM2838State *soc = &s->soc; + s_base->binfo.modify_dtb = raspi4_modify_dtb; s_base->binfo.board_id = mc->board_rev; object_initialize_child(OBJECT(machine), "soc", soc, diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h index 45003e2425..0db146e592 100644 --- a/include/hw/arm/raspi_platform.h +++ b/include/hw/arm/raspi_platform.h @@ -31,6 +31,9 @@ #include "hw/boards.h" #include "hw/arm/boot.h" +/* Registered machine type (matches RPi Foundation bootloader and U-Boot) */ +#define MACH_TYPE_BCM2708 3138 + #define TYPE_RASPI_BASE_MACHINE MACHINE_TYPE_NAME("raspi-base") OBJECT_DECLARE_TYPE(RaspiBaseMachineState, RaspiBaseMachineClass, RASPI_BASE_MACHINE) @@ -59,6 +62,7 @@ void raspi_base_machine_init(MachineState *machine, void raspi_machine_class_common_init(MachineClass *mc, uint32_t board_rev); +uint64_t board_ram_size(uint32_t board_rev); #define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */ #define CCPT_OFFSET 0x1000 /* Compact Camera Port 2 TX */ From patchwork Sun Dec 3 21:28:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=m1mbg05D; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Qc5fXkz23p4 for ; Mon, 4 Dec 2023 08:33:12 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2G-00026u-48; Sun, 03 Dec 2023 16:29:56 -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 1r9u1n-0001RH-BQ; Sun, 03 Dec 2023 16:29:27 -0500 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1k-0005Qu-De; Sun, 03 Dec 2023 16:29:27 -0500 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-da41acaea52so2056732276.3; Sun, 03 Dec 2023 13:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638962; x=1702243762; 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=fVH9O9un+zwSeBPQSL0IeMDZWUWBtxU0cSyYzIJS41g=; b=m1mbg05DqHhpzuq1Kzak32tVcM7hSOa4g3HZ6QxlhlLeCVmG6Va4iJM1YugbbMOPxm TXjfzR6gkAWOTVxuV4LmZ04X3P28FA8KG/WHl39rzLtJFcVPLG7blsSG0sKRX8zkLlRc b7PcPiLyONEXuSsvrgQZNMdNRcwwkO5dDQJ+bywVRgMCx6xsCbIYY/gNAvAaHv5EZoo2 +pOx24m460vtzreGvSL75Mp+IGG6KZtZa/UKiliJ4vXGMi4Wqm5bLrUZr6xwef7mhG1Z EvCTVCm7EZ9Y0zMWD8H8QW2Pnr0qMgU/LhOTFez4rQOxEz8GGrNfoxmUFTP7dDpiMgRi 1BpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638962; x=1702243762; 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=fVH9O9un+zwSeBPQSL0IeMDZWUWBtxU0cSyYzIJS41g=; b=ErGp4LdOz41M5lbVkQmoRFTauNb4T8JJK6SlKGZlcVxXkeGCzkdVQ6YI3LhOS+Op1f YiCAjzmkNz+Ei9zG2sBwLHJzy9GMUpkw/MYT06eVZBsoVsvn+6JTUhwfp+Bf7RdZ2owR 5QcesFa25m1o/qBzTIPY3Tfmsl7GJAp3o7mjueD1/pgyLTmoaH4DTh58lwiWW9u33OjR OBH91Z4VwOq38bf0V6VVfrRZPcAg4TIn7rfoWiPxojquHmtWtQjTqTvR9oOdgisPuCxA URBmTd9iTFAPWnnOAIgltwDQv909ui6wxSS0kV4ggDbwixl5DFM9yKjJApx4m/eOfyDO Lq4g== X-Gm-Message-State: AOJu0YyqZk7MDHKZ076qSrvVdG3k7+vrb3YIzRrBVu02PR7JnI0OmS1i 683uvQ4ybZeSHJN3O94dYr6faVhopPjCSw== X-Google-Smtp-Source: AGHT+IGJkEoXyYSNQk8YBFhKcgSjICdPhBXSBuXj82XV1e4XIfy/9vF5pUaafVEBnG2GpudoWoOvfw== X-Received: by 2002:a25:908c:0:b0:db7:dacf:3fb1 with SMTP id t12-20020a25908c000000b00db7dacf3fb1mr1697054ybl.94.1701638962729; Sun, 03 Dec 2023 13:29:22 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:22 -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 13/45] Add memory region for BCM2837 RPiVid ASB Date: Sun, 3 Dec 2023 15:28:33 -0600 Message-Id: <20231203212905.1364036-14-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-13-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b32; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb32.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 3 +++ include/hw/arm/bcm2838_peripherals.h | 3 ++- include/hw/arm/raspi_platform.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index 196fb890a2..d3b42cf25b 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -182,6 +182,9 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gpio), 0)); object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->gpio), "sd-bus"); + + /* BCM2838 RPiVid ASB must be mapped to prevent kernel crash */ + create_unimp(s_base, &s->asb, "bcm2838-asb", RPI4B_ASB_OFFSET, 0x24); } static void bcm2838_peripherals_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 0a87645e01..af085934c9 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -64,12 +64,13 @@ struct BCM2838PeripheralState { MemoryRegion mphi_mr_alias; SDHCIState emmc2; - UnimplementedDeviceState clkisp; BCM2838GpioState gpio; OrIRQState mmc_irq_orgate; OrIRQState dma_7_8_irq_orgate; OrIRQState dma_9_10_irq_orgate; + + UnimplementedDeviceState asb; }; struct BCM2838PeripheralClass { diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h index 0db146e592..537fc6b4af 100644 --- a/include/hw/arm/raspi_platform.h +++ b/include/hw/arm/raspi_platform.h @@ -74,6 +74,7 @@ uint64_t board_ram_size(uint32_t board_rev); #define DMA_OFFSET 0x7000 /* DMA controller, channels 0-14 */ #define ARBA_OFFSET 0x9000 #define BRDG_OFFSET 0xa000 +#define RPI4B_ASB_OFFSET 0xa000 /* BCM2838 (BCM2711) RPiVid ASB */ #define ARM_OFFSET 0xB000 /* ARM control block */ #define ARMCTRL_OFFSET (ARM_OFFSET + 0x000) #define ARMCTRL_IC_OFFSET (ARM_OFFSET + 0x200) /* Interrupt controller */ From patchwork Sun Dec 3 21:28:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jCM9s7RT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0RW03K6z23nJ for ; Mon, 4 Dec 2023 08:33:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2J-0002F3-SY; Sun, 03 Dec 2023 16:29:59 -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 1r9u1p-0001Rv-1h; Sun, 03 Dec 2023 16:29:32 -0500 Received: from mail-yb1-xb33.google.com ([2607:f8b0:4864:20::b33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1m-0005R6-1H; Sun, 03 Dec 2023 16:29:28 -0500 Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-db54611b920so1855756276.3; Sun, 03 Dec 2023 13:29:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638963; x=1702243763; 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=wFeuloyQQG/pWB1qNvNMADuHoBFz7/WggqgaHUnwlWg=; b=jCM9s7RTS6dvqib1J7J/MH0JWT7i+0VqUf/05lD81b4rEqgoOAWxxJbV/rlxCMSkr3 awf9fAyriUWCYGbx/TPVq+8yDAo/rIOLuCNZmd3KmugToM50Bm7k9w6LLFxTMeEQCiVO F8oZXvf4cjxdmrS/GK1V3Yf5pM5Z8KHvgpCu90msVserHWHrr0SU1R41TeKdFxkRsMGs 2mJmGnbn+K3HhXrOlc+a9/B9+Qa4UYK28ISQdsLwQNsage2K37im30eYVhyuYbGjcqzF 9FZgMLm7e2/z+K9+aizjx8TUsjzDEPjoZugr/yotBoRq9d2UpfqWjcae2kmhIWOkIgca GtMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638963; x=1702243763; 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=wFeuloyQQG/pWB1qNvNMADuHoBFz7/WggqgaHUnwlWg=; b=lVUnrrpQOv8cLeJbY2vFWE9mdxxjutd9MI/kl2BOScIKfIiahY9I5xbvMsWlF4zxUw alrHtJxAgThuhChjmo+9nuey8GchY1vEAUWUy5wVge1dqDxBLKWCY6s4EEcnG16Ve9GZ BFjeoLNF3k3mptacMcFw7zAKkn6o+1qVHTiMn07suqjEKBLorEh3giNZoNN3sD7oe5Gf xenBSPbGAwrmnKBZdcdDm7NLPVhoUcN/0gHyOQx+ksonBthaN73XjniDjma9feQb3nOJ Y6Otdyd1y300WKVTnlsedb9YcJDLwq3Oxf2t6WaZQlXfTBgorOGvzqMlMnPyMJHxYJKj vNzw== X-Gm-Message-State: AOJu0Yx9lQFqhTRdYKz30+TpNk8IHcubgZ/eoltzCmpJg5lA3jFKyRZe oyTi6E9OMTBk2O7hWDKLNO+/LO3b8TthRA== X-Google-Smtp-Source: AGHT+IEYQPqxoI3MWN/A3bdT4agtNue02rDfHkMSCNeNldqXsBsiLWVbGX+zvLJTJGfDKS24XialHg== X-Received: by 2002:a25:d803:0:b0:db7:dacf:2f10 with SMTP id p3-20020a25d803000000b00db7dacf2f10mr1524049ybg.87.1701638963674; Sun, 03 Dec 2023 13:29:23 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:23 -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 14/45] Add BCM2838 PCIE Root Complex Date: Sun, 3 Dec 2023 15:28:34 -0600 Message-Id: <20231203212905.1364036-15-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-14-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b33; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb33.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_pcie.c | 74 +++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 5 ++- hw/arm/trace-events | 4 ++ include/hw/arm/bcm2838_pcie.h | 53 +++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 hw/arm/bcm2838_pcie.c create mode 100644 include/hw/arm/bcm2838_pcie.h diff --git a/hw/arm/bcm2838_pcie.c b/hw/arm/bcm2838_pcie.c new file mode 100644 index 0000000000..3b4373c6a6 --- /dev/null +++ b/hw/arm/bcm2838_pcie.c @@ -0,0 +1,74 @@ +/* + * BCM2838 PCIe Root Complex emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "hw/irq.h" +#include "hw/pci-host/gpex.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "qemu/module.h" +#include "hw/arm/bcm2838_pcie.h" +#include "trace.h" + +/* + * RC root part (D0:F0) + */ + +static void bcm2838_pcie_root_reg_reset(PCIDevice *dev) +{ + BCM2838PcieRootState *s = BCM2838_PCIE_ROOT(dev); + memset(s->regs, 0xFF, sizeof(s->regs)); +} + +static void bcm2838_pcie_root_realize(PCIDevice *dev, Error **errp) { + bcm2838_pcie_root_reg_reset(dev); +} + +static void bcm2838_pcie_root_init(Object *obj) +{ + PCIBridge *br = PCI_BRIDGE(obj); + br->bus_name = "pcie.1"; +} + +static void bcm2838_pcie_root_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(class); + PCIDeviceClass *k = PCI_DEVICE_CLASS(class); + BCM2838PcieRootClass *brpc = BCM2838_PCIE_ROOT_CLASS(class); + + dc->desc = "BCM2711 PCIe Bridge"; + /* + * PCI-facing part of the host bridge, not usable without the host-facing + * part, which can't be device_add'ed. + */ + dc->user_creatable = false; + k->vendor_id = BCM2838_PCIE_VENDOR_ID; + k->device_id = BCM2838_PCIE_DEVICE_ID; + k->revision = BCM2838_PCIE_REVISION; + brpc->parent_obj.exp_offset = BCM2838_PCIE_EXP_CAP_OFFSET; + brpc->parent_obj.aer_offset = BCM2838_PCIE_AER_CAP_OFFSET; + brpc->parent_realize = k->realize; + k->realize = bcm2838_pcie_root_realize; +} + +static const TypeInfo bcm2838_pcie_root_info = { + .name = TYPE_BCM2838_PCIE_ROOT, + .parent = TYPE_PCIE_ROOT_PORT, + .instance_size = sizeof(BCM2838PcieRootState), + .instance_init = bcm2838_pcie_root_init, + .class_init = bcm2838_pcie_root_class_init, +}; + +static void bcm2838_pcie_register(void) +{ + type_register_static(&bcm2838_pcie_root_info); +} + +type_init(bcm2838_pcie_register) diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 27e6797de2..b26ed13c6f 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -39,7 +39,10 @@ arm_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10.c', 'cubi arm_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3.c', 'orangepi.c')) arm_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bananapi_m2u.c')) arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c')) -arm_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files('bcm2838.c', 'raspi4b.c')) +arm_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files( + 'bcm2838.c', + 'bcm2838_pcie.c', + 'raspi4b.c')) arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c')) arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c')) arm_ss.add(when: 'CONFIG_STM32F405_SOC', if_true: files('stm32f405_soc.c')) diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 4f0167e638..6cfab31539 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -55,5 +55,9 @@ smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64 +# bcm2838_pcie.c +bcm2838_pcie_host_read(unsigned int size, uint64_t offset, uint64_t value) "%u bytes @ 0x%04"PRIx64": 0x%016"PRIx64 +bcm2838_pcie_host_write(unsigned int size, uint64_t offset, uint64_t value) "%u bytes @ 0x%04"PRIx64": 0x%016"PRIx64 + # bcm2838.c bcm2838_gic_set_irq(int irq, int level) "gic irq:%d lvl:%d" diff --git a/include/hw/arm/bcm2838_pcie.h b/include/hw/arm/bcm2838_pcie.h new file mode 100644 index 0000000000..39828f817f --- /dev/null +++ b/include/hw/arm/bcm2838_pcie.h @@ -0,0 +1,53 @@ +/* + * BCM2838 PCIe Root Complex emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BCM2838_PCIE_H +#define BCM2838_PCIE_H + +#include "exec/hwaddr.h" +#include "hw/sysbus.h" +#include "hw/pci/pci.h" +#include "hw/pci/pcie_host.h" +#include "hw/pci/pcie_port.h" +#include "qom/object.h" + +#define TYPE_BCM2838_PCIE_ROOT "bcm2838-pcie-root" +OBJECT_DECLARE_TYPE(BCM2838PcieRootState, BCM2838PcieRootClass, + BCM2838_PCIE_ROOT) + +#define BCM2838_PCIE_VENDOR_ID 0x14E4 +#define BCM2838_PCIE_DEVICE_ID 0x2711 +#define BCM2838_PCIE_REVISION 20 + +#define BCM2838_PCIE_REGS_SIZE 0x9310 +#define BCM2838_PCIE_NUM_IRQS 4 + +#define BCM2838_PCIE_EXP_CAP_OFFSET 0xAC +#define BCM2838_PCIE_AER_CAP_OFFSET 0x100 + +#define BCM2838_PCIE_EXT_CFG_DATA 0x8000 +#define BCM2838_PCIE_EXT_CFG_INDEX 0x9000 + +struct BCM2838PcieRootState { + /*< private >*/ + PCIESlot parent_obj; + + /*< public >*/ + uint8_t regs[BCM2838_PCIE_REGS_SIZE - PCIE_CONFIG_SPACE_SIZE]; +}; + +struct BCM2838PcieRootClass { + /*< private >*/ + PCIERootPortClass parent_obj; + + /*< public >*/ + void (*parent_realize)(PCIDevice *dev, Error **errp); +}; + + +#endif /* BCM2838_PCIE_H */ From patchwork Sun Dec 3 21:28:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TKwrcrwc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Vd54Hpz23mf for ; Mon, 4 Dec 2023 08:36:41 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2D-0001xK-Um; Sun, 03 Dec 2023 16:29:53 -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 1r9u1p-0001Rw-6M; Sun, 03 Dec 2023 16:29:32 -0500 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1m-0005RH-4J; Sun, 03 Dec 2023 16:29:28 -0500 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-db3a09e96daso2128220276.3; Sun, 03 Dec 2023 13:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638964; x=1702243764; 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=IA89nY8jxlWQU5cEQQofnym1Upjf0MuK6dyCKlAlClw=; b=TKwrcrwcXUVfHuqQCVKC2vzpjRxfTajT12srcn+BkWCDq1xr5oepYONJ+ZfZWNsRSB OIpbfm4Vkm/3TC1fa5XoW06R3Mp9P/olK3TydT/jrDaNCv1sT1xRoYCKB5XvKh+K62Cp k8xPBoSsVndQ9q9Ey15h9UqiGM0crrF6TvglXqDkPBOL4VimIfPNK0TaJr6kLGPjPU17 S1eHh6ZiJF6jOGkSqjyB2ZkPt87fMg5oJbJduFHq4h5WcHKzKpJDhngrg/X9q+e3XZey 8o4Rl+BvGtQG/9xi8+rzaVJoQPK0vLh4IBAgKyvCtu6ObB0/VdL7R8hEqGakcHl/6uc6 sqaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638964; x=1702243764; 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=IA89nY8jxlWQU5cEQQofnym1Upjf0MuK6dyCKlAlClw=; b=E7J2I5iRamMuYSzFSQ1Hc5dd1husR64LwkeuDIJtQvzXY1In2BbfP0hxRmonsik6l3 cJOGydvuteh5c1h/+BX4GAMy40G09OWe+kTs67UsQjFCfyN8Hj7eX3cCVUySkacD2xZq o4bfyUmuKxQ+CEQZBHoeKAqN/WrG+Uq2yq5OqyYk0aBf8NgWWhRZELW/qI6EdQ7muyG+ tZX+ZL5PYvY+4hOhsfRO0Azfm92L9Xx3AgN7vU2FWz8Pp5q9xhVwXH642TDPJkchLH72 v9DIxSFOJ9xWPJY+MWNOKjJ1kzDAgZl8DEhZKgjg+31EQNkstStDF/cYZA88wkS8gpYJ 5z3g== X-Gm-Message-State: AOJu0YwyOHLuAFKn91cg6azMCkbXRntRqKcxBS5aDFDqwN+YB3nNjUMl KyHohWyJh90+SVf0xDPY21An3yiyfVYTAw== X-Google-Smtp-Source: AGHT+IG01BGKnhBW9S+2NohKjQR3/ei7HDGE4c61uQYX2ljUDTvkKaCHRtvLF3+AgqYkpBIzgAhprQ== X-Received: by 2002:a25:d8c6:0:b0:db7:dad0:60f5 with SMTP id p189-20020a25d8c6000000b00db7dad060f5mr2063446ybg.130.1701638964612; Sun, 03 Dec 2023 13:29:24 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:24 -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 15/45] Add BCM2838 PCIE host Date: Sun, 3 Dec 2023 15:28:35 -0600 Message-Id: <20231203212905.1364036-16-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-15-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b29; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb29.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_pcie.c | 216 +++++++++++++++++++++++++++++++++- include/hw/arm/bcm2838_pcie.h | 22 ++++ 2 files changed, 236 insertions(+), 2 deletions(-) diff --git a/hw/arm/bcm2838_pcie.c b/hw/arm/bcm2838_pcie.c index 3b4373c6a6..75146d6c2e 100644 --- a/hw/arm/bcm2838_pcie.c +++ b/hw/arm/bcm2838_pcie.c @@ -12,11 +12,222 @@ #include "hw/irq.h" #include "hw/pci-host/gpex.h" #include "hw/qdev-properties.h" -#include "migration/vmstate.h" -#include "qemu/module.h" #include "hw/arm/bcm2838_pcie.h" #include "trace.h" +/* + * RC host part + */ + +static uint64_t bcm2838_pcie_host_read(void *opaque, hwaddr offset, + unsigned size) { + hwaddr mmcfg_addr; + uint64_t value = ~0; + BCM2838PcieHostState *s = opaque; + PCIExpressHost *pcie_hb = PCIE_HOST_BRIDGE(s); + PCIDevice *root_pci_dev = PCI_DEVICE(&s->root_port); + uint8_t *root_regs = s->root_port.regs; + uint32_t *cfg_idx = (uint32_t *)(root_regs + BCM2838_PCIE_EXT_CFG_INDEX + - PCIE_CONFIG_SPACE_SIZE); + + if (offset < PCIE_CONFIG_SPACE_SIZE) { + value = pci_host_config_read_common(root_pci_dev, offset, + PCIE_CONFIG_SPACE_SIZE, size); + } else if (offset - PCIE_CONFIG_SPACE_SIZE + size + <= sizeof(s->root_port.regs)) { + switch (offset) { + case BCM2838_PCIE_EXT_CFG_DATA + ... BCM2838_PCIE_EXT_CFG_DATA + PCIE_CONFIG_SPACE_SIZE - 1: + mmcfg_addr = *cfg_idx + | PCIE_MMCFG_CONFOFFSET(offset - BCM2838_PCIE_EXT_CFG_DATA); + value = pcie_hb->mmio.ops->read(opaque, mmcfg_addr, size); + break; + default: + memcpy(&value, root_regs + offset - PCIE_CONFIG_SPACE_SIZE, size); + } + } else { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); + } + + trace_bcm2838_pcie_host_read(size, offset, value); + return value; +} + +static void bcm2838_pcie_host_write(void *opaque, hwaddr offset, + uint64_t value, unsigned size) { + hwaddr mmcfg_addr; + BCM2838PcieHostState *s = opaque; + PCIExpressHost *pcie_hb = PCIE_HOST_BRIDGE(s); + PCIDevice *root_pci_dev = PCI_DEVICE(&s->root_port); + uint8_t *root_regs = s->root_port.regs; + uint32_t *cfg_idx = (uint32_t *)(root_regs + BCM2838_PCIE_EXT_CFG_INDEX + - PCIE_CONFIG_SPACE_SIZE); + + trace_bcm2838_pcie_host_write(size, offset, value); + + if (offset < PCIE_CONFIG_SPACE_SIZE) { + pci_host_config_write_common(root_pci_dev, offset, + PCIE_CONFIG_SPACE_SIZE, value, size); + } else if (offset - PCIE_CONFIG_SPACE_SIZE + size + <= sizeof(s->root_port.regs)) { + switch (offset) { + case BCM2838_PCIE_EXT_CFG_DATA + ... BCM2838_PCIE_EXT_CFG_DATA + PCIE_CONFIG_SPACE_SIZE - 1: + mmcfg_addr = *cfg_idx + | PCIE_MMCFG_CONFOFFSET(offset - BCM2838_PCIE_EXT_CFG_DATA); + pcie_hb->mmio.ops->write(opaque, mmcfg_addr, value, size); + break; + default: + memcpy(root_regs + offset - PCIE_CONFIG_SPACE_SIZE, &value, size); + } + } else { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); + } +} + +static const MemoryRegionOps bcm2838_pcie_host_ops = { + .read = bcm2838_pcie_host_read, + .write = bcm2838_pcie_host_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = {.max_access_size = sizeof(uint64_t)}, +}; + +int bcm2838_pcie_host_set_irq_num(BCM2838PcieHostState *s, int index, int spi) +{ + if (index >= BCM2838_PCIE_NUM_IRQS) { + return -EINVAL; + } + + s->irq_num[index] = spi; + return 0; +} + +static void bcm2838_pcie_host_set_irq(void *opaque, int irq_num, int level) +{ + BCM2838PcieHostState *s = opaque; + + qemu_set_irq(s->irq[irq_num], level); +} + +static PCIINTxRoute bcm2838_pcie_host_route_intx_pin_to_irq(void *opaque, + int pin) +{ + PCIINTxRoute route; + BCM2838PcieHostState *s = opaque; + + route.irq = s->irq_num[pin]; + route.mode = route.irq < 0 ? PCI_INTX_DISABLED : PCI_INTX_ENABLED; + + return route; +} + +static int bcm2838_pcie_host_map_irq(PCIDevice *pci_dev, int pin) +{ + return pin; +} + +static void bcm2838_pcie_host_realize(DeviceState *dev, Error **errp) +{ + PCIHostState *pci = PCI_HOST_BRIDGE(dev); + BCM2838PcieHostState *s = BCM2838_PCIE_HOST(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + + int i; + + memory_region_init_io(&s->cfg_regs, OBJECT(s), &bcm2838_pcie_host_ops, s, + "bcm2838_pcie_cfg_regs", BCM2838_PCIE_REGS_SIZE); + sysbus_init_mmio(sbd, &s->cfg_regs); + + /* + * The MemoryRegions io_mmio and io_ioport that we pass to + * pci_register_root_bus() are not the same as the MemoryRegions + * io_mmio_window and io_ioport_window that we expose as SysBus MRs. + * The difference is in the behavior of accesses to addresses where no PCI + * device has been mapped. + * + * io_mmio and io_ioport are the underlying PCI view of the PCI address + * space, and when a PCI device does a bus master access to a bad address + * this is reported back to it as a transaction failure. + * + * io_mmio_window and io_ioport_window implement "unmapped addresses read as + * -1 and ignore writes"; this is a traditional x86 PC behavior, which is + * not mandated properly by the PCI spec but expected by the majority of + * PCI-using guest software, including Linux. + * + * We implement it in the PCIe host controller, by providing the *_window + * MRs, which are containers with io ops that implement the 'background' + * behavior and which hold the real PCI MRs as sub-regions. + */ + memory_region_init(&s->io_mmio, OBJECT(s), "bcm2838_pcie_mmio", UINT64_MAX); + memory_region_init(&s->io_ioport, OBJECT(s), "bcm2838_pcie_ioport", + 64 * 1024); + + memory_region_init_io(&s->io_mmio_window, OBJECT(s), + &unassigned_io_ops, OBJECT(s), + "bcm2838_pcie_mmio_window", UINT64_MAX); + memory_region_init_io(&s->io_ioport_window, OBJECT(s), + &unassigned_io_ops, OBJECT(s), + "bcm2838_pcie_ioport_window", 64 * 1024); + + memory_region_add_subregion(&s->io_mmio_window, 0, &s->io_mmio); + memory_region_add_subregion(&s->io_ioport_window, 0, &s->io_ioport); + sysbus_init_mmio(sbd, &s->io_mmio_window); + sysbus_init_mmio(sbd, &s->io_ioport_window); + + for (i = 0; i < BCM2838_PCIE_NUM_IRQS; i++) { + sysbus_init_irq(sbd, &s->irq[i]); + s->irq_num[i] = -1; + } + + pci->bus = pci_register_root_bus(dev, "pcie.0", bcm2838_pcie_host_set_irq, + bcm2838_pcie_host_map_irq, s, &s->io_mmio, + &s->io_ioport, 0, BCM2838_PCIE_NUM_IRQS, + TYPE_PCIE_BUS); + pci_bus_set_route_irq_fn(pci->bus, bcm2838_pcie_host_route_intx_pin_to_irq); + qdev_realize(DEVICE(&s->root_port), BUS(pci->bus), &error_fatal); +} + +static const char *bcm2838_pcie_host_root_bus_path(PCIHostState *host_bridge, + PCIBus *rootbus) +{ + return "0000:00"; +} + +static void bcm2838_pcie_host_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(class); + PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(class); + + hc->root_bus_path = bcm2838_pcie_host_root_bus_path; + dc->realize = bcm2838_pcie_host_realize; + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + dc->fw_name = "pci"; +} + +static void bcm2838_pcie_host_initfn(Object *obj) +{ + BCM2838PcieHostState *s = BCM2838_PCIE_HOST(obj); + BCM2838PcieRootState *root = &s->root_port; + + object_initialize_child(obj, "root_port", root, TYPE_BCM2838_PCIE_ROOT); + qdev_prop_set_int32(DEVICE(root), "addr", PCI_DEVFN(0, 0)); + qdev_prop_set_bit(DEVICE(root), "multifunction", false); +} + +static const TypeInfo bcm2838_pcie_host_info = { + .name = TYPE_BCM2838_PCIE_HOST, + .parent = TYPE_PCIE_HOST_BRIDGE, + .instance_size = sizeof(BCM2838PcieHostState), + .instance_init = bcm2838_pcie_host_initfn, + .class_init = bcm2838_pcie_host_class_init, +}; + /* * RC root part (D0:F0) */ @@ -69,6 +280,7 @@ static const TypeInfo bcm2838_pcie_root_info = { static void bcm2838_pcie_register(void) { type_register_static(&bcm2838_pcie_root_info); + type_register_static(&bcm2838_pcie_host_info); } type_init(bcm2838_pcie_register) diff --git a/include/hw/arm/bcm2838_pcie.h b/include/hw/arm/bcm2838_pcie.h index 39828f817f..58c3a0efe7 100644 --- a/include/hw/arm/bcm2838_pcie.h +++ b/include/hw/arm/bcm2838_pcie.h @@ -16,6 +16,9 @@ #include "hw/pci/pcie_port.h" #include "qom/object.h" +#define TYPE_BCM2838_PCIE_HOST "bcm2838-pcie-host" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2838PcieHostState, BCM2838_PCIE_HOST) + #define TYPE_BCM2838_PCIE_ROOT "bcm2838-pcie-root" OBJECT_DECLARE_TYPE(BCM2838PcieRootState, BCM2838PcieRootClass, BCM2838_PCIE_ROOT) @@ -50,4 +53,23 @@ struct BCM2838PcieRootClass { }; +struct BCM2838PcieHostState { + /*< private >*/ + PCIExpressHost parent_obj; + + /*< public >*/ + BCM2838PcieRootState root_port; + + MemoryRegion cfg_regs; + MemoryRegion io_ioport; + MemoryRegion io_mmio; + MemoryRegion io_ioport_window; + MemoryRegion io_mmio_window; + + qemu_irq irq[BCM2838_PCIE_NUM_IRQS]; + int irq_num[BCM2838_PCIE_NUM_IRQS]; +}; + +int bcm2838_pcie_host_set_irq_num(BCM2838PcieHostState *s, int index, int spi); + #endif /* BCM2838_PCIE_H */ From patchwork Sun Dec 3 21:28:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=f76ZZ2vL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0X60MNNz23mf for ; Mon, 4 Dec 2023 08:37:58 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2P-0002T0-SY; Sun, 03 Dec 2023 16:30:05 -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 1r9u1q-0001Ry-0R; Sun, 03 Dec 2023 16:29:34 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1n-0005RV-3Y; Sun, 03 Dec 2023 16:29:29 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-da37522a363so1873644276.0; Sun, 03 Dec 2023 13:29:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638965; x=1702243765; 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=hlzqq1rIcBw375iNxsrI6JHCl35tGrND0ZoDvB52ZmE=; b=f76ZZ2vLIxOURYLcDiJHCt1hZ6Qk92zx92F7PNNtwOI/dlx1J1w82b/WBzNfxzZk0S +Eg//IcKDwXMOsLyMCHyFYnKvYu7kbtm6F2h5fgFgH9ywgVPcQFvPbiOI6D7zHyshVPO YEtGw8tiBq8zMDRjGNuOIflPLbYiNMxxh315ultoo8difnZ9kIXUqhHDT8lRYYGJiL9u ciI0TKLOwC763MhpjdBdNo41WgL8QxWWClRHQutwBo6GykNrMKI8rBruKE8KFA0JYS+N I6lJD+NUIcItjztHtqyn2fumHHrTXKIRXr8dlVEgdt2qSkEebuoRw3g0HaTmONlq9WEO s+fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638965; x=1702243765; 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=hlzqq1rIcBw375iNxsrI6JHCl35tGrND0ZoDvB52ZmE=; b=YdNGSdRID7L/dhkU0UX7CaJ7beaOg7WxsYcBK0zrjDgAFIDuZNhELEZjyZcXRzRllo nVB/Z2ICQtZsuDX/+m5ZTpFqoFTkelR/ag+xpMjgiuQziIFvpX0kfKzDmch4mFlgV1af wF1knA/ohIDDCBHmWPxnWhPNNWWu4+/1k/iGYldgnZUfZ2MxeOJhy0iq5hR6PLB122gh lFIYWuhTieAw2nLUFM489J9i89pg6x6b20cZI04GXyQzpLKid0NNuGKV4Ld+CH4i7PMm 6S8Su6hFYlorinIc8gL5Xrd00JuWpSfmL50rvfXEUD+3wsEs1FggMNAn5EUQHyTXml2/ Uj3w== X-Gm-Message-State: AOJu0YwA477wHyEHS4iaG0SH46dRU97pz3Vki28Z/eYfluQ6COivCYxz GoT/f+ACTt7xJdHYEv0P6RbF2XuwcgOYRA== X-Google-Smtp-Source: AGHT+IEjD3cEZiRFcNW7jJ3ve+CEEqFKMCASabG1xEKgjLzavjJRzhL+DqhlDmPhEZZKwf32WBWaew== X-Received: by 2002:a25:77c2:0:b0:db7:dacf:2f14 with SMTP id s185-20020a2577c2000000b00db7dacf2f14mr1801428ybc.91.1701638965660; Sun, 03 Dec 2023 13:29:25 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:25 -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 16/45] Enable BCM2838 PCIE Date: Sun, 3 Dec 2023 15:28:36 -0600 Message-Id: <20231203212905.1364036-17-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-16-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_pcie.c | 3 +++ hw/arm/bcm2838_peripherals.c | 26 ++++++++++++++++++++++++++ hw/arm/meson.build | 7 ++++--- hw/arm/raspi4b.c | 1 - include/hw/arm/bcm2838_peripherals.h | 3 +++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/hw/arm/bcm2838_pcie.c b/hw/arm/bcm2838_pcie.c index 75146d6c2e..8e046d0ac7 100644 --- a/hw/arm/bcm2838_pcie.c +++ b/hw/arm/bcm2838_pcie.c @@ -239,6 +239,9 @@ static void bcm2838_pcie_root_reg_reset(PCIDevice *dev) } static void bcm2838_pcie_root_realize(PCIDevice *dev, Error **errp) { + BCM2838PcieRootClass *brpc = BCM2838_PCIE_ROOT_GET_CLASS(dev); + + brpc->parent_realize(dev, errp); bcm2838_pcie_root_reg_reset(dev); } diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index d3b42cf25b..ee06214715 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -12,6 +12,11 @@ #include "hw/arm/raspi_platform.h" #include "hw/arm/bcm2838_peripherals.h" +#define PCIE_RC_OFFSET 0x1500000 +#define PCIE_MMIO_OFFSET 0xc0000000 +#define PCIE_MMIO_ARM_OFFSET 0x600000000 +#define PCIE_MMIO_SIZE 0x40000000 + /* Lower peripheral base address on the VC (GPU) system bus */ #define BCM2838_VC_PERI_LOW_BASE 0x7c000000 @@ -29,6 +34,10 @@ static void bcm2838_peripherals_init(Object *obj) bc->peri_low_size); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_low_mr); + /* PCIe Host Bridge */ + object_initialize_child(obj, "pcie-host", &s->pcie_host, + TYPE_BCM2838_PCIE_HOST); + /* Extended Mass Media Controller 2 */ object_initialize_child(obj, "emmc2", &s->emmc2, TYPE_SYSBUS_SDHCI); @@ -61,6 +70,9 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) MemoryRegion *mphi_mr; BCM2838PeripheralState *s = BCM2838_PERIPHERALS(dev); BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(dev); + MemoryRegion *regs_mr; + MemoryRegion *mmio_mr; + int n; bcm_soc_peripherals_common_realize(dev, errp); @@ -172,6 +184,20 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) BCM2838_MPHI_SIZE); memory_region_add_subregion(&s_base->peri_mr, BCM2838_MPHI_OFFSET, &s->mphi_mr_alias); + /* PCIe Root Complex */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie_host), errp)) { + return; + } + /* RC registers region */ + regs_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->pcie_host), 0); + memory_region_add_subregion(&s->peri_low_mr, PCIE_RC_OFFSET, regs_mr); + /* MMIO region */ + mmio_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->pcie_host), 1); + memory_region_init_alias(&s->pcie_mmio_alias, OBJECT(&s->pcie_host), + "pcie-mmio", mmio_mr, PCIE_MMIO_OFFSET, + PCIE_MMIO_SIZE); + memory_region_add_subregion(get_system_memory(), PCIE_MMIO_ARM_OFFSET, + &s->pcie_mmio_alias); /* GPIO */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { diff --git a/hw/arm/meson.build b/hw/arm/meson.build index b26ed13c6f..69d199b73e 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -41,7 +41,6 @@ arm_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bana arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c')) arm_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files( 'bcm2838.c', - 'bcm2838_pcie.c', 'raspi4b.c')) arm_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c')) arm_ss.add(when: 'CONFIG_STM32F205_SOC', if_true: files('stm32f205_soc.c')) @@ -72,8 +71,10 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files('xen_arm.c')) system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) -system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c')) -system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c')) +system_ss.add(when: 'CONFIG_RASPI', if_true: files( + 'bcm2835_peripherals.c', + 'bcm2838_peripherals.c', + 'bcm2838_pcie.c')) system_ss.add(when: 'CONFIG_TOSA', if_true: files('tosa.c')) hw_arch += {'arm': arm_ss} diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c index 10376b62dc..2e8474e1c5 100644 --- a/hw/arm/raspi4b.c +++ b/hw/arm/raspi4b.c @@ -67,7 +67,6 @@ static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt) /* Temporarily disable following devices until they are implemented*/ const char *to_be_removed_from_dt_as_wa[] = { - "brcm,bcm2711-pcie", "brcm,bcm2711-rng200", "brcm,bcm2711-thermal", "brcm,bcm2711-genet-v5", diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index af085934c9..2af96df1c6 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -10,6 +10,7 @@ #define BCM2838_PERIPHERALS_H #include "hw/arm/bcm2835_peripherals.h" +#include "hw/arm/bcm2838_pcie.h" #include "hw/sd/sdhci.h" #include "hw/gpio/bcm2838_gpio.h" @@ -62,8 +63,10 @@ struct BCM2838PeripheralState { MemoryRegion peri_low_mr; MemoryRegion peri_low_mr_alias; MemoryRegion mphi_mr_alias; + MemoryRegion pcie_mmio_alias; SDHCIState emmc2; + BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; OrIRQState mmc_irq_orgate; From patchwork Sun Dec 3 21:28:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=f/S+6Joj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Wt4wyCz23mf for ; Mon, 4 Dec 2023 08:37:46 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2H-0002BV-NN; Sun, 03 Dec 2023 16:29:57 -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 1r9u1q-0001S2-PM; Sun, 03 Dec 2023 16:29:38 -0500 Received: from mail-yb1-xb2c.google.com ([2607:f8b0:4864:20::b2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1o-0005Rr-AM; Sun, 03 Dec 2023 16:29:30 -0500 Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-d9caf5cc948so2076379276.0; Sun, 03 Dec 2023 13:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638966; x=1702243766; 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=U3q6AiL1mbxBiKidAQHbdRXxykNtox5744GvYZOpg/0=; b=f/S+6JojORm/qFcmZ0FFGxsEz8HyzekfYsfPzl3dn27pco5XUgG+iWedJ3s/+DjjiX XXXBMeMSFrWOpdf2sU1iC8Pabc4cBox7tOw0bEcRWKksEkaR/ysdya49202ytDRZ+v6v zPl8cJ5cNBtgY/17ReMqECnfGHp/swKlYqpkaJoxAjdlhW8VW214LHxUstReE+2lMLBX uGtUtBFdaG911mMt0CXQWAWnFK0b6C1HCH6swra4kJfbQj+1Vbuy3rE1/vCbtwey00h0 XM2u8wUQkeLz9Thtx4EtZy7OjxjmYtofxx52rE7lSebUof2edPBHEc5fNRHdbl9F3usp EzsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638966; x=1702243766; 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=U3q6AiL1mbxBiKidAQHbdRXxykNtox5744GvYZOpg/0=; b=NgrwQuQbXftyqIi7PrxgqBEtR5CyM3pjw5s/n76+h8wNMVRyUpr4qWlYM7Ud6xgWl6 rR8109cXyC9fQRre/Ol6oe1tKpRnu66ETQVFkutwSRNKcVdRiqgiBq5U6+Opxg4C3v6r V1SpjRw3ZdA4cHH/fj34BL7j7HoIANixk8IbLUXIz6f3veLOUcEzRFVQiKBd/5FA8IDm enWwKGBVTn57K12ymfM2FslmSCJxdMy5XTkoTsEECT2z2c4ffeO/HiTbZRJVtEXT83fv Nejikss+hrPYRjaSZTiqI0pd3eD3OC0Q8KXVJQWZKD5+xda0lKtGO7IcZjFq4mwYYY3q 5aJQ== X-Gm-Message-State: AOJu0YyKVcpdTrE3rTOXUedzMqN19OwT/wUSdF4ibR9cc1YjmJq0Gx3s nwakwK7ZLZo+c/GLK2xmCclTw4VHRnFubg== X-Google-Smtp-Source: AGHT+IFtMDBPpID0Fh+fXuhs3qdHEYJsEXzMIxUNC+goJlLo3WD5aPtfVyOJpfGhJRUIysOVSES9AQ== X-Received: by 2002:a5b:b47:0:b0:db7:dacf:3f9b with SMTP id b7-20020a5b0b47000000b00db7dacf3f9bmr1643132ybr.72.1701638966683; Sun, 03 Dec 2023 13:29:26 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:26 -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 17/45] Add RNG200 skeleton Date: Sun, 3 Dec 2023 15:28:37 -0600 Message-Id: <20231203212905.1364036-18-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-17-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2c; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2c.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/misc/bcm2838_rng200.c | 152 +++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 9 ++ include/hw/misc/bcm2838_rng200.h | 51 +++++++++++ 4 files changed, 213 insertions(+) create mode 100644 hw/misc/bcm2838_rng200.c create mode 100644 include/hw/misc/bcm2838_rng200.h diff --git a/hw/misc/bcm2838_rng200.c b/hw/misc/bcm2838_rng200.c new file mode 100644 index 0000000000..8f64e6a20f --- /dev/null +++ b/hw/misc/bcm2838_rng200.c @@ -0,0 +1,152 @@ +/* + * BCM2838 Random Number Generator emulation + * + * Copyright (C) 2022 Sergey Pushkarev + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/misc/bcm2838_rng200.h" +#include "migration/vmstate.h" +#include "trace.h" + +static const VMStateDescription vmstate_bcm2838_rng200_regs = { + .name = "bcm2838_rng200_regs", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(ctrl, BCM2838_rng_regs_t), + VMSTATE_UINT32(int_status, BCM2838_rng_regs_t), + VMSTATE_UINT32(fifo_count, BCM2838_rng_regs_t), + VMSTATE_UINT32(fifo_count_threshold, BCM2838_rng_regs_t), + VMSTATE_UINT32(total_bit_count_threshold, BCM2838_rng_regs_t), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_bcm2838_rng200 = { + .name = "bcm2838_rng200", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(rbg_period, BCM2838Rng200State), + VMSTATE_UINT32(rng_fifo_cap, BCM2838Rng200State), + VMSTATE_BOOL(use_timer, BCM2838Rng200State), + + VMSTATE_STRUCT(regs, BCM2838Rng200State, 0, vmstate_bcm2838_rng200_regs, + BCM2838_rng_regs_t), + + VMSTATE_END_OF_LIST() + } +}; + +static void bcm2838_rng200_rng_reset(BCM2838Rng200State *state) +{ + state->regs.ctrl = 0; + + trace_bcm2838_rng200_rng_soft_reset(); +} + +static uint64_t bcm2838_rng200_read(void *opaque, hwaddr offset, + unsigned size) +{ + uint32_t res = 0; + + /* will be implemented in upcoming commits */ + return res; +} + +static void bcm2838_rng200_write(void *opaque, hwaddr offset, + uint64_t value, unsigned size) +{ + /* will be implemented in upcoming commits */ +} + +static const MemoryRegionOps bcm2838_rng200_ops = { + .read = bcm2838_rng200_read, + .write = bcm2838_rng200_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void bcm2838_rng200_realize(DeviceState *dev, Error **errp) +{ + BCM2838Rng200State *s = BCM2838_RNG200(dev); + + if (s->rng == NULL) { + Object *default_backend = object_new(TYPE_RNG_BUILTIN); + + object_property_add_child(OBJECT(dev), "default-backend", + default_backend); + object_unref(default_backend); + + object_property_set_link(OBJECT(dev), "rng", default_backend, + errp); + } + + sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); +} + +static void bcm2838_rng200_init(Object *obj) +{ + BCM2838Rng200State *s = BCM2838_RNG200(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + + s->rbg_period = 250; + s->use_timer = true; + + s->rng_fifo_cap = 128; + + s->clock = qdev_init_clock_in(DEVICE(s), "rbg-clock", + NULL, s, + ClockPreUpdate); + if (s->clock == NULL) { + error_setg(&error_fatal, "Failed to init RBG clock"); + return; + } + + memory_region_init_io(&s->iomem, obj, &bcm2838_rng200_ops, s, + TYPE_BCM2838_RNG200, 0x28); + sysbus_init_mmio(sbd, &s->iomem); +} + +static void bcm2838_rng200_reset(DeviceState *dev) +{ + BCM2838Rng200State *s = BCM2838_RNG200(dev); + bcm2838_rng200_rng_reset(s); +} + +static Property bcm2838_rng200_properties[] = { + DEFINE_PROP_LINK("rng", BCM2838Rng200State, rng, + TYPE_RNG_BACKEND, RngBackend *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void bcm2838_rng200_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = bcm2838_rng200_realize; + dc->reset = bcm2838_rng200_reset; + dc->vmsd = &vmstate_bcm2838_rng200; + + device_class_set_props(dc, bcm2838_rng200_properties); +} + +static const TypeInfo bcm2838_rng200_info = { + .name = TYPE_BCM2838_RNG200, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(BCM2838Rng200State), + .class_init = bcm2838_rng200_class_init, + .instance_init = bcm2838_rng200_init, +}; + +static void bcm2838_rng200_register_types(void) +{ + type_register_static(&bcm2838_rng200_info); +} + +type_init(bcm2838_rng200_register_types) diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 36c20d5637..b899e6b596 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -91,6 +91,7 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2835_thermal.c', 'bcm2835_cprman.c', 'bcm2835_powermgt.c', + 'bcm2838_rng200.c' )) system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c')) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 05ff692441..5e5d3fe61a 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -330,3 +330,12 @@ djmemc_write(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRI # iosb.c iosb_read(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRIx64" size=%u" iosb_write(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRIx64" size=%u" +# bcm2838_rng200.c +bcm2838_rng200_rng_soft_reset(void) "RNumG soft reset" +bcm2838_rng200_rbg_soft_reset(void) "RBitG soft reset" +bcm2838_rng200_enable_rbg(void) "RBitG enabled" +bcm2838_rng200_disable_rbg(void) "RBitG disabled" +bcm2838_rng200_update_fifo(uint32_t len, uint32_t fifo_len) "len %u, fifo_len %u" +bcm2838_rng200_fifo_full(void) "RNumG FIFO full" +bcm2838_rng200_write(uint64_t addr, uint64_t value, unsigned size) "addr: 0x%"PRIx64" value: 0x%016" PRIx64 " size: %u" +bcm2838_rng200_read(uint64_t addr, unsigned size, uint64_t value) "addr: 0x%"PRIx64" size: %u value: 0x%016" PRIx64 diff --git a/include/hw/misc/bcm2838_rng200.h b/include/hw/misc/bcm2838_rng200.h new file mode 100644 index 0000000000..c9c52f84be --- /dev/null +++ b/include/hw/misc/bcm2838_rng200.h @@ -0,0 +1,51 @@ +/* + * BCM2838 Random Number Generator emulation + * + * Copyright (C) 2022 Sergey Pushkarev + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef BCM2838_RNG200_H +#define BCM2838_RNG200_H + +#include +#include "qom/object.h" +#include "qemu/fifo8.h" +#include "sysemu/rng.h" +#include "hw/sysbus.h" +#include "hw/ptimer.h" +#include "hw/qdev-clock.h" +#include "hw/irq.h" + +#define TYPE_BCM2838_RNG200 "bcm2838-rng200" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2838Rng200State, BCM2838_RNG200) + +typedef struct { + uint32_t ctrl; + uint32_t int_status; + uint32_t fifo_count; + uint32_t fifo_count_threshold; + uint32_t total_bit_count_threshold; +} BCM2838_rng_regs_t; + +struct BCM2838Rng200State { + SysBusDevice busdev; + MemoryRegion iomem; + + ptimer_state *ptimer; + RngBackend *rng; + Clock *clock; + + uint32_t rbg_period; + uint32_t rng_fifo_cap; + bool use_timer; + + Fifo8 fifo; + qemu_irq irq; + + BCM2838_rng_regs_t regs; +}; + +#endif /* BCM2838_RNG200_H */ From patchwork Sun Dec 3 21:28:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nMM0GJjA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Wj3fn1z23mf for ; Mon, 4 Dec 2023 08:37:37 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2I-0002CK-4L; Sun, 03 Dec 2023 16:29:58 -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 1r9u1s-0001S6-0U; Sun, 03 Dec 2023 16:29:40 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1p-0005SB-9G; Sun, 03 Dec 2023 16:29:31 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-db54611b920so1855798276.3; Sun, 03 Dec 2023 13:29:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638968; x=1702243768; 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=T2+RqTI992Z6aHpF/YzHyQQsizepG5slMHL58oIyT+w=; b=nMM0GJjA+OyGMSbrJuesGzQ1IIJI8LBZtudhl3mp2p2RhmPJlfbhHlccjbuA04K5Hk sY3+b9KbJFUh8j+yaomHMWm+NuJKlBi3EOGDUQkJQ4f2lHlpSttj+8mbd9hNdZ15454i eAZ8HFZdn5LweKa0DUzn4woJnJ8sEUThmsvx4LRTxg+GtEYWYBCSJCl4KJs+PhZ6qsn3 Qxs+l6mxiQ58+BVsYkjSgC981Y4lyrgz7ZuXpImUkRYqugcxr7xapTSuiSFlC1ctSJmq cTEOu3DCmzEo0G9FPGIN3glYeYZ/yXHx1FukE1U3JDN4/gJ7xSGCzN6G6mYBAjS1YjDH fdEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638968; x=1702243768; 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=T2+RqTI992Z6aHpF/YzHyQQsizepG5slMHL58oIyT+w=; b=dJ1WnVod/ebg4NWXV+TA8sf5oRFIHQifWHWly2QYdJ/O1XXLHoMGtnTgLRBlOPr2cE E08I4DOg3j7b5a6svZAlXU7OXmr3c0JRCpawKsN/bera3Bz5tF5KLHAY8u57hcIu0SKa F6KYd9UNQ4mFdR8AjcZ1Zrska2mxq0TC90xYDDzXNEuqdu4AvbDVxfUrEPJC/EoncbUi mTrszy9VGonFWp3QKRNFcyflX6GyZKh5nvyGvwy4Vkwf2oVl6SMjcJT79nIJQzqzaT94 QJpfoJVwqP5B734hiEhd6kdaZbzaddHFT+z6KZ27Yi5E6iG+4iNWQfc34Kj974wCLsiM FCMg== X-Gm-Message-State: AOJu0YxxPrUyfX62iOIU++v0kZl5llRiOm12FTXolgUdukjSX9b8ESEo oErj4bjvh4/S65r8pqTwxS16abyE0P70xA== X-Google-Smtp-Source: AGHT+IFvJ4CklOMpxVGc/fgSYeQsT+uPUQUszyviExi+BuraGVxNZzejKumqi+uOtVw7tzorWBI9XQ== X-Received: by 2002:a25:5f44:0:b0:db5:c77d:1fae with SMTP id h4-20020a255f44000000b00db5c77d1faemr3552035ybm.29.1701638967698; Sun, 03 Dec 2023 13:29:27 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:27 -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 18/45] Add RNG200 RNG and RBG Date: Sun, 3 Dec 2023 15:28:38 -0600 Message-Id: <20231203212905.1364036-19-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-18-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/misc/bcm2838_rng200.c | 292 +++++++++++++++++++++++++++++-- include/hw/misc/bcm2838_rng200.h | 10 +- 2 files changed, 275 insertions(+), 27 deletions(-) diff --git a/hw/misc/bcm2838_rng200.c b/hw/misc/bcm2838_rng200.c index 8f64e6a20f..f91ea0754c 100644 --- a/hw/misc/bcm2838_rng200.c +++ b/hw/misc/bcm2838_rng200.c @@ -8,25 +8,56 @@ */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "qapi/error.h" #include "hw/qdev-properties.h" #include "hw/misc/bcm2838_rng200.h" +#include "hw/registerfields.h" #include "migration/vmstate.h" #include "trace.h" -static const VMStateDescription vmstate_bcm2838_rng200_regs = { - .name = "bcm2838_rng200_regs", - .version_id = 1, - .minimum_version_id = 1, - .fields = (VMStateField[]) { - VMSTATE_UINT32(ctrl, BCM2838_rng_regs_t), - VMSTATE_UINT32(int_status, BCM2838_rng_regs_t), - VMSTATE_UINT32(fifo_count, BCM2838_rng_regs_t), - VMSTATE_UINT32(fifo_count_threshold, BCM2838_rng_regs_t), - VMSTATE_UINT32(total_bit_count_threshold, BCM2838_rng_regs_t), - VMSTATE_END_OF_LIST() - } -}; +/* RNG200 registers */ +REG32(RNG_CTRL, 0x00) + FIELD(RNG_CTRL, RBG_ENABLE, 0 , 1) + FIELD(RNG_CTRL, RSVD, 1 , 12) + FIELD(RNG_CTRL, DIV, 13 , 8) + +REG32(RNG_SOFT_RESET, 0x04) +REG32(RBG_SOFT_RESET, 0x08) +REG32(RNG_TOTAL_BIT_COUNT, 0x0C) +REG32(RNG_TOTAL_BIT_COUNT_THRESHOLD, 0x10) + +REG32(RNG_INT_STATUS, 0x18) + FIELD(RNG_INT_STATUS, TOTAL_BITS_COUNT_IRQ, 0, 1) + FIELD(RNG_INT_STATUS, RSVD0, 1, 4) + FIELD(RNG_INT_STATUS, NIST_FAIL_IRQ, 5, 1) + FIELD(RNG_INT_STATUS, RSVD1, 6, 11) + FIELD(RNG_INT_STATUS, STARTUP_TRANSITIONS_MET_IRQ, 17, 1) + FIELD(RNG_INT_STATUS, RSVD2, 18, 13) + FIELD(RNG_INT_STATUS, MASTER_FAIL_LOCKOUT_IRQ, 30, 1) + +REG32(RNG_INT_ENABLE, 0x1C) + FIELD(RNG_INT_ENABLE, TOTAL_BITS_COUNT_IRQ, 0, 1) + FIELD(RNG_INT_ENABLE, RSVD0, 1, 4) + FIELD(RNG_INT_ENABLE, NIST_FAIL_IRQ, 5, 1) + FIELD(RNG_INT_ENABLE, RSVD1, 6, 11) + FIELD(RNG_INT_ENABLE, STARTUP_TRANSITIONS_MET_IRQ, 17, 1) + FIELD(RNG_INT_ENABLE, RSVD2, 18, 13) + FIELD(RNG_INT_ENABLE, MASTER_FAIL_LOCKOUT_IRQ, 30, 1) + +REG32(RNG_FIFO_DATA, 0x20) + +REG32(RNG_FIFO_COUNT, 0x24) + FIELD(RNG_FIFO_COUNT, COUNT, 0, 8) + FIELD(RNG_FIFO_COUNT, THRESHOLD, 8, 8) + + +#define RNG_WARM_UP_PERIOD_ELAPSED 17 + +#define SOFT_RESET 1 +#define IRQ_PENDING 1 + +#define BCM2838_RNG200_PTIMER_POLICY (PTIMER_POLICY_CONTINUOUS_TRIGGER) static const VMStateDescription vmstate_bcm2838_rng200 = { .name = "bcm2838_rng200", @@ -37,33 +68,253 @@ static const VMStateDescription vmstate_bcm2838_rng200 = { VMSTATE_UINT32(rng_fifo_cap, BCM2838Rng200State), VMSTATE_BOOL(use_timer, BCM2838Rng200State), - VMSTATE_STRUCT(regs, BCM2838Rng200State, 0, vmstate_bcm2838_rng200_regs, - BCM2838_rng_regs_t), + VMSTATE_ARRAY(regs, BCM2838Rng200State, N_BCM2838_RNG200_REGS, 0, + vmstate_info_uint32, uint32_t), VMSTATE_END_OF_LIST() } }; -static void bcm2838_rng200_rng_reset(BCM2838Rng200State *state) +static bool is_rbg_enabled(BCM2838Rng200State *s) +{ + return FIELD_EX32(s->regs[R_RNG_CTRL], RNG_CTRL, RBG_ENABLE); +} + +static void increment_bit_counter_by(BCM2838Rng200State *s, uint32_t inc_val) { + s->regs[R_RNG_TOTAL_BIT_COUNT] += inc_val; +} + +static void bcm2838_rng200_update_irq(BCM2838Rng200State *s) +{ + qemu_set_irq(s->irq, + !!(s->regs[R_RNG_INT_ENABLE] & s->regs[R_RNG_INT_STATUS])); +} + +static void bcm2838_rng200_update_fifo(void *opaque, const void *buf, + size_t size) { - state->regs.ctrl = 0; + BCM2838Rng200State *s = (BCM2838Rng200State *)opaque; + Fifo8 *fifo = &s->fifo; + size_t num = MIN(size, fifo8_num_free(fifo)); + uint32_t num_bits = num * 8; + uint32_t bit_threshold_left = 0; + uint32_t bit_count = 0; + uint32_t bit_count_thld = 0; + uint32_t fifo_thld = 0; + + increment_bit_counter_by(s, num_bits); + + bit_count = s->regs[R_RNG_TOTAL_BIT_COUNT]; + bit_count_thld = s->regs[R_RNG_TOTAL_BIT_COUNT_THRESHOLD]; + + bit_threshold_left = (bit_count < bit_count_thld) + ? bit_count_thld - bit_count + : 0; + + if (bit_threshold_left < num_bits) { + num_bits -= bit_threshold_left; + } else { + num_bits = 0; + } + + num = num_bits / 8; + if ((num == 0) && (num_bits > 0)) { + num = 1; + } + if (num > 0) { + fifo8_push_all(fifo, buf, num); + + + fifo_thld = FIELD_EX32(s->regs[R_RNG_FIFO_COUNT], + RNG_FIFO_COUNT, THRESHOLD); + + if (fifo8_num_used(fifo) > fifo_thld) { + s->regs[R_RNG_INT_STATUS] = FIELD_DP32(s->regs[R_RNG_INT_STATUS], + RNG_INT_STATUS, + TOTAL_BITS_COUNT_IRQ, 1); + } + } + + s->regs[R_RNG_FIFO_COUNT] = FIELD_DP32(s->regs[R_RNG_FIFO_COUNT], + RNG_FIFO_COUNT, + COUNT, + fifo8_num_used(fifo) >> 2); + bcm2838_rng200_update_irq(s); + trace_bcm2838_rng200_update_fifo(num, fifo8_num_used(fifo)); +} + +static void bcm2838_rng200_fill_fifo(BCM2838Rng200State *s) +{ + rng_backend_request_entropy(s->rng, fifo8_num_free(&s->fifo), + bcm2838_rng200_update_fifo, s); +} + +/* This function will be implemnented in upcoming commits */ +static void bcm2838_rng200_disable_rbg(BCM2838Rng200State *s + __attribute__((unused))) +{ + trace_bcm2838_rng200_disable_rbg(); +} + +static void bcm2838_rng200_enable_rbg(BCM2838Rng200State *s) +{ + s->regs[R_RNG_TOTAL_BIT_COUNT] = RNG_WARM_UP_PERIOD_ELAPSED; + + bcm2838_rng200_fill_fifo(s); + + trace_bcm2838_rng200_enable_rbg(); +} + +static void bcm2838_rng200_rng_reset(BCM2838Rng200State *s) +{ + memset(s->regs, 0, sizeof(s->regs)); + s->regs[R_RNG_INT_STATUS] = FIELD_DP32(s->regs[R_RNG_INT_STATUS], + RNG_INT_STATUS, + STARTUP_TRANSITIONS_MET_IRQ, + IRQ_PENDING); + fifo8_reset(&s->fifo); trace_bcm2838_rng200_rng_soft_reset(); } +static void bcm2838_rng200_rbg_reset(BCM2838Rng200State *s) +{ + trace_bcm2838_rng200_rbg_soft_reset(); +} + +static uint32_t bcm2838_rng200_read_fifo_data(BCM2838Rng200State *s) +{ + Fifo8 *fifo = &s->fifo; + const uint8_t *buf; + uint32_t ret = 0; + uint32_t num = 0; + uint32_t max = MIN(fifo8_num_used(fifo), sizeof(ret)); + + if (max > 0) { + buf = fifo8_pop_buf(fifo, max, &num); + if ((buf != NULL) && (num > 0)) { + memcpy(&ret, buf, num); + } + } else { + qemu_log_mask( + LOG_GUEST_ERROR, + "bcm2838_rng200_read_fifo_data: FIFO is empty\n" + ); + } + + s->regs[R_RNG_FIFO_COUNT] = FIELD_DP32(s->regs[R_RNG_FIFO_COUNT], + RNG_FIFO_COUNT, + COUNT, + fifo8_num_used(fifo) >> 2); + + bcm2838_rng200_fill_fifo(s); + + return ret; +} + +static void bcm2838_rng200_ctrl_write(BCM2838Rng200State *s, uint32_t value) +{ + bool currently_enabled = is_rbg_enabled(s); + bool enable_requested = FIELD_EX32(value, RNG_CTRL, RBG_ENABLE); + + s->regs[R_RNG_CTRL] = value; + + if (!currently_enabled && enable_requested) { + bcm2838_rng200_enable_rbg(s); + } else if (currently_enabled && !enable_requested) { + bcm2838_rng200_disable_rbg(s); + } +} + static uint64_t bcm2838_rng200_read(void *opaque, hwaddr offset, unsigned size) { + BCM2838Rng200State *s = (BCM2838Rng200State *)opaque; uint32_t res = 0; - /* will be implemented in upcoming commits */ + switch (offset) { + case A_RNG_CTRL: + res = s->regs[R_RNG_CTRL]; + break; + case A_RNG_SOFT_RESET: + case A_RBG_SOFT_RESET: + break; + case A_RNG_INT_STATUS: + res = s->regs[R_RNG_INT_STATUS]; + break; + case A_RNG_INT_ENABLE: + res = s->regs[R_RNG_INT_ENABLE]; + break; + case A_RNG_FIFO_DATA: + res = bcm2838_rng200_read_fifo_data(s); + break; + case A_RNG_FIFO_COUNT: + res = s->regs[R_RNG_FIFO_COUNT]; + break; + case A_RNG_TOTAL_BIT_COUNT: + res = s->regs[R_RNG_TOTAL_BIT_COUNT]; + break; + case A_RNG_TOTAL_BIT_COUNT_THRESHOLD: + res = s->regs[R_RNG_TOTAL_BIT_COUNT_THRESHOLD]; + break; + default: + qemu_log_mask( + LOG_GUEST_ERROR, + "bcm2838_rng200_read: Bad offset 0x%" HWADDR_PRIx "\n", + offset + ); + res = 0; + break; + } + + trace_bcm2838_rng200_read(offset, size, res); return res; } static void bcm2838_rng200_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { - /* will be implemented in upcoming commits */ + BCM2838Rng200State *s = (BCM2838Rng200State *)opaque; + + trace_bcm2838_rng200_write(offset, value, size); + + switch (offset) { + case A_RNG_CTRL: + bcm2838_rng200_ctrl_write(s, value); + break; + case A_RNG_SOFT_RESET: + if (value & SOFT_RESET) { + bcm2838_rng200_rng_reset(s); + } + break; + case A_RBG_SOFT_RESET: + if (value & SOFT_RESET) { + bcm2838_rng200_rbg_reset(s); + } + break; + case A_RNG_INT_STATUS: + s->regs[R_RNG_INT_STATUS] &= ~value; + bcm2838_rng200_update_irq(s); + break; + case A_RNG_INT_ENABLE: + s->regs[R_RNG_INT_ENABLE] = value; + bcm2838_rng200_update_irq(s); + break; + case A_RNG_FIFO_COUNT: + s->regs[R_RNG_FIFO_COUNT] = value; + break; + case A_RNG_TOTAL_BIT_COUNT_THRESHOLD: + s->regs[R_RNG_TOTAL_BIT_COUNT_THRESHOLD] = value; + s->regs[R_RNG_TOTAL_BIT_COUNT] = value + 1; + break; + default: + qemu_log_mask( + LOG_GUEST_ERROR, + "bcm2838_rng200_write: Bad offset 0x%" HWADDR_PRIx "\n", + offset + ); + break; + } } static const MemoryRegionOps bcm2838_rng200_ops = { @@ -87,6 +338,7 @@ static void bcm2838_rng200_realize(DeviceState *dev, Error **errp) errp); } + fifo8_create(&s->fifo, s->rng_fifo_cap); sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); } @@ -116,6 +368,8 @@ static void bcm2838_rng200_init(Object *obj) static void bcm2838_rng200_reset(DeviceState *dev) { BCM2838Rng200State *s = BCM2838_RNG200(dev); + + bcm2838_rng200_rbg_reset(s); bcm2838_rng200_rng_reset(s); } diff --git a/include/hw/misc/bcm2838_rng200.h b/include/hw/misc/bcm2838_rng200.h index c9c52f84be..46fdba48da 100644 --- a/include/hw/misc/bcm2838_rng200.h +++ b/include/hw/misc/bcm2838_rng200.h @@ -22,13 +22,7 @@ #define TYPE_BCM2838_RNG200 "bcm2838-rng200" OBJECT_DECLARE_SIMPLE_TYPE(BCM2838Rng200State, BCM2838_RNG200) -typedef struct { - uint32_t ctrl; - uint32_t int_status; - uint32_t fifo_count; - uint32_t fifo_count_threshold; - uint32_t total_bit_count_threshold; -} BCM2838_rng_regs_t; +#define N_BCM2838_RNG200_REGS 9 struct BCM2838Rng200State { SysBusDevice busdev; @@ -45,7 +39,7 @@ struct BCM2838Rng200State { Fifo8 fifo; qemu_irq irq; - BCM2838_rng_regs_t regs; + uint32_t regs[N_BCM2838_RNG200_REGS]; }; #endif /* BCM2838_RNG200_H */ From patchwork Sun Dec 3 21:28:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871102 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=A/qlYS2c; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Vh1WJ8z23n4 for ; Mon, 4 Dec 2023 08:36:44 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2S-0002Ve-27; Sun, 03 Dec 2023 16:30:08 -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 1r9u1t-0001SU-SH; Sun, 03 Dec 2023 16:29:40 -0500 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1q-0005SY-SP; Sun, 03 Dec 2023 16:29:33 -0500 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-db8892a5f96so844416276.2; Sun, 03 Dec 2023 13:29:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638968; x=1702243768; 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=tcKM0zsaUF6OxJgIAQHfOevQ93BKCzxRx4ONFnlRnhk=; b=A/qlYS2c8TdYXS4twjeGUkBg87C1m8pa2VmP9vtEnCml9WCWRlV/YTr9a6qwCF+iga iHAF/vwkSeqck9Zk1VbQSRybfyPPtCF7Zl5H9AWasnk7wIRqgUhC7Y0Yd/IX30XAmAR1 KbN6m1/35CvAjYE637bXYc2uz41Ve1uBklI+QrudrIK2XldRGgrNwUYR3pKp6UwMa9uR 8TXqbG3BAf8xOxEr21seJ2dNRe9iEzWQ9tutDyIE8hRG1bus5f+jCw6Rw+ORWYbLCKvz k2V7dX5Rt/kXq3sonwW9Jyf4djCLFCL72kzPekq4z6JnMXe3Oq1+wbvebN3CZfh9CRdA 5kDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638968; x=1702243768; 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=tcKM0zsaUF6OxJgIAQHfOevQ93BKCzxRx4ONFnlRnhk=; b=IS5xoY3YT07BwwNo3++sDHh0mqJP9O5xoBbtqPAgoMbdKpl8drg6+Pyk+hQrcMb8w7 T9ChjFWGknsFhR1HdVYoKsWVbrvxPDFB9RdsQZxGHfS5yGgwNWn4q37wOXfQdbUkemPs Yj4WC+thYQQJ+4E+AndcYw2/D6uLvAlafi0M3pbKbn+r7Em9fGBWlPiooNQwsJwYRHKH zbtCPrC2ZBlZ8UUctR+m1hLW/q3dxb6J/k4Iy0KYdNATOkDD44KA4W35sMY/3K9phC9c 04rc+pcN4SuAwoT3VpY1AEXQNdAlaqTKJBIF5jD2FaNTE8ak2rO8/RHDxkArd/i1b5li incA== X-Gm-Message-State: AOJu0YyA/HXIgB+I2ncxKWICQFBVcYz6j1b7kVxvJEOsKYiTzguTdzkl EyYKfWnTt+hfjb1CQhZbt3forAiqfYRaPg== X-Google-Smtp-Source: AGHT+IEA3yizIZ19/3Eenqlq9PoUsv1tjk2uDJ2nTN5r+IgSuwKOnFDoH6Jp4TLVma9yJhO+HHZ0Iw== X-Received: by 2002:a5b:f52:0:b0:db3:fd6b:758b with SMTP id y18-20020a5b0f52000000b00db3fd6b758bmr2038434ybr.48.1701638968691; Sun, 03 Dec 2023 13:29:28 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:28 -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 19/45] Get rid of RNG200 timer Date: Sun, 3 Dec 2023 15:28:39 -0600 Message-Id: <20231203212905.1364036-20-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-19-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2f; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 14 +++++ hw/arm/raspi4b.c | 1 - hw/misc/bcm2838_rng200.c | 78 ++++++++++++++++------------ include/hw/arm/bcm2838_peripherals.h | 2 + include/hw/misc/bcm2838_rng200.h | 4 +- 5 files changed, 63 insertions(+), 36 deletions(-) diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index ee06214715..7c489c8e8a 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -34,6 +34,9 @@ static void bcm2838_peripherals_init(Object *obj) bc->peri_low_size); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_low_mr); + /* Random Number Generator */ + object_initialize_child(obj, "rng200", &s->rng200, TYPE_BCM2838_RNG200); + /* PCIe Host Bridge */ object_initialize_child(obj, "pcie-host", &s->pcie_host, TYPE_BCM2838_PCIE_HOST); @@ -85,6 +88,17 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) BCM2838_VC_PERI_LOW_BASE, &s->peri_low_mr_alias, 1); + /* Random Number Generator */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->rng200), errp)) { + return; + } + memory_region_add_subregion( + &s_base->peri_mr, RNG_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng200), 0)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->rng200), 0, + qdev_get_gpio_in_named(DEVICE(&s_base->ic), BCM2835_IC_GPU_IRQ, + INTERRUPT_RNG)); + /* Extended Mass Media Controller 2 */ object_property_set_uint(OBJECT(&s->emmc2), "sd-spec-version", 3, &error_abort); diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c index 2e8474e1c5..7b5385b8dd 100644 --- a/hw/arm/raspi4b.c +++ b/hw/arm/raspi4b.c @@ -67,7 +67,6 @@ static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt) /* Temporarily disable following devices until they are implemented*/ const char *to_be_removed_from_dt_as_wa[] = { - "brcm,bcm2711-rng200", "brcm,bcm2711-thermal", "brcm,bcm2711-genet-v5", }; diff --git a/hw/misc/bcm2838_rng200.c b/hw/misc/bcm2838_rng200.c index f91ea0754c..1b334b94d5 100644 --- a/hw/misc/bcm2838_rng200.c +++ b/hw/misc/bcm2838_rng200.c @@ -9,6 +9,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" +#include "qom/object_interfaces.h" #include "qapi/error.h" #include "hw/qdev-properties.h" #include "hw/misc/bcm2838_rng200.h" @@ -64,10 +65,7 @@ static const VMStateDescription vmstate_bcm2838_rng200 = { .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField[]) { - VMSTATE_UINT32(rbg_period, BCM2838Rng200State), VMSTATE_UINT32(rng_fifo_cap, BCM2838Rng200State), - VMSTATE_BOOL(use_timer, BCM2838Rng200State), - VMSTATE_ARRAY(regs, BCM2838Rng200State, N_BCM2838_RNG200_REGS, 0, vmstate_info_uint32, uint32_t), @@ -90,6 +88,15 @@ static void bcm2838_rng200_update_irq(BCM2838Rng200State *s) !!(s->regs[R_RNG_INT_ENABLE] & s->regs[R_RNG_INT_STATUS])); } +static void bcm2838_rng200_update_rbg_period(void *opaque, ClockEvent event) +{ + BCM2838Rng200State *s = (BCM2838Rng200State *)opaque; + + ptimer_transaction_begin(s->ptimer); + ptimer_set_period_from_clock(s->ptimer, s->clock, s->rng_fifo_cap * 8); + ptimer_transaction_commit(s->ptimer); +} + static void bcm2838_rng200_update_fifo(void *opaque, const void *buf, size_t size) { @@ -121,18 +128,17 @@ static void bcm2838_rng200_update_fifo(void *opaque, const void *buf, if ((num == 0) && (num_bits > 0)) { num = 1; } - if (num > 0) { - fifo8_push_all(fifo, buf, num); + fifo8_push_all(fifo, buf, num); - fifo_thld = FIELD_EX32(s->regs[R_RNG_FIFO_COUNT], - RNG_FIFO_COUNT, THRESHOLD); - if (fifo8_num_used(fifo) > fifo_thld) { - s->regs[R_RNG_INT_STATUS] = FIELD_DP32(s->regs[R_RNG_INT_STATUS], - RNG_INT_STATUS, - TOTAL_BITS_COUNT_IRQ, 1); - } + fifo_thld = FIELD_EX32(s->regs[R_RNG_FIFO_COUNT], + RNG_FIFO_COUNT, THRESHOLD); + + if (fifo8_num_used(fifo) > fifo_thld) { + s->regs[R_RNG_INT_STATUS] = FIELD_DP32(s->regs[R_RNG_INT_STATUS], + RNG_INT_STATUS, + TOTAL_BITS_COUNT_IRQ, 1); } s->regs[R_RNG_FIFO_COUNT] = FIELD_DP32(s->regs[R_RNG_FIFO_COUNT], @@ -149,9 +155,7 @@ static void bcm2838_rng200_fill_fifo(BCM2838Rng200State *s) bcm2838_rng200_update_fifo, s); } -/* This function will be implemnented in upcoming commits */ -static void bcm2838_rng200_disable_rbg(BCM2838Rng200State *s - __attribute__((unused))) +static void bcm2838_rng200_disable_rbg(void) { trace_bcm2838_rng200_disable_rbg(); } @@ -184,23 +188,21 @@ static void bcm2838_rng200_rbg_reset(BCM2838Rng200State *s) static uint32_t bcm2838_rng200_read_fifo_data(BCM2838Rng200State *s) { - Fifo8 *fifo = &s->fifo; const uint8_t *buf; + Fifo8 *fifo = &s->fifo; + uint32_t to_read = MIN(fifo8_num_used(fifo), 4); + uint8_t byte_buf[4] = {}; + uint8_t *p = byte_buf; uint32_t ret = 0; uint32_t num = 0; - uint32_t max = MIN(fifo8_num_used(fifo), sizeof(ret)); - if (max > 0) { - buf = fifo8_pop_buf(fifo, max, &num); - if ((buf != NULL) && (num > 0)) { - memcpy(&ret, buf, num); - } - } else { - qemu_log_mask( - LOG_GUEST_ERROR, - "bcm2838_rng200_read_fifo_data: FIFO is empty\n" - ); + while (to_read) { + buf = fifo8_pop_buf(fifo, to_read, &num); + memcpy(p, buf, num); + p += num; + to_read -= num; } + ret = ldl_le_p(byte_buf); s->regs[R_RNG_FIFO_COUNT] = FIELD_DP32(s->regs[R_RNG_FIFO_COUNT], RNG_FIFO_COUNT, @@ -222,7 +224,7 @@ static void bcm2838_rng200_ctrl_write(BCM2838Rng200State *s, uint32_t value) if (!currently_enabled && enable_requested) { bcm2838_rng200_enable_rbg(s); } else if (currently_enabled && !enable_requested) { - bcm2838_rng200_disable_rbg(s); + bcm2838_rng200_disable_rbg(); } } @@ -321,6 +323,14 @@ static const MemoryRegionOps bcm2838_rng200_ops = { .read = bcm2838_rng200_read, .write = bcm2838_rng200_write, .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .max_access_size = 4, + .min_access_size = 4, + }, + .valid = { + .max_access_size = 4, + .min_access_size = 4 + }, }; static void bcm2838_rng200_realize(DeviceState *dev, Error **errp) @@ -330,6 +340,13 @@ static void bcm2838_rng200_realize(DeviceState *dev, Error **errp) if (s->rng == NULL) { Object *default_backend = object_new(TYPE_RNG_BUILTIN); + if (!user_creatable_complete(USER_CREATABLE(default_backend), + errp)) { + object_unref(default_backend); + error_setg(errp, "Failed to create user creatable RNG backend"); + return; + } + object_property_add_child(OBJECT(dev), "default-backend", default_backend); object_unref(default_backend); @@ -347,13 +364,10 @@ static void bcm2838_rng200_init(Object *obj) BCM2838Rng200State *s = BCM2838_RNG200(obj); SysBusDevice *sbd = SYS_BUS_DEVICE(obj); - s->rbg_period = 250; - s->use_timer = true; - s->rng_fifo_cap = 128; s->clock = qdev_init_clock_in(DEVICE(s), "rbg-clock", - NULL, s, + bcm2838_rng200_update_rbg_period, s, ClockPreUpdate); if (s->clock == NULL) { error_setg(&error_fatal, "Failed to init RBG clock"); diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 2af96df1c6..317df005bf 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -10,6 +10,7 @@ #define BCM2838_PERIPHERALS_H #include "hw/arm/bcm2835_peripherals.h" +#include "hw/misc/bcm2838_rng200.h" #include "hw/arm/bcm2838_pcie.h" #include "hw/sd/sdhci.h" #include "hw/gpio/bcm2838_gpio.h" @@ -65,6 +66,7 @@ struct BCM2838PeripheralState { MemoryRegion mphi_mr_alias; MemoryRegion pcie_mmio_alias; + BCM2838Rng200State rng200; SDHCIState emmc2; BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; diff --git a/include/hw/misc/bcm2838_rng200.h b/include/hw/misc/bcm2838_rng200.h index 46fdba48da..8e084b7254 100644 --- a/include/hw/misc/bcm2838_rng200.h +++ b/include/hw/misc/bcm2838_rng200.h @@ -32,11 +32,9 @@ struct BCM2838Rng200State { RngBackend *rng; Clock *clock; - uint32_t rbg_period; uint32_t rng_fifo_cap; - bool use_timer; - Fifo8 fifo; + qemu_irq irq; uint32_t regs[N_BCM2838_RNG200_REGS]; From patchwork Sun Dec 3 21:28:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871088 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=kOKzDSel; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0SN6MfKz23nJ for ; Mon, 4 Dec 2023 08:34:44 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2S-0002WW-Rj; Sun, 03 Dec 2023 16:30:08 -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 1r9u1t-0001SV-TI; Sun, 03 Dec 2023 16:29:40 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1r-0005Sl-1T; Sun, 03 Dec 2023 16:29:33 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-db35caa1749so2058231276.2; Sun, 03 Dec 2023 13:29:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638969; x=1702243769; 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=Hn3L+Coco1H6/YNonu1EoHLfU3MXIUyQ7hkFiSOQ2kE=; b=kOKzDSelE5lZLnlCBRTNBLevGQKzf135NpcI7w5XNZr1XmhgWusGfFhZirN9yO33D2 6c0XXz277MpqEaGXx1oPjQymfYwK3pmmTLeLoCjsdwkz6vsSpqFeFgpYdxbc18+n0Mhv FbHj8mKiL5rhE3UPZ6imraeYzW8PNqYHkqysq7bI2TQamSHH6SnVVO7QigQp4ATvQw2s qfR9lqjHFkq/+Hx1kRuHBgifhT5srP6KkF7pAIgw2C6br1xicZ8lh7z86UGPrkzxTdqE dokffe5jEuV86XTJhoDrwxv56f+vzTeQKKe0QWpU1rBF7AHqSQl9IxZTwogQAN0xD/EA uvzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638969; x=1702243769; 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=Hn3L+Coco1H6/YNonu1EoHLfU3MXIUyQ7hkFiSOQ2kE=; b=J4fyOIim81f/GUf2d939p2yzM0z0NTGVon48IpNoEL0F+Yz8KE/+CbCI7+hoNWC0BU ZRSREmxKAYqeC9xVHdz/wlkIRQJg54w+hFLU6djb1YOLRruf/gVlyviFD2PuAanC0icG Cgpp9+ISWjWDefkwJdZxwl5Sr/WXnM4OU07jE1xFOOZF23kLJY+7LExEpgaxH6xilVI/ e2fmNunTH1hDT5ziVHuabvpMJMsE9J8nL0FXMablM2Nk+D8BVolb048BsvMYgEcgDjNQ CAFdoZzK2jGq/eWs+W4tQSYlyWvtwr4Q/0yl0FohH8Go3J4jVdW8X2WpGxh7EttfVGo6 MJ2w== X-Gm-Message-State: AOJu0Yw43YfOibCOHeKBhbPiygtPDmrub/ofn3Gj0Jh6nYqg/dbY88d8 EI6UBuQPehrb1mZyjcOlob4QlkaOqyC0wQ== X-Google-Smtp-Source: AGHT+IEAAhEeFcXIkYWnYIgPGEVkvfK4RYJz0Xh4LlNMzEYN4QCuZK8NclBuSx/28T7tg+FCAA+1sw== X-Received: by 2002:a25:db4e:0:b0:db7:dacf:3f9c with SMTP id g75-20020a25db4e000000b00db7dacf3f9cmr1851797ybf.73.1701638969654; Sun, 03 Dec 2023 13:29:29 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:29 -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 20/45] Implement BCM2838 thermal sensor Date: Sun, 3 Dec 2023 15:28:40 -0600 Message-Id: <20231203212905.1364036-21-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-20-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 27 ++++++-- hw/arm/raspi4b.c | 1 - hw/misc/bcm2838_thermal.c | 98 ++++++++++++++++++++++++++++ hw/misc/meson.build | 3 +- include/hw/arm/bcm2838_peripherals.h | 2 + include/hw/misc/bcm2838_thermal.h | 24 +++++++ 6 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 hw/misc/bcm2838_thermal.c create mode 100644 include/hw/misc/bcm2838_thermal.h diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index 7c489c8e8a..e9c6d47ba6 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -37,6 +37,9 @@ static void bcm2838_peripherals_init(Object *obj) /* Random Number Generator */ object_initialize_child(obj, "rng200", &s->rng200, TYPE_BCM2838_RNG200); + /* Thermal */ + object_initialize_child(obj, "thermal", &s->thermal, TYPE_BCM2838_THERMAL); + /* PCIe Host Bridge */ object_initialize_child(obj, "pcie-host", &s->pcie_host, TYPE_BCM2838_PCIE_HOST); @@ -75,6 +78,9 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(dev); MemoryRegion *regs_mr; MemoryRegion *mmio_mr; + MemoryRegion *rng200_mr; + MemoryRegion *thermal_mr; + qemu_irq rng_200_irq; int n; @@ -92,12 +98,20 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) if (!sysbus_realize(SYS_BUS_DEVICE(&s->rng200), errp)) { return; } - memory_region_add_subregion( - &s_base->peri_mr, RNG_OFFSET, - sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng200), 0)); - sysbus_connect_irq(SYS_BUS_DEVICE(&s->rng200), 0, - qdev_get_gpio_in_named(DEVICE(&s_base->ic), BCM2835_IC_GPU_IRQ, - INTERRUPT_RNG)); + rng200_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng200), 0); + memory_region_add_subregion(&s_base->peri_mr, RNG_OFFSET, rng200_mr); + + rng_200_irq = qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, INTERRUPT_RNG); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->rng200), 0, rng_200_irq); + + + /* THERMAL */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->thermal), errp)) { + return; + } + thermal_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->thermal), 0); + memory_region_add_subregion( &s->peri_low_mr, 0x15D2000, thermal_mr); /* Extended Mass Media Controller 2 */ object_property_set_uint(OBJECT(&s->emmc2), "sd-spec-version", 3, @@ -198,6 +212,7 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) BCM2838_MPHI_SIZE); memory_region_add_subregion(&s_base->peri_mr, BCM2838_MPHI_OFFSET, &s->mphi_mr_alias); + /* PCIe Root Complex */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie_host), errp)) { return; diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c index 7b5385b8dd..fda27d36cb 100644 --- a/hw/arm/raspi4b.c +++ b/hw/arm/raspi4b.c @@ -67,7 +67,6 @@ static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt) /* Temporarily disable following devices until they are implemented*/ const char *to_be_removed_from_dt_as_wa[] = { - "brcm,bcm2711-thermal", "brcm,bcm2711-genet-v5", }; diff --git a/hw/misc/bcm2838_thermal.c b/hw/misc/bcm2838_thermal.c new file mode 100644 index 0000000000..2301f657d0 --- /dev/null +++ b/hw/misc/bcm2838_thermal.c @@ -0,0 +1,98 @@ +/* + * BCM2838 dummy thermal sensor + * + * Copyright (C) 2022 Maksim Kopusov + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "hw/misc/bcm2838_thermal.h" +#include "hw/registerfields.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" + +REG32(STAT, 0x200) +FIELD(STAT, DATA, 0, 10) +FIELD(STAT, VALID_1, 10, 1) +FIELD(STAT, VALID_2, 16, 1) + +#define BCM2838_THERMAL_SIZE 0xf00 + +#define THERMAL_OFFSET_C 410040 +#define THERMAL_COEFF (-487.0f) +#define MILLIDEGREE_COEFF 1000 + +static uint16_t bcm2838_thermal_temp2adc(int temp_C) +{ + return (temp_C * MILLIDEGREE_COEFF - THERMAL_OFFSET_C) / THERMAL_COEFF; +} + +static uint64_t bcm2838_thermal_read(void *opaque, hwaddr addr, unsigned size) +{ + uint32_t val = 0; + + switch (addr) { + case A_STAT: + /* Temperature is always 25°C */ + val = FIELD_DP32(val, STAT, DATA, bcm2838_thermal_temp2adc(25)); + val = FIELD_DP32(val, STAT, VALID_1, 1); + val = FIELD_DP32(val, STAT, VALID_2, 1); + + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s can't access addr: 0x%"PRIx64, + TYPE_BCM2838_THERMAL, addr); + } + return val; +} + +static void bcm2838_thermal_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size) +{ + qemu_log_mask(LOG_GUEST_ERROR, "%s: write 0x%" PRIx64 + " to 0x%" HWADDR_PRIx "\n", + __func__, value, addr); +} + +static const MemoryRegionOps bcm2838_thermal_ops = { + .read = bcm2838_thermal_read, + .write = bcm2838_thermal_write, + .impl.max_access_size = 4, + .valid.min_access_size = 4, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void bcm2838_thermal_realize(DeviceState *dev, Error **errp) +{ + Bcm2838ThermalState *s = BCM2838_THERMAL(dev); + + memory_region_init_io(&s->iomem, OBJECT(s), &bcm2838_thermal_ops, + s, TYPE_BCM2838_THERMAL, BCM2838_THERMAL_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); +} + +static void bcm2838_thermal_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = bcm2838_thermal_realize; + + /* This device has no state: no need for vmstate or reset */ +} + +static const TypeInfo bcm2838_thermal_info = { + .name = TYPE_BCM2838_THERMAL, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(Bcm2838ThermalState), + .class_init = bcm2838_thermal_class_init, +}; + +static void bcm2838_thermal_register_types(void) +{ + type_register_static(&bcm2838_thermal_info); +} + +type_init(bcm2838_thermal_register_types) diff --git a/hw/misc/meson.build b/hw/misc/meson.build index b899e6b596..386471a5e4 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -91,7 +91,8 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2835_thermal.c', 'bcm2835_cprman.c', 'bcm2835_powermgt.c', - 'bcm2838_rng200.c' + 'bcm2838_rng200.c', + 'bcm2838_thermal.c' )) system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c')) diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 317df005bf..0e8465ba34 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -11,6 +11,7 @@ #include "hw/arm/bcm2835_peripherals.h" #include "hw/misc/bcm2838_rng200.h" +#include "hw/misc/bcm2838_thermal.h" #include "hw/arm/bcm2838_pcie.h" #include "hw/sd/sdhci.h" #include "hw/gpio/bcm2838_gpio.h" @@ -67,6 +68,7 @@ struct BCM2838PeripheralState { MemoryRegion pcie_mmio_alias; BCM2838Rng200State rng200; + Bcm2838ThermalState thermal; SDHCIState emmc2; BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; diff --git a/include/hw/misc/bcm2838_thermal.h b/include/hw/misc/bcm2838_thermal.h new file mode 100644 index 0000000000..bb6302a037 --- /dev/null +++ b/include/hw/misc/bcm2838_thermal.h @@ -0,0 +1,24 @@ +/* + * BCM2838 dummy thermal sensor + * + * Copyright (C) 2022 Maksim Kopusov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef BCM2838_THERMAL_H +#define BCM2838_THERMAL_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_BCM2838_THERMAL "bcm2838-thermal" +OBJECT_DECLARE_SIMPLE_TYPE(Bcm2838ThermalState, BCM2838_THERMAL) + +struct Bcm2838ThermalState { + SysBusDevice busdev; + MemoryRegion iomem; +}; + +#endif /* BCM2838_THERMAL_H */ From patchwork Sun Dec 3 21:28:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=AAJNe+HT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Ss6YKdz23n4 for ; Mon, 4 Dec 2023 08:35:09 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2K-0002Fk-3Q; Sun, 03 Dec 2023 16:30:00 -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 1r9u1v-0001Sd-Gj; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb34.google.com ([2607:f8b0:4864:20::b34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1s-0005T2-83; Sun, 03 Dec 2023 16:29:34 -0500 Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-da077db5145so1585331276.0; Sun, 03 Dec 2023 13:29:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638971; x=1702243771; 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=Wh1QnDZocCaPOy/8crynrl25nM9IxATZq1B+Q2/YqWE=; b=AAJNe+HThDNysusqmDIVHKF/DnNvVKPYe0jvUm9TFOmtH09JDuTi4gd4KRWitlp6u3 F3hy9VDMPpgnAjVOsTcLE8VUDJFK3F1L7QD/hxnKOq26y5+oF9oMiNRp6ilpXUzUgXPc hGDu4mDGgX0XUaCA+0CnIXb9eKYCLnVxeGDVRS41NtY1VYKTK+A5pyNcAW3OYXk6LAhU LrQ2uHe81Hk+nPrsRM31YMmz9L63qaSFFNLMEhLC5hGkeCUY2h40ypKeclohQJikAKzL GCw57nVvKt/mAwctjQXs3z602Qx9D+Rhtft/ZaxIYaequ5p+K2nuUbCS/tVRgtly2wWR nP3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638971; x=1702243771; 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=Wh1QnDZocCaPOy/8crynrl25nM9IxATZq1B+Q2/YqWE=; b=vPGykqruNrKZ+7aIio2IbV1vzZgUOQOiEP8WO/go+PvSNn+eFfPxtvcxV78uigP9Ue VicTT54BxuY+WrZKD3yLjJsyeEJzthiPy0jICfxC0gb42tJUOshZg18J74CW3hIW4J9+ o7VThESIDWXUDhm0FGEFYfHjPMpjma/0T/PadtbrZCuYBARjQgcbZ1KzLK6BXK2HjNc5 CycSK0/q39gV+cKp8b2ENh0odmzcfMlbK/HGdIl95DaYhrGiE7yAzj//LTfiuSxj6zMQ xZo0ruuWSZfreB7N8q2pwiI17dZQr0jgrGi9Y4i6q4pLj+1jrpfHtUUEzO11kahqpxNC Owhg== X-Gm-Message-State: AOJu0YzHYItVl+C7gieoTfeQ4JlCdNU8wa305R6iqupezmDO63dSlgTi 8Cec1z8aSp8MW/meAkx1ef7wY/5M0yMszg== X-Google-Smtp-Source: AGHT+IHzGAsF5OWRlorI5IXXQ4GLTRTsqDygHvZvoobOYu2oHHzHJ6GO9vkxhoWwps0vp/8V/UbuxQ== X-Received: by 2002:a25:ad0e:0:b0:db7:dad0:76e2 with SMTP id y14-20020a25ad0e000000b00db7dad076e2mr1229753ybi.126.1701638970759; Sun, 03 Dec 2023 13:29:30 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:30 -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 21/45] Add clock_isp stub Date: Sun, 3 Dec 2023 15:28:41 -0600 Message-Id: <20231203212905.1364036-22-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-21-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b34; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb34.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 6 ++++++ include/hw/arm/bcm2838_peripherals.h | 1 + 2 files changed, 7 insertions(+) diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index e9c6d47ba6..65a659c15c 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -17,6 +17,9 @@ #define PCIE_MMIO_ARM_OFFSET 0x600000000 #define PCIE_MMIO_SIZE 0x40000000 +#define CLOCK_ISP_OFFSET 0xc11000 +#define CLOCK_ISP_SIZE 0x100 + /* Lower peripheral base address on the VC (GPU) system bus */ #define BCM2838_VC_PERI_LOW_BASE 0x7c000000 @@ -228,6 +231,9 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) memory_region_add_subregion(get_system_memory(), PCIE_MMIO_ARM_OFFSET, &s->pcie_mmio_alias); + create_unimp(s_base, &s->clkisp, "bcm2835-clkisp", CLOCK_ISP_OFFSET, + CLOCK_ISP_SIZE); + /* GPIO */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { return; diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 0e8465ba34..20b7d1eb67 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -70,6 +70,7 @@ struct BCM2838PeripheralState { BCM2838Rng200State rng200; Bcm2838ThermalState thermal; SDHCIState emmc2; + UnimplementedDeviceState clkisp; BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; From patchwork Sun Dec 3 21:28:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nF/9sVqc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Mc15FHz23nJ for ; Mon, 4 Dec 2023 08:30:36 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2N-0002Mm-BX; Sun, 03 Dec 2023 16:30:03 -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 1r9u1y-0001Su-Gp; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb36.google.com ([2607:f8b0:4864:20::b36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1u-0005TF-0T; Sun, 03 Dec 2023 16:29:36 -0500 Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-db35caa1749so2058252276.2; Sun, 03 Dec 2023 13:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638972; x=1702243772; 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=eoic2SJMSZx65HVKTXZRhdGUrx/jLGrSNvb3iX2VkKs=; b=nF/9sVqcyrn0r5lPdkNTe4+hqGhdK4aIHYcGnm1SbaApIKomBZ2rJ6rnKr92svNwOt ieEzQ6v2MMoulFJSICEETHAAnbaFB3VIU+XaaqoeWjxbemJSvCeaPzRITF0lwR5lDUJF af9+AAFFVOOEZpi4DHVssvXTIeT8ySNhVDg2NLCdt04fqzrqB9DT+EihZiP8M27KAL3l ZLuo1T2+LZTs6TpEA1JonEWO6yRltOOXe0Wor4+m8qzdqjmq0ouNgOiTFBhZBtWNuaqm Q92Y7sIb8+0RaEdPIHf31CV6NSTnPDHBaqjnJMLwoFqrCCW8HRFi7dbEVtTEs4RMEhyx 70sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638972; x=1702243772; 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=eoic2SJMSZx65HVKTXZRhdGUrx/jLGrSNvb3iX2VkKs=; b=O59GVTPp57eNwJSvzfKLKGowseav9RlaIXkGvRwu6EDVAy9LIFT3vsB4gHxdzBF4ah cqy5Pg6ZEda15l22vv2oMyEqY+fs1bu119oYPBWJikkGtFPFlrL4bMQGvo8aBQ67M9Cn EJ4GcI79XcGuk+GW3nmSfcgJs2tzybZuB6rZhiN+VsNCcgDVNl641puO0OLhSBSLbHXR NhkaVI+p5eAVLFhTW7w3Fg+zbgB43eZ/IBCsXQiQsCql91X7Cdvtm61Z8FC9nyoHZptR NeQjv3dULnxRI8tO9cjzYcuCPOextBm7FrEOyuXdr3d0GSexqCceomyFwA8Qms83az1W rK8Q== X-Gm-Message-State: AOJu0YyEfF3zGiR5kGeHW6foqngjgPaCMQv8i1kPif/nr5JpGu/tjX9O c4E0kst/cBgP6IF5aNXURHQJ3gWDTaqZnw== X-Google-Smtp-Source: AGHT+IEhk7MyV3g1L2O5QlFnM69drkWcK+GAPAt+AmRQ7iB/O5sXbwS8ca0Nzy+/BDBhkctjwZ6nuQ== X-Received: by 2002:a25:3290:0:b0:db5:9004:cf5b with SMTP id y138-20020a253290000000b00db59004cf5bmr1665308yby.64.1701638971784; Sun, 03 Dec 2023 13:29:31 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:31 -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 22/45] Add GENET stub Date: Sun, 3 Dec 2023 15:28:42 -0600 Message-Id: <20231203212905.1364036-23-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-22-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b36; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb36.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/misc/bcm2838_thermal.c | 2 +- hw/net/bcm2838_genet.c | 99 ++++++++++++++++++++++++++++++++++ hw/net/meson.build | 2 + hw/net/trace-events | 16 ++++++ include/hw/net/bcm2838_genet.h | 40 ++++++++++++++ 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 hw/net/bcm2838_genet.c create mode 100644 include/hw/net/bcm2838_genet.h diff --git a/hw/misc/bcm2838_thermal.c b/hw/misc/bcm2838_thermal.c index 2301f657d0..372962b9ba 100644 --- a/hw/misc/bcm2838_thermal.c +++ b/hw/misc/bcm2838_thermal.c @@ -80,7 +80,7 @@ static void bcm2838_thermal_class_init(ObjectClass *klass, void *data) dc->realize = bcm2838_thermal_realize; - /* This device has no state: no need for vmstate or reset */ + /* This device has nothing to save: no need for vmstate or reset */ } static const TypeInfo bcm2838_thermal_info = { diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c new file mode 100644 index 0000000000..4420486e00 --- /dev/null +++ b/hw/net/bcm2838_genet.c @@ -0,0 +1,99 @@ +/* + * BCM2838 Gigabit Ethernet emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "net/eth.h" +#include "qapi/error.h" +#include "hw/irq.h" +#include "net/checksum.h" +#include "sysemu/dma.h" +#include "hw/net/bcm2838_genet.h" +#include "trace.h" + + +static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) +{ + uint64_t value = ~0; + + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); + + trace_bcm2838_genet_read(size, offset, value); + return value; +} + +static void bcm2838_genet_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); +} + +static const MemoryRegionOps bcm2838_genet_ops = { + .read = bcm2838_genet_read, + .write = bcm2838_genet_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = {.max_access_size = 4}, + .valid = {.min_access_size = 4}, +}; + + +static void bcm2838_genet_realize(DeviceState *dev, Error **errp) +{ + BCM2838GenetState *s = BCM2838_GENET(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + + /* Controller registers */ + memory_region_init_io(&s->regs_mr, OBJECT(s), &bcm2838_genet_ops, s, + "bcm2838_genet_regs", sizeof(s->regs)); + sysbus_init_mmio(sbd, &s->regs_mr); +} + +static void bcm2838_genet_phy_reset(BCM2838GenetState *s) +{ + trace_bcm2838_genet_phy_reset("done"); +} + +static void bcm2838_genet_reset(DeviceState *d) +{ + BCM2838GenetState *s = BCM2838_GENET(d); + + memset(&s->regs, 0x00, sizeof(s->regs)); + + trace_bcm2838_genet_reset("done"); + + bcm2838_genet_phy_reset(s); +} + +static void bcm2838_genet_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(class); + + dc->realize = bcm2838_genet_realize; + dc->reset = bcm2838_genet_reset; +} + +static const TypeInfo bcm2838_genet_info = { + .name = TYPE_BCM2838_GENET, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(BCM2838GenetState), + .class_init = bcm2838_genet_class_init, +}; + +static void bcm2838_genet_register(void) +{ + type_register_static(&bcm2838_genet_info); +} + +type_init(bcm2838_genet_register) diff --git a/hw/net/meson.build b/hw/net/meson.build index f64651c467..d513a8d029 100644 --- a/hw/net/meson.build +++ b/hw/net/meson.build @@ -72,4 +72,6 @@ system_ss.add(when: 'CONFIG_ROCKER', if_true: files( system_ss.add(when: 'CONFIG_ALL', if_true: files('rocker/qmp-norocker.c')) system_ss.add(files('rocker/rocker-hmp-cmds.c')) +system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_genet.c')) + subdir('can') diff --git a/hw/net/trace-events b/hw/net/trace-events index 387e32e153..4081bd09d6 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -494,3 +494,19 @@ xen_netdev_connect(int dev, unsigned int tx, unsigned int rx, int port) "vif%u t xen_netdev_frontend_changed(const char *dev, int state) "vif%s state %d" xen_netdev_tx(int dev, int ref, int off, int len, unsigned int flags, const char *c, const char *d, const char *m, const char *e) "vif%u ref %u off %u len %u flags 0x%x%s%s%s%s" xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d status %d flags 0x%x" +# bcm2838_genet.c +bcm2838_genet_read(unsigned int size, uint64_t offset, uint64_t value) "%u bytes @ 0x%04" PRIx64 ": 0x%016" PRIx64 +bcm2838_genet_write(unsigned int size, uint64_t offset, uint64_t value) "%u bytes @ 0x%04" PRIx64 ": 0x%016" PRIx64 +bcm2838_genet_can_receive(const char *state) "receive is %s" +bcm2838_genet_receive(ssize_t bytes_received) "%zd bytes received" +bcm2838_genet_phy_update_link(const char *link_state) "link is %s" +bcm2838_genet_phy_reset(const char *status) "PHY reset %s" +bcm2838_genet_reset(const char *status) "MAC reset %s" +bcm2838_genet_mac_address(const char *info) "%s" +bcm2838_genet_tx_dma(const char *dma_state) "TX DMA %s" +bcm2838_genet_tx_dma_ring(uint32_t ring_en) "TX DMA enabled rings: 0x%05x" +bcm2838_genet_tx_dma_ring_buf(uint32_t ring_buf_en) "TX DMA enabled ring buffers: 0x%05x" +bcm2838_genet_tx_dma_ring_active(unsigned int ring, const char *ring_state) "ring %u is %s" +bcm2838_genet_tx_request(unsigned int ring_idx, uint32_t prod_idx, uint32_t cons_idx) "ring %u, PROD_INDEX %u, CONS_INDEX %u" +bcm2838_genet_tx(unsigned int ring_idx, uint64_t desc_idx, uint32_t desc_status, uint64_t data_addr) "ring %u, descriptor %" PRIu64 ": 0x%08x, data @ 0x%08" PRIx64 +bcm2838_genet_rx_dma_ring_active(unsigned int ring, const char *ring_state) "ring %u is %s" diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h new file mode 100644 index 0000000000..d166a5c24c --- /dev/null +++ b/include/hw/net/bcm2838_genet.h @@ -0,0 +1,40 @@ +/* + * BCM2838 Gigabit Ethernet emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BCM2838_GENET_H +#define BCM2838_GENET_H + +#include "net/net.h" +#include "hw/sysbus.h" + +#define TYPE_BCM2838_GENET "bcm2838-genet" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) + +#define BCM2838_GENET_REV_MAJOR 6 +#define BCM2838_GENET_REV_MINOR 0 + +typedef struct { + uint8_t stub_area[0x10000]; /* temporary stub */ +} BCM2838GenetRegs; + +struct BCM2838GenetState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + + MemoryRegion regs_mr; + AddressSpace dma_as; + + BCM2838GenetRegs regs; + + qemu_irq irq_default; + qemu_irq irq_prio; +}; + +#endif /* BCM2838_GENET_H */ From patchwork Sun Dec 3 21:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871085 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cgSHkGrj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0RR4xYKz23nJ for ; Mon, 4 Dec 2023 08:33:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2K-0002Gp-K2; Sun, 03 Dec 2023 16:30:00 -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 1r9u1y-0001Sr-GV; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1u-0005TU-4r; Sun, 03 Dec 2023 16:29:36 -0500 Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-db54ec0c7b8so1828590276.0; Sun, 03 Dec 2023 13:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638973; x=1702243773; 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=Xkr/gnxxaICGpe6iHiYAh3AvCqlJB8T1ravIgTidKoY=; b=cgSHkGrjByTZHJZwS3qOwGTK9FaaANfyDqVxAuv4DJipm6B7t0N7JzKRO+X3rIf7si +bS1n/YzVht2b5vrNAfWznpjA5+E0p0Fu+oDrm4jXQfs9CwmMrtOJKlQKglSfFjhfut2 3C5RN7Pquool2Td4xmlrTYF26YYxYMUQG5kEGTsKAvBe9ahCit+AHjocYhapvDQuatPV aUS5nGsjxPPERVywAxcsAve6yQ/qNnJxlwo2/GlLNnYkQEAYXh+xDwaz7bY+KA0y42ap M5foWK4iVy8wJpzjPr0F0ipD/WBs+SC5e+o2iGa6bFfzfrIztM9fgO4CpR9fK3BSlRJA /F8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638973; x=1702243773; 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=Xkr/gnxxaICGpe6iHiYAh3AvCqlJB8T1ravIgTidKoY=; b=IBhoWL/X/QP+Kw7y5DLnZ4XpG8QmO7+1kGYOFCVk4qYMcjRZBB2nOHOdPJjE7udh1e m4fX2OXILFXxJ1kb+APRPuF4TFL18PHB1PIgV8S5xF48FzF7Gaz7IPEIBbnttJtEv/wi 5cEvuznn4KtntCcGTcEkHi5+2Qxmz7FbH9EDBwmqzDSYtmVZpEkE0uj6x/eQkytxHa7G dgIiYiio4RWgumcXILbZDs7AN9eqjWvg6np5hxmsbSw0Z2lxOKcoxM8KwtYLuC+AW7qX 5D1ozj77Ww89B+/vLHDQKpoERH0glLi1RUc6O83I4YCJTZd4VtNWbo7mcuAnpDjZvfzv sswg== X-Gm-Message-State: AOJu0YyqA7lkcPxTLhApsW5W2/C9wbwX34cHtR1lOQ6pLqVAF3tlecjd fJN6xpEs/r04htqgVIBcYvoobTVZ21Sa0g== X-Google-Smtp-Source: AGHT+IGq9pyc66n0IFEyg7QpyeY0Yr4k57lz/LniO3bZrLZNepiL3qvmcxYSokEucqxVBDH5AHKcJA== X-Received: by 2002:a25:d70f:0:b0:db5:4743:7c37 with SMTP id o15-20020a25d70f000000b00db547437c37mr1974427ybg.21.1701638972775; Sun, 03 Dec 2023 13:29:32 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:32 -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 23/45] Add GENET register structs. Part 1 Date: Sun, 3 Dec 2023 15:28:43 -0600 Message-Id: <20231203212905.1364036-24-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-23-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2e; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2e.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 37 ++++++++++++++++ include/hw/net/bcm2838_genet.h | 77 +++++++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 4420486e00..0d98d1b30e 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -15,9 +15,46 @@ #include "hw/irq.h" #include "net/checksum.h" #include "sysemu/dma.h" +#include "hw/registerfields.h" #include "hw/net/bcm2838_genet.h" #include "trace.h" +REG32(GENET_SYS_REV_CTRL, 0) +FIELD(GENET_SYS_REV_CTRL, GPHY_REV, 0, 16) +FIELD(GENET_SYS_REV_CTRL, MINOR_REV, 16, 4) +FIELD(GENET_SYS_REV_CTRL, RSVD_20_23, 20, 4) +FIELD(GENET_SYS_REV_CTRL, MAJOR_REV, 24, 4) +FIELD(GENET_SYS_REV_CTRL, RSVD_28_31, 28, 4) + +REG32(GENET_INTRL_0, 0) +FIELD(GENET_INTRL_0, SCB, 0, 1) +FIELD(GENET_INTRL_0, EPHY, 1, 1) +FIELD(GENET_INTRL_0, PHY_DET_R, 2, 1) +FIELD(GENET_INTRL_0, PHY_DET_F, 3, 1) +FIELD(GENET_INTRL_0, LINK_UP, 4, 1) +FIELD(GENET_INTRL_0, LINK_DOWN, 5, 1) +FIELD(GENET_INTRL_0, UMAC, 6, 1) +FIELD(GENET_INTRL_0, UMAC_TSV, 7, 1) +FIELD(GENET_INTRL_0, TBUF_UNDERRUN, 8, 1) +FIELD(GENET_INTRL_0, RBUF_OVERFLOW, 9, 1) +FIELD(GENET_INTRL_0, HFB_SM, 10, 1) +FIELD(GENET_INTRL_0, HFB_MM, 11, 1) +FIELD(GENET_INTRL_0, MPD_R, 12, 1) +FIELD(GENET_INTRL_0, RXDMA_MBDONE, 13, 1) +FIELD(GENET_INTRL_0, RXDMA_PDONE, 14, 1) +FIELD(GENET_INTRL_0, RXDMA_BDONE, 15, 1) +FIELD(GENET_INTRL_0, TXDMA_MBDONE, 16, 1) +FIELD(GENET_INTRL_0, TXDMA_PDONE, 17, 1) +FIELD(GENET_INTRL_0, TXDMA_BDONE, 18, 1) +FIELD(GENET_INTRL_0, RSVD_19_22, 19, 4) +FIELD(GENET_INTRL_0, MDIO_DONE, 23, 1) +FIELD(GENET_INTRL_0, MDIO_ERROR, 24, 1) +FIELD(GENET_INTRL_0, RSVD_25_31, 25, 4) + +REG32(GENET_INTRL_1, 0) +FIELD(GENET_INTRL_1, TX_INTRS, 0, 16) +FIELD(GENET_INTRL_1, RX_INTRS, 16, 16) + static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) { diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index d166a5c24c..f583818399 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -19,7 +19,82 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_REV_MINOR 0 typedef struct { - uint8_t stub_area[0x10000]; /* temporary stub */ + uint32_t rev_ctrl; + uint32_t port_ctrl; + uint32_t rbuf_flush_ctrl; + uint32_t tbuf_flush_ctrl; + uint32_t reserved_0x10[12]; +} BCM2838GenetRegsSys; + +typedef struct { + uint32_t reserved_0x0[16]; +} BCM2838GenetRegsGrBridge; + +typedef struct { + uint32_t pwr_mgmt; + uint32_t reserved_0x4[2]; + uint32_t rgmii_oob_ctrl; + uint32_t reserved_0x10[3]; + uint32_t gphy_ctrl; + uint32_t reserved_0x20[24]; +} BCM2838GenetRegsExt; + +typedef struct { + uint32_t stat; + uint32_t set; + uint32_t clear; + uint32_t mask_status; + uint32_t mask_set; + uint32_t mask_clear; + uint32_t reserved_0x18[10]; +} BCM2838GenetRegsIntrl0; + +typedef struct { + uint32_t stat; + uint32_t set; + uint32_t clear; + uint32_t mask_status; + uint32_t mask_set; + uint32_t mask_clear; + uint32_t reserved_0x18[10]; +} BCM2838GenetRegsIntrl1; + +typedef struct { + uint32_t ctrl; + uint32_t reserved_0x4[2]; + uint32_t status; + uint32_t reserved_0x10; + uint32_t chk_ctrl; + uint32_t reserved_0x18[31]; + uint32_t ovfl_cnt; + uint32_t err_cnt; + uint32_t energy_ctrl; + uint32_t reserved_0xA0[5]; + uint32_t size_ctrl; + uint32_t reserved_0xB8[18]; +} BCM2838GenetRegsRbuf; + +typedef struct { + uint32_t ctrl; + uint32_t reserved_0x4[2]; + uint32_t bp_mc; + uint32_t reserved_0x10; + uint32_t energy_ctrl; + uint32_t reserved_0x18[58]; +} BCM2838GenetRegsTbuf; + +typedef struct { + BCM2838GenetRegsSys sys; + BCM2838GenetRegsGrBridge gr_bridge; + BCM2838GenetRegsExt ext; + uint32_t reserved_0x100[64]; + BCM2838GenetRegsIntrl0 intrl0; + BCM2838GenetRegsIntrl1 intrl1; + uint32_t reserved_0x280[32]; + BCM2838GenetRegsRbuf rbuf; + uint32_t reserved_0x400[128]; + BCM2838GenetRegsTbuf tbuf; + uint32_t reserved_0x700[64]; } BCM2838GenetRegs; struct BCM2838GenetState { From patchwork Sun Dec 3 21:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hUbzvZfq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0TN1pDWz23mf for ; Mon, 4 Dec 2023 08:35:36 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2K-0002H8-Pq; Sun, 03 Dec 2023 16:30:00 -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 1r9u1y-0001Sv-HE; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1v-0005Tp-KM; Sun, 03 Dec 2023 16:29:38 -0500 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-dae7cc31151so2204698276.3; Sun, 03 Dec 2023 13:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638974; x=1702243774; 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=+Rjbw5RYP1TnoKVdXAKQhTrSFNyGeuEqSS68XHm6tGg=; b=hUbzvZfqA/tg8NoGMr+8xi7P+meijM72SE1sDUtrfwbyDmddKNKzosvxeM07SNkPgx tAfrMHdiuhbM/5GdJ5Vr7fU1lq0/wUWrj7Rq4dLmDb7v83mNewYeV6TE6fAiv49S0bXV N3nKZC8/WkSeNQUpqPq5c34tr/Hy7xrkjbrto+mjsKv8ijKXGAAr+zPBHmBVMzJLrmR5 LqkdOAJ6xQRKqt0Fy353werwI/HkYYZqq7Y0GdY6HzTc8I83KC1ORdTVOCwog7hYCOjd QWCuWBc9UhtUjiz4PxZ51w3i9nHZY9HPtpwrXo3nUjBbrKYSss6YfbzR2qilObAIIB8I 5XRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638974; x=1702243774; 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=+Rjbw5RYP1TnoKVdXAKQhTrSFNyGeuEqSS68XHm6tGg=; b=pYzapqkrI3q6N1rZmFNcvAGYvSl4OBhpM7m/JbHxFtstL0K3InR9rGQLQV0epFrbw4 SNmxtoKlWbSlTuITZoB7y4gohkuC8iGaEtj/6Ahg+rqQkS+6EVew073Y90ebixkYVyoY FLIpTSQ6ioSMXzfaatWOwE1xvPfb79/Wd5lP4vkkzmDDJN9Ih9mvZOpODCNdnonn6RvM mK+PPGHPARQpnAK1WJ+Y1auXSt2ECBSflyaxJTxF9B5g/s2vHDdE1bg1xd5VfdMpy7SD uZB3P7EhQHE/WBj0rikzC6XnHv/0R62hJzKBLxWjYwjkNNfkJo22SSla0DVHXzFIBav+ k9AQ== X-Gm-Message-State: AOJu0YyfNowzTAAfAXLOxWvIFkxnS5FZzqjzNAVnDgiLVRT6Ewk0b4Pc xSXsb5pTdbmuwy8Y5po2bBwmjzZoW9aDQA== X-Google-Smtp-Source: AGHT+IHyfMP/j3OBWveyj15Xp2J63T3dd3sRcR5DGhYGq92mfuM+cxASoT0fGDBGyiHI56A6AJvh4A== X-Received: by 2002:a05:6902:24f:b0:db7:dacf:6fd1 with SMTP id k15-20020a056902024f00b00db7dacf6fd1mr1973699ybs.89.1701638973905; Sun, 03 Dec 2023 13:29:33 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:33 -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 24/45] Add GENET register structs. Part 2 Date: Sun, 3 Dec 2023 15:28:44 -0600 Message-Id: <20231203212905.1364036-25-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-24-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b32; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb32.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 89 ++++++++++++++++++++++++++++++++++ include/hw/net/bcm2838_genet.h | 89 ++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 0d98d1b30e..9a99f34c4a 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -19,6 +19,7 @@ #include "hw/net/bcm2838_genet.h" #include "trace.h" +/* GENET layouts */ REG32(GENET_SYS_REV_CTRL, 0) FIELD(GENET_SYS_REV_CTRL, GPHY_REV, 0, 16) FIELD(GENET_SYS_REV_CTRL, MINOR_REV, 16, 4) @@ -55,6 +56,94 @@ REG32(GENET_INTRL_1, 0) FIELD(GENET_INTRL_1, TX_INTRS, 0, 16) FIELD(GENET_INTRL_1, RX_INTRS, 16, 16) +REG32(GENET_UMAC_CMD, 0) +FIELD(GENET_UMAC_CMD, TX_EN, 0, 1) +FIELD(GENET_UMAC_CMD, RX_EN, 1, 1) +FIELD(GENET_UMAC_CMD, SPEED, 2, 2) +FIELD(GENET_UMAC_CMD, PROMISC, 4, 1) +FIELD(GENET_UMAC_CMD, PAD_EN, 5, 1) +FIELD(GENET_UMAC_CMD, CRC_FWD, 6, 1) +FIELD(GENET_UMAC_CMD, PAUSE_FWD, 7, 1) +FIELD(GENET_UMAC_CMD, RX_PAUSE_IGNORE, 8, 1) +FIELD(GENET_UMAC_CMD, TX_ADDR_INS, 9, 1) +FIELD(GENET_UMAC_CMD, HD_EN, 10, 1) +FIELD(GENET_UMAC_CMD, SW_RESET_OLD, 11, 1) +FIELD(GENET_UMAC_CMD, RSVD_12, 12, 1) +FIELD(GENET_UMAC_CMD, SW_RESET, 13, 1) +FIELD(GENET_UMAC_CMD, RSVD_14, 14, 1) +FIELD(GENET_UMAC_CMD, LCL_LOOP_EN, 15, 1) +FIELD(GENET_UMAC_CMD, RSVD_16_21, 16, 6) +FIELD(GENET_UMAC_CMD, AUTO_CONFIG, 22, 1) +FIELD(GENET_UMAC_CMD, CNTL_FRM_EN, 23, 1) +FIELD(GENET_UMAC_CMD, NO_LEN_CHK, 24, 1) +FIELD(GENET_UMAC_CMD, RMT_LOOP_EN, 25, 1) +FIELD(GENET_UMAC_CMD, RX_ERR_DISC, 26, 1) +FIELD(GENET_UMAC_CMD, PRBL_EN, 27, 1) +FIELD(GENET_UMAC_CMD, TX_PAUSE_IGNORE, 28, 1) +FIELD(GENET_UMAC_CMD, TX_RX_EN, 29, 1) +FIELD(GENET_UMAC_CMD, RUNT_FILTER_DIS, 30, 1) +FIELD(GENET_UMAC_CMD, RSVD_31, 31, 1) + +REG32(GENET_UMAC_MAC_0, 0) +FIELD(GENET_UMAC_MAC_0, ADDR_3, 0, 8) +FIELD(GENET_UMAC_MAC_0, ADDR_2, 8, 8) +FIELD(GENET_UMAC_MAC_0, ADDR_1, 16, 8) +FIELD(GENET_UMAC_MAC_0, ADDR_0, 24, 8) + +REG32(GENET_UMAC_MAC_1, 0) +FIELD(GENET_UMAC_MAC_1, ADDR_5, 0, 8) +FIELD(GENET_UMAC_MAC_1, ADDR_4, 8, 8) +FIELD(GENET_UMAC_MAC_1, RSVD_16_31, 16, 8) + +REG32(GENET_UMAC_MDIO_CMD, 0) +FIELD(GENET_UMAC_MDIO_CMD, REG_DATA, 0, 16) +FIELD(GENET_UMAC_MDIO_CMD, REG_ID, 16, 5) +FIELD(GENET_UMAC_MDIO_CMD, PHY_ID, 21, 5) +FIELD(GENET_UMAC_MDIO_CMD, WR, 26, 1) +FIELD(GENET_UMAC_MDIO_CMD, RD, 27, 1) +FIELD(GENET_UMAC_MDIO_CMD, RD_FAIL, 28, 1) +FIELD(GENET_UMAC_MDIO_CMD, START_BUSY, 29, 1) +FIELD(GENET_UMAC_MDIO_CMD, RSVD_30_31, 30, 2) + +REG32(GENET_DMA_RING_CFG, 0) +FIELD(GENET_DMA_RING_CFG, EN, 0, 17) +FIELD(GENET_DMA_RING_CFG, RSVD_17_31, 17, 14) + +REG32(GENET_DMA_CTRL, 0) +FIELD(GENET_DMA_CTRL, EN, 0, 1) +FIELD(GENET_DMA_CTRL, RING_BUF_EN, 1, 17) +FIELD(GENET_DMA_CTRL, RSVD_18_19, 18, 2) +FIELD(GENET_DMA_CTRL, TSB_SWAP_EN, 20, 1) +FIELD(GENET_DMA_CTRL, RSVD_21_31, 21, 11) + +REG32(GENET_DMA_PROD_INDEX, 0) +FIELD(GENET_DMA_PROD_INDEX, INDEX, 0, 16) +FIELD(GENET_DMA_PROD_INDEX, DISCARD_CNT, 16, 16) + +REG32(GENET_DMA_CONS_INDEX, 0) +FIELD(GENET_DMA_CONS_INDEX, INDEX, 0, 16) +FIELD(GENET_DMA_CONS_INDEX, RSVD_16_31, 16, 16) + +REG32(GENET_DMA_STATUS, 0) +FIELD(GENET_DMA_STATUS, DISABLED, 0, 1) +FIELD(GENET_DMA_STATUS, DESC_RAM_INIT_BUSY, 1, 1) +FIELD(GENET_DMA_STATUS, RSVD_2_31, 2, 30) + +REG32(GENET_RDMA_LENGTH_STATUS, 0) +FIELD(GENET_RDMA_LENGTH_STATUS, OVERRUN, 0, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, CRC_ERROR, 1, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, RXERR, 2, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, NO, 3, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, LG, 4, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, MULTICAST, 5, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, BROADCAST, 6, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, RSVD_7_11, 7, 5) +FIELD(GENET_RDMA_LENGTH_STATUS, WRAP, 12, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, SOP, 13, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, EOP, 14, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, OWN, 15, 1) +FIELD(GENET_RDMA_LENGTH_STATUS, BUFLENGTH, 16, 12) +FIELD(GENET_RDMA_LENGTH_STATUS, RSVD_28_31, 29, 4) static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) { diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index f583818399..736b4d1757 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -18,6 +18,10 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_REV_MAJOR 6 #define BCM2838_GENET_REV_MINOR 0 +#define BCM2838_GENET_DMA_DESC_CNT 256 +#define BCM2838_GENET_DMA_RING_CNT 17 +#define BCM2838_GENET_DMA_RING_DEFAULT (BCM2838_GENET_DMA_RING_CNT - 1) + typedef struct { uint32_t rev_ctrl; uint32_t port_ctrl; @@ -83,6 +87,88 @@ typedef struct { uint32_t reserved_0x18[58]; } BCM2838GenetRegsTbuf; +typedef struct { + uint32_t reserved_0x0; + uint32_t hd_bkp_ctrl; + uint32_t cmd; + uint32_t mac0; + uint32_t mac1; + uint32_t max_frame_len; + uint32_t pause_quanta; + uint32_t reserved_0x1C[10]; + uint32_t mode; + uint32_t frm_tag0; + uint32_t frm_tag1; + uint32_t reserved_0x50[3]; + uint32_t tx_ipg_len; + uint32_t reserved_0x60; + uint32_t eee_ctrl; + uint32_t eee_lpi_timer; + uint32_t eee_wake_timer; + uint32_t eee_ref_count; + uint32_t reserved_0x74; + uint32_t rx_ipg_inv; + uint32_t reserved_0x7C[165]; + uint32_t macsec_prog_tx_crc; + uint32_t macsec_ctrl; + uint32_t reserved_0x318[6]; + uint32_t pause_ctrl; + uint32_t tx_flush; + uint32_t rx_fifo_status; + uint32_t tx_fifo_status; + uint32_t reserved_0x340[48]; + uint32_t mib[96]; + uint32_t mib_ctrl; + uint32_t reserved_0x584[36]; + uint32_t mdio_cmd; + uint32_t reserved_0x618[2]; + uint32_t mpd_ctrl; + uint32_t mpd_pw_ms; + uint32_t mpd_pw_ls; + uint32_t reserved_0x62C[3]; + uint32_t mdf_err_cnt; + uint32_t reserved_0x63C[5]; + uint32_t mdf_ctrl; + uint32_t mdf_addr; + uint32_t reserved_0x658[106]; +} BCM2838GenetRegsUmac; + +typedef struct { + uint32_t length_status; + uint32_t address_lo; + uint32_t address_hi; +} BCM2838GenetRdmaDesc; + +typedef struct { + uint32_t write_ptr; + uint32_t write_ptr_hi; + uint32_t prod_index; + uint32_t cons_index; + uint32_t ring_buf_size; + uint32_t start_addr; + uint32_t start_addr_hi; + uint32_t end_addr; + uint32_t end_addr_hi; + uint32_t mbuf_done_tresh; + uint32_t xon_xoff_tresh; + uint32_t read_ptr; + uint32_t read_ptr_hi; + uint32_t reserved_0x34[3]; +} BCM2838GenetRdmaRing; + +typedef struct { + BCM2838GenetRdmaDesc descs[BCM2838_GENET_DMA_DESC_CNT]; + BCM2838GenetRdmaRing rings[BCM2838_GENET_DMA_RING_CNT]; + uint32_t ring_cfg; + uint32_t ctrl; + uint32_t status; + uint32_t scb_burst_size; + uint32_t reserved_0x1050[7]; + uint32_t ring_timeout[17]; + uint32_t index2ring[8]; + uint32_t reserved_0x10D0[972]; +} BCM2838GenetRegsRdma; + typedef struct { BCM2838GenetRegsSys sys; BCM2838GenetRegsGrBridge gr_bridge; @@ -95,6 +181,9 @@ typedef struct { uint32_t reserved_0x400[128]; BCM2838GenetRegsTbuf tbuf; uint32_t reserved_0x700[64]; + BCM2838GenetRegsUmac umac; + uint32_t reserved_0x1000[1024]; + BCM2838GenetRegsRdma rdma; } BCM2838GenetRegs; struct BCM2838GenetState { From patchwork Sun Dec 3 21:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gJfPavTm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0SP0ltRz23p4 for ; Mon, 4 Dec 2023 08:34:45 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2N-0002N9-Pi; Sun, 03 Dec 2023 16:30:03 -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 1r9u1y-0001Sw-IK; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1w-0005U0-GG; Sun, 03 Dec 2023 16:29:38 -0500 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-db539f21712so1817985276.1; Sun, 03 Dec 2023 13:29:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638975; x=1702243775; 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=3GUF+BYnLIFgUYZSAH+PcH4wY20N6XyOgpSpQ20MSSg=; b=gJfPavTmcdz/2+6UqF/mI0fs2m+EN2zux89xVg/EA25Ol9LTjBk8nOLma7AFVFEfZ6 d+nxaKphzn575ShtDxpSdHmxXLLmgSQjA6Puwp/boowPjIj3gVEIEt7aTxszuro3fB9W 0n/U0psA6rl3cyMd4NT2lG8dW9Dqb6biOq5ziA4tD+Dd6kI2tavVlzz7emwKJR8rvsgu 6y/GRTO3cIIiPbHdulHfssK54JlrW8uksDe2tl7PXN7F2oXk5CK/Y4eJq0ptphsbiAWy gi/TNulWl7yUG5gD4yDXiwBEfknZHIuMLWtjX/xr62Ih2Uxin5f7yfwzCr5mgAFuVc1p toqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638975; x=1702243775; 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=3GUF+BYnLIFgUYZSAH+PcH4wY20N6XyOgpSpQ20MSSg=; b=weQtAoRVkUp03vbFUCOWj+puWyVZe7LIajptExKT8EOikc1+spoYu2M4w+2s9XOs2E jkEF885r35/GhABpMncK81PufMK1aqODvvagpJwueqi2DiaFG24N9Jw/dJIiHM9kHfJK NlLZXUcIhzZpZk+PyT4t74/43x4fY8oTDafJANhmTsN7yQv7xvvoHPIn+dMmEy85g3zI umA55hP3SA8ypGafPchCV8YQ1ly+JWJjvVMLY7TbC2h7Gl9nEqEOUoCssqUCBcikS869 nYtCrGpMVk1unetuPU4tkcUQd6Ucig53grGGZHG7nSw00QzkUsGn93z/qYklKE15miOx 2aBg== X-Gm-Message-State: AOJu0YzMx/c77kxm6md+R999IZy2xmIOOar09SUsZXOEynUvA/7r8mno 1y93FLhGRj/eg3JShgWkEFZdNwzkuaa5MA== X-Google-Smtp-Source: AGHT+IHsSIobkau5VAoHeIZLz/ksBBSknVKivQUpUt5naQbift82CHd89njJOHSLGUuAY5RyCWhsUQ== X-Received: by 2002:a25:824c:0:b0:db7:dacf:6e6 with SMTP id d12-20020a25824c000000b00db7dacf06e6mr1856322ybn.42.1701638974993; Sun, 03 Dec 2023 13:29:34 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:34 -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 25/45] Add GENET register structs. Part 3 Date: Sun, 3 Dec 2023 15:28:45 -0600 Message-Id: <20231203212905.1364036-26-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-25-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b32; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb32.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 88 ++++++++++++++++++++++++++++++++++ include/hw/net/bcm2838_genet.h | 88 ++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 9a99f34c4a..be899b68f8 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -145,6 +145,94 @@ FIELD(GENET_RDMA_LENGTH_STATUS, OWN, 15, 1) FIELD(GENET_RDMA_LENGTH_STATUS, BUFLENGTH, 16, 12) FIELD(GENET_RDMA_LENGTH_STATUS, RSVD_28_31, 29, 4) +REG32(GENET_TDMA_LENGTH_STATUS, 0) +FIELD(GENET_TDMA_LENGTH_STATUS, RSVD_0_3, 0, 4) +FIELD(GENET_TDMA_LENGTH_STATUS, DO_CSUM, 4, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, OW_CRC, 5, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, APPEND_CRC, 6, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, RSVD_7_8, 7, 2) +FIELD(GENET_TDMA_LENGTH_STATUS, UNDERRUN, 9, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, RSVD_10_11, 10, 2) +FIELD(GENET_TDMA_LENGTH_STATUS, WRAP, 12, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, SOP, 13, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, EOP, 14, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, OWN, 15, 1) +FIELD(GENET_TDMA_LENGTH_STATUS, BUFLENGTH, 16, 12) +FIELD(GENET_TDMA_LENGTH_STATUS, RSVD_28_31, 29, 4) + +REG16(GENET_PHY_BMCR, 0) +FIELD(GENET_PHY_BMCR, RSVD_0_5, 0, 6) +FIELD(GENET_PHY_BMCR, SPEED1000, 6, 1) +FIELD(GENET_PHY_BMCR, CTST, 7, 1) +FIELD(GENET_PHY_BMCR, FULLDPLX, 8, 1) +FIELD(GENET_PHY_BMCR, ANRESTART, 9, 1) +FIELD(GENET_PHY_BMCR, ISOLATE, 10, 1) +FIELD(GENET_PHY_BMCR, PDOWN, 11, 1) +FIELD(GENET_PHY_BMCR, AENABLE, 12, 1) +FIELD(GENET_PHY_BMCR, SPEED100, 13, 1) +FIELD(GENET_PHY_BMCR, LOOPBACK, 14, 1) +FIELD(GENET_PHY_BMCR, RESET, 15, 1) + +REG16(GENET_PHY_BMSR, 0) +FIELD(GENET_PHY_BMSR, ERCAP, 0, 1) +FIELD(GENET_PHY_BMSR, JCD, 1, 1) +FIELD(GENET_PHY_BMSR, LSTATUS, 2, 1) +FIELD(GENET_PHY_BMSR, ANEGCAPABLE, 3, 1) +FIELD(GENET_PHY_BMSR, RFAULT, 4, 1) +FIELD(GENET_PHY_BMSR, ANEGCOMPLETE, 5, 1) +FIELD(GENET_PHY_BMSR, RSVD_6_7, 6, 2) +FIELD(GENET_PHY_BMSR, ESTATEN, 8, 1) +FIELD(GENET_PHY_BMSR, _100HALF2, 9, 1) +FIELD(GENET_PHY_BMSR, _100FULL2, 10, 1) +FIELD(GENET_PHY_BMSR, _10HALF, 11, 1) +FIELD(GENET_PHY_BMSR, _10FULL, 12, 1) +FIELD(GENET_PHY_BMSR, _100HALF, 13, 1) +FIELD(GENET_PHY_BMSR, _100FULL, 14, 1) +FIELD(GENET_PHY_BMSR, _10BASE4, 15, 1) + +REG16(GENET_PHY_LPA, 0) +FIELD(GENET_PHY_LPA, SLCT, 0, 5) +FIELD(GENET_PHY_LPA, _10HALF_1000XFULL, 5, 1) +FIELD(GENET_PHY_LPA, _10FULL_1000XHALF, 6, 1) +FIELD(GENET_PHY_LPA, _100HALF_1000XPAUSE, 7, 1) +FIELD(GENET_PHY_LPA, _100FULL_1000XPAUSE_ASYM, 8, 1) +FIELD(GENET_PHY_LPA, _100BASE4, 9, 1) +FIELD(GENET_PHY_LPA, PAUSE_CAP, 10, 1) +FIELD(GENET_PHY_LPA, PAUSE_ASYM, 11, 1) +FIELD(GENET_PHY_LPA, RSVD_12, 12, 1) +FIELD(GENET_PHY_LPA, RFAULT, 13, 1) +FIELD(GENET_PHY_LPA, LPACK, 14, 1) +FIELD(GENET_PHY_LPA, NPAGE, 15, 1) + +REG16(GENET_PHY_STAT_1000, 0) +FIELD(GENET_PHY_STAT_1000, RSVD_0_9, 0, 10) +FIELD(GENET_PHY_STAT_1000, HALF, 10, 1) +FIELD(GENET_PHY_STAT_1000, FULL, 11, 1) +FIELD(GENET_PHY_STAT_1000, REMRXOK, 12, 1) +FIELD(GENET_PHY_STAT_1000, LOCALRXOK, 13, 1) +FIELD(GENET_PHY_STAT_1000, MSRES, 14, 1) +FIELD(GENET_PHY_STAT_1000, MSFAIL, 15, 1) + +REG16(GENET_PHY_AUX_CTRL_0, 0) +FIELD(GENET_PHY_AUX_CTRL_0, REG_ID_MASK, 0, 3) +FIELD(GENET_PHY_AUX_CTRL_0, RSVD_3, 3, 1) +FIELD(GENET_PHY_AUX_CTRL_0, REG_DATA, 4, 8) +FIELD(GENET_PHY_AUX_CTRL_0, REG_ID, 12, 3) +FIELD(GENET_PHY_AUX_CTRL_0, MISC_WREN, 15, 1) + +REG16(GENET_PHY_AUX_CTRL_1, 0) +FIELD(GENET_PHY_AUX_CTRL_1, RSVD_0_3, 0, 4) +FIELD(GENET_PHY_AUX_CTRL_1, REG_DATA, 4, 12) + +REG16(GENET_PHY_SHADOW, 0) +FIELD(GENET_PHY_SHADOW, REG_DATA, 0, 10) +FIELD(GENET_PHY_SHADOW, REG_ID, 10, 5) +FIELD(GENET_PHY_SHADOW, WR, 15, 1) + +REG16(GENET_PHY_EXP_SEL, 0) +FIELD(GENET_PHY_EXP_SEL, REG_ID, 0, 8) +FIELD(GENET_PHY_EXP_SEL, BLOCK_ID, 8, 8) + static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) { uint64_t value = ~0; diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index 736b4d1757..1bd004785a 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -22,6 +22,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_DMA_RING_CNT 17 #define BCM2838_GENET_DMA_RING_DEFAULT (BCM2838_GENET_DMA_RING_CNT - 1) +#define BCM2838_GENET_HFB_FILTER_CNT 48 +#define BCM2838_GENET_HFB_FILTER_SIZE 128 + typedef struct { uint32_t rev_ctrl; uint32_t port_ctrl; @@ -169,6 +172,53 @@ typedef struct { uint32_t reserved_0x10D0[972]; } BCM2838GenetRegsRdma; +typedef struct { + uint32_t length_status; + uint32_t address_lo; + uint32_t address_hi; +} BCM2838GenetTdmaDesc; + +typedef struct { + uint32_t read_ptr; + uint32_t read_ptr_hi; + uint32_t cons_index; + uint32_t prod_index; + uint32_t ring_buf_size; + uint32_t start_addr; + uint32_t start_addr_hi; + uint32_t end_addr; + uint32_t end_addr_hi; + uint32_t mbuf_done_tresh; + uint32_t flow_period; + uint32_t write_ptr; + uint32_t write_ptr_hi; + uint32_t reserved_0x34[3]; +} BCM2838GenetTdmaRing; + +typedef struct { + BCM2838GenetTdmaDesc descs[BCM2838_GENET_DMA_DESC_CNT]; + BCM2838GenetTdmaRing rings[BCM2838_GENET_DMA_RING_CNT]; + uint32_t ring_cfg; + uint32_t ctrl; + uint32_t status; + uint32_t scb_burst_size; + uint32_t reserved_0x1050[7]; + uint32_t arb_ctrl; + uint32_t priority[3]; + uint32_t reserved_0x10D0[993]; +} BCM2838GenetRegsTdma; + +typedef struct { + uint8_t flt[BCM2838_GENET_HFB_FILTER_CNT * BCM2838_GENET_HFB_FILTER_SIZE + * sizeof(uint32_t)]; + uint32_t reserved_0x6000[1792]; + uint32_t ctrl; + uint32_t flt_enable[2]; + uint32_t reserved_0x7C0C[4]; + uint32_t flt_len[BCM2838_GENET_HFB_FILTER_CNT / sizeof(uint32_t)]; + uint32_t reserved_0x7C4C[237]; +} BCM2838GenetRegsHfb; + typedef struct { BCM2838GenetRegsSys sys; BCM2838GenetRegsGrBridge gr_bridge; @@ -184,8 +234,45 @@ typedef struct { BCM2838GenetRegsUmac umac; uint32_t reserved_0x1000[1024]; BCM2838GenetRegsRdma rdma; + BCM2838GenetRegsTdma tdma; + uint32_t reserved_0x6000[2048]; + BCM2838GenetRegsHfb hfb; } BCM2838GenetRegs; +typedef struct { + uint16_t bmcr; + uint16_t bmsr; + uint16_t sid1; + uint16_t sid2; + uint16_t advertise; + uint16_t lpa; + uint16_t expansion; + uint16_t next_page; + uint16_t lpa_next_page; + uint16_t ctrl1000; + uint16_t stat1000; + uint16_t reserved_11_12[2]; + uint16_t mmd_ctrl; + uint16_t mmd_data; + uint16_t estatus; + uint16_t ecr; + uint16_t esr; + uint16_t dcounter; + uint16_t fcscounter; + uint16_t nwaytest; + uint16_t exp_data; + uint16_t srevision; + uint16_t exp_ctrl; + uint16_t aux_ctl; + uint16_t phyaddr; + uint16_t isr; + uint16_t imr; + uint16_t shd; + uint16_t reserved_29; + uint16_t rdb_addr; + uint16_t rdb_data; +} BCM2838GenetPhyRegs; + struct BCM2838GenetState { /*< private >*/ SysBusDevice parent_obj; @@ -196,6 +283,7 @@ struct BCM2838GenetState { AddressSpace dma_as; BCM2838GenetRegs regs; + BCM2838GenetPhyRegs phy_regs; qemu_irq irq_default; qemu_irq irq_prio; From patchwork Sun Dec 3 21:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ToHTxLzf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Sy4gqcz23mf for ; Mon, 4 Dec 2023 08:35:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2Q-0002U7-Iv; Sun, 03 Dec 2023 16:30:06 -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 1r9u21-0001Uh-Ae; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1y-0005UB-Ij; Sun, 03 Dec 2023 16:29:39 -0500 Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-d9beb865a40so2067279276.1; Sun, 03 Dec 2023 13:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638976; x=1702243776; 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=m35zG+ajLJL60pM6bIM9adMNO13lGgmKjK7XnKNpmk8=; b=ToHTxLzfokRByjyeX53nZWoTl5uBue0ng2hDfUsf6ktGOZXZTV3cPexsiWNKlLh+ge MOGFAZ8pJYByCQ3YCBMXjsur+ygxVF35gvMiWYk7m4n8jGuqUZbf4zeBknOaxm789aMf xsjQVQELgYLXpd8LeGFG7CEIHAMmztzAxv7/jY1oWQBgIPfexz251KpNRphevXeyBx5r uNmYDSXj6Di00aIf6R69qbbvvHiNu7DpIVcXfZVmuFzMr1qnGBy4qPWvgVpEYeIMB7Nw QmoYn542GvrMSCsAOgpITv3bpS1ZxJqJAFgHIl4JJgvD5uDDM4WnB5aNY5x6aE97foab 9Y2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638976; x=1702243776; 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=m35zG+ajLJL60pM6bIM9adMNO13lGgmKjK7XnKNpmk8=; b=NJgBCkduOlRfNwWalRXCDFU0p+JW5ZhkfXiWF206N5Uo9j1+ULQviEyFNkIT6/H7w3 qhY0VoAgBCN30iuIs8JNtyMrrAV9n0zRJv4GyrQyQWIGO5cw/UOfyA5+VlbEm9/UuDB4 80lb6d359/JXnWQVgcfqXoDKWTTnRvPcVOeY45Q+yospIAHUTXUdXXwuVdUXmCY06ENu lJnOB9NoWYCwZyS28hANhpYZyOmuH+ta8O4pEy061rdS3ez65xTLiJN28nJDiB3nb3uF /v+DuFUwXI6/OfD07MJEUyMrc+RSiue0op+TJ7W6UifOc3q6t+PteMqzx/btlI1rpViR t2LQ== X-Gm-Message-State: AOJu0YxsXLko5hZo91+0r6bfxQKeNlRJZq8h/8Hl26Imx9NtAgkzCb3n VyjGlWKMtHM5wN+6He9xdh9wsNEtz63a8Q== X-Google-Smtp-Source: AGHT+IEyCGtjpUSMO1dP2NzO7acAUYIX2YIZZVjrVV7NFJ18TBfYpY7LhUjukbR5VId0BFD9/gUcLg== X-Received: by 2002:a25:cb0a:0:b0:db7:dacf:3fc2 with SMTP id b10-20020a25cb0a000000b00db7dacf3fc2mr1821696ybg.111.1701638975994; Sun, 03 Dec 2023 13:29:35 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:35 -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 26/45] Add GENET register structs. Part 4 Date: Sun, 3 Dec 2023 15:28:46 -0600 Message-Id: <20231203212905.1364036-27-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-26-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2e; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2e.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- include/hw/net/bcm2838_genet.h | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index 1bd004785a..94c2f3ebca 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -25,6 +25,12 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_HFB_FILTER_CNT 48 #define BCM2838_GENET_HFB_FILTER_SIZE 128 +#define BCM2838_GENET_PHY_AUX_CTL_MISC 0x7 +#define BCM2838_GENET_PHY_AUX_CTL_REGS_SIZE 8 + +#define BCM2838_GENET_PHY_EXP_SHD_BLOCKS_CNT 256 +#define BCM2838_GENET_PHY_EXP_SHD_REGS_CNT 256 + typedef struct { uint32_t rev_ctrl; uint32_t port_ctrl; @@ -273,6 +279,34 @@ typedef struct { uint16_t rdb_data; } BCM2838GenetPhyRegs; +typedef struct { + uint16_t reserved_0_2[3]; + uint16_t clk_ctl; + uint16_t scr2; + uint16_t scr3; + uint16_t reserved_6_9[4]; + uint16_t apd; + uint16_t rgmii_mode; + uint16_t reserved_12; + uint16_t leds1; + uint16_t reserved_14_18[5]; + uint16_t _100fx_ctrl; + uint16_t ssd; + uint16_t reserved_21_30[10]; + uint16_t mode; +} BCM2838GenetPhyShdRegs; + +typedef struct { + uint16_t auxctl; + uint16_t reserved_1_6[BCM2838_GENET_PHY_AUX_CTL_REGS_SIZE - 2]; + uint16_t misc; +} BCM2838GenetPhyAuxShdRegs; + +typedef struct { + uint16_t regs[BCM2838_GENET_PHY_EXP_SHD_BLOCKS_CNT] + [BCM2838_GENET_PHY_EXP_SHD_REGS_CNT]; +} BCM2838GenetPhyExpShdRegs; + struct BCM2838GenetState { /*< private >*/ SysBusDevice parent_obj; @@ -284,6 +318,9 @@ struct BCM2838GenetState { BCM2838GenetRegs regs; BCM2838GenetPhyRegs phy_regs; + BCM2838GenetPhyShdRegs phy_shd_regs; + BCM2838GenetPhyAuxShdRegs phy_aux_ctl_shd_regs; + BCM2838GenetPhyExpShdRegs phy_exp_shd_regs; qemu_irq irq_default; qemu_irq irq_prio; From patchwork Sun Dec 3 21:28:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871084 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=e3vmIsPS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0R20XSZz23nJ for ; Mon, 4 Dec 2023 08:33:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2F-00024d-H4; Sun, 03 Dec 2023 16:29:55 -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 1r9u21-0001Ui-BT; Sun, 03 Dec 2023 16:29:42 -0500 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1y-0005UX-Ja; Sun, 03 Dec 2023 16:29:40 -0500 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-d9caf5cc948so2076441276.0; Sun, 03 Dec 2023 13:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638977; x=1702243777; 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=A0Jk5tssg+pczQf+sURfDosRQjtzzg5NlLkdIkk5IGA=; b=e3vmIsPSFY1GH/wnFhcCyspua84Tz1LgqU8msWdY8EH06c7iOH4LVy5GQN2znknGxX qNTOv2TjnooOGorgAYxe5FAv8NMz+bLBtCMGrWy4E2axkBgZ4hcpQX7xjAM4lQItE8op B5iy14UXTvL9JcdwvqNtv/z302+kV/9bdB+sBnH/uHmvkQ/1jT8DNUTPQOEHD/PkAjZQ 62U6XEAxzUXS76Jk5FjZsnr1E0H7OsKZRxm9sH0ZfKrDkZJoGOl+DbnTwAqlFnrDBtCA aokd2Szuy3+mO6MuwY//Bjkj4fOnUX1FvRnikfMx/TT0FFJf4K9rzjkZxxi04rTSszfc Iz8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638977; x=1702243777; 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=A0Jk5tssg+pczQf+sURfDosRQjtzzg5NlLkdIkk5IGA=; b=ZTCwsPv1eAH7zgzYSTOalusJ4sdOKIzRWVUl0T0cR0VJOgNXeDWUrenUOT9IjJxThM Jt4TeAk5kFpM2ksSuCpc520+AIlHMkHyElr17DHRbxhJLSZ3DWD3jmA3PuOjoNmCzDN1 gJuh8QL70k7AFssXj1IWHLx6BYi8r04qcn9bJP1woZIcDcQylNrVGlSgetTY3kpwTW7r v/Uqkalz23zdiNjcdEtKGoC6jPW8cDcpBYxVBl8zhXuQiHKRoArVxjP+HwxfNOanugKe AniOeIQYJ33LxTbz0gYl6RBtgy/zAFjoWmtrKe6qm84VPPinaVhphcLaDGxDttvzuUYn 1X+A== X-Gm-Message-State: AOJu0YzdrJzd5hXba+WOL/376w490D460BO24PwXC46UI99XO16nk+19 GPUf+qlAZLDkr+rLRUmXDkhUXvxmgcyoeA== X-Google-Smtp-Source: AGHT+IGhk4myTrRnEmwz6rEApbT5k3pzr9CWzxZNbMb9mQoMSNfe7NpbQS5vFqBAVnWQLUK+gx0adQ== X-Received: by 2002:a25:81c8:0:b0:db5:3f2a:e0ed with SMTP id n8-20020a2581c8000000b00db53f2ae0edmr1655367ybm.59.1701638976978; Sun, 03 Dec 2023 13:29:36 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:36 -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 27/45] Add GENET register access macros Date: Sun, 3 Dec 2023 15:28:47 -0600 Message-Id: <20231203212905.1364036-28-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-27-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b30; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb30.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, UPPERCASE_50_75=0.008 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- include/hw/net/bcm2838_genet.h | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index 94c2f3ebca..e7a76cda81 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -22,9 +22,85 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_DMA_RING_CNT 17 #define BCM2838_GENET_DMA_RING_DEFAULT (BCM2838_GENET_DMA_RING_CNT - 1) +#define BCM2838_GENET_HFB_FILTER_REGS offsetof(BCM2838GenetRegs, hfb) +#define BCM2838_GENET_HFB_FILTER_REG(reg) (BCM2838_GENET_HFB_FILTER_REGS \ + + offsetof(BCM2838GenetRegsHfb, reg)) #define BCM2838_GENET_HFB_FILTER_CNT 48 #define BCM2838_GENET_HFB_FILTER_SIZE 128 +#define BCM2838_GENET_INTRL0_REG(reg) (offsetof(BCM2838GenetRegs, intrl0) \ + + offsetof(BCM2838GenetRegsIntrl0, reg)) +#define BCM2838_GENET_INTRL0_SET BCM2838_GENET_INTRL0_REG(set) +#define BCM2838_GENET_INTRL0_CLEAR BCM2838_GENET_INTRL0_REG(clear) +#define BCM2838_GENET_INTRL0_MASK_SET BCM2838_GENET_INTRL0_REG(mask_set) +#define BCM2838_GENET_INTRL0_MASK_CLEAR BCM2838_GENET_INTRL0_REG(mask_clear) + +#define BCM2838_GENET_INTRL1_REG(reg) (offsetof(BCM2838GenetRegs, intrl1) \ + + offsetof(BCM2838GenetRegsIntrl1, reg)) +#define BCM2838_GENET_INTRL1_SET BCM2838_GENET_INTRL1_REG(set) +#define BCM2838_GENET_INTRL1_CLEAR BCM2838_GENET_INTRL1_REG(clear) +#define BCM2838_GENET_INTRL1_MASK_SET BCM2838_GENET_INTRL1_REG(mask_set) +#define BCM2838_GENET_INTRL1_MASK_CLEAR BCM2838_GENET_INTRL1_REG(mask_clear) + +#define BCM2838_GENET_UMAC_REG(reg) (offsetof(BCM2838GenetRegs, umac) \ + + offsetof(BCM2838GenetRegsUmac, reg)) +#define BCM2838_GENET_UMAC_CMD BCM2838_GENET_UMAC_REG(cmd) +#define BCM2838_GENET_UMAC_MAC0 BCM2838_GENET_UMAC_REG(mac0) +#define BCM2838_GENET_UMAC_MAC1 BCM2838_GENET_UMAC_REG(mac1) +#define BCM2838_GENET_UMAC_MDIO_CMD BCM2838_GENET_UMAC_REG(mdio_cmd) + +#define BCM2838_GENET_TDMA_REGS offsetof(BCM2838GenetRegs, tdma) +#define BCM2838_GENET_TDMA_REG(reg) (BCM2838_GENET_TDMA_REGS \ + + offsetof(BCM2838GenetRegsTdma, reg)) +#define BCM2838_GENET_TDMA_RINGS BCM2838_GENET_TDMA_REG(rings) +#define BCM2838_GENET_TDMA_RING_CFG BCM2838_GENET_TDMA_REG(ring_cfg) +#define BCM2838_GENET_TDMA_CTRL BCM2838_GENET_TDMA_REG(ctrl) + +#define BCM2838_GENET_RDMA_REGS offsetof(BCM2838GenetRegs, rdma) +#define BCM2838_GENET_RDMA_REG(reg) (BCM2838_GENET_RDMA_REGS \ + + offsetof(BCM2838GenetRegsRdma, reg)) +#define BCM2838_GENET_RDMA_RINGS BCM2838_GENET_RDMA_REG(rings) +#define BCM2838_GENET_RDMA_RING_CFG BCM2838_GENET_RDMA_REG(ring_cfg) +#define BCM2838_GENET_RDMA_CTRL BCM2838_GENET_RDMA_REG(ctrl) + +#define BCM2838_GENET_TRING_REG(reg) offsetof(BCM2838GenetTdmaRing, reg) +#define BCM2838_GENET_TRING_WRITE_PTR BCM2838_GENET_TRING_REG(write_ptr) +#define BCM2838_GENET_TRING_WRITE_PTR_HI BCM2838_GENET_TRING_REG(write_ptr_hi) +#define BCM2838_GENET_TRING_PROD_INDEX BCM2838_GENET_TRING_REG(prod_index) +#define BCM2838_GENET_TRING_CONS_INDEX BCM2838_GENET_TRING_REG(cons_index) +#define BCM2838_GENET_TRING_RING_BUF_SIZE BCM2838_GENET_TRING_REG(ring_buf_size) +#define BCM2838_GENET_TRING_RING_START_ADDR BCM2838_GENET_TRING_REG(start_addr) +#define BCM2838_GENET_TRING_RING_START_ADDR_HI BCM2838_GENET_TRING_REG(start_addr_hi) +#define BCM2838_GENET_TRING_RING_END_ADDR BCM2838_GENET_TRING_REG(end_addr) +#define BCM2838_GENET_TRING_RING_END_ADDR_HI BCM2838_GENET_TRING_REG(end_addr_hi) +#define BCM2838_GENET_TRING_RING_MBUF_DONE_TRESH BCM2838_GENET_TRING_REG(mbuf_done_tresh) +#define BCM2838_GENET_TRING_RING_FLOW_PERIOD BCM2838_GENET_TRING_REG(flow_period) +#define BCM2838_GENET_TRING_RING_READ_PTR BCM2838_GENET_TRING_REG(read_ptr) +#define BCM2838_GENET_TRING_RING_READ_PTR_HI BCM2838_GENET_TRING_REG(read_ptr_hi) + +#define BCM2838_GENET_RRING_REG(reg) offsetof(BCM2838GenetRdmaRing, reg) +#define BCM2838_GENET_RRING_WRITE_PTR BCM2838_GENET_RRING_REG(write_ptr) +#define BCM2838_GENET_RRING_WRITE_PTR_HI BCM2838_GENET_RRING_REG(write_ptr_hi) +#define BCM2838_GENET_RRING_PROD_INDEX BCM2838_GENET_RRING_REG(prod_index) +#define BCM2838_GENET_RRING_CONS_INDEX BCM2838_GENET_RRING_REG(cons_index) +#define BCM2838_GENET_RRING_RING_BUF_SIZE BCM2838_GENET_RRING_REG(ring_buf_size) +#define BCM2838_GENET_RRING_RING_START_ADDR BCM2838_GENET_RRING_REG(start_addr) +#define BCM2838_GENET_RRING_RING_START_ADDR_HI BCM2838_GENET_RRING_REG(start_addr_hi) +#define BCM2838_GENET_RRING_RING_END_ADDR BCM2838_GENET_RRING_REG(end_addr) +#define BCM2838_GENET_RRING_RING_END_ADDR_HI BCM2838_GENET_RRING_REG(end_addr_hi) +#define BCM2838_GENET_RRING_RING_MBUF_DONE_TRESH BCM2838_GENET_RRING_REG(mbuf_done_tresh) +#define BCM2838_GENET_RRING_RING_XON_XOFF_TRESH BCM2838_GENET_RRING_REG(xon_xoff_tresh) +#define BCM2838_GENET_RRING_RING_READ_PTR BCM2838_GENET_RRING_REG(read_ptr) +#define BCM2838_GENET_RRING_RING_READ_PTR_HI BCM2838_GENET_RRING_REG(read_ptr_hi) + + +#define BCM2838_GENET_PHY_REG(reg) (offsetof(BCM2838GenetPhyRegs, reg) / 2) +#define BCM2838_GENET_PHY_BMCR BCM2838_GENET_PHY_REG(bmcr) +#define BCM2838_GENET_PHY_AUX_CTL BCM2838_GENET_PHY_REG(aux_ctl) +#define BCM2838_GENET_PHY_SHD BCM2838_GENET_PHY_REG(shd) +#define BCM2838_GENET_EXP_DATA BCM2838_GENET_PHY_REG(exp_data) +#define BCM2838_GENET_EXP_SEL BCM2838_GENET_PHY_REG(exp_ctrl) + #define BCM2838_GENET_PHY_AUX_CTL_MISC 0x7 #define BCM2838_GENET_PHY_AUX_CTL_REGS_SIZE 8 From patchwork Sun Dec 3 21:28:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871091 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=fAczcgk2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Sm6KlCz23nJ for ; Mon, 4 Dec 2023 08:35:04 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2d-0002go-KE; Sun, 03 Dec 2023 16:30:19 -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 1r9u23-0001Vn-0l; Sun, 03 Dec 2023 16:29:44 -0500 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u1z-0005Uu-AJ; Sun, 03 Dec 2023 16:29:42 -0500 Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-db539ab8e02so2184821276.0; Sun, 03 Dec 2023 13:29:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638978; x=1702243778; 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=eYmWgHZv1i9ycEb8Rk2NOoEFjXjhR9gUFRUNKobjtVA=; b=fAczcgk2MVY2xj0O9N1yWbWETf931QhzrIoAHGOwc7g4WQ04+RdBu89yOG1O+7av0w oDPU7QtHfSU0UQmT+A1U+qj6B0onegeXQkp+SBHzFa5wObOnbdOOYxP0A5/3fs3aV0Ur YgO5tVvVfE+BXbTeZiZlOCgdop6cQ5KCuKMF0yxNanMojpuh6dOPPvCUmMpClcpD1T4O JSV3g2vd2ZJHlgFyFJ+E5Q+94kgNeZLrtO5edrxcJzObevCcvzlq9F7E3NojB6w7J7Pm m+6UcOBNaoJ4KPDhGMwrqlK/3MlSN9SGzW0azgjhM/a9rs6MOABjPsiBYJID5pNBdE5U rz9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638978; x=1702243778; 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=eYmWgHZv1i9ycEb8Rk2NOoEFjXjhR9gUFRUNKobjtVA=; b=Q7hAOE26RPedS8gSVgZQrL0FAM1QwAI261s2xfj2Aa8Vklq/lb4YC+0ULrf3/y1TjW gvUCRnz/ZhcyrSXqG00N3A5aL3v7O88MC45IsLDTuqkGPdWrI55AEMXrBAxNQB5UsPKA d52JGULPPrOK+pYxSy2nJRX6zkb9GSzc+6+unQwIpils2/z72WuH400KknoEJY9X0Jrt B3d52kJAX9ZemtwJVTElg17/dL31+MiRrgGArd4z5PtXJNIUb/xVNTTL36sHaOueXMs8 XSHyudWhyGBliQzL8VFWTq2JCWkqik+bvBUaBnTqUwOf7rVBJ3clkNGtJWiMxBtYkRnR jZLA== X-Gm-Message-State: AOJu0YxaJJAaB0es0lFp0cjwWqUTMZyTug/YNGRxtrCaBjMiGm74z282 bP6hjTfRwU6QZjOOgOe7b0oIHHoWlUcL6w== X-Google-Smtp-Source: AGHT+IG2Gyz/NKaf8coBhObq5zWB26AlC/D0A9cUWQ34bJo78PClD+57jdnf/fHANhVuPyAGduBYug== X-Received: by 2002:a25:5c3:0:b0:db5:416d:49e0 with SMTP id 186-20020a2505c3000000b00db5416d49e0mr1828466ybf.22.1701638977957; Sun, 03 Dec 2023 13:29:37 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:37 -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 28/45] Implement GENET register ops Date: Sun, 3 Dec 2023 15:28:48 -0600 Message-Id: <20231203212905.1364036-29-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-28-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2b; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2b.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 189 +++++++++++++++++++++++++++++++-- include/hw/net/bcm2838_genet.h | 2 + 2 files changed, 182 insertions(+), 9 deletions(-) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index be899b68f8..56ff6a6f39 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -233,25 +233,144 @@ REG16(GENET_PHY_EXP_SEL, 0) FIELD(GENET_PHY_EXP_SEL, REG_ID, 0, 8) FIELD(GENET_PHY_EXP_SEL, BLOCK_ID, 8, 8) +static void bcm2838_genet_set_qemu_mac(BCM2838GenetState *s) +{ + const MACAddr *addr = &s->nic_conf.macaddr; + + s->regs.umac.mac0 = FIELD_DP32(s->regs.umac.mac0, GENET_UMAC_MAC_0, + ADDR_0, addr->a[0]); + s->regs.umac.mac0 = FIELD_DP32(s->regs.umac.mac0, GENET_UMAC_MAC_0, + ADDR_1, addr->a[1]); + s->regs.umac.mac0 = FIELD_DP32(s->regs.umac.mac0, GENET_UMAC_MAC_0, + ADDR_2, addr->a[2]); + s->regs.umac.mac0 = FIELD_DP32(s->regs.umac.mac0, GENET_UMAC_MAC_0, + ADDR_3, addr->a[3]); + s->regs.umac.mac1 = FIELD_DP32(s->regs.umac.mac1, GENET_UMAC_MAC_1, + ADDR_4, addr->a[4]); + s->regs.umac.mac1 = FIELD_DP32(s->regs.umac.mac1, GENET_UMAC_MAC_1, + ADDR_5, addr->a[5]); +} + +static void bcm2838_genet_set_irq_default(BCM2838GenetState *s) +{ + uint32_t intrl_0_status = s->regs.intrl0.stat; + uint32_t intrl_0_mask = s->regs.intrl0.mask_status; + int level = (intrl_0_status & ~intrl_0_mask) == 0 ? 0 : 1; + + qemu_set_irq(s->irq_default, level); +} + +static void bcm2838_genet_set_irq_prio(BCM2838GenetState *s) +{ + uint32_t intrl_1_status = s->regs.intrl1.stat; + uint32_t intrl_1_mask = s->regs.intrl1.mask_status; + int level = (intrl_1_status & ~intrl_1_mask) == 0 ? 0 : 1; + + qemu_set_irq(s->irq_prio, level); +} + static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) { uint64_t value = ~0; + BCM2838GenetState *s = opaque; - qemu_log_mask( - LOG_GUEST_ERROR, - "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", - __func__, size, offset); + if (offset + size < sizeof(s->regs)) { + memcpy(&value, (uint8_t *)&s->regs + offset, size); + } else { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); + } trace_bcm2838_genet_read(size, offset, value); return value; } static void bcm2838_genet_write(void *opaque, hwaddr offset, uint64_t value, - unsigned size) { - qemu_log_mask( - LOG_GUEST_ERROR, - "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", - __func__, size, offset); + unsigned size) +{ + BCM2838GenetState *s = opaque; + MACAddr *mac = &s->nic_conf.macaddr; + NetClientState *ncs = qemu_get_queue(s->nic); + + trace_bcm2838_genet_write(size, offset, value); + + if (offset + size < sizeof(s->regs)) { + switch (offset) { + case BCM2838_GENET_INTRL0_SET: + s->regs.intrl0.stat |= value; + break; + case BCM2838_GENET_INTRL0_CLEAR: + s->regs.intrl0.stat &= ~value; + break; + case BCM2838_GENET_INTRL0_MASK_SET: + s->regs.intrl0.mask_status |= value; + break; + case BCM2838_GENET_INTRL0_MASK_CLEAR: + s->regs.intrl0.mask_status &= ~value; + break; + case BCM2838_GENET_INTRL1_SET: + s->regs.intrl1.stat |= value; + break; + case BCM2838_GENET_INTRL1_CLEAR: + s->regs.intrl1.stat &= ~value; + break; + case BCM2838_GENET_INTRL1_MASK_SET: + s->regs.intrl1.mask_status |= value; + break; + case BCM2838_GENET_INTRL1_MASK_CLEAR: + s->regs.intrl1.mask_status &= ~value; + break; + case BCM2838_GENET_UMAC_CMD: + /* Complete SW reset as soon as it has been requested */ + if (FIELD_EX32(value, GENET_UMAC_CMD, SW_RESET) == 1) { + device_cold_reset(DEVICE(s)); + value = FIELD_DP32(value, GENET_UMAC_CMD, SW_RESET, 0); + } + break; + /* + * TODO: before changing MAC address we'd better inform QEMU + * network subsystem about freeing previously used one, but + * qemu_macaddr_set_free function isn't accessible for us (marked + * as static in net/net.c), see also https://lists.nongnu.org/ + * archive/html/qemu-devel/2022-07/msg02123.html + */ + case BCM2838_GENET_UMAC_MAC0: + mac->a[0] = FIELD_EX32(value, GENET_UMAC_MAC_0, ADDR_0); + mac->a[1] = FIELD_EX32(value, GENET_UMAC_MAC_0, ADDR_1); + mac->a[2] = FIELD_EX32(value, GENET_UMAC_MAC_0, ADDR_2); + mac->a[3] = FIELD_EX32(value, GENET_UMAC_MAC_0, ADDR_3); + qemu_macaddr_default_if_unset(mac); + qemu_format_nic_info_str(ncs, mac->a); + trace_bcm2838_genet_mac_address(ncs->info_str); + break; + case BCM2838_GENET_UMAC_MAC1: + mac->a[4] = FIELD_EX32(value, GENET_UMAC_MAC_1, ADDR_4); + mac->a[5] = FIELD_EX32(value, GENET_UMAC_MAC_1, ADDR_5); + qemu_macaddr_default_if_unset(mac); + qemu_format_nic_info_str(ncs, mac->a); + trace_bcm2838_genet_mac_address(ncs->info_str); + break; + case BCM2838_GENET_UMAC_MDIO_CMD: + case BCM2838_GENET_TDMA_REGS + ... BCM2838_GENET_TDMA_REGS + sizeof(BCM2838GenetRegsTdma) - 1: + qemu_log_mask(LOG_UNIMP, + "UMAC MDIO and TDMA aren't implemented yet"); + break; + default: + break; + } + + memcpy((uint8_t *)&s->regs + offset, &value, size); + bcm2838_genet_set_irq_default(s); + bcm2838_genet_set_irq_prio(s); + } else { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); + } } static const MemoryRegionOps bcm2838_genet_ops = { @@ -262,9 +381,14 @@ static const MemoryRegionOps bcm2838_genet_ops = { .valid = {.min_access_size = 4}, }; +static NetClientInfo bcm2838_genet_client_info = { + .type = NET_CLIENT_DRIVER_NIC, + .size = sizeof(NICState) +}; static void bcm2838_genet_realize(DeviceState *dev, Error **errp) { + NetClientState *ncs; BCM2838GenetState *s = BCM2838_GENET(dev); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); @@ -272,10 +396,46 @@ static void bcm2838_genet_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->regs_mr, OBJECT(s), &bcm2838_genet_ops, s, "bcm2838_genet_regs", sizeof(s->regs)); sysbus_init_mmio(sbd, &s->regs_mr); + + /* QEMU-managed NIC (host network back-end connection) */ + qemu_macaddr_default_if_unset(&s->nic_conf.macaddr); + s->nic = qemu_new_nic(&bcm2838_genet_client_info, &s->nic_conf, + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); + bcm2838_genet_set_qemu_mac(s); + ncs = qemu_get_queue(s->nic); + qemu_format_nic_info_str(ncs, s->nic_conf.macaddr.a); + trace_bcm2838_genet_mac_address(ncs->info_str); + + /* Interrupts */ + sysbus_init_irq(sbd, &s->irq_default); + sysbus_init_irq(sbd, &s->irq_prio); + + /* DMA space */ + address_space_init(&s->dma_as, get_system_memory(), "bcm2838_genet_dma"); } static void bcm2838_genet_phy_reset(BCM2838GenetState *s) { + memset(&s->phy_regs, 0x00, sizeof(s->phy_regs)); + memset(&s->phy_shd_regs, 0x00, sizeof(s->phy_shd_regs)); + memset(&s->phy_aux_ctl_shd_regs, 0x00, sizeof(s->phy_aux_ctl_shd_regs)); + + /* All values below were taken from real HW trace and logs */ + s->phy_regs.bmcr = 0x1140; + s->phy_regs.bmsr = 0x7949; + s->phy_regs.sid1 = 0x600D; + s->phy_regs.sid2 = 0x84A2; + s->phy_regs.advertise = 0x01E1; + s->phy_regs.ctrl1000 = 0x0200; + s->phy_regs.estatus = 0x3000; + + s->phy_shd_regs.clk_ctl = 0x0200; + s->phy_shd_regs.scr3 = 0x001F; + s->phy_shd_regs.apd = 0x0001; + + s->phy_aux_ctl_shd_regs.misc = 0x1E; + trace_bcm2838_genet_phy_reset("done"); } @@ -285,17 +445,28 @@ static void bcm2838_genet_reset(DeviceState *d) memset(&s->regs, 0x00, sizeof(s->regs)); + s->regs.sys.rev_ctrl = FIELD_DP32(s->regs.sys.rev_ctrl, GENET_SYS_REV_CTRL, + MAJOR_REV, BCM2838_GENET_REV_MAJOR); + s->regs.sys.rev_ctrl = FIELD_DP32(s->regs.sys.rev_ctrl, GENET_SYS_REV_CTRL, + MINOR_REV, BCM2838_GENET_REV_MINOR); + trace_bcm2838_genet_reset("done"); bcm2838_genet_phy_reset(s); } +static Property genet_properties[] = { + DEFINE_NIC_PROPERTIES(BCM2838GenetState, nic_conf), + DEFINE_PROP_END_OF_LIST(), +}; + static void bcm2838_genet_class_init(ObjectClass *class, void *data) { DeviceClass *dc = DEVICE_CLASS(class); dc->realize = bcm2838_genet_realize; dc->reset = bcm2838_genet_reset; + device_class_set_props(dc, genet_properties); } static const TypeInfo bcm2838_genet_info = { diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index e7a76cda81..b9d6d35cce 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -388,6 +388,8 @@ struct BCM2838GenetState { SysBusDevice parent_obj; /*< public >*/ + NICState *nic; + NICConf nic_conf; MemoryRegion regs_mr; AddressSpace dma_as; From patchwork Sun Dec 3 21:28:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=T7P+l3Sd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0QR4yQbz23nJ for ; Mon, 4 Dec 2023 08:33:03 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2U-0002XF-IP; Sun, 03 Dec 2023 16:30:10 -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 1r9u24-0001Wf-Ke; Sun, 03 Dec 2023 16:29:44 -0500 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u21-0005VE-FD; Sun, 03 Dec 2023 16:29:44 -0500 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-db5311eab29so1984129276.3; Sun, 03 Dec 2023 13:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638979; x=1702243779; 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=v0plx2CSfyD/hqodRTCcCQxsf1hkYu3FpLFu5vV8rvY=; b=T7P+l3Sd/oZvGB1zGo/Ooy2N1UrLJBqZig/hySr0zFzO3xdaixzPlXFOwOiyaKc4Sr eERwxTrUUeeh/uAbaWd1LWoyF+ZxOEsvSmjV1l/JDPCrKjN571pcygH0N/iiorz3qlbj AgFFuzTavaYlYRdZNmmFyPHrkIx6QN/ahmBL9UpkJoUmrok5CB0CnrNa+sMCB+wewSrn GBXLGq6ofeeZo6PcrQC7z3KwVQNk6Af4hh7BlfGdCu0TVpljIap2ec1ieSX4Zcdo1n5j PRdGr/cyPtxOJ/kwpKc396GWacpCTxfDsiWCKP3IpkWf+7XVGsn8Q268YyHS92wF5v4G 4+MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638979; x=1702243779; 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=v0plx2CSfyD/hqodRTCcCQxsf1hkYu3FpLFu5vV8rvY=; b=a0MffmiRzAt/TG5l2QliVAVYbga5BTmMcQrBIho2MP9tQMh1mxu32KEEP4vv7VV7k6 PoYZOEMGSX1Om5Ovp7O/nczb+abQ4E30bmhZAza2ApJ44o+2+LSxV7nvTtfWt1c4m98V 9PkzFyewH3ZqOsjoP+z23QbgNG6rpXaMscm0xnntGtns3sM8rzNhJjFeOrL0e9eOyasU 2cwpoZx+GgFSQrtHGOzL3QTGuI0NajS0cjvDd4OgrH9d4hqKFN8kWhIQWqif8VBdna7G rSXU1iQSwnXxRRhY3ILlYlLipNIqyt+CwAe12TjSK5jOIfUe6PzrPxDCZ5jeTZjKx85/ DJ9Q== X-Gm-Message-State: AOJu0YxLIS9MgDKsylDvec5Nl+X6ZbqUY5GsR88ezVm84/Aae5zOcBLE zYYF7rqAFG+o5q357xcgRVzE23p1XflIcA== X-Google-Smtp-Source: AGHT+IGpPTxyujJJxEfmI/daaW5J0PHEUL2IBWCWzfnlzevu6oSyHgkf3WAyG+8gDQ/9ZyoqebJqkQ== X-Received: by 2002:a25:ae1f:0:b0:db5:4857:5fdf with SMTP id a31-20020a25ae1f000000b00db548575fdfmr1855729ybj.37.1701638978949; Sun, 03 Dec 2023 13:29:38 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:38 -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 29/45] Implement GENET MDIO Date: Sun, 3 Dec 2023 15:28:49 -0600 Message-Id: <20231203212905.1364036-30-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-29-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b32; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb32.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 126 ++++++++++++++++++++++++++++++++- include/hw/net/bcm2838_genet.h | 3 +- 2 files changed, 126 insertions(+), 3 deletions(-) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 56ff6a6f39..1fae3ecbc2 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -213,6 +213,7 @@ FIELD(GENET_PHY_STAT_1000, LOCALRXOK, 13, 1) FIELD(GENET_PHY_STAT_1000, MSRES, 14, 1) FIELD(GENET_PHY_STAT_1000, MSFAIL, 15, 1) +/* There are two data representations for PHY_AUX_CTRL register */ REG16(GENET_PHY_AUX_CTRL_0, 0) FIELD(GENET_PHY_AUX_CTRL_0, REG_ID_MASK, 0, 3) FIELD(GENET_PHY_AUX_CTRL_0, RSVD_3, 3, 1) @@ -269,6 +270,123 @@ static void bcm2838_genet_set_irq_prio(BCM2838GenetState *s) qemu_set_irq(s->irq_prio, level); } +static void bcm2838_genet_phy_aux_ctl_write(BCM2838GenetState *s, + uint16_t value) +{ + uint16_t reg_id = FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, REG_ID); + uint16_t reg_id_mask = FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, REG_ID_MASK); + uint16_t misc_wren = FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, MISC_WREN); + uint16_t reg_data = FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, REG_DATA); + uint16_t reg_data12 = FIELD_EX16(value, GENET_PHY_AUX_CTRL_1, REG_DATA); + + uint16_t *phy_aux_ctl_shd_reg_id = (uint16_t *)&s->phy_aux_ctl_shd_regs + reg_id; + uint16_t *phy_aux_ctl_shd_reg_id_mask = (uint16_t *)&s->phy_aux_ctl_shd_regs + reg_id_mask; + + if (reg_id_mask == BCM2838_GENET_PHY_AUX_CTL_MISC) { + if (reg_id == BCM2838_GENET_PHY_AUX_CTL_MISC) { + if (misc_wren == 0) { + /* write for subsequent read (8-bit from AUX_CTL_MISC) */ + FIELD_DP16(value, GENET_PHY_AUX_CTRL_0, REG_DATA, *phy_aux_ctl_shd_reg_id); + } else { + /* write 8 bits to AUX_CTL_MISC */ + *phy_aux_ctl_shd_reg_id_mask = reg_data; + } + } else { + /* write for subsequent read (12-bit) */ + FIELD_DP16(value, GENET_PHY_AUX_CTRL_1, REG_DATA, *phy_aux_ctl_shd_reg_id); + } + } else { + /* write 12 bits */ + *phy_aux_ctl_shd_reg_id_mask = reg_data12; + } + + s->phy_regs.aux_ctl = value; +} + +static void bcm2838_genet_phy_shadow_write(BCM2838GenetState *s, + uint16_t value) +{ + uint16_t reg_id = FIELD_EX16(value, GENET_PHY_SHADOW, REG_ID); + uint16_t wr = FIELD_EX16(value, GENET_PHY_SHADOW, WR); + uint16_t reg_data = FIELD_EX16(value, GENET_PHY_SHADOW, REG_DATA); + + uint16_t *phy_shd_reg = (uint16_t *)&s->phy_shd_regs + reg_id; + + if (wr == 0) { + FIELD_DP16(value, GENET_PHY_SHADOW, REG_DATA, *phy_shd_reg); + } else { + *phy_shd_reg = reg_data; + } + + s->phy_regs.shd = value; +} + +static void bcm2838_genet_phy_exp_shadow_write(BCM2838GenetState *s, + uint16_t value) +{ + /* TODO Stub implementation without side effect, + just storing registers values */ + uint16_t reg_id = FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, REG_ID); + uint16_t block_id = FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, BLOCK_ID); + + s->phy_exp_shd_regs.regs[block_id][reg_id] = value; +} + +static uint16_t bcm2838_genet_phy_exp_shadow_read(BCM2838GenetState *s) +{ + uint16_t reg_id = FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, REG_ID); + uint16_t block_id = FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, BLOCK_ID); + + return s->phy_exp_shd_regs.regs[block_id][reg_id]; +} + +static uint64_t bcm2838_genet_mdio_cmd(BCM2838GenetState *s, uint64_t cmd) +{ + uint32_t phy_reg_id = FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, REG_ID); + uint32_t phy_reg_data = FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, REG_DATA); + uint32_t start_busy = FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, START_BUSY); + uint32_t rd = FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, RD); + uint32_t wr = FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, WR); + uint16_t *phy_reg = (uint16_t *)&s->phy_regs + phy_reg_id; + + uint16_t anrestart = FIELD_EX16(phy_reg_data, GENET_PHY_BMCR, ANRESTART); + + if (start_busy != 0) { + cmd = FIELD_DP32(cmd, GENET_UMAC_MDIO_CMD, START_BUSY, 0); + + if (rd != 0) { + if (phy_reg_id == BCM2838_GENET_EXP_DATA) { + cmd = FIELD_DP32(cmd, GENET_UMAC_MDIO_CMD, REG_DATA, + bcm2838_genet_phy_exp_shadow_read(s)); + } else { + cmd = FIELD_DP32(cmd, GENET_UMAC_MDIO_CMD, REG_DATA, *phy_reg); + } + } else if (wr != 0) { + if (phy_reg_id == BCM2838_GENET_PHY_AUX_CTL) { + bcm2838_genet_phy_aux_ctl_write(s, phy_reg_data); + } else if (phy_reg_id == BCM2838_GENET_PHY_SHD) { + bcm2838_genet_phy_shadow_write(s, phy_reg_data); + } else if (phy_reg_id == BCM2838_GENET_EXP_DATA) { + bcm2838_genet_phy_exp_shadow_write(s, phy_reg_data); + } else { + if (phy_reg_id == BCM2838_GENET_PHY_BMCR) { + /* Initiate auto-negotiation once it has been restarted */ + if (anrestart == 1) { + FIELD_DP16(phy_reg_data, GENET_PHY_BMCR, ANRESTART, 0); + } + } + *phy_reg = phy_reg_data; + } + } + } + + return cmd; +} + static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) { uint64_t value = ~0; @@ -353,10 +471,13 @@ static void bcm2838_genet_write(void *opaque, hwaddr offset, uint64_t value, trace_bcm2838_genet_mac_address(ncs->info_str); break; case BCM2838_GENET_UMAC_MDIO_CMD: + value = bcm2838_genet_mdio_cmd(s, value); + s->regs.intrl0.stat = FIELD_DP32(s->regs.intrl0.stat, + GENET_INTRL_0, MDIO_DONE, 1); + break; case BCM2838_GENET_TDMA_REGS ... BCM2838_GENET_TDMA_REGS + sizeof(BCM2838GenetRegsTdma) - 1: - qemu_log_mask(LOG_UNIMP, - "UMAC MDIO and TDMA aren't implemented yet"); + qemu_log_mask(LOG_UNIMP, "TDMA isn't implemented yet"); break; default: break; @@ -452,6 +573,7 @@ static void bcm2838_genet_reset(DeviceState *d) trace_bcm2838_genet_reset("done"); + bcm2838_genet_set_qemu_mac(s); bcm2838_genet_phy_reset(s); } diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index b9d6d35cce..7a483bd265 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -101,7 +101,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_EXP_DATA BCM2838_GENET_PHY_REG(exp_data) #define BCM2838_GENET_EXP_SEL BCM2838_GENET_PHY_REG(exp_ctrl) -#define BCM2838_GENET_PHY_AUX_CTL_MISC 0x7 +#define BCM2838_GENET_PHY_AUX_CTL_AUXCTL 0x0 +#define BCM2838_GENET_PHY_AUX_CTL_MISC 0x7 #define BCM2838_GENET_PHY_AUX_CTL_REGS_SIZE 8 #define BCM2838_GENET_PHY_EXP_SHD_BLOCKS_CNT 256 From patchwork Sun Dec 3 21:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=SrFoFoEX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Sp1Rs9z23p6 for ; Mon, 4 Dec 2023 08:35:06 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2C-0001sZ-T5; Sun, 03 Dec 2023 16:29:53 -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 1r9u23-0001Vo-AT; Sun, 03 Dec 2023 16:29:44 -0500 Received: from mail-yb1-xb33.google.com ([2607:f8b0:4864:20::b33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u21-0005VG-Df; Sun, 03 Dec 2023 16:29:43 -0500 Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-db539f21712so1818015276.1; Sun, 03 Dec 2023 13:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638980; x=1702243780; 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=+hjmG1A2tPvmGc3N2NipyVPILE0g9ff37LS2A1O0hS0=; b=SrFoFoEX0xczZ2P2EDKq7r6De80KgUbeqnJTvU/OBoI4El7tpKBYCQiyXrn4A+v1vh kToq04A77PaMC0lS9bRwEDuPUxhmANZ81hBtD93eJWhdzB7u1Z2bQtqvcpxIWYdLg9ER cs015g99fS1UW90XChW+uIForYI87/IDgYOhrTw312JGd087+NW9fcZH9EahCJf4RKJM SMdC1ur5q4zmpIAO7UkoicRmg87OtbKw8WUkuTGJ+RREew7P3aChWI/iHD6QdJ/2dJhV xC9Z93I2hLBnCXsAzVD51EldqwSuC4/iCrfjgBodzDj33si4U/IxKC7OjdK/DEZFR/cG ln0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638980; x=1702243780; 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=+hjmG1A2tPvmGc3N2NipyVPILE0g9ff37LS2A1O0hS0=; b=NR/jywFFXQHx0Uq+veHxSX8ORne5AUkvRiYwTqv7tmxUuPRuG6xGBGbQ2VY8LhEAIi ZKMcz6P05EowJbNUcTXhB7eG3t7awo/bZuDdHBX2kSILcAA4tOxday6vWScNRXaUeThC pevo0N335piPP05b8SOvy2i2B63JIKBVhP7BOSxMvOp14D2aejdaY9eWCw8dcppJZOQf mJs3CKRaTnArcxYsxpMnsZOMHd2UdjvXnF7/2E/fY0UXYQZeD0vUmxWdemFU+p4w0uRI UGjkQN/qbHIzqf/P5Wbihl+1IsUbunUj2oJ+USvHLN+C+6Z5mCrXa999B7g4Ib2OsgOs jJbg== X-Gm-Message-State: AOJu0Ywcw1NCsygTwHk9YYD3Goq9+FAjWi9+r3M5oq4zXss7j9rjs457 2vXKKfvIyAPzMj87QXW7MQVWl/Yx7nNC7Q== X-Google-Smtp-Source: AGHT+IF//w/hI/neSbgXD1W5OUzCqJdPByq0GmHJ2sfeDv/Rjn1BnGtuIiVJOuQ/gv1bGO3V016L3A== X-Received: by 2002:a5b:743:0:b0:db7:dacf:6f6 with SMTP id s3-20020a5b0743000000b00db7dacf06f6mr1969602ybq.58.1701638980013; Sun, 03 Dec 2023 13:29:40 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:39 -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 30/45] Implement GENET TX path Date: Sun, 3 Dec 2023 15:28:50 -0600 Message-Id: <20231203212905.1364036-31-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-30-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b33; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb33.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 221 ++++++++++++++++++++++++++++++++- include/hw/net/bcm2838_genet.h | 17 +++ 2 files changed, 237 insertions(+), 1 deletion(-) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 1fae3ecbc2..4c9b39a3ca 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -234,6 +234,13 @@ REG16(GENET_PHY_EXP_SEL, 0) FIELD(GENET_PHY_EXP_SEL, REG_ID, 0, 8) FIELD(GENET_PHY_EXP_SEL, BLOCK_ID, 8, 8) +REG32(GENET_TX_CSUM_INFO, 0) +FIELD(GENET_TX_CSUM_INFO, OFFSET, 0, 15) +FIELD(GENET_TX_CSUM_INFO, PROTO_UDP, 15, 1) +FIELD(GENET_TX_CSUM_INFO, START, 16, 15) +FIELD(GENET_TX_CSUM_INFO, LV, 30, 1) + + static void bcm2838_genet_set_qemu_mac(BCM2838GenetState *s) { const MACAddr *addr = &s->nic_conf.macaddr; @@ -387,6 +394,218 @@ static uint64_t bcm2838_genet_mdio_cmd(BCM2838GenetState *s, uint64_t cmd) return cmd; } +static void bcm2838_genet_xmit_packet(NetClientState *s, void *packet, + size_t size) +{ + uint8_t *buf = packet + sizeof(BCM2838GenetXmitStatus); + size_t len = size; + uint16_t len_type = 0; + + len -= sizeof(BCM2838GenetXmitStatus); + net_checksum_calculate(buf, len, CSUM_ALL); + + memcpy(&len_type, &buf[12], sizeof(len_type)); + len_type = ntohs(len_type); + if (len_type < MAX_PAYLOAD_SIZE) { + len_type = len; + len_type = htons(len_type); + memcpy(&buf[12], &len_type, sizeof(len_type)); + } + + qemu_send_packet(s, buf, len); +} + +static uint64_t bcm2838_genet_tx(BCM2838GenetState *s, unsigned int ring_index, + uint32_t prod_index, + uint32_t cons_index) +{ + const unsigned int DESC_SIZE_WORDS + = sizeof(BCM2838GenetTdmaDesc) / sizeof(uint32_t); + const uint64_t RING_START_ADDR + = ((uint64_t)s->regs.tdma.rings[ring_index].start_addr_hi << 32) + + s->regs.tdma.rings[ring_index].start_addr; + const uint64_t RING_END_ADDR + = ((uint64_t)s->regs.tdma.rings[ring_index].end_addr_hi << 32) + + s->regs.tdma.rings[ring_index].end_addr; + + hwaddr data_addr; + uint64_t desc_index; + uint32_t desc_status = 0; + uint32_t buflength = 0; + uint64_t num_descs = 0; + uint64_t read_ptr + = ((uint64_t)s->regs.tdma.rings[ring_index].read_ptr_hi << 32) + + s->regs.tdma.rings[ring_index].read_ptr; + off_t packet_off = 0; + + uint32_t prod_index_fld = FIELD_EX32(prod_index, + GENET_DMA_PROD_INDEX, INDEX); + uint32_t cons_index_fld = FIELD_EX32(cons_index, + GENET_DMA_CONS_INDEX, INDEX); + + while (cons_index_fld != prod_index_fld) { + desc_index = read_ptr / DESC_SIZE_WORDS; + if (desc_index >= BCM2838_GENET_DMA_DESC_CNT) { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: invalid TX descriptor index %" PRIu64 " (exceeds %u)\n", + __func__, desc_index, BCM2838_GENET_DMA_DESC_CNT - 1); + break; + } + desc_status = s->regs.tdma.descs[desc_index].length_status; + data_addr = ((uint64_t)s->regs.tdma.descs[desc_index].address_hi << 32) + + s->regs.tdma.descs[desc_index].address_lo; + trace_bcm2838_genet_tx(ring_index, desc_index, desc_status, + data_addr); + + if (FIELD_EX32(desc_status, GENET_RDMA_LENGTH_STATUS, SOP) != 0) { + packet_off = 0; + } + + buflength = FIELD_EX32(desc_status, + GENET_RDMA_LENGTH_STATUS, BUFLENGTH); + + /* TODO: Add address_space_read() return value check */ + address_space_read(&s->dma_as, data_addr, + MEMTXATTRS_UNSPECIFIED, + s->tx_packet + packet_off, + buflength); + packet_off += buflength; + + if (FIELD_EX32(desc_status, GENET_RDMA_LENGTH_STATUS, EOP) != 0) { + bcm2838_genet_xmit_packet(qemu_get_queue(s->nic), s->tx_packet, + packet_off); + packet_off = 0; + } + + num_descs++; + cons_index_fld++; + s->regs.tdma.descs[desc_index].length_status = + FIELD_DP32(s->regs.tdma.descs[desc_index].length_status, + GENET_RDMA_LENGTH_STATUS, OWN, 1); + read_ptr = read_ptr == RING_END_ADDR + 1 - DESC_SIZE_WORDS + ? RING_START_ADDR : read_ptr + DESC_SIZE_WORDS; + } + + s->regs.tdma.rings[ring_index].read_ptr = read_ptr; + s->regs.tdma.rings[ring_index].read_ptr_hi = read_ptr >> 32; + + return num_descs; +} + +static bool bcm2838_genet_tdma_ring_active(BCM2838GenetState *s, + unsigned int ring_index) +{ + uint32_t ctrl_reg = s->regs.tdma.ctrl; + uint32_t ring_cfg_reg = s->regs.tdma.ring_cfg; + uint32_t ring_mask = 1 << ring_index; + bool dma_en = FIELD_EX32(ctrl_reg, GENET_DMA_CTRL, EN) != 0; + bool ring_en = + (FIELD_EX32(ring_cfg_reg, GENET_DMA_CTRL, EN) & ring_mask) != 0; + bool ring_buf_en = + (FIELD_EX32(ctrl_reg, GENET_DMA_CTRL, RING_BUF_EN) & ring_mask) != 0; + bool active = dma_en && ring_en && ring_buf_en; + + trace_bcm2838_genet_tx_dma_ring_active(ring_index, + active ? "active" : "halted"); + return active; +} + +static void bcm2838_genet_tdma(BCM2838GenetState *s, hwaddr offset, + uint64_t value) +{ + hwaddr ring_offset; + uint64_t num_descs_tx; + unsigned int ring_index; + uint32_t tx_intrs; + uint32_t cons_index; + uint32_t prod_index = value; + uint32_t ring_cfg = value; + uint32_t dma_ctrl = value; + + uint32_t cons_index_fld; + uint32_t prod_index_fld = + FIELD_EX32(prod_index, GENET_DMA_PROD_INDEX, INDEX); + + uint32_t exst_tdma_en = + FIELD_EX32(s->regs.tdma.ctrl, GENET_DMA_CTRL, EN); + uint32_t exst_ring_en = + FIELD_EX32(s->regs.tdma.ring_cfg, GENET_DMA_RING_CFG, EN); + uint32_t incm_tdma_en = + FIELD_EX32(dma_ctrl, GENET_DMA_CTRL, EN); + uint32_t incm_ring_en = + FIELD_EX32(ring_cfg, GENET_DMA_RING_CFG, EN); + uint32_t incm_ring_buf_en = + FIELD_EX32(dma_ctrl, GENET_DMA_CTRL, RING_BUF_EN); + + switch (offset) { + case BCM2838_GENET_TDMA_RINGS + ... BCM2838_GENET_TDMA_RINGS + sizeof(s->regs.tdma.rings) - 1: + ring_index = (offset - BCM2838_GENET_TDMA_RINGS) + / sizeof(BCM2838GenetTdmaRing); + if (bcm2838_genet_tdma_ring_active(s, ring_index)) { + ring_offset = offset - BCM2838_GENET_TDMA_RINGS + - ring_index * sizeof(BCM2838GenetTdmaRing); + switch (ring_offset) { + case BCM2838_GENET_TRING_PROD_INDEX: + cons_index = s->regs.tdma.rings[ring_index].cons_index; + cons_index_fld = FIELD_EX32(cons_index, + GENET_DMA_CONS_INDEX, INDEX); + if (cons_index_fld != prod_index_fld) { + trace_bcm2838_genet_tx_request(ring_index, + prod_index_fld, + cons_index_fld); + num_descs_tx = bcm2838_genet_tx(s, ring_index, prod_index, + cons_index); + if (num_descs_tx > 0) { + s->regs.tdma.rings[ring_index].cons_index = + FIELD_DP32(s->regs.tdma.rings[ring_index].cons_index, + GENET_DMA_CONS_INDEX, INDEX, + cons_index + num_descs_tx); + + if (ring_index == BCM2838_GENET_DMA_RING_DEFAULT) { + s->regs.intrl0.stat = + FIELD_DP32(s->regs.intrl0.stat, GENET_INTRL_0, + TXDMA_MBDONE, 1); + } else { + tx_intrs = FIELD_EX32(s->regs.intrl1.stat, + GENET_INTRL_1, TX_INTRS); + s->regs.intrl1.stat = + FIELD_DP32(s->regs.intrl1.stat, + GENET_INTRL_1, TX_INTRS, + tx_intrs | 1 << ring_index); + } + } + } + break; + default: + break; + } + } + break; + case BCM2838_GENET_TDMA_RING_CFG: + if (exst_ring_en != incm_ring_en) { + trace_bcm2838_genet_tx_dma_ring(incm_ring_en); + } + break; + case BCM2838_GENET_TDMA_CTRL: + if (exst_tdma_en != incm_tdma_en) { + s->regs.tdma.status = FIELD_DP32(s->regs.tdma.status, + GENET_DMA_STATUS, + DISABLED, !exst_tdma_en); + trace_bcm2838_genet_tx_dma(incm_tdma_en == 1 + ? "enabled" + : "disabled"); + } + if (exst_ring_en != incm_ring_buf_en) { + trace_bcm2838_genet_tx_dma_ring_buf(incm_ring_buf_en); + } + break; + default: + break; + } +} + static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned size) { uint64_t value = ~0; @@ -477,7 +696,7 @@ static void bcm2838_genet_write(void *opaque, hwaddr offset, uint64_t value, break; case BCM2838_GENET_TDMA_REGS ... BCM2838_GENET_TDMA_REGS + sizeof(BCM2838GenetRegsTdma) - 1: - qemu_log_mask(LOG_UNIMP, "TDMA isn't implemented yet"); + bcm2838_genet_tdma(s, offset, value); break; default: break; diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index 7a483bd265..f96ea3a145 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -108,6 +108,21 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) #define BCM2838_GENET_PHY_EXP_SHD_BLOCKS_CNT 256 #define BCM2838_GENET_PHY_EXP_SHD_REGS_CNT 256 +#define MAX_FRAME_SIZE 0xFFF +#define MAX_PACKET_SIZE 1518 +#define MAX_PAYLOAD_SIZE 1500 +#define TX_MIN_PKT_SIZE 60 + + +typedef struct BCM2838GenetXmitStatus { + uint32_t length_status; /* length and peripheral status */ + uint32_t ext_status; /* Extended status */ + uint32_t rx_csum; /* partial rx checksum */ + uint32_t unused1[9]; /* unused */ + uint32_t tx_csum_info; /* Tx checksum info. */ + uint32_t unused2[3]; /* unused */ +} BCM2838GenetXmitStatus; + typedef struct { uint32_t rev_ctrl; uint32_t port_ctrl; @@ -403,6 +418,8 @@ struct BCM2838GenetState { qemu_irq irq_default; qemu_irq irq_prio; + + uint8_t tx_packet[MAX_FRAME_SIZE]; }; #endif /* BCM2838_GENET_H */ From patchwork Sun Dec 3 21:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XO2v3NCB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0PM67y5z23nJ for ; Mon, 4 Dec 2023 08:32:07 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2L-0002HW-43; Sun, 03 Dec 2023 16:30:01 -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 1r9u24-0001Wg-Oq; Sun, 03 Dec 2023 16:29:44 -0500 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u22-0005Ve-J1; Sun, 03 Dec 2023 16:29:44 -0500 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-db4364ecd6aso1305336276.2; Sun, 03 Dec 2023 13:29:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638981; x=1702243781; 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=B9Nhv49pbU7bZ8mzot2h9NoKamHuW2o0gQPpPceL6vk=; b=XO2v3NCB7p/YwhRcFGhX+VlO/bGgXnsm+8B6zE0ehPl184Qb2wr9nZApTKVRrsOAi0 9noulvaWKAFvrOEHiwWI8yssmRJnLpDGVyV+Btr4z2HLHsdi5qpPNYtyZmm6uccbMlur mQ7NWNo8/+pT7pvr7S0NvcNU3dmfZGvEm0uRKHXFxVidxnuH7cB4TLOLUxNMwWghPGc1 s0pD9Fq+ih0b3XdQThLo7y/cf2hhwvWxh6wXKBchnGp5OCjSUZXHrQ8SPT3h+FZj4Fje eBEp46/4rlytGpfK1xqm1TJsrShm3BS/l635XQjgOdd1i9a/2eMQqaBmV5CvL4LnjZ+K LCHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638981; x=1702243781; 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=B9Nhv49pbU7bZ8mzot2h9NoKamHuW2o0gQPpPceL6vk=; b=VlsFsnTFaO+XzPgIbnlyHEiyGUEEXArdSzJXW+davy2ZDIic0FB3r+JN340jLJ8NB8 uJcaJJQ8zHxzNCV3qON1eCDfMDeL0j1WjeuQsQ1Z0qOD47P9vnSsIdwK89iBSqtLA1Sj Kd42Aavn0JqKiehiLJyxGFESn3H7fMsNgQJwjqIvCuPXHqW1jKifS/+wpDAZpoijjVS/ v+GBxVgJBv5/nzAg9g6vmjsXr6VX9DK36KVCIPbq2eaRo4HShR1ICcziDLTtH8N3CxYA MfhVf3h6PdQhfQABs5wfOUAFwi9bPfocV6wlje3hdl2DYxtaRD2sGRNJdIzTwGvRXbQk Crzw== X-Gm-Message-State: AOJu0YxNrEJXP0y4QZKMRxi59iXGVXE45LPs5THUmu5Q7CL/W70urtjb C3gdLxuR8YK6mcYyFP/v9FqYPnBGw3la3A== X-Google-Smtp-Source: AGHT+IFYin58bPcCCufSrED+mKmG2VfbkoT0LjAXednkwPUT24qcEKHhmhwgGv3OJBG9i2zf4rH2wA== X-Received: by 2002:a25:cad0:0:b0:db7:dacf:4d52 with SMTP id a199-20020a25cad0000000b00db7dacf4d52mr786191ybg.78.1701638980966; Sun, 03 Dec 2023 13:29:40 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:40 -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 31/45] Implement GENET RX path Date: Sun, 3 Dec 2023 15:28:51 -0600 Message-Id: <20231203212905.1364036-32-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-31-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b29; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb29.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 265 ++++++++++++++++++++++++++++++++- include/hw/net/bcm2838_genet.h | 1 + 2 files changed, 265 insertions(+), 1 deletion(-) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 4c9b39a3ca..61c1981e10 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -511,6 +511,25 @@ static bool bcm2838_genet_tdma_ring_active(BCM2838GenetState *s, return active; } +static bool bcm2838_genet_rdma_ring_active(BCM2838GenetState *s, + unsigned int ring_index) +{ + uint32_t ring_mask = 1 << ring_index; + + bool dma_en = FIELD_EX32(s->regs.rdma.ctrl, GENET_DMA_CTRL, EN) != 0; + bool ring_en = (FIELD_EX32(s->regs.rdma.ring_cfg, GENET_DMA_RING_CFG, EN) + & ring_mask) != 0; + bool ring_buf_en = (FIELD_EX32(s->regs.rdma.ctrl, + GENET_DMA_CTRL, RING_BUF_EN) + & ring_mask) != 0; + bool active = dma_en && ring_en && ring_buf_en; + + trace_bcm2838_genet_rx_dma_ring_active(ring_index, + active ? "active" : "halted"); + + return active; +} + static void bcm2838_genet_tdma(BCM2838GenetState *s, hwaddr offset, uint64_t value) { @@ -721,9 +740,251 @@ static const MemoryRegionOps bcm2838_genet_ops = { .valid = {.min_access_size = 4}, }; +static int32_t bcm2838_genet_filter(BCM2838GenetState *s, const void *buf, + size_t size) +{ + qemu_log_mask(LOG_UNIMP, + "Packet filtration with HFB isn't implemented yet"); + return -1; +} + +static int32_t bcm2838_genet_filter2ring(BCM2838GenetState *s, + uint32_t filter_idx) +{ + qemu_log_mask(LOG_UNIMP, + "Packet filtration with HFB isn't implemented yet"); + return -1; +} + +static bool is_packet_broadcast(const uint8_t *buf, size_t size) +{ + static const uint8_t bcst_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + if (size < sizeof(bcst_addr)) { + return false; + } + + return !memcmp(buf, bcst_addr, sizeof(bcst_addr)); +} + +static bool is_packet_multicast(const uint8_t *buf, size_t size) +{ + return !!(buf[0] & 0x01); +} + +static ssize_t bcm2838_genet_rdma(BCM2838GenetState *s, uint32_t ring_idx, + const void *buf, size_t size) +{ + const size_t DESC_WORD_SIZE = + sizeof(BCM2838GenetRdmaDesc) / sizeof(uint32_t); + + ssize_t len = 0; + BCM2838GenetRegsRdma *rdma = &s->regs.rdma; + BCM2838GenetRdmaRing *ring = &rdma->rings[ring_idx]; + hwaddr write_index = + (ring->write_ptr + ((hwaddr)ring->write_ptr_hi << 32)) / DESC_WORD_SIZE; + BCM2838GenetRdmaDesc *desc = &rdma->descs[write_index]; + + const hwaddr START_INDEX = + (ring->start_addr + ((hwaddr)ring->start_addr_hi << 32)) + / DESC_WORD_SIZE; + const hwaddr END_INDEX = + (ring->end_addr + ((hwaddr)ring->end_addr_hi << 32)) / DESC_WORD_SIZE; + + if (!bcm2838_genet_rdma_ring_active(s, ring_idx)) { + return -1; + } + + desc->length_status = FIELD_DP32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, SOP, 1); + + while (len < size) { + size_t l = size - len; + size_t buf_size = ring->ring_buf_size & 0xffff; + uint8_t *dma_buf = s->rx_packet; + hwaddr dma_buf_addr = + desc->address_lo + ((hwaddr)desc->address_hi << 32); + MemTxResult mem_tx_result = MEMTX_OK; + uint8_t *frame_buf = dma_buf + sizeof(BCM2838GenetXmitStatus) + 2; + BCM2838GenetXmitStatus *xmit_status = (BCM2838GenetXmitStatus *)dma_buf; + struct iovec iov; + bool isip4, isip6; + size_t l3hdr_off, l4hdr_off, l5hdr_off; + eth_ip6_hdr_info ip6hdr_info; + eth_ip4_hdr_info ip4hdr_info; + eth_l4_hdr_info l4hdr_info; + + bool crc_fwd = FIELD_EX32(s->regs.umac.cmd, GENET_UMAC_CMD, CRC_FWD); + size_t buflength; + uint32_t prod_index; + + if (l > ring->ring_buf_size) { + l = ring->ring_buf_size; + } + + memcpy(frame_buf, buf + len, l); + iov.iov_base = frame_buf; + iov.iov_len = l; + eth_get_protocols(&iov, 1, 0, + &isip4, &isip6, + &l3hdr_off, &l4hdr_off, &l5hdr_off, + &ip6hdr_info, &ip4hdr_info, &l4hdr_info); + + len += l; + + desc->length_status = FIELD_DP32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, + EOP, !!(len >= size)); + + buflength = l + sizeof(BCM2838GenetXmitStatus) + 2; + if (crc_fwd) { + buflength += 4; + } + + desc->length_status = FIELD_DP32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, + BUFLENGTH, buflength); + + desc->length_status = FIELD_DP32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, + BROADCAST, + !!is_packet_broadcast(frame_buf, l)); + desc->length_status = FIELD_DP32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, + MULTICAST, + !!is_packet_multicast(frame_buf, l)); + + xmit_status->rx_csum = 0; + if (isip4) { + xmit_status->rx_csum = ip4hdr_info.ip4_hdr.ip_sum; + } + xmit_status->length_status = desc->length_status; + + mem_tx_result = address_space_write(&s->dma_as, dma_buf_addr, + MEMTXATTRS_UNSPECIFIED, + dma_buf, buf_size); + if (mem_tx_result != MEMTX_OK) { + desc->length_status = FIELD_DP32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, + RXERR, 1); + } + + if (FIELD_EX32(desc->length_status, + GENET_RDMA_LENGTH_STATUS, RXERR) != 0) { + break; + } + + prod_index = FIELD_EX32(ring->prod_index, GENET_DMA_PROD_INDEX, INDEX); + ring->prod_index = FIELD_DP32(ring->prod_index, + GENET_DMA_PROD_INDEX, + INDEX, ++prod_index); + if (++write_index > END_INDEX) { + write_index = START_INDEX; + } + desc = &rdma->descs[write_index]; + ring->write_ptr = write_index * DESC_WORD_SIZE; + ring->write_ptr_hi = ((hwaddr)write_index * DESC_WORD_SIZE) >> 32; + } + + if (ring_idx == BCM2838_GENET_DMA_RING_DEFAULT) { + s->regs.intrl0.stat = FIELD_DP32(s->regs.intrl0.stat, + GENET_INTRL_0, RXDMA_MBDONE, 1); + } else { + uint32_t rx_intrs = + FIELD_EX32(s->regs.intrl1.stat, GENET_INTRL_1, RX_INTRS); + rx_intrs |= 1 << ring_idx; + + s->regs.intrl1.stat = FIELD_DP32(s->regs.intrl1.stat, + GENET_INTRL_1, RX_INTRS, rx_intrs); + } + + return len; +} + +static ssize_t bcm2838_genet_receive(NetClientState *nc, const uint8_t *buf, + size_t size) +{ + BCM2838GenetState *s = (BCM2838GenetState *)qemu_get_nic_opaque(nc); + ssize_t bytes_received = -1; + int32_t filter_index = -1; + int32_t ring_index = -1; + + if (FIELD_EX32(s->regs.rdma.ctrl, GENET_DMA_CTRL, EN) != 0) { + filter_index = bcm2838_genet_filter(s, buf, size); + + if (filter_index >= 0) { + ring_index = bcm2838_genet_filter2ring(s, filter_index); + } else { + ring_index = BCM2838_GENET_DMA_RING_CNT - 1; + } + + if (size <= MAX_PACKET_SIZE) { + bytes_received = bcm2838_genet_rdma(s, ring_index, buf, size); + } + } + + bcm2838_genet_set_irq_default(s); + bcm2838_genet_set_irq_prio(s); + + return bytes_received; +} + +static void bcm2838_genet_phy_update_link(BCM2838GenetState *s) +{ + bool qemu_link_down = qemu_get_queue(s->nic)->link_down != 0; + + bool lstatus = FIELD_EX32(s->phy_regs.bmsr, GENET_PHY_BMSR, LSTATUS) != 0; + + if (qemu_link_down && lstatus) { + trace_bcm2838_genet_phy_update_link("down"); + + s->phy_regs.bmsr = FIELD_DP32(s->phy_regs.bmsr, + GENET_PHY_BMSR, ANEGCOMPLETE, 0); + s->phy_regs.bmsr = FIELD_DP32(s->phy_regs.bmsr, + GENET_PHY_BMSR, LSTATUS, 0); + s->regs.intrl0.stat = FIELD_DP32(s->regs.intrl0.stat, + GENET_INTRL_0, LINK_DOWN, 1); + } else if (!qemu_link_down && !lstatus) { + trace_bcm2838_genet_phy_update_link("up"); + + /* + * Complete auto-negotiation (fixed link partner's abilities for now: + * 1Gbps with flow control) + */ + s->phy_regs.stat1000 = FIELD_DP32(s->phy_regs.stat1000, + GENET_PHY_STAT_1000, HALF, 1); + s->phy_regs.stat1000 = FIELD_DP32(s->phy_regs.stat1000, + GENET_PHY_STAT_1000, FULL, 1); + + s->phy_regs.lpa = FIELD_DP32(s->phy_regs.lpa, + GENET_PHY_LPA, PAUSE_CAP, 1); + s->phy_regs.lpa = FIELD_DP32(s->phy_regs.lpa, + GENET_PHY_LPA, PAUSE_ASYM, 1); + s->phy_regs.lpa = FIELD_DP32(s->phy_regs.lpa, GENET_PHY_LPA, LPACK, 1); + + s->phy_regs.bmsr = FIELD_DP32(s->phy_regs.bmsr, + GENET_PHY_BMSR, ANEGCOMPLETE, 1); + s->phy_regs.bmsr = FIELD_DP32(s->phy_regs.bmsr, + GENET_PHY_BMSR, LSTATUS, 1); + + s->regs.intrl0.stat = FIELD_DP32(s->regs.intrl0.stat, + GENET_INTRL_0, LINK_UP, 1); + } + + bcm2838_genet_set_irq_default(s); +} +static void bcm2838_genet_set_link(NetClientState *nc) +{ + BCM2838GenetState *s = qemu_get_nic_opaque(nc); + + bcm2838_genet_phy_update_link(s); +} + static NetClientInfo bcm2838_genet_client_info = { .type = NET_CLIENT_DRIVER_NIC, - .size = sizeof(NICState) + .size = sizeof(NICState), + .receive = bcm2838_genet_receive, + .link_status_changed = bcm2838_genet_set_link, }; static void bcm2838_genet_realize(DeviceState *dev, Error **errp) @@ -777,6 +1038,8 @@ static void bcm2838_genet_phy_reset(BCM2838GenetState *s) s->phy_aux_ctl_shd_regs.misc = 0x1E; trace_bcm2838_genet_phy_reset("done"); + + bcm2838_genet_phy_update_link(s); } static void bcm2838_genet_reset(DeviceState *d) diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index f96ea3a145..f044d0d17e 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -420,6 +420,7 @@ struct BCM2838GenetState { qemu_irq irq_prio; uint8_t tx_packet[MAX_FRAME_SIZE]; + uint8_t rx_packet[MAX_FRAME_SIZE]; }; #endif /* BCM2838_GENET_H */ From patchwork Sun Dec 3 21:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WL/GMVtH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Vg0275z23mf for ; Mon, 4 Dec 2023 08:36:42 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2O-0002QZ-Nv; Sun, 03 Dec 2023 16:30:04 -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 1r9u25-0001XL-4k; Sun, 03 Dec 2023 16:29:46 -0500 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u23-0005W4-GE; Sun, 03 Dec 2023 16:29:44 -0500 Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-db54ec0c7b8so1828654276.0; Sun, 03 Dec 2023 13:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638982; x=1702243782; 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=FgtBxKk/YnE0/ZchwODTjsH1Cpkh2DZnmTE8Tpp7q3Y=; b=WL/GMVtHbLnryvwIt6la21AZG/TjoU1eba1HAxSL/zns4WJXpDvGrscnkWVezge4jh kMMfTWecTUOuiUyfo0zamI4lSPo2XeVmNc19BOSOwSWiVa9puHL6WBUI6bLJDQxl7H/f q110G2IM5/YFUz91JvFeF3ZEH5UbV2P0xjOGwqu1lqNyY3OhzvraoGaYzInZafUbNql7 m5Sn6BXfn5l+803EtbYdcNYuYcJtAJyrLrGzOzKG9qKb4I4u3oXBPyZz6sc4DERToM8S d5JMveJVaW4gk4fp9g3Rv2UBRbxodkm0gAYHVWxVeYi5iAelsLVg0MAa7+c+ZQvEO0L8 057g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638982; x=1702243782; 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=FgtBxKk/YnE0/ZchwODTjsH1Cpkh2DZnmTE8Tpp7q3Y=; b=VaHQOjGgowUN8EkP41yP7hpgERWRw2De0bVJbQo4kTYdAvM2ATgtq4WAUdznQEtB+X +G2w+lbmOBPpGxOOTIWC4a6pzriWPjInkiHKa7Ts48aEi/JzdUqUwzs+t4l5Do/HCMig J6zlQ9UCDC2TWl2CBN+Dyuj6RgqRirxPr1vp0gY0t8YVrsypNNNRgBfymqI85YJAeoZ+ v8+Y+YIsWg9eoabjuczQ2hWW/Xi9Pm3B/L6a/pjoFbzRn6VouNWMT7M8Z+e+1dSne38W hKXIand+a+7fveZEduC9D56YR/8729KeVCfLVeJk9gdC6/zCukS0lYD0nWdv8qr51V2T QAxA== X-Gm-Message-State: AOJu0Yx8rypW8ZZpb/uggD/TxNns2lqSQvXNlwWUboGNyQvnGa5o1Hqa XDhSLzxiOIf/2rHWdtub970R5g6l3TUhxA== X-Google-Smtp-Source: AGHT+IFNrew00qL7YYyOpxxX6pxCfcbCgDjQdQMxsdvPiY37hiwp8SbCnwMTcNJA939HfYJIN4icOg== X-Received: by 2002:a05:6902:18c3:b0:db7:d3f9:add7 with SMTP id ck3-20020a05690218c300b00db7d3f9add7mr2124041ybb.31.1701638981962; Sun, 03 Dec 2023 13:29:41 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:41 -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 32/45] Enable BCM2838 GENET controller Date: Sun, 3 Dec 2023 15:28:52 -0600 Message-Id: <20231203212905.1364036-33-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-32-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b31; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb31.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 16 ++++++++++++++++ hw/arm/raspi4b.c | 17 ----------------- include/hw/arm/bcm2838_peripherals.h | 2 ++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index 65a659c15c..d962999daf 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -47,6 +47,15 @@ static void bcm2838_peripherals_init(Object *obj) object_initialize_child(obj, "pcie-host", &s->pcie_host, TYPE_BCM2838_PCIE_HOST); + /* Gigabit Ethernet */ + object_initialize_child(obj, "genet", &s->genet, TYPE_BCM2838_GENET); + for (int i = 0; i < nb_nics; i++) { + if ((nd_table[i].used && nd_table[i].model) && !strcmp(nd_table[i].model, "bcmgenet")) { + qdev_set_nic_properties(DEVICE(&s->genet), &nd_table[i]); + break; + } + } + /* Extended Mass Media Controller 2 */ object_initialize_child(obj, "emmc2", &s->emmc2, TYPE_SYSBUS_SDHCI); @@ -231,6 +240,13 @@ static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp) memory_region_add_subregion(get_system_memory(), PCIE_MMIO_ARM_OFFSET, &s->pcie_mmio_alias); + /* Gigabit Ethernet */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->genet), errp)) { + return; + } + regs_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->genet), 0); + memory_region_add_subregion(&s->peri_low_mr, GENET_OFFSET, regs_mr); + create_unimp(s_base, &s->clkisp, "bcm2835-clkisp", CLOCK_ISP_OFFSET, CLOCK_ISP_SIZE); diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c index fda27d36cb..8aa8dfb087 100644 --- a/hw/arm/raspi4b.c +++ b/hw/arm/raspi4b.c @@ -64,23 +64,6 @@ static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt) { - - /* Temporarily disable following devices until they are implemented*/ - const char *to_be_removed_from_dt_as_wa[] = { - "brcm,bcm2711-genet-v5", - }; - - for (int i = 0; i < ARRAY_SIZE(to_be_removed_from_dt_as_wa); i++) { - const char *dev_str = to_be_removed_from_dt_as_wa[i]; - - int offset = fdt_node_offset_by_compatible(fdt, -1, dev_str); - if (offset >= 0) { - if (!fdt_nop_node(fdt, offset)) { - warn_report("bcm2711 dtc: %s has been disabled!", dev_str); - } - } - } - uint64_t ram_size = board_ram_size(info->board_id); if (info->ram_size > UPPER_RAM_BASE) { diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 20b7d1eb67..1cfcf5dcce 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -13,6 +13,7 @@ #include "hw/misc/bcm2838_rng200.h" #include "hw/misc/bcm2838_thermal.h" #include "hw/arm/bcm2838_pcie.h" +#include "hw/net/bcm2838_genet.h" #include "hw/sd/sdhci.h" #include "hw/gpio/bcm2838_gpio.h" @@ -73,6 +74,7 @@ struct BCM2838PeripheralState { UnimplementedDeviceState clkisp; BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; + BCM2838GenetState genet; OrIRQState mmc_irq_orgate; OrIRQState dma_7_8_irq_orgate; From patchwork Sun Dec 3 21:28:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JZQcGgNJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Ry1QPZz23nJ for ; Mon, 4 Dec 2023 08:34:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2F-00023g-5Y; Sun, 03 Dec 2023 16:29:55 -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 1r9u25-0001Xd-VU; Sun, 03 Dec 2023 16:29:46 -0500 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u24-0005WP-FB; Sun, 03 Dec 2023 16:29:45 -0500 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-da7ea62e76cso2173423276.3; Sun, 03 Dec 2023 13:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638983; x=1702243783; 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=jt9YUbIlO6FMtWaTdWEGV74ka7r2AOm7LpJmnrybMmM=; b=JZQcGgNJGkZ40inncOzr+0iVYEdE6ggHiXHhvHWqPd5zobWRxPAXb59iQWcJ7F6cfI QgPZ0LcB3Dsk7T4iChW6I+mp/24OruWWWbPmV4FyeOlJYli+YTXQp/QuYsWPYIqUoNoe fRtHkhdIRk1oiJEbEiO7/zumMbEZuskBHIpP8TWogwrLzQvgMooejhYuxCC3irzAKteo CficW6XWEh1AN4b9auSwU/DePx8+I419lL3ssQm6DT7/SNZ8KH1TwQWDpWd1HipX79W7 6MF4C0jIA/nACxRa6FxDArBjnR/TQr2QjvG+gJZGB3kkQVE2l6BBiHuuRrbUIRJp4dO6 6ntw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638983; x=1702243783; 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=jt9YUbIlO6FMtWaTdWEGV74ka7r2AOm7LpJmnrybMmM=; b=DXg5yCYvWz4CLwNr91WG4hfvjCChs8hXqTMB6Bh62yg1vvz5XPKKFDqK5GRjIPU4z3 zQOvT3yYiVFE/uxCJXeEd/7zkS7kNnY3m1ov1gFJrTFw2IzzGaYPXwQ3fWTc4YhETA6G qYhR0nPAEUL+8d28vi4RbR5ihagLeU6vROl1Nc3DxXExwHWKYp+hEE4yMC5ssWNCff4U EFPf2W9esIZ12K7gWPegqebhbXTg1GRQXvd8Vx00bNRf3H8nfzIsSS1BomJVTWPjqpk6 2gNvJS++jRD06w3EQOWB+VMSaSaTb5GaI79ygS2aq27aQjXjCS8DuUVgIG81wFzpd2vS 81nQ== X-Gm-Message-State: AOJu0YxjaHMokGOmatqVGVSbSRlGxA2vUypIp4RA2cRkfHh4oVUZiySP kagSuIhIfwWAWjfIU6hrs3bo8EfuFv4Kbg== X-Google-Smtp-Source: AGHT+IFwI5FAGdTpugcfeoKjWKEif7gS5+v4p1Iv2+p77uYD0eJUS07+If1PkjLhbPkH7oIEf1IKXg== X-Received: by 2002:a25:2182:0:b0:da0:b36c:1af1 with SMTP id h124-20020a252182000000b00da0b36c1af1mr1654545ybh.62.1701638982999; Sun, 03 Dec 2023 13:29:42 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:42 -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 33/45] Connect RNG200, PCIE and GENET to GIC Date: Sun, 3 Dec 2023 15:28:53 -0600 Message-Id: <20231203212905.1364036-34-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-33-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2a; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838.c | 19 +++++++++++++++++++ include/hw/arm/bcm2838_peripherals.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c index 89cd9d5d8c..83f84b22ad 100644 --- a/hw/arm/bcm2838.c +++ b/hw/arm/bcm2838.c @@ -210,6 +210,10 @@ static void bcm2838_realize(DeviceState *dev, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->dwc2), 0, qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_DWC2)); + /* Connect RNG200 to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps->rng200), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_RNG200)); + /* Connect DMA 0-6 to the interrupt controller */ for (int_n = GIC_SPI_INTERRUPT_DMA_0; int_n <= GIC_SPI_INTERRUPT_DMA_6; int_n++) { @@ -232,6 +236,21 @@ static void bcm2838_realize(DeviceState *dev, Error **errp) qdev_connect_gpio_out(dma_9_10_irq_orgate, 0, qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_DMA_9_10)); + /* Connect PCIe host bridge to the interrupt controller */ + for (n = 0; n < BCM2838_PCIE_NUM_IRQS; n++) { + int_n = GIC_SPI_INTERRUPT_PCI_INT_A + n; + sysbus_connect_irq(SYS_BUS_DEVICE(&ps->pcie_host), n, + qdev_get_gpio_in(gicdev, int_n)); + bcm2838_pcie_host_set_irq_num(BCM2838_PCIE_HOST(&ps->pcie_host), n, + int_n); + } + + /* Connect Gigabit Ethernet controller to the interrupt controller */ + sysbus_connect_irq(SYS_BUS_DEVICE(&ps->genet), 0, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_GENET_A)); + sysbus_connect_irq(SYS_BUS_DEVICE(&ps->genet), 1, + qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_GENET_B)); + /* Pass through inbound GPIO lines to the GIC */ qdev_init_gpio_in(dev, bcm2838_gic_set_irq, GIC_NUM_IRQS); diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h index 1cfcf5dcce..cdeb892f04 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -17,6 +17,8 @@ #include "hw/sd/sdhci.h" #include "hw/gpio/bcm2838_gpio.h" +#define GENET_OFFSET 0x1580000 + /* SPI */ #define GIC_SPI_INTERRUPT_MBOX 33 #define GIC_SPI_INTERRUPT_MPHI 40 From patchwork Sun Dec 3 21:28:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=EH08Mf+m; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Sq5K7Nz23nJ for ; Mon, 4 Dec 2023 08:35:07 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2S-0002Vz-FI; Sun, 03 Dec 2023 16:30:08 -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 1r9u29-0001fy-80; Sun, 03 Dec 2023 16:29:50 -0500 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u25-0005Wy-PQ; Sun, 03 Dec 2023 16:29:47 -0500 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-db3a09e96daso2128364276.3; Sun, 03 Dec 2023 13:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638984; x=1702243784; 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=mcF9QghvfuN/SOxiRcej/fFnaurGCk30s1qkfL8vZWQ=; b=EH08Mf+m+DfFBWiIhjb0gKzZFAVN/boP2AgHg/fPVIUzqQW0i1tVJnJNqL9U+s6FNs atcwpUpnY8I8DLMwiw3kqddyi6IdzhJgTF4l72F1BbxUVStx3Mefjrv61zF62fNmrQDv dDwYd5a+ULIdDyU7tfBX21K7g/xEa51Lkvuskw2yWJda1PfvRnLe/L0rlnNgUVfvEYEq kJS5m8I98SbZBpmQt08aVuLcP6huam9wf8mJ/5B5jyneH2uR/N9IAQ4+4dR5VPQiaVtD Ai6+XcBCMh2CQls20T4oMmBG+kOpEXNoaNCm6OaK6z1x7AGP43YSksU9i8m/5rWH+lR1 6CrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638984; x=1702243784; 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=mcF9QghvfuN/SOxiRcej/fFnaurGCk30s1qkfL8vZWQ=; b=jzYL5fBENXB2lmIpl0uC28+UltCLDsQbj7jihOG9tA0mwG1w9GQboYH2iNbxAPH/XU npP9wextHOKNTq1a7m5vwzPLDwb3cxmDsD1ARdoxe/s2amuRqADLuNx4axjwbGAhOzQC qE3x5ztw/mu5wKdMw2FBOVxUeg1d57fcCgPN9RZNKyLi/3qewrsZbXiolnxNvBS6rJPn x44ZxVNmAQgnlnMHUAJgT9HVU3XifwiMCa41YfkQJT+inTNxp2qxLmdexrAdSWpUX/A0 zMGRxmPaQVrTjIwqIIKFrchdib07L8s8u/Up1AsZb6xhXJoeeHAaHKWXYPBV1fgKE26N L9jw== X-Gm-Message-State: AOJu0Yxd2wEz5Q3Gx/89tutwUG7eu95MAcERlcfjaqB+dW9maPNDMFfM OSErWi607Jp3aHb18TWvKa3NKoi8Wd7M4g== X-Google-Smtp-Source: AGHT+IFTharRN2hzDXvkDULj3zQT5Q6jV9t1sie8grDzO/ukAKOam8cidsKUvnjklZD80nDgzE0zRA== X-Received: by 2002:a25:d0e:0:b0:db7:dad0:60c0 with SMTP id 14-20020a250d0e000000b00db7dad060c0mr1743781ybn.77.1701638984197; Sun, 03 Dec 2023 13:29:44 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:43 -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 34/45] Add Rpi4b boot tests Date: Sun, 3 Dec 2023 15:28:54 -0600 Message-Id: <20231203212905.1364036-35-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-34-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b30; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb30.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/avocado/boot_linux_console.py | 92 +++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tests/avocado/boot_linux_console.py b/tests/avocado/boot_linux_console.py index 6eab515718..62aac02bbb 100644 --- a/tests/avocado/boot_linux_console.py +++ b/tests/avocado/boot_linux_console.py @@ -501,6 +501,98 @@ def test_arm_raspi2_initrd(self): # Wait for VM to shut down gracefully self.vm.wait() + def test_arm_raspi4(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=machine:raspi4b2g + :avocado: tags=device:pl011 + :avocado: tags=accel:tcg + :avocado: tags=rpi4b + + The kernel can be rebuilt using the kernel source referenced + and following the instructions on the on: + https://www.raspberrypi.org/documentation/linux/kernel/building.md + """ + + deb_url = ('http://archive.raspberrypi.org/debian/' + 'pool/main/r/raspberrypi-firmware/' + 'raspberrypi-kernel_1.20230106-1_arm64.deb') + deb_hash = '08dc55696535b18a6d4fe6fa10d4c0d905cbb2ed' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img') + dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2711-rpi-4-b.dtb') + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'earlycon=pl011,mmio32,0xfe201000 ' + + 'console=ttyAMA0,115200 ' + + 'root=/dev/mmcblk1p2 rootwait ' + + 'dwc_otg.fiq_fsm_enable=0') + self.vm.add_args('-kernel', kernel_path, + '-dtb', dtb_path, + '-append', kernel_command_line, + '-device', 'qemu-xhci,bus=pcie.1,id=xhci', + '-device', 'usb-kbd,bus=xhci.0') + self.vm.launch() + console_pattern = 'Kernel command line: %s' % kernel_command_line + self.wait_for_console_pattern(console_pattern) + console_pattern = 'Product: QEMU USB Keyboard' + self.wait_for_console_pattern(console_pattern) + + + def test_arm_raspi4_initrd(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=machine:raspi4b2g + :avocado: tags=device:pl011 + :avocado: tags=accel:tcg + :avocado: tags=rpi4b + + The kernel can be rebuilt using the kernel source referenced + and following the instructions on the on: + https://www.raspberrypi.org/documentation/linux/kernel/building.md + """ + deb_url = ('http://archive.raspberrypi.org/debian/' + 'pool/main/r/raspberrypi-firmware/' + 'raspberrypi-kernel_1.20230106-1_arm64.deb') + deb_hash = '08dc55696535b18a6d4fe6fa10d4c0d905cbb2ed' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img') + dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2711-rpi-4-b.dtb') + + initrd_url = ('https://github.com/groeck/linux-build-test/raw/' + '86b2be1384d41c8c388e63078a847f1e1c4cb1de/rootfs/' + 'arm64/rootfs.cpio.gz') + initrd_hash = 'f3d4f9fa92a49aa542f1b44d34be77bbf8ca5b9d' + initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + initrd_path = os.path.join(self.workdir, 'rootfs.cpio') + archive.gzip_uncompress(initrd_path_gz, initrd_path) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'earlycon=pl011,mmio32,0xfe201000 ' + + 'console=ttyAMA0,115200 ' + + 'panic=-1 noreboot ' + + 'dwc_otg.fiq_fsm_enable=0') + self.vm.add_args('-kernel', kernel_path, + '-dtb', dtb_path, + '-initrd', initrd_path, + '-append', kernel_command_line, + '-device', 'qemu-xhci,bus=pcie.1,id=xhci', + '-device', 'usb-kbd,bus=xhci.0', + '-no-reboot') + self.vm.launch() + self.wait_for_console_pattern('Boot successful.') + + exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', + 'BCM2835') + exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', + 'cprman@7e101000') + exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted') + # TODO: Raspberry Pi4 doesn't shut down properly with recent kernels + # Wait for VM to shut down gracefully + #self.vm.wait() + def test_arm_exynos4210_initrd(self): """ :avocado: tags=arch:arm From patchwork Sun Dec 3 21:28:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Lc4cHjJq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0XG3JsVz23mf for ; Mon, 4 Dec 2023 08:38:06 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2P-0002SW-Lu; Sun, 03 Dec 2023 16:30:05 -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 1r9u29-0001fx-7S; Sun, 03 Dec 2023 16:29:50 -0500 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u26-0005XL-LY; Sun, 03 Dec 2023 16:29:48 -0500 Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-db3a09e96daso2128378276.3; Sun, 03 Dec 2023 13:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638985; x=1702243785; 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=Lc4cHjJqek4Y71WF9AtBEIcTHF+L4JjqM0Asl0BGwQPxFrMHHyWLYW57m9q8ITBz/k rBLBEXHn0NjJMSCMThuadCBKph1G6g5N86JRKS4IZZs79GFATYW1k5vSnaR8JVTh2kFM IB+sePGG+f2s9c8m12H5IJJOGkO+g8/j+tNHb4YhMt0DUP5XrVnYAymKosgUzTC4HBZ+ 90BPkBAf/vEm24qEhnDRtRUS2/YhsGrHwjRx7g35bTeyKIMfNZxTTC3JA6Hs+J3UZK/V Y9d3vsnxkJ5yqgrd+C3ZgzLBwZlHsKD0YmV7r+7ZUywtFNY8QYcbRnlhN3dz1W+hcA0F ygZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638985; x=1702243785; 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=n2xAdgHNnCtq/NFc2h/393H9nhtuBxfQOTaOr26elXOxSjz/qYl19kfKckwrnbrd3P T32i2X1owel1eRUpUzIjjQfTcpV6/G1z1riPbeIBIWsaubif9Drkfg3smvStzrZYk01q vEJxEgH7EozIzjXAAW+jnDhUL7BS1PWyFWNO21JJ1rPzTMxjUnigkIVrvcVMPB0kz6yH HLuhiXgDpA6bpaEMOa0jPDNsIOwwth7saM9fX3Knlv4epeIHK9ZAnQgi0Q1IOetbf2ZH EdfBiKIavXfUBk55gG3CYcTaKtypmaUVynqvK8Shs0x2MUtf7mFiyyOlFroWkPEmIEDa Xg0w== X-Gm-Message-State: AOJu0YzL2aWu81WsBSKHmQ8ESlr8Iq0CKiYKsf+6Eulvv86LqsSqDP15 pSx8yClfsFdp8C+ucFk4N5zskLKNqqeheA== X-Google-Smtp-Source: AGHT+IHcXBJEStRHNgKLnyOEgU8IXNTvETtjJ39PlKV6r54lxeGc3mQqUefYpvjuDHV2Xg/z06sjXA== X-Received: by 2002:a5b:c0c:0:b0:db5:248a:ebd1 with SMTP id f12-20020a5b0c0c000000b00db5248aebd1mr2006934ybq.54.1701638985145; Sun, 03 Dec 2023 13:29:45 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:44 -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 35/45] Add mailbox test stub Date: Sun, 3 Dec 2023 15:28:55 -0600 Message-Id: <20231203212905.1364036-36-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-35-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b31; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb31.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 +#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 later. + * 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 data) +{ + uint32_t reg; + + reg = FIELD_DP32(reg, MBOX_WRITE_REG, CHANNEL, channel); + reg = 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 = qtest_mbox0_read_reg32(s, MBOX_REG_READ); + g_assert_cmphex(FIELD_EX32(reg, MBOX_WRITE_REG, CHANNEL), ==, channel); + msgaddr = 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 msg_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 later. + * 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 msg_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 = { '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'), } if vnc.found() From patchwork Sun Dec 3 21:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QngOXQxy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0W61Nzhz23p6 for ; Mon, 4 Dec 2023 08:37:06 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2Q-0002Uc-PJ; Sun, 03 Dec 2023 16:30:06 -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 1r9u2A-0001gI-ND; Sun, 03 Dec 2023 16:29:50 -0500 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u28-0005XV-Gk; Sun, 03 Dec 2023 16:29:50 -0500 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-db8892a5f96so844580276.2; Sun, 03 Dec 2023 13:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638986; x=1702243786; 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=KE00WoL8kxJ8pW7oRCni4sp/uw+yPOzo+IEwlEl9WAg=; b=QngOXQxy6GQow+aDt1SQKeQpD/gWxkMeYFbC5I/YZb78VOPx3tMu+IY6SHCKmkYx60 6ofDSOMJTI7L52GbKbjVbTh/OIizMdBxfdLzNNfCE4QVv9pVoU17iOvHQKGBLoXntL6C eXMyDkCr4CCL+EsmjE6iSpFIqu5NEF8NwmeTPrWMnh7DJJ5jTRNQ9wh6wQR4viq872rF ubbKldh2sM3DhVk5zDNEfkeYDCJj559LdIlQn67g61GKFgU7tttSnR2Q0rGpUdk6CIOe feLSlyIn3tFM38cHGzfAskVQOpMqZhsh1YaDsilE5FDit/xCGsZN3+9ISlydW0mmn2vB WFjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638986; x=1702243786; 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=KE00WoL8kxJ8pW7oRCni4sp/uw+yPOzo+IEwlEl9WAg=; b=UMYkZXHOXrdw5LkGdiHvUhySiNdCXfrlDEEPsrhoNWenURKVvnkzPAP3emKmiUk1Dd cIOWDYmegc6cG1jUoqmQ3KflwIXyd+VNEaOA9f4HBdCtpWrw7vEJuHqr05WmK/TRx0lg nJDwT1Hrve0DVEe8FOE1Z5uVQ5/W/upYtqrKzrcP994h54ekfFZyDzTwXemaaKThPR6Z anARoV+EFAY4rHb7QwcJFsfrpVU8Sc4J+7Dg3NmlCfx3ZKH9LVK2hmjaiuXxplWKwhOV DAOPNmtQHuWPME33ViaQ5Bg9smh1SSw8ryGFax4YsVWCP2VIxjbn8NKM32afpJxwohHL RbpQ== X-Gm-Message-State: AOJu0YzYPcGO1+aAZar5jIZ2IYA/f1Te/9hLLo1hVUUrWGQzuhjqxQV/ nyA1Aqc9q/kArj3+JqKGyP2qonMSEmrQLw== X-Google-Smtp-Source: AGHT+IGh4dydh4/Hmgu8Giild8R1wregn1kekSBQU/FL6r1HHrBI5zXZY3p+jJ5IpRiy7kf/3LMh1Q== X-Received: by 2002:a25:293:0:b0:db7:dacf:620a with SMTP id 141-20020a250293000000b00db7dacf620amr1612840ybc.92.1701638986135; Sun, 03 Dec 2023 13:29:46 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:45 -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 36/45] Add mailbox test constants Date: Sun, 3 Dec 2023 15:28:56 -0600 Message-Id: <20231203212905.1364036-37-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-36-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b29; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb29.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mailbox.h | 139 ++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tests/qtest/bcm2838-mailbox.h b/tests/qtest/bcm2838-mailbox.h index 1d02ca9c2c..8acc4bd2ff 100644 --- a/tests/qtest/bcm2838-mailbox.h +++ b/tests/qtest/bcm2838-mailbox.h @@ -7,6 +7,145 @@ * See the COPYING file in the top-level directory. */ +#define MBOX0_BASE 0xFE00B880 +#define MBOX1_BASE 0xFE00B8A0 + +#define MBOX_REG_READ 0x00 +#define MBOX_REG_WRITE 0x00 +#define MBOX_REG_PEEK 0x10 +#define MBOX_REG_SENDER 0x14 +#define MBOX_REG_STATUS 0x18 +#define MBOX_REG_CONFIG 0x1C + +#define MBOX_READ_EMPTY 0x40000000 + +#define MBOX_CHANNEL_ID_PROPERTY 8 + +#define MBOX_PROCESS_REQUEST 0x00000000 +#define MBOX_SUCCESS 0x80000000 +#define MBOX_ERROR_PARSING_BUFFER 0x80000001 + +#define TAG_END 0x00000000 +#define TAG_GET_FIRMWARE_REVISION 0x00000001 +#define TAG_GET_FIRMWARE_VARIANT 0x00000002 +#define TAG_GET_BOARD_REVISION 0x00010002 +#define TAG_GET_ARM_MEMORY 0x00010005 +#define TAG_GET_VC_MEMORY 0x00010006 +#define TAG_SET_DEVICE_POWER_STATE 0x00028001 +#define TAG_GET_CLOCK_STATE 0x00030001 +#define TAG_GET_CLOCK_RATE 0x00030002 +#define TAG_GET_MAX_CLOCK_RATE 0x00030004 +#define TAG_GET_MIN_CLOCK_RATE 0x00030007 +#define TAG_GET_CLOCKS 0x00010007 +#define TAG_GET_TEMPERATURE 0x00030006 +#define TAG_GET_MAX_TEMPERATURE 0x0003000a +#define TAG_ALLOCATE_BUFFER 0x00040001 +#define TAG_RELEASE_FRAMEBUFFER 0x00048001 +#define TAG_BLANK_FRAMEBUFFER 0x00040002 +#define TAG_GET_FB_PHYS_WIDTH 0x00040003 +#define TAG_TEST_FB_PHYS_WIDTH 0x00044003 +#define TAG_SET_FB_PHYS_WIDTH 0x00048003 +#define TAG_GET_FB_VIRT_WIDTH 0x00040004 +#define TAG_TEST_FB_VIRT_WIDTH 0x00044004 +#define TAG_SET_FB_VIRT_WIDTH 0x00048004 +#define TAG_GET_FB_DEPTH 0x00040005 +#define TAG_TEST_FB_DEPTH 0x00044005 +#define TAG_SET_FB_DEPTH 0x00048005 +#define TAG_GET_PIXEL_ORDER 0x00040006 +#define TAG_TEST_PIXEL_ORDER 0x00044006 +#define TAG_SET_PIXEL_ORDER 0x00048006 +#define TAG_GET_FB_ALPHA_MODE 0x00040007 +#define TAG_TEST_FB_ALPHA_MODE 0x00044007 +#define TAG_SET_FB_ALPHA_MODE 0x00048007 +#define TAG_GET_PITCH 0x00040008 +#define TAG_SET_PITCH 0x00048008 +#define TAG_GET_VIRTUAL_OFFSET 0x00040009 +#define TAG_TEST_VIRTUAL_OFFSET 0x00044009 +#define TAG_SET_VIRTUAL_OFFSET 0x00048009 +#define TAG_GET_OVERSCAN 0x0004000a +#define TAG_TEST_OVERSCAN 0x0004400a +#define TAG_SET_OVERSCAN 0x0004800a +#define TAG_SET_PALETTE 0x0004800b +#define TAG_GET_COMMANDLINE 0x00050001 +#define TAG_GET_DMA_CHANNELS 0x00060001 +#define TAG_GET_THROTTLED 0x00030046 +#define TAG_GET_NUM_DISPLAYS 0x00040013 +#define TAG_GET_DISPLAY_SETTINGS 0x00040014 +#define TAG_GET_GPIO_CONFIG 0x00030043 +#define TAG_SET_GPIO_CONFIG 0x00038043 +#define TAG_GET_GPIO_STATE 0x00030041 +#define TAG_SET_GPIO_STATE 0x00038041 +#define TAG_INITIALIZE_VCHIQ 0x00048010 + +#define BOARD_REVISION 11546898 +#define FIRMWARE_REVISION 346337 +#define FIRMWARE_VARIANT 0x77777777 /* TODO: Find the real value */ + +#define ARM_MEMORY_BASE 0x00000000 +#define ARM_MEMORY_SIZE 0x3c000000 +#define VC_MEMORY_BASE 0x3c000000 +#define VC_MEMORY_SIZE 0x04000000 +#define VC_FB_BASE 0x3c100000 +#define VC_FB_SIZE 0x00096000 + +#define CLOCK_ID_ROOT 0x00000000 +#define CLOCK_ID_EMMC 0x00000001 +#define CLOCK_ID_UART 0x00000002 +#define CLOCK_ID_ARM 0x00000003 +#define CLOCK_ID_CORE 0x00000004 +#define CLOCK_ID_UNDEFINED 0x12345678 + +#define CLOCK_RATE_EMMC 50000000 +#define CLOCK_RATE_UART 3000000 +#define CLOCK_RATE_CORE 350000000 +#define CLOCK_RATE_ANY 700000000 + +#define DEVICE_ID_SD_CARD 0x00000000 +#define DEVICE_ID_UART0 0x00000001 +#define DEVICE_ID_UART1 0x00000002 +#define DEVICE_ID_USB HCD 0x00000003 +#define DEVICE_ID_I2C0 0x00000004 +#define DEVICE_ID_I2C1 0x00000005 +#define DEVICE_ID_I2C2 0x00000006 +#define DEVICE_ID_SPI 0x00000007 +#define DEVICE_ID_CCP2TX 0x00000008 +#define DEVICE_ID_UNKNOWN_0 0x00000009 +#define DEVICE_ID_UNKNOWN_1 0x0000000a + +#define TEMPERATURE_ID_SOC 0x00000000 + +#define TEMPERATURE_SOC 25000 +#define TEMPERATURE_SOC_MAX 99000 + +#define ALIGN_4K 4096 + +#define PIXEL_ORDER_BGR 0 +#define PIXEL_ORDER_RGB 1 + +#define ALPHA_MODE_ENABLED 0 +#define ALPHA_MODE_REVERSED 1 +#define ALPHA_MODE_IGNORED 2 + +#define GPIO_MASK 0x003c + +#define GPIO_0 0x00000080 + +#define GPIO_DIRECTION_IN 0 +#define GPIO_DIRECTION_OUT 1 + +#define GPIO_TERMINATION_DISABLED 0 +#define GPIO_TERMINATION_ENABLED 1 + +#define GPIO_TERMINATION_PULLUP_DISABLED 0 +#define GPIO_TERMINATION_PULLUP_ENABLED 1 + +#define GPIO_POLARITY_LOW 0 +#define GPIO_POLARITY_HIGH 1 + +#define GPIO_STATE_DOWN 0 + +/* Used to test stubs that don't perform actual work */ +#define DUMMY_VALUE 0x12345678 REG32(MBOX_WRITE_REG, 0) FIELD(MBOX_WRITE_REG, CHANNEL, 0, 4) From patchwork Sun Dec 3 21:28:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QgDPIid/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0X65wYBz23n4 for ; Mon, 4 Dec 2023 08:37:58 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2g-0002iq-4z; Sun, 03 Dec 2023 16:30:22 -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 1r9u2A-0001gb-VB; Sun, 03 Dec 2023 16:29:50 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u29-0005Xp-8G; Sun, 03 Dec 2023 16:29:50 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-daf7ed42ea6so2000198276.0; Sun, 03 Dec 2023 13:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638987; x=1702243787; 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=y/krSYU1BfE52MIIAgN9xYHAgzoYPsQ2UC+lvFrcJE0=; b=QgDPIid/lDeYY31sxAj7V/uWr6WIO6NqX7gH8JH+AiG8cmHZ7LK87eIu7796523nJd j6ADKHOfuC776+OPJZx0kJlAvCpiQXXMeEBihVZAsFm0hOC4eKaM7ULXN+P/fPRDxIrQ 0TsCUfMxC21vClqcVdcsB3kbTDI+oooLdyZEbl3iA2EbXAy9FFL7pEHhNimF/J4ssmMK Nt7iugrH+QdNvnqoq7HOwokcMY+/VbxyQAVpbcjBolyeHX1zISO/In3Ri1YsrO48SLOQ 5dOE6grP2z9R2kwm5ogAsxodknlnRJhLlrSOJIFLEpBJF4n/O9eIX2Bc0SFfqUPz/0To zMCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638987; x=1702243787; 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=y/krSYU1BfE52MIIAgN9xYHAgzoYPsQ2UC+lvFrcJE0=; b=lwqKzp4Pmyw45kLaUtDetRnwF3/W0YpWVuo95+1+qKX+h9BYzoi67i7v2hw8mmLmUO JDhHt6NtBb6HGiAdf6D9c1wbDHlJa3GUDqnUpfulTm/VHNBbNuFoRV8xfVKHRjBznO46 g4zep2ktLHlyJU3pdW7pEnrpQ/MonVlMuBV4giJnL0QZCF1dkC/6lInhUwaCnHCxcS6g j844opdnaLSJKWJe9+mx8hGtRiQ9ehmlOdsUEFJYmz16muqZnaXYDmWEtyf/vNCh6YlG rLDplZhpo9oEzLrQw/3HyTm6LVbLvnR8MuxV76u7cDUeUGcdnkhU0z/hnwaOkIoDRUfW 4Hyw== X-Gm-Message-State: AOJu0YxvOUS7pJrfLua+K9g7pqEyvaRD7KlU5HNAVpsUH6KiBEmNbGmZ QsF1i4jp3OD+/mp0zpChuANnd8PTA5iOBw== X-Google-Smtp-Source: AGHT+IHpp52gcqI20QDrJdCyI4hZhgntTcNpx0CrpC1Lad/TPGJa2xeN6qnGO6JyBnkSFoTF51B8cA== X-Received: by 2002:a25:ca03:0:b0:db7:dacf:61f6 with SMTP id a3-20020a25ca03000000b00db7dacf61f6mr1998546ybg.72.1701638987166; Sun, 03 Dec 2023 13:29:47 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:46 -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 37/45] Add mailbox tests tags. Part 1 Date: Sun, 3 Dec 2023 15:28:57 -0600 Message-Id: <20231203212905.1364036-38-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-37-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mailbox.h | 195 +++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 5 deletions(-) diff --git a/tests/qtest/bcm2838-mailbox.h b/tests/qtest/bcm2838-mailbox.h index 8acc4bd2ff..04472fe23d 100644 --- a/tests/qtest/bcm2838-mailbox.h +++ b/tests/qtest/bcm2838-mailbox.h @@ -147,13 +147,21 @@ /* Used to test stubs that don't perform actual work */ #define DUMMY_VALUE 0x12345678 -REG32(MBOX_WRITE_REG, 0) +REG32(MBOX_WRITE_REG, 0) FIELD(MBOX_WRITE_REG, CHANNEL, 0, 4) -FIELD(MBOX_WRITE_REG, DATA, 4, 28) +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) +REG32(MBOX_SIZE_STAT, 0) +FIELD(MBOX_SIZE_STAT, SIZE, 0, 30) +FIELD(MBOX_SIZE_STAT, SUCCESS, 30, 1) + +REG32(SET_DEVICE_POWER_STATE_CMD, 0) +FIELD(SET_DEVICE_POWER_STATE_CMD, EN, 0, 1) +FIELD(SET_DEVICE_POWER_STATE_CMD, WAIT, 1, 1) + +REG32(GET_CLOCK_STATE_CMD, 0) +FIELD(GET_CLOCK_STATE_CMD, EN, 0, 1) +FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1) typedef struct { uint32_t size; @@ -176,6 +184,183 @@ typedef struct { \ }; \ } TypeName +DECLARE_TAG_TYPE(TAG_GET_FIRMWARE_REVISION_t, + struct {}, + struct { + uint32_t revision; + }); + +DECLARE_TAG_TYPE(TAG_GET_FIRMWARE_VARIANT_t, + struct {}, + struct { + uint32_t variant; + }); + +DECLARE_TAG_TYPE(TAG_GET_BOARD_REVISION_t, + struct {}, + struct { + uint32_t revision; + }); + +DECLARE_TAG_TYPE(TAG_GET_ARM_MEMORY_t, + struct {}, + struct { + uint32_t base; + uint32_t size; + }); + +DECLARE_TAG_TYPE(TAG_GET_VC_MEMORY_t, + struct {}, + struct { + uint32_t base; + uint32_t size; + }); + +DECLARE_TAG_TYPE(TAG_SET_DEVICE_POWER_STATE_t, + struct { + uint32_t device_id; + uint32_t cmd; + }, + struct { + uint32_t device_id; + uint32_t cmd; + }); + +DECLARE_TAG_TYPE(TAG_GET_CLOCK_STATE_t, + struct { + uint32_t clock_id; + }, + struct { + uint32_t clock_id; + uint32_t cmd; + }); + +DECLARE_TAG_TYPE(TAG_GET_CLOCK_RATE_t, + struct { + uint32_t clock_id; + }, + struct { + uint32_t clock_id; + uint32_t rate; + }); + +DECLARE_TAG_TYPE(TAG_GET_MAX_CLOCK_RATE_t, + struct { + uint32_t clock_id; + }, + struct { + uint32_t clock_id; + uint32_t rate; + }); + +DECLARE_TAG_TYPE(TAG_GET_MIN_CLOCK_RATE_t, + struct { + uint32_t clock_id; + }, + struct { + uint32_t clock_id; + uint32_t rate; + }); + +DECLARE_TAG_TYPE(TAG_GET_CLOCKS_t, + struct {}, + struct { + uint32_t root_clock; + uint32_t arm_clock; + }); + +DECLARE_TAG_TYPE(TAG_GET_TEMPERATURE_t, + struct { + uint32_t temperature_id; + }, + struct { + uint32_t temperature_id; + uint32_t temperature; + }); + +DECLARE_TAG_TYPE(TAG_GET_MAX_TEMPERATURE_t, + struct { + uint32_t temperature_id; + }, + struct { + uint32_t temperature_id; + uint32_t temperature; + }); + +DECLARE_TAG_TYPE(TAG_ALLOCATE_BUFFER_t, + struct { + uint32_t alignment; + }, + struct { + uint32_t base; + uint32_t size; + }); + +DECLARE_TAG_TYPE(TAG_RELEASE_FRAMEBUFFER_t, + struct {}, + struct {}); + +DECLARE_TAG_TYPE(TAG_BLANK_FRAMEBUFFER_t, + struct { + uint32_t on; + }, + struct { + uint32_t on; + }); + +DECLARE_TAG_TYPE(TAG_GET_FB_PHYS_WIDTH_t, + struct {}, + struct { + uint32_t width; + uint32_t height; + }); + +DECLARE_TAG_TYPE(TAG_TEST_FB_PHYS_WIDTH_t, + struct { + uint32_t width; + uint32_t height; + }, + struct { + uint32_t width; + uint32_t height; + }); + +DECLARE_TAG_TYPE(TAG_SET_FB_PHYS_WIDTH_t, + struct { + uint32_t width; + uint32_t height; + }, + struct { + uint32_t width; + uint32_t height; + }); + +DECLARE_TAG_TYPE(TAG_GET_FB_VIRT_WIDTH_t, + struct {}, + struct { + uint32_t width; + uint32_t height; + }); + +DECLARE_TAG_TYPE(TAG_TEST_FB_VIRT_WIDTH_t, + struct { + uint32_t width; + uint32_t height; + }, + struct { + uint32_t width; + uint32_t height; + }); + +DECLARE_TAG_TYPE(TAG_SET_FB_VIRT_WIDTH_t, + struct { + uint32_t width; + uint32_t height; + }, + struct { + uint32_t width; + uint32_t height; + }); int mbox0_has_data(void); void mbox0_read_message(uint8_t channel, void *msgbuf, size_t msgbuf_size); From patchwork Sun Dec 3 21:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FwB3UOKR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0SZ3C5Cz23nJ for ; Mon, 4 Dec 2023 08:34:54 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2P-0002St-Ru; Sun, 03 Dec 2023 16:30:05 -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 1r9u2C-0001oG-4i; Sun, 03 Dec 2023 16:29:52 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u29-0005Xw-IZ; Sun, 03 Dec 2023 16:29:51 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-daf4f0e3a0fso1989504276.1; Sun, 03 Dec 2023 13:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638988; x=1702243788; 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=laWmoNjX7Q2VjrFH6E3XuRIGiJEarrDw3NKpsYtiHac=; b=FwB3UOKREYjnz8BW61DvSL9xs98W2OjJ771DvFpG0msLbsj7krU1k1RedQvZ/6Uz+d 8VISb8ihilVS+ZMc9JU/U7VWHEdG9E/SvLNqZByBMQPADTRO4LR1+vBfWQ0GNHX0wvM8 yUtarkxXVaJ1fbbAGamTkoamKXxN4cnLC3wvJeHBEsTWxY/2hC1CSPSknE5gSXAAqmqO XpOkfYENNsAQ3wMlisDkMOvNS8ZLY7OjMavFnwcyNp6QCrBSGV3MHd17H0lnmbT6hV0A ntvi7gsF0UYmJ1GR3pNZOjvQ1ZquOYTjJOUT5GCC9TlWrWnRI8m6qWk9tktW02c/3lnE Cc3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638988; x=1702243788; 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=laWmoNjX7Q2VjrFH6E3XuRIGiJEarrDw3NKpsYtiHac=; b=cDu0cGR1r6+Et7BqIkXQydoG1IrT14P/XozY8mT4VoHi1i3x5j89twsp/33rKA9awp Er+rNgxnUm+5to4t2BENx2gou3KGh2n4S37hnsHEYEbPfiiGlgpNVXmfuYe9wjyPfExU ZuLGwrd3k1Hk2sEbLgQjxgFH/V9kGLKtYwcyXgLhblcYUPZ7dcAkST/sA4m1dDMyOI2J A5003bNM+5tbZJ6+RpQEtE/dl6fqx0ZewKFxaOxV3tq5/jZMeDQFMoo69QIuZiNqCVwP cOfQbItqyLg9qBrNmbAdnfA2DIwQiRXcKI71ebQ1Z5RAlVIVO95gmu86eGdMFMEALA9Z aNqA== X-Gm-Message-State: AOJu0YzoZvhNDw86lPQAgjMg8RB9Us0noezJbkThJ2YSUDh6K6n1Y3ny 08Udf9ZA95Ro9SskRdZmWBnUWl15PH3OaA== X-Google-Smtp-Source: AGHT+IHWO77GjJEdVB2CKBM1BR5kafugmcxstS18KcujjIv1cxFDlhQFh6JgdvBnQQd1TcOUZffd5g== X-Received: by 2002:a25:bb05:0:b0:db5:479f:93a2 with SMTP id z5-20020a25bb05000000b00db5479f93a2mr1883844ybg.34.1701638988118; Sun, 03 Dec 2023 13:29:48 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:47 -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 38/45] Add mailbox tests tags. Part 2 Date: Sun, 3 Dec 2023 15:28:58 -0600 Message-Id: <20231203212905.1364036-39-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-38-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mailbox.h | 152 ++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/tests/qtest/bcm2838-mailbox.h b/tests/qtest/bcm2838-mailbox.h index 04472fe23d..49668668da 100644 --- a/tests/qtest/bcm2838-mailbox.h +++ b/tests/qtest/bcm2838-mailbox.h @@ -362,6 +362,158 @@ DECLARE_TAG_TYPE(TAG_SET_FB_VIRT_WIDTH_t, uint32_t height; }); +DECLARE_TAG_TYPE(TAG_GET_FB_DEPTH_t, + struct {}, + struct { + uint32_t bpp; + }); + +DECLARE_TAG_TYPE(TAG_TEST_FB_DEPTH_t, + struct { + uint32_t bpp; + }, + struct { + uint32_t bpp; + }); + +DECLARE_TAG_TYPE(TAG_SET_FB_DEPTH_t, + struct { + uint32_t bpp; + }, + struct { + uint32_t bpp; + }); + +DECLARE_TAG_TYPE(TAG_GET_PIXEL_ORDER_t, + struct {}, + struct { + uint32_t pixel_order; + }); + +DECLARE_TAG_TYPE(TAG_TEST_PIXEL_ORDER_t, + struct { + uint32_t pixel_order; + }, + struct { + uint32_t pixel_order; + }); + +DECLARE_TAG_TYPE(TAG_SET_PIXEL_ORDER_t, + struct { + uint32_t pixel_order; + }, + struct { + uint32_t pixel_order; + }); + +DECLARE_TAG_TYPE(TAG_GET_FB_ALPHA_MODE_t, + struct {}, + struct { + uint32_t alpha_mode; + }); + +DECLARE_TAG_TYPE(TAG_TEST_FB_ALPHA_MODE_t, + struct { + uint32_t alpha_mode; + }, + struct { + uint32_t alpha_mode; + }); + +DECLARE_TAG_TYPE(TAG_SET_FB_ALPHA_MODE_t, + struct { + uint32_t alpha_mode; + }, + struct { + uint32_t alpha_mode; + }); + +DECLARE_TAG_TYPE(TAG_GET_PITCH_t, + struct {}, + struct { + uint32_t pitch; + }); + +DECLARE_TAG_TYPE(TAG_SET_PITCH_t, + struct { + uint32_t pitch; + }, + struct {}); + +DECLARE_TAG_TYPE(TAG_GET_VIRTUAL_OFFSET_t, + struct {}, + struct { + uint32_t x; + uint32_t y; + }); + +DECLARE_TAG_TYPE(TAG_TEST_VIRTUAL_OFFSET_t, + struct { + uint32_t x; + uint32_t y; + }, + struct { + uint32_t x; + uint32_t y; + }); + +DECLARE_TAG_TYPE(TAG_SET_VIRTUAL_OFFSET_t, + struct { + uint32_t x; + uint32_t y; + }, + struct { + uint32_t x; + uint32_t y; + }); + +DECLARE_TAG_TYPE(TAG_GET_OVERSCAN_t, + struct {}, + struct { + uint32_t top; + uint32_t bottom; + uint32_t left; + uint32_t right; + }); + +DECLARE_TAG_TYPE(TAG_TEST_OVERSCAN_t, + struct { + uint32_t top; + uint32_t bottom; + uint32_t left; + uint32_t right; + }, + struct { + uint32_t top; + uint32_t bottom; + uint32_t left; + uint32_t right; + }); + +DECLARE_TAG_TYPE(TAG_SET_OVERSCAN_t, + struct { + uint32_t top; + uint32_t bottom; + uint32_t left; + uint32_t right; + }, + struct { + uint32_t top; + uint32_t bottom; + uint32_t left; + uint32_t right; + }); + +DECLARE_TAG_TYPE(TAG_GET_COMMANDLINE_t, + struct {}, + struct {}); + +DECLARE_TAG_TYPE(TAG_GET_DMA_CHANNELS_t, + struct {}, + struct { + uint32_t mask; + }); + 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); From patchwork Sun Dec 3 21:28:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VchIxTaH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0MX5Z96z23nJ for ; Mon, 4 Dec 2023 08:30:32 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2M-0002JT-5e; Sun, 03 Dec 2023 16:30:02 -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 1r9u2D-0001vx-Jg; Sun, 03 Dec 2023 16:29:53 -0500 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2B-0005YP-S0; Sun, 03 Dec 2023 16:29:53 -0500 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-db539ab8e02so2184993276.0; Sun, 03 Dec 2023 13:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638989; x=1702243789; 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=gY8sUeibQtSIKqZZj4hPgQKFQsYZHNo91+gsd8Kiers=; b=VchIxTaHzE/Q26lfnVbzLHh6MiSP8MUiuEvF/zZfAVBaHJC8+8ykYZTAQNa6Eh+Ahj CWvHogQzAuLQ5jQEUmzj/WZW9eC2ZvfBjMOV6GXcwbeWu1Fy8vUaOli2l6nXJNj8rGAL i+ykCDk46q6d19eOeeVgpE8oIN2AguQotijFcxYT1SpBourAKQtP3tA3PGo+YAwFN9Tv v1oKItMAgRhEpuMSENnuEOE4YVWBYtgFCsABnarMvK/7QU138AGCx1+TY5pUtzdyuOvi em9SROQvVoS6rjDOiXMPcSGbuz4Q2np9X8OkiOOXalxrl9mQSnyTKUvfshqUyK1B+3PC FLLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638989; x=1702243789; 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=gY8sUeibQtSIKqZZj4hPgQKFQsYZHNo91+gsd8Kiers=; b=rUfQCZX7MsJh6IT1krASNxlDo1SL9M58KG1ApuKbIS9mbPv4reaXocru9uvSqx9FgY X3yBJYCoYckEqAj9sscx28DswWh4ns8yasTW5cHWhnStoJiGAcB0Au3obeln1dt2/pIA LCbiou2RGGHSz5vtXmvUacJWvlmZ+yMJOrsJWUHcern8+rlIt/O9XFEk4RYMj//Zt2jV EG96YqFWQ4Ox+w50tioWQYnCB984SLh+yIql19Nl8P9LfnlsahTfgDHIReSmvv+umtqK gjpYaALTRg56PKfmSWBd0O2W2RfINcK2KqzjJoD/n+D9rXawS2kR5ZHsJbrs6ez4Vhw9 tC4g== X-Gm-Message-State: AOJu0YzaYlnlpamDV8k+H1BLbBDybtkVGDpTNwzO4ZQj9nbblqOqeL1K TEsHOEppd+O1umEeXVXabhf4eRXy0swsVA== X-Google-Smtp-Source: AGHT+IEOLEflvl8zdkitssxI5ZdSx8ZtvgBOrzHzim2vYuNLk2ZEr33bBgL+OMVe0FllMVdLpNz8SA== X-Received: by 2002:a5b:41:0:b0:db7:dacf:ed85 with SMTP id e1-20020a5b0041000000b00db7dacfed85mr1908746ybp.102.1701638989290; Sun, 03 Dec 2023 13:29:49 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:49 -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 39/45] Add mailbox tests tags. Part 3 Date: Sun, 3 Dec 2023 15:28:59 -0600 Message-Id: <20231203212905.1364036-40-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-39-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2f; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mailbox.h | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/qtest/bcm2838-mailbox.h b/tests/qtest/bcm2838-mailbox.h index 49668668da..2b140a5d32 100644 --- a/tests/qtest/bcm2838-mailbox.h +++ b/tests/qtest/bcm2838-mailbox.h @@ -514,6 +514,84 @@ DECLARE_TAG_TYPE(TAG_GET_DMA_CHANNELS_t, uint32_t mask; }); +DECLARE_TAG_TYPE(TAG_GET_THROTTLED_t, + struct {}, + struct { + uint32_t throttled; + }); + +DECLARE_TAG_TYPE(TAG_GET_NUM_DISPLAYS_t, + struct {}, + struct { + uint32_t num_displays; + }); + +DECLARE_TAG_TYPE(TAG_GET_DISPLAY_SETTINGS_t, + struct {}, + struct { + uint32_t display_num; + uint32_t phys_width; + uint32_t phys_height; + uint32_t bpp; + uint16_t pitch; + uint32_t virt_width; + uint32_t virt_height; + uint16_t virt_width_offset; + uint32_t virt_height_offset; + uint32_t fb_bus_address_lo; + uint32_t fb_bus_address_hi; + }); + +DECLARE_TAG_TYPE(TAG_GET_GPIO_CONFIG_t, + struct { + uint32_t gpio_num; + }, + struct { + uint32_t zero; + uint32_t direction; + uint32_t polarity; + uint32_t term_en; + uint32_t term_pull_up; + }); + + +DECLARE_TAG_TYPE(TAG_SET_GPIO_CONFIG_t, + struct { + uint32_t gpio_num; + uint32_t direction; + uint32_t polarity; + uint32_t term_en; + uint32_t term_pull_up; + uint32_t state; + }, + struct { + uint32_t zero; + }); + +DECLARE_TAG_TYPE(TAG_GET_GPIO_STATE_t, + struct { + uint32_t gpio_num; + }, + struct { + uint32_t zero; + uint32_t state; + }); + +DECLARE_TAG_TYPE(TAG_SET_GPIO_STATE_t, + struct { + uint32_t gpio_num; + uint32_t state; + }, + struct { + uint32_t zero; + }); + +DECLARE_TAG_TYPE(TAG_INITIALIZE_VCHIQ_t, + struct {}, + struct { + uint32_t zero; + }); + 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); From patchwork Sun Dec 3 21:29:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mtIgLBKR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0VZ5v3bz23mf for ; Mon, 4 Dec 2023 08:36:38 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2S-0002Vd-21; Sun, 03 Dec 2023 16:30:08 -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 1r9u2D-0001xV-Tv; Sun, 03 Dec 2023 16:29:53 -0500 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2B-0005Yi-MG; Sun, 03 Dec 2023 16:29:53 -0500 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-dae7cc31151so2204874276.3; Sun, 03 Dec 2023 13:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638990; x=1702243790; 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=KEcoat7SC4jN+C9La2rhXqQ9NFVHbLoJsMPiUtjdyFI=; b=mtIgLBKRkMoepJtX/pKIYMXR/SohkiSNkv+1hekWMadKsT/WoiX6bLGpkrXCI/2JKu yKMtIyy8luNcpK+h8DjE+bmRaZ7ET/AuyrUcd16gtCM0MVlZoRdepIwzXCCiLAC0kkt0 pazD0gfe9UiAhLRcDIMsV9sWY2O7ZXjPDmIs44xdRO4gKB5Mf/02RIFG95HSRYCaf9Du BchUzSwlD728rHEcvrT3d68EZSX5KMchSFLUNWT/WbpvVZurnkk5FYUJFs3D+SOcuSI6 MsUJLuk8jShcRzGQxbf2sIRAwmBvul0cHWMRLUIHXjQqbxdKskulg/c+vemmh9C9uk8t 4rpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638990; x=1702243790; 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=KEcoat7SC4jN+C9La2rhXqQ9NFVHbLoJsMPiUtjdyFI=; b=ThDB6fBZAfn4iRaWeKm/1Xq+UU0Ub5Sc1I6Ub8UKeOqVvi6SVA0VbQOF6YJprOakR/ 2aCXrQ8GtM8v6OoqR6M5l1ufB/gW986DEe50EX4d4SWu8w06rqogSYQ18Ev6KPU05+yb cdhR0UTusLtfcVFaXsCwaY51Bj4oKYpnPv/WOg1JsTcMp8oeSTe3L5wqLMvyM5hDVNKq BGvNM8z8qpYUmGBQaea/nEyakmY11Mv/He2s1yFQD4rucsaQef6ktVpTlbOWmZLrrOYm gq2bAAZvTNFcsG1tirIGDQb+tb8DrkLtme68jZarwJvMVjIY4u6VoGyUa2gloIyNE3su 5kZA== X-Gm-Message-State: AOJu0Yx8PEohBmWRJWODyuN+JH3MUWgevi5aov51vonhAdJw2ccDGy3L G3LNCG6jwV+UkVXZn00wOQP1UQVHrxs0vA== X-Google-Smtp-Source: AGHT+IF7UP57FwBKzimMJQKlh+Ye3k6uI62g8iYHBZi6at+QefpgJQU0kgSMnNnJ5dK9YmR1Iw5Keg== X-Received: by 2002:a25:cf0d:0:b0:db5:4d24:3ca3 with SMTP id f13-20020a25cf0d000000b00db54d243ca3mr2676782ybg.43.1701638990255; Sun, 03 Dec 2023 13:29:50 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:50 -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 40/45] Add mailbox property tests. Part 1 Date: Sun, 3 Dec 2023 15:29:00 -0600 Message-Id: <20231203212905.1364036-41-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-40-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> <20231203212905.1364036-40-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2a; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mailbox.c | 34 ++-- tests/qtest/bcm2838-mailbox.h | 18 +- tests/qtest/bcm2838-mbox-property-test.c | 206 +++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 4 files changed, 220 insertions(+), 40 deletions(-) create mode 100644 tests/qtest/bcm2838-mbox-property-test.c diff --git a/tests/qtest/bcm2838-mailbox.c b/tests/qtest/bcm2838-mailbox.c index 2edc24e15e..4b160cd56c 100644 --- a/tests/qtest/bcm2838-mailbox.c +++ b/tests/qtest/bcm2838-mailbox.c @@ -12,6 +12,10 @@ #include "libqtest-single.h" #include "bcm2838-mailbox.h" +REG32(MBOX_EXCHNG_REG, 0) +FIELD(MBOX_EXCHNG_REG, CHANNEL, 0, 4) +FIELD(MBOX_EXCHNG_REG, DATA, 4, 28) + static uint32_t qtest_mbox0_read_reg32(QTestState *s, uint32_t offset) { @@ -25,47 +29,33 @@ static void qtest_mbox1_write_reg32(QTestState *s, uint32_t offset, uint32_t val static void qtest_mbox1_write(QTestState *s, uint8_t channel, uint32_t data) { - uint32_t reg; + uint32_t mbox_reg = 0; - reg = FIELD_DP32(reg, MBOX_WRITE_REG, CHANNEL, channel); - reg = FIELD_DP32(reg, MBOX_WRITE_REG, DATA, data); - qtest_mbox1_write_reg32(s, MBOX_REG_WRITE, reg); + mbox_reg = FIELD_DP32(mbox_reg, MBOX_EXCHNG_REG, CHANNEL, channel); + mbox_reg = FIELD_DP32(mbox_reg, MBOX_EXCHNG_REG, DATA, data); + qtest_mbox1_write_reg32(s, MBOX_REG_WRITE, mbox_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 mbox_reg; uint32_t msgaddr; g_assert(qtest_mbox0_has_data(s)); - reg = qtest_mbox0_read_reg32(s, MBOX_REG_READ); - g_assert_cmphex(FIELD_EX32(reg, MBOX_WRITE_REG, CHANNEL), ==, channel); - msgaddr = FIELD_EX32(reg, MBOX_WRITE_REG, DATA) << 4; + mbox_reg = qtest_mbox0_read_reg32(s, MBOX_REG_READ); + g_assert_cmphex(FIELD_EX32(mbox_reg, MBOX_EXCHNG_REG, CHANNEL), ==, channel); + msgaddr = FIELD_EX32(mbox_reg, MBOX_EXCHNG_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 msg_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 index 2b140a5d32..7e660e65a7 100644 --- a/tests/qtest/bcm2838-mailbox.h +++ b/tests/qtest/bcm2838-mailbox.h @@ -77,7 +77,7 @@ #define TAG_SET_GPIO_STATE 0x00038041 #define TAG_INITIALIZE_VCHIQ 0x00048010 -#define BOARD_REVISION 11546898 +#define BOARD_REVISION 0xB03115 #define FIRMWARE_REVISION 346337 #define FIRMWARE_VARIANT 0x77777777 /* TODO: Find the real value */ @@ -147,22 +147,6 @@ /* Used to test stubs that don't perform actual work */ #define DUMMY_VALUE 0x12345678 -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_SIZE_STAT, SIZE, 0, 30) -FIELD(MBOX_SIZE_STAT, SUCCESS, 30, 1) - -REG32(SET_DEVICE_POWER_STATE_CMD, 0) -FIELD(SET_DEVICE_POWER_STATE_CMD, EN, 0, 1) -FIELD(SET_DEVICE_POWER_STATE_CMD, WAIT, 1, 1) - -REG32(GET_CLOCK_STATE_CMD, 0) -FIELD(GET_CLOCK_STATE_CMD, EN, 0, 1) -FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1) - typedef struct { uint32_t size; uint32_t req_resp_code; diff --git a/tests/qtest/bcm2838-mbox-property-test.c b/tests/qtest/bcm2838-mbox-property-test.c new file mode 100644 index 0000000000..80746dbb95 --- /dev/null +++ b/tests/qtest/bcm2838-mbox-property-test.c @@ -0,0 +1,206 @@ +/* + * Tests set for BCM2838 mailbox property interface. + * + * Copyright (c) 2022 Auriga + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * 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" + +REG32(MBOX_SIZE_STAT, 0) +FIELD(MBOX_SIZE_STAT, SIZE, 0, 31) +FIELD(MBOX_SIZE_STAT, SUCCESS, 31, 1) + +REG32(SET_DEVICE_POWER_STATE_CMD, 0) +FIELD(SET_DEVICE_POWER_STATE_CMD, EN, 0, 1) +FIELD(SET_DEVICE_POWER_STATE_CMD, WAIT, 1, 1) + +REG32(GET_CLOCK_STATE_CMD, 0) +FIELD(GET_CLOCK_STATE_CMD, EN, 0, 1) +FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1) + +#define MBOX_TEST_MESSAGE_ADDRESS 0x10000000 + +#define TEST_TAG(x) TAG_ ## x +#define TEST_TAG_TYPE(x) TAG_##x##_t + +#define TEST_FN_NAME(test, subtest) \ + test ## _ ## subtest ## _test + +#define SETUP_FN_NAME(test, subtest) \ + test ## _ ## subtest ## _setup + +#define CHECK_FN_NAME(test, subtest) \ + test ## _ ## subtest ## _spec_check + +#define DECLARE_TEST_CASE_SETUP(testname, ...) \ + void SETUP_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) * tag) + +/*----------------------------------------------------------------------------*/ +#define DECLARE_TEST_CASE(testname, ...) \ + __attribute__((weak)) \ + void SETUP_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) * tag); \ + static void CHECK_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) *tag); \ + static void TEST_FN_NAME(testname, __VA_ARGS__)(void) { \ + struct { \ + MboxBufHeader header; \ + TEST_TAG_TYPE(testname) tag; \ + uint32_t end_tag; \ + } mailbox_buffer = { 0 }; \ + \ + QTestState *qts = qtest_init("-machine raspi4b-2g"); \ + \ + mailbox_buffer.header.size = sizeof(mailbox_buffer); \ + mailbox_buffer.header.req_resp_code = MBOX_PROCESS_REQUEST; \ + \ + mailbox_buffer.tag.id = TEST_TAG(testname); \ + mailbox_buffer.tag.value_buffer_size = MAX( \ + sizeof(mailbox_buffer.tag.request.value), \ + sizeof(mailbox_buffer.tag.response.value)); \ + mailbox_buffer.tag.request.zero = 0; \ + \ + mailbox_buffer.end_tag = TAG_END; \ + \ + 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)); \ + qtest_mbox1_write_message(qts, MBOX_CHANNEL_ID_PROPERTY, \ + MBOX_TEST_MESSAGE_ADDRESS); \ + \ + qtest_mbox0_read_message(qts, MBOX_CHANNEL_ID_PROPERTY, \ + &mailbox_buffer, sizeof(mailbox_buffer)); \ + \ + g_assert_cmphex(mailbox_buffer.header.req_resp_code, ==, MBOX_SUCCESS);\ + \ + 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); \ + g_assert_cmpint(size, ==, sizeof(mailbox_buffer.tag.response.value)); \ + g_assert_cmpint(success, ==, 1); \ + \ + CHECK_FN_NAME(testname, __VA_ARGS__)(&mailbox_buffer.tag); \ + \ + qtest_quit(qts); \ + } \ + static void CHECK_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) * tag) + +/*----------------------------------------------------------------------------*/ + +#define QTEST_ADD_TEST_CASE(testname, ...) \ + qtest_add_func(stringify(/bcm2838/mbox/property/ \ + TEST_FN_NAME(testname, __VA_ARGS__)-test), \ + TEST_FN_NAME(testname, __VA_ARGS__)) + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_FIRMWARE_REVISION) { + g_assert_cmpint(tag->response.value.revision, ==, FIRMWARE_REVISION); +} + +// /*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_BOARD_REVISION) { + g_assert_cmpint(tag->response.value.revision, ==, BOARD_REVISION); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_ARM_MEMORY) { + g_assert_cmphex(tag->response.value.base, ==, ARM_MEMORY_BASE); + g_assert_cmphex(tag->response.value.size, ==, ARM_MEMORY_SIZE); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_VC_MEMORY) { + g_assert_cmphex(tag->response.value.base, ==, VC_MEMORY_BASE); + g_assert_cmphex(tag->response.value.size, ==, VC_MEMORY_SIZE); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_DEVICE_POWER_STATE) { + uint32_t enabled = + FIELD_EX32(tag->response.value.cmd, SET_DEVICE_POWER_STATE_CMD, EN); + uint32_t wait = + FIELD_EX32(tag->response.value.cmd, SET_DEVICE_POWER_STATE_CMD, WAIT); + g_assert_cmphex(tag->response.value.device_id, ==, DEVICE_ID_UART0); + g_assert_cmpint(enabled, ==, 1); + g_assert_cmpint(wait, ==, 0); +} +DECLARE_TEST_CASE_SETUP(SET_DEVICE_POWER_STATE) { + tag->request.value.device_id = DEVICE_ID_UART0; + tag->response.value.cmd = + FIELD_DP32(tag->response.value.cmd, SET_DEVICE_POWER_STATE_CMD, EN, 1); + tag->response.value.cmd = + FIELD_DP32(tag->response.value.cmd, SET_DEVICE_POWER_STATE_CMD, WAIT, 1); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_STATE) { + uint32_t enabled = + FIELD_EX32(tag->response.value.cmd, GET_CLOCK_STATE_CMD, EN); + uint32_t not_present = + FIELD_EX32(tag->response.value.cmd, GET_CLOCK_STATE_CMD, NPRES); + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_CORE); + g_assert_cmphex(enabled, ==, 1); + g_assert_cmphex(not_present, ==, 0); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_STATE) { + tag->request.value.clock_id = CLOCK_ID_CORE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_RATE, EMMC) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_EMMC); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_EMMC); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_RATE, EMMC) { + tag->request.value.clock_id = CLOCK_ID_EMMC; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MAX_CLOCK_RATE, EMMC) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_EMMC); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_EMMC); +} +DECLARE_TEST_CASE_SETUP(GET_MAX_CLOCK_RATE, EMMC) { + tag->request.value.clock_id = CLOCK_ID_EMMC; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MIN_CLOCK_RATE, EMMC) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_EMMC); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_EMMC); +} +DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, EMMC) { + tag->request.value.clock_id = CLOCK_ID_EMMC; +} + +/*----------------------------------------------------------------------------*/ +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + QTEST_ADD_TEST_CASE(GET_FIRMWARE_REVISION); + QTEST_ADD_TEST_CASE(GET_BOARD_REVISION); + QTEST_ADD_TEST_CASE(GET_ARM_MEMORY); + QTEST_ADD_TEST_CASE(GET_VC_MEMORY); + QTEST_ADD_TEST_CASE(SET_DEVICE_POWER_STATE); + QTEST_ADD_TEST_CASE(GET_CLOCK_STATE); + QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, EMMC); + QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, EMMC); + QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, EMMC); + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 92eba5ac99..2351e99fd5 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -217,7 +217,7 @@ qtests_aarch64 = \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', 'xlnx-versal-trng-test'] : []) + \ - (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2838-mbox-property-test'] : []) + \ (config_all.has_key('CONFIG_TCG') and \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \ ['arm-cpu-features', From patchwork Sun Dec 3 21:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lYBEQqR3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Vk5ywKz23mf for ; Mon, 4 Dec 2023 08:36:46 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2Y-0002ZN-Fd; Sun, 03 Dec 2023 16:30:15 -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 1r9u2E-00022k-Nh; Sun, 03 Dec 2023 16:29:54 -0500 Received: from mail-yb1-xb36.google.com ([2607:f8b0:4864:20::b36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2C-0005Z8-NM; Sun, 03 Dec 2023 16:29:54 -0500 Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-da41acaea52so2056899276.3; Sun, 03 Dec 2023 13:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638991; x=1702243791; 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=VOsDq4GO7J9Ybd/9mWWm7M2ltcuRdDgkXqPddf6YrXg=; b=lYBEQqR3l4pjxsG2J64fjEopJAhTIPleFFskn6Mr/JySU7UhLI3hzMghc+CAvMqQ0r GVBCHMcAuKtCOmcT1qwoSYDUwEsj98e3zg3i+6OfBrQY0kLg4J/N1WdHqRsgE96UlzsV DI50hwLw48KFgA0Cv7Ocf4GFJiWIfOU+BtpFft7Eb34KTo6hdCS2Ez22/l9f0aVSxfX3 hVp01pISQ93wLmX/hnXjpOa9zb966LSs5In0Un7NZrBUJWgqIwUju6armn5KA7KiJVBq eI0lDeIKIyUONYou2Annt1oWwgGMKW/KxgAtziKHPBWCRNhAOJxBpILlF+z0oUrIFowq brCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638991; x=1702243791; 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=VOsDq4GO7J9Ybd/9mWWm7M2ltcuRdDgkXqPddf6YrXg=; b=p35yPrNvZU0za8uN0N5ZG5kLkony67D4R4x9YWRuHoG+u8EEZvGdOK1oSXl6ZhG156 acPyt3dg3eEsehPnPaa6hw4EKzjKZqLF3HuOKTHFGGBadgFuu5RO72fQDaJBXFKrND0l 0nIVf6O2LFAy2og2ijuCo5HQAbjax6AUqmqj6kL/xwGmnRKpfLfSfq04J+gF+XW+wulj FNM3BXYYRhRk+hjdo1JKn4/l6PEHkX3213VF4XhZLoRtrkT1RcFFyHpUsdovBS8snakF wCjpUzrLLGMrjgoF7GJn5aQ5Zn1DdwYrlRfsQFb9z+BH4mDB9K/diOXmfytqhdn/9wRm D9Gg== X-Gm-Message-State: AOJu0YzTplDYTU1xnAVngtB6c884ecetJGe/8g4Td5kU0lgJgUuVFXUQ jnRABquP3rUQSFwy2aTylBMUeCYO+VBnxg== X-Google-Smtp-Source: AGHT+IG7ccyxIKHqD1GjV6GC3WexbZjwydWQtlFDruc4WMBnSTV3yYj4wgYAWfSdqSi/7/eRmizo1A== X-Received: by 2002:a25:2f87:0:b0:db9:5b19:4852 with SMTP id v129-20020a252f87000000b00db95b194852mr799064ybv.50.1701638991232; Sun, 03 Dec 2023 13:29:51 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:51 -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 41/45] Add mailbox property tests. Part 2 Date: Sun, 3 Dec 2023 15:29:01 -0600 Message-Id: <20231203212905.1364036-42-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-41-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> <20231203212905.1364036-40-sergey.kambalin@auriga.com> <20231203212905.1364036-41-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b36; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb36.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, UPPERCASE_50_75=0.008 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mbox-property-test.c | 196 ++++++++++++++++++++++- 1 file changed, 195 insertions(+), 1 deletion(-) diff --git a/tests/qtest/bcm2838-mbox-property-test.c b/tests/qtest/bcm2838-mbox-property-test.c index 80746dbb95..5322c563a0 100644 --- a/tests/qtest/bcm2838-mbox-property-test.c +++ b/tests/qtest/bcm2838-mbox-property-test.c @@ -49,7 +49,8 @@ FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1) (TEST_TAG_TYPE(testname) * tag); \ static void CHECK_FN_NAME(testname, __VA_ARGS__) \ (TEST_TAG_TYPE(testname) *tag); \ - static void TEST_FN_NAME(testname, __VA_ARGS__)(void) { \ + static void TEST_FN_NAME(testname, __VA_ARGS__)(void) \ + { \ struct { \ MboxBufHeader header; \ TEST_TAG_TYPE(testname) tag; \ @@ -188,6 +189,179 @@ DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, EMMC) { } /*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_RATE, UART) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_UART); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_UART); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_RATE, UART) { + tag->request.value.clock_id = CLOCK_ID_UART; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MAX_CLOCK_RATE, UART) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_UART); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_UART); +} +DECLARE_TEST_CASE_SETUP(GET_MAX_CLOCK_RATE, UART) { + tag->request.value.clock_id = CLOCK_ID_UART; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MIN_CLOCK_RATE, UART) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_UART); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_UART); +} +DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, UART) { + tag->request.value.clock_id = CLOCK_ID_UART; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_RATE, CORE) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_CORE); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_CORE); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_RATE, CORE) { + tag->request.value.clock_id = CLOCK_ID_CORE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MAX_CLOCK_RATE, CORE) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_CORE); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_CORE); +} +DECLARE_TEST_CASE_SETUP(GET_MAX_CLOCK_RATE, CORE) { + tag->request.value.clock_id = CLOCK_ID_CORE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MIN_CLOCK_RATE, CORE) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_CORE); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_CORE); +} +DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, CORE) { + tag->request.value.clock_id = CLOCK_ID_CORE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_RATE, ANY) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_UNDEFINED); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_ANY); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_RATE, ANY) { + tag->request.value.clock_id = CLOCK_ID_UNDEFINED; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MAX_CLOCK_RATE, ANY) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_UNDEFINED); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_ANY); +} +DECLARE_TEST_CASE_SETUP(GET_MAX_CLOCK_RATE, ANY) { + tag->request.value.clock_id = CLOCK_ID_UNDEFINED; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MIN_CLOCK_RATE, ANY) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_UNDEFINED); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_ANY); +} +DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, ANY) { + tag->request.value.clock_id = CLOCK_ID_UNDEFINED; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_TEMPERATURE) { + g_assert_cmphex(tag->response.value.temperature_id, ==, TEMPERATURE_ID_SOC); + g_assert_cmpint(tag->response.value.temperature, ==, TEMPERATURE_SOC); +} +DECLARE_TEST_CASE_SETUP(GET_TEMPERATURE) { + tag->request.value.temperature_id = TEMPERATURE_ID_SOC; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MAX_TEMPERATURE) { + g_assert_cmphex(tag->response.value.temperature_id, ==, TEMPERATURE_ID_SOC); + g_assert_cmpint(tag->response.value.temperature, ==, TEMPERATURE_SOC_MAX); +} +DECLARE_TEST_CASE_SETUP(GET_MAX_TEMPERATURE) { + tag->request.value.temperature_id = TEMPERATURE_ID_SOC; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(ALLOCATE_BUFFER) { + g_assert_cmphex(tag->response.value.base, ==, VC_FB_BASE); + g_assert_cmphex(tag->response.value.size, ==, VC_FB_SIZE); +} +DECLARE_TEST_CASE_SETUP(ALLOCATE_BUFFER) { + tag->request.value.alignment = ALIGN_4K; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(RELEASE_FRAMEBUFFER) { + /* No special checks are needed for this test */ +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(BLANK_FRAMEBUFFER) { + g_assert_cmphex(tag->response.value.on, ==, 0); +} +DECLARE_TEST_CASE_SETUP(BLANK_FRAMEBUFFER) { + tag->request.value.on = 0; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_FB_PHYS_WIDTH) { + g_assert_cmpint(tag->response.value.width, ==, DUMMY_VALUE); + g_assert_cmpint(tag->response.value.height, ==, DUMMY_VALUE); +} +DECLARE_TEST_CASE_SETUP(TEST_FB_PHYS_WIDTH) { + tag->request.value.width = DUMMY_VALUE; + tag->request.value.height = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_FB_PHYS_WIDTH, INITIAL) { + g_assert_cmpint(tag->response.value.width, ==, 640); + g_assert_cmpint(tag->response.value.height, ==, 480); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_FB_PHYS_WIDTH) { + g_assert_cmpint(tag->response.value.width, ==, 800); + g_assert_cmpint(tag->response.value.height, ==, 600); +} +DECLARE_TEST_CASE_SETUP(SET_FB_PHYS_WIDTH) { + tag->request.value.width = 800; + tag->request.value.height = 600; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_FB_VIRT_WIDTH) { + g_assert_cmpint(tag->response.value.width, ==, DUMMY_VALUE); + g_assert_cmpint(tag->response.value.height, ==, DUMMY_VALUE); +} +DECLARE_TEST_CASE_SETUP(TEST_FB_VIRT_WIDTH) { + tag->request.value.width = DUMMY_VALUE; + tag->request.value.height = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_FB_VIRT_WIDTH, INITIAL) { + g_assert_cmpint(tag->response.value.width, ==, 640); + g_assert_cmpint(tag->response.value.height, ==, 480); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_FB_VIRT_WIDTH) { + g_assert_cmpint(tag->response.value.width, ==, 800); + g_assert_cmpint(tag->response.value.height, ==, 600); +} +DECLARE_TEST_CASE_SETUP(SET_FB_VIRT_WIDTH) { + tag->request.value.width = 800; + tag->request.value.height = 600; +} + +//============================================================================== int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -201,6 +375,26 @@ int main(int argc, char **argv) QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, EMMC); QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, EMMC); QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, EMMC); + QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, UART); + QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, UART); + QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, UART); + QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, CORE); + QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, CORE); + QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, CORE); + QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, ANY); + QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, ANY); + QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, ANY); + QTEST_ADD_TEST_CASE(GET_TEMPERATURE); + QTEST_ADD_TEST_CASE(GET_MAX_TEMPERATURE); + QTEST_ADD_TEST_CASE(ALLOCATE_BUFFER); + QTEST_ADD_TEST_CASE(RELEASE_FRAMEBUFFER); + QTEST_ADD_TEST_CASE(BLANK_FRAMEBUFFER); + QTEST_ADD_TEST_CASE(TEST_FB_PHYS_WIDTH); + QTEST_ADD_TEST_CASE(GET_FB_PHYS_WIDTH, INITIAL); + QTEST_ADD_TEST_CASE(SET_FB_PHYS_WIDTH); + QTEST_ADD_TEST_CASE(TEST_FB_VIRT_WIDTH); + QTEST_ADD_TEST_CASE(GET_FB_VIRT_WIDTH, INITIAL); + QTEST_ADD_TEST_CASE(SET_FB_VIRT_WIDTH); return g_test_run(); } From patchwork Sun Dec 3 21:29:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VJ5jrEuk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0Sn3Qtkz23p4 for ; Mon, 4 Dec 2023 08:35:05 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2L-0002Im-Oh; Sun, 03 Dec 2023 16:30:01 -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 1r9u2F-00025C-Lc; Sun, 03 Dec 2023 16:29:55 -0500 Received: from mail-yb1-xb2c.google.com ([2607:f8b0:4864:20::b2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2D-0005Zk-O9; Sun, 03 Dec 2023 16:29:55 -0500 Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-db3fa47c2f7so2142964276.0; Sun, 03 Dec 2023 13:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638992; x=1702243792; 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=QIUscvz7pf1VFtRN5hHqsbtj5B7mCmCi2M+oBvF9ZJ8=; b=VJ5jrEukI5fM8WIPuCd/nTk2Jbj8pmRe2dpMo3QgkmhIJoWW/4fORhAcUpYCXq5pbI Z2y1jK4WIPaaSVcoLh/z+GufxbA/8s0mG0Ekn2L5vjRG+ch7eg290k2/LLjPy1MVKC/v UzT9/KHm44dCTryfzButL4XKgPxjqZZcIHP3yHEiqhOT6FEeVzWKuvb2DIU3XmKyuO0/ /QwqQ0+UrTcCBCdOmF1Tuq4bh8rC/Qh1K6qkkrm10hYreevOIeY3wLaWSWQHxmlup3Qf INjUoHs6E5uqtzdY6zvrFcMEmOE2eDwBifiS7cmNMfIH+XGijwq44ZuOk2o2dr70FfbX bj4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638992; x=1702243792; 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=QIUscvz7pf1VFtRN5hHqsbtj5B7mCmCi2M+oBvF9ZJ8=; b=ZZPw9K2H78L3UGW2mBcabvrgPY5l6hfWfCrFuAgxCroyLX5v6Q6yl6ViHe186m7vBT hLoJTR/0ufAVsvabbxJVvhRX8zCRy19vl8qGwQTReZf1Z+iLqujxkD9Uri67UCyOzZoo HtUwzVmBGA0h+eS3CgGPdMPQSLHEEE8boPzsuvKATeGhp0UZtE8VV58IDdIN/PS1HQUA D95Cp93RtRIAKO7FB9K2E0dn4yAMhWdSbl85xB1R4a34AjQcdawEpKTeUC7VQncIGGy5 yfNgClPhhtz1NpGgPvvA0ZqVcZQ1Qxz6F2fr5xyCMEXIqV7PpAchQ0i42FCBtkzIFj43 Y0Qg== X-Gm-Message-State: AOJu0Yw3U0yXXcLxGfcwxNej0Whs219XL60KmlTnDwwsJ6ZxaVwIjZBr 4mVxG8e3YlK57ZvLfnHKAcL9UD8I5wAebA== X-Google-Smtp-Source: AGHT+IFlbgCIIfP/3p6ClThaLrGdrZP/lTccAM/o+8UJkX/XH7md1E157S6gIFbEzZ5YQgZClzQKGA== X-Received: by 2002:a05:6902:188d:b0:db7:dad0:60df with SMTP id cj13-20020a056902188d00b00db7dad060dfmr2078955ybb.108.1701638992305; Sun, 03 Dec 2023 13:29:52 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:52 -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 42/45] Add mailbox property tests. Part 3 Date: Sun, 3 Dec 2023 15:29:02 -0600 Message-Id: <20231203212905.1364036-43-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-42-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> <20231203212905.1364036-40-sergey.kambalin@auriga.com> <20231203212905.1364036-41-sergey.kambalin@auriga.com> <20231203212905.1364036-42-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2c; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2c.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_PDS_OTHER_BAD_TLD=0.01, T_SCC_BODY_TEXT_LINE=-0.01, UPPERCASE_50_75=0.008 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mbox-property-test.c | 213 ++++++++++++++++++++++- 1 file changed, 212 insertions(+), 1 deletion(-) diff --git a/tests/qtest/bcm2838-mbox-property-test.c b/tests/qtest/bcm2838-mbox-property-test.c index 5322c563a0..1b4a2ed9cb 100644 --- a/tests/qtest/bcm2838-mbox-property-test.c +++ b/tests/qtest/bcm2838-mbox-property-test.c @@ -361,7 +361,194 @@ DECLARE_TEST_CASE_SETUP(SET_FB_VIRT_WIDTH) { tag->request.value.height = 600; } -//============================================================================== +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_FB_DEPTH) { + g_assert_cmpint(tag->response.value.bpp, ==, DUMMY_VALUE); +} +DECLARE_TEST_CASE_SETUP(TEST_FB_DEPTH) { + tag->request.value.bpp = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_FB_DEPTH) { + g_assert_cmpint(tag->response.value.bpp, ==, 16); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_FB_DEPTH) { + g_assert_cmpint(tag->response.value.bpp, ==, 24); +} +DECLARE_TEST_CASE_SETUP(SET_FB_DEPTH) { + tag->request.value.bpp = 24; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_PIXEL_ORDER) { + g_assert_cmphex(tag->response.value.pixel_order, ==, DUMMY_VALUE); +} +DECLARE_TEST_CASE_SETUP(TEST_PIXEL_ORDER) { + tag->request.value.pixel_order = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_PIXEL_ORDER) { + g_assert_cmphex(tag->response.value.pixel_order, ==, PIXEL_ORDER_RGB); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_PIXEL_ORDER, BGR) { + g_assert_cmphex(tag->response.value.pixel_order, ==, PIXEL_ORDER_BGR); +} +DECLARE_TEST_CASE_SETUP(SET_PIXEL_ORDER, BGR) { + tag->request.value.pixel_order = PIXEL_ORDER_BGR; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_PIXEL_ORDER, RGB) { + g_assert_cmphex(tag->response.value.pixel_order, ==, PIXEL_ORDER_BGR); +} +DECLARE_TEST_CASE_SETUP(SET_PIXEL_ORDER, RGB) { + tag->request.value.pixel_order = PIXEL_ORDER_BGR; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_FB_ALPHA_MODE) { + g_assert_cmphex(tag->response.value.alpha_mode, ==, DUMMY_VALUE); +} +DECLARE_TEST_CASE_SETUP(TEST_FB_ALPHA_MODE) { + tag->request.value.alpha_mode = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_FB_ALPHA_MODE) { + g_assert_cmphex(tag->response.value.alpha_mode, ==, ALPHA_MODE_IGNORED); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_FB_ALPHA_MODE, ENABLED) { + g_assert_cmphex(tag->response.value.alpha_mode, ==, ALPHA_MODE_ENABLED); +} +DECLARE_TEST_CASE_SETUP(SET_FB_ALPHA_MODE, ENABLED) { + tag->request.value.alpha_mode = ALPHA_MODE_ENABLED; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_FB_ALPHA_MODE, REVERSED) { + g_assert_cmphex(tag->response.value.alpha_mode, ==, ALPHA_MODE_REVERSED); +} +DECLARE_TEST_CASE_SETUP(SET_FB_ALPHA_MODE, REVERSED) { + tag->request.value.alpha_mode = ALPHA_MODE_REVERSED; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_FB_ALPHA_MODE, IGNORED) { + g_assert_cmphex(tag->response.value.alpha_mode, ==, ALPHA_MODE_IGNORED); +} +DECLARE_TEST_CASE_SETUP(SET_FB_ALPHA_MODE, IGNORED) { + tag->request.value.alpha_mode = ALPHA_MODE_IGNORED; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_PITCH) { + g_assert_cmpint(tag->response.value.pitch, ==, 1280); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_VIRTUAL_OFFSET) { + g_assert_cmpint(tag->response.value.x, ==, DUMMY_VALUE); + g_assert_cmpint(tag->response.value.y, ==, DUMMY_VALUE); +} +DECLARE_TEST_CASE_SETUP(TEST_VIRTUAL_OFFSET) { + tag->request.value.x = DUMMY_VALUE; + tag->request.value.y = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_VIRTUAL_OFFSET) { + g_assert_cmpint(tag->response.value.x, ==, 0); + g_assert_cmpint(tag->response.value.y, ==, 0); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_VIRTUAL_OFFSET, _0_) { + g_assert_cmpint(tag->response.value.x, ==, 0); + g_assert_cmpint(tag->response.value.y, ==, 0); +} +DECLARE_TEST_CASE_SETUP(SET_VIRTUAL_OFFSET, _0_) { + tag->request.value.x = 0; + tag->request.value.y = 0; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_VIRTUAL_OFFSET, _42_) { + g_assert_cmpint(tag->response.value.x, ==, 42); + g_assert_cmpint(tag->response.value.y, ==, 42); +} +DECLARE_TEST_CASE_SETUP(SET_VIRTUAL_OFFSET, _42_) { + tag->request.value.x = 42; + tag->request.value.y = 42; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_OVERSCAN) { + g_assert_cmpint(tag->response.value.top, ==, 0); + g_assert_cmpint(tag->response.value.bottom, ==, 0); + g_assert_cmpint(tag->response.value.left, ==, 0); + g_assert_cmpint(tag->response.value.right, ==, 0); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(TEST_OVERSCAN) { + g_assert_cmpint(tag->response.value.top, ==, 0); + g_assert_cmpint(tag->response.value.bottom, ==, 0); + g_assert_cmpint(tag->response.value.left, ==, 0); + g_assert_cmpint(tag->response.value.right, ==, 0); +} +DECLARE_TEST_CASE_SETUP(TEST_OVERSCAN) { + tag->request.value.top = DUMMY_VALUE; + tag->request.value.bottom = DUMMY_VALUE; + tag->request.value.left = DUMMY_VALUE; + tag->request.value.right = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_OVERSCAN) { + g_assert_cmpint(tag->response.value.top, ==, 0); + g_assert_cmpint(tag->response.value.bottom, ==, 0); + g_assert_cmpint(tag->response.value.left, ==, 0); + g_assert_cmpint(tag->response.value.right, ==, 0); +} +DECLARE_TEST_CASE_SETUP(SET_OVERSCAN) { + tag->request.value.top = DUMMY_VALUE; + tag->request.value.bottom = DUMMY_VALUE; + tag->request.value.left = DUMMY_VALUE; + tag->request.value.right = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_DMA_CHANNELS) { + g_assert_cmphex(tag->response.value.mask, ==, GPIO_MASK); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_COMMANDLINE) { + /* No special checks are needed for this test case */ +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_NUM_DISPLAYS) { + g_assert_cmpint(tag->response.value.num_displays, ==, 1); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_PITCH) { + /* No special checks are needed for this test case */ +} +DECLARE_TEST_CASE_SETUP(SET_PITCH) { + tag->request.value.pitch = DUMMY_VALUE; +} + +/*----------------------------------------------------------------------------*/ int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -395,6 +582,30 @@ int main(int argc, char **argv) QTEST_ADD_TEST_CASE(TEST_FB_VIRT_WIDTH); QTEST_ADD_TEST_CASE(GET_FB_VIRT_WIDTH, INITIAL); QTEST_ADD_TEST_CASE(SET_FB_VIRT_WIDTH); + QTEST_ADD_TEST_CASE(TEST_FB_DEPTH); + QTEST_ADD_TEST_CASE(GET_FB_DEPTH); + QTEST_ADD_TEST_CASE(SET_FB_DEPTH); + QTEST_ADD_TEST_CASE(TEST_PIXEL_ORDER); + QTEST_ADD_TEST_CASE(GET_PIXEL_ORDER); + QTEST_ADD_TEST_CASE(SET_PIXEL_ORDER, BGR); + QTEST_ADD_TEST_CASE(SET_PIXEL_ORDER, RGB); + QTEST_ADD_TEST_CASE(TEST_FB_ALPHA_MODE); + QTEST_ADD_TEST_CASE(GET_FB_ALPHA_MODE); + QTEST_ADD_TEST_CASE(SET_FB_ALPHA_MODE, ENABLED); + QTEST_ADD_TEST_CASE(SET_FB_ALPHA_MODE, REVERSED); + QTEST_ADD_TEST_CASE(SET_FB_ALPHA_MODE, IGNORED); + QTEST_ADD_TEST_CASE(GET_PITCH); + QTEST_ADD_TEST_CASE(TEST_VIRTUAL_OFFSET); + QTEST_ADD_TEST_CASE(GET_VIRTUAL_OFFSET); + QTEST_ADD_TEST_CASE(SET_VIRTUAL_OFFSET, _0_); + QTEST_ADD_TEST_CASE(SET_VIRTUAL_OFFSET, _42_); + QTEST_ADD_TEST_CASE(GET_OVERSCAN); + QTEST_ADD_TEST_CASE(TEST_OVERSCAN); + QTEST_ADD_TEST_CASE(SET_OVERSCAN); + QTEST_ADD_TEST_CASE(GET_DMA_CHANNELS); + QTEST_ADD_TEST_CASE(GET_COMMANDLINE); + QTEST_ADD_TEST_CASE(GET_NUM_DISPLAYS); + QTEST_ADD_TEST_CASE(SET_PITCH); return g_test_run(); } From patchwork Sun Dec 3 21:29:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Rli2kxYl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0QV3G5Tz23nJ for ; Mon, 4 Dec 2023 08:33:06 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2d-0002gk-Gm; Sun, 03 Dec 2023 16:30:19 -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 1r9u2G-00029K-M9; Sun, 03 Dec 2023 16:29:56 -0500 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2E-0005a3-U7; Sun, 03 Dec 2023 16:29:56 -0500 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-da37522a363so1874016276.0; Sun, 03 Dec 2023 13:29:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638993; x=1702243793; 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=1GNEkGSGTayvrkpE/A09q7fosCX6vgAb65BjfPwzFOc=; b=Rli2kxYljvzuGVNneAWTg3Kqfr7y0PbLKxve8aLyGV7VEeKVEHMQb+DjDwzufWJ7m1 dg8K/9yETvEE2zD95TSMq4o2Iyrsbq3funmDUqVBYzVtresdDAGbMVpB8KRpN3A+nQYr EKZMeXy4vN1j0sTG2SXQb/0vACfp3HCivYRqGo8/ZidhUG/8rZ39nyuBosJugWko5dcM H62I6pwNqR1o0K9GPMEePDNtgau1f3vd6/GpZRxOM5BnWGrrrveIbXzw2dIAdUCk2D4q GXZefT4OCZhW9Hrh/EyOa1Wc5wO+uDhBsDYWqSCVuj7wZ9qTkCjNXIzs8Yys76Tf3tPr g/hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638993; x=1702243793; 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=1GNEkGSGTayvrkpE/A09q7fosCX6vgAb65BjfPwzFOc=; b=H8Oz2eWzpdbjaQJe9kb8QiRiIc4sXVx/3Ax+aQCeq9Wk1vDs8lL4v08xVKqIyal+pi IMxXzAdWVOh8X/Cc9U/SOX/itNXnnhaNKvPBGz/dH/QjEYTSP6Lfy62NRVTrDTvwdecw QCQxur6Ne5FuV4zbEjJATNMe+5mcCFfeZAYWBjftzr6rcdexuOGNVjS4GSsCnWD9XD09 mOgIMmp5iFZMD6BMbdBtMUhpq/y04s88wPtCVzE/iKoOyDUijColhhP93vpLZatSjSQT PG7r47Uijt+nv1NQqRgv+ZZBdacyLu3V6ouXYRQ/nTY7mZYvzl++DDqJFKhyiLhY89f+ exZQ== X-Gm-Message-State: AOJu0YxNyAY4bxG+DsyCfghrFohcfDkaV8eoUmGNckig8wnE7R0n4rGU UFS9hstxocleCcHJspKmcJRI6iidtlPhmQ== X-Google-Smtp-Source: AGHT+IEZIndBGnAulCxDm6ejUvIByVromQltKmTbnc7fVhoqjUVv0UuIn9RGpzUf/+Ky85aHHAGNoA== X-Received: by 2002:a25:aca3:0:b0:db5:50a4:5d90 with SMTP id x35-20020a25aca3000000b00db550a45d90mr1800655ybi.31.1701638993565; Sun, 03 Dec 2023 13:29:53 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:53 -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 43/45] Add missed BCM2835 properties Date: Sun, 3 Dec 2023 15:29:03 -0600 Message-Id: <20231203212905.1364036-44-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-43-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> <20231203212905.1364036-40-sergey.kambalin@auriga.com> <20231203212905.1364036-41-sergey.kambalin@auriga.com> <20231203212905.1364036-42-sergey.kambalin@auriga.com> <20231203212905.1364036-43-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb35.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- hw/misc/bcm2835_property.c | 47 ++++++++++++++++++++++++++++ include/hw/arm/raspberrypi-fw-defs.h | 12 ++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c index ff55a4e2cd..dfeb793b3e 100644 --- a/hw/misc/bcm2835_property.c +++ b/hw/misc/bcm2835_property.c @@ -19,6 +19,9 @@ #include "trace.h" #include "hw/arm/raspi_platform.h" +#define RPI_EXP_GPIO_BASE 128 +#define VCHI_BUSADDR_SIZE sizeof(uint32_t) + /* https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface */ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) @@ -138,6 +141,13 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) resplen = 8; break; + case RPI_FWREQ_GET_CLOCKS: + /* TODO: add more clock IDs if needed */ + stl_le_phys(&s->dma_as, value + 12, 0); + stl_le_phys(&s->dma_as, value + 16, RPI_FIRMWARE_ARM_CLK_ID); + resplen = 8; + break; + case RPI_FWREQ_SET_CLOCK_RATE: case RPI_FWREQ_SET_MAX_CLOCK_RATE: case RPI_FWREQ_SET_MIN_CLOCK_RATE: @@ -276,6 +286,7 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) stl_le_phys(&s->dma_as, value + 12, 0); resplen = 4; break; + case RPI_FWREQ_FRAMEBUFFER_GET_NUM_DISPLAYS: stl_le_phys(&s->dma_as, value + 12, 1); resplen = 4; @@ -301,6 +312,42 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) resplen); break; + case RPI_FWREQ_GET_THROTTLED: + stl_le_phys(&s->dma_as, value + 12, 0); + resplen = 4; + break; + + case RPI_FWREQ_FRAMEBUFFER_SET_PITCH: + qemu_log_mask(LOG_UNIMP, "RPI_FWREQ_FRAMEBUFFER_SET_PITCH " + "is not implemented\n"); + break; + + case RPI_FWREQ_GET_GPIO_CONFIG: + qemu_log_mask(LOG_UNIMP, "RPI_FWREQ_GET_GPIO_CONFIG " + "is not implemented\n"); + break; + + case RPI_FWREQ_SET_GPIO_CONFIG: + qemu_log_mask(LOG_UNIMP, "RPI_FWREQ_SET_GPIO_CONFIG " + "is not implemented\n"); + break; + + case RPI_FWREQ_GET_GPIO_STATE: + qemu_log_mask(LOG_UNIMP, "RPI_FWREQ_GET_GPIO_STATE " + "is not implemented\n"); + break; + + case RPI_FWREQ_SET_GPIO_STATE: + qemu_log_mask(LOG_UNIMP, "RPI_FWREQ_SET_GPIO_STATE " + "is not implemented\n"); + break; + + case RPI_FWREQ_VCHIQ_INIT: + stl_le_phys(&s->dma_as, + value + offsetof(rpi_firmware_prop_request_t, payload), + 0); + resplen = VCHI_BUSADDR_SIZE; + break; default: qemu_log_mask(LOG_UNIMP, "bcm2835_property: unhandled tag 0x%08x\n", tag); diff --git a/include/hw/arm/raspberrypi-fw-defs.h b/include/hw/arm/raspberrypi-fw-defs.h index 4551fe7450..ded7a22f02 100644 --- a/include/hw/arm/raspberrypi-fw-defs.h +++ b/include/hw/arm/raspberrypi-fw-defs.h @@ -101,7 +101,6 @@ enum rpi_firmware_property_tag { RPI_FWREQ_FRAMEBUFFER_GET_DISPLAY_ID = 0x00040016, RPI_FWREQ_FRAMEBUFFER_SET_DISPLAY_NUM = 0x00048013, RPI_FWREQ_FRAMEBUFFER_GET_NUM_DISPLAYS = 0x00040013, - RPI_FWREQ_FRAMEBUFFER_GET_DISPLAY_SETTINGS = 0x00040014, RPI_FWREQ_FRAMEBUFFER_TEST_PHYSICAL_WIDTH_HEIGHT = 0x00044003, RPI_FWREQ_FRAMEBUFFER_TEST_VIRTUAL_WIDTH_HEIGHT = 0x00044004, RPI_FWREQ_FRAMEBUFFER_TEST_DEPTH = 0x00044005, @@ -160,4 +159,15 @@ enum rpi_firmware_clk_id { RPI_FIRMWARE_NUM_CLK_ID, }; +struct rpi_firmware_property_tag_header { + uint32_t tag; + uint32_t buf_size; + uint32_t req_resp_size; +}; + +typedef struct rpi_firmware_prop_request { + struct rpi_firmware_property_tag_header hdr; + uint8_t payload[0]; +} rpi_firmware_prop_request_t; + #endif /* INCLUDE_HW_MISC_RASPBERRYPI_FW_DEFS_H_ */ From patchwork Sun Dec 3 21:29:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=h8KuwIY8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0TS2cpyz23mf for ; Mon, 4 Dec 2023 08:35:40 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2d-0002gI-F5; Sun, 03 Dec 2023 16:30:19 -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 1r9u2H-0002BO-Jb; Sun, 03 Dec 2023 16:29:57 -0500 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2G-0005aJ-2t; Sun, 03 Dec 2023 16:29:57 -0500 Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-da7ea62e76cso2173509276.3; Sun, 03 Dec 2023 13:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638994; x=1702243794; 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=pjKhO+PzqqrLoVjDzrdEJqubBSeVITy6r+qEgUKg3Ec=; b=h8KuwIY8o3PnH230wgqySbQqjmg1lraZjRHFU+iUgQ9iqSwFXphwGpGA6fPXSM7Slc XO2F+XtfVFNOMCPqzpMbWo2p6mfEUvJ9YZDqO0F8dYCIHXB88Bq6S4akcX61sDxsVvdP nMhYxUDAoNGYswtjcq/BjhODGGUPg0zJFWzjUyD//sdrvmEyME6ZEt9P/8ZT9PlfrWB5 LOsrkVH+dDHK1nvMoA6wSaHTnctbFN8OSKWXpkQjmPUKMmREvPDbOp2f5VN9B8GSafQq WzmXbHkuQby7llXsN35dVetOVTQ3vsm9FYZ7c1VPL/9C+RhZynQcVJeiLqGi+sHVXsq3 w6Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638994; x=1702243794; 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=pjKhO+PzqqrLoVjDzrdEJqubBSeVITy6r+qEgUKg3Ec=; b=O/VyYfRRzUP2EY4EJC1ogSaWAtAJ1x2c+AdOcQRI1qJDsGglc/GuqPcGRu48WHcJ90 Xl7RaLjzLnog5/2qJ5peSTC6RZ4Z1OT7xn3X4PIG7occpvcJxYFeZwdC1YJbvBvda8BK nHEVfCmC/WieaeyLokZuus/fkYbImUMt3iUNEC8/6Xu+TDGAxEFnsKsogTM05ZDDVbcr XlSTw9N+P5kAJjIoeror5vTMBecMaUsuxpApaRIKoLCLArMFQWRlgTr338SfOE3KF+a/ UFdGulxIX/i4qWaDjyZgYoZEew4tsGeRM5NMpsxK7dfzbFnm2uTJUO3Y5NmNBxK2nIuL JzpQ== X-Gm-Message-State: AOJu0YyklatUj4oN0wg3EQEqgGq0bBLDOFkPJ90W1mW0+L5xOXw4k4tN b75lIZJUHAn3gVsgQhB6IVUkbLYCVpDpfQ== X-Google-Smtp-Source: AGHT+IGBSJFSiGlQ7qKcIQOAhBImVmaL0HQmbCGFFlmbZ4XxHauALBRETtRxijzF9MsBNqt8+gBDjg== X-Received: by 2002:a25:6605:0:b0:db9:34c9:87c9 with SMTP id a5-20020a256605000000b00db934c987c9mr1408674ybc.101.1701638994583; Sun, 03 Dec 2023 13:29:54 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:54 -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 44/45] Append added properties to mailbox test Date: Sun, 3 Dec 2023 15:29:04 -0600 Message-Id: <20231203212905.1364036-45-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-44-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> <20231203212905.1364036-40-sergey.kambalin@auriga.com> <20231203212905.1364036-41-sergey.kambalin@auriga.com> <20231203212905.1364036-42-sergey.kambalin@auriga.com> <20231203212905.1364036-43-sergey.kambalin@auriga.com> <20231203212905.1364036-44-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2e; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2e.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mbox-property-test.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/qtest/bcm2838-mbox-property-test.c b/tests/qtest/bcm2838-mbox-property-test.c index 1b4a2ed9cb..3a2e7f9194 100644 --- a/tests/qtest/bcm2838-mbox-property-test.c +++ b/tests/qtest/bcm2838-mbox-property-test.c @@ -269,6 +269,12 @@ DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, ANY) { tag->request.value.clock_id = CLOCK_ID_UNDEFINED; } +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCKS) { + g_assert_cmphex(tag->response.value.root_clock, ==, CLOCK_ID_ROOT); + g_assert_cmphex(tag->response.value.arm_clock, ==, CLOCK_ID_ARM); +} + /*----------------------------------------------------------------------------*/ DECLARE_TEST_CASE(GET_TEMPERATURE) { g_assert_cmphex(tag->response.value.temperature_id, ==, TEMPERATURE_ID_SOC); @@ -535,17 +541,19 @@ DECLARE_TEST_CASE(GET_COMMANDLINE) { /* No special checks are needed for this test case */ } +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_THROTTLED) { + g_assert_cmpint(tag->response.value.throttled, ==, 0); +} + /*----------------------------------------------------------------------------*/ DECLARE_TEST_CASE(GET_NUM_DISPLAYS) { g_assert_cmpint(tag->response.value.num_displays, ==, 1); } /*----------------------------------------------------------------------------*/ -DECLARE_TEST_CASE(SET_PITCH) { - /* No special checks are needed for this test case */ -} -DECLARE_TEST_CASE_SETUP(SET_PITCH) { - tag->request.value.pitch = DUMMY_VALUE; +DECLARE_TEST_CASE(INITIALIZE_VCHIQ) { + g_assert_cmpint(tag->response.value.zero, ==, 0); } /*----------------------------------------------------------------------------*/ @@ -571,6 +579,7 @@ int main(int argc, char **argv) QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, ANY); QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, ANY); QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, ANY); + QTEST_ADD_TEST_CASE(GET_CLOCKS); QTEST_ADD_TEST_CASE(GET_TEMPERATURE); QTEST_ADD_TEST_CASE(GET_MAX_TEMPERATURE); QTEST_ADD_TEST_CASE(ALLOCATE_BUFFER); @@ -604,8 +613,9 @@ int main(int argc, char **argv) QTEST_ADD_TEST_CASE(SET_OVERSCAN); QTEST_ADD_TEST_CASE(GET_DMA_CHANNELS); QTEST_ADD_TEST_CASE(GET_COMMANDLINE); + QTEST_ADD_TEST_CASE(GET_THROTTLED); QTEST_ADD_TEST_CASE(GET_NUM_DISPLAYS); - QTEST_ADD_TEST_CASE(SET_PITCH); + QTEST_ADD_TEST_CASE(INITIALIZE_VCHIQ); return g_test_run(); } From patchwork Sun Dec 3 21:29:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 1871106 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=N08LSo8B; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sk0W20Cvnz23mf for ; Mon, 4 Dec 2023 08:37:02 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9u2Z-0002Zu-Su; Sun, 03 Dec 2023 16:30:16 -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 1r9u2J-0002Dv-FW; Sun, 03 Dec 2023 16:29:59 -0500 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9u2G-0005ae-Tn; Sun, 03 Dec 2023 16:29:58 -0500 Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-db8892a5f96so844671276.2; Sun, 03 Dec 2023 13:29:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701638995; x=1702243795; 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=igayQuYX/F7iH3RNFaYv1D/3MuPEz8Ua3kpb9vPSfPs=; b=N08LSo8B1Gm5C+nnV936qqkUL7oThEwb4fhCu7Qw42JyuY2y4xVoCGoI3g5Ru1ztZV XxxTsjSlizVWcI2+eKAeHd4Ai4uviI/7xziW8hexHLSP7/Ttk9vD7bg77vtuMaf067C+ r/oT2AU9dgNIk5YP12jrchu1cyPuyK7pl2VXpY5Fw83h8eBCCxXCs+T4LkdaUp1eIMum 0qIrdJdLyQ+iuoK7NUW5gMpV+hhq3UH4WG8qdddGuP/triw9fj6CSaa7c+sfvunc1xhp SaVJDpQTE9qbK4B3dbpa7/S77groirKjHK15hcdDg1HdWrDzMx3hecdnjIR5mvBRMXB2 zDWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701638995; x=1702243795; 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=igayQuYX/F7iH3RNFaYv1D/3MuPEz8Ua3kpb9vPSfPs=; b=XprY+rxs1m3swyPyqasNt3zQha2+tMwtkte+BaKrcwoDHND1fnLII7ec1iTWRupxJ9 i5j2X2qgTYHo/yAU6ZTVOEw865bl3Vp0uuCqIQ8ZjkaSx8tOgZr0vwrFBUHfnvYgRvcn IrVS9T8A2hpaF5T2QFgPnOd44VmjwNkIpyasBs8efJVsOUXnHeyUIIcVzs6j0bu6NVri Xwp0FzODLTj6SuXV+YEUcL2ZvLTbz36NYCkGGsuMeeetnpBCh8IkjZ1UvBjnB1erpvZn VB/tg8eEfgFM+bBmRGBG4pkCKk33y5XgAkIHNIiiX1F9KaUPtvxpE0JDDTvKFBWlU3kR Wo5Q== X-Gm-Message-State: AOJu0YyKD+YZXuDcFnu3Uepxn+DuuZsN7ZEvcN1Kzj1Ir8vSZdHmZEPa AlrPwF38JD22qB42i9bmEVASjbAu/Q3H7Q== X-Google-Smtp-Source: AGHT+IGp8l9nIreZkOFoAcEMRcLbCd9jhilYumz9ef3e/GUNhk4pzoxvFPYT82NvW0KBtenU6Kc2DA== X-Received: by 2002:a25:68d1:0:b0:db7:dacf:6210 with SMTP id d200-20020a2568d1000000b00db7dacf6210mr2066292ybc.98.1701638995565; Sun, 03 Dec 2023 13:29:55 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id c17-20020a25a291000000b00d9cc606c78csm1807318ybi.41.2023.12.03.13.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 13:29:55 -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 45/45] Add RPi4B to paspi4.rst Date: Sun, 3 Dec 2023 15:29:05 -0600 Message-Id: <20231203212905.1364036-46-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203212905.1364036-45-sergey.kambalin@auriga.com> References: <20230726132512.149618-1-sergey.kambalin@auriga.com> <20231203212905.1364036-1-sergey.kambalin@auriga.com> <20231203212905.1364036-2-sergey.kambalin@auriga.com> <20231203212905.1364036-3-sergey.kambalin@auriga.com> <20231203212905.1364036-4-sergey.kambalin@auriga.com> <20231203212905.1364036-5-sergey.kambalin@auriga.com> <20231203212905.1364036-6-sergey.kambalin@auriga.com> <20231203212905.1364036-7-sergey.kambalin@auriga.com> <20231203212905.1364036-8-sergey.kambalin@auriga.com> <20231203212905.1364036-9-sergey.kambalin@auriga.com> <20231203212905.1364036-10-sergey.kambalin@auriga.com> <20231203212905.1364036-11-sergey.kambalin@auriga.com> <20231203212905.1364036-12-sergey.kambalin@auriga.com> <20231203212905.1364036-13-sergey.kambalin@auriga.com> <20231203212905.1364036-14-sergey.kambalin@auriga.com> <20231203212905.1364036-15-sergey.kambalin@auriga.com> <20231203212905.1364036-16-sergey.kambalin@auriga.com> <20231203212905.1364036-17-sergey.kambalin@auriga.com> <20231203212905.1364036-18-sergey.kambalin@auriga.com> <20231203212905.1364036-19-sergey.kambalin@auriga.com> <20231203212905.1364036-20-sergey.kambalin@auriga.com> <20231203212905.1364036-21-sergey.kambalin@auriga.com> <20231203212905.1364036-22-sergey.kambalin@auriga.com> <20231203212905.1364036-23-sergey.kambalin@auriga.com> <20231203212905.1364036-24-sergey.kambalin@auriga.com> <20231203212905.1364036-25-sergey.kambalin@auriga.com> <20231203212905.1364036-26-sergey.kambalin@auriga.com> <20231203212905.1364036-27-sergey.kambalin@auriga.com> <20231203212905.1364036-28-sergey.kambalin@auriga.com> <20231203212905.1364036-29-sergey.kambalin@auriga.com> <20231203212905.1364036-30-sergey.kambalin@auriga.com> <20231203212905.1364036-31-sergey.kambalin@auriga.com> <20231203212905.1364036-32-sergey.kambalin@auriga.com> <20231203212905.1364036-33-sergey.kambalin@auriga.com> <20231203212905.1364036-34-sergey.kambalin@auriga.com> <20231203212905.1364036-35-sergey.kambalin@auriga.com> <20231203212905.1364036-36-sergey.kambalin@auriga.com> <20231203212905.1364036-37-sergey.kambalin@auriga.com> <20231203212905.1364036-38-sergey.kambalin@auriga.com> <20231203212905.1364036-39-sergey.kambalin@auriga.com> <20231203212905.1364036-40-sergey.kambalin@auriga.com> <20231203212905.1364036-41-sergey.kambalin@auriga.com> <20231203212905.1364036-42-sergey.kambalin@auriga.com> <20231203212905.1364036-43-sergey.kambalin@auriga.com> <20231203212905.1364036-44-sergey.kambalin@auriga.com> <20231203212905.1364036-45-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b2e; envelope-from=serg.oker@gmail.com; helo=mail-yb1-xb2e.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Sergey Kambalin --- docs/system/arm/raspi.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/system/arm/raspi.rst b/docs/system/arm/raspi.rst index 922fe375a6..db9e0949ef 100644 --- a/docs/system/arm/raspi.rst +++ b/docs/system/arm/raspi.rst @@ -1,5 +1,5 @@ -Raspberry Pi boards (``raspi0``, ``raspi1ap``, ``raspi2b``, ``raspi3ap``, ``raspi3b``) -====================================================================================== +Raspberry Pi boards (``raspi0``, ``raspi1ap``, ``raspi2b``, ``raspi3ap``, ``raspi3b``, ``raspi4b-2g``) +====================================================================================================== QEMU provides models of the following Raspberry Pi boards: @@ -12,12 +12,13 @@ QEMU provides models of the following Raspberry Pi boards: Cortex-A53 (4 cores), 512 MiB of RAM ``raspi3b`` Cortex-A53 (4 cores), 1 GiB of RAM - +``raspi4b-2g`` + Cortex-A72 (4 cores), 2 GiB of RAM Implemented devices ------------------- - * ARM1176JZF-S, Cortex-A7 or Cortex-A53 CPU + * ARM1176JZF-S, Cortex-A7, Cortex-A53 or Cortex-A72 CPU * Interrupt controller * DMA controller * Clock and reset controller (CPRMAN) @@ -33,6 +34,8 @@ Implemented devices * USB2 host controller (DWC2 and MPHI) * MailBox controller (MBOX) * VideoCore firmware (property) + * PCIE Root Port (raspi4b-2g) + * GENET Ethernet Controller (raspi4b-2g) Missing devices