efi.c (9938b04472d5c59f8bd8152a548533a8599596a2) efi.c (9fc68b717c24a215a32c1b4e05b30433cafb2599)
1/*
2 * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/efi.h>
10#include <asm/efi.h>
11#include <asm/mach/map.h>
12#include <asm/mmu_context.h>
13
1/*
2 * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/efi.h>
10#include <asm/efi.h>
11#include <asm/mach/map.h>
12#include <asm/mmu_context.h>
13
14static int __init set_permissions(pte_t *ptep, pgtable_t token,
15 unsigned long addr, void *data)
16{
17 efi_memory_desc_t *md = data;
18 pte_t pte = *ptep;
19
20 if (md->attribute & EFI_MEMORY_RO)
21 pte = set_pte_bit(pte, __pgprot(L_PTE_RDONLY));
22 if (md->attribute & EFI_MEMORY_XP)
23 pte = set_pte_bit(pte, __pgprot(L_PTE_XN));
24 set_pte_ext(ptep, pte, PTE_EXT_NG);
25 return 0;
26}
27
28int __init efi_set_mapping_permissions(struct mm_struct *mm,
29 efi_memory_desc_t *md)
30{
31 unsigned long base, size;
32
33 base = md->virt_addr;
34 size = md->num_pages << EFI_PAGE_SHIFT;
35
36 /*
37 * We can only use apply_to_page_range() if we can guarantee that the
38 * entire region was mapped using pages. This should be the case if the
39 * region does not cover any naturally aligned SECTION_SIZE sized
40 * blocks.
41 */
42 if (round_down(base + size, SECTION_SIZE) <
43 round_up(base, SECTION_SIZE) + SECTION_SIZE)
44 return apply_to_page_range(mm, base, size, set_permissions, md);
45
46 return 0;
47}
48
14int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
15{
16 struct map_desc desc = {
17 .virtual = md->virt_addr,
18 .pfn = __phys_to_pfn(md->phys_addr),
19 .length = md->num_pages * EFI_PAGE_SIZE,
20 };
21

--- 7 unchanged lines hidden (view full) ---

29 else if (md->attribute & EFI_MEMORY_WT)
30 desc.type = MT_MEMORY_RWX_NONCACHED;
31 else if (md->attribute & EFI_MEMORY_WC)
32 desc.type = MT_DEVICE_WC;
33 else
34 desc.type = MT_DEVICE;
35
36 create_mapping_late(mm, &desc, true);
49int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
50{
51 struct map_desc desc = {
52 .virtual = md->virt_addr,
53 .pfn = __phys_to_pfn(md->phys_addr),
54 .length = md->num_pages * EFI_PAGE_SIZE,
55 };
56

--- 7 unchanged lines hidden (view full) ---

64 else if (md->attribute & EFI_MEMORY_WT)
65 desc.type = MT_MEMORY_RWX_NONCACHED;
66 else if (md->attribute & EFI_MEMORY_WC)
67 desc.type = MT_DEVICE_WC;
68 else
69 desc.type = MT_DEVICE;
70
71 create_mapping_late(mm, &desc, true);
72
73 /*
74 * If stricter permissions were specified, apply them now.
75 */
76 if (md->attribute & (EFI_MEMORY_RO | EFI_MEMORY_XP))
77 return efi_set_mapping_permissions(mm, md);
37 return 0;
38}
78 return 0;
79}