Skip to content

Commit

Permalink
hw/arm/sbsa-ref: Force CPU generic timer to 62.5MHz
Browse files Browse the repository at this point in the history
Currently QEMU CPUs always run with a generic timer counter frequency
of 62.5MHz, but ARMv8.6 CPUs will run at 1GHz.  For older versions of
the TF-A firmware that sbsa-ref runs, the frequency of the generic
timer is hardcoded into the firmware, and so if the CPU actually has
a different frequency then timers in the guest will be set
incorrectly.

The default frequency used by the 'max' CPU is about to change, so
make the sbsa-ref board force the CPU frequency to the value which
the firmware expects.

Newer versions of TF-A will read the frequency from the CPU's
CNTFRQ_EL0 register:
 ARM-software/arm-trusted-firmware@4c77fac
so in the longer term we could make this board use the 1GHz
frequency. We will need to make sure we update the binaries used
by our avocado test
 Aarch64SbsarefMachine.test_sbsaref_alpine_linux_max_pauth_impdef
before we can do that.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
Message-id: 20240426122913.3427983-3-peter.maydell@linaro.org
  • Loading branch information
pm215 committed Apr 30, 2024
1 parent bd8e9dd commit ee4336f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hw/arm/sbsa-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@
#define NUM_SMMU_IRQS 4
#define NUM_SATA_PORTS 6

/*
* Generic timer frequency in Hz (which drives both the CPU generic timers
* and the SBSA watchdog-timer). Older versions of the TF-A firmware
* typically used with sbsa-ref (including the binaries in our Avocado test
* Aarch64SbsarefMachine.test_sbsaref_alpine_linux_max_pauth_impdef
* assume it is this value.
*
* TODO: this value is not architecturally correct for an Armv8.6 or
* better CPU, so we should move to 1GHz once the TF-A fix above has
* made it into a release and into our Avocado test.
*/
#define SBSA_GTIMER_HZ 62500000

enum {
SBSA_FLASH,
SBSA_MEM,
Expand Down Expand Up @@ -767,6 +780,8 @@ static void sbsa_ref_init(MachineState *machine)
&error_abort);
}

object_property_set_int(cpuobj, "cntfrq", SBSA_GTIMER_HZ, &error_abort);

object_property_set_link(cpuobj, "memory", OBJECT(sysmem),
&error_abort);

Expand Down

0 comments on commit ee4336f

Please sign in to comment.