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];
40 /* For the common case: add/remove a page from the minidump bitset. */
41 #define dump_add_page(pa) vm_page_dump_add(vm_page_dump, pa)
42 #define dump_drop_page(pa) vm_page_dump_drop(vm_page_dump, pa)
45 vm_page_dump_add(struct bitset *bitset, vm_paddr_t pa)
51 for (i = 0; dump_avail[i + 1] != 0; i += 2) {
52 if (pa >= dump_avail[i] && pa < dump_avail[i + 1]) {
53 BIT_SET_ATOMIC(vm_page_dump_pages,
54 (pa >> PAGE_SHIFT) - (dump_avail[i] >> PAGE_SHIFT) +
58 adj += howmany(dump_avail[i + 1], PAGE_SIZE) -
59 dump_avail[i] / PAGE_SIZE;
64 vm_page_dump_drop(struct bitset *bitset, vm_paddr_t pa)
70 for (i = 0; dump_avail[i + 1] != 0; i += 2) {
71 if (pa >= dump_avail[i] && pa < dump_avail[i + 1]) {
72 BIT_CLR_ATOMIC(vm_page_dump_pages,
73 (pa >> PAGE_SHIFT) - (dump_avail[i] >> PAGE_SHIFT) +
77 adj += howmany(dump_avail[i + 1], PAGE_SIZE) -
78 dump_avail[i] / PAGE_SIZE;
82 static inline vm_paddr_t
83 vm_page_dump_index_to_pa(int bit)
87 for (i = 0; dump_avail[i + 1] != 0; i += 2) {
88 tot = howmany(dump_avail[i + 1], PAGE_SIZE) -
89 dump_avail[i] / PAGE_SIZE;
91 return ((vm_paddr_t)bit * PAGE_SIZE +
92 (dump_avail[i] & ~PAGE_MASK));
98 #define VM_PAGE_DUMP_FOREACH(bitset, pa) \
99 for (vm_pindex_t __b = BIT_FFS(vm_page_dump_pages, bitset); \
100 (pa) = vm_page_dump_index_to_pa(__b - 1), __b != 0; \
101 __b = BIT_FFS_AT(vm_page_dump_pages, bitset, __b))
103 #endif /* _SYS_DUMPSET_H_ */