19c7c85f7SJonathan Kim /*
29c7c85f7SJonathan Kim * Copyright 2019 Advanced Micro Devices, Inc.
39c7c85f7SJonathan Kim *
49c7c85f7SJonathan Kim * Permission is hereby granted, free of charge, to any person obtaining a
59c7c85f7SJonathan Kim * copy of this software and associated documentation files (the "Software"),
69c7c85f7SJonathan Kim * to deal in the Software without restriction, including without limitation
79c7c85f7SJonathan Kim * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89c7c85f7SJonathan Kim * and/or sell copies of the Software, and to permit persons to whom the
99c7c85f7SJonathan Kim * Software is furnished to do so, subject to the following conditions:
109c7c85f7SJonathan Kim *
119c7c85f7SJonathan Kim * The above copyright notice and this permission notice shall be included in
129c7c85f7SJonathan Kim * all copies or substantial portions of the Software.
139c7c85f7SJonathan Kim *
149c7c85f7SJonathan Kim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
159c7c85f7SJonathan Kim * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169c7c85f7SJonathan Kim * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
179c7c85f7SJonathan Kim * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
189c7c85f7SJonathan Kim * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
199c7c85f7SJonathan Kim * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
209c7c85f7SJonathan Kim * OTHER DEALINGS IN THE SOFTWARE.
219c7c85f7SJonathan Kim *
229c7c85f7SJonathan Kim */
239c7c85f7SJonathan Kim
249c7c85f7SJonathan Kim #include <linux/perf_event.h>
259c7c85f7SJonathan Kim #include <linux/init.h>
269c7c85f7SJonathan Kim #include "amdgpu.h"
279c7c85f7SJonathan Kim #include "amdgpu_pmu.h"
289c7c85f7SJonathan Kim
299c7c85f7SJonathan Kim #define PMU_NAME_SIZE 32
30b4a7db71SJonathan Kim #define NUM_FORMATS_AMDGPU_PMU 4
31b4a7db71SJonathan Kim #define NUM_FORMATS_DF_VEGA20 3
32b4a7db71SJonathan Kim #define NUM_EVENTS_DF_VEGA20 8
33b4a7db71SJonathan Kim #define NUM_EVENT_TYPES_VEGA20 1
34b4a7db71SJonathan Kim #define NUM_EVENTS_VEGA20_XGMI 2
35b4a7db71SJonathan Kim #define NUM_EVENTS_VEGA20_MAX NUM_EVENTS_VEGA20_XGMI
36a9d17930SJonathan Kim #define NUM_EVENT_TYPES_ARCTURUS 1
37a9d17930SJonathan Kim #define NUM_EVENTS_ARCTURUS_XGMI 6
38a9d17930SJonathan Kim #define NUM_EVENTS_ARCTURUS_MAX NUM_EVENTS_ARCTURUS_XGMI
39b4a7db71SJonathan Kim
40b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute {
41b4a7db71SJonathan Kim struct device_attribute attr;
42b4a7db71SJonathan Kim const char *event_str;
43b4a7db71SJonathan Kim unsigned int type;
44b4a7db71SJonathan Kim };
459c7c85f7SJonathan Kim
469c7c85f7SJonathan Kim /* record to keep track of pmu entry per pmu type per device */
479c7c85f7SJonathan Kim struct amdgpu_pmu_entry {
489c7c85f7SJonathan Kim struct list_head entry;
499c7c85f7SJonathan Kim struct amdgpu_device *adev;
509c7c85f7SJonathan Kim struct pmu pmu;
519c7c85f7SJonathan Kim unsigned int pmu_perf_type;
52b4a7db71SJonathan Kim char *pmu_type_name;
53b4a7db71SJonathan Kim char *pmu_file_prefix;
54b4a7db71SJonathan Kim struct attribute_group fmt_attr_group;
55b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute *fmt_attr;
56b4a7db71SJonathan Kim struct attribute_group evt_attr_group;
57b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute *evt_attr;
589c7c85f7SJonathan Kim };
599c7c85f7SJonathan Kim
amdgpu_pmu_event_show(struct device * dev,struct device_attribute * attr,char * buf)60b4a7db71SJonathan Kim static ssize_t amdgpu_pmu_event_show(struct device *dev,
61b4a7db71SJonathan Kim struct device_attribute *attr, char *buf)
62b4a7db71SJonathan Kim {
63b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute *amdgpu_pmu_attr;
64b4a7db71SJonathan Kim
65b4a7db71SJonathan Kim amdgpu_pmu_attr = container_of(attr, struct amdgpu_pmu_event_attribute,
66b4a7db71SJonathan Kim attr);
67b4a7db71SJonathan Kim
68b4a7db71SJonathan Kim if (!amdgpu_pmu_attr->type)
69b4a7db71SJonathan Kim return sprintf(buf, "%s\n", amdgpu_pmu_attr->event_str);
70b4a7db71SJonathan Kim
71b4a7db71SJonathan Kim return sprintf(buf, "%s,type=0x%x\n",
72b4a7db71SJonathan Kim amdgpu_pmu_attr->event_str, amdgpu_pmu_attr->type);
73b4a7db71SJonathan Kim }
74b4a7db71SJonathan Kim
759c7c85f7SJonathan Kim static LIST_HEAD(amdgpu_pmu_list);
769c7c85f7SJonathan Kim
779c7c85f7SJonathan Kim
78b4a7db71SJonathan Kim struct amdgpu_pmu_attr {
79b4a7db71SJonathan Kim const char *name;
80b4a7db71SJonathan Kim const char *config;
81b4a7db71SJonathan Kim };
82b4a7db71SJonathan Kim
83b4a7db71SJonathan Kim struct amdgpu_pmu_type {
84b4a7db71SJonathan Kim const unsigned int type;
85b4a7db71SJonathan Kim const unsigned int num_of_type;
86b4a7db71SJonathan Kim };
87b4a7db71SJonathan Kim
88b4a7db71SJonathan Kim struct amdgpu_pmu_config {
89b4a7db71SJonathan Kim struct amdgpu_pmu_attr *formats;
90b4a7db71SJonathan Kim unsigned int num_formats;
91b4a7db71SJonathan Kim struct amdgpu_pmu_attr *events;
92b4a7db71SJonathan Kim unsigned int num_events;
93b4a7db71SJonathan Kim struct amdgpu_pmu_type *types;
94b4a7db71SJonathan Kim unsigned int num_types;
95b4a7db71SJonathan Kim };
96b4a7db71SJonathan Kim
97b4a7db71SJonathan Kim /*
98b4a7db71SJonathan Kim * Events fall under two categories:
99b4a7db71SJonathan Kim * - PMU typed
100b4a7db71SJonathan Kim * Events in /sys/bus/event_source/devices/amdgpu_<pmu_type>_<dev_num> have
101b4a7db71SJonathan Kim * performance counter operations handled by one IP <pmu_type>. Formats and
102b4a7db71SJonathan Kim * events should be defined by <pmu_type>_<asic_type>_formats and
103b4a7db71SJonathan Kim * <pmu_type>_<asic_type>_events respectively.
104b4a7db71SJonathan Kim *
105b4a7db71SJonathan Kim * - Event config typed
106b4a7db71SJonathan Kim * Events in /sys/bus/event_source/devices/amdgpu_<dev_num> have performance
107b4a7db71SJonathan Kim * counter operations that can be handled by multiple IPs dictated by their
108b4a7db71SJonathan Kim * "type" format field. Formats and events should be defined by
109b4a7db71SJonathan Kim * amdgpu_pmu_formats and <asic_type>_events respectively. Format field
110b4a7db71SJonathan Kim * "type" is generated in amdgpu_pmu_event_show and defined in
111b4a7db71SJonathan Kim * <asic_type>_event_config_types.
112b4a7db71SJonathan Kim */
113b4a7db71SJonathan Kim
114b4a7db71SJonathan Kim static struct amdgpu_pmu_attr amdgpu_pmu_formats[NUM_FORMATS_AMDGPU_PMU] = {
115b4a7db71SJonathan Kim { .name = "event", .config = "config:0-7" },
116b4a7db71SJonathan Kim { .name = "instance", .config = "config:8-15" },
117b4a7db71SJonathan Kim { .name = "umask", .config = "config:16-23"},
118b4a7db71SJonathan Kim { .name = "type", .config = "config:56-63"}
119b4a7db71SJonathan Kim };
120b4a7db71SJonathan Kim
121b4a7db71SJonathan Kim /* Vega20 events */
122b4a7db71SJonathan Kim static struct amdgpu_pmu_attr vega20_events[NUM_EVENTS_VEGA20_MAX] = {
123b4a7db71SJonathan Kim { .name = "xgmi_link0_data_outbound",
124b4a7db71SJonathan Kim .config = "event=0x7,instance=0x46,umask=0x2" },
125b4a7db71SJonathan Kim { .name = "xgmi_link1_data_outbound",
126b4a7db71SJonathan Kim .config = "event=0x7,instance=0x47,umask=0x2" }
127b4a7db71SJonathan Kim };
128b4a7db71SJonathan Kim
129b4a7db71SJonathan Kim static struct amdgpu_pmu_type vega20_types[NUM_EVENT_TYPES_VEGA20] = {
130b4a7db71SJonathan Kim { .type = AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI,
131b4a7db71SJonathan Kim .num_of_type = NUM_EVENTS_VEGA20_XGMI }
132b4a7db71SJonathan Kim };
133b4a7db71SJonathan Kim
134b4a7db71SJonathan Kim static struct amdgpu_pmu_config vega20_config = {
135b4a7db71SJonathan Kim .formats = amdgpu_pmu_formats,
136b4a7db71SJonathan Kim .num_formats = ARRAY_SIZE(amdgpu_pmu_formats),
137b4a7db71SJonathan Kim .events = vega20_events,
138b4a7db71SJonathan Kim .num_events = ARRAY_SIZE(vega20_events),
139b4a7db71SJonathan Kim .types = vega20_types,
140b4a7db71SJonathan Kim .num_types = ARRAY_SIZE(vega20_types)
141b4a7db71SJonathan Kim };
142b4a7db71SJonathan Kim
143b4a7db71SJonathan Kim /* Vega20 data fabric (DF) events */
144b4a7db71SJonathan Kim static struct amdgpu_pmu_attr df_vega20_formats[NUM_FORMATS_DF_VEGA20] = {
145b4a7db71SJonathan Kim { .name = "event", .config = "config:0-7" },
146b4a7db71SJonathan Kim { .name = "instance", .config = "config:8-15" },
147b4a7db71SJonathan Kim { .name = "umask", .config = "config:16-23"}
148b4a7db71SJonathan Kim };
149b4a7db71SJonathan Kim
150b4a7db71SJonathan Kim static struct amdgpu_pmu_attr df_vega20_events[NUM_EVENTS_DF_VEGA20] = {
151b4a7db71SJonathan Kim { .name = "cake0_pcsout_txdata",
152b4a7db71SJonathan Kim .config = "event=0x7,instance=0x46,umask=0x2" },
153b4a7db71SJonathan Kim { .name = "cake1_pcsout_txdata",
154b4a7db71SJonathan Kim .config = "event=0x7,instance=0x47,umask=0x2" },
155b4a7db71SJonathan Kim { .name = "cake0_pcsout_txmeta",
156b4a7db71SJonathan Kim .config = "event=0x7,instance=0x46,umask=0x4" },
157b4a7db71SJonathan Kim { .name = "cake1_pcsout_txmeta",
158b4a7db71SJonathan Kim .config = "event=0x7,instance=0x47,umask=0x4" },
159b4a7db71SJonathan Kim { .name = "cake0_ftiinstat_reqalloc",
160b4a7db71SJonathan Kim .config = "event=0xb,instance=0x46,umask=0x4" },
161b4a7db71SJonathan Kim { .name = "cake1_ftiinstat_reqalloc",
162b4a7db71SJonathan Kim .config = "event=0xb,instance=0x47,umask=0x4" },
163b4a7db71SJonathan Kim { .name = "cake0_ftiinstat_rspalloc",
164b4a7db71SJonathan Kim .config = "event=0xb,instance=0x46,umask=0x8" },
165b4a7db71SJonathan Kim { .name = "cake1_ftiinstat_rspalloc",
166b4a7db71SJonathan Kim .config = "event=0xb,instance=0x47,umask=0x8" }
167b4a7db71SJonathan Kim };
168b4a7db71SJonathan Kim
169b4a7db71SJonathan Kim static struct amdgpu_pmu_config df_vega20_config = {
170b4a7db71SJonathan Kim .formats = df_vega20_formats,
171b4a7db71SJonathan Kim .num_formats = ARRAY_SIZE(df_vega20_formats),
172b4a7db71SJonathan Kim .events = df_vega20_events,
173b4a7db71SJonathan Kim .num_events = ARRAY_SIZE(df_vega20_events),
174b4a7db71SJonathan Kim .types = NULL,
175b4a7db71SJonathan Kim .num_types = 0
176b4a7db71SJonathan Kim };
177b4a7db71SJonathan Kim
178a9d17930SJonathan Kim /* Arcturus events */
179a9d17930SJonathan Kim static struct amdgpu_pmu_attr arcturus_events[NUM_EVENTS_ARCTURUS_MAX] = {
180a9d17930SJonathan Kim { .name = "xgmi_link0_data_outbound",
181a9d17930SJonathan Kim .config = "event=0x7,instance=0x4b,umask=0x2" },
182a9d17930SJonathan Kim { .name = "xgmi_link1_data_outbound",
183a9d17930SJonathan Kim .config = "event=0x7,instance=0x4c,umask=0x2" },
184a9d17930SJonathan Kim { .name = "xgmi_link2_data_outbound",
185a9d17930SJonathan Kim .config = "event=0x7,instance=0x4d,umask=0x2" },
186a9d17930SJonathan Kim { .name = "xgmi_link3_data_outbound",
187a9d17930SJonathan Kim .config = "event=0x7,instance=0x4e,umask=0x2" },
188a9d17930SJonathan Kim { .name = "xgmi_link4_data_outbound",
189a9d17930SJonathan Kim .config = "event=0x7,instance=0x4f,umask=0x2" },
190a9d17930SJonathan Kim { .name = "xgmi_link5_data_outbound",
191a9d17930SJonathan Kim .config = "event=0x7,instance=0x50,umask=0x2" }
192a9d17930SJonathan Kim };
193a9d17930SJonathan Kim
194a9d17930SJonathan Kim static struct amdgpu_pmu_type arcturus_types[NUM_EVENT_TYPES_ARCTURUS] = {
195a9d17930SJonathan Kim { .type = AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI,
196a9d17930SJonathan Kim .num_of_type = NUM_EVENTS_ARCTURUS_XGMI }
197a9d17930SJonathan Kim };
198a9d17930SJonathan Kim
199a9d17930SJonathan Kim static struct amdgpu_pmu_config arcturus_config = {
200a9d17930SJonathan Kim .formats = amdgpu_pmu_formats,
201a9d17930SJonathan Kim .num_formats = ARRAY_SIZE(amdgpu_pmu_formats),
202a9d17930SJonathan Kim .events = arcturus_events,
203a9d17930SJonathan Kim .num_events = ARRAY_SIZE(arcturus_events),
204a9d17930SJonathan Kim .types = arcturus_types,
205a9d17930SJonathan Kim .num_types = ARRAY_SIZE(arcturus_types)
206a9d17930SJonathan Kim };
207a9d17930SJonathan Kim
2089c7c85f7SJonathan Kim /* initialize perf counter */
amdgpu_perf_event_init(struct perf_event * event)2099c7c85f7SJonathan Kim static int amdgpu_perf_event_init(struct perf_event *event)
2109c7c85f7SJonathan Kim {
2119c7c85f7SJonathan Kim struct hw_perf_event *hwc = &event->hw;
2129c7c85f7SJonathan Kim
2139c7c85f7SJonathan Kim /* test the event attr type check for PMU enumeration */
2149c7c85f7SJonathan Kim if (event->attr.type != event->pmu->type)
2159c7c85f7SJonathan Kim return -ENOENT;
2169c7c85f7SJonathan Kim
2179c7c85f7SJonathan Kim /* update the hw_perf_event struct with config data */
21846d1da73SJonathan Kim hwc->config = event->attr.config;
219b4a7db71SJonathan Kim hwc->config_base = AMDGPU_PMU_PERF_TYPE_NONE;
2209c7c85f7SJonathan Kim
2219c7c85f7SJonathan Kim return 0;
2229c7c85f7SJonathan Kim }
2239c7c85f7SJonathan Kim
2249c7c85f7SJonathan Kim /* start perf counter */
amdgpu_perf_start(struct perf_event * event,int flags)2259c7c85f7SJonathan Kim static void amdgpu_perf_start(struct perf_event *event, int flags)
2269c7c85f7SJonathan Kim {
2279c7c85f7SJonathan Kim struct hw_perf_event *hwc = &event->hw;
2289c7c85f7SJonathan Kim struct amdgpu_pmu_entry *pe = container_of(event->pmu,
2299c7c85f7SJonathan Kim struct amdgpu_pmu_entry,
2309c7c85f7SJonathan Kim pmu);
231576e0ec2SJonathan Kim int target_cntr = 0;
2329c7c85f7SJonathan Kim
2339c7c85f7SJonathan Kim if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
2349c7c85f7SJonathan Kim return;
2359c7c85f7SJonathan Kim
236cace4bffSHawking Zhang if ((!pe->adev->df.funcs) ||
237cace4bffSHawking Zhang (!pe->adev->df.funcs->pmc_start))
238cace4bffSHawking Zhang return;
239cace4bffSHawking Zhang
2409c7c85f7SJonathan Kim WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));
2419c7c85f7SJonathan Kim hwc->state = 0;
2429c7c85f7SJonathan Kim
243b4a7db71SJonathan Kim switch (hwc->config_base) {
244b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
245b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
246576e0ec2SJonathan Kim if (!(flags & PERF_EF_RELOAD)) {
247576e0ec2SJonathan Kim target_cntr = pe->adev->df.funcs->pmc_start(pe->adev,
248576e0ec2SJonathan Kim hwc->config, 0 /* unused */,
249576e0ec2SJonathan Kim 1 /* add counter */);
250576e0ec2SJonathan Kim if (target_cntr < 0)
251576e0ec2SJonathan Kim break;
2529c7c85f7SJonathan Kim
253576e0ec2SJonathan Kim hwc->idx = target_cntr;
254576e0ec2SJonathan Kim }
255576e0ec2SJonathan Kim
256576e0ec2SJonathan Kim pe->adev->df.funcs->pmc_start(pe->adev, hwc->config,
257576e0ec2SJonathan Kim hwc->idx, 0);
2589c7c85f7SJonathan Kim break;
2599c7c85f7SJonathan Kim default:
2609c7c85f7SJonathan Kim break;
2619c7c85f7SJonathan Kim }
2629c7c85f7SJonathan Kim
2639c7c85f7SJonathan Kim perf_event_update_userpage(event);
2649c7c85f7SJonathan Kim }
2659c7c85f7SJonathan Kim
2669c7c85f7SJonathan Kim /* read perf counter */
amdgpu_perf_read(struct perf_event * event)2679c7c85f7SJonathan Kim static void amdgpu_perf_read(struct perf_event *event)
2689c7c85f7SJonathan Kim {
2699c7c85f7SJonathan Kim struct hw_perf_event *hwc = &event->hw;
2709c7c85f7SJonathan Kim struct amdgpu_pmu_entry *pe = container_of(event->pmu,
2719c7c85f7SJonathan Kim struct amdgpu_pmu_entry,
2729c7c85f7SJonathan Kim pmu);
2739c7c85f7SJonathan Kim u64 count, prev;
2749c7c85f7SJonathan Kim
275cace4bffSHawking Zhang if ((!pe->adev->df.funcs) ||
276cace4bffSHawking Zhang (!pe->adev->df.funcs->pmc_get_count))
277cace4bffSHawking Zhang return;
278cace4bffSHawking Zhang
2799c7c85f7SJonathan Kim prev = local64_read(&hwc->prev_count);
280*9e761bffSUros Bizjak do {
281b4a7db71SJonathan Kim switch (hwc->config_base) {
282b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
283b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
284576e0ec2SJonathan Kim pe->adev->df.funcs->pmc_get_count(pe->adev,
285576e0ec2SJonathan Kim hwc->config, hwc->idx, &count);
2869c7c85f7SJonathan Kim break;
2879c7c85f7SJonathan Kim default:
2889c7c85f7SJonathan Kim count = 0;
2899c7c85f7SJonathan Kim break;
2902111a5f7Szhengbin }
291*9e761bffSUros Bizjak } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, count));
2929c7c85f7SJonathan Kim
2939c7c85f7SJonathan Kim local64_add(count - prev, &event->count);
2949c7c85f7SJonathan Kim }
2959c7c85f7SJonathan Kim
2969c7c85f7SJonathan Kim /* stop perf counter */
amdgpu_perf_stop(struct perf_event * event,int flags)2979c7c85f7SJonathan Kim static void amdgpu_perf_stop(struct perf_event *event, int flags)
2989c7c85f7SJonathan Kim {
2999c7c85f7SJonathan Kim struct hw_perf_event *hwc = &event->hw;
3009c7c85f7SJonathan Kim struct amdgpu_pmu_entry *pe = container_of(event->pmu,
3019c7c85f7SJonathan Kim struct amdgpu_pmu_entry,
3029c7c85f7SJonathan Kim pmu);
3039c7c85f7SJonathan Kim
3049c7c85f7SJonathan Kim if (hwc->state & PERF_HES_UPTODATE)
3059c7c85f7SJonathan Kim return;
3069c7c85f7SJonathan Kim
307cace4bffSHawking Zhang if ((!pe->adev->df.funcs) ||
308cace4bffSHawking Zhang (!pe->adev->df.funcs->pmc_stop))
309cace4bffSHawking Zhang return;
310cace4bffSHawking Zhang
311b4a7db71SJonathan Kim switch (hwc->config_base) {
312b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
313b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
314576e0ec2SJonathan Kim pe->adev->df.funcs->pmc_stop(pe->adev, hwc->config, hwc->idx,
315576e0ec2SJonathan Kim 0);
3169c7c85f7SJonathan Kim break;
3179c7c85f7SJonathan Kim default:
3189c7c85f7SJonathan Kim break;
3192111a5f7Szhengbin }
3209c7c85f7SJonathan Kim
3219c7c85f7SJonathan Kim WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
3229c7c85f7SJonathan Kim hwc->state |= PERF_HES_STOPPED;
3239c7c85f7SJonathan Kim
3249c7c85f7SJonathan Kim if (hwc->state & PERF_HES_UPTODATE)
3259c7c85f7SJonathan Kim return;
3269c7c85f7SJonathan Kim
3279c7c85f7SJonathan Kim amdgpu_perf_read(event);
3289c7c85f7SJonathan Kim hwc->state |= PERF_HES_UPTODATE;
3299c7c85f7SJonathan Kim }
3309c7c85f7SJonathan Kim
3319c7c85f7SJonathan Kim /* add perf counter */
amdgpu_perf_add(struct perf_event * event,int flags)3329c7c85f7SJonathan Kim static int amdgpu_perf_add(struct perf_event *event, int flags)
3339c7c85f7SJonathan Kim {
3349c7c85f7SJonathan Kim struct hw_perf_event *hwc = &event->hw;
335576e0ec2SJonathan Kim int retval = 0, target_cntr;
3369c7c85f7SJonathan Kim struct amdgpu_pmu_entry *pe = container_of(event->pmu,
3379c7c85f7SJonathan Kim struct amdgpu_pmu_entry,
3389c7c85f7SJonathan Kim pmu);
3399c7c85f7SJonathan Kim
340cace4bffSHawking Zhang if ((!pe->adev->df.funcs) ||
341cace4bffSHawking Zhang (!pe->adev->df.funcs->pmc_start))
342cace4bffSHawking Zhang return -EINVAL;
343cace4bffSHawking Zhang
344b4a7db71SJonathan Kim switch (pe->pmu_perf_type) {
345b4a7db71SJonathan Kim case AMDGPU_PMU_PERF_TYPE_DF:
346b4a7db71SJonathan Kim hwc->config_base = AMDGPU_PMU_EVENT_CONFIG_TYPE_DF;
347b4a7db71SJonathan Kim break;
348b4a7db71SJonathan Kim case AMDGPU_PMU_PERF_TYPE_ALL:
349b4a7db71SJonathan Kim hwc->config_base = (hwc->config >>
350b4a7db71SJonathan Kim AMDGPU_PMU_EVENT_CONFIG_TYPE_SHIFT) &
351b4a7db71SJonathan Kim AMDGPU_PMU_EVENT_CONFIG_TYPE_MASK;
352b4a7db71SJonathan Kim break;
353b4a7db71SJonathan Kim }
354b4a7db71SJonathan Kim
3559c7c85f7SJonathan Kim event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
3569c7c85f7SJonathan Kim
357b4a7db71SJonathan Kim switch (hwc->config_base) {
358b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
359b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
360576e0ec2SJonathan Kim target_cntr = pe->adev->df.funcs->pmc_start(pe->adev,
361576e0ec2SJonathan Kim hwc->config, 0 /* unused */,
362576e0ec2SJonathan Kim 1 /* add counter */);
363576e0ec2SJonathan Kim if (target_cntr < 0)
364576e0ec2SJonathan Kim retval = target_cntr;
365576e0ec2SJonathan Kim else
366576e0ec2SJonathan Kim hwc->idx = target_cntr;
367576e0ec2SJonathan Kim
3689c7c85f7SJonathan Kim break;
3699c7c85f7SJonathan Kim default:
3709c7c85f7SJonathan Kim return 0;
3712111a5f7Szhengbin }
3729c7c85f7SJonathan Kim
3739c7c85f7SJonathan Kim if (retval)
3749c7c85f7SJonathan Kim return retval;
3759c7c85f7SJonathan Kim
3769c7c85f7SJonathan Kim if (flags & PERF_EF_START)
3779c7c85f7SJonathan Kim amdgpu_perf_start(event, PERF_EF_RELOAD);
3789c7c85f7SJonathan Kim
3799c7c85f7SJonathan Kim return retval;
3809c7c85f7SJonathan Kim }
3819c7c85f7SJonathan Kim
3829c7c85f7SJonathan Kim /* delete perf counter */
amdgpu_perf_del(struct perf_event * event,int flags)3839c7c85f7SJonathan Kim static void amdgpu_perf_del(struct perf_event *event, int flags)
3849c7c85f7SJonathan Kim {
3859c7c85f7SJonathan Kim struct hw_perf_event *hwc = &event->hw;
3869c7c85f7SJonathan Kim struct amdgpu_pmu_entry *pe = container_of(event->pmu,
3879c7c85f7SJonathan Kim struct amdgpu_pmu_entry,
3889c7c85f7SJonathan Kim pmu);
389cace4bffSHawking Zhang if ((!pe->adev->df.funcs) ||
390cace4bffSHawking Zhang (!pe->adev->df.funcs->pmc_stop))
391cace4bffSHawking Zhang return;
3929c7c85f7SJonathan Kim
3939c7c85f7SJonathan Kim amdgpu_perf_stop(event, PERF_EF_UPDATE);
3949c7c85f7SJonathan Kim
395b4a7db71SJonathan Kim switch (hwc->config_base) {
396b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
397b4a7db71SJonathan Kim case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
398576e0ec2SJonathan Kim pe->adev->df.funcs->pmc_stop(pe->adev, hwc->config, hwc->idx,
399576e0ec2SJonathan Kim 1);
4009c7c85f7SJonathan Kim break;
4019c7c85f7SJonathan Kim default:
4029c7c85f7SJonathan Kim break;
4032111a5f7Szhengbin }
4049c7c85f7SJonathan Kim
4059c7c85f7SJonathan Kim perf_event_update_userpage(event);
4069c7c85f7SJonathan Kim }
4079c7c85f7SJonathan Kim
amdgpu_pmu_create_event_attrs_by_type(struct attribute_group * attr_group,struct amdgpu_pmu_event_attribute * pmu_attr,struct amdgpu_pmu_attr events[],int s_offset,int e_offset,unsigned int type)408b4a7db71SJonathan Kim static void amdgpu_pmu_create_event_attrs_by_type(
409b4a7db71SJonathan Kim struct attribute_group *attr_group,
410b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute *pmu_attr,
411b4a7db71SJonathan Kim struct amdgpu_pmu_attr events[],
412b4a7db71SJonathan Kim int s_offset,
413b4a7db71SJonathan Kim int e_offset,
414b4a7db71SJonathan Kim unsigned int type)
4159c7c85f7SJonathan Kim {
416b4a7db71SJonathan Kim int i;
4179c7c85f7SJonathan Kim
418b4a7db71SJonathan Kim pmu_attr += s_offset;
4199c7c85f7SJonathan Kim
420b4a7db71SJonathan Kim for (i = s_offset; i < e_offset; i++) {
421b4a7db71SJonathan Kim attr_group->attrs[i] = &pmu_attr->attr.attr;
422b4a7db71SJonathan Kim sysfs_attr_init(&pmu_attr->attr.attr);
423b4a7db71SJonathan Kim pmu_attr->attr.attr.name = events[i].name;
424b4a7db71SJonathan Kim pmu_attr->attr.attr.mode = 0444;
425b4a7db71SJonathan Kim pmu_attr->attr.show = amdgpu_pmu_event_show;
426b4a7db71SJonathan Kim pmu_attr->event_str = events[i].config;
427b4a7db71SJonathan Kim pmu_attr->type = type;
428b4a7db71SJonathan Kim pmu_attr++;
429b4a7db71SJonathan Kim }
430b4a7db71SJonathan Kim }
431b4a7db71SJonathan Kim
amdgpu_pmu_create_attrs(struct attribute_group * attr_group,struct amdgpu_pmu_event_attribute * pmu_attr,struct amdgpu_pmu_attr events[],int num_events)432b4a7db71SJonathan Kim static void amdgpu_pmu_create_attrs(struct attribute_group *attr_group,
433b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute *pmu_attr,
434b4a7db71SJonathan Kim struct amdgpu_pmu_attr events[],
435b4a7db71SJonathan Kim int num_events)
436b4a7db71SJonathan Kim {
437b4a7db71SJonathan Kim amdgpu_pmu_create_event_attrs_by_type(attr_group, pmu_attr, events, 0,
438b4a7db71SJonathan Kim num_events, AMDGPU_PMU_EVENT_CONFIG_TYPE_NONE);
439b4a7db71SJonathan Kim }
440b4a7db71SJonathan Kim
441b4a7db71SJonathan Kim
amdgpu_pmu_alloc_pmu_attrs(struct attribute_group * fmt_attr_group,struct amdgpu_pmu_event_attribute ** fmt_attr,struct attribute_group * evt_attr_group,struct amdgpu_pmu_event_attribute ** evt_attr,struct amdgpu_pmu_config * config)442b4a7db71SJonathan Kim static int amdgpu_pmu_alloc_pmu_attrs(
443b4a7db71SJonathan Kim struct attribute_group *fmt_attr_group,
444b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute **fmt_attr,
445b4a7db71SJonathan Kim struct attribute_group *evt_attr_group,
446b4a7db71SJonathan Kim struct amdgpu_pmu_event_attribute **evt_attr,
447b4a7db71SJonathan Kim struct amdgpu_pmu_config *config)
448b4a7db71SJonathan Kim {
449b4a7db71SJonathan Kim *fmt_attr = kcalloc(config->num_formats, sizeof(**fmt_attr),
450b4a7db71SJonathan Kim GFP_KERNEL);
451b4a7db71SJonathan Kim
452b4a7db71SJonathan Kim if (!(*fmt_attr))
4539c7c85f7SJonathan Kim return -ENOMEM;
4549c7c85f7SJonathan Kim
455b4a7db71SJonathan Kim fmt_attr_group->attrs = kcalloc(config->num_formats + 1,
456b4a7db71SJonathan Kim sizeof(*fmt_attr_group->attrs), GFP_KERNEL);
457b4a7db71SJonathan Kim
458b4a7db71SJonathan Kim if (!fmt_attr_group->attrs)
459b4a7db71SJonathan Kim goto err_fmt_attr_grp;
460b4a7db71SJonathan Kim
461b4a7db71SJonathan Kim *evt_attr = kcalloc(config->num_events, sizeof(**evt_attr), GFP_KERNEL);
462b4a7db71SJonathan Kim
463b4a7db71SJonathan Kim if (!(*evt_attr))
464b4a7db71SJonathan Kim goto err_evt_attr;
465b4a7db71SJonathan Kim
466b4a7db71SJonathan Kim evt_attr_group->attrs = kcalloc(config->num_events + 1,
467b4a7db71SJonathan Kim sizeof(*evt_attr_group->attrs), GFP_KERNEL);
468b4a7db71SJonathan Kim
469b4a7db71SJonathan Kim if (!evt_attr_group->attrs)
470b4a7db71SJonathan Kim goto err_evt_attr_grp;
471b4a7db71SJonathan Kim
472b4a7db71SJonathan Kim return 0;
473b4a7db71SJonathan Kim err_evt_attr_grp:
474b4a7db71SJonathan Kim kfree(*evt_attr);
475b4a7db71SJonathan Kim err_evt_attr:
476b4a7db71SJonathan Kim kfree(fmt_attr_group->attrs);
477b4a7db71SJonathan Kim err_fmt_attr_grp:
478b4a7db71SJonathan Kim kfree(*fmt_attr);
479b4a7db71SJonathan Kim return -ENOMEM;
480b4a7db71SJonathan Kim }
481b4a7db71SJonathan Kim
482b4a7db71SJonathan Kim /* init pmu tracking per pmu type */
init_pmu_entry_by_type_and_add(struct amdgpu_pmu_entry * pmu_entry,struct amdgpu_pmu_config * config)483b4a7db71SJonathan Kim static int init_pmu_entry_by_type_and_add(struct amdgpu_pmu_entry *pmu_entry,
484b4a7db71SJonathan Kim struct amdgpu_pmu_config *config)
485b4a7db71SJonathan Kim {
486b4a7db71SJonathan Kim const struct attribute_group *attr_groups[] = {
487b4a7db71SJonathan Kim &pmu_entry->fmt_attr_group,
488b4a7db71SJonathan Kim &pmu_entry->evt_attr_group,
489b4a7db71SJonathan Kim NULL
490b4a7db71SJonathan Kim };
491b4a7db71SJonathan Kim char pmu_name[PMU_NAME_SIZE];
492b4a7db71SJonathan Kim int ret = 0, total_num_events = 0;
493b4a7db71SJonathan Kim
4949c7c85f7SJonathan Kim pmu_entry->pmu = (struct pmu){
4959c7c85f7SJonathan Kim .event_init = amdgpu_perf_event_init,
4969c7c85f7SJonathan Kim .add = amdgpu_perf_add,
4979c7c85f7SJonathan Kim .del = amdgpu_perf_del,
4989c7c85f7SJonathan Kim .start = amdgpu_perf_start,
4999c7c85f7SJonathan Kim .stop = amdgpu_perf_stop,
5009c7c85f7SJonathan Kim .read = amdgpu_perf_read,
5019c7c85f7SJonathan Kim .task_ctx_nr = perf_invalid_context,
5029c7c85f7SJonathan Kim };
5039c7c85f7SJonathan Kim
504b4a7db71SJonathan Kim ret = amdgpu_pmu_alloc_pmu_attrs(&pmu_entry->fmt_attr_group,
505b4a7db71SJonathan Kim &pmu_entry->fmt_attr,
506b4a7db71SJonathan Kim &pmu_entry->evt_attr_group,
507b4a7db71SJonathan Kim &pmu_entry->evt_attr,
508b4a7db71SJonathan Kim config);
509b4a7db71SJonathan Kim
510b4a7db71SJonathan Kim if (ret)
511b4a7db71SJonathan Kim goto err_out;
512b4a7db71SJonathan Kim
513b4a7db71SJonathan Kim amdgpu_pmu_create_attrs(&pmu_entry->fmt_attr_group, pmu_entry->fmt_attr,
514b4a7db71SJonathan Kim config->formats, config->num_formats);
515b4a7db71SJonathan Kim
516b4a7db71SJonathan Kim if (pmu_entry->pmu_perf_type == AMDGPU_PMU_PERF_TYPE_ALL) {
517b4a7db71SJonathan Kim int i;
518b4a7db71SJonathan Kim
519b4a7db71SJonathan Kim for (i = 0; i < config->num_types; i++) {
520b4a7db71SJonathan Kim amdgpu_pmu_create_event_attrs_by_type(
521b4a7db71SJonathan Kim &pmu_entry->evt_attr_group,
522b4a7db71SJonathan Kim pmu_entry->evt_attr,
523b4a7db71SJonathan Kim config->events,
524b4a7db71SJonathan Kim total_num_events,
525b4a7db71SJonathan Kim total_num_events +
526b4a7db71SJonathan Kim config->types[i].num_of_type,
527b4a7db71SJonathan Kim config->types[i].type);
528b4a7db71SJonathan Kim total_num_events += config->types[i].num_of_type;
529b4a7db71SJonathan Kim }
530b4a7db71SJonathan Kim } else {
531b4a7db71SJonathan Kim amdgpu_pmu_create_attrs(&pmu_entry->evt_attr_group,
532b4a7db71SJonathan Kim pmu_entry->evt_attr,
533b4a7db71SJonathan Kim config->events, config->num_events);
534b4a7db71SJonathan Kim total_num_events = config->num_events;
535b4a7db71SJonathan Kim }
536b4a7db71SJonathan Kim
537b4a7db71SJonathan Kim pmu_entry->pmu.attr_groups = kmemdup(attr_groups, sizeof(attr_groups),
538b4a7db71SJonathan Kim GFP_KERNEL);
539b4a7db71SJonathan Kim
54090cb3d8aSDan Carpenter if (!pmu_entry->pmu.attr_groups) {
54190cb3d8aSDan Carpenter ret = -ENOMEM;
542b4a7db71SJonathan Kim goto err_attr_group;
54390cb3d8aSDan Carpenter }
544b4a7db71SJonathan Kim
545b4a7db71SJonathan Kim snprintf(pmu_name, PMU_NAME_SIZE, "%s_%d", pmu_entry->pmu_file_prefix,
546b4a7db71SJonathan Kim adev_to_drm(pmu_entry->adev)->primary->index);
5479c7c85f7SJonathan Kim
5489c7c85f7SJonathan Kim ret = perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
5499c7c85f7SJonathan Kim
550b4a7db71SJonathan Kim if (ret)
551b4a7db71SJonathan Kim goto err_register;
5529c7c85f7SJonathan Kim
553b4a7db71SJonathan Kim if (pmu_entry->pmu_perf_type != AMDGPU_PMU_PERF_TYPE_ALL)
5549c7c85f7SJonathan Kim pr_info("Detected AMDGPU %s Counters. # of Counters = %d.\n",
555b4a7db71SJonathan Kim pmu_entry->pmu_type_name, total_num_events);
556b4a7db71SJonathan Kim else
557b4a7db71SJonathan Kim pr_info("Detected AMDGPU %d Perf Events.\n", total_num_events);
558b4a7db71SJonathan Kim
5599c7c85f7SJonathan Kim
5609c7c85f7SJonathan Kim list_add_tail(&pmu_entry->entry, &amdgpu_pmu_list);
5619c7c85f7SJonathan Kim
5629c7c85f7SJonathan Kim return 0;
563b4a7db71SJonathan Kim err_register:
564b4a7db71SJonathan Kim kfree(pmu_entry->pmu.attr_groups);
565b4a7db71SJonathan Kim err_attr_group:
566b4a7db71SJonathan Kim kfree(pmu_entry->fmt_attr_group.attrs);
567b4a7db71SJonathan Kim kfree(pmu_entry->fmt_attr);
568b4a7db71SJonathan Kim kfree(pmu_entry->evt_attr_group.attrs);
569b4a7db71SJonathan Kim kfree(pmu_entry->evt_attr);
570b4a7db71SJonathan Kim err_out:
571b4a7db71SJonathan Kim pr_warn("Error initializing AMDGPU %s PMUs.\n",
572b4a7db71SJonathan Kim pmu_entry->pmu_type_name);
573b4a7db71SJonathan Kim return ret;
5749c7c85f7SJonathan Kim }
5759c7c85f7SJonathan Kim
5769c7c85f7SJonathan Kim /* destroy all pmu data associated with target device */
amdgpu_pmu_fini(struct amdgpu_device * adev)5779c7c85f7SJonathan Kim void amdgpu_pmu_fini(struct amdgpu_device *adev)
5789c7c85f7SJonathan Kim {
5799c7c85f7SJonathan Kim struct amdgpu_pmu_entry *pe, *temp;
5809c7c85f7SJonathan Kim
5819c7c85f7SJonathan Kim list_for_each_entry_safe(pe, temp, &amdgpu_pmu_list, entry) {
582b4a7db71SJonathan Kim if (pe->adev != adev)
583b4a7db71SJonathan Kim continue;
5849c7c85f7SJonathan Kim list_del(&pe->entry);
5859c7c85f7SJonathan Kim perf_pmu_unregister(&pe->pmu);
586b4a7db71SJonathan Kim kfree(pe->pmu.attr_groups);
587b4a7db71SJonathan Kim kfree(pe->fmt_attr_group.attrs);
588b4a7db71SJonathan Kim kfree(pe->fmt_attr);
589b4a7db71SJonathan Kim kfree(pe->evt_attr_group.attrs);
590b4a7db71SJonathan Kim kfree(pe->evt_attr);
5919c7c85f7SJonathan Kim kfree(pe);
5929c7c85f7SJonathan Kim }
5939c7c85f7SJonathan Kim }
594b4a7db71SJonathan Kim
create_pmu_entry(struct amdgpu_device * adev,unsigned int pmu_type,char * pmu_type_name,char * pmu_file_prefix)595b4a7db71SJonathan Kim static struct amdgpu_pmu_entry *create_pmu_entry(struct amdgpu_device *adev,
596b4a7db71SJonathan Kim unsigned int pmu_type,
597b4a7db71SJonathan Kim char *pmu_type_name,
598b4a7db71SJonathan Kim char *pmu_file_prefix)
599b4a7db71SJonathan Kim {
600b4a7db71SJonathan Kim struct amdgpu_pmu_entry *pmu_entry;
601b4a7db71SJonathan Kim
602b4a7db71SJonathan Kim pmu_entry = kzalloc(sizeof(struct amdgpu_pmu_entry), GFP_KERNEL);
603b4a7db71SJonathan Kim
604b4a7db71SJonathan Kim if (!pmu_entry)
605b4a7db71SJonathan Kim return pmu_entry;
606b4a7db71SJonathan Kim
607b4a7db71SJonathan Kim pmu_entry->adev = adev;
608b4a7db71SJonathan Kim pmu_entry->fmt_attr_group.name = "format";
609b4a7db71SJonathan Kim pmu_entry->fmt_attr_group.attrs = NULL;
610b4a7db71SJonathan Kim pmu_entry->evt_attr_group.name = "events";
611b4a7db71SJonathan Kim pmu_entry->evt_attr_group.attrs = NULL;
612b4a7db71SJonathan Kim pmu_entry->pmu_perf_type = pmu_type;
613b4a7db71SJonathan Kim pmu_entry->pmu_type_name = pmu_type_name;
614b4a7db71SJonathan Kim pmu_entry->pmu_file_prefix = pmu_file_prefix;
615b4a7db71SJonathan Kim
616b4a7db71SJonathan Kim return pmu_entry;
617b4a7db71SJonathan Kim }
618b4a7db71SJonathan Kim
619b4a7db71SJonathan Kim /* init amdgpu_pmu */
amdgpu_pmu_init(struct amdgpu_device * adev)620b4a7db71SJonathan Kim int amdgpu_pmu_init(struct amdgpu_device *adev)
621b4a7db71SJonathan Kim {
622b4a7db71SJonathan Kim int ret = 0;
623b4a7db71SJonathan Kim struct amdgpu_pmu_entry *pmu_entry, *pmu_entry_df;
624b4a7db71SJonathan Kim
625b4a7db71SJonathan Kim switch (adev->asic_type) {
626b4a7db71SJonathan Kim case CHIP_VEGA20:
627b4a7db71SJonathan Kim pmu_entry_df = create_pmu_entry(adev, AMDGPU_PMU_PERF_TYPE_DF,
628b4a7db71SJonathan Kim "DF", "amdgpu_df");
629b4a7db71SJonathan Kim
630b4a7db71SJonathan Kim if (!pmu_entry_df)
631b4a7db71SJonathan Kim return -ENOMEM;
632b4a7db71SJonathan Kim
633b4a7db71SJonathan Kim ret = init_pmu_entry_by_type_and_add(pmu_entry_df,
634b4a7db71SJonathan Kim &df_vega20_config);
635b4a7db71SJonathan Kim
636b4a7db71SJonathan Kim if (ret) {
637b4a7db71SJonathan Kim kfree(pmu_entry_df);
638b4a7db71SJonathan Kim return ret;
639b4a7db71SJonathan Kim }
640b4a7db71SJonathan Kim
641b4a7db71SJonathan Kim pmu_entry = create_pmu_entry(adev, AMDGPU_PMU_PERF_TYPE_ALL,
642b4a7db71SJonathan Kim "", "amdgpu");
643b4a7db71SJonathan Kim
644b4a7db71SJonathan Kim if (!pmu_entry) {
645b4a7db71SJonathan Kim amdgpu_pmu_fini(adev);
646b4a7db71SJonathan Kim return -ENOMEM;
647b4a7db71SJonathan Kim }
648b4a7db71SJonathan Kim
649b4a7db71SJonathan Kim ret = init_pmu_entry_by_type_and_add(pmu_entry,
650b4a7db71SJonathan Kim &vega20_config);
651b4a7db71SJonathan Kim
652b4a7db71SJonathan Kim if (ret) {
653b4a7db71SJonathan Kim kfree(pmu_entry);
654b4a7db71SJonathan Kim amdgpu_pmu_fini(adev);
655b4a7db71SJonathan Kim return ret;
656b4a7db71SJonathan Kim }
657b4a7db71SJonathan Kim
658b4a7db71SJonathan Kim break;
659a9d17930SJonathan Kim case CHIP_ARCTURUS:
660a9d17930SJonathan Kim pmu_entry = create_pmu_entry(adev, AMDGPU_PMU_PERF_TYPE_ALL,
661a9d17930SJonathan Kim "", "amdgpu");
662a9d17930SJonathan Kim if (!pmu_entry)
663a9d17930SJonathan Kim return -ENOMEM;
664a9d17930SJonathan Kim
665a9d17930SJonathan Kim ret = init_pmu_entry_by_type_and_add(pmu_entry,
666a9d17930SJonathan Kim &arcturus_config);
667a9d17930SJonathan Kim
668a9d17930SJonathan Kim if (ret) {
669a9d17930SJonathan Kim kfree(pmu_entry);
670a9d17930SJonathan Kim return -ENOMEM;
671a9d17930SJonathan Kim }
672a9d17930SJonathan Kim
673a9d17930SJonathan Kim break;
674a9d17930SJonathan Kim
675b4a7db71SJonathan Kim default:
676b4a7db71SJonathan Kim return 0;
677206b7372Skernel test robot }
678b4a7db71SJonathan Kim
679b4a7db71SJonathan Kim return ret;
6809c7c85f7SJonathan Kim }
681