Merge branch '2021-09-24-arm64-optimized-str-funcs' into next
[platform/kernel/u-boot.git] / common / board_r.c
index bdb0389..0cbe5f7 100644 (file)
 
 #include <common.h>
 #include <api.h>
+#include <bootstage.h>
 #include <cpu_func.h>
 #include <exports.h>
+#include <flash.h>
 #include <hang.h>
 #include <image.h>
 #include <irq_func.h>
+#include <log.h>
 #include <net.h>
+#include <asm/cache.h>
+#include <asm/global_data.h>
 #include <u-boot/crc.h>
 /* TODO: can we just include all these headers whether needed or not? */
 #if defined(CONFIG_CMD_BEDBUG)
 #include <miiphy.h>
 #endif
 #include <mmc.h>
+#include <mux.h>
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
+#include <pvblock.h>
 #include <scsi.h>
 #include <serial.h>
 #include <status_led.h>
@@ -52,6 +59,9 @@
 #include <timer.h>
 #include <trace.h>
 #include <watchdog.h>
+#ifdef CONFIG_XEN
+#include <xen.h>
+#endif
 #ifdef CONFIG_ADDR_MAP
 #include <asm/mmu.h>
 #endif
@@ -64,6 +74,9 @@
 #if defined(CONFIG_GPIO_HOG)
 #include <asm/gpio.h>
 #endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+#include <efi_loader.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -79,21 +92,8 @@ __weak int board_flash_wp_on(void)
        return 0;
 }
 
-__weak void cpu_secondary_init_r(void)
-{
-}
-
-static int initr_secondary_cpu(void)
+__weak int cpu_secondary_init_r(void)
 {
-       /*
-        * after non-volatile devices & environment is setup and cpu code have
-        * another round to deal with any initialization that might require
-        * full access to the environment or loading of some image (firmware)
-        * from a non-volatile device
-        */
-       /* TODO: maybe define this for all archs? */
-       cpu_secondary_init_r();
-
        return 0;
 }
 
@@ -114,7 +114,7 @@ static int initr_reloc(void)
        return 0;
 }
 
-#ifdef CONFIG_ARM
+#if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
 /*
  * Some of these functions are needed purely because the functions they
  * call return void. If we change them to return 0, these stubs can go away.
@@ -183,27 +183,11 @@ static int initr_reloc_global_data(void)
        return 0;
 }
 
-static int initr_serial(void)
+__weak int arch_initr_trap(void)
 {
-       serial_initialize();
        return 0;
 }
 
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
-static int initr_trap(void)
-{
-       /*
-        * Setup trap handlers
-        */
-#if defined(CONFIG_PPC)
-       trap_init(gd->relocaddr);
-#else
-       trap_init(CONFIG_SYS_SDRAM_BASE);
-#endif
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_ADDR_MAP
 static int initr_addr_map(void)
 {
@@ -213,14 +197,6 @@ static int initr_addr_map(void)
 }
 #endif
 
-#ifdef CONFIG_POST
-static int initr_post_backlog(void)
-{
-       post_output_backlog();
-       return 0;
-}
-#endif
-
 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
 static int initr_unlock_ram_in_cache(void)
 {
@@ -229,17 +205,6 @@ static int initr_unlock_ram_in_cache(void)
 }
 #endif
 
-#ifdef CONFIG_PCI
-static int initr_pci(void)
-{
-#ifndef CONFIG_DM_PCI
-       pci_init();
-#endif
-
-       return 0;
-}
-#endif
-
 static int initr_barrier(void)
 {
 #ifdef CONFIG_PPC
@@ -268,37 +233,21 @@ static int initr_malloc(void)
        return 0;
 }
 
-static int initr_console_record(void)
-{
-#if defined(CONFIG_CONSOLE_RECORD)
-       return console_record_init();
-#else
-       return 0;
-#endif
-}
-
-#ifdef CONFIG_SYS_NONCACHED_MEMORY
-static int initr_noncached(void)
-{
-       noncached_init();
-       return 0;
-}
-#endif
-
-#ifdef CONFIG_OF_LIVE
 static int initr_of_live(void)
 {
-       int ret;
+       if (CONFIG_IS_ENABLED(OF_LIVE)) {
+               int ret;
 
-       bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
-       ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root);
-       bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
-       if (ret)
-               return ret;
+               bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
+               ret = of_live_build(gd->fdt_blob,
+                                   (struct device_node **)gd_of_root_ptr());
+               bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
+               if (ret)
+                       return ret;
+       }
 
        return 0;
 }
-#endif
 
 #ifdef CONFIG_DM
 static int initr_dm(void)
@@ -311,9 +260,9 @@ static int initr_dm(void)
 #ifdef CONFIG_TIMER
        gd->timer = NULL;
 #endif
-       bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
+       bootstage_start(BOOTSTAGE_ID_ACCUM_DM_R, "dm_r");
        ret = dm_init_and_scan(false);
-       bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
+       bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_R);
        if (ret)
                return ret;
 
@@ -331,6 +280,17 @@ static int initr_dm_devices(void)
                        return ret;
        }
 
+       if (IS_ENABLED(CONFIG_MULTIPLEXER)) {
+               /*
+                * Initialize the multiplexer controls to their default state.
+                * This must be done early as other drivers may unknowingly
+                * rely on it.
+                */
+               ret = dm_mux_init();
+               if (ret)
+                       return ret;
+       }
+
        return 0;
 }
 
@@ -355,25 +315,39 @@ static int initr_announce(void)
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
 static int initr_manual_reloc_cmdtable(void)
 {
-       fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
-                      ll_entry_count(cmd_tbl_t, cmd));
+       fixup_cmdtable(ll_entry_start(struct cmd_tbl, cmd),
+                      ll_entry_count(struct cmd_tbl, cmd));
        return 0;
 }
 #endif
 
 static int initr_binman(void)
 {
+       int ret;
+
        if (!CONFIG_IS_ENABLED(BINMAN_FDT))
                return 0;
 
-       return binman_init();
+       ret = binman_init();
+       if (ret)
+               printf("binman_init failed:%d\n", ret);
+
+       return ret;
 }
 
 #if defined(CONFIG_MTD_NOR_FLASH)
+__weak int is_flash_available(void)
+{
+       return 1;
+}
+
 static int initr_flash(void)
 {
        ulong flash_size = 0;
-       bd_t *bd = gd->bd;
+       struct bd_info *bd = gd->bd;
+
+       if (!is_flash_available())
+               return 0;
 
        puts("Flash: ");
 
@@ -451,6 +425,15 @@ static int initr_mmc(void)
 }
 #endif
 
+#ifdef CONFIG_PVBLOCK
+static int initr_pvblock(void)
+{
+       puts("PVBLOCK: ");
+       pvblock_init();
+       return 0;
+}
+#endif
+
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -464,13 +447,14 @@ static int initr_mmc(void)
  */
 static int should_load_env(void)
 {
-#ifdef CONFIG_OF_CONTROL
-       return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
-#elif defined CONFIG_DELAY_ENVIRONMENT
-       return 0;
-#else
+       if (IS_ENABLED(CONFIG_OF_CONTROL))
+               return fdtdec_get_config_int(gd->fdt_blob,
+                                               "load-environment", 1);
+
+       if (IS_ENABLED(CONFIG_DELAY_ENVIRONMENT))
+               return 0;
+
        return 1;
-#endif
 }
 
 static int initr_env(void)
@@ -480,10 +464,12 @@ static int initr_env(void)
                env_relocate();
        else
                env_set_default(NULL, 0);
-#ifdef CONFIG_OF_CONTROL
-       env_set_hex("fdtcontroladdr",
-                   (unsigned long)map_to_sysmem(gd->fdt_blob));
-#endif
+
+       env_import_fdt();
+
+       if (IS_ENABLED(CONFIG_OF_CONTROL))
+               env_set_hex("fdtcontroladdr",
+                           (unsigned long)map_to_sysmem(gd->fdt_blob));
 
        /* Initialize from environment */
        image_load_addr = env_get_ulong("loadaddr", 16, image_load_addr);
@@ -503,43 +489,14 @@ static int initr_malloc_bootparams(void)
 }
 #endif
 
-static int initr_jumptable(void)
-{
-       jumptable_init();
-       return 0;
-}
-
-#if defined(CONFIG_API)
-static int initr_api(void)
-{
-       /* Initialize API */
-       api_init();
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_CMD_NET
 static int initr_ethaddr(void)
 {
-       bd_t *bd = gd->bd;
+       struct bd_info *bd = gd->bd;
 
        /* kept around for legacy kernels only ... ignore the next section */
        eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr);
-#ifdef CONFIG_HAS_ETH1
-       eth_env_get_enetaddr("eth1addr", bd->bi_enet1addr);
-#endif
-#ifdef CONFIG_HAS_ETH2
-       eth_env_get_enetaddr("eth2addr", bd->bi_enet2addr);
-#endif
-#ifdef CONFIG_HAS_ETH3
-       eth_env_get_enetaddr("eth3addr", bd->bi_enet3addr);
-#endif
-#ifdef CONFIG_HAS_ETH4
-       eth_env_get_enetaddr("eth4addr", bd->bi_enet4addr);
-#endif
-#ifdef CONFIG_HAS_ETH5
-       eth_env_get_enetaddr("eth5addr", bd->bi_enet5addr);
-#endif
+
        return 0;
 }
 #endif /* CONFIG_CMD_NET */
@@ -576,14 +533,6 @@ static int initr_scsi(void)
 }
 #endif
 
-#ifdef CONFIG_BITBANGMII
-static int initr_bbmii(void)
-{
-       bb_miiphy_init();
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_CMD_NET
 static int initr_net(void)
 {
@@ -637,15 +586,6 @@ int initr_mem(void)
 }
 #endif
 
-#ifdef CONFIG_CMD_BEDBUG
-static int initr_bedbug(void)
-{
-       bedbug_init();
-
-       return 0;
-}
-#endif
-
 static int run_main_loop(void)
 {
 #ifdef CONFIG_SANDBOX
@@ -667,7 +607,7 @@ static init_fnc_t init_sequence_r[] = {
        initr_trace,
        initr_reloc,
        /* TODO: could x86/PPC have this also perhaps? */
-#ifdef CONFIG_ARM
+#if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
        initr_caches,
        /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
         *       A temporary mapping of IFC high region is since removed,
@@ -684,16 +624,19 @@ static init_fnc_t init_sequence_r[] = {
        initr_malloc,
        log_init,
        initr_bootstage,        /* Needs malloc() but has its own timer */
-       initr_console_record,
+#if defined(CONFIG_CONSOLE_RECORD)
+       console_record_init,
+#endif
 #ifdef CONFIG_SYS_NONCACHED_MEMORY
-       initr_noncached,
+       noncached_init,
 #endif
-#ifdef CONFIG_OF_LIVE
        initr_of_live,
-#endif
 #ifdef CONFIG_DM
        initr_dm,
 #endif
+#ifdef CONFIG_ADDR_MAP
+       initr_addr_map,
+#endif
 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
        defined(CONFIG_SANDBOX)
        board_init,     /* Setup chipselects */
@@ -716,35 +659,33 @@ static init_fnc_t init_sequence_r[] = {
 #endif
        initr_dm_devices,
        stdio_init_tables,
-       initr_serial,
+       serial_initialize,
        initr_announce,
 #if CONFIG_IS_ENABLED(WDT)
        initr_watchdog,
 #endif
        INIT_FUNC_WATCHDOG_RESET
+#if defined(CONFIG_NEEDS_MANUAL_RELOC) && defined(CONFIG_BLOCK_CACHE)
+       blkcache_init,
+#endif
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
        initr_manual_reloc_cmdtable,
 #endif
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
-       initr_trap,
-#endif
-#ifdef CONFIG_ADDR_MAP
-       initr_addr_map,
-#endif
+       arch_initr_trap,
 #if defined(CONFIG_BOARD_EARLY_INIT_R)
        board_early_init_r,
 #endif
        INIT_FUNC_WATCHDOG_RESET
 #ifdef CONFIG_POST
-       initr_post_backlog,
+       post_output_backlog,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
+#if defined(CONFIG_PCI_INIT_R) && defined(CONFIG_SYS_EARLY_PCI_INIT)
        /*
         * Do early PCI configuration _before_ the flash gets initialised,
         * because PCU resources are crucial for flash access on some boards.
         */
-       initr_pci,
+       pci_init,
 #endif
 #ifdef CONFIG_ARCH_EARLY_INIT_R
        arch_early_init_r,
@@ -767,26 +708,32 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_MMC
        initr_mmc,
 #endif
+#ifdef CONFIG_XEN
+       xen_init,
+#endif
+#ifdef CONFIG_PVBLOCK
+       initr_pvblock,
+#endif
        initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
        initr_malloc_bootparams,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-       initr_secondary_cpu,
-#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
+       cpu_secondary_init_r,
+#if defined(CONFIG_ID_EEPROM)
        mac_read_from_eeprom,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
+#if defined(CONFIG_PCI_INIT_R) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
        /*
         * Do pci configuration
         */
-       initr_pci,
+       pci_init,
 #endif
        stdio_add_devices,
-       initr_jumptable,
+       jumptable_init,
 #ifdef CONFIG_API
-       initr_api,
+       api_init,
 #endif
        console_init_r,         /* fully init console as a device */
 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
@@ -825,7 +772,10 @@ static init_fnc_t init_sequence_r[] = {
        initr_scsi,
 #endif
 #ifdef CONFIG_BITBANGMII
-       initr_bbmii,
+       bb_miiphy_init,
+#endif
+#ifdef CONFIG_PCI_ENDPOINT
+       pci_ep_init,
 #endif
 #ifdef CONFIG_CMD_NET
        INIT_FUNC_WATCHDOG_RESET
@@ -848,13 +798,13 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_CMD_BEDBUG
        INIT_FUNC_WATCHDOG_RESET
-       initr_bedbug,
+       bedbug_init,
 #endif
 #if defined(CONFIG_PRAM)
        initr_mem,
 #endif
-#if defined(CONFIG_M68K) && defined(CONFIG_BLOCK_CACHE)
-       blkcache_init,
+#ifdef CONFIG_EFI_SETUP_EARLY
+       (init_fnc_t)efi_init_obj_list,
 #endif
        run_main_loop,
 };