blob: d7d0566101fe58b937637052e7511cfd08b6d2b8 [file] [log] [blame]
Andrew Scullb401ba32018-11-09 10:30:54 +00001/*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "hf/boot_params.h"
18#include "hf/dlog.h"
19#include "hf/fdt_handler.h"
20#include "hf/layout.h"
21
22/**
23 * Default implementation assumes the FDT has been linked into the image.
24 *
25 * This can be overridden e.g. to provide a fixed address or an address passed
26 * by the loader.
27 */
28#pragma weak plat_get_fdt_addr
29paddr_t plat_get_fdt_addr(void)
30{
31 return layout_fdt_begin();
32}
33
34/**
35 * Default implementation assumes the initrd has been linked into the image.
36 *
37 * This can be overridden e.g. to provide a fixed address or an address passed
38 * by the loader.
39 */
40#pragma weak plat_get_initrd_range
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000041void plat_get_initrd_range(paddr_t *begin, paddr_t *end, struct mpool *ppool)
Andrew Scullb401ba32018-11-09 10:30:54 +000042{
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000043 (void)ppool;
44
Andrew Scullb401ba32018-11-09 10:30:54 +000045 *begin = layout_initrd_begin();
46 *end = layout_initrd_end();
47}
48
49/**
50 * Default implementation assumes the FDT address is passed to the kernel.
51 *
52 * TODO: make this part of the VM configuration as secondary VMs will also need
53 * to take arguments.
54 */
55#pragma weak plat_get_kernel_arg
56uintreg_t plat_get_kernel_arg(void)
57{
58 return (uintreg_t)pa_addr(plat_get_fdt_addr());
59}
60
61/**
62 * Default implementation extracts the boot parameters from the FDT but the
63 * initrd is provided separately.
64 */
65#pragma weak plat_get_boot_params
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000066bool plat_get_boot_params(struct boot_params *p, struct mpool *ppool)
Andrew Scullb401ba32018-11-09 10:30:54 +000067{
68 struct fdt_header *fdt;
69 struct fdt_node n;
70 bool ret = false;
71
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000072 plat_get_initrd_range(&p->initrd_begin, &p->initrd_end, ppool);
Andrew Scullb401ba32018-11-09 10:30:54 +000073 p->kernel_arg = plat_get_kernel_arg();
74
75 /* Get the memory map from the FDT. */
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000076 fdt = fdt_map(plat_get_fdt_addr(), &n, ppool);
Andrew Scullb401ba32018-11-09 10:30:54 +000077 if (!fdt) {
78 return false;
79 }
80
81 if (!fdt_find_child(&n, "")) {
82 dlog("Unable to find FDT root node.\n");
83 goto out_unmap_fdt;
84 }
85
86 p->mem_ranges_count = 0;
87 fdt_find_memory_ranges(&n, p);
88
89 ret = true;
90
91out_unmap_fdt:
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000092 if (!fdt_unmap(fdt, ppool)) {
Andrew Scullb401ba32018-11-09 10:30:54 +000093 dlog("Unable to unmap fdt.");
94 return false;
95 }
96
97 return ret;
98}
99
100/**
101 * Default implementation updates the FDT which is the argument passed to the
102 * primary VM's kernel.
103 *
104 * TODO: in future, each VM will declare whether it expects an argument passed
105 * and that will be static data e.g. it will provide its own FDT so there will
106 * be no FDT modification. This is done because each VM has a very different
107 * view of the system and we don't want to force VMs to require loader code when
108 * another loader can load the data for it.
109 */
110#pragma weak plat_update_boot_params
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +0000111bool plat_update_boot_params(struct boot_params_update *p, struct mpool *ppool)
Andrew Scullb401ba32018-11-09 10:30:54 +0000112{
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +0000113 return fdt_patch(plat_get_fdt_addr(), p, ppool);
Andrew Scullb401ba32018-11-09 10:30:54 +0000114}