platform: generic: allwinner: add support for c9xx pmu

With the T-HEAD C9XX cores being designed before or during ratification
of the SSCOFPMF extension, they implement a PMU extension that behaves
very similar but not equal to it by providing overflow interrupts though
in a slightly different registers format.

The sun20i-d1 is using this core. So implement the necessary overrides
to allow its pmu to be used via the standard sbi-pmu extension.

For now it's also the only soc using this core, so keep the additional
code in the d1-space for now.

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
This commit is contained in:
Heiko Stuebner
2022-10-04 18:42:27 +02:00
committed by Anup Patel
parent 2f63f2465c
commit b6e520b2a8
2 changed files with 187 additions and 0 deletions

View File

@@ -5,11 +5,13 @@
*/
#include <platform_override.h>
#include <thead_c9xx.h>
#include <sbi/riscv_io.h>
#include <sbi/sbi_bitops.h>
#include <sbi/sbi_ecall_interface.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_hsm.h>
#include <sbi/sbi_pmu.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/irqchip/fdt_irqchip_plic.h>
@@ -199,6 +201,63 @@ static int sun20i_d1_final_init(bool cold_boot, const struct fdt_match *match)
return 0;
}
#include <sbi/sbi_console.h>
static void thead_c9xx_pmu_ctr_enable_irq(uint32_t ctr_idx)
{
unsigned long mip_val;
if (ctr_idx >= SBI_PMU_HW_CTR_MAX)
return;
mip_val = csr_read(CSR_MIP);
/**
* Clear out the OF bit so that next interrupt can be enabled.
* This should be done only when the corresponding overflow interrupt
* bit is cleared. That indicates that software has already handled the
* previous interrupts or the hardware yet to set an overflow interrupt.
* Otherwise, there will be race conditions where we may clear the bit
* the software is yet to handle the interrupt.
*/
if (!(mip_val & THEAD_C9XX_MIP_MOIP))
csr_clear(THEAD_C9XX_CSR_MCOUNTEROF, BIT(ctr_idx));
/**
* SSCOFPMF uses the OF bit for enabling/disabling the interrupt,
* while the C9XX has designated enable bits.
* So enable per-counter interrupt on C9xx here.
*/
csr_set(THEAD_C9XX_CSR_MCOUNTERINTEN, BIT(ctr_idx));
}
static void thead_c9xx_pmu_ctr_disable_irq(uint32_t ctr_idx)
{
csr_clear(THEAD_C9XX_CSR_MCOUNTERINTEN, BIT(ctr_idx));
}
static int thead_c9xx_pmu_irq_bit(void)
{
return THEAD_C9XX_MIP_MOIP;
}
const struct sbi_pmu_device thead_c9xx_pmu_device = {
.hw_counter_enable_irq = thead_c9xx_pmu_ctr_enable_irq,
.hw_counter_disable_irq = thead_c9xx_pmu_ctr_disable_irq,
.hw_counter_irq_bit = thead_c9xx_pmu_irq_bit,
};
static int sun20i_d1_extensions_init(const struct fdt_match *match,
struct sbi_hart_features *hfeatures)
{
sbi_pmu_set_device(&thead_c9xx_pmu_device);
/* auto-detection doesn't work on t-head c9xx cores */
hfeatures->mhpm_count = 29;
hfeatures->mhpm_bits = 64;
return 0;
}
static const struct fdt_match sun20i_d1_match[] = {
{ .compatible = "allwinner,sun20i-d1" },
{ },
@@ -207,4 +266,5 @@ static const struct fdt_match sun20i_d1_match[] = {
const struct platform_override sun20i_d1 = {
.match_table = sun20i_d1_match,
.final_init = sun20i_d1_final_init,
.extensions_init = sun20i_d1_extensions_init,
};