1*22ce4affSfengbojiang /*-
2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*22ce4affSfengbojiang *
4*22ce4affSfengbojiang * Copyright (c) 2014 Ian Lepore <[email protected]>
5*22ce4affSfengbojiang * All rights reserved.
6*22ce4affSfengbojiang *
7*22ce4affSfengbojiang * Redistribution and use in source and binary forms, with or without
8*22ce4affSfengbojiang * modification, are permitted provided that the following conditions
9*22ce4affSfengbojiang * are met:
10*22ce4affSfengbojiang * 1. Redistributions of source code must retain the above copyright
11*22ce4affSfengbojiang * notice, this list of conditions and the following disclaimer.
12*22ce4affSfengbojiang * 2. Redistributions in binary form must reproduce the above copyright
13*22ce4affSfengbojiang * notice, this list of conditions and the following disclaimer in the
14*22ce4affSfengbojiang * documentation and/or other materials provided with the distribution.
15*22ce4affSfengbojiang *
16*22ce4affSfengbojiang * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*22ce4affSfengbojiang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*22ce4affSfengbojiang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*22ce4affSfengbojiang * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*22ce4affSfengbojiang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*22ce4affSfengbojiang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*22ce4affSfengbojiang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*22ce4affSfengbojiang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*22ce4affSfengbojiang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*22ce4affSfengbojiang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*22ce4affSfengbojiang * SUCH DAMAGE.
27*22ce4affSfengbojiang *
28*22ce4affSfengbojiang * $FreeBSD$
29*22ce4affSfengbojiang */
30*22ce4affSfengbojiang
31*22ce4affSfengbojiang #ifndef _SYS_PHYSMEM_H_
32*22ce4affSfengbojiang #define _SYS_PHYSMEM_H_
33*22ce4affSfengbojiang
34*22ce4affSfengbojiang /*
35*22ce4affSfengbojiang * Routines to help configure physical ram.
36*22ce4affSfengbojiang *
37*22ce4affSfengbojiang * Multiple regions of contiguous physical ram can be added (in any order).
38*22ce4affSfengbojiang *
39*22ce4affSfengbojiang * Multiple regions of physical ram that should be excluded from crash dumps, or
40*22ce4affSfengbojiang * memory allocation, or both, can be added (in any order).
41*22ce4affSfengbojiang *
42*22ce4affSfengbojiang * After all early kernel init is done and it's time to configure all
43*22ce4affSfengbojiang * remainining non-excluded physical ram for use by other parts of the kernel,
44*22ce4affSfengbojiang * physmem_init_kernel_globals() processes the hardware regions and
45*22ce4affSfengbojiang * exclusion regions to generate the global dump_avail and phys_avail arrays
46*22ce4affSfengbojiang * that communicate physical ram configuration to other parts of the kernel.
47*22ce4affSfengbojiang */
48*22ce4affSfengbojiang
49*22ce4affSfengbojiang #define EXFLAG_NODUMP 0x01
50*22ce4affSfengbojiang #define EXFLAG_NOALLOC 0x02
51*22ce4affSfengbojiang
52*22ce4affSfengbojiang void physmem_hardware_region(uint64_t pa, uint64_t sz);
53*22ce4affSfengbojiang void physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t flags);
54*22ce4affSfengbojiang size_t physmem_avail(vm_paddr_t *avail, size_t maxavail);
55*22ce4affSfengbojiang void physmem_init_kernel_globals(void);
56*22ce4affSfengbojiang void physmem_print_tables(void);
57*22ce4affSfengbojiang
58*22ce4affSfengbojiang /*
59*22ce4affSfengbojiang * Convenience routines for FDT.
60*22ce4affSfengbojiang */
61*22ce4affSfengbojiang
62*22ce4affSfengbojiang #ifdef FDT
63*22ce4affSfengbojiang
64*22ce4affSfengbojiang #include <machine/ofw_machdep.h>
65*22ce4affSfengbojiang
66*22ce4affSfengbojiang static inline void
physmem_hardware_regions(struct mem_region * mrptr,int mrcount)67*22ce4affSfengbojiang physmem_hardware_regions(struct mem_region * mrptr, int mrcount)
68*22ce4affSfengbojiang {
69*22ce4affSfengbojiang while (mrcount--) {
70*22ce4affSfengbojiang physmem_hardware_region(mrptr->mr_start, mrptr->mr_size);
71*22ce4affSfengbojiang ++mrptr;
72*22ce4affSfengbojiang }
73*22ce4affSfengbojiang }
74*22ce4affSfengbojiang
75*22ce4affSfengbojiang static inline void
physmem_exclude_regions(struct mem_region * mrptr,int mrcount,uint32_t exflags)76*22ce4affSfengbojiang physmem_exclude_regions(struct mem_region * mrptr, int mrcount,
77*22ce4affSfengbojiang uint32_t exflags)
78*22ce4affSfengbojiang {
79*22ce4affSfengbojiang while (mrcount--) {
80*22ce4affSfengbojiang physmem_exclude_region(mrptr->mr_start, mrptr->mr_size,
81*22ce4affSfengbojiang exflags);
82*22ce4affSfengbojiang ++mrptr;
83*22ce4affSfengbojiang }
84*22ce4affSfengbojiang }
85*22ce4affSfengbojiang
86*22ce4affSfengbojiang #endif /* FDT */
87*22ce4affSfengbojiang
88*22ce4affSfengbojiang #endif /* !_SYS_PHYSMEM_H_ */
89