xref: /titanic_41/usr/src/uts/common/sys/mem_config.h (revision 7c2fbfb345896881c631598ee3852ce9ce33fb07)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Memory add/delete interfaces.
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef _KERNEL
40 
41 /*
42  * Memory add/delete client interface.
43  */
44 
45 extern int kphysm_add_memory_dynamic(pfn_t base, pgcnt_t npgs);
46 
47 typedef void *memhandle_t;
48 
49 /*
50  * Managed pages have associated page structures ('page_t's).
51  * The difference between phys_pages and managed is accounted for by
52  * boot time memory allocation for the kernel text and data, and also
53  * for page structures.
54  */
55 typedef struct {
56 	pgcnt_t	phys_pages;	/* total physical pages */
57 	pgcnt_t	managed;	/* providing this many managed pages */
58 	pgcnt_t	nonrelocatable;	/* of which this many non-relocatable */
59 	pfn_t	first_nonrelocatable;
60 	pfn_t	last_nonrelocatable;
61 } memquery_t;
62 
63 typedef struct {
64 	pgcnt_t	phys_pages;	/* total physical pages */
65 	pgcnt_t	managed;	/* providing this many managed pages */
66 	pgcnt_t	collected; 	/* done when == managed */
67 } memdelstat_t;
68 
69 extern int kphysm_del_gethandle(memhandle_t *);
70 
71 extern int kphysm_del_span(memhandle_t, pfn_t base, pgcnt_t npgs);
72 
73 extern int kphysm_del_span_query(pfn_t base, pgcnt_t npgs, memquery_t *);
74 
75 extern int kphysm_del_start(memhandle_t,
76 	void (*complete)(void *, int error), void *arg);
77 
78 extern int kphysm_del_release(memhandle_t);
79 
80 extern int kphysm_del_cancel(memhandle_t);
81 
82 extern int kphysm_del_status(memhandle_t, memdelstat_t *);
83 
84 /*
85  * Error returns.
86  */
87 
88 #define	KPHYSM_OK		0	/* Success */
89 #define	KPHYSM_ESPAN		1	/* Memory already in use (add) */
90 #define	KPHYSM_EFAULT		2	/* Memory access test failed (add) */
91 #define	KPHYSM_ERESOURCE	3	/* Some resource was not available */
92 #define	KPHYSM_ENOTSUP		4	/* Operation not supported */
93 #define	KPHYSM_ENOHANDLES	5	/* Cannot allocate any more handles */
94 #define	KPHYSM_ENONRELOC	6	/* Non-relocatable pages in span */
95 #define	KPHYSM_EHANDLE		7	/* Bad handle supplied */
96 #define	KPHYSM_EBUSY		8	/* Memory in span is being deleted */
97 #define	KPHYSM_ENOTVIABLE	9	/* VM viability test failed */
98 #define	KPHYSM_ESEQUENCE	10	/* Function called out of sequence */
99 #define	KPHYSM_ENOWORK		11	/* No pages to delete */
100 #define	KPHYSM_ECANCELLED	12	/* kphysm_del_cancel (for complete) */
101 #define	KPHYSM_EREFUSED		13	/* kphysm_pre_del fail (for complete) */
102 #define	KPHYSM_ENOTFINISHED	14	/* Thread not finished */
103 #define	KPHYSM_ENOTRUNNING	15	/* Thread not running */
104 #define	KPHYSM_EDUP		16	/* Memory span duplicate (delete) */
105 
106 /*
107  * Memory system change call-back interface.
108  */
109 
110 #define	KPHYSM_SETUP_VECTOR_VERSION	1
111 typedef struct {
112 	uint_t		version;
113 	void		(*post_add)(void *arg, pgcnt_t delta_pages);
114 	int		(*pre_del)(void *arg, pgcnt_t delta_pages);
115 	void		(*post_del)(void *arg, pgcnt_t delta_pages,
116 			    int cancelled);
117 } kphysm_setup_vector_t;
118 
119 /*
120  * The register function returns 0 if the vector/arg pair is recorded
121  * successfully.
122  * The error returns are:
123  *	EEXIST	if the vector/arg pair is already registered.
124  *	EINVAL	if the vector version is not supported.
125  *	ENOMEM	if the registration could not be stored.
126  *
127  * A return of EEXIST should be considered a program logic error by
128  * the caller.
129  */
130 extern int kphysm_setup_func_register(kphysm_setup_vector_t *, void *arg);
131 
132 extern void kphysm_setup_func_unregister(kphysm_setup_vector_t *, void *arg);
133 
134 
135 /*
136  * Memory add/delete architecture (lower) interfaces.
137  * These interfaces should not be used by drivers.
138  */
139 
140 extern int arch_kphysm_del_span_ok(pfn_t, pgcnt_t);
141 extern int arch_kphysm_relocate(pfn_t, pgcnt_t);
142 extern int arch_kphysm_del_supported(void);
143 
144 extern int pfn_is_being_deleted(pfn_t);
145 
146 #endif /* _KERNEL */
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif	/* _SYS_MEM_CONFIG_H */
153