1261643Sian/*-
2261643Sian * Copyright (c) 2014 Ian Lepore <ian@freebsd.org>
3261643Sian * All rights reserved.
4261643Sian *
5261643Sian * Redistribution and use in source and binary forms, with or without
6261643Sian * modification, are permitted provided that the following conditions
7261643Sian * are met:
8261643Sian * 1. Redistributions of source code must retain the above copyright
9261643Sian *    notice, this list of conditions and the following disclaimer.
10261643Sian * 2. Redistributions in binary form must reproduce the above copyright
11261643Sian *    notice, this list of conditions and the following disclaimer in the
12261643Sian *    documentation and/or other materials provided with the distribution.
13261643Sian *
14261643Sian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15261643Sian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16261643Sian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17261643Sian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18261643Sian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19261643Sian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20261643Sian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21261643Sian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22261643Sian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23261643Sian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24261643Sian * SUCH DAMAGE.
25261643Sian *
26261643Sian * $FreeBSD$
27261643Sian */
28261643Sian
29261643Sian#ifndef	_MACHINE_PHYSMEM_H_
30261643Sian#define	_MACHINE_PHYSMEM_H_
31261643Sian
32261643Sian/*
33261649Sian * The physical address at which the kernel was loaded.
34261649Sian */
35261656Sianextern vm_paddr_t arm_physmem_kernaddr;
36261649Sian
37261649Sian/*
38261643Sian * Routines to help configure physical ram.
39261643Sian *
40261643Sian * Multiple regions of contiguous physical ram can be added (in any order).
41261643Sian *
42261643Sian * Multiple regions of physical ram that should be excluded from crash dumps, or
43261643Sian * memory allocation, or both, can be added (in any order).
44261643Sian *
45261643Sian * After all early kernel init is done and it's time to configure all
46261643Sian * remainining non-excluded physical ram for use by other parts of the kernel,
47261643Sian * arm_physmem_init_kernel_globals() processes the hardware regions and
48261643Sian * exclusion regions to generate the global dump_avail and phys_avail arrays
49261643Sian * that communicate physical ram configuration to other parts of the kernel.
50261643Sian */
51261643Sian
52261643Sian#define	EXFLAG_NODUMP	0x01
53261643Sian#define	EXFLAG_NOALLOC	0x02
54261643Sian
55294754Sandrewvoid arm_physmem_hardware_region(uint64_t pa, uint64_t sz);
56261656Sianvoid arm_physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t flags);
57261643Sianvoid arm_physmem_init_kernel_globals(void);
58261643Sianvoid arm_physmem_print_tables(void);
59261643Sian
60261643Sian/*
61261643Sian * Convenience routines for FDT.
62261643Sian */
63261643Sian
64261643Sian#ifdef FDT
65261643Sian
66261643Sian#include <machine/ofw_machdep.h>
67261643Sian
68290648Smmelstatic inline void
69261643Sianarm_physmem_hardware_regions(struct mem_region * mrptr, int mrcount)
70261643Sian{
71261643Sian	while (mrcount--) {
72261643Sian		arm_physmem_hardware_region(mrptr->mr_start, mrptr->mr_size);
73261643Sian		++mrptr;
74261643Sian	}
75261643Sian}
76261643Sian
77262123Sianstatic inline void
78290648Smmelarm_physmem_exclude_regions(struct mem_region * mrptr, int mrcount,
79261643Sian    uint32_t exflags)
80261643Sian{
81261643Sian	while (mrcount--) {
82290648Smmel		arm_physmem_exclude_region(mrptr->mr_start, mrptr->mr_size,
83261643Sian		    exflags);
84261643Sian		++mrptr;
85261643Sian	}
86261643Sian}
87261643Sian
88261643Sian#endif /* FDT */
89261643Sian
90261643Sian#endif
91261643Sian
92