xref: /titanic_44/usr/src/uts/common/sys/kcpc.h (revision b7f45089ccbe01bab3d7c7377b49d80d2ae18a69)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_KCPC_H
28 #define	_SYS_KCPC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/cpc_impl.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Kernel clients need this file in order to know what a request is and how to
40  * program one.
41  */
42 
43 typedef struct _kcpc_set kcpc_set_t;
44 
45 #ifdef _KERNEL
46 
47 /*
48  * Forward declarations.
49  */
50 struct _kthread;
51 struct cpu;
52 typedef struct _kcpc_request kcpc_request_t;
53 struct __pcbe_ops;
54 
55 struct _kcpc_set {
56 	int			ks_flags;
57 	int			ks_nreqs;	/* Number of reqs */
58 	kcpc_request_t		*ks_req;	/* Pointer to reqs */
59 	uint64_t		*ks_data;	/* Data store for this set */
60 	kcpc_ctx_t		*ks_ctx;	/* ctx this set belongs to */
61 };
62 
63 struct _kcpc_request {
64 	void			*kr_config;
65 	int			kr_index;	/* indx of data for this req */
66 	int			kr_picnum;	/* Number of phys pic */
67 	kcpc_pic_t		*kr_picp;	/* Ptr to PIC in context */
68 	uint64_t		*kr_data;	/* Ptr to virtual 64-bit pic */
69 	char			kr_event[CPC_MAX_EVENT_LEN];
70 	uint64_t		kr_preset;
71 	uint_t			kr_flags;
72 	uint_t			kr_nattrs;
73 	kcpc_attr_t		*kr_attr;
74 };
75 
76 /*
77  * Bind the set to the indicated thread.
78  * Returns 0 on success, or an errno in case of error. If EINVAL is returned,
79  * a specific error code will be returned in the subcode parameter.
80  */
81 extern int kcpc_bind_thread(kcpc_set_t *set, struct _kthread *t, int *subcode);
82 
83 /*
84  * Bind the set to the indicated CPU.
85  * Same return convention as kcpc_bind_thread().
86  */
87 extern int kcpc_bind_cpu(kcpc_set_t *set, int cpuid, int *subcode);
88 
89 /*
90  * Request the system to sample the current state of the set into users buf.
91  */
92 extern int kcpc_sample(kcpc_set_t *set, uint64_t *buf, hrtime_t *hrtime,
93     uint64_t *tick);
94 
95 /*
96  * Unbind a request and release the associated resources.
97  */
98 extern int kcpc_unbind(kcpc_set_t *set);
99 
100 /*
101  * Preset the indicated request's counter and underlying PCBE config to the
102  * given value.
103  */
104 extern int kcpc_preset(kcpc_set_t *set, int index, uint64_t preset);
105 
106 /*
107  * Unfreeze the set and get it counting again.
108  */
109 extern int kcpc_restart(kcpc_set_t *set);
110 
111 extern int kcpc_enable(struct _kthread *t, int cmd, int enable);
112 
113 /*
114  * Mark a thread's CPC context, if it exists, INVALID.
115  */
116 extern void kcpc_invalidate(struct _kthread *t);
117 
118 extern int kcpc_overflow_ast(void);
119 extern uint_t kcpc_hw_overflow_intr(caddr_t, caddr_t);
120 extern int kcpc_hw_cpu_hook(int cpuid, ulong_t *kcpc_cpumap);
121 extern int kcpc_hw_lwp_hook(void);
122 extern void kcpc_idle_save(struct cpu *cp);
123 extern void kcpc_idle_restore(struct cpu *cp);
124 
125 extern krwlock_t	kcpc_cpuctx_lock;  /* lock for 'kcpc_cpuctx' below */
126 extern int		kcpc_cpuctx;	   /* number of cpu-specific contexts */
127 
128 extern void kcpc_free_set(kcpc_set_t *set);
129 
130 extern void *kcpc_next_config(void *token, void *current,
131     uint64_t **data);
132 
133 /*
134  * Called by a PCBE to determine if nonprivileged access to counters should be
135  * allowed. Returns non-zero if non-privileged access is allowed, 0 if not.
136  */
137 extern int kcpc_allow_nonpriv(void *token);
138 
139 extern void kcpc_register_pcbe(struct __pcbe_ops *);
140 
141 #endif /* _KERNEL */
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif /* _SYS_KCPC_H */
148