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 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _PGHW_H 28 #define _PGHW_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #if (defined(_KERNEL) || defined(_KMEMUSER)) 35 #include <sys/cpuvar.h> 36 #include <sys/group.h> 37 #include <sys/processor.h> 38 #include <sys/bitmap.h> 39 #include <sys/atomic.h> 40 #include <sys/types.h> 41 #include <sys/kstat.h> 42 #include <sys/pg.h> 43 44 /* 45 * Hardware that may be shared by a group of processors 46 */ 47 typedef enum pghw_type { 48 PGHW_START, 49 PGHW_IPIPE, /* Instruction Pipeline */ 50 PGHW_CACHE, /* Cache (generally last level) */ 51 PGHW_FPU, /* Floating Point Unit / Pipeline */ 52 PGHW_MPIPE, /* Pipe to Memory */ 53 PGHW_CHIP, /* Socket */ 54 PGHW_MEMORY, 55 PGHW_POW_ACTIVE, /* Active Power Management Domain */ 56 PGHW_POW_IDLE, /* Idle Power Management Domain */ 57 PGHW_NUM_COMPONENTS 58 } pghw_type_t; 59 60 /* 61 * See comments in usr/src/uts/i86pc/os/cpuid.c 62 * for description of processor nodes 63 * 64 * From sharing point of view processor nodes are 65 * very similar to memory pipes, hence the #define below. 66 */ 67 #define PGHW_PROCNODE PGHW_MPIPE 68 69 /* 70 * Returns true if the hardware is a type of power management domain 71 */ 72 #define PGHW_IS_PM_DOMAIN(hw) \ 73 (hw == PGHW_POW_ACTIVE || hw == PGHW_POW_IDLE) 74 75 /* 76 * Anonymous instance id 77 */ 78 #define PGHW_INSTANCE_ANON ((id_t)0xdecafbad) 79 80 /* 81 * Max length of PGHW kstat strings 82 */ 83 #define PGHW_KSTAT_STR_LEN_MAX 32 84 85 86 /* 87 * Platform specific handle 88 */ 89 typedef uintptr_t pghw_handle_t; 90 91 /* 92 * Processor Group (physical sharing relationship) 93 */ 94 typedef struct pghw { 95 pg_t pghw_pg; /* processor group */ 96 pghw_type_t pghw_hw; /* HW sharing relationship */ 97 id_t pghw_instance; /* sharing instance identifier */ 98 pghw_handle_t pghw_handle; /* hw specific opaque handle */ 99 kstat_t *pghw_kstat; /* physical kstats exported */ 100 } pghw_t; 101 102 /* 103 * IDs associating a CPU with various physical hardware 104 */ 105 typedef struct cpu_physid { 106 id_t cpu_chipid; /* CPU's physical processor */ 107 id_t cpu_coreid; /* CPU's physical core */ 108 id_t cpu_cacheid; /* CPU's cache id */ 109 } cpu_physid_t; 110 111 /* 112 * Physical PG initialization / CPU service hooks 113 */ 114 void pghw_init(pghw_t *, cpu_t *, pghw_type_t); 115 void pghw_fini(pghw_t *); 116 void pghw_cpu_add(pghw_t *, cpu_t *); 117 pghw_t *pghw_place_cpu(cpu_t *, pghw_type_t); 118 119 /* 120 * Physical ID cache creation / destruction 121 */ 122 void pghw_physid_create(cpu_t *); 123 void pghw_physid_destroy(cpu_t *); 124 125 /* 126 * CPU / PG hardware related seach operations 127 */ 128 pghw_t *pghw_find_pg(cpu_t *, pghw_type_t); 129 pghw_t *pghw_find_by_instance(id_t, pghw_type_t); 130 group_t *pghw_set_lookup(pghw_type_t); 131 132 void pghw_kstat_create(pghw_t *); 133 int pghw_kstat_update(kstat_t *, int); 134 135 /* Hardware sharing relationship platform interfaces */ 136 int pg_plat_hw_shared(cpu_t *, pghw_type_t); 137 int pg_plat_cpus_share(cpu_t *, cpu_t *, pghw_type_t); 138 id_t pg_plat_hw_instance_id(cpu_t *, pghw_type_t); 139 pghw_type_t pg_plat_hw_rank(pghw_type_t, pghw_type_t); 140 141 /* 142 * What comprises a "core" may vary across processor implementations, 143 * and so the term itself is somewhat unstable. For this reason, there 144 * is no PGHW_CORE type, but we provide an interface here to allow platforms 145 * to express cpu <=> core mappings. 146 */ 147 id_t pg_plat_get_core_id(cpu_t *); 148 149 #endif /* !_KERNEL && !_KMEMUSER */ 150 151 #ifdef __cplusplus 152 } 153 #endif 154 155 #endif /* _PGHW_H */ 156