1 /*
2  * This file contains the code to configure and utilize the ppc64 pmc hardware
3  * Copyright (C) 2002 David Engebretsen <engebret@us.ibm.com>
4  */
5 
6 #ifndef __KERNEL__
7 #define INLINE_SYSCALL(arg1, arg2)       \
8   ({                                            \
9     register long r0 __asm__ ("r0");     \
10     register long r3 __asm__ ("r3"); \
11     register long r4 __asm__ ("r4"); \
12     long ret, err;                              \
13     r0 = 208; \
14     r3 = (long) (arg1); \
15     r4 = (long) (arg2); \
16     __asm__ ("sc\n\t"                           \
17              "mfcr      %1\n\t"                 \
18              : "=r" (r3), "=r" (err)            \
19              : "r" (r0), "r" (r3), "r" (r4) \
20              : "cc", "memory");                 \
21     ret = r3;                                   \
22   })
23 #endif
24 
25 #ifndef __ASSEMBLY__
26 struct perfmon_base_struct {
27 	u64 profile_buffer;
28 	u64 profile_length;
29 	u64 trace_buffer;
30 	u64 trace_length;
31 	u64 trace_end;
32 	u64 timeslice_buffer;
33 	u64 timeslice_length;
34 	u64 state;
35 };
36 
37 struct pmc_header {
38 	int subcmd;
39 	union {
40 		int type;
41 		int pid;	/* PID to trace */
42 		int slice; 	/* Timeslice ID */
43 	} vdata;
44 	int resv[30];
45 };
46 
47 struct pmc_struct {
48         unsigned long pmc[11];
49 };
50 
51 struct pmc_info_struct {
52 	unsigned int mode, cpu;
53 
54 	unsigned int  pmc_base[11];
55 	unsigned long pmc_cumulative[8];
56 };
57 
58 struct perfmon_struct {
59 	struct pmc_header header;
60 
61 	union {
62 		struct pmc_struct      pmc;
63 		struct pmc_info_struct pmc_info;
64  	} vdata;
65 };
66 
67 enum {
68 	PMC_CMD_BUFFER       = 1,
69 	PMC_CMD_DUMP         = 2,
70 	PMC_CMD_DECR_PROFILE = 3,
71 	PMC_CMD_PROFILE      = 4,
72 	PMC_CMD_TRACE        = 5,
73 	PMC_CMD_TIMESLICE    = 6
74 };
75 
76 enum {
77 	PMC_SUBCMD_BUFFER_ALLOC         = 1,
78 	PMC_SUBCMD_BUFFER_FREE          = 2,
79 	PMC_SUBCMD_BUFFER_CLEAR         = 3
80 };
81 
82 enum {
83 	PMC_SUBCMD_DUMP_COUNTERS        = 1,
84 	PMC_SUBCMD_DUMP_HARDWARE        = 2
85 };
86 
87 enum {
88 	PMC_SUBCMD_PROFILE_CYCLE        = 1,
89 };
90 
91 enum {
92 	PMC_SUBCMD_TIMESLICE_ENABLE     = 1,
93 	PMC_SUBCMD_TIMESLICE_DISABLE    = 2,
94 	PMC_SUBCMD_TIMESLICE_SET        = 3
95 };
96 
97 #define	PMC_TRACE_CMD 0xFF
98 
99 /*
100  * The following types are not used by the kernel; they are put into the
101  * trace as flag records for the user space tools to interpret.
102  */
103 enum  {
104 	PMC_TYPE_DERC_PROFILE   = 1,
105 	PMC_TYPE_CYCLE          = 2,
106 	PMC_TYPE_PROFILE        = 3,
107 	PMC_TYPE_DCACHE         = 4,
108 	PMC_TYPE_L2_MISS        = 5,
109 	PMC_TYPE_LWARCX         = 6,
110 	PMC_TYPE_TIMESLICE      = 7,
111         PMC_TYPE_TIMESLICE_DUMP = 8,
112 	PMC_TYPE_END            = 8
113 };
114 #endif
115 
116 #define	PMC_STATE_INITIAL         0x00
117 #define	PMC_STATE_READY           0x01
118 #define	PMC_STATE_DECR_PROFILE    0x10
119 #define	PMC_STATE_PROFILE_KERN    0x11
120 #define	PMC_STATE_TRACE_KERN      0x20
121 #define	PMC_STATE_TRACE_USER      0x21
122 #define	PMC_STATE_TIMESLICE       0x40
123 
124