xref: /openbmc/linux/arch/arm/kernel/efi.c (revision a8fe58ce)
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 
14 int __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 
22 	/*
23 	 * Order is important here: memory regions may have all of the
24 	 * bits below set (and usually do), so we check them in order of
25 	 * preference.
26 	 */
27 	if (md->attribute & EFI_MEMORY_WB)
28 		desc.type = MT_MEMORY_RWX;
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);
37 	return 0;
38 }
39