Files
opensbi/platform/generic/sophgo/sg2042.c
T
Xiang W 4e79fd7de5 platform: generic: sophgo: Move SG2042 timer memregion workaround
Commit 4813a20420 ("lib: sbi_init: Call hart init and timer init
before platform early init") reordered the cold/warm boot sequence so
that sbi_timer_init() runs before sbi_platform_early_init().

The SG2042 platform workaround that merges the 16 separate timer
regions into a single domain memregion was previously performed in
early_init().  After the reordering the MTIMER driver therefore adds
the individual regions first, defeating the purpose of the combined
region (and wasting PMP entries).

Move the addition of the combined memregion into extensions_init(),
which is invoked from sbi_hart_init() and consequently still executes
before sbi_timer_init().

Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260721150844.741606-1-wangxiang@iscas.ac.cn
Signed-off-by: Anup Patel <anup@brainfault.org>
2026-08-20 20:46:25 +05:30

83 lines
1.8 KiB
C

/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Authors:
* Inochi Amaoto <inochiama@outlook.com>
*
*/
#include <platform_override.h>
#include <thead/c9xx_errata.h>
#include <thead/c9xx_pmu.h>
#include <sbi/sbi_const.h>
#include <sbi/sbi_domain.h>
#include <sbi/sbi_platform.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_string.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/timer/aclint_mtimer.h>
#define SOPHGO_SG2042_TIMER_BASE 0x70ac000000ULL
#define SOPHGO_SG2042_TIMER_SIZE 0x10000UL
#define SOPHGO_SG2042_TIMER_NUM 16
static int sophgo_sg2042_early_init(bool cold_boot)
{
int rc;
rc = generic_early_init(cold_boot);
if (rc)
return rc;
thead_register_tlb_flush_trap_handler();
return 0;
}
static int sophgo_sg2042_extensions_init(bool cold_boot)
{
int rc;
rc = generic_extensions_init(cold_boot);
if (rc)
return rc;
/*
* SG2042 has 16 separate timers. Add one combined region before the
* MTIMER driver adds the individual regions.
*/
if (cold_boot) {
rc = sbi_domain_root_add_memrange(
(ulong)SOPHGO_SG2042_TIMER_BASE,
SOPHGO_SG2042_TIMER_SIZE *
SOPHGO_SG2042_TIMER_NUM,
MTIMER_REGION_ALIGN,
(SBI_DOMAIN_MEMREGION_MMIO |
SBI_DOMAIN_MEMREGION_M_READABLE |
SBI_DOMAIN_MEMREGION_M_WRITABLE));
if (rc)
return rc;
}
thead_c9xx_register_pmu_device();
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[] = {
{ .compatible = "sophgo,sg2042" },
{ },
};
const struct fdt_driver sophgo_sg2042 = {
.match_table = sophgo_sg2042_match,
.init = sophgo_sg2042_platform_init,
};