]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/hw_perfmon.h
3464b676a36eed7387e574a7558332faea1ec890
[apple/xnu.git] / osfmk / ppc / hw_perfmon.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 #ifndef _HW_PERFMON_H_
31 #define _HW_PERFMON_H_
32
33 #ifndef __ppc__
34 #error This file is only useful on PowerPC.
35 #endif
36
37 #define MAX_CPUPMC_COUNT 8
38
39 #define PMC_1 0
40 #define PMC_2 1
41 #define PMC_3 2
42 #define PMC_4 3
43 #define PMC_5 4
44 #define PMC_6 5
45 #define PMC_7 6
46 #define PMC_8 7
47
48 /* these actions can be combined and simultaneously performed with a single call to perfmon_control() */
49 typedef enum {
50 PPC_PERFMON_CLEAR_COUNTERS = 0x0002,
51 PPC_PERFMON_START_COUNTERS = 0x0004,
52 PPC_PERFMON_STOP_COUNTERS = 0x0008,
53 PPC_PERFMON_READ_COUNTERS = 0x0010,
54 PPC_PERFMON_WRITE_COUNTERS = 0x0020
55 } perfmon_multi_action_t;
56
57 /* these actions can not be combined and each requires a separate call to perfmon_control() */
58 typedef enum {
59 PPC_PERFMON_ENABLE = 0x00010000,
60 PPC_PERFMON_DISABLE = 0x00020000,
61 PPC_PERFMON_SET_EVENT = 0x00030000,
62 PPC_PERFMON_SET_THRESHOLD = 0x00040000,
63 PPC_PERFMON_SET_TBSEL = 0x00050000,
64 PPC_PERFMON_SET_EVENT_FUNC = 0x00060000,
65 PPC_PERFMON_ENABLE_PMI_BRKPT = 0x00070000
66 } perfmon_single_action_t;
67
68 /* used to select byte lane and speculative events (currently 970 only) */
69 typedef enum { /* SPECSEL[0:1] TD_CP_DBGxSEL[0:1] TTM3SEL[0:1] TTM1SEL[0:1] TTM0SEL[0:1] */
70 PPC_PERFMON_FUNC_FPU = 0, /* 00 00 00 00 00 */
71 PPC_PERFMON_FUNC_ISU = 1, /* 00 00 00 00 01 */
72 PPC_PERFMON_FUNC_IFU = 2, /* 00 00 00 00 10 */
73 PPC_PERFMON_FUNC_VMX = 3, /* 00 00 00 00 11 */
74 PPC_PERFMON_FUNC_IDU = 64, /* 00 01 00 00 00 */
75 PPC_PERFMON_FUNC_GPS = 76, /* 00 01 00 11 00 */
76 PPC_PERFMON_FUNC_LSU0 = 128, /* 00 10 00 00 00 */
77 PPC_PERFMON_FUNC_LSU1A = 192, /* 00 11 00 00 00 */
78 PPC_PERFMON_FUNC_LSU1B = 240, /* 00 11 11 00 00 */
79 PPC_PERFMON_FUNC_SPECA = 256, /* 01 00 00 00 00 */
80 PPC_PERFMON_FUNC_SPECB = 512, /* 10 00 00 00 00 */
81 PPC_PERFMON_FUNC_SPECC = 768, /* 11 00 00 00 00 */
82 } perfmon_functional_unit_t;
83
84 #ifdef MACH_KERNEL_PRIVATE
85 int perfmon_acquire_facility(task_t task);
86 int perfmon_release_facility(task_t task);
87
88 extern int perfmon_disable(thread_t thr_act);
89 extern int perfmon_init(void);
90 extern int perfmon_control(struct savearea *save);
91 extern int perfmon_handle_pmi(struct savearea *ssp);
92
93 /* perfmonFlags */
94 #define PERFMONFLAG_BREAKPOINT_FOR_PMI 0x1
95
96 #endif /* MACH_KERNEL_PRIVATE */
97
98 /*
99 * From user space:
100 *
101 * int perfmon_control(thread_t thread, perfmon_action_t action, int pmc, u_int32_t val, u_int64_t *pmcs);
102 *
103 * r3: thread
104 * r4: action
105 * r5: pmc
106 * r6: event/threshold/tbsel/count
107 * r7: pointer to space for PMC counts: uint64_t[MAX_CPUPMC_COUNT]
108 *
109 * perfmon_control(thread, PPC_PERFMON_CLEAR_COUNTERS, 0, 0, NULL);
110 * perfmon_control(thread, PPC_PERFMON_START_COUNTERS, 0, 0, NULL);
111 * perfmon_control(thread, PPC_PERFMON_STOP_COUNTERS, 0, 0, NULL);
112 * perfmon_control(thread, PPC_PERFMON_READ_COUNTERS, 0, 0, uint64_t *pmcs);
113 * perfmon_control(thread, PPC_PERFMON_WRITE_COUNTERS, 0, 0, uint64_t *pmcs);
114 * perfmon_control(thread, PPC_PERFMON_ENABLE, 0, 0, NULL);
115 * perfmon_control(thread, PPC_PERFMON_DISABLE, 0, 0, NULL);
116 * perfmon_control(thread, PPC_PERFMON_SET_EVENT, int pmc, int event, NULL);
117 * perfmon_control(thread, PPC_PERFMON_SET_THRESHOLD, 0, int threshold, NULL);
118 * perfmon_control(thread, PPC_PERFMON_SET_TBSEL, 0, int tbsel, NULL);
119 * perfmon_control(thread, PPC_PERFMON_SET_EVENT_FUNC, 0, perfmon_functional_unit_t func, NULL);
120 * perfmon_control(thread, PPC_PERFMON_ENABLE_PMI_BRKPT, 0, boolean_t enable, NULL);
121 *
122 */
123
124 #endif /* _HW_PERFMON_H_ */