4501652e11ab642000e4fe26dd56603234ee3c34
[platform/kernel/linux-rpi.git] / drivers / firmware / efi / libstub / arm64.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2013, 2014 Linaro Ltd;  <roy.franz@linaro.org>
4  *
5  * This file implements the EFI boot stub for the arm64 kernel.
6  * Adapted from ARM version by Mark Salter <msalter@redhat.com>
7  */
8
9
10 #include <linux/efi.h>
11 #include <asm/efi.h>
12 #include <asm/memory.h>
13 #include <asm/sysreg.h>
14
15 #include "efistub.h"
16
17 static bool system_needs_vamap(void)
18 {
19         const u8 *type1_family = efi_get_smbios_string(1, family);
20
21         /*
22          * Ampere eMAG, Altra, and Altra Max machines crash in SetTime() if
23          * SetVirtualAddressMap() has not been called prior.
24          */
25         if (!type1_family || (
26             strcmp(type1_family, "eMAG") &&
27             strcmp(type1_family, "Altra") &&
28             strcmp(type1_family, "Altra Max")))
29                 return false;
30
31         efi_warn("Working around broken SetVirtualAddressMap()\n");
32         return true;
33 }
34
35 efi_status_t check_platform_features(void)
36 {
37         u64 tg;
38
39         /*
40          * If we have 48 bits of VA space for TTBR0 mappings, we can map the
41          * UEFI runtime regions 1:1 and so calling SetVirtualAddressMap() is
42          * unnecessary.
43          */
44         if (VA_BITS_MIN >= 48 && !system_needs_vamap())
45                 efi_novamap = true;
46
47         /* UEFI mandates support for 4 KB granularity, no need to check */
48         if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
49                 return EFI_SUCCESS;
50
51         tg = (read_cpuid(ID_AA64MMFR0_EL1) >> ID_AA64MMFR0_EL1_TGRAN_SHIFT) & 0xf;
52         if (tg < ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN || tg > ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MAX) {
53                 if (IS_ENABLED(CONFIG_ARM64_64K_PAGES))
54                         efi_err("This 64 KB granular kernel is not supported by your CPU\n");
55                 else
56                         efi_err("This 16 KB granular kernel is not supported by your CPU\n");
57                 return EFI_UNSUPPORTED;
58         }
59         return EFI_SUCCESS;
60 }
61
62 void efi_cache_sync_image(unsigned long image_base,
63                           unsigned long alloc_size,
64                           unsigned long code_size)
65 {
66         u32 ctr = read_cpuid_effective_cachetype();
67         u64 lsize = 4 << cpuid_feature_extract_unsigned_field(ctr,
68                                                 CTR_EL0_DminLine_SHIFT);
69
70         do {
71                 asm("dc civac, %0" :: "r"(image_base));
72                 image_base += lsize;
73                 alloc_size -= lsize;
74         } while (alloc_size >= lsize);
75
76         asm("ic ialluis");
77         dsb(ish);
78         isb();
79 }