summaryrefslogtreecommitdiff
path: root/kern/bootmem.h
blob: 69a62115ed53466aaae67a4ede9c85013e88fff9 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (c) 2017 Richard Braun.
 *
 * 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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 *
 * This module provides memory-related services at bootstrap, before
 * paging is enabled. In particular :
 *  - zone registration
 *  - memory allocation (mainly for page tables)
 *  - boot data reservation
 */

#ifndef _KERN_BOOTMEM_H
#define _KERN_BOOTMEM_H

#include <stdbool.h>
#include <stddef.h>

#include <kern/init.h>
#include <machine/types.h>

/*
 * Helper functions available before paging is enabled.
 *
 * Any memory passed to these must also be accessible without paging.
 */
void * bootmem_memcpy(void *dest, const void *src, size_t n);
void * bootmem_memmove(void *dest, const void *src, size_t n);
void * bootmem_memset(void *s, int c, size_t n);
size_t bootmem_strlen(const char *s);

/*
 * Register a physical memory zone.
 *
 * Zones are expected to be sorted in ascending order of addresses and
 * not overlap. They are later loaded to the VM system. Set direct_mapped
 * to true if the zone is part of the direct mapping of physical memory.
 *
 * This function is called before paging is enabled.
 */
void bootmem_register_zone(unsigned int zone_index, bool direct_mapped,
                           phys_addr_t start, phys_addr_t end);

/*
 * Report reserved addresses to the bootmem module.
 *
 * The kernel is automatically reserved.
 *
 * Once all reserved ranges have been registered, the user can initialize
 * the module.
 *
 * If the range is marked temporary, it will be unregistered once
 * the boot data have been saved/consumed so that their backing
 * pages are loaded into the VM system.
 *
 * This function is called before paging is enabled.
 */
void bootmem_reserve_range(phys_addr_t start, phys_addr_t end, bool temporary);

/*
 * Initialize the early page allocator.
 *
 * This function builds a heap based on the registered zones while carefully
 * avoiding reserved data.
 *
 * This function is called before paging is enabled.
 */
void bootmem_setup(void);

/*
 * Allocate memory.
 *
 * The size of the returned region is a power-of-two, and its address is
 * aligned on that size. The region is guaranteed to be part of the direct
 * physical mapping when paging is enabled.
 *
 * This function is called before paging is enabled.
 */
void * bootmem_alloc(size_t size);

/*
 * Return the end address of the direct physical mapping.
 */
size_t bootmem_directmap_end(void);

#endif /* _KERN_BOOTMEM_H */