@@ -65,14 +65,14 @@ static struct attribute *format_attrs[] = {
6565 NULL ,
6666};
6767
68- static struct attribute_group format_group = {
68+ static const struct attribute_group format_group = {
6969 .name = "format" ,
7070 .attrs = format_attrs ,
7171};
7272
7373static struct attribute_group event_group = {
7474 .name = "events" ,
75- .attrs = hv_gpci_event_attrs ,
75+ /* .attrs is set in init */
7676};
7777
7878#define HV_CAPS_ATTR (_name , _format ) \
@@ -126,11 +126,11 @@ static struct attribute *cpumask_attrs[] = {
126126 NULL ,
127127};
128128
129- static struct attribute_group cpumask_attr_group = {
129+ static const struct attribute_group cpumask_attr_group = {
130130 .attrs = cpumask_attrs ,
131131};
132132
133- static struct attribute_group interface_group = {
133+ static const struct attribute_group interface_group = {
134134 .name = "interface" ,
135135 .attrs = interface_attrs ,
136136};
@@ -330,6 +330,7 @@ static int hv_gpci_init(void)
330330 int r ;
331331 unsigned long hret ;
332332 struct hv_perf_caps caps ;
333+ struct hv_gpci_request_buffer * arg ;
333334
334335 hv_gpci_assert_offsets_correct ();
335336
@@ -353,6 +354,36 @@ static int hv_gpci_init(void)
353354 /* sampling not supported */
354355 h_gpci_pmu .capabilities |= PERF_PMU_CAP_NO_INTERRUPT ;
355356
357+ arg = (void * )get_cpu_var (hv_gpci_reqb );
358+ memset (arg , 0 , HGPCI_REQ_BUFFER_SIZE );
359+
360+ /*
361+ * hcall H_GET_PERF_COUNTER_INFO populates the output
362+ * counter_info_version value based on the system hypervisor.
363+ * Pass the counter request 0x10 corresponds to request type
364+ * 'Dispatch_timebase_by_processor', to get the supported
365+ * counter_info_version.
366+ */
367+ arg -> params .counter_request = cpu_to_be32 (0x10 );
368+
369+ r = plpar_hcall_norets (H_GET_PERF_COUNTER_INFO ,
370+ virt_to_phys (arg ), HGPCI_REQ_BUFFER_SIZE );
371+ if (r ) {
372+ pr_devel ("hcall failed, can't get supported counter_info_version: 0x%x\n" , r );
373+ arg -> params .counter_info_version_out = 0x8 ;
374+ }
375+
376+ /*
377+ * Use counter_info_version_out value to assign
378+ * required hv-gpci event list.
379+ */
380+ if (arg -> params .counter_info_version_out >= 0x8 )
381+ event_group .attrs = hv_gpci_event_attrs ;
382+ else
383+ event_group .attrs = hv_gpci_event_attrs_v6 ;
384+
385+ put_cpu_var (hv_gpci_reqb );
386+
356387 r = perf_pmu_register (& h_gpci_pmu , h_gpci_pmu .name , -1 );
357388 if (r )
358389 return r ;
0 commit comments