xref: /illumos-gate/usr/src/uts/sun4/sys/memnode.h (revision 9853d9e8)
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
5ce8eb11aSdp  * Common Development and Distribution License (the "License").
6ce8eb11aSdp  * 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*9853d9e8SJason Beloro  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_MEMNODE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_MEMNODE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/lgrp.h>
36986fd29aSsetje #include <sys/memlist_plat.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * This file defines the mappings between physical addresses and memory
407c478bd9Sstevel@tonic-gate  * nodes. Memory nodes are defined so that the low-order bits are the
417c478bd9Sstevel@tonic-gate  * memory slice ID and the high-order bits are the SSM nodeid.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * The MAX_MEM_NODES constant is the maximum number of memory nodes for the
467c478bd9Sstevel@tonic-gate  * unix binary and is used to help size static data structures.  The
477c478bd9Sstevel@tonic-gate  * max_mem_nodes variable is the maximum number of memory nodes for the
487c478bd9Sstevel@tonic-gate  * running platform and may be smaller than MAX_MEM_NODES since the platform
497c478bd9Sstevel@tonic-gate  * may not need to use all of them.
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  * The default value of MAX_MEM_NODES is 4 to create enough memory nodes for
527c478bd9Sstevel@tonic-gate  * Chalupa and max_mem_nodes is set to 1 by default since the generic sun4u
537c478bd9Sstevel@tonic-gate  * unix binary mostly includes platforms only needing one memory node.
547c478bd9Sstevel@tonic-gate  * For platforms requiring more than one memory node, max_mem_nodes is set to
557c478bd9Sstevel@tonic-gate  * a bigger value in the lgroup platform initialization routines which are
567c478bd9Sstevel@tonic-gate  * called before the memory nodes are initialized.  Some platforms like
577c478bd9Sstevel@tonic-gate  * Serengeti and Starcat simply define MAX_MEM_NODES to be their respective
587c478bd9Sstevel@tonic-gate  * maximum memory nodes at compile time, since they have their own unix binary
597c478bd9Sstevel@tonic-gate  * and don't share one with any other platform like Enchilada and Chalupa do.
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * For machines that don't support DR, they can set max_mem_nodes to the actual
627c478bd9Sstevel@tonic-gate  * number of memory nodes in the running system instead of the maximum.  The
637c478bd9Sstevel@tonic-gate  * platform controls the mapping of lgroup platform handles and PFNs to memory
647c478bd9Sstevel@tonic-gate  * nodes, so the platform can always make everything work.
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate 
67ce8eb11aSdp #ifndef MAX_MEM_NODES
687c478bd9Sstevel@tonic-gate #define	MAX_MEM_NODES	(4)
697c478bd9Sstevel@tonic-gate #endif	/* MAX_MEM_NODES */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #define	PFN_2_MEM_NODE(pfn)			\
727c478bd9Sstevel@tonic-gate 	((max_mem_nodes > 1) ? plat_pfn_to_mem_node(pfn) : 0)
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	MEM_NODE_2_LGRPHAND(mnode)		\
757c478bd9Sstevel@tonic-gate 	((max_mem_nodes > 1) ? plat_mem_node_to_lgrphand(mnode) : \
767c478bd9Sstevel@tonic-gate 	    LGRP_DEFAULT_HANDLE)
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * Platmod hooks
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate extern int plat_pfn_to_mem_node(pfn_t);
837c478bd9Sstevel@tonic-gate extern int plat_lgrphand_to_mem_node(lgrp_handle_t);
847c478bd9Sstevel@tonic-gate extern void plat_assign_lgrphand_to_mem_node(lgrp_handle_t, int);
857c478bd9Sstevel@tonic-gate extern lgrp_handle_t plat_mem_node_to_lgrphand(int);
867c478bd9Sstevel@tonic-gate extern void plat_slice_add(pfn_t, pfn_t);
877c478bd9Sstevel@tonic-gate extern void plat_slice_del(pfn_t, pfn_t);
88ce8eb11aSdp extern void plat_mem_node_intersect_range(pfn_t, pgcnt_t, int, pgcnt_t *);
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #pragma	weak plat_pfn_to_mem_node
917c478bd9Sstevel@tonic-gate #pragma	weak plat_lgrphand_to_mem_node
927c478bd9Sstevel@tonic-gate #pragma	weak plat_mem_node_to_lgrphand
937c478bd9Sstevel@tonic-gate #pragma	weak plat_slice_add
947c478bd9Sstevel@tonic-gate #pragma	weak plat_slice_del
95ce8eb11aSdp #pragma weak plat_mem_node_intersect_range
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate struct	mem_node_conf {
987c478bd9Sstevel@tonic-gate 	int	exists;		/* only try if set, list may still be empty */
997c478bd9Sstevel@tonic-gate 	pfn_t	physbase;	/* lowest PFN in this memnode */
1007c478bd9Sstevel@tonic-gate 	pfn_t	physmax;	/* highest PFN in this memnode */
1017c478bd9Sstevel@tonic-gate };
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate struct memlist;
1047c478bd9Sstevel@tonic-gate 
105*9853d9e8SJason Beloro /*
106*9853d9e8SJason Beloro  * Common layer calls the mem_node_*_range interfaces
107*9853d9e8SJason Beloro  * which in turn call the platmod hooks if they exist.
108*9853d9e8SJason Beloro  * The platmod layer then calls the mem_node_*slice interfaces.
109*9853d9e8SJason Beloro  */
110986fd29aSsetje extern void startup_build_mem_nodes(prom_memlist_t *, size_t);
1117c478bd9Sstevel@tonic-gate extern void mem_node_add_slice(pfn_t, pfn_t);
112*9853d9e8SJason Beloro extern void mem_node_del_slice(pfn_t, pfn_t);
1137c478bd9Sstevel@tonic-gate extern int mem_node_alloc(void);
1147c478bd9Sstevel@tonic-gate extern pgcnt_t mem_node_memlist_pages(int, struct memlist *);
115ce8eb11aSdp extern void mem_node_max_range(pfn_t *, pfn_t *);
116*9853d9e8SJason Beloro extern void mem_node_add_range(pfn_t, pfn_t);
117*9853d9e8SJason Beloro extern void mem_node_del_range(pfn_t, pfn_t);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate extern struct mem_node_conf	mem_node_config[];
1207c478bd9Sstevel@tonic-gate extern uint64_t			mem_node_physalign;
1217c478bd9Sstevel@tonic-gate extern int			mem_node_pfn_shift;
1227c478bd9Sstevel@tonic-gate extern int			max_mem_nodes;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #endif	/* _SYS_MEMNODE_H */
131