8702 PCI addresses with physaddr > 0xffffffff can't be mapped in
[unleashed.git] / usr / src / uts / common / sys / kcpc.h
blobd90b1c1d299ef36367be6093aa5c505185e990d3
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_KCPC_H
27 #define _SYS_KCPC_H
29 #include <sys/cpc_impl.h>
30 #include <sys/ksynch.h>
31 #include <sys/types.h>
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
39 * Kernel clients need this file in order to know what a request is and how to
40 * program one.
43 typedef struct _kcpc_set kcpc_set_t;
45 #ifdef _KERNEL
48 * Forward declarations.
50 struct _kthread;
51 struct cpu;
52 typedef struct _kcpc_request kcpc_request_t;
53 struct __pcbe_ops;
55 #define KCPC_SET_BOUND 0x0001 /* Used in ks_state */
57 struct _kcpc_set {
58 int ks_flags;
59 int ks_nreqs; /* Number of reqs */
60 kcpc_request_t *ks_req; /* Pointer to reqs */
61 uint64_t *ks_data; /* Data store for this set */
62 kcpc_ctx_t *ks_ctx; /* ctx this set belongs to */
63 ushort_t ks_state; /* Set is bound or unbound */
64 kmutex_t ks_lock; /* Protects ks_state */
65 kcondvar_t ks_condv; /* Wait for bind to complete */
68 struct _kcpc_request {
69 void *kr_config;
70 int kr_index; /* indx of data for this req */
71 int kr_picnum; /* Number of phys pic */
72 kcpc_pic_t *kr_picp; /* Ptr to PIC in context */
73 uint64_t *kr_data; /* Ptr to virtual 64-bit pic */
74 char kr_event[CPC_MAX_EVENT_LEN];
75 uint64_t kr_preset;
76 uint_t kr_flags;
77 uint_t kr_nattrs;
78 kcpc_attr_t *kr_attr;
79 void *kr_ptr; /* Ptr assigned by requester */
82 typedef struct _kcpc_request_list {
83 kcpc_request_t *krl_list; /* counter event requests */
84 int krl_cnt; /* how many requests */
85 int krl_max; /* max request entries */
86 } kcpc_request_list_t;
89 * Type of update function to be called when reading counters on current CPU in
90 * kcpc_read()
92 typedef int (*kcpc_update_func_t)(void *, uint64_t);
95 * Type of read function to be called when reading counters on current CPU
96 * (ie. should be same type signature as kcpc_read())
98 typedef int (*kcpc_read_func_t)(kcpc_update_func_t);
102 * Initialize the kcpc framework
104 extern int kcpc_init(void);
107 * Bind the set to the indicated thread.
108 * Returns 0 on success, or an errno in case of error. If EINVAL is returned,
109 * a specific error code will be returned in the subcode parameter.
111 extern int kcpc_bind_thread(kcpc_set_t *set, struct _kthread *t, int *subcode);
114 * Bind the set to the indicated CPU.
115 * Same return convention as kcpc_bind_thread().
117 extern int kcpc_bind_cpu(kcpc_set_t *set, int cpuid, int *subcode);
120 * Request the system to sample the current state of the set into users buf.
122 extern int kcpc_sample(kcpc_set_t *set, uint64_t *buf, hrtime_t *hrtime,
123 uint64_t *tick);
126 * Create CPC context containing specified list of requested counter events
128 extern int kcpc_cpu_ctx_create(struct cpu *cp, kcpc_request_list_t *req_list,
129 int kmem_flags, kcpc_ctx_t ***ctx_ptr_array, size_t *ctx_ptr_array_sz);
132 * Returns whether specified counter event is supported
134 extern boolean_t kcpc_event_supported(char *event);
137 * Initialize list of CPC event requests
139 extern kcpc_request_list_t *kcpc_reqs_init(int nreqs, int kmem_flags);
142 * Add counter event request to given list of counter event requests
144 extern int kcpc_reqs_add(kcpc_request_list_t *req_list, char *event,
145 uint64_t preset, uint_t flags, uint_t nattrs, kcpc_attr_t *attr, void *ptr,
146 int kmem_flags);
149 * Reset list of CPC event requests so its space can be used for another set
150 * of requests
152 extern int kcpc_reqs_reset(kcpc_request_list_t *req_list);
155 * Free given list of counter event requests
157 extern int kcpc_reqs_fini(kcpc_request_list_t *req_list);
160 * Read CPC data for given event on current CPU
162 extern int kcpc_read(kcpc_update_func_t);
165 * Program current CPU with given CPC context
167 extern void kcpc_program(kcpc_ctx_t *ctx, boolean_t for_thread,
168 boolean_t cu_interpose);
171 * Unprogram CPC counters on current CPU
173 extern void kcpc_unprogram(kcpc_ctx_t *ctx, boolean_t cu_interpose);
176 * Unbind a request and release the associated resources.
178 extern int kcpc_unbind(kcpc_set_t *set);
181 * Preset the indicated request's counter and underlying PCBE config to the
182 * given value.
184 extern int kcpc_preset(kcpc_set_t *set, int index, uint64_t preset);
187 * Unfreeze the set and get it counting again.
189 extern int kcpc_restart(kcpc_set_t *set);
191 extern int kcpc_enable(struct _kthread *t, int cmd, int enable);
194 * Mark a thread's CPC context, if it exists, INVALID.
196 extern void kcpc_invalidate(struct _kthread *t);
198 extern int kcpc_overflow_ast(void);
199 extern uint_t kcpc_hw_overflow_intr(caddr_t, caddr_t);
200 extern int kcpc_hw_cpu_hook(int cpuid, ulong_t *kcpc_cpumap);
201 extern int kcpc_hw_lwp_hook(void);
202 extern void kcpc_idle_save(struct cpu *cp);
203 extern void kcpc_idle_restore(struct cpu *cp);
205 extern krwlock_t kcpc_cpuctx_lock; /* lock for 'kcpc_cpuctx' below */
206 extern int kcpc_cpuctx; /* number of cpu-specific contexts */
208 extern void kcpc_free(kcpc_ctx_t *ctx, int isexec);
211 * 'dtrace_cpc_in_use' contains the number of currently active cpc provider
212 * based enablings. See the block comment in uts/common/os/dtrace_subr.c for
213 * details of its actual usage.
215 extern uint32_t dtrace_cpc_in_use;
216 extern void (*dtrace_cpc_fire)(uint64_t);
218 extern void kcpc_free_set(kcpc_set_t *set);
220 extern void *kcpc_next_config(void *token, void *current,
221 uint64_t **data);
222 extern void kcpc_invalidate_config(void *token);
223 extern char *kcpc_list_attrs(void);
224 extern char *kcpc_list_events(uint_t pic);
225 extern void kcpc_free_configs(kcpc_set_t *set);
226 extern uint_t kcpc_pcbe_capabilities(void);
227 extern int kcpc_pcbe_loaded(void);
230 * Called by a PCBE to determine if nonprivileged access to counters should be
231 * allowed. Returns non-zero if non-privileged access is allowed, 0 if not.
233 extern int kcpc_allow_nonpriv(void *token);
235 extern void kcpc_register_pcbe(struct __pcbe_ops *);
237 #endif /* _KERNEL */
239 #ifdef __cplusplus
241 #endif
243 #endif /* _SYS_KCPC_H */