License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-03-01 03:30:39 +07:00
|
|
|
/*
|
|
|
|
* Common EFI memory map functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "efi: " fmt
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <asm/early_ioremap.h>
|
2017-01-05 19:51:29 +07:00
|
|
|
#include <linux/memblock.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
static phys_addr_t __init __efi_memmap_alloc_early(unsigned long size)
|
|
|
|
{
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 05:09:57 +07:00
|
|
|
return memblock_phys_alloc(size, SMP_CACHE_BYTES);
|
2017-01-05 19:51:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static phys_addr_t __init __efi_memmap_alloc_late(unsigned long size)
|
|
|
|
{
|
|
|
|
unsigned int order = get_order(size);
|
|
|
|
struct page *p = alloc_pages(GFP_KERNEL, order);
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return PFN_PHYS(page_to_pfn(p));
|
|
|
|
}
|
|
|
|
|
2020-01-14 00:22:45 +07:00
|
|
|
void __init __efi_memmap_free(u64 phys, unsigned long size, unsigned long flags)
|
2020-01-14 00:22:44 +07:00
|
|
|
{
|
|
|
|
if (flags & EFI_MEMMAP_MEMBLOCK) {
|
|
|
|
if (slab_is_available())
|
|
|
|
memblock_free_late(phys, size);
|
|
|
|
else
|
|
|
|
memblock_free(phys, size);
|
|
|
|
} else if (flags & EFI_MEMMAP_SLAB) {
|
|
|
|
struct page *p = pfn_to_page(PHYS_PFN(phys));
|
|
|
|
unsigned int order = get_order(size);
|
|
|
|
|
|
|
|
free_pages((unsigned long) page_address(p), order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init efi_memmap_free(void)
|
|
|
|
{
|
|
|
|
__efi_memmap_free(efi.memmap.phys_map,
|
|
|
|
efi.memmap.desc_size * efi.memmap.nr_map,
|
|
|
|
efi.memmap.flags);
|
|
|
|
}
|
|
|
|
|
2017-01-05 19:51:29 +07:00
|
|
|
/**
|
|
|
|
* efi_memmap_alloc - Allocate memory for the EFI memory map
|
|
|
|
* @num_entries: Number of entries in the allocated map.
|
2020-01-14 00:22:43 +07:00
|
|
|
* @data: efi memmap installation parameters
|
2017-01-05 19:51:29 +07:00
|
|
|
*
|
|
|
|
* Depending on whether mm_init() has already been invoked or not,
|
|
|
|
* either memblock or "normal" page allocation is used.
|
|
|
|
*
|
|
|
|
* Returns the physical address of the allocated memory map on
|
|
|
|
* success, zero on failure.
|
|
|
|
*/
|
2020-01-14 00:22:43 +07:00
|
|
|
int __init efi_memmap_alloc(unsigned int num_entries,
|
|
|
|
struct efi_memory_map_data *data)
|
2017-01-05 19:51:29 +07:00
|
|
|
{
|
2020-01-14 00:22:43 +07:00
|
|
|
/* Expect allocation parameters are zero initialized */
|
|
|
|
WARN_ON(data->phys_map || data->size);
|
|
|
|
|
|
|
|
data->size = num_entries * efi.memmap.desc_size;
|
|
|
|
data->desc_version = efi.memmap.desc_version;
|
|
|
|
data->desc_size = efi.memmap.desc_size;
|
|
|
|
data->flags &= ~(EFI_MEMMAP_SLAB | EFI_MEMMAP_MEMBLOCK);
|
|
|
|
data->flags |= efi.memmap.flags & EFI_MEMMAP_LATE;
|
|
|
|
|
|
|
|
if (slab_is_available()) {
|
|
|
|
data->flags |= EFI_MEMMAP_SLAB;
|
|
|
|
data->phys_map = __efi_memmap_alloc_late(data->size);
|
|
|
|
} else {
|
|
|
|
data->flags |= EFI_MEMMAP_MEMBLOCK;
|
|
|
|
data->phys_map = __efi_memmap_alloc_early(data->size);
|
|
|
|
}
|
2017-01-05 19:51:29 +07:00
|
|
|
|
2020-01-14 00:22:43 +07:00
|
|
|
if (!data->phys_map)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
2017-01-05 19:51:29 +07:00
|
|
|
}
|
2016-03-01 03:30:39 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* __efi_memmap_init - Common code for mapping the EFI memory map
|
|
|
|
* @data: EFI memory map data
|
|
|
|
*
|
|
|
|
* This function takes care of figuring out which function to use to
|
|
|
|
* map the EFI memory map in efi.memmap based on how far into the boot
|
|
|
|
* we are.
|
|
|
|
*
|
2020-01-14 00:22:42 +07:00
|
|
|
* During bootup EFI_MEMMAP_LATE in data->flags should be clear since we
|
|
|
|
* only have access to the early_memremap*() functions as the vmalloc
|
|
|
|
* space isn't setup. Once the kernel is fully booted we can fallback
|
|
|
|
* to the more robust memremap*() API.
|
2016-03-01 03:30:39 +07:00
|
|
|
*
|
|
|
|
* Returns zero on success, a negative error code on failure.
|
|
|
|
*/
|
2020-01-14 00:22:43 +07:00
|
|
|
static int __init __efi_memmap_init(struct efi_memory_map_data *data)
|
2016-03-01 03:30:39 +07:00
|
|
|
{
|
|
|
|
struct efi_memory_map map;
|
|
|
|
phys_addr_t phys_map;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_PARAVIRT))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
phys_map = data->phys_map;
|
|
|
|
|
2020-01-14 00:22:42 +07:00
|
|
|
if (data->flags & EFI_MEMMAP_LATE)
|
2016-03-01 03:30:39 +07:00
|
|
|
map.map = memremap(phys_map, data->size, MEMREMAP_WB);
|
|
|
|
else
|
|
|
|
map.map = early_memremap(phys_map, data->size);
|
|
|
|
|
|
|
|
if (!map.map) {
|
|
|
|
pr_err("Could not map the memory map!\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-01-14 00:22:44 +07:00
|
|
|
/* NOP if data->flags & (EFI_MEMMAP_MEMBLOCK | EFI_MEMMAP_SLAB) == 0 */
|
|
|
|
efi_memmap_free();
|
|
|
|
|
2016-03-01 03:30:39 +07:00
|
|
|
map.phys_map = data->phys_map;
|
|
|
|
map.nr_map = data->size / data->desc_size;
|
|
|
|
map.map_end = map.map + data->size;
|
|
|
|
|
|
|
|
map.desc_version = data->desc_version;
|
|
|
|
map.desc_size = data->desc_size;
|
2020-01-14 00:22:42 +07:00
|
|
|
map.flags = data->flags;
|
2016-03-01 03:30:39 +07:00
|
|
|
|
|
|
|
set_bit(EFI_MEMMAP, &efi.flags);
|
|
|
|
|
|
|
|
efi.memmap = map;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* efi_memmap_init_early - Map the EFI memory map data structure
|
|
|
|
* @data: EFI memory map data
|
|
|
|
*
|
|
|
|
* Use early_memremap() to map the passed in EFI memory map and assign
|
|
|
|
* it to efi.memmap.
|
|
|
|
*/
|
|
|
|
int __init efi_memmap_init_early(struct efi_memory_map_data *data)
|
|
|
|
{
|
|
|
|
/* Cannot go backwards */
|
2020-01-14 00:22:42 +07:00
|
|
|
WARN_ON(efi.memmap.flags & EFI_MEMMAP_LATE);
|
2016-03-01 03:30:39 +07:00
|
|
|
|
2020-01-14 00:22:42 +07:00
|
|
|
data->flags = 0;
|
|
|
|
return __efi_memmap_init(data);
|
2016-03-01 03:30:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init efi_memmap_unmap(void)
|
|
|
|
{
|
2018-11-15 00:55:41 +07:00
|
|
|
if (!efi_enabled(EFI_MEMMAP))
|
|
|
|
return;
|
|
|
|
|
2020-01-14 00:22:42 +07:00
|
|
|
if (!(efi.memmap.flags & EFI_MEMMAP_LATE)) {
|
2016-03-01 03:30:39 +07:00
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
size = efi.memmap.desc_size * efi.memmap.nr_map;
|
|
|
|
early_memunmap(efi.memmap.map, size);
|
|
|
|
} else {
|
|
|
|
memunmap(efi.memmap.map);
|
|
|
|
}
|
|
|
|
|
|
|
|
efi.memmap.map = NULL;
|
|
|
|
clear_bit(EFI_MEMMAP, &efi.flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* efi_memmap_init_late - Map efi.memmap with memremap()
|
|
|
|
* @phys_addr: Physical address of the new EFI memory map
|
|
|
|
* @size: Size in bytes of the new EFI memory map
|
|
|
|
*
|
|
|
|
* Setup a mapping of the EFI memory map using ioremap_cache(). This
|
|
|
|
* function should only be called once the vmalloc space has been
|
|
|
|
* setup and is therefore not suitable for calling during early EFI
|
|
|
|
* initialise, e.g. in efi_init(). Additionally, it expects
|
|
|
|
* efi_memmap_init_early() to have already been called.
|
|
|
|
*
|
|
|
|
* The reason there are two EFI memmap initialisation
|
|
|
|
* (efi_memmap_init_early() and this late version) is because the
|
|
|
|
* early EFI memmap should be explicitly unmapped once EFI
|
|
|
|
* initialisation is complete as the fixmap space used to map the EFI
|
|
|
|
* memmap (via early_memremap()) is a scarce resource.
|
|
|
|
*
|
|
|
|
* This late mapping is intended to persist for the duration of
|
|
|
|
* runtime so that things like efi_mem_desc_lookup() and
|
|
|
|
* efi_mem_attributes() always work.
|
|
|
|
*
|
|
|
|
* Returns zero on success, a negative error code on failure.
|
|
|
|
*/
|
|
|
|
int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size)
|
|
|
|
{
|
|
|
|
struct efi_memory_map_data data = {
|
|
|
|
.phys_map = addr,
|
|
|
|
.size = size,
|
2020-01-14 00:22:42 +07:00
|
|
|
.flags = EFI_MEMMAP_LATE,
|
2016-03-01 03:30:39 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Did we forget to unmap the early EFI memmap? */
|
|
|
|
WARN_ON(efi.memmap.map);
|
|
|
|
|
|
|
|
/* Were we already called? */
|
2020-01-14 00:22:42 +07:00
|
|
|
WARN_ON(efi.memmap.flags & EFI_MEMMAP_LATE);
|
2016-03-01 03:30:39 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It makes no sense to allow callers to register different
|
|
|
|
* values for the following fields. Copy them out of the
|
|
|
|
* existing early EFI memmap.
|
|
|
|
*/
|
|
|
|
data.desc_version = efi.memmap.desc_version;
|
|
|
|
data.desc_size = efi.memmap.desc_size;
|
|
|
|
|
2020-01-14 00:22:42 +07:00
|
|
|
return __efi_memmap_init(&data);
|
2016-03-01 03:30:39 +07:00
|
|
|
}
|
|
|
|
|
2016-06-22 22:54:00 +07:00
|
|
|
/**
|
|
|
|
* efi_memmap_install - Install a new EFI memory map in efi.memmap
|
2020-01-14 00:22:43 +07:00
|
|
|
* @ctx: map allocation parameters (address, size, flags)
|
2016-06-22 22:54:00 +07:00
|
|
|
*
|
|
|
|
* Unlike efi_memmap_init_*(), this function does not allow the caller
|
|
|
|
* to switch from early to late mappings. It simply uses the existing
|
|
|
|
* mapping function and installs the new memmap.
|
|
|
|
*
|
|
|
|
* Returns zero on success, a negative error code on failure.
|
|
|
|
*/
|
2020-01-14 00:22:43 +07:00
|
|
|
int __init efi_memmap_install(struct efi_memory_map_data *data)
|
2016-06-22 22:54:00 +07:00
|
|
|
{
|
|
|
|
efi_memmap_unmap();
|
|
|
|
|
2020-01-14 00:22:43 +07:00
|
|
|
return __efi_memmap_init(data);
|
2016-06-22 22:54:00 +07:00
|
|
|
}
|
|
|
|
|
2016-03-01 03:30:39 +07:00
|
|
|
/**
|
|
|
|
* efi_memmap_split_count - Count number of additional EFI memmap entries
|
|
|
|
* @md: EFI memory descriptor to split
|
|
|
|
* @range: Address range (start, end) to split around
|
|
|
|
*
|
|
|
|
* Returns the number of additional EFI memmap entries required to
|
|
|
|
* accomodate @range.
|
|
|
|
*/
|
|
|
|
int __init efi_memmap_split_count(efi_memory_desc_t *md, struct range *range)
|
|
|
|
{
|
|
|
|
u64 m_start, m_end;
|
|
|
|
u64 start, end;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
start = md->phys_addr;
|
|
|
|
end = start + (md->num_pages << EFI_PAGE_SHIFT) - 1;
|
|
|
|
|
|
|
|
/* modifying range */
|
|
|
|
m_start = range->start;
|
|
|
|
m_end = range->end;
|
|
|
|
|
|
|
|
if (m_start <= start) {
|
|
|
|
/* split into 2 parts */
|
|
|
|
if (start < m_end && m_end < end)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start < m_start && m_start < end) {
|
|
|
|
/* split into 3 parts */
|
|
|
|
if (m_end < end)
|
|
|
|
count += 2;
|
|
|
|
/* split into 2 parts */
|
|
|
|
if (end <= m_end)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* efi_memmap_insert - Insert a memory region in an EFI memmap
|
|
|
|
* @old_memmap: The existing EFI memory map structure
|
|
|
|
* @buf: Address of buffer to store new map
|
|
|
|
* @mem: Memory map entry to insert
|
|
|
|
*
|
|
|
|
* It is suggested that you call efi_memmap_split_count() first
|
|
|
|
* to see how large @buf needs to be.
|
|
|
|
*/
|
|
|
|
void __init efi_memmap_insert(struct efi_memory_map *old_memmap, void *buf,
|
|
|
|
struct efi_mem_range *mem)
|
|
|
|
{
|
|
|
|
u64 m_start, m_end, m_attr;
|
|
|
|
efi_memory_desc_t *md;
|
|
|
|
u64 start, end;
|
|
|
|
void *old, *new;
|
|
|
|
|
|
|
|
/* modifying range */
|
|
|
|
m_start = mem->range.start;
|
|
|
|
m_end = mem->range.end;
|
|
|
|
m_attr = mem->attribute;
|
|
|
|
|
2016-09-16 21:12:47 +07:00
|
|
|
/*
|
|
|
|
* The EFI memory map deals with regions in EFI_PAGE_SIZE
|
|
|
|
* units. Ensure that the region described by 'mem' is aligned
|
|
|
|
* correctly.
|
|
|
|
*/
|
|
|
|
if (!IS_ALIGNED(m_start, EFI_PAGE_SIZE) ||
|
|
|
|
!IS_ALIGNED(m_end + 1, EFI_PAGE_SIZE)) {
|
|
|
|
WARN_ON(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-01 03:30:39 +07:00
|
|
|
for (old = old_memmap->map, new = buf;
|
|
|
|
old < old_memmap->map_end;
|
|
|
|
old += old_memmap->desc_size, new += old_memmap->desc_size) {
|
|
|
|
|
|
|
|
/* copy original EFI memory descriptor */
|
|
|
|
memcpy(new, old, old_memmap->desc_size);
|
|
|
|
md = new;
|
|
|
|
start = md->phys_addr;
|
|
|
|
end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1;
|
|
|
|
|
|
|
|
if (m_start <= start && end <= m_end)
|
|
|
|
md->attribute |= m_attr;
|
|
|
|
|
|
|
|
if (m_start <= start &&
|
|
|
|
(start < m_end && m_end < end)) {
|
|
|
|
/* first part */
|
|
|
|
md->attribute |= m_attr;
|
|
|
|
md->num_pages = (m_end - md->phys_addr + 1) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
/* latter part */
|
|
|
|
new += old_memmap->desc_size;
|
|
|
|
memcpy(new, old, old_memmap->desc_size);
|
|
|
|
md = new;
|
|
|
|
md->phys_addr = m_end + 1;
|
|
|
|
md->num_pages = (end - md->phys_addr + 1) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((start < m_start && m_start < end) && m_end < end) {
|
|
|
|
/* first part */
|
|
|
|
md->num_pages = (m_start - md->phys_addr) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
/* middle part */
|
|
|
|
new += old_memmap->desc_size;
|
|
|
|
memcpy(new, old, old_memmap->desc_size);
|
|
|
|
md = new;
|
|
|
|
md->attribute |= m_attr;
|
|
|
|
md->phys_addr = m_start;
|
|
|
|
md->num_pages = (m_end - m_start + 1) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
/* last part */
|
|
|
|
new += old_memmap->desc_size;
|
|
|
|
memcpy(new, old, old_memmap->desc_size);
|
|
|
|
md = new;
|
|
|
|
md->phys_addr = m_end + 1;
|
|
|
|
md->num_pages = (end - m_end) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((start < m_start && m_start < end) &&
|
|
|
|
(end <= m_end)) {
|
|
|
|
/* first part */
|
|
|
|
md->num_pages = (m_start - md->phys_addr) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
/* latter part */
|
|
|
|
new += old_memmap->desc_size;
|
|
|
|
memcpy(new, old, old_memmap->desc_size);
|
|
|
|
md = new;
|
|
|
|
md->phys_addr = m_start;
|
|
|
|
md->num_pages = (end - md->phys_addr + 1) >>
|
|
|
|
EFI_PAGE_SHIFT;
|
|
|
|
md->attribute |= m_attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|