platform: generic: Pass FDT to early/final_init overrides

Several of these override functions access the FDT blob. Explicitly
indicate which callbacks are allowed to modify the FDT blob by passing
the parameter as a possibly-const pointer. This also reduces code size
by deduplicating the call to fdt_get_address().

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-07-30 21:58:54 -07:00
committed by Anup Patel
parent 3f964652d9
commit 6e5db7b09c
11 changed files with 25 additions and 29 deletions

View File

@@ -187,7 +187,8 @@ 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, const struct fdt_match *match) static int sun20i_d1_final_init(bool cold_boot, void *fdt,
const struct fdt_match *match)
{ {
if (cold_boot) { if (cold_boot) {
sun20i_d1_riscv_cfg_init(); sun20i_d1_riscv_cfg_init();

View File

@@ -88,12 +88,9 @@ static const struct sbi_hsm_device andes_smu = {
.hart_stop = ae350_hart_stop, .hart_stop = ae350_hart_stop,
}; };
static void ae350_hsm_device_init(void) static void ae350_hsm_device_init(const void *fdt)
{ {
int rc; int rc;
void *fdt;
fdt = fdt_get_address();
rc = fdt_parse_compat_addr(fdt, (uint64_t *)&smu.addr, rc = fdt_parse_compat_addr(fdt, (uint64_t *)&smu.addr,
"andestech,atcsmu"); "andestech,atcsmu");
@@ -103,10 +100,11 @@ static void ae350_hsm_device_init(void)
} }
} }
static int ae350_final_init(bool cold_boot, const struct fdt_match *match) static int ae350_final_init(bool cold_boot, void *fdt,
const struct fdt_match *match)
{ {
if (cold_boot) if (cold_boot)
ae350_hsm_device_init(); ae350_hsm_device_init(fdt);
return 0; return 0;
} }

View File

@@ -311,13 +311,13 @@ static int andes_fdt_reserved_memory_fixup(void *fdt,
return andes_fdt_pma_resv(fdt, pma, entry, parent); return andes_fdt_pma_resv(fdt, pma, entry, parent);
} }
int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, int andes_pma_setup_regions(void *fdt,
const struct andes_pma_region *pma_regions,
unsigned int pma_regions_count) unsigned int pma_regions_count)
{ {
unsigned int dt_populate_cnt; unsigned int dt_populate_cnt;
unsigned int i, j; unsigned int i, j;
unsigned long pa; unsigned long pa;
void *fdt;
int ret; int ret;
if (!pma_regions || !pma_regions_count) if (!pma_regions || !pma_regions_count)
@@ -342,8 +342,6 @@ int andes_pma_setup_regions(const struct andes_pma_region *pma_regions,
if (!dt_populate_cnt) if (!dt_populate_cnt)
return 0; return 0;
fdt = fdt_get_address();
ret = fdt_open_into(fdt, fdt, ret = fdt_open_into(fdt, fdt,
fdt_totalsize(fdt) + (64 * dt_populate_cnt)); fdt_totalsize(fdt) + (64 * dt_populate_cnt));
if (ret < 0) if (ret < 0)

View File

@@ -48,7 +48,8 @@ struct andes_pma_region {
bool dma_default; bool dma_default;
}; };
int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, int andes_pma_setup_regions(void *fdt,
const struct andes_pma_region *pma_regions,
unsigned int pma_regions_count); unsigned int pma_regions_count);
/** /**

View File

@@ -21,8 +21,8 @@ struct platform_override {
u64 (*tlbr_flush_limit)(const struct fdt_match *match); u64 (*tlbr_flush_limit)(const struct fdt_match *match);
u32 (*tlb_num_entries)(const struct fdt_match *match); u32 (*tlb_num_entries)(const struct fdt_match *match);
bool (*cold_boot_allowed)(u32 hartid, const struct fdt_match *match); bool (*cold_boot_allowed)(u32 hartid, const struct fdt_match *match);
int (*early_init)(bool cold_boot, const struct fdt_match *match); int (*early_init)(bool cold_boot, const void *fdt, const struct fdt_match *match);
int (*final_init)(bool cold_boot, const struct fdt_match *match); int (*final_init)(bool cold_boot, void *fdt, const struct fdt_match *match);
void (*early_exit)(const struct fdt_match *match); void (*early_exit)(const struct fdt_match *match);
void (*final_exit)(const struct fdt_match *match); void (*final_exit)(const struct fdt_match *match);
int (*fdt_fixup)(void *fdt, const struct fdt_match *match); int (*fdt_fixup)(void *fdt, const struct fdt_match *match);

View File

@@ -221,6 +221,7 @@ static int generic_nascent_init(void)
static int generic_early_init(bool cold_boot) static int generic_early_init(bool cold_boot)
{ {
const void *fdt = fdt_get_address();
int rc; int rc;
if (cold_boot) { if (cold_boot) {
@@ -237,16 +238,16 @@ static int generic_early_init(bool cold_boot)
if (!generic_plat || !generic_plat->early_init) if (!generic_plat || !generic_plat->early_init)
return 0; return 0;
return generic_plat->early_init(cold_boot, generic_plat_match); return generic_plat->early_init(cold_boot, fdt, generic_plat_match);
} }
static int generic_final_init(bool cold_boot) static int generic_final_init(bool cold_boot)
{ {
void *fdt; void *fdt = fdt_get_address();
int rc; int rc;
if (generic_plat && generic_plat->final_init) { if (generic_plat && generic_plat->final_init) {
rc = generic_plat->final_init(cold_boot, generic_plat_match); rc = generic_plat->final_init(cold_boot, fdt, generic_plat_match);
if (rc) if (rc)
return rc; return rc;
} }
@@ -254,8 +255,6 @@ static int generic_final_init(bool cold_boot)
if (!cold_boot) if (!cold_boot)
return 0; return 0;
fdt = fdt_get_address();
fdt_cpu_fixup(fdt); fdt_cpu_fixup(fdt);
fdt_fixups(fdt); fdt_fixups(fdt);
fdt_domain_fixup(fdt); fdt_domain_fixup(fdt);

View File

@@ -24,13 +24,15 @@ static const struct andes_pma_region renesas_rzfive_pma_regions[] = {
}, },
}; };
static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *match) static int renesas_rzfive_final_init(bool cold_boot, void *fdt,
const struct fdt_match *match)
{ {
return andes_pma_setup_regions(renesas_rzfive_pma_regions, return andes_pma_setup_regions(fdt, renesas_rzfive_pma_regions,
array_size(renesas_rzfive_pma_regions)); array_size(renesas_rzfive_pma_regions));
} }
static int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match) static int renesas_rzfive_early_init(bool cold_boot, const void *fdt,
const struct fdt_match *match)
{ {
/* /*
* Renesas RZ/Five RISC-V SoC has Instruction local memory and * Renesas RZ/Five RISC-V SoC has Instruction local memory and

View File

@@ -226,11 +226,10 @@ 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, static int sifive_fu740_final_init(bool cold_boot, void *fdt,
const struct fdt_match *match) const struct fdt_match *match)
{ {
int rc; int rc;
void *fdt = fdt_get_address();
if (cold_boot) { if (cold_boot) {
rc = fdt_reset_driver_init(fdt, &fdt_reset_da9063); rc = fdt_reset_driver_init(fdt, &fdt_reset_da9063);

View File

@@ -21,7 +21,7 @@
#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, static int sophgo_sg2042_early_init(bool cold_boot, const void *fdt,
const struct fdt_match *match) const struct fdt_match *match)
{ {
thead_register_tlb_flush_trap_handler(); thead_register_tlb_flush_trap_handler();

View File

@@ -277,11 +277,9 @@ err:
return rc; return rc;
} }
static int starfive_jh7110_final_init(bool cold_boot, static int starfive_jh7110_final_init(bool cold_boot, void *fdt,
const struct fdt_match *match) const struct fdt_match *match)
{ {
void *fdt = fdt_get_address();
if (cold_boot) { if (cold_boot) {
fdt_reset_driver_init(fdt, &fdt_reset_pmic); fdt_reset_driver_init(fdt, &fdt_reset_pmic);
} }

View File

@@ -19,7 +19,7 @@ struct thead_generic_quirks {
u64 errata; u64 errata;
}; };
static int thead_generic_early_init(bool cold_boot, static int thead_generic_early_init(bool cold_boot, const void *fdt,
const struct fdt_match *match) const struct fdt_match *match)
{ {
struct thead_generic_quirks *quirks = (void *)match->data; struct thead_generic_quirks *quirks = (void *)match->data;