xref: /titanic_50/usr/src/uts/common/sys/pghw.h (revision 8031591d3cc3c82e97f4b60ea22d671525077b15)
1fb2f18f8Sesaxe /*
2fb2f18f8Sesaxe  * CDDL HEADER START
3fb2f18f8Sesaxe  *
4fb2f18f8Sesaxe  * The contents of this file are subject to the terms of the
5fb2f18f8Sesaxe  * Common Development and Distribution License (the "License").
6fb2f18f8Sesaxe  * You may not use this file except in compliance with the License.
7fb2f18f8Sesaxe  *
8fb2f18f8Sesaxe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fb2f18f8Sesaxe  * or http://www.opensolaris.org/os/licensing.
10fb2f18f8Sesaxe  * See the License for the specific language governing permissions
11fb2f18f8Sesaxe  * and limitations under the License.
12fb2f18f8Sesaxe  *
13fb2f18f8Sesaxe  * When distributing Covered Code, include this CDDL HEADER in each
14fb2f18f8Sesaxe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fb2f18f8Sesaxe  * If applicable, add the following below this CDDL HEADER, with the
16fb2f18f8Sesaxe  * fields enclosed by brackets "[]" replaced with your own identifying
17fb2f18f8Sesaxe  * information: Portions Copyright [yyyy] [name of copyright owner]
18fb2f18f8Sesaxe  *
19fb2f18f8Sesaxe  * CDDL HEADER END
20fb2f18f8Sesaxe  */
21*8031591dSSrihari Venkatesan 
22fb2f18f8Sesaxe /*
230e751525SEric Saxe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24fb2f18f8Sesaxe  * Use is subject to license terms.
25fb2f18f8Sesaxe  */
26fb2f18f8Sesaxe 
27fb2f18f8Sesaxe #ifndef	_PGHW_H
28fb2f18f8Sesaxe #define	_PGHW_H
29fb2f18f8Sesaxe 
30fb2f18f8Sesaxe #ifdef	__cplusplus
31fb2f18f8Sesaxe extern "C" {
32fb2f18f8Sesaxe #endif
33fb2f18f8Sesaxe 
34fb2f18f8Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER))
35fb2f18f8Sesaxe #include <sys/cpuvar.h>
36fb2f18f8Sesaxe #include <sys/group.h>
37fb2f18f8Sesaxe #include <sys/processor.h>
38fb2f18f8Sesaxe #include <sys/bitmap.h>
39fb2f18f8Sesaxe #include <sys/atomic.h>
40fb2f18f8Sesaxe #include <sys/types.h>
41fb2f18f8Sesaxe #include <sys/kstat.h>
42fb2f18f8Sesaxe #include <sys/pg.h>
43fb2f18f8Sesaxe 
44fb2f18f8Sesaxe /*
45fb2f18f8Sesaxe  * Hardware that may be shared by a group of processors
46fb2f18f8Sesaxe  */
47fb2f18f8Sesaxe typedef enum pghw_type {
48fb2f18f8Sesaxe 	PGHW_START,
490e751525SEric Saxe 	PGHW_IPIPE,	/* Instruction Pipeline */
500e751525SEric Saxe 	PGHW_CACHE,	/* Cache (generally last level) */
510e751525SEric Saxe 	PGHW_FPU,	/* Floating Point Unit / Pipeline */
520e751525SEric Saxe 	PGHW_MPIPE,	/* Pipe to Memory */
530e751525SEric Saxe 	PGHW_CHIP,	/* Socket */
54fb2f18f8Sesaxe 	PGHW_MEMORY,
550e751525SEric Saxe 	PGHW_POW_ACTIVE,	/* Active Power Management Domain */
560e751525SEric Saxe 	PGHW_POW_IDLE,		/* Idle Power Management Domain */
57fb2f18f8Sesaxe 	PGHW_NUM_COMPONENTS
58fb2f18f8Sesaxe } pghw_type_t;
59fb2f18f8Sesaxe 
60fb2f18f8Sesaxe /*
61*8031591dSSrihari Venkatesan  * See comments in usr/src/uts/i86pc/os/cpuid.c
62*8031591dSSrihari Venkatesan  * for description of processor nodes
63*8031591dSSrihari Venkatesan  *
64*8031591dSSrihari Venkatesan  * From sharing point of view processor nodes are
65*8031591dSSrihari Venkatesan  * very similar to memory pipes, hence the #define below.
66*8031591dSSrihari Venkatesan  */
67*8031591dSSrihari Venkatesan #define	PGHW_PROCNODE	PGHW_MPIPE
68*8031591dSSrihari Venkatesan 
69*8031591dSSrihari Venkatesan /*
700e751525SEric Saxe  * Returns true if the hardware is a type of power management domain
710e751525SEric Saxe  */
720e751525SEric Saxe #define	PGHW_IS_PM_DOMAIN(hw)	\
730e751525SEric Saxe 	(hw == PGHW_POW_ACTIVE || hw == PGHW_POW_IDLE)
740e751525SEric Saxe 
750e751525SEric Saxe /*
76fb2f18f8Sesaxe  * Anonymous instance id
77fb2f18f8Sesaxe  */
78fb2f18f8Sesaxe #define	PGHW_INSTANCE_ANON ((id_t)0xdecafbad)
79fb2f18f8Sesaxe 
80fb2f18f8Sesaxe /*
810e751525SEric Saxe  * Max length of PGHW kstat strings
820e751525SEric Saxe  */
830e751525SEric Saxe #define	PGHW_KSTAT_STR_LEN_MAX	32
840e751525SEric Saxe 
850e751525SEric Saxe 
860e751525SEric Saxe /*
870e751525SEric Saxe  * Platform specific handle
880e751525SEric Saxe  */
890e751525SEric Saxe typedef uintptr_t pghw_handle_t;
900e751525SEric Saxe 
910e751525SEric Saxe /*
92fb2f18f8Sesaxe  * Processor Group (physical sharing relationship)
93fb2f18f8Sesaxe  */
94fb2f18f8Sesaxe typedef struct pghw {
95fb2f18f8Sesaxe 	pg_t		pghw_pg;	/* processor group */
96fb2f18f8Sesaxe 	pghw_type_t	pghw_hw;	/* HW sharing relationship */
97fb2f18f8Sesaxe 	id_t		pghw_instance;	/* sharing instance identifier */
980e751525SEric Saxe 	pghw_handle_t	pghw_handle;	/* hw specific opaque handle */
99fb2f18f8Sesaxe 	kstat_t		*pghw_kstat;	/* physical kstats exported */
100fb2f18f8Sesaxe } pghw_t;
101fb2f18f8Sesaxe 
102fb2f18f8Sesaxe /*
103fb2f18f8Sesaxe  * IDs associating a CPU with various physical hardware
104fb2f18f8Sesaxe  */
105fb2f18f8Sesaxe typedef struct cpu_physid {
106fb2f18f8Sesaxe 	id_t		cpu_chipid;	/* CPU's physical processor */
107fb2f18f8Sesaxe 	id_t		cpu_coreid;	/* CPU's physical core */
108fb2f18f8Sesaxe 	id_t		cpu_cacheid;	/* CPU's cache id */
109fb2f18f8Sesaxe } cpu_physid_t;
110fb2f18f8Sesaxe 
111fb2f18f8Sesaxe /*
112fb2f18f8Sesaxe  * Physical PG initialization / CPU service hooks
113fb2f18f8Sesaxe  */
114fb2f18f8Sesaxe void		pghw_init(pghw_t *, cpu_t *, pghw_type_t);
115fb2f18f8Sesaxe void		pghw_fini(pghw_t *);
116fb2f18f8Sesaxe void		pghw_cpu_add(pghw_t *, cpu_t *);
117fb2f18f8Sesaxe pghw_t		*pghw_place_cpu(cpu_t *, pghw_type_t);
118fb2f18f8Sesaxe 
119fb2f18f8Sesaxe /*
120fb2f18f8Sesaxe  * Physical ID cache creation / destruction
121fb2f18f8Sesaxe  */
122fb2f18f8Sesaxe void		pghw_physid_create(cpu_t *);
123fb2f18f8Sesaxe void		pghw_physid_destroy(cpu_t *);
124fb2f18f8Sesaxe 
125fb2f18f8Sesaxe /*
126fb2f18f8Sesaxe  * CPU / PG hardware related seach operations
127fb2f18f8Sesaxe  */
128fb2f18f8Sesaxe pghw_t		*pghw_find_pg(cpu_t *, pghw_type_t);
129fb2f18f8Sesaxe pghw_t		*pghw_find_by_instance(id_t, pghw_type_t);
130fb2f18f8Sesaxe group_t		*pghw_set_lookup(pghw_type_t);
131fb2f18f8Sesaxe 
132fb2f18f8Sesaxe void		pghw_kstat_create(pghw_t *);
133fb2f18f8Sesaxe int		pghw_kstat_update(kstat_t *, int);
134fb2f18f8Sesaxe 
135fb2f18f8Sesaxe /* Hardware sharing relationship platform interfaces */
136fb2f18f8Sesaxe int		pg_plat_hw_shared(cpu_t *, pghw_type_t);
137fb2f18f8Sesaxe int		pg_plat_cpus_share(cpu_t *, cpu_t *, pghw_type_t);
138fb2f18f8Sesaxe id_t		pg_plat_hw_instance_id(cpu_t *, pghw_type_t);
1390e751525SEric Saxe pghw_type_t	pg_plat_hw_rank(pghw_type_t, pghw_type_t);
140fb2f18f8Sesaxe 
141fb2f18f8Sesaxe /*
142fb2f18f8Sesaxe  * What comprises a "core" may vary across processor implementations,
143fb2f18f8Sesaxe  * and so the term itself is somewhat unstable. For this reason, there
144fb2f18f8Sesaxe  * is no PGHW_CORE type, but we provide an interface here to allow platforms
145fb2f18f8Sesaxe  * to express cpu <=> core mappings.
146fb2f18f8Sesaxe  */
147fb2f18f8Sesaxe id_t		pg_plat_get_core_id(cpu_t *);
148fb2f18f8Sesaxe 
149fb2f18f8Sesaxe #endif	/* !_KERNEL && !_KMEMUSER */
150fb2f18f8Sesaxe 
151fb2f18f8Sesaxe #ifdef	__cplusplus
152fb2f18f8Sesaxe }
153fb2f18f8Sesaxe #endif
154fb2f18f8Sesaxe 
155fb2f18f8Sesaxe #endif /* _PGHW_H */
156