/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2020, Scott Phillips <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice unmodified, this list of conditions, and the following10* disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#ifndef _SYS_DUMPSET_H_28#define _SYS_DUMPSET_H_2930#include <sys/_bitset.h>31#include <sys/bitset.h>3233extern struct bitset *vm_page_dump;34extern long vm_page_dump_pages;35extern vm_paddr_t dump_avail[PHYS_AVAIL_COUNT];3637/* For the common case: add/remove a page from the minidump bitset. */38#define dump_add_page(pa) vm_page_dump_add(vm_page_dump, pa)39#define dump_drop_page(pa) vm_page_dump_drop(vm_page_dump, pa)4041static inline void42vm_page_dump_add(struct bitset *bitset, vm_paddr_t pa)43{44vm_pindex_t adj;45int i;4647adj = 0;48for (i = 0; dump_avail[i + 1] != 0; i += 2) {49if (pa >= dump_avail[i] && pa < dump_avail[i + 1]) {50BIT_SET_ATOMIC(vm_page_dump_pages,51(pa >> PAGE_SHIFT) - (dump_avail[i] >> PAGE_SHIFT) +52adj, bitset);53return;54}55adj += howmany(dump_avail[i + 1], PAGE_SIZE) -56dump_avail[i] / PAGE_SIZE;57}58}5960static inline void61vm_page_dump_drop(struct bitset *bitset, vm_paddr_t pa)62{63vm_pindex_t adj;64int i;6566adj = 0;67for (i = 0; dump_avail[i + 1] != 0; i += 2) {68if (pa >= dump_avail[i] && pa < dump_avail[i + 1]) {69BIT_CLR_ATOMIC(vm_page_dump_pages,70(pa >> PAGE_SHIFT) - (dump_avail[i] >> PAGE_SHIFT) +71adj, bitset);72return;73}74adj += howmany(dump_avail[i + 1], PAGE_SIZE) -75dump_avail[i] / PAGE_SIZE;76}77}7879static inline vm_paddr_t80vm_page_dump_index_to_pa(int bit)81{82int i, tot;8384for (i = 0; dump_avail[i + 1] != 0; i += 2) {85tot = howmany(dump_avail[i + 1], PAGE_SIZE) -86dump_avail[i] / PAGE_SIZE;87if (bit < tot)88return ((vm_paddr_t)bit * PAGE_SIZE +89(dump_avail[i] & ~PAGE_MASK));90bit -= tot;91}92return (0);93}9495#define VM_PAGE_DUMP_FOREACH(bitset, pa) \96for (vm_pindex_t __b = BIT_FFS(vm_page_dump_pages, bitset); \97(pa) = vm_page_dump_index_to_pa(__b - 1), __b != 0; \98__b = BIT_FFS_AT(vm_page_dump_pages, bitset, __b))99100#endif /* _SYS_DUMPSET_H_ */101102103