xref: /titanic_50/usr/src/uts/sun4/sys/memnode.h (revision e061a5d7a75180eab31acb1289368162e020bc71)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_MEMNODE_H
27 #define	_SYS_MEMNODE_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #ifdef	_KERNEL
34 
35 #include <sys/lgrp.h>
36 #include <sys/memlist_plat.h>
37 
38 /*
39  * This file defines the mappings between physical addresses and memory
40  * nodes. Memory nodes are defined so that the low-order bits are the
41  * memory slice ID and the high-order bits are the SSM nodeid.
42  */
43 
44 /*
45  * The MAX_MEM_NODES constant is the maximum number of memory nodes for the
46  * unix binary and is used to help size static data structures.  The
47  * max_mem_nodes variable is the maximum number of memory nodes for the
48  * running platform and may be smaller than MAX_MEM_NODES since the platform
49  * may not need to use all of them.
50  *
51  * The default value of MAX_MEM_NODES is 4 to create enough memory nodes for
52  * Chalupa and max_mem_nodes is set to 1 by default since the generic sun4u
53  * unix binary mostly includes platforms only needing one memory node.
54  * For platforms requiring more than one memory node, max_mem_nodes is set to
55  * a bigger value in the lgroup platform initialization routines which are
56  * called before the memory nodes are initialized.  Some platforms like
57  * Serengeti and Starcat simply define MAX_MEM_NODES to be their respective
58  * maximum memory nodes at compile time, since they have their own unix binary
59  * and don't share one with any other platform like Enchilada and Chalupa do.
60  *
61  * For machines that don't support DR, they can set max_mem_nodes to the actual
62  * number of memory nodes in the running system instead of the maximum.  The
63  * platform controls the mapping of lgroup platform handles and PFNs to memory
64  * nodes, so the platform can always make everything work.
65  */
66 
67 #ifndef MAX_MEM_NODES
68 #define	MAX_MEM_NODES	(4)
69 #endif	/* MAX_MEM_NODES */
70 
71 #define	PFN_2_MEM_NODE(pfn)			\
72 	((max_mem_nodes > 1) ? plat_pfn_to_mem_node(pfn) : 0)
73 
74 #define	MEM_NODE_2_LGRPHAND(mnode)		\
75 	((max_mem_nodes > 1) ? plat_mem_node_to_lgrphand(mnode) : \
76 	    LGRP_DEFAULT_HANDLE)
77 
78 /*
79  * Platmod hooks
80  */
81 
82 extern int plat_pfn_to_mem_node(pfn_t);
83 extern int plat_lgrphand_to_mem_node(lgrp_handle_t);
84 extern void plat_assign_lgrphand_to_mem_node(lgrp_handle_t, int);
85 extern lgrp_handle_t plat_mem_node_to_lgrphand(int);
86 extern void plat_slice_add(pfn_t, pfn_t);
87 extern void plat_slice_del(pfn_t, pfn_t);
88 extern void plat_mem_node_intersect_range(pfn_t, pgcnt_t, int, pgcnt_t *);
89 
90 #pragma	weak plat_pfn_to_mem_node
91 #pragma	weak plat_lgrphand_to_mem_node
92 #pragma	weak plat_mem_node_to_lgrphand
93 #pragma	weak plat_slice_add
94 #pragma	weak plat_slice_del
95 #pragma weak plat_mem_node_intersect_range
96 
97 struct	mem_node_conf {
98 	int	exists;		/* only try if set, list may still be empty */
99 	pfn_t	physbase;	/* lowest PFN in this memnode */
100 	pfn_t	physmax;	/* highest PFN in this memnode */
101 };
102 
103 struct memlist;
104 
105 /*
106  * Common layer calls the mem_node_*_range interfaces
107  * which in turn call the platmod hooks if they exist.
108  * The platmod layer then calls the mem_node_*slice interfaces.
109  */
110 extern void startup_build_mem_nodes(prom_memlist_t *, size_t);
111 extern void mem_node_add_slice(pfn_t, pfn_t);
112 extern void mem_node_del_slice(pfn_t, pfn_t);
113 extern int mem_node_alloc(void);
114 extern pgcnt_t mem_node_memlist_pages(int, struct memlist *);
115 extern void mem_node_max_range(pfn_t *, pfn_t *);
116 extern void mem_node_add_range(pfn_t, pfn_t);
117 extern void mem_node_del_range(pfn_t, pfn_t);
118 
119 extern struct mem_node_conf	mem_node_config[];
120 extern uint64_t			mem_node_physalign;
121 extern int			mem_node_pfn_shift;
122 extern int			max_mem_nodes;
123 
124 #endif	/* _KERNEL */
125 
126 #ifdef	__cplusplus
127 }
128 #endif
129 
130 #endif	/* _SYS_MEMNODE_H */
131