#include "../../../util/cpumap.h"
 #include "../../../util/pmu.h"
 
-const struct pmu_event *pmu_events_table__find(void)
+const struct pmu_events_table *pmu_events_table__find(void)
 {
        struct perf_pmu *pmu = NULL;
 
 
        },
 };
 
+/* Struct used to make the PMU event table implementation opaque to callers. */
+struct pmu_events_table {
+       const struct pmu_event *entries;
+};
 
 /*
  * Map a CPU to its table of PMU events. The CPU is identified by the
 struct pmu_events_map {
        const char *arch;
        const char *cpuid;
-       const struct pmu_event *table;
+       const struct pmu_events_table table;
 };
 
 /*
        {
                .arch = "testarch",
                .cpuid = "testcpu",
-               .table = pme_test_soc_cpu,
+               .table = { pme_test_soc_cpu },
        },
        {
                .arch = 0,
                .cpuid = 0,
-               .table = 0,
+               .table = { 0 },
        },
 };
 
 
 struct pmu_sys_events {
        const char *name;
-       const struct pmu_event *table;
+       const struct pmu_events_table table;
 };
 
 static const struct pmu_sys_events pmu_sys_event_tables[] = {
        {
-               .table = pme_test_soc_sys,
+               .table = { pme_test_soc_sys },
                .name = "pme_test_soc_sys",
        },
        {
-               .table = 0
+               .table = { 0 }
        },
 };
 
-int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
+int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
                                    void *data)
 {
-       for (const struct pmu_event *pe = &table[0];
+       for (const struct pmu_event *pe = &table->entries[0];
             pe->name || pe->metric_group || pe->metric_name;
             pe++) {
                int ret = fn(pe, table, data);
        return 0;
 }
 
-const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
+const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
 {
-       const struct pmu_event *table = NULL;
+       const struct pmu_events_table *table = NULL;
        char *cpuid = perf_pmu__getcpuid(pmu);
        int i;
 
        for (;;) {
                const struct pmu_events_map *map = &pmu_events_map[i++];
 
-               if (!map->table)
+               if (!map->cpuid)
                        break;
 
                if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
-                       table = map->table;
+                       table = &map->table;
                        break;
                }
        }
        return table;
 }
 
-const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
+const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
 {
        for (const struct pmu_events_map *tables = &pmu_events_map[0];
-            tables->table;
+            tables->arch;
             tables++) {
                if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
-                       return tables->table;
+                       return &tables->table;
        }
        return NULL;
 }
 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
 {
        for (const struct pmu_events_map *tables = &pmu_events_map[0];
-            tables->table;
+            tables->arch;
             tables++) {
-               int ret = pmu_events_table_for_each_event(tables->table, fn, data);
+               int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
 
                if (ret)
                        return ret;
        return 0;
 }
 
-const struct pmu_event *find_sys_events_table(const char *name)
+const struct pmu_events_table *find_sys_events_table(const char *name)
 {
        for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
             tables->name;
             tables++) {
                if (!strcmp(tables->name, name))
-                       return tables->table;
+                       return &tables->table;
        }
        return NULL;
 }
        for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
             tables->name;
             tables++) {
-               int ret = pmu_events_table_for_each_event(tables->table, fn, data);
+               int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
 
                if (ret)
                        return ret;
 
 def print_mapping_table(archs: Sequence[str]) -> None:
   """Read the mapfile and generate the struct from cpuid string to event table."""
   _args.output_file.write("""
+/* Struct used to make the PMU event table implementation opaque to callers. */
+struct pmu_events_table {
+        const struct pmu_event *entries;
+};
+
 /*
  * Map a CPU to its table of PMU events. The CPU is identified by the
  * cpuid field, which is an arch-specific identifier for the CPU.
 struct pmu_events_map {
         const char *arch;
         const char *cpuid;
-        const struct pmu_event *table;
+        struct pmu_events_table table;
 };
 
 /*
       _args.output_file.write("""{
 \t.arch = "testarch",
 \t.cpuid = "testcpu",
-\t.table = pme_test_soc_cpu,
+\t.table = { pme_test_soc_cpu },
 },
 """)
     else:
             _args.output_file.write(f"""{{
 \t.arch = "{arch}",
 \t.cpuid = "{cpuid}",
-\t.table = {tblname}
+\t.table = {{ {tblname} }}
 }},
 """)
           first = False
   _args.output_file.write("""{
 \t.arch = 0,
 \t.cpuid = 0,
-\t.table = 0,
+\t.table = { 0 },
 }
 };
 """)
   _args.output_file.write("""
 struct pmu_sys_events {
 \tconst char *name;
-\tconst struct pmu_event *table;
+\tstruct pmu_events_table table;
 };
 
 static const struct pmu_sys_events pmu_sys_event_tables[] = {
 """)
   for tblname in _sys_event_tables:
     _args.output_file.write(f"""\t{{
-\t\t.table = {tblname},
+\t\t.table = {{ {tblname} }},
 \t\t.name = \"{tblname}\",
 \t}},
 """)
   _args.output_file.write("""\t{
-\t\t.table = 0
+\t\t.table = { 0 }
 \t},
 };
 
-int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
+int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
                                     void *data)
 {
-        for (const struct pmu_event *pe = &table[0];
+        for (const struct pmu_event *pe = &table->entries[0];
              pe->name || pe->metric_group || pe->metric_name;
              pe++) {
                 int ret = fn(pe, table, data);
         return 0;
 }
 
-const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
+const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
 {
-        const struct pmu_event *table = NULL;
+        const struct pmu_events_table *table = NULL;
         char *cpuid = perf_pmu__getcpuid(pmu);
         int i;
 
         i = 0;
         for (;;) {
                 const struct pmu_events_map *map = &pmu_events_map[i++];
-                if (!map->table)
+                if (!map->arch)
                         break;
 
                 if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
-                        table = map->table;
+                        table = &map->table;
                         break;
                 }
         }
         return table;
 }
 
-const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
+const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
 {
         for (const struct pmu_events_map *tables = &pmu_events_map[0];
-             tables->table;
+             tables->arch;
              tables++) {
                 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
-                        return tables->table;
+                        return &tables->table;
         }
         return NULL;
 }
 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
 {
         for (const struct pmu_events_map *tables = &pmu_events_map[0];
-             tables->table;
+             tables->arch;
              tables++) {
-                int ret = pmu_events_table_for_each_event(tables->table, fn, data);
+                int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
 
                 if (ret)
                         return ret;
         return 0;
 }
 
-const struct pmu_event *find_sys_events_table(const char *name)
+const struct pmu_events_table *find_sys_events_table(const char *name)
 {
         for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
              tables->name;
              tables++) {
                 if (!strcmp(tables->name, name))
-                        return tables->table;
+                        return &tables->table;
         }
         return NULL;
 }
         for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
              tables->name;
              tables++) {
-                int ret = pmu_events_table_for_each_event(tables->table, fn, data);
+                int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
 
                 if (ret)
                         return ret;
 
        const char *metric_constraint;
 };
 
+struct pmu_events_table;
+
 typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe,
-                                const struct pmu_event *table,
+                                const struct pmu_events_table *table,
                                 void *data);
 
-int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
+int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
                                    void *data);
 
-const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu);
-const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid);
+const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu);
+const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid);
 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data);
 
-const struct pmu_event *find_sys_events_table(const char *name);
+const struct pmu_events_table *find_sys_events_table(const char *name);
 int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data);
 
 #endif
 
        struct evlist *evlist;
        struct rblist metric_events;
        const char metric_str[] = "CPI";
-       const struct pmu_event *pme_test;
+       const struct pmu_events_table *pme_test;
 
        evlist = evlist__new();
        TEST_ASSERT_VAL("failed to get evlist", evlist);
 
        struct rblist metric_events = {
                .nr_entries = 0,
        };
-       const struct pmu_event *pme_test;
+       const struct pmu_events_table *pme_test;
        struct perf_cpu_map *cpus;
        struct runtime_stat st;
        struct evlist *evlist;
 
 }
 
 static int test__pmu_event_table_core_callback(const struct pmu_event *pe,
-                                              const struct pmu_event *table __maybe_unused,
+                                              const struct pmu_events_table *table __maybe_unused,
                                               void *data)
 {
        int *map_events = data;
 }
 
 static int test__pmu_event_table_sys_callback(const struct pmu_event *pe,
-                                             const struct pmu_event *table __maybe_unused,
+                                             const struct pmu_events_table *table __maybe_unused,
                                              void *data)
 {
        int *map_events = data;
 static int test__pmu_event_table(struct test_suite *test __maybe_unused,
                                 int subtest __maybe_unused)
 {
-       const struct pmu_event *sys_event_table = find_sys_events_table("pme_test_soc_sys");
-       const struct pmu_event *table = find_core_events_table("testarch", "testcpu");
+       const struct pmu_events_table *sys_event_table = find_sys_events_table("pme_test_soc_sys");
+       const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu");
        int map_events = 0, expected_events, err;
 
        /* ignore 3x sentinels */
        struct perf_pmu *pmu;
        LIST_HEAD(aliases);
        int res = 0;
-       const struct pmu_event *table = find_core_events_table("testarch", "testcpu");
+       const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu");
        struct perf_pmu_alias *a, *tmp;
 
        if (!table)
        struct perf_pmu *pmu = &test_pmu->pmu;
        const char *pmu_name = pmu->name;
        struct perf_pmu_alias *a, *tmp, *alias;
-       const struct pmu_event *events_table;
+       const struct pmu_events_table *events_table;
        LIST_HEAD(aliases);
        int res = 0;
 
        struct metric_ref metric_ref;
 };
 
-static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_event *table,
+static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_events_table *table,
                                  void *data)
 {
        int *failures = data;
 }
 
 static int test__parsing_fake_callback(const struct pmu_event *pe,
-                                      const struct pmu_event *table __maybe_unused,
+                                      const struct pmu_events_table *table __maybe_unused,
                                       void *data __maybe_unused)
 {
        if (!pe->metric_expr)
 
 };
 
 static int metricgroup__sys_event_iter(const struct pmu_event *pe,
-                                      const struct pmu_event *table __maybe_unused,
+                                      const struct pmu_events_table *table,
                                       void *data)
 {
        struct metricgroup_iter_data *d = data;
 }
 
 static int metricgroup__print_sys_event_iter(const struct pmu_event *pe,
-                                            const struct pmu_event *table __maybe_unused,
+                                            const struct pmu_events_table *table __maybe_unused,
                                             void *data)
 {
        struct metricgroup_print_sys_idata *d = data;
 };
 
 static int metricgroup__print_callback(const struct pmu_event *pe,
-                                      const struct pmu_event *table __maybe_unused,
+                                      const struct pmu_events_table *table __maybe_unused,
                                       void *vdata)
 {
        struct metricgroup_print_data *data = vdata;
        struct rblist groups;
        struct rb_node *node, *next;
        struct strlist *metriclist = NULL;
-       const struct pmu_event *table;
+       const struct pmu_events_table *table;
 
        if (!metricgroups) {
                metriclist = strlist__new(NULL, NULL);
        bool metric_no_group;
        struct metric *root_metric;
        const struct visited_metric *visited;
-       const struct pmu_event *table;
+       const struct pmu_events_table *table;
 };
 
 static int add_metric(struct list_head *metric_list,
                      bool metric_no_group,
                      struct metric *root_metric,
                      const struct visited_metric *visited,
-                     const struct pmu_event *table);
+                     const struct pmu_events_table *table);
 
 /**
  * resolve_metric - Locate metrics within the root metric and recursively add
                          bool metric_no_group,
                          struct metric *root_metric,
                          const struct visited_metric *visited,
-                         const struct pmu_event *table)
+                         const struct pmu_events_table *table)
 {
        struct hashmap_entry *cur;
        size_t bkt;
                        int runtime,
                        struct metric *root_metric,
                        const struct visited_metric *visited,
-                       const struct pmu_event *table)
+                       const struct pmu_events_table *table)
 {
        const struct visited_metric *vm;
        int ret;
 };
 
 static int metricgroup__find_metric_callback(const struct pmu_event *pe,
-                                            const struct pmu_event *table  __maybe_unused,
+                                            const struct pmu_events_table *table  __maybe_unused,
                                             void *vdata)
 {
        struct metricgroup__find_metric_data *data = vdata;
 }
 
 const struct pmu_event *metricgroup__find_metric(const char *metric,
-                                                const struct pmu_event *table)
+                                                const struct pmu_events_table *table)
 {
        struct metricgroup__find_metric_data data = {
                .metric = metric,
                      bool metric_no_group,
                      struct metric *root_metric,
                      const struct visited_metric *visited,
-                     const struct pmu_event *table)
+                     const struct pmu_events_table *table)
 {
        int ret = 0;
 
 }
 
 static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe,
-                                                 const struct pmu_event *table __maybe_unused,
-                                                 void *data)
+                                               const struct pmu_events_table *table __maybe_unused,
+                                               void *data)
 {
        struct metricgroup_add_iter_data *d = data;
        int ret;
 };
 
 static int metricgroup__add_metric_callback(const struct pmu_event *pe,
-                                           const struct pmu_event *table,
+                                           const struct pmu_events_table *table,
                                            void *vdata)
 {
        struct metricgroup__add_metric_data *data = vdata;
 static int metricgroup__add_metric(const char *metric_name, const char *modifier,
                                   bool metric_no_group,
                                   struct list_head *metric_list,
-                                  const struct pmu_event *table)
+                                  const struct pmu_events_table *table)
 {
        LIST_HEAD(list);
        int ret;
  */
 static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
                                        struct list_head *metric_list,
-                                       const struct pmu_event *table)
+                                       const struct pmu_events_table *table)
 {
        char *list_itr, *list_copy, *metric_name, *modifier;
        int ret, count = 0;
                        bool metric_no_merge,
                        struct perf_pmu *fake_pmu,
                        struct rblist *metric_events_list,
-                       const struct pmu_event *table)
+                       const struct pmu_events_table *table)
 {
        struct evlist *combined_evlist = NULL;
        LIST_HEAD(metric_list);
                              struct rblist *metric_events)
 {
        struct evlist *perf_evlist = *(struct evlist **)opt->value;
-       const struct pmu_event *table = pmu_events_table__find();
+       const struct pmu_events_table *table = pmu_events_table__find();
 
        return parse_groups(perf_evlist, str, metric_no_group,
                            metric_no_merge, NULL, metric_events, table);
 }
 
 int metricgroup__parse_groups_test(struct evlist *evlist,
-                                  const struct pmu_event *table,
+                                  const struct pmu_events_table *table,
                                   const char *str,
                                   bool metric_no_group,
                                   bool metric_no_merge,
 }
 
 static int metricgroup__has_metric_callback(const struct pmu_event *pe,
-                                           const struct pmu_event *table __maybe_unused,
+                                           const struct pmu_events_table *table __maybe_unused,
                                            void *vdata)
 {
        const char *metric = vdata;
 
 bool metricgroup__has_metric(const char *metric)
 {
-       const struct pmu_event *table = pmu_events_table__find();
+       const struct pmu_events_table *table = pmu_events_table__find();
 
        if (!table)
                return false;
 
 struct evsel;
 struct option;
 struct rblist;
-struct pmu_events_map;
 struct cgroup;
 
 /**
                              bool metric_no_merge,
                              struct rblist *metric_events);
 const struct pmu_event *metricgroup__find_metric(const char *metric,
-                                                const struct pmu_event *table);
+                                                const struct pmu_events_table *table);
 int metricgroup__parse_groups_test(struct evlist *evlist,
-                                  const struct pmu_event *table,
+                                  const struct pmu_events_table *table,
                                   const char *str,
                                   bool metric_no_group,
                                   bool metric_no_merge,
 
        return cpuid;
 }
 
-__weak const struct pmu_event *pmu_events_table__find(void)
+__weak const struct pmu_events_table *pmu_events_table__find(void)
 {
        return perf_pmu__find_table(NULL);
 }
 };
 
 static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
-                                       const struct pmu_event *table __maybe_unused,
+                                       const struct pmu_events_table *table __maybe_unused,
                                        void *vdata)
 {
        struct pmu_add_cpu_aliases_map_data *data = vdata;
  * as aliases.
  */
 void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
-                              const struct pmu_event *table)
+                              const struct pmu_events_table *table)
 {
        struct pmu_add_cpu_aliases_map_data data = {
                .head = head,
 
 static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
 {
-       const struct pmu_event *table;
+       const struct pmu_events_table *table;
 
        table = perf_pmu__find_table(pmu);
        if (!table)
 };
 
 static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
-                                      const struct pmu_event *table __maybe_unused,
+                                      const struct pmu_events_table *table __maybe_unused,
                                       void *data)
 {
        struct pmu_sys_event_iter_data *idata = data;
 
 
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
 void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
-                              const struct pmu_event *table);
+                              const struct pmu_events_table *table);
 
 char *perf_pmu__getcpuid(struct perf_pmu *pmu);
-const struct pmu_event *pmu_events_table__find(void);
+const struct pmu_events_table *pmu_events_table__find(void);
 bool pmu_uncore_alias_match(const char *pmu_name, const char *name);
 void perf_pmu_free_alias(struct perf_pmu_alias *alias);
 
 
 };
 
 static int get_counter_name_callback(const struct pmu_event *evp,
-                                    const struct pmu_event *table __maybe_unused,
+                                    const struct pmu_events_table *table __maybe_unused,
                                     void *vdata)
 {
        struct get_counter_name_data *data = vdata;
  * the name of this counter.
  * If no match is found a NULL pointer is returned.
  */
-static const char *get_counter_name(int set, int nr, const struct pmu_event *table)
+static const char *get_counter_name(int set, int nr, const struct pmu_events_table *table)
 {
        struct get_counter_name_data data = {
                .wanted = get_counterset_start(set) + nr,
        unsigned char *buf = sample->raw_data;
        const char *color = PERF_COLOR_BLUE;
        struct cf_ctrset_entry *cep, ce;
-       const struct pmu_event *table;
+       const struct pmu_events_table *table;
        u64 *p;
 
        table = pmu_events_table__find();