xref: /illumos-gate/usr/src/uts/common/sys/mem_config.h (revision 2d6eb4a5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*ae115bc7Smrj  * Common Development and Distribution License (the "License").
6*ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*ae115bc7Smrj  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_MEM_CONFIG_H
277c478bd9Sstevel@tonic-gate #define	_SYS_MEM_CONFIG_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Memory add/delete interfaces.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef _KERNEL
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Memory add/delete client interface.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate extern int kphysm_add_memory_dynamic(pfn_t base, pgcnt_t npgs);
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef void *memhandle_t;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Managed pages have associated page structures ('page_t's).
497c478bd9Sstevel@tonic-gate  * The difference between phys_pages and managed is accounted for by
507c478bd9Sstevel@tonic-gate  * boot time memory allocation for the kernel text and data, and also
517c478bd9Sstevel@tonic-gate  * for page structures.
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate typedef struct {
547c478bd9Sstevel@tonic-gate 	pgcnt_t	phys_pages;	/* total physical pages */
557c478bd9Sstevel@tonic-gate 	pgcnt_t	managed;	/* providing this many managed pages */
567c478bd9Sstevel@tonic-gate 	pgcnt_t	nonrelocatable;	/* of which this many non-relocatable */
577c478bd9Sstevel@tonic-gate 	pfn_t	first_nonrelocatable;
587c478bd9Sstevel@tonic-gate 	pfn_t	last_nonrelocatable;
597c478bd9Sstevel@tonic-gate } memquery_t;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate typedef struct {
627c478bd9Sstevel@tonic-gate 	pgcnt_t	phys_pages;	/* total physical pages */
637c478bd9Sstevel@tonic-gate 	pgcnt_t	managed;	/* providing this many managed pages */
647c478bd9Sstevel@tonic-gate 	pgcnt_t	collected; 	/* done when == managed */
657c478bd9Sstevel@tonic-gate } memdelstat_t;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate extern int kphysm_del_gethandle(memhandle_t *);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate extern int kphysm_del_span(memhandle_t, pfn_t base, pgcnt_t npgs);
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate extern int kphysm_del_span_query(pfn_t base, pgcnt_t npgs, memquery_t *);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate extern int kphysm_del_start(memhandle_t,
747c478bd9Sstevel@tonic-gate 	void (*complete)(void *, int error), void *arg);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate extern int kphysm_del_release(memhandle_t);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate extern int kphysm_del_cancel(memhandle_t);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate extern int kphysm_del_status(memhandle_t, memdelstat_t *);
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * Error returns.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	KPHYSM_OK		0	/* Success */
877c478bd9Sstevel@tonic-gate #define	KPHYSM_ESPAN		1	/* Memory already in use (add) */
887c478bd9Sstevel@tonic-gate #define	KPHYSM_EFAULT		2	/* Memory access test failed (add) */
897c478bd9Sstevel@tonic-gate #define	KPHYSM_ERESOURCE	3	/* Some resource was not available */
907c478bd9Sstevel@tonic-gate #define	KPHYSM_ENOTSUP		4	/* Operation not supported */
917c478bd9Sstevel@tonic-gate #define	KPHYSM_ENOHANDLES	5	/* Cannot allocate any more handles */
927c478bd9Sstevel@tonic-gate #define	KPHYSM_ENONRELOC	6	/* Non-relocatable pages in span */
937c478bd9Sstevel@tonic-gate #define	KPHYSM_EHANDLE		7	/* Bad handle supplied */
947c478bd9Sstevel@tonic-gate #define	KPHYSM_EBUSY		8	/* Memory in span is being deleted */
957c478bd9Sstevel@tonic-gate #define	KPHYSM_ENOTVIABLE	9	/* VM viability test failed */
967c478bd9Sstevel@tonic-gate #define	KPHYSM_ESEQUENCE	10	/* Function called out of sequence */
977c478bd9Sstevel@tonic-gate #define	KPHYSM_ENOWORK		11	/* No pages to delete */
987c478bd9Sstevel@tonic-gate #define	KPHYSM_ECANCELLED	12	/* kphysm_del_cancel (for complete) */
997c478bd9Sstevel@tonic-gate #define	KPHYSM_EREFUSED		13	/* kphysm_pre_del fail (for complete) */
1007c478bd9Sstevel@tonic-gate #define	KPHYSM_ENOTFINISHED	14	/* Thread not finished */
1017c478bd9Sstevel@tonic-gate #define	KPHYSM_ENOTRUNNING	15	/* Thread not running */
1027c478bd9Sstevel@tonic-gate #define	KPHYSM_EDUP		16	/* Memory span duplicate (delete) */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * Memory system change call-back interface.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	KPHYSM_SETUP_VECTOR_VERSION	1
1097c478bd9Sstevel@tonic-gate typedef struct {
1107c478bd9Sstevel@tonic-gate 	uint_t		version;
1117c478bd9Sstevel@tonic-gate 	void		(*post_add)(void *arg, pgcnt_t delta_pages);
1127c478bd9Sstevel@tonic-gate 	int		(*pre_del)(void *arg, pgcnt_t delta_pages);
1137c478bd9Sstevel@tonic-gate 	void		(*post_del)(void *arg, pgcnt_t delta_pages,
1147c478bd9Sstevel@tonic-gate 			    int cancelled);
1157c478bd9Sstevel@tonic-gate } kphysm_setup_vector_t;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * The register function returns 0 if the vector/arg pair is recorded
1197c478bd9Sstevel@tonic-gate  * successfully.
1207c478bd9Sstevel@tonic-gate  * The error returns are:
1217c478bd9Sstevel@tonic-gate  *	EEXIST	if the vector/arg pair is already registered.
1227c478bd9Sstevel@tonic-gate  *	EINVAL	if the vector version is not supported.
1237c478bd9Sstevel@tonic-gate  *	ENOMEM	if the registration could not be stored.
1247c478bd9Sstevel@tonic-gate  *
1257c478bd9Sstevel@tonic-gate  * A return of EEXIST should be considered a program logic error by
1267c478bd9Sstevel@tonic-gate  * the caller.
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate extern int kphysm_setup_func_register(kphysm_setup_vector_t *, void *arg);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate extern void kphysm_setup_func_unregister(kphysm_setup_vector_t *, void *arg);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Memory add/delete architecture (lower) interfaces.
1357c478bd9Sstevel@tonic-gate  * These interfaces should not be used by drivers.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate extern int arch_kphysm_del_span_ok(pfn_t, pgcnt_t);
1397c478bd9Sstevel@tonic-gate extern int arch_kphysm_relocate(pfn_t, pgcnt_t);
1407c478bd9Sstevel@tonic-gate extern int arch_kphysm_del_supported(void);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate extern int pfn_is_being_deleted(pfn_t);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate #endif
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #endif	/* _SYS_MEM_CONFIG_H */
151