summaryrefslogtreecommitdiff
path: root/kexec/firmware_memmap.h
blob: eac0ddbd78a510af8ee4550dc625443566caf06f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * firmware_memmap.c: Read /sys/firmware/memmap
 *
 * Created by: Bernhard Walle (bernhard.walle@gmx.de)
 * Copyright (C) SUSE LINUX Products GmbH, 2008. All rights reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation (version 2 of the License).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef FIRMWARE_MEMMAP_H
#define FIRMWARE_MEMMAP_H

#include "kexec.h"

/**
 * Reads the /sys/firmware/memmap interface, documented in
 * Documentation/ABI/testing/sysfs-firmware-memmap (kernel tree).
 *
 * The difference between /proc/iomem and /sys/firmware/memmap is that
 * /sys/firmware/memmap provides the raw memory map, provided by the
 * firmware of the system. That memory map should be passed to a kexec'd
 * kernel because the behaviour should be the same as a normal booted kernel,
 * so any limitation (e.g. by the user providing the mem command line option)
 * should not be passed to the kexec'd kernel.
 *
 * The parsing of the code is independent of the architecture. However, the
 * actual architecture-specific code might postprocess the code a bit, like
 * x86 does.
 */

/**
 * Compares two memory ranges according to their start address. This function
 * can be used with qsort() as @c compar function.
 *
 * @param[in] first a pointer to the first memory range
 * @param[in] second a pointer to the second memory range
 * @return 0 if @p first and @p second have the same start address,
 *         a value less then 0 if the start address of @p first is less than
 *         the start address of @p second, and a value greater than 0 if
 *         the opposite is in case.
 */
int compare_ranges(const void *first, const void *second);

/**
 * Checks if the kernel provides the /sys/firmware/memmap interface.
 * It makes sense to use that function in advance before calling
 * get_firmware_memmap_ranges() because the latter function prints an error
 * if it cannot open the directory. If have_sys_firmware_memmap() returns
 * false, then one can use the old /proc/iomem interface (for older kernels).
 */
int have_sys_firmware_memmap(void);

/**
 * Parses the /sys/firmware/memmap memory map.
 *
 * @param[out] range a pointer to an array of type struct memory_range with
 *             at least *range entries
 * @param[in,out] ranges a pointer to an integer that holds the number of
 *        	  entries which range contains (at least). After successful
 *        	  return, the number of actual entries will be written.
 * @return 0 on success, -1 on failure.
 */
int get_firmware_memmap_ranges(struct memory_range *range, size_t *ranges);


#endif /* FIRMWARE_MEMMAP_H */