xref: /illumos-gate/usr/src/uts/common/sys/mem_config.h (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_MEM_CONFIG_H
27 #define	_SYS_MEM_CONFIG_H
28 
29 /*
30  * Memory add/delete interfaces.
31  */
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef _KERNEL
38 
39 /*
40  * Memory add/delete client interface.
41  */
42 
43 extern int kphysm_add_memory_dynamic(pfn_t base, pgcnt_t npgs);
44 
45 typedef void *memhandle_t;
46 
47 /*
48  * Managed pages have associated page structures ('page_t's).
49  * The difference between phys_pages and managed is accounted for by
50  * boot time memory allocation for the kernel text and data, and also
51  * for page structures.
52  */
53 typedef struct {
54 	pgcnt_t	phys_pages;	/* total physical pages */
55 	pgcnt_t	managed;	/* providing this many managed pages */
56 	pgcnt_t	nonrelocatable;	/* of which this many non-relocatable */
57 	pfn_t	first_nonrelocatable;
58 	pfn_t	last_nonrelocatable;
59 } memquery_t;
60 
61 typedef struct {
62 	pgcnt_t	phys_pages;	/* total physical pages */
63 	pgcnt_t	managed;	/* providing this many managed pages */
64 	pgcnt_t	collected; 	/* done when == managed */
65 } memdelstat_t;
66 
67 extern int kphysm_del_gethandle(memhandle_t *);
68 
69 extern int kphysm_del_span(memhandle_t, pfn_t base, pgcnt_t npgs);
70 
71 extern int kphysm_del_span_query(pfn_t base, pgcnt_t npgs, memquery_t *);
72 
73 extern int kphysm_del_start(memhandle_t,
74 	void (*complete)(void *, int error), void *arg);
75 
76 extern int kphysm_del_release(memhandle_t);
77 
78 extern int kphysm_del_cancel(memhandle_t);
79 
80 extern int kphysm_del_status(memhandle_t, memdelstat_t *);
81 
82 /*
83  * Error returns.
84  */
85 
86 #define	KPHYSM_OK		0	/* Success */
87 #define	KPHYSM_ESPAN		1	/* Memory already in use (add) */
88 #define	KPHYSM_EFAULT		2	/* Memory access test failed (add) */
89 #define	KPHYSM_ERESOURCE	3	/* Some resource was not available */
90 #define	KPHYSM_ENOTSUP		4	/* Operation not supported */
91 #define	KPHYSM_ENOHANDLES	5	/* Cannot allocate any more handles */
92 #define	KPHYSM_ENONRELOC	6	/* Non-relocatable pages in span */
93 #define	KPHYSM_EHANDLE		7	/* Bad handle supplied */
94 #define	KPHYSM_EBUSY		8	/* Memory in span is being deleted */
95 #define	KPHYSM_ENOTVIABLE	9	/* VM viability test failed */
96 #define	KPHYSM_ESEQUENCE	10	/* Function called out of sequence */
97 #define	KPHYSM_ENOWORK		11	/* No pages to delete */
98 #define	KPHYSM_ECANCELLED	12	/* kphysm_del_cancel (for complete) */
99 #define	KPHYSM_EREFUSED		13	/* kphysm_pre_del fail (for complete) */
100 #define	KPHYSM_ENOTFINISHED	14	/* Thread not finished */
101 #define	KPHYSM_ENOTRUNNING	15	/* Thread not running */
102 #define	KPHYSM_EDUP		16	/* Memory span duplicate (delete) */
103 
104 /*
105  * Memory system change call-back interface.
106  */
107 
108 #define	KPHYSM_SETUP_VECTOR_VERSION	1
109 typedef struct {
110 	uint_t		version;
111 	void		(*post_add)(void *arg, pgcnt_t delta_pages);
112 	int		(*pre_del)(void *arg, pgcnt_t delta_pages);
113 	void		(*post_del)(void *arg, pgcnt_t delta_pages,
114 			    int cancelled);
115 } kphysm_setup_vector_t;
116 
117 /*
118  * The register function returns 0 if the vector/arg pair is recorded
119  * successfully.
120  * The error returns are:
121  *	EEXIST	if the vector/arg pair is already registered.
122  *	EINVAL	if the vector version is not supported.
123  *	ENOMEM	if the registration could not be stored.
124  *
125  * A return of EEXIST should be considered a program logic error by
126  * the caller.
127  */
128 extern int kphysm_setup_func_register(kphysm_setup_vector_t *, void *arg);
129 
130 extern void kphysm_setup_func_unregister(kphysm_setup_vector_t *, void *arg);
131 
132 
133 /*
134  * Memory add/delete architecture (lower) interfaces.
135  * These interfaces should not be used by drivers.
136  */
137 
138 extern int arch_kphysm_del_span_ok(pfn_t, pgcnt_t);
139 extern int arch_kphysm_relocate(pfn_t, pgcnt_t);
140 extern int arch_kphysm_del_supported(void);
141 
142 extern int pfn_is_being_deleted(pfn_t);
143 
144 #endif /* _KERNEL */
145 
146 #ifdef	__cplusplus
147 }
148 #endif
149 
150 #endif	/* _SYS_MEM_CONFIG_H */
151