From nobody Sat Feb 7 05:32:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.68 as permitted sender) client-ip=209.85.221.68; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f68.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1602362619; cv=none; d=zohomail.com; s=zohoarc; b=YmznnKs0JODKj7JXNuile3HLlFJMUSImDAc2ZBNglbkp37wSJZwxxiHYAZD9CqAm0iAY88UPWsItaPaQvWG0sYGkf4Wy1ZAEwf/RwWsN4WoXLHPkYtPstf/5wl6cLxawzHRmvSL14KA2OhvQHcifg0twEkeKySoppf1Zi4YJxrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602362619; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GJs+vUPbnbBqVHsKvcVatNykiV7Rg7UUaqvKVc5FZic=; b=d0wiUxFHy97HYRj0WRzkQ1oVNuJkt10BTrAUjJvPs3y7juR+WWLdTPuTKODHBZfGFssluN15BlGojxgr8uSgORK6qvzf28Cf2qE3oIa+3nRHHApfjRzAtR5M7g7S0Xmw7kaTOvyY1+88G3OudP93XIVJ2Y02bF7z1P011DkbkLE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.zohomail.com with SMTPS id 1602362619044352.02603107362665; Sat, 10 Oct 2020 13:43:39 -0700 (PDT) Received: by mail-wr1-f68.google.com with SMTP id e18so14153907wrw.9 for ; Sat, 10 Oct 2020 13:43:38 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (106.red-83-59-162.dynamicip.rima-tde.net. [83.59.162.106]) by smtp.gmail.com with ESMTPSA id 205sm2705471wme.38.2020.10.10.13.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 13:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GJs+vUPbnbBqVHsKvcVatNykiV7Rg7UUaqvKVc5FZic=; b=s2LL2ZXSOX6F4bXPGexisBmZPJ3k8Sr3e2Gqakl2QDk6oLoCWFs0Lyz8HkaXWJKf2j Mqbj4hU78NgTTfNsqWu077fQ0q5Wp7ckx/mT3xZ9pwrJGvbuuQfbC/SNkSa7PtnMZqFW mi+8LktY6V8Po1h0Pfv/mr32NpayXt3PPNSW5QV23lA+guszeatWXfb0mi6QgYqUOCr6 Otgjcn7qGKGIYftbcbTGX7d4utKgGpRH92gliwKPEeM0QBKbI94fTvUnGm/BOvHlC3Ge iqYLNX4YtxNSNlYd09NbI6mgLiBiWz2QiqNZ6CKxyjaXZoqVVsyU0pTLqljudyI2x6ku 8iBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=GJs+vUPbnbBqVHsKvcVatNykiV7Rg7UUaqvKVc5FZic=; b=GtB116Vm5Chl+CXt4+vvdMuvCMKOhcAtaopsU196igUertqdkIQIjMNbUJU/2Jm4m7 StsjNK/FtqaUUDNP1Ne4ppSPuQZ4T9xCBcKjew//N6vtfRn4/QZ9pAbKeg7GIZBUjwQz 4N4RiI+ituHTlyGfR2Mg+R9wbklY3QlYqE9fGXtnme+3+lZAtoGnrK0mrTgLIXBoJHyK lNfo1YZSN6iwQURjph68/XpithajmIPQIBjiY3ATm2AmxLCNBl0pHv87XiKT3q2tv3YB lBM5zR94qWrirqYl6VtAbcKYb+5zsVVSSEyasFGeBKPQHcmxOt8LUJjaj0f67N2IXZUw +rww== X-Gm-Message-State: AOAM531pdwQEYifNmipY3yBC6DgLCjYgKKjmys5gHEuIRLZ7jVJEMev1 0T1KX8kzLlJRR9DJmsab8Ts= X-Google-Smtp-Source: ABdhPJxbbwiuB788sbpn/3sl2yf2mLvv4GbL7Y9t1aXNvPwMB/Q6/twkA0Icla0EvRHL1yuptkiWkQ== X-Received: by 2002:adf:94c6:: with SMTP id 64mr133352wrr.8.1602362617070; Sat, 10 Oct 2020 13:43:37 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Huacai Chen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Damien Hedde , Paul Burton , Luc Michel , Aleksandar Rikalo , Huacai Chen , Richard Henderson , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Paolo Bonzini , Aurelien Jarno , Jiaxun Yang Subject: [PATCH v3 11/20] target/mips/cpu: Allow the CPU to use dynamic frequencies Date: Sat, 10 Oct 2020 22:43:10 +0200 Message-Id: <20201010204319.3119239-12-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201010204319.3119239-1-f4bug@amsat.org> References: <20201010204319.3119239-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Use the Clock API and let the CPU object have an input clock. If no clock is connected, keep using the default frequency of 200 MHz used since the introduction of the 'r4k' machine in commit 6af0bf9c7c3. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- target/mips/cpu.h | 4 ++++ target/mips/cpu.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index baeceb892ef..062a4ba6225 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -4,6 +4,7 @@ #include "cpu-qom.h" #include "exec/cpu-defs.h" #include "fpu/softfloat-types.h" +#include "hw/clock.h" #include "mips-defs.h" =20 #define TCG_GUEST_DEFAULT_MO (0) @@ -1151,6 +1152,8 @@ struct CPUMIPSState { /** * MIPSCPU: * @env: #CPUMIPSState + * @clock: this CPU input clock (may be connected + * to an output clock from another device). * @cp0_count_rate: rate at which the coprocessor 0 counter increments * * A MIPS CPU. @@ -1160,6 +1163,7 @@ struct MIPSCPU { CPUState parent_obj; /*< public >*/ =20 + Clock *clock; CPUNegativeOffsetState neg; CPUMIPSState env; /* diff --git a/target/mips/cpu.c b/target/mips/cpu.c index 461edfe22b7..3deb0245e7c 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -27,6 +27,7 @@ #include "sysemu/kvm.h" #include "exec/exec-all.h" #include "hw/qdev-properties.h" +#include "hw/qdev-clock.h" =20 static void mips_cpu_set_pc(CPUState *cs, vaddr value) { @@ -144,8 +145,8 @@ static void mips_cp0_period_set(MIPSCPU *cpu) { CPUMIPSState *env =3D &cpu->env; =20 - env->cp0_count_ns =3D muldiv64(NANOSECONDS_PER_SECOND, cpu->cp0_count_= rate, - CPU_FREQ_HZ_DEFAULT); + env->cp0_count_ns =3D cpu->cp0_count_rate + * clock_get_ns(MIPS_CPU(cpu)->clock); } =20 static void mips_cpu_realizefn(DeviceState *dev, Error **errp) @@ -155,6 +156,10 @@ static void mips_cpu_realizefn(DeviceState *dev, Error= **errp) MIPSCPUClass *mcc =3D MIPS_CPU_GET_CLASS(dev); Error *local_err =3D NULL; =20 + if (!clock_get(cpu->clock)) { + /* Initialize the frequency in case the clock remains unconnected.= */ + clock_set_hz(cpu->clock, CPU_FREQ_HZ_DEFAULT); + } mips_cp0_period_set(cpu); =20 cpu_exec_realizefn(cs, &local_err); @@ -178,6 +183,7 @@ static void mips_cpu_initfn(Object *obj) MIPSCPUClass *mcc =3D MIPS_CPU_GET_CLASS(obj); =20 cpu_set_cpustate_pointers(cpu); + cpu->clock =3D qdev_init_clock_in(DEVICE(obj), "clk-in", NULL, cpu); env->cpu_model =3D mcc->cpu_def; } =20 --=20 2.26.2