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