xref: /netbsd-src/sys/uvm/uvm_physseg.h (revision ecaf2f40636d722d955675482a7dee48814b8405)
1*ecaf2f40Stnn /* $NetBSD: uvm_physseg.h,v 1.9 2024/01/13 09:44:42 tnn Exp $ */
2ce8e005dScherry 
3ce8e005dScherry /*-
4ce8e005dScherry  * Copyright (c) 2016 The NetBSD Foundation, Inc.
5ce8e005dScherry  * All rights reserved.
6ce8e005dScherry  *
7ce8e005dScherry  * This code is derived from software contributed to The NetBSD Foundation
8ce8e005dScherry  * by  Cherry G. Mathew <cherry@NetBSD.org>
9ce8e005dScherry  *
10ce8e005dScherry  * Redistribution and use in source and binary forms, with or without
11ce8e005dScherry  * modification, are permitted provided that the following conditions
12ce8e005dScherry  * are met:
13ce8e005dScherry  * 1. Redistributions of source code must retain the above copyright
14ce8e005dScherry  *    notice, this list of conditions and the following disclaimer.
15ce8e005dScherry  * 2. Redistributions in binary form must reproduce the above copyright
16ce8e005dScherry  *    notice, this list of conditions and the following disclaimer in the
17ce8e005dScherry  *    documentation and/or other materials provided with the distribution.
18ce8e005dScherry  *
19ce8e005dScherry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ce8e005dScherry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ce8e005dScherry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ce8e005dScherry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ce8e005dScherry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ce8e005dScherry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ce8e005dScherry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ce8e005dScherry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ce8e005dScherry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ce8e005dScherry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ce8e005dScherry  * POSSIBILITY OF SUCH DAMAGE.
30ce8e005dScherry  */
3107acf3c0Scherry 
3207acf3c0Scherry /*
3307acf3c0Scherry  * Consolidated API from uvm_page.c and others.
34ce8e005dScherry  * Consolidated and designed by Cherry G. Mathew <cherry@NetBSD.org>
3507acf3c0Scherry  */
3607acf3c0Scherry 
3707acf3c0Scherry #ifndef _UVM_UVM_PHYSSEG_H_
3807acf3c0Scherry #define _UVM_UVM_PHYSSEG_H_
3907acf3c0Scherry 
4007acf3c0Scherry #if defined(_KERNEL_OPT)
4107acf3c0Scherry #include "opt_uvm_hotplug.h"
4207acf3c0Scherry #endif
4307acf3c0Scherry 
4407acf3c0Scherry #include <sys/cdefs.h>
4507acf3c0Scherry #include <sys/param.h>
4607acf3c0Scherry #include <sys/types.h>
4707acf3c0Scherry 
4807acf3c0Scherry /*
4907acf3c0Scherry  * No APIs are explicitly #included in uvm_physseg.c
5007acf3c0Scherry  */
5107acf3c0Scherry 
5207acf3c0Scherry #if defined(UVM_HOTPLUG) /* rbtree impementation */
5307acf3c0Scherry #define PRIxPHYSSEG "p"
5407acf3c0Scherry 
5507acf3c0Scherry /*
5607acf3c0Scherry  * These are specific values of invalid constants for uvm_physseg_t.
57e6ff351eScherry  * uvm_physseg_valid_p() == false on any of the below constants.
5807acf3c0Scherry  *
5907acf3c0Scherry  * Specific invalid constants encapsulate specific explicit failure
6007acf3c0Scherry  * scenarios (see the comments next to them)
6107acf3c0Scherry  */
6207acf3c0Scherry 
6307acf3c0Scherry #define UVM_PHYSSEG_TYPE_INVALID NULL /* Generic invalid value */
6407acf3c0Scherry #define UVM_PHYSSEG_TYPE_INVALID_EMPTY NULL /* empty segment access */
6507acf3c0Scherry #define UVM_PHYSSEG_TYPE_INVALID_OVERFLOW NULL /* ran off the end of the last segment */
6607acf3c0Scherry 
6707acf3c0Scherry typedef struct uvm_physseg * uvm_physseg_t;
6807acf3c0Scherry 
6907acf3c0Scherry #else  /* UVM_HOTPLUG */
7007acf3c0Scherry 
7107acf3c0Scherry #define PRIxPHYSSEG "d"
7207acf3c0Scherry 
7307acf3c0Scherry /*
7407acf3c0Scherry  * These are specific values of invalid constants for uvm_physseg_t.
75e6ff351eScherry  * uvm_physseg_valid_p() == false on any of the below constants.
7607acf3c0Scherry  *
7707acf3c0Scherry  * Specific invalid constants encapsulate specific explicit failure
7807acf3c0Scherry  * scenarios (see the comments next to them)
7907acf3c0Scherry  */
8007acf3c0Scherry 
8107acf3c0Scherry #define UVM_PHYSSEG_TYPE_INVALID -1 /* Generic invalid value */
8207acf3c0Scherry #define UVM_PHYSSEG_TYPE_INVALID_EMPTY -1 /* empty segment access */
8307acf3c0Scherry #define UVM_PHYSSEG_TYPE_INVALID_OVERFLOW (uvm_physseg_get_last() + 1) /* ran off the end of the last segment */
8407acf3c0Scherry 
8507acf3c0Scherry typedef int uvm_physseg_t;
8607acf3c0Scherry #endif /* UVM_HOTPLUG */
8707acf3c0Scherry 
8807acf3c0Scherry void uvm_physseg_init(void);
8907acf3c0Scherry 
90e6ff351eScherry bool uvm_physseg_valid_p(uvm_physseg_t);
9107acf3c0Scherry 
9207acf3c0Scherry /*
9307acf3c0Scherry  * Return start/end pfn of given segment
9407acf3c0Scherry  * Returns: -1 if the segment number is invalid
9507acf3c0Scherry  */
9607acf3c0Scherry paddr_t uvm_physseg_get_start(uvm_physseg_t);
9707acf3c0Scherry paddr_t uvm_physseg_get_end(uvm_physseg_t);
9807acf3c0Scherry 
9907acf3c0Scherry paddr_t uvm_physseg_get_avail_start(uvm_physseg_t);
10007acf3c0Scherry paddr_t uvm_physseg_get_avail_end(uvm_physseg_t);
10107acf3c0Scherry 
10207acf3c0Scherry struct vm_page * uvm_physseg_get_pg(uvm_physseg_t, paddr_t);
10307acf3c0Scherry 
10407acf3c0Scherry #ifdef __HAVE_PMAP_PHYSSEG
10507acf3c0Scherry struct	pmap_physseg * uvm_physseg_get_pmseg(uvm_physseg_t);
10607acf3c0Scherry #endif
10707acf3c0Scherry 
10807acf3c0Scherry int uvm_physseg_get_free_list(uvm_physseg_t);
109*ecaf2f40Stnn u_long uvm_physseg_get_start_hint(uvm_physseg_t);
110*ecaf2f40Stnn bool uvm_physseg_set_start_hint(uvm_physseg_t, u_long);
11107acf3c0Scherry 
11207acf3c0Scherry /*
11307acf3c0Scherry  * Functions to help walk the list of segments.
11407acf3c0Scherry  * Returns: NULL if the segment number is invalid
11507acf3c0Scherry  */
11607acf3c0Scherry uvm_physseg_t uvm_physseg_get_next(uvm_physseg_t);
11707acf3c0Scherry uvm_physseg_t uvm_physseg_get_prev(uvm_physseg_t);
11807acf3c0Scherry uvm_physseg_t uvm_physseg_get_first(void);
11907acf3c0Scherry uvm_physseg_t uvm_physseg_get_last(void);
12007acf3c0Scherry 
12107acf3c0Scherry 
12207acf3c0Scherry /* Return the frame number of the highest registered physical page frame */
12307acf3c0Scherry paddr_t uvm_physseg_get_highest_frame(void);
12407acf3c0Scherry 
12507acf3c0Scherry /* Actually, uvm_page_physload takes PF#s which need their own type */
12607acf3c0Scherry uvm_physseg_t uvm_page_physload(paddr_t, paddr_t, paddr_t,
12707acf3c0Scherry     paddr_t, int);
12807acf3c0Scherry 
12907acf3c0Scherry bool uvm_page_physunload(uvm_physseg_t, int, paddr_t *);
13007acf3c0Scherry bool uvm_page_physunload_force(uvm_physseg_t, int, paddr_t *);
13107acf3c0Scherry 
13207acf3c0Scherry uvm_physseg_t uvm_physseg_find(paddr_t, psize_t *);
13307acf3c0Scherry 
13407acf3c0Scherry bool uvm_physseg_plug(paddr_t, size_t, uvm_physseg_t *);
13507acf3c0Scherry bool uvm_physseg_unplug(paddr_t, size_t);
13607acf3c0Scherry 
137c7ed8c6fSrin #if defined(UVM_PHYSSEG_LEGACY)
13807acf3c0Scherry /*
13907acf3c0Scherry  * XXX: Legacy: This needs to be upgraded to a full pa management
14007acf3c0Scherry  * layer.
14107acf3c0Scherry  */
14207acf3c0Scherry void uvm_physseg_set_avail_start(uvm_physseg_t, paddr_t);
14307acf3c0Scherry void uvm_physseg_set_avail_end(uvm_physseg_t, paddr_t);
144c7ed8c6fSrin #endif /* UVM_PHYSSEG_LEGACY */
14507acf3c0Scherry 
146ab54d6b9Smaya #endif /* _UVM_UVM_PHYSSEG_H_ */
147