2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2020, Scott Phillips <scottph@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef _SYS_DUMPSET_H_
31 #define _SYS_DUMPSET_H_
33 #include <sys/_bitset.h>
34 #include <sys/bitset.h>
36 extern struct bitset *vm_page_dump;
37 extern long vm_page_dump_pages;
38 extern vm_paddr_t dump_avail[PHYS_AVAIL_COUNT];
41 dump_add_page(vm_paddr_t pa)
47 for (i = 0; dump_avail[i + 1] != 0; i += 2) {
48 if (pa >= dump_avail[i] && pa < dump_avail[i + 1]) {
49 BIT_SET_ATOMIC(vm_page_dump_pages,
50 (pa >> PAGE_SHIFT) - (dump_avail[i] >> PAGE_SHIFT) +
54 adj += howmany(dump_avail[i + 1], PAGE_SIZE) -
55 dump_avail[i] / PAGE_SIZE;
60 dump_drop_page(vm_paddr_t pa)
66 for (i = 0; dump_avail[i + 1] != 0; i += 2) {
67 if (pa >= dump_avail[i] && pa < dump_avail[i + 1]) {
68 BIT_CLR_ATOMIC(vm_page_dump_pages,
69 (pa >> PAGE_SHIFT) - (dump_avail[i] >> PAGE_SHIFT) +
73 adj += howmany(dump_avail[i + 1], PAGE_SIZE) -
74 dump_avail[i] / PAGE_SIZE;
78 static inline vm_paddr_t
79 vm_page_dump_index_to_pa(int bit)
83 for (i = 0; dump_avail[i + 1] != 0; i += 2) {
84 tot = howmany(dump_avail[i + 1], PAGE_SIZE) -
85 dump_avail[i] / PAGE_SIZE;
87 return ((vm_paddr_t)bit * PAGE_SIZE +
88 (dump_avail[i] & ~PAGE_MASK));
91 return ((vm_paddr_t)NULL);
94 #define VM_PAGE_DUMP_FOREACH(pa) \
95 for (vm_pindex_t __b = BIT_FFS(vm_page_dump_pages, vm_page_dump); \
96 (pa) = vm_page_dump_index_to_pa(__b - 1), __b != 0; \
97 __b = BIT_FFS_AT(vm_page_dump_pages, vm_page_dump, __b))
99 #endif /* _SYS_DUMPSET_H_ */