~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/kernel/efi.c

Version: ~ [ linux-6.3-rc3 ] ~ [ linux-6.2.7 ] ~ [ linux-6.1.20 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.103 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.175 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.237 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.278 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.310 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
  4  */
  5 
  6 #include <linux/efi.h>
  7 #include <asm/efi.h>
  8 #include <asm/mach/map.h>
  9 #include <asm/mmu_context.h>
 10 
 11 static int __init set_permissions(pte_t *ptep, unsigned long addr, void *data)
 12 {
 13         efi_memory_desc_t *md = data;
 14         pte_t pte = *ptep;
 15 
 16         if (md->attribute & EFI_MEMORY_RO)
 17                 pte = set_pte_bit(pte, __pgprot(L_PTE_RDONLY));
 18         if (md->attribute & EFI_MEMORY_XP)
 19                 pte = set_pte_bit(pte, __pgprot(L_PTE_XN));
 20         set_pte_ext(ptep, pte, PTE_EXT_NG);
 21         return 0;
 22 }
 23 
 24 int __init efi_set_mapping_permissions(struct mm_struct *mm,
 25                                        efi_memory_desc_t *md)
 26 {
 27         unsigned long base, size;
 28 
 29         base = md->virt_addr;
 30         size = md->num_pages << EFI_PAGE_SHIFT;
 31 
 32         /*
 33          * We can only use apply_to_page_range() if we can guarantee that the
 34          * entire region was mapped using pages. This should be the case if the
 35          * region does not cover any naturally aligned SECTION_SIZE sized
 36          * blocks.
 37          */
 38         if (round_down(base + size, SECTION_SIZE) <
 39             round_up(base, SECTION_SIZE) + SECTION_SIZE)
 40                 return apply_to_page_range(mm, base, size, set_permissions, md);
 41 
 42         return 0;
 43 }
 44 
 45 int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
 46 {
 47         struct map_desc desc = {
 48                 .virtual        = md->virt_addr,
 49                 .pfn            = __phys_to_pfn(md->phys_addr),
 50                 .length         = md->num_pages * EFI_PAGE_SIZE,
 51         };
 52 
 53         /*
 54          * Order is important here: memory regions may have all of the
 55          * bits below set (and usually do), so we check them in order of
 56          * preference.
 57          */
 58         if (md->attribute & EFI_MEMORY_WB)
 59                 desc.type = MT_MEMORY_RWX;
 60         else if (md->attribute & EFI_MEMORY_WT)
 61                 desc.type = MT_MEMORY_RWX_NONCACHED;
 62         else if (md->attribute & EFI_MEMORY_WC)
 63                 desc.type = MT_DEVICE_WC;
 64         else
 65                 desc.type = MT_DEVICE;
 66 
 67         create_mapping_late(mm, &desc, true);
 68 
 69         /*
 70          * If stricter permissions were specified, apply them now.
 71          */
 72         if (md->attribute & (EFI_MEMORY_RO | EFI_MEMORY_XP))
 73                 return efi_set_mapping_permissions(mm, md);
 74         return 0;
 75 }
 76 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp