From nobody Wed Nov 27 02:41:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1702003112; cv=none; d=zohomail.com; s=zohoarc; b=BQTD4KJXYrPuFUUGfFbS4peN2WdjOV1NeSEPqKNTQyKbMIwKiyErVd9fSoz69gdVQQyqg0K3Mt65IQswaa7pv1D6D50UYI505CjoBsbvFOwqD7vnAFsWd4sMQPGjk6uvNEqnwibKd+ZjYCmgUBnLRiGT423YhUG4I1tMBYSv1hU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702003112; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tcKM0zsaUF6OxJgIAQHfOevQ93BKCzxRx4ONFnlRnhk=; b=nMAkgj6tdJYlteIx7WU6W3sAbx65ScLnOc98kzjF206aarADkvBblmRz4LwrjVifuAMAp6h6A3MLEahMeIjUYfR2vE9pRDFbbnQDPqMyVeelrZkyqlGEk2zEJddg2q5LJrozsSv2e2paWbiBDpvwJPFzkg41Y9L+/nr9AUUSY/M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1702003112683988.8109935518339; Thu, 7 Dec 2023 18:38:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBQfz-0004lm-UJ; Thu, 07 Dec 2023 21:33: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 1rBQfm-0004PM-Tb; Thu, 07 Dec 2023 21:33:04 -0500 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rBQfk-0002Xn-L9; Thu, 07 Dec 2023 21:33:02 -0500 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2c9f62fca3bso20103331fa.0; Thu, 07 Dec 2023 18:32:59 -0800 (PST) Received: from localhost.localdomain ([185.200.240.39]) by smtp.gmail.com with ESMTPSA id r1-20020a2e94c1000000b002c9e6cbf78esm99062ljh.19.2023.12.07.18.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 18:32:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702002777; x=1702607577; 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=dSKyKaZcm/oCrZx97W6pen6FL/ZeERP7cBwKa0HXwbmFEfGn1h9tVhs8Zhno0+9Op3 DqYlPe2Uaz2w6Y/wR7vkb8sOr39IEPBJjjh8VVTCunn0QVN9XEMQj6G04uoAn59LWu3T Zwo3Qpu2s5hQqIiv9a/34dGQSYUzEm1Id21wTppdCNii1wHgrAacbtDvwp2SAL4jKBy6 FtUokDBTAr8jtBVosiO0bdxNu12xN54tTyPbGeFBzIwOZxyfXplJXsC1rwPkMIlIo8jp R26mJp5aGFgZvwLr7MieRuoD+ZGNkDYlbxuS75D6prwQwfqhwiuYlV7YIKEWpkg5i0lQ 2rNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702002777; x=1702607577; 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=VPxLoNxCi8WwAkJxaoBFa1YzNqfOYAZ7dHG4b5i1Ybongmnp1Ulgt8mV6Jc8iPtqYw uVybozdc1ZeKiIdNR0yP2l4SIxpJsYCuyE5JYLlPDUwMfWuaX+FSzNi26Lxp8EwMx12y qWY1sjt0pnzQ420oQj9yTHvcpI8s4slZXwxN/E8BfL4q9WBf8BjHyYJTmoI/W0PM/mMf llfxUaTRna1J6oQdXSPoXRGDu6YMyIsM+xl9cCaKROx26roTFjiCFtlH2TTlSAgA57r3 hxe/9O+wt5rneCzaXcFSzxjcSP/KeH7/YmDysa/MSz7XPumXDj1ZjMerVWFKskC1VzNx 2CSQ== X-Gm-Message-State: AOJu0YyTOiBuSAKzjc9myGTNt8XudtuYppvDkEqKLM9FpIsHVBgc1Ef5 kHN4aher7Vqaye3gqVU+hS79kYp5dVkNTQ== X-Google-Smtp-Source: AGHT+IGlNoTaz3lgcoVsI9K0vu6+nIYGNHa2CRNXoFh+xzWIgZEtiD2TFG/Hyht7PvIRq/c1n4nN9Q== X-Received: by 2002:a2e:9854:0:b0:2ca:959:d28d with SMTP id e20-20020a2e9854000000b002ca0959d28dmr2221794ljj.100.1702002777480; Thu, 07 Dec 2023 18:32:57 -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 v4 19/45] Get rid of RNG200 timer Date: Thu, 7 Dec 2023 20:31:19 -0600 Message-Id: <20231208023145.1385775-20-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208023145.1385775-1-sergey.kambalin@auriga.com> References: <20231208023145.1385775-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=serg.oker@gmail.com; helo=mail-lj1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1702003113024100001 Content-Type: text/plain; charset="utf-8" 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); =20 + /* 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); =20 + /* 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) =20 /* Temporarily disable following devices until they are implemented*/ const char *to_be_removed_from_dt_as_wa[] =3D { - "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 @@ =20 #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 = =3D { .version_id =3D 1, .minimum_version_id =3D 1, .fields =3D (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), =20 @@ -90,6 +88,15 @@ static void bcm2838_rng200_update_irq(BCM2838Rng200State= *s) !!(s->regs[R_RNG_INT_ENABLE] & s->regs[R_RNG_INT_STATUS])); } =20 +static void bcm2838_rng200_update_rbg_period(void *opaque, ClockEvent even= t) +{ + BCM2838Rng200State *s =3D (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 =3D=3D 0) && (num_bits > 0)) { num =3D 1; } - if (num > 0) { - fifo8_push_all(fifo, buf, num); =20 + fifo8_push_all(fifo, buf, num); =20 - fifo_thld =3D FIELD_EX32(s->regs[R_RNG_FIFO_COUNT], - RNG_FIFO_COUNT, THRESHOLD); =20 - if (fifo8_num_used(fifo) > fifo_thld) { - s->regs[R_RNG_INT_STATUS] =3D FIELD_DP32(s->regs[R_RNG_INT_STA= TUS], - RNG_INT_STATUS, - TOTAL_BITS_COUNT_IRQ, 1= ); - } + fifo_thld =3D 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] =3D FIELD_DP32(s->regs[R_RNG_INT_STATUS], + RNG_INT_STATUS, + TOTAL_BITS_COUNT_IRQ, 1); } =20 s->regs[R_RNG_FIFO_COUNT] =3D 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); } =20 -/* 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(BCM2838Rng200Sta= te *s) =20 static uint32_t bcm2838_rng200_read_fifo_data(BCM2838Rng200State *s) { - Fifo8 *fifo =3D &s->fifo; const uint8_t *buf; + Fifo8 *fifo =3D &s->fifo; + uint32_t to_read =3D MIN(fifo8_num_used(fifo), 4); + uint8_t byte_buf[4] =3D {}; + uint8_t *p =3D byte_buf; uint32_t ret =3D 0; uint32_t num =3D 0; - uint32_t max =3D MIN(fifo8_num_used(fifo), sizeof(ret)); =20 - if (max > 0) { - buf =3D fifo8_pop_buf(fifo, max, &num); - if ((buf !=3D 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 =3D fifo8_pop_buf(fifo, to_read, &num); + memcpy(p, buf, num); + p +=3D num; + to_read -=3D num; } + ret =3D ldl_le_p(byte_buf); =20 s->regs[R_RNG_FIFO_COUNT] =3D FIELD_DP32(s->regs[R_RNG_FIFO_COUNT], RNG_FIFO_COUNT, @@ -222,7 +224,7 @@ static void bcm2838_rng200_ctrl_write(BCM2838Rng200Stat= e *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(); } } =20 @@ -321,6 +323,14 @@ static const MemoryRegionOps bcm2838_rng200_ops =3D { .read =3D bcm2838_rng200_read, .write =3D bcm2838_rng200_write, .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .max_access_size =3D 4, + .min_access_size =3D 4, + }, + .valid =3D { + .max_access_size =3D 4, + .min_access_size =3D 4 + }, }; =20 static void bcm2838_rng200_realize(DeviceState *dev, Error **errp) @@ -330,6 +340,13 @@ static void bcm2838_rng200_realize(DeviceState *dev, E= rror **errp) if (s->rng =3D=3D NULL) { Object *default_backend =3D object_new(TYPE_RNG_BUILTIN); =20 + 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 =3D BCM2838_RNG200(obj); SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); =20 - s->rbg_period =3D 250; - s->use_timer =3D true; - s->rng_fifo_cap =3D 128; =20 s->clock =3D qdev_init_clock_in(DEVICE(s), "rbg-clock", - NULL, s, + bcm2838_rng200_update_rbg_period, s, ClockPreUpdate); if (s->clock =3D=3D 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 =20 #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; =20 + BCM2838Rng200State rng200; SDHCIState emmc2; BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; diff --git a/include/hw/misc/bcm2838_rng200.h b/include/hw/misc/bcm2838_rng= 200.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; =20 - uint32_t rbg_period; uint32_t rng_fifo_cap; - bool use_timer; - Fifo8 fifo; + qemu_irq irq; =20 uint32_t regs[N_BCM2838_RNG200_REGS]; --=20 2.34.1