/* * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) * * Authors: * Inochi Amaoto * YuQing Cai * ZhenYu Zhang <1204122531@qq.com> */ #include #include #include #include #include #include #include #include #include #include #include #include #define SOPHGO_MANGO_TIMER_BASE 0x70ac000000UL #define SOPHGO_MANGO_TIMER_OFFSET 0x10000UL extern struct sbi_platform platform; static u32 selected_hartid = -1; static bool force_emulate_time_csr; static bool mango_cold_boot_allowed(u32 hartid, const struct fdt_match *match) { if (selected_hartid != -1) return (selected_hartid == hartid); return (hartid < 64); } int mango_early_init(bool cold_boot, const struct fdt_match *match) { const struct sbi_platform * plat = sbi_platform_thishart_ptr(); /* * Sophgo mango board use seperate 16/32 timers while initiating, * merge them as a single domain to avoid wasting. */ if (cold_boot) return sbi_domain_root_add_memrange(SOPHGO_MANGO_TIMER_BASE, SOPHGO_MANGO_TIMER_OFFSET * sbi_platform_hart_count(plat), MTIMER_REGION_ALIGN, (SBI_DOMAIN_MEMREGION_MMIO | SBI_DOMAIN_MEMREGION_M_READABLE | SBI_DOMAIN_MEMREGION_M_WRITABLE)); return 0; } static int mango_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 void mango_fw_init(void *fdt, const struct fdt_match *match) { platform.hart_stack_size = 16384; if (fdt_node_offset_by_compatible(fdt, 0, "sophgo,sg2042-global-mtimer") > 0) force_emulate_time_csr = true; else force_emulate_time_csr = false; } static bool mango_force_emulate_time_csr(const struct fdt_match *match) { return force_emulate_time_csr; } static const struct fdt_match sophgo_mango_match[] = { { .compatible = "sophgo,mango" }, { }, }; const struct platform_override sophgo_mango = { .match_table = sophgo_mango_match, .fw_init = mango_fw_init, .cold_boot_allowed = mango_cold_boot_allowed, .force_emulate_time_csr = mango_force_emulate_time_csr, .early_init = mango_early_init, .extensions_init = mango_extensions_init, };