platform: generic: Modify platform ops instead of using hooks

Switch all existing platform overrides to use the helper pattern instead
of the platform hooks. After this commit, only the .match_table and
.init members of struct platform_override are used.

There are two minor behavioral differences:
 - For Allwinner D1, fdt_add_cpu_idle_states() is now called before the
   body of generic_final_init(). This should have no functional impact.
 - For StarFive JH7110, if the /chosen/starfive,boot-hart-id property is
   missing, the code now falls back to using generic_coldboot_harts,
   instead of accepting any hart.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20250325234342.711447-7-samuel.holland@sifive.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2025-03-25 16:43:29 -07:00
committed by Anup Patel
parent 2489e1421d
commit b353af63e2
12 changed files with 160 additions and 80 deletions

View File

@@ -13,6 +13,7 @@
#include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_ecall_interface.h>
#include <sbi/sbi_error.h> #include <sbi/sbi_error.h>
#include <sbi/sbi_hsm.h> #include <sbi/sbi_hsm.h>
#include <sbi/sbi_platform.h>
#include <sbi/sbi_pmu.h> #include <sbi/sbi_pmu.h>
#include <sbi/sbi_scratch.h> #include <sbi/sbi_scratch.h>
#include <sbi_utils/fdt/fdt_fixup.h> #include <sbi_utils/fdt/fdt_fixup.h>
@@ -165,17 +166,6 @@ static const struct sbi_hsm_device sun20i_d1_ppu = {
.hart_resume = sun20i_d1_hart_resume, .hart_resume = sun20i_d1_hart_resume,
}; };
static int sun20i_d1_final_init(bool cold_boot, void *fdt,
const struct fdt_match *match)
{
if (cold_boot) {
sun20i_d1_riscv_cfg_init();
sbi_hsm_set_device(&sun20i_d1_ppu);
}
return 0;
}
static const struct sbi_cpu_idle_state sun20i_d1_cpu_idle_states[] = { static const struct sbi_cpu_idle_state sun20i_d1_cpu_idle_states[] = {
{ {
.name = "cpu-nonretentive", .name = "cpu-nonretentive",
@@ -189,14 +179,32 @@ static const struct sbi_cpu_idle_state sun20i_d1_cpu_idle_states[] = {
{ } { }
}; };
static int sun20i_d1_fdt_fixup(void *fdt, const struct fdt_match *match) static int sun20i_d1_final_init(bool cold_boot)
{ {
return fdt_add_cpu_idle_states(fdt, sun20i_d1_cpu_idle_states); int rc;
if (cold_boot) {
void *fdt = fdt_get_address_rw();
sun20i_d1_riscv_cfg_init();
sbi_hsm_set_device(&sun20i_d1_ppu);
rc = fdt_add_cpu_idle_states(fdt, sun20i_d1_cpu_idle_states);
if (rc)
return rc;
}
return generic_final_init(cold_boot);
} }
static int sun20i_d1_extensions_init(const struct fdt_match *match, static int sun20i_d1_extensions_init(struct sbi_hart_features *hfeatures)
struct sbi_hart_features *hfeatures)
{ {
int rc;
rc = generic_extensions_init(hfeatures);
if (rc)
return rc;
thead_c9xx_register_pmu_device(); thead_c9xx_register_pmu_device();
/* auto-detection doesn't work on t-head c9xx cores */ /* auto-detection doesn't work on t-head c9xx cores */
@@ -207,6 +215,15 @@ static int sun20i_d1_extensions_init(const struct fdt_match *match,
return 0; return 0;
} }
static int sun20i_d1_platform_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
{
generic_platform_ops.final_init = sun20i_d1_final_init;
generic_platform_ops.extensions_init = sun20i_d1_extensions_init;
return 0;
}
static const struct fdt_match sun20i_d1_match[] = { static const struct fdt_match sun20i_d1_match[] = {
{ .compatible = "allwinner,sun20i-d1" }, { .compatible = "allwinner,sun20i-d1" },
{ }, { },
@@ -214,7 +231,5 @@ static const struct fdt_match sun20i_d1_match[] = {
const struct platform_override sun20i_d1 = { const struct platform_override sun20i_d1 = {
.match_table = sun20i_d1_match, .match_table = sun20i_d1_match,
.final_init = sun20i_d1_final_init, .init = sun20i_d1_platform_init,
.fdt_fixup = sun20i_d1_fdt_fixup,
.extensions_init = sun20i_d1_extensions_init,
}; };

View File

@@ -102,11 +102,23 @@ static void ae350_hsm_device_init(const void *fdt)
} }
} }
static int ae350_final_init(bool cold_boot, void *fdt, static int ae350_final_init(bool cold_boot)
const struct fdt_match *match)
{ {
if (cold_boot) if (cold_boot) {
const void *fdt = fdt_get_address();
ae350_hsm_device_init(fdt); ae350_hsm_device_init(fdt);
}
return generic_final_init(cold_boot);
}
static int ae350_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
{
generic_platform_ops.final_init = ae350_final_init;
generic_platform_ops.extensions_init = andes_pmu_extensions_init;
generic_platform_ops.pmu_init = andes_pmu_init;
generic_platform_ops.vendor_ext_provider = andes_sbi_vendor_ext_provider;
return 0; return 0;
} }
@@ -118,8 +130,5 @@ static const struct fdt_match andes_ae350_match[] = {
const struct platform_override andes_ae350 = { const struct platform_override andes_ae350 = {
.match_table = andes_ae350_match, .match_table = andes_ae350_match,
.final_init = ae350_final_init, .init = ae350_platform_init,
.extensions_init = andes_pmu_extensions_init,
.pmu_init = andes_pmu_init,
.vendor_ext_provider = andes_sbi_vendor_ext_provider,
}; };

View File

@@ -11,6 +11,7 @@
#include <sbi/sbi_error.h> #include <sbi/sbi_error.h>
#include <sbi/sbi_pmu.h> #include <sbi/sbi_pmu.h>
#include <libfdt.h> #include <libfdt.h>
#include <platform_override.h>
static void andes_hw_counter_enable_irq(uint32_t ctr_idx) static void andes_hw_counter_enable_irq(uint32_t ctr_idx)
{ {
@@ -57,10 +58,14 @@ static struct sbi_pmu_device andes_pmu = {
.hw_counter_filter_mode = andes_hw_counter_filter_mode .hw_counter_filter_mode = andes_hw_counter_filter_mode
}; };
int andes_pmu_extensions_init(const struct fdt_match *match, int andes_pmu_extensions_init(struct sbi_hart_features *hfeatures)
struct sbi_hart_features *hfeatures)
{ {
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
int rc;
rc = generic_extensions_init(hfeatures);
if (rc)
return rc;
if (!has_andes_pmu()) if (!has_andes_pmu())
return 0; return 0;
@@ -82,12 +87,12 @@ int andes_pmu_extensions_init(const struct fdt_match *match,
return 0; return 0;
} }
int andes_pmu_init(const struct fdt_match *match) int andes_pmu_init(void)
{ {
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_XANDESPMU)) if (sbi_hart_has_extension(scratch, SBI_HART_EXT_XANDESPMU))
sbi_pmu_set_device(&andes_pmu); sbi_pmu_set_device(&andes_pmu);
return 0; return generic_pmu_init();
} }

View File

@@ -38,8 +38,7 @@ static bool andes_apply_iocp_sw_workaround(void)
int andes_sbi_vendor_ext_provider(long funcid, int andes_sbi_vendor_ext_provider(long funcid,
struct sbi_trap_regs *regs, struct sbi_trap_regs *regs,
struct sbi_ecall_return *out, struct sbi_ecall_return *out)
const struct fdt_match *match)
{ {
int ret = 0; int ret = 0;

View File

@@ -8,11 +8,8 @@
#define _RISCV_ANDES_PMU_H #define _RISCV_ANDES_PMU_H
#include <sbi/sbi_hart.h> #include <sbi/sbi_hart.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/fdt/fdt_pmu.h>
int andes_pmu_init(const struct fdt_match *match); int andes_pmu_init(void);
int andes_pmu_extensions_init(const struct fdt_match *match, int andes_pmu_extensions_init(struct sbi_hart_features *hfeatures);
struct sbi_hart_features *hfeatures);
#endif /* _RISCV_ANDES_PMU_H */ #endif /* _RISCV_ANDES_PMU_H */

View File

@@ -5,11 +5,9 @@
#include <sbi/sbi_ecall.h> #include <sbi/sbi_ecall.h>
#include <sbi/sbi_trap.h> #include <sbi/sbi_trap.h>
#include <sbi_utils/fdt/fdt_helper.h>
int andes_sbi_vendor_ext_provider(long funcid, int andes_sbi_vendor_ext_provider(long funcid,
struct sbi_trap_regs *regs, struct sbi_trap_regs *regs,
struct sbi_ecall_return *out, struct sbi_ecall_return *out);
const struct fdt_match *match);
#endif /* _RISCV_ANDES_SBI_H */ #endif /* _RISCV_ANDES_SBI_H */

View File

@@ -24,24 +24,30 @@ static const struct andes_pma_region renesas_rzfive_pma_regions[] = {
}, },
}; };
static int renesas_rzfive_final_init(bool cold_boot, void *fdt, static int renesas_rzfive_final_init(bool cold_boot)
const struct fdt_match *match)
{ {
int rc; int rc;
if (cold_boot) { if (cold_boot) {
void *fdt = fdt_get_address_rw();
rc = andes_pma_setup_regions(fdt, renesas_rzfive_pma_regions, rc = andes_pma_setup_regions(fdt, renesas_rzfive_pma_regions,
array_size(renesas_rzfive_pma_regions)); array_size(renesas_rzfive_pma_regions));
if (rc) if (rc)
return rc; return rc;
} }
return 0; return generic_final_init(cold_boot);
} }
static int renesas_rzfive_early_init(bool cold_boot, const void *fdt, static int renesas_rzfive_early_init(bool cold_boot)
const struct fdt_match *match)
{ {
int rc;
rc = generic_early_init(cold_boot);
if (rc)
return rc;
/* /*
* Renesas RZ/Five RISC-V SoC has Instruction local memory and * Renesas RZ/Five RISC-V SoC has Instruction local memory and
* Data local memory (ILM & DLM) mapped between region 0x30000 * Data local memory (ILM & DLM) mapped between region 0x30000
@@ -58,6 +64,18 @@ static int renesas_rzfive_early_init(bool cold_boot, const void *fdt,
SBI_DOMAIN_MEMREGION_M_RWX); SBI_DOMAIN_MEMREGION_M_RWX);
} }
static int renesas_rzfive_platform_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
{
generic_platform_ops.early_init = renesas_rzfive_early_init;
generic_platform_ops.final_init = renesas_rzfive_final_init;
generic_platform_ops.extensions_init = andes_pmu_extensions_init;
generic_platform_ops.pmu_init = andes_pmu_init;
generic_platform_ops.vendor_ext_provider = andes_sbi_vendor_ext_provider;
return 0;
}
static const struct fdt_match renesas_rzfive_match[] = { static const struct fdt_match renesas_rzfive_match[] = {
{ .compatible = "renesas,r9a07g043f01" }, { .compatible = "renesas,r9a07g043f01" },
{ /* sentinel */ } { /* sentinel */ }
@@ -65,9 +83,5 @@ static const struct fdt_match renesas_rzfive_match[] = {
const struct platform_override renesas_rzfive = { const struct platform_override renesas_rzfive = {
.match_table = renesas_rzfive_match, .match_table = renesas_rzfive_match,
.early_init = renesas_rzfive_early_init, .init = renesas_rzfive_platform_init,
.final_init = renesas_rzfive_final_init,
.vendor_ext_provider = andes_sbi_vendor_ext_provider,
.extensions_init = andes_pmu_extensions_init,
.pmu_init = andes_pmu_init,
}; };

View File

@@ -11,7 +11,7 @@
#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/fdt/fdt_fixup.h> #include <sbi_utils/fdt/fdt_fixup.h>
static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match) static u64 sifive_fu540_tlbr_flush_limit(void)
{ {
/* /*
* The sfence.vma by virtual address does not work on * The sfence.vma by virtual address does not work on
@@ -20,6 +20,13 @@ static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match)
return 0; return 0;
} }
static int sifive_fu540_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
{
generic_platform_ops.get_tlbr_flush_limit = sifive_fu540_tlbr_flush_limit;
return 0;
}
static const struct fdt_match sifive_fu540_match[] = { static const struct fdt_match sifive_fu540_match[] = {
{ .compatible = "sifive,fu540" }, { .compatible = "sifive,fu540" },
{ .compatible = "sifive,fu540g" }, { .compatible = "sifive,fu540g" },
@@ -30,5 +37,5 @@ static const struct fdt_match sifive_fu540_match[] = {
const struct platform_override sifive_fu540 = { const struct platform_override sifive_fu540 = {
.match_table = sifive_fu540_match, .match_table = sifive_fu540_match,
.tlbr_flush_limit = sifive_fu540_tlbr_flush_limit, .init = sifive_fu540_platform_init,
}; };

View File

@@ -219,7 +219,7 @@ static const struct fdt_driver *const sifive_fu740_reset_drivers[] = {
NULL NULL
}; };
static u64 sifive_fu740_tlbr_flush_limit(const struct fdt_match *match) static u64 sifive_fu740_tlbr_flush_limit(void)
{ {
/* /*
* Needed to address CIP-1200 errata on SiFive FU740 * Needed to address CIP-1200 errata on SiFive FU740
@@ -231,18 +231,27 @@ static u64 sifive_fu740_tlbr_flush_limit(const struct fdt_match *match)
return 0; return 0;
} }
static int sifive_fu740_final_init(bool cold_boot, void *fdt, static int sifive_fu740_final_init(bool cold_boot)
const struct fdt_match *match)
{ {
int rc; int rc;
if (cold_boot) { if (cold_boot) {
const void *fdt = fdt_get_address();
rc = fdt_driver_init_one(fdt, sifive_fu740_reset_drivers); rc = fdt_driver_init_one(fdt, sifive_fu740_reset_drivers);
if (rc) if (rc)
sbi_printf("%s: failed to find da9063 for reset\n", sbi_printf("%s: failed to find da9063 for reset\n",
__func__); __func__);
} }
return generic_final_init(cold_boot);
}
static int sifive_fu740_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
{
generic_platform_ops.final_init = sifive_fu740_final_init;
generic_platform_ops.get_tlbr_flush_limit = sifive_fu740_tlbr_flush_limit;
return 0; return 0;
} }
@@ -255,6 +264,5 @@ static const struct fdt_match sifive_fu740_match[] = {
const struct platform_override sifive_fu740 = { const struct platform_override sifive_fu740 = {
.match_table = sifive_fu740_match, .match_table = sifive_fu740_match,
.tlbr_flush_limit = sifive_fu740_tlbr_flush_limit, .init = sifive_fu740_platform_init,
.final_init = sifive_fu740_final_init,
}; };

View File

@@ -21,9 +21,14 @@
#define SOPHGO_SG2042_TIMER_SIZE 0x10000UL #define SOPHGO_SG2042_TIMER_SIZE 0x10000UL
#define SOPHGO_SG2042_TIMER_NUM 16 #define SOPHGO_SG2042_TIMER_NUM 16
static int sophgo_sg2042_early_init(bool cold_boot, const void *fdt, static int sophgo_sg2042_early_init(bool cold_boot)
const struct fdt_match *match)
{ {
int rc;
rc = generic_early_init(cold_boot);
if (rc)
return rc;
thead_register_tlb_flush_trap_handler(); thead_register_tlb_flush_trap_handler();
/* /*
@@ -44,13 +49,26 @@ static int sophgo_sg2042_early_init(bool cold_boot, const void *fdt,
return 0; return 0;
} }
static int sophgo_sg2042_extensions_init(const struct fdt_match *match, static int sophgo_sg2042_extensions_init(struct sbi_hart_features *hfeatures)
struct sbi_hart_features *hfeatures)
{ {
int rc;
rc = generic_extensions_init(hfeatures);
if (rc)
return rc;
thead_c9xx_register_pmu_device(); thead_c9xx_register_pmu_device();
return 0; return 0;
} }
static int sophgo_sg2042_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
{
generic_platform_ops.early_init = sophgo_sg2042_early_init;
generic_platform_ops.extensions_init = sophgo_sg2042_extensions_init;
return 0;
}
static const struct fdt_match sophgo_sg2042_match[] = { static const struct fdt_match sophgo_sg2042_match[] = {
{ .compatible = "sophgo,sg2042" }, { .compatible = "sophgo,sg2042" },
{ }, { },
@@ -58,6 +76,5 @@ static const struct fdt_match sophgo_sg2042_match[] = {
const struct platform_override sophgo_sg2042 = { const struct platform_override sophgo_sg2042 = {
.match_table = sophgo_sg2042_match, .match_table = sophgo_sg2042_match,
.early_init = sophgo_sg2042_early_init, .init = sophgo_sg2042_platform_init,
.extensions_init = sophgo_sg2042_extensions_init,
}; };

View File

@@ -282,23 +282,23 @@ err:
return rc; return rc;
} }
static int starfive_jh7110_final_init(bool cold_boot, void *fdt, static int starfive_jh7110_final_init(bool cold_boot)
const struct fdt_match *match)
{ {
if (cold_boot) { if (cold_boot) {
const void *fdt = fdt_get_address();
fdt_driver_init_one(fdt, starfive_jh7110_reset_drivers); fdt_driver_init_one(fdt, starfive_jh7110_reset_drivers);
} }
return 0; return generic_final_init(cold_boot);
} }
static bool starfive_jh7110_cold_boot_allowed(u32 hartid, static bool starfive_jh7110_cold_boot_allowed(u32 hartid)
const struct fdt_match *match)
{ {
if (selected_hartid != -1) if (selected_hartid != -1)
return (selected_hartid == hartid); return (selected_hartid == hartid);
return true; return generic_cold_boot_allowed(hartid);
} }
static int starfive_jh7110_platform_init(const void *fdt, int nodeoff, static int starfive_jh7110_platform_init(const void *fdt, int nodeoff,
@@ -314,6 +314,9 @@ static int starfive_jh7110_platform_init(const void *fdt, int nodeoff,
selected_hartid = (u32) fdt32_to_cpu(*val); selected_hartid = (u32) fdt32_to_cpu(*val);
} }
generic_platform_ops.cold_boot_allowed = starfive_jh7110_cold_boot_allowed;
generic_platform_ops.final_init = starfive_jh7110_final_init;
return 0; return 0;
} }
@@ -325,6 +328,4 @@ static const struct fdt_match starfive_jh7110_match[] = {
const struct platform_override starfive_jh7110 = { const struct platform_override starfive_jh7110 = {
.match_table = starfive_jh7110_match, .match_table = starfive_jh7110_match,
.init = starfive_jh7110_platform_init, .init = starfive_jh7110_platform_init,
.cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
.final_init = starfive_jh7110_final_init,
}; };

View File

@@ -19,24 +19,35 @@ struct thead_generic_quirks {
u64 errata; u64 errata;
}; };
static int thead_generic_early_init(bool cold_boot, const void *fdt, static int thead_tlb_flush_early_init(bool cold_boot)
const struct fdt_match *match)
{ {
const struct thead_generic_quirks *quirks = match->data; thead_register_tlb_flush_trap_handler();
if (quirks->errata & THEAD_QUIRK_ERRATA_TLB_FLUSH) return generic_early_init(cold_boot);
thead_register_tlb_flush_trap_handler(); }
static int thead_pmu_extensions_init(struct sbi_hart_features *hfeatures)
{
int rc;
rc = generic_extensions_init(hfeatures);
if (rc)
return rc;
thead_c9xx_register_pmu_device();
return 0; return 0;
} }
static int thead_generic_extensions_init(const struct fdt_match *match, static int thead_generic_platform_init(const void *fdt, int nodeoff,
struct sbi_hart_features *hfeatures) const struct fdt_match *match)
{ {
const struct thead_generic_quirks *quirks = match->data; const struct thead_generic_quirks *quirks = match->data;
if (quirks->errata & THEAD_QUIRK_ERRATA_TLB_FLUSH)
generic_platform_ops.early_init = thead_tlb_flush_early_init;
if (quirks->errata & THEAD_QUIRK_ERRATA_THEAD_PMU) if (quirks->errata & THEAD_QUIRK_ERRATA_THEAD_PMU)
thead_c9xx_register_pmu_device(); generic_platform_ops.extensions_init = thead_pmu_extensions_init;
return 0; return 0;
} }
@@ -62,6 +73,5 @@ static const struct fdt_match thead_generic_match[] = {
const struct platform_override thead_generic = { const struct platform_override thead_generic = {
.match_table = thead_generic_match, .match_table = thead_generic_match,
.early_init = thead_generic_early_init, .init = thead_generic_platform_init,
.extensions_init = thead_generic_extensions_init,
}; };