xref: /illumos-gate/usr/src/uts/sun4/sys/memnode.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_MEMNODE_H
28 #define	_SYS_MEMNODE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef	_KERNEL
37 
38 #include <sys/lgrp.h>
39 
40 /*
41  * This file defines the mappings between physical addresses and memory
42  * nodes. Memory nodes are defined so that the low-order bits are the
43  * memory slice ID and the high-order bits are the SSM nodeid.
44  */
45 
46 /*
47  * The MAX_MEM_NODES constant is the maximum number of memory nodes for the
48  * unix binary and is used to help size static data structures.  The
49  * max_mem_nodes variable is the maximum number of memory nodes for the
50  * running platform and may be smaller than MAX_MEM_NODES since the platform
51  * may not need to use all of them.
52  *
53  * The default value of MAX_MEM_NODES is 4 to create enough memory nodes for
54  * Chalupa and max_mem_nodes is set to 1 by default since the generic sun4u
55  * unix binary mostly includes platforms only needing one memory node.
56  * For platforms requiring more than one memory node, max_mem_nodes is set to
57  * a bigger value in the lgroup platform initialization routines which are
58  * called before the memory nodes are initialized.  Some platforms like
59  * Serengeti and Starcat simply define MAX_MEM_NODES to be their respective
60  * maximum memory nodes at compile time, since they have their own unix binary
61  * and don't share one with any other platform like Enchilada and Chalupa do.
62  *
63  * For machines that don't support DR, they can set max_mem_nodes to the actual
64  * number of memory nodes in the running system instead of the maximum.  The
65  * platform controls the mapping of lgroup platform handles and PFNs to memory
66  * nodes, so the platform can always make everything work.
67  */
68 
69 #ifndef	MAX_MEM_NODES
70 #define	MAX_MEM_NODES	(4)
71 #endif	/* MAX_MEM_NODES */
72 
73 #define	PFN_2_MEM_NODE(pfn)			\
74 	((max_mem_nodes > 1) ? plat_pfn_to_mem_node(pfn) : 0)
75 
76 #define	LGRPHAND_2_MEM_NODE(lgrp_plat_hand)	\
77 	((max_mem_nodes > 1) ? plat_lgrphand_to_mem_node(lgrp_plat_hand) : 0)
78 
79 #define	MEM_NODE_2_LGRPHAND(mnode)		\
80 	((max_mem_nodes > 1) ? plat_mem_node_to_lgrphand(mnode) : \
81 	    LGRP_DEFAULT_HANDLE)
82 
83 /*
84  * Platmod hooks
85  */
86 
87 extern int plat_pfn_to_mem_node(pfn_t);
88 extern int plat_lgrphand_to_mem_node(lgrp_handle_t);
89 extern void plat_assign_lgrphand_to_mem_node(lgrp_handle_t, int);
90 extern lgrp_handle_t plat_mem_node_to_lgrphand(int);
91 extern void plat_slice_add(pfn_t, pfn_t);
92 extern void plat_slice_del(pfn_t, pfn_t);
93 
94 #pragma	weak plat_pfn_to_mem_node
95 #pragma	weak plat_lgrphand_to_mem_node
96 #pragma	weak plat_mem_node_to_lgrphand
97 #pragma	weak plat_slice_add
98 #pragma	weak plat_slice_del
99 
100 struct	mem_node_conf {
101 	int	exists;		/* only try if set, list may still be empty */
102 	pfn_t	physbase;	/* lowest PFN in this memnode */
103 	pfn_t	physmax;	/* highest PFN in this memnode */
104 	size_t	cursize;	/* current number of PAGESIZE pages on lists */
105 };
106 
107 struct memlist;
108 
109 extern void startup_build_mem_nodes(u_longlong_t *, size_t);
110 extern void mem_node_add_slice(pfn_t, pfn_t);
111 extern void mem_node_pre_del_slice(pfn_t, pfn_t);
112 extern void mem_node_post_del_slice(pfn_t, pfn_t, int);
113 extern int mem_node_alloc(void);
114 extern pgcnt_t mem_node_memlist_pages(int, struct memlist *);
115 
116 
117 extern struct mem_node_conf	mem_node_config[];
118 extern uint64_t			mem_node_physalign;
119 extern int			mem_node_pfn_shift;
120 extern int			max_mem_nodes;
121 
122 #endif	/* _KERNEL */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _SYS_MEMNODE_H */
129