Tarun Karra | 1382e51 | 2017-10-30 19:41:25 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-2015, 2017 The Linux Foundation. All rights reserved. |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | #ifndef __ADRENO_PERFCOUNTER_H |
| 14 | #define __ADRENO_PERFCOUNTER_H |
| 15 | |
| 16 | #include "adreno.h" |
| 17 | |
| 18 | struct adreno_device; |
| 19 | |
| 20 | /* ADRENO_PERFCOUNTERS - Given an adreno device, return the perfcounters list */ |
| 21 | #define ADRENO_PERFCOUNTERS(_a) \ |
| 22 | (ADRENO_GPU_DEVICE(_a) ? ADRENO_GPU_DEVICE(_a)->perfcounters : NULL) |
| 23 | |
| 24 | #define PERFCOUNTER_FLAG_NONE 0x0 |
| 25 | #define PERFCOUNTER_FLAG_KERNEL 0x1 |
| 26 | |
| 27 | /* Structs to maintain the list of active performance counters */ |
| 28 | |
| 29 | /** |
| 30 | * struct adreno_perfcount_register: register state |
| 31 | * @countable: countable the register holds |
| 32 | * @kernelcount: number of user space users of the register |
| 33 | * @usercount: number of kernel users of the register |
| 34 | * @offset: register hardware offset |
| 35 | * @load_bit: The bit number in LOAD register which corresponds to this counter |
| 36 | * @select: The countable register offset |
| 37 | * @value: The 64 bit countable register value |
| 38 | */ |
| 39 | struct adreno_perfcount_register { |
| 40 | unsigned int countable; |
| 41 | unsigned int kernelcount; |
| 42 | unsigned int usercount; |
| 43 | unsigned int offset; |
| 44 | unsigned int offset_hi; |
| 45 | int load_bit; |
| 46 | unsigned int select; |
| 47 | uint64_t value; |
| 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * struct adreno_perfcount_group: registers for a hardware group |
| 52 | * @regs: available registers for this group |
| 53 | * @reg_count: total registers for this group |
| 54 | * @name: group name for this group |
| 55 | */ |
| 56 | struct adreno_perfcount_group { |
| 57 | struct adreno_perfcount_register *regs; |
| 58 | unsigned int reg_count; |
| 59 | const char *name; |
| 60 | unsigned long flags; |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * ADRENO_PERFCOUNTER_GROUP_FIXED indicates that a perfcounter group is fixed - |
| 65 | * instead of having configurable countables like the other groups, registers in |
| 66 | * fixed groups have a hardwired countable. So when the user requests a |
| 67 | * countable in one of these groups, that countable should be used as the |
| 68 | * register offset to return |
| 69 | */ |
| 70 | |
| 71 | #define ADRENO_PERFCOUNTER_GROUP_FIXED BIT(0) |
| 72 | |
Tarun Karra | 1382e51 | 2017-10-30 19:41:25 -0700 | [diff] [blame] | 73 | /* |
| 74 | * ADRENO_PERFCOUNTER_GROUP_RESTORE indicates CP needs to restore the select |
| 75 | * registers of this perfcounter group as part of preemption and IFPC |
| 76 | */ |
| 77 | #define ADRENO_PERFCOUNTER_GROUP_RESTORE BIT(1) |
| 78 | |
| 79 | |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 80 | /** |
| 81 | * adreno_perfcounts: all available perfcounter groups |
| 82 | * @groups: available groups for this device |
| 83 | * @group_count: total groups for this device |
| 84 | */ |
| 85 | struct adreno_perfcounters { |
| 86 | struct adreno_perfcount_group *groups; |
| 87 | unsigned int group_count; |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * adreno_invalid_countabless: Invalid countables that do not work properly |
| 92 | * @countables: List of unusable countables |
| 93 | * @num_countables: Number of unusable countables |
| 94 | */ |
| 95 | struct adreno_invalid_countables { |
| 96 | const unsigned int *countables; |
| 97 | int num_countables; |
| 98 | }; |
| 99 | |
| 100 | #define ADRENO_PERFCOUNTER_GROUP_FLAGS(core, offset, name, flags) \ |
| 101 | [KGSL_PERFCOUNTER_GROUP_##offset] = { core##_perfcounters_##name, \ |
| 102 | ARRAY_SIZE(core##_perfcounters_##name), __stringify(name), flags } |
| 103 | |
| 104 | #define ADRENO_PERFCOUNTER_GROUP(core, offset, name) \ |
| 105 | ADRENO_PERFCOUNTER_GROUP_FLAGS(core, offset, name, 0) |
| 106 | |
| 107 | #define ADRENO_POWER_COUNTER_GROUP(core, offset, name) \ |
| 108 | [KGSL_PERFCOUNTER_GROUP_##offset##_PWR] = { core##_pwrcounters_##name, \ |
| 109 | ARRAY_SIZE(core##_pwrcounters_##name), __stringify(name##_pwr), 0} |
| 110 | |
| 111 | #define ADRENO_PERFCOUNTER_INVALID_COUNTABLE(name, off) \ |
| 112 | [KGSL_PERFCOUNTER_GROUP_##off] = { name##_invalid_countables, \ |
| 113 | ARRAY_SIZE(name##_invalid_countables) } |
| 114 | |
| 115 | int adreno_perfcounter_query_group(struct adreno_device *adreno_dev, |
| 116 | unsigned int groupid, unsigned int __user *countables, |
| 117 | unsigned int count, unsigned int *max_counters); |
| 118 | |
| 119 | int adreno_perfcounter_read_group(struct adreno_device *adreno_dev, |
| 120 | struct kgsl_perfcounter_read_group __user *reads, unsigned int count); |
| 121 | |
| 122 | void adreno_perfcounter_close(struct adreno_device *adreno_dev); |
| 123 | |
| 124 | void adreno_perfcounter_restore(struct adreno_device *adreno_dev); |
| 125 | |
| 126 | void adreno_perfcounter_save(struct adreno_device *adreno_dev); |
| 127 | |
| 128 | void adreno_perfcounter_start(struct adreno_device *adreno_dev); |
| 129 | |
| 130 | void adreno_perfcounter_init(struct adreno_device *adreno_dev); |
| 131 | |
| 132 | int adreno_perfcounter_get_groupid(struct adreno_device *adreno_dev, |
| 133 | const char *name); |
| 134 | |
| 135 | uint64_t adreno_perfcounter_read(struct adreno_device *adreno_dev, |
| 136 | unsigned int group, unsigned int counter); |
| 137 | |
| 138 | const char *adreno_perfcounter_get_name(struct adreno_device |
| 139 | *adreno_dev, unsigned int groupid); |
| 140 | |
| 141 | int adreno_perfcounter_get(struct adreno_device *adreno_dev, |
| 142 | unsigned int groupid, unsigned int countable, unsigned int *offset, |
| 143 | unsigned int *offset_hi, unsigned int flags); |
| 144 | |
| 145 | int adreno_perfcounter_put(struct adreno_device *adreno_dev, |
| 146 | unsigned int groupid, unsigned int countable, unsigned int flags); |
| 147 | |
| 148 | #endif /* __ADRENO_PERFCOUNTER_H */ |