123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #include <arch.h>
- #include <arch_features.h>
- #include <arch_helpers.h>
- #include <lib/extensions/pmuv3.h>
- static u_register_t init_mdcr_el2_hpmn(u_register_t mdcr_el2)
- {
-
- mdcr_el2 &= ~MDCR_EL2_HPMN_MASK;
- mdcr_el2 |= ((read_pmcr_el0() >> PMCR_EL0_N_SHIFT) & PMCR_EL0_N_MASK);
- return mdcr_el2;
- }
- void pmuv3_enable(cpu_context_t *ctx)
- {
- #if (CTX_INCLUDE_EL2_REGS && IMAGE_BL31)
- u_register_t mdcr_el2_val;
- mdcr_el2_val = read_el2_ctx_common(get_el2_sysregs_ctx(ctx), mdcr_el2);
- mdcr_el2_val = init_mdcr_el2_hpmn(mdcr_el2_val);
- write_el2_ctx_common(get_el2_sysregs_ctx(ctx), mdcr_el2, mdcr_el2_val);
- #endif
- }
- static u_register_t mtpmu_disable_el3(u_register_t mdcr_el3)
- {
- if (!is_feat_mtpmu_supported()) {
- return mdcr_el3;
- }
-
- mdcr_el3 &= ~MDCR_MTPME_BIT;
- return mdcr_el3;
- }
- void pmuv3_init_el3(void)
- {
- u_register_t mdcr_el3 = read_mdcr_el3();
-
- mdcr_el3 = (mdcr_el3 | MDCR_SCCD_BIT | MDCR_MCCD_BIT) &
- ~(MDCR_MPMX_BIT | MDCR_SPME_BIT | MDCR_TPM_BIT);
- mdcr_el3 = mtpmu_disable_el3(mdcr_el3);
- write_mdcr_el3(mdcr_el3);
-
- write_pmcr_el0((read_pmcr_el0() | PMCR_EL0_DP_BIT | PMCR_EL0_C_BIT |
- PMCR_EL0_P_BIT) & ~(PMCR_EL0_X_BIT | PMCR_EL0_E_BIT));
- }
- static u_register_t mtpmu_disable_el2(u_register_t mdcr_el2)
- {
- if (!is_feat_mtpmu_supported()) {
- return mdcr_el2;
- }
-
- mdcr_el2 &= ~MDCR_EL2_MTPME;
- return mdcr_el2;
- }
- void pmuv3_init_el2_unused(void)
- {
- u_register_t mdcr_el2 = read_mdcr_el2();
-
- mdcr_el2 = (mdcr_el2 | MDCR_EL2_HLP_BIT | MDCR_EL2_HPMD_BIT |
- MDCR_EL2_HCCD_BIT) &
- ~(MDCR_EL2_HPME_BIT | MDCR_EL2_TPM_BIT | MDCR_EL2_TPMCR_BIT);
- mdcr_el2 = init_mdcr_el2_hpmn(mdcr_el2);
- mdcr_el2 = mtpmu_disable_el2(mdcr_el2);
- write_mdcr_el2(mdcr_el2);
- }
|