Merge tag 'xilinx-for-v2022.07-rc1' of https://source.denx.de/u-boot/custodians/u...
[platform/kernel/u-boot.git] / board / xilinx / microblaze-generic / microblaze-generic.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2007-2018 Michal Simek
4  *
5  * Michal SIMEK <monstr@monstr.eu>
6  */
7
8 /*
9  * This is a board specific file.  It's OK to include board specific
10  * header files
11  */
12
13 #include <common.h>
14 #include <config.h>
15 #include <env.h>
16 #include <init.h>
17 #include <image.h>
18 #include <lmb.h>
19 #include <log.h>
20 #include <asm/global_data.h>
21 #include <dm/lists.h>
22 #include <fdtdec.h>
23 #include <linux/sizes.h>
24 #include "../common/board.h"
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 int dram_init_banksize(void)
29 {
30         return fdtdec_setup_memory_banksize();
31 }
32
33 int dram_init(void)
34 {
35         if (fdtdec_setup_mem_size_base() != 0)
36                 return -EINVAL;
37
38         return 0;
39 };
40
41 ulong board_get_usable_ram_top(ulong total_size)
42 {
43         phys_size_t size;
44         phys_addr_t reg;
45         struct lmb lmb;
46
47         /* found enough not-reserved memory to relocated U-Boot */
48         lmb_init(&lmb);
49         lmb_add(&lmb, gd->ram_base, gd->ram_size);
50         boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
51         size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
52         reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
53
54         if (!reg)
55                 reg = gd->ram_top - size;
56
57         return reg + size;
58 }
59
60 int board_late_init(void)
61 {
62         ulong max_size;
63         u32 status = 0;
64
65 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SYSRESET_MICROBLAZE)
66         int ret;
67
68         ret = device_bind_driver(gd->dm_root, "mb_soft_reset",
69                                  "reset_soft", NULL);
70         if (ret)
71                 printf("Warning: No reset driver: ret=%d\n", ret);
72 #endif
73
74         if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
75                 debug("Saved variables - Skipping\n");
76                 return 0;
77         }
78
79         max_size = gd->start_addr_sp - CONFIG_STACK_SIZE;
80         max_size = round_down(max_size, SZ_16M);
81
82         status |= env_set_hex("scriptaddr", max_size + SZ_2M);
83
84         status |= env_set_hex("pxefile_addr_r", max_size + SZ_1M);
85
86         status |= env_set_hex("kernel_addr_r", gd->ram_base + SZ_32M);
87
88         status |= env_set_hex("fdt_addr_r", gd->ram_base + SZ_32M - SZ_1M);
89
90         status |= env_set_hex("ramdisk_addr_r",
91                                gd->ram_base + SZ_32M + SZ_4M + SZ_2M);
92         if (IS_ENABLED(CONFIG_MTD_NOR_FLASH))
93                 status |= env_set_hex("script_offset_nor",
94                                        gd->bd->bi_flashstart +
95                                        CONFIG_BOOT_SCRIPT_OFFSET);
96         if (status)
97                 printf("%s: Saving run time variables FAILED\n", __func__);
98
99         return board_late_init_xilinx();
100 }