2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2003-2008 Joseph Koshy
5 * Copyright (c) 2007 The FreeBSD Foundation
6 * Copyright (c) 2021 Ampere Computing LLC
8 * Portions of this software were developed by A. Joseph Koshy under
9 * sponsorship from the FreeBSD Foundation and Google, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 /* Support for ARM DMC-620 Memory Controller PMU */
35 #include <sys/param.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
40 #include <sys/pmckern.h>
41 #include <sys/systm.h>
43 #include <dev/hwpmc/pmu_dmc620_reg.h>
45 #define DMC620_TYPE_CLKDIV2 0
46 #define DMC620_TYPE_CLK 1
47 #define CLASS2TYPE(c) ((c) - PMC_CLASS_DMC620_PMU_CD2)
49 /* Create wrapper for each class. */
50 #define CLASSDEP_FN2(fn, t1, a1, t2, a2) \
51 static int fn(int class, t1 a1, t2 a2); \
52 static int fn ## _cd2(t1 a1, t2 a2) \
54 return (fn(PMC_CLASS_DMC620_PMU_CD2, a1, a2)); \
56 static int fn ## _c(t1 a1, t2 a2) \
58 return (fn(PMC_CLASS_DMC620_PMU_C, a1, a2)); \
60 static int fn(int class, t1 a1, t2 a2)
62 #define CLASSDEP_FN3(fn, t1, a1, t2, a2, t3, a3) \
63 static int fn(int class, t1 a1, t2 a2, t3 a3); \
64 static int fn ## _cd2(t1 a1, t2 a2, t3 a3) \
66 return (fn(PMC_CLASS_DMC620_PMU_CD2, a1, a2, a3)); \
68 static int fn ## _c(t1 a1, t2 a2, t3 a3) \
70 return (fn(PMC_CLASS_DMC620_PMU_C, a1, a2, a3)); \
72 static int fn(int class, t1 a1, t2 a2, t3 a3)
74 #define CLASSDEP_FN4(fn, t1, a1, t2, a2, t3, a3, t4, a4) \
75 static int fn(int class, t1 a1, t2 a2, t3 a3, t4 a4); \
76 static int fn ## _cd2(t1 a1, t2 a2, t3 a3, t4 a4) \
78 return (fn(PMC_CLASS_DMC620_PMU_CD2, a1, a2, a3, a4)); \
80 static int fn ## _c(t1 a1, t2 a2, t3 a3, t4 a4) \
82 return (fn(PMC_CLASS_DMC620_PMU_C, a1, a2, a3, a4)); \
84 static int fn(int class, t1 a1, t2 a2, t3 a3, t4 a4)
92 struct pmc_descr pd_descr; /* "base class" */
93 void *pd_rw_arg; /* Argument to use with read/write */
95 struct pmc_hw *pd_phw;
99 uint32_t pd_evsel; /* address of EVSEL register */
100 uint32_t pd_perfctr; /* address of PERFCTR register */
104 static struct dmc620_descr **dmc620_pmcdesc[2];
105 static struct dmc620_pmc dmc620_pmcs[DMC620_UNIT_MAX];
106 static int dmc620_npmcs = 0;
109 dmc620_pmc_register(int unit, void *arg, int domain)
112 if (unit >= DMC620_UNIT_MAX) {
117 dmc620_pmcs[unit].arg = arg;
118 dmc620_pmcs[unit].domain = domain;
123 dmc620_pmc_unregister(int unit)
126 dmc620_pmcs[unit].arg = NULL;
131 pmc_dmc620_nclasses(void)
134 if (dmc620_npmcs > 0)
139 static inline struct dmc620_descr *
140 dmc620desc(int class, int cpu, int ri)
144 c = CLASS2TYPE(class);
145 KASSERT((c & 0xfffffffe) == 0, ("[dmc620,%d] 'c' can only be 0 or 1. "
146 "now %d", __LINE__, c));
148 return (dmc620_pmcdesc[c][ri]);
152 cntr(int class, int ri)
156 c = CLASS2TYPE(class);
157 KASSERT((c & 0xfffffffe) == 0, ("[dmc620,%d] 'c' can only be 0 or 1. "
158 "now %d", __LINE__, c));
160 if (c == DMC620_TYPE_CLKDIV2)
161 return (ri % DMC620_CLKDIV2_COUNTERS_N);
162 return ((ri % DMC620_CLK_COUNTERS_N) + DMC620_CLKDIV2_COUNTERS_N);
166 class2mdep(int class)
170 case PMC_CLASS_DMC620_PMU_CD2:
171 return (PMC_MDEP_CLASS_INDEX_DMC620_CD2);
172 case PMC_CLASS_DMC620_PMU_C:
173 return (PMC_MDEP_CLASS_INDEX_DMC620_C);
179 class_ri2unit(int class, int ri)
182 if (class == PMC_CLASS_DMC620_PMU_CD2)
183 return (ri / DMC620_CLKDIV2_COUNTERS_N);
185 return (ri / DMC620_CLK_COUNTERS_N);
189 * read a pmc register
192 CLASSDEP_FN4(dmc620_read_pmc, int, cpu, int, ri, struct pmc *, pm,
195 struct dmc620_descr *desc;
197 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
198 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
199 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
202 desc = dmc620desc(class, cpu, ri);
204 PMCDBG3(MDP,REA,1,"%s id=%d class=%d", __func__, ri, class);
207 * Should emulate 64bits, because 32 bits counter overflows faster than
208 * pmcstat default period.
210 /* Always CPU0. Single controller for all CPUs. */
211 *v = ((uint64_t)pm->pm_pcpu_state[0].pps_overflowcnt << 32) |
212 pmu_dmc620_rd4(desc->pd_rw_arg, cntr(class, ri),
213 DMC620_COUNTER_VALUE_LO);
215 PMCDBG3(MDP, REA, 2, "%s id=%d -> %jd", __func__, ri, *v);
221 * Write a pmc register.
224 CLASSDEP_FN4(dmc620_write_pmc, int, cpu, int, ri, struct pmc *, pm,
227 struct dmc620_descr *desc;
229 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
230 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
231 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
234 desc = dmc620desc(class, cpu, ri);
236 PMCDBG4(MDP, WRI, 1, "%s cpu=%d ri=%d v=%jx", __func__, cpu, ri, v);
238 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
239 DMC620_COUNTER_VALUE_LO, v);
244 * configure hardware pmc according to the configuration recorded in
248 CLASSDEP_FN3(dmc620_config_pmc, int, cpu, int, ri, struct pmc *, pm)
252 PMCDBG4(MDP, CFG, 1, "%s cpu=%d ri=%d pm=%p", __func__, cpu, ri, pm);
254 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
255 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
256 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
259 phw = dmc620desc(class, cpu, ri)->pd_phw;
261 KASSERT(pm == NULL || phw->phw_pmc == NULL,
262 ("[dmc620,%d] pm=%p phw->pm=%p hwpmc not unconfigured",
263 __LINE__, pm, phw->phw_pmc));
270 * Retrieve a configured PMC pointer from hardware state.
273 CLASSDEP_FN3(dmc620_get_config, int, cpu, int, ri, struct pmc **, ppm)
276 *ppm = dmc620desc(class, cpu, ri)->pd_phw->phw_pmc;
282 * Check if a given allocation is feasible.
285 CLASSDEP_FN4(dmc620_allocate_pmc, int, cpu, int, ri, struct pmc *,pm,
286 const struct pmc_op_pmcallocate *, a)
288 const struct pmc_descr *pd;
289 uint64_t caps, control;
295 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
296 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
297 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
300 pd = &dmc620desc(class, cpu, ri)->pd_descr;
301 if (dmc620_pmcs[class_ri2unit(class, ri)].domain !=
302 pcpu_find(cpu)->pc_domain)
305 /* check class match */
306 if (pd->pd_class != a->pm_class)
311 PMCDBG3(MDP, ALL, 1, "%s ri=%d caps=0x%x", __func__, ri, caps);
314 if (class == PMC_CLASS_DMC620_PMU_CD2)
315 e = pe - PMC_EV_DMC620_PMU_CD2_FIRST;
317 e = pe - PMC_EV_DMC620_PMU_C_FIRST;
319 control = (e << DMC620_COUNTER_CONTROL_EVENT_SHIFT) &
320 DMC620_COUNTER_CONTROL_EVENT_MASK;
322 if (caps & PMC_CAP_INVERT)
323 control |= DMC620_COUNTER_CONTROL_INVERT;
325 pm->pm_md.pm_dmc620.pm_control = control;
326 pm->pm_md.pm_dmc620.pm_match = a->pm_md.pm_dmc620.pm_dmc620_match;
327 pm->pm_md.pm_dmc620.pm_mask = a->pm_md.pm_dmc620.pm_dmc620_mask;
329 PMCDBG3(MDP, ALL, 2, "%s ri=%d -> control=0x%x", __func__, ri, control);
335 * Release machine dependent state associated with a PMC. This is a
336 * no-op on this architecture.
341 CLASSDEP_FN3(dmc620_release_pmc, int, cpu, int, ri, struct pmc *, pmc)
343 struct pmc_hw *phw __diagused;
347 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
348 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
349 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
352 phw = dmc620desc(class, cpu, ri)->pd_phw;
354 KASSERT(phw->phw_pmc == NULL,
355 ("[dmc620,%d] PHW pmc %p non-NULL", __LINE__, phw->phw_pmc));
364 CLASSDEP_FN3(dmc620_start_pmc, int, cpu, int, ri, struct pmc *, pm)
366 struct dmc620_descr *desc;
369 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
370 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
371 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
374 desc = dmc620desc(class, cpu, ri);
376 PMCDBG3(MDP, STA, 1, "%s cpu=%d ri=%d", __func__, cpu, ri);
378 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
379 DMC620_COUNTER_MASK_LO, pm->pm_md.pm_dmc620.pm_mask & 0xffffffff);
380 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
381 DMC620_COUNTER_MASK_HI, pm->pm_md.pm_dmc620.pm_mask >> 32);
382 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
383 DMC620_COUNTER_MATCH_LO, pm->pm_md.pm_dmc620.pm_match & 0xffffffff);
384 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
385 DMC620_COUNTER_MATCH_HI, pm->pm_md.pm_dmc620.pm_match >> 32);
386 /* turn on the PMC ENABLE bit */
387 control = pm->pm_md.pm_dmc620.pm_control | DMC620_COUNTER_CONTROL_ENABLE;
389 PMCDBG2(MDP, STA, 2, "%s control=0x%x", __func__, control);
391 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
392 DMC620_COUNTER_CONTROL, control);
400 CLASSDEP_FN3(dmc620_stop_pmc, int, cpu, int, ri, struct pmc *, pm)
402 struct dmc620_descr *desc;
405 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
406 ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu));
407 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
410 desc = dmc620desc(class, cpu, ri);
412 PMCDBG2(MDP, STO, 1, "%s ri=%d", __func__, ri);
414 /* turn off the PMC ENABLE bit */
415 control = pm->pm_md.pm_dmc620.pm_control & ~DMC620_COUNTER_CONTROL_ENABLE;
416 pmu_dmc620_wr4(desc->pd_rw_arg, cntr(class, ri),
417 DMC620_COUNTER_CONTROL, control);
425 CLASSDEP_FN4(dmc620_describe, int, cpu, int, ri, struct pmc_info *, pi,
428 struct pmc_descr *pd;
431 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
432 ("[dmc620,%d] illegal CPU %d", __LINE__, cpu));
433 KASSERT(ri >= 0, ("[dmc620,%d] row-index %d out of range", __LINE__,
436 phw = dmc620desc(class, cpu, ri)->pd_phw;
437 pd = &dmc620desc(class, cpu, ri)->pd_descr;
439 strlcpy(pi->pm_name, pd->pd_name, sizeof(pi->pm_name));
440 pi->pm_class = pd->pd_class;
442 if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
443 pi->pm_enabled = TRUE;
444 *ppmc = phw->phw_pmc;
446 pi->pm_enabled = FALSE;
454 * processor dependent initialization.
457 CLASSDEP_FN2(dmc620_pcpu_init, struct pmc_mdep *, md, int, cpu)
459 int first_ri, n, npmc;
464 mdep_class = class2mdep(class);
465 KASSERT(mdep_class != -1, ("[dmc620,%d] wrong class %d", __LINE__,
467 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
468 ("[dmc620,%d] insane cpu number %d", __LINE__, cpu));
470 PMCDBG1(MDP, INI, 1, "dmc620-init cpu=%d", cpu);
473 * Set the content of the hardware descriptors to a known
474 * state and initialize pointers in the MI per-cpu descriptor.
478 first_ri = md->pmd_classdep[mdep_class].pcd_ri;
479 npmc = md->pmd_classdep[mdep_class].pcd_num;
481 for (n = 0; n < npmc; n++, phw++) {
482 phw = dmc620desc(class, cpu, n)->pd_phw;
483 phw->phw_state = PMC_PHW_CPU_TO_STATE(cpu) |
484 PMC_PHW_INDEX_TO_STATE(n);
485 /* Set enabled only if unit present. */
486 if (dmc620_pmcs[class_ri2unit(class, n)].arg != NULL)
487 phw->phw_state |= PMC_PHW_FLAG_IS_ENABLED;
489 pc->pc_hwpmcs[n + first_ri] = phw;
495 * processor dependent cleanup prior to the KLD
499 CLASSDEP_FN2(dmc620_pcpu_fini, struct pmc_mdep *, md, int, cpu)
506 dmc620_intr(struct trapframe *tf, int class, int unit, int i)
508 struct pmc_cpu *pc __diagused;
513 ri = i + unit * ((class == PMC_CLASS_DMC620_PMU_CD2) ?
514 DMC620_CLKDIV2_COUNTERS_N : DMC620_CLK_COUNTERS_N);
516 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
517 ("[dmc620,%d] CPU %d out of range", __LINE__, cpu));
519 KASSERT(pc != NULL, ("pc != NULL"));
521 phw = dmc620desc(class, cpu, ri)->pd_phw;
522 KASSERT(phw != NULL, ("phw != NULL"));
527 if (!PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) {
529 pm->pm_pcpu_state[0].pps_overflowcnt += 1;
533 if (pm->pm_state != PMC_STATE_RUNNING)
536 error = pmc_process_interrupt(PMC_HR, pm, tf);
538 dmc620_stop_pmc(class, cpu, ri, pm);
540 /* Reload sampling count */
541 dmc620_write_pmc(class, cpu, ri, pm, pm->pm_sc.pm_reloadcount);
547 * Initialize ourselves.
551 pmc_dmc620_initialize_cd2(struct pmc_mdep *md)
553 struct pmc_classdep *pcd;
556 KASSERT(md != NULL, ("[dmc620,%d] md is NULL", __LINE__));
557 KASSERT(dmc620_npmcs <= DMC620_UNIT_MAX,
558 ("[dmc620,%d] dmc620_npmcs too big", __LINE__));
560 PMCDBG0(MDP,INI,1, "dmc620-initialize");
562 npmc = DMC620_CLKDIV2_COUNTERS_N * dmc620_npmcs;
563 pcd = &md->pmd_classdep[PMC_MDEP_CLASS_INDEX_DMC620_CD2];
565 pcd->pcd_caps = PMC_CAP_SYSTEM | PMC_CAP_READ |
566 PMC_CAP_WRITE | PMC_CAP_INVERT | PMC_CAP_QUALIFIER |
567 PMC_CAP_INTERRUPT | PMC_CAP_DOMWIDE;
568 pcd->pcd_class = PMC_CLASS_DMC620_PMU_CD2;
570 pcd->pcd_ri = md->pmd_npmc;
573 pcd->pcd_allocate_pmc = dmc620_allocate_pmc_cd2;
574 pcd->pcd_config_pmc = dmc620_config_pmc_cd2;
575 pcd->pcd_describe = dmc620_describe_cd2;
576 pcd->pcd_get_config = dmc620_get_config_cd2;
577 pcd->pcd_get_msr = NULL;
578 pcd->pcd_pcpu_fini = dmc620_pcpu_fini_cd2;
579 pcd->pcd_pcpu_init = dmc620_pcpu_init_cd2;
580 pcd->pcd_read_pmc = dmc620_read_pmc_cd2;
581 pcd->pcd_release_pmc = dmc620_release_pmc_cd2;
582 pcd->pcd_start_pmc = dmc620_start_pmc_cd2;
583 pcd->pcd_stop_pmc = dmc620_stop_pmc_cd2;
584 pcd->pcd_write_pmc = dmc620_write_pmc_cd2;
586 md->pmd_npmc += npmc;
587 dmc620_pmcdesc[0] = malloc(sizeof(struct dmc620_descr *) * npmc *
588 DMC620_PMU_DEFAULT_UNITS_N, M_PMC, M_WAITOK|M_ZERO);
589 for (i = 0; i < npmc; i++) {
590 dmc620_pmcdesc[0][i] = malloc(sizeof(struct dmc620_descr),
591 M_PMC, M_WAITOK|M_ZERO);
593 unit = i / DMC620_CLKDIV2_COUNTERS_N;
594 KASSERT(unit >= 0, ("unit >= 0"));
595 KASSERT(dmc620_pmcs[unit].arg != NULL, ("arg != NULL"));
597 dmc620_pmcdesc[0][i]->pd_rw_arg = dmc620_pmcs[unit].arg;
598 dmc620_pmcdesc[0][i]->pd_descr.pd_class =
599 PMC_CLASS_DMC620_PMU_CD2;
600 dmc620_pmcdesc[0][i]->pd_descr.pd_caps = pcd->pcd_caps;
601 dmc620_pmcdesc[0][i]->pd_phw = malloc(sizeof(struct pmc_hw),
602 M_PMC, M_WAITOK|M_ZERO);
603 snprintf(dmc620_pmcdesc[0][i]->pd_descr.pd_name, 63,
611 pmc_dmc620_initialize_c(struct pmc_mdep *md)
613 struct pmc_classdep *pcd;
616 KASSERT(md != NULL, ("[dmc620,%d] md is NULL", __LINE__));
617 KASSERT(dmc620_npmcs <= DMC620_UNIT_MAX,
618 ("[dmc620,%d] dmc620_npmcs too big", __LINE__));
620 PMCDBG0(MDP,INI,1, "dmc620-initialize");
622 npmc = DMC620_CLK_COUNTERS_N * dmc620_npmcs;
623 pcd = &md->pmd_classdep[PMC_MDEP_CLASS_INDEX_DMC620_C];
625 pcd->pcd_caps = PMC_CAP_SYSTEM | PMC_CAP_READ |
626 PMC_CAP_WRITE | PMC_CAP_INVERT | PMC_CAP_QUALIFIER |
627 PMC_CAP_INTERRUPT | PMC_CAP_DOMWIDE;
628 pcd->pcd_class = PMC_CLASS_DMC620_PMU_C;
630 pcd->pcd_ri = md->pmd_npmc;
633 pcd->pcd_allocate_pmc = dmc620_allocate_pmc_c;
634 pcd->pcd_config_pmc = dmc620_config_pmc_c;
635 pcd->pcd_describe = dmc620_describe_c;
636 pcd->pcd_get_config = dmc620_get_config_c;
637 pcd->pcd_get_msr = NULL;
638 pcd->pcd_pcpu_fini = dmc620_pcpu_fini_c;
639 pcd->pcd_pcpu_init = dmc620_pcpu_init_c;
640 pcd->pcd_read_pmc = dmc620_read_pmc_c;
641 pcd->pcd_release_pmc = dmc620_release_pmc_c;
642 pcd->pcd_start_pmc = dmc620_start_pmc_c;
643 pcd->pcd_stop_pmc = dmc620_stop_pmc_c;
644 pcd->pcd_write_pmc = dmc620_write_pmc_c;
646 md->pmd_npmc += npmc;
647 dmc620_pmcdesc[1] = malloc(sizeof(struct dmc620_descr *) * npmc *
648 DMC620_PMU_DEFAULT_UNITS_N, M_PMC, M_WAITOK|M_ZERO);
649 for (i = 0; i < npmc; i++) {
650 dmc620_pmcdesc[1][i] = malloc(sizeof(struct dmc620_descr),
651 M_PMC, M_WAITOK|M_ZERO);
653 unit = i / DMC620_CLK_COUNTERS_N;
654 KASSERT(unit >= 0, ("unit >= 0"));
655 KASSERT(dmc620_pmcs[unit].arg != NULL, ("arg != NULL"));
657 dmc620_pmcdesc[1][i]->pd_rw_arg = dmc620_pmcs[unit].arg;
658 dmc620_pmcdesc[1][i]->pd_descr.pd_class = PMC_CLASS_DMC620_PMU_C;
659 dmc620_pmcdesc[1][i]->pd_descr.pd_caps = pcd->pcd_caps;
660 dmc620_pmcdesc[1][i]->pd_phw = malloc(sizeof(struct pmc_hw),
661 M_PMC, M_WAITOK|M_ZERO);
662 snprintf(dmc620_pmcdesc[1][i]->pd_descr.pd_name, 63,
670 pmc_dmc620_finalize_cd2(struct pmc_mdep *md)
672 struct pmc_classdep *pcd;
675 KASSERT(md->pmd_classdep[PMC_MDEP_CLASS_INDEX_DMC620_CD2].pcd_class ==
676 PMC_CLASS_DMC620_PMU_CD2, ("[dmc620,%d] pmc class mismatch",
679 pcd = &md->pmd_classdep[PMC_MDEP_CLASS_INDEX_DMC620_CD2];
682 for (i = 0; i < npmc; i++) {
683 free(dmc620_pmcdesc[0][i]->pd_phw, M_PMC);
684 free(dmc620_pmcdesc[0][i], M_PMC);
686 free(dmc620_pmcdesc[0], M_PMC);
687 dmc620_pmcdesc[0] = NULL;
691 pmc_dmc620_finalize_c(struct pmc_mdep *md)
693 struct pmc_classdep *pcd;
696 KASSERT(md->pmd_classdep[PMC_MDEP_CLASS_INDEX_DMC620_C].pcd_class ==
697 PMC_CLASS_DMC620_PMU_C, ("[dmc620,%d] pmc class mismatch",
700 pcd = &md->pmd_classdep[PMC_MDEP_CLASS_INDEX_DMC620_C];
703 for (i = 0; i < npmc; i++) {
704 free(dmc620_pmcdesc[1][i]->pd_phw, M_PMC);
705 free(dmc620_pmcdesc[1][i], M_PMC);
707 free(dmc620_pmcdesc[1], M_PMC);
708 dmc620_pmcdesc[1] = NULL;