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 5*8d4e547dSae112802 * Common Development and Distribution License (the "License"). 6*8d4e547dSae112802 * 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*8d4e547dSae112802 * Copyright 2007 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_KCPC_H 277c478bd9Sstevel@tonic-gate #define _SYS_KCPC_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * Kernel clients need this file in order to know what a request is and how to 397c478bd9Sstevel@tonic-gate * program one. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate typedef struct _kcpc_set kcpc_set_t; 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifdef _KERNEL 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* 477c478bd9Sstevel@tonic-gate * Forward declarations. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate struct _kthread; 507c478bd9Sstevel@tonic-gate struct cpu; 517c478bd9Sstevel@tonic-gate typedef struct _kcpc_request kcpc_request_t; 527c478bd9Sstevel@tonic-gate struct __pcbe_ops; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate struct _kcpc_set { 557c478bd9Sstevel@tonic-gate int ks_flags; 567c478bd9Sstevel@tonic-gate int ks_nreqs; /* Number of reqs */ 577c478bd9Sstevel@tonic-gate kcpc_request_t *ks_req; /* Pointer to reqs */ 587c478bd9Sstevel@tonic-gate uint64_t *ks_data; /* Data store for this set */ 597c478bd9Sstevel@tonic-gate kcpc_ctx_t *ks_ctx; /* ctx this set belongs to */ 607c478bd9Sstevel@tonic-gate }; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate struct _kcpc_request { 637c478bd9Sstevel@tonic-gate void *kr_config; 647c478bd9Sstevel@tonic-gate int kr_index; /* indx of data for this req */ 657c478bd9Sstevel@tonic-gate int kr_picnum; /* Number of phys pic */ 667c478bd9Sstevel@tonic-gate kcpc_pic_t *kr_picp; /* Ptr to PIC in context */ 677c478bd9Sstevel@tonic-gate uint64_t *kr_data; /* Ptr to virtual 64-bit pic */ 687c478bd9Sstevel@tonic-gate char kr_event[CPC_MAX_EVENT_LEN]; 697c478bd9Sstevel@tonic-gate uint64_t kr_preset; 707c478bd9Sstevel@tonic-gate uint_t kr_flags; 717c478bd9Sstevel@tonic-gate uint_t kr_nattrs; 727c478bd9Sstevel@tonic-gate kcpc_attr_t *kr_attr; 737c478bd9Sstevel@tonic-gate }; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate * Bind the set to the indicated thread. 777c478bd9Sstevel@tonic-gate * Returns 0 on success, or an errno in case of error. If EINVAL is returned, 787c478bd9Sstevel@tonic-gate * a specific error code will be returned in the subcode parameter. 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate extern int kcpc_bind_thread(kcpc_set_t *set, struct _kthread *t, int *subcode); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * Bind the set to the indicated CPU. 847c478bd9Sstevel@tonic-gate * Same return convention as kcpc_bind_thread(). 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate extern int kcpc_bind_cpu(kcpc_set_t *set, int cpuid, int *subcode); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Request the system to sample the current state of the set into users buf. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate extern int kcpc_sample(kcpc_set_t *set, uint64_t *buf, hrtime_t *hrtime, 927c478bd9Sstevel@tonic-gate uint64_t *tick); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * Unbind a request and release the associated resources. 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate extern int kcpc_unbind(kcpc_set_t *set); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * Preset the indicated request's counter and underlying PCBE config to the 1017c478bd9Sstevel@tonic-gate * given value. 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate extern int kcpc_preset(kcpc_set_t *set, int index, uint64_t preset); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * Unfreeze the set and get it counting again. 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate extern int kcpc_restart(kcpc_set_t *set); 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate extern int kcpc_enable(struct _kthread *t, int cmd, int enable); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * Mark a thread's CPC context, if it exists, INVALID. 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate extern void kcpc_invalidate(struct _kthread *t); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate extern int kcpc_overflow_ast(void); 1187c478bd9Sstevel@tonic-gate extern uint_t kcpc_hw_overflow_intr(caddr_t, caddr_t); 1197c478bd9Sstevel@tonic-gate extern int kcpc_hw_cpu_hook(int cpuid, ulong_t *kcpc_cpumap); 1207c478bd9Sstevel@tonic-gate extern int kcpc_hw_lwp_hook(void); 1217c478bd9Sstevel@tonic-gate extern void kcpc_idle_save(struct cpu *cp); 1227c478bd9Sstevel@tonic-gate extern void kcpc_idle_restore(struct cpu *cp); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate extern krwlock_t kcpc_cpuctx_lock; /* lock for 'kcpc_cpuctx' below */ 1257c478bd9Sstevel@tonic-gate extern int kcpc_cpuctx; /* number of cpu-specific contexts */ 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate extern void kcpc_free_set(kcpc_set_t *set); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate extern void *kcpc_next_config(void *token, void *current, 1307c478bd9Sstevel@tonic-gate uint64_t **data); 131*8d4e547dSae112802 extern void kcpc_invalidate_config(void *token); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Called by a PCBE to determine if nonprivileged access to counters should be 1357c478bd9Sstevel@tonic-gate * allowed. Returns non-zero if non-privileged access is allowed, 0 if not. 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate extern int kcpc_allow_nonpriv(void *token); 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate extern void kcpc_register_pcbe(struct __pcbe_ops *); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate #endif 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #endif /* _SYS_KCPC_H */ 148