blob: 80cd79ac3d2ac3f5699a89d1cdce7952531e88c1 [file] [log] [blame]
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02001/*
2 * Copyright (c) 2019-2020 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#include "common.h"
19#include "ethosu55_interface.h"
20#include "ethosu_pmu_config.h"
21#include <assert.h>
22#include <ethosu_driver.h>
23#include <pmu_ethosu.h>
24#include <stdint.h>
25
26PMU_Ethosu_ctrl_Type *ethosu_pmu_ctrl = (PMU_Ethosu_ctrl_Type *)ETHOSU_PMU_CTRL_BASE;
27PMU_Ethosu_cntr_Type *ethosu_pmu_cntr = (PMU_Ethosu_cntr_Type *)ETHOSU_PMU_CNTR_BASE;
28PMU_Ethosu_evnt_Type *ethosu_pmu_evnt = (PMU_Ethosu_evnt_Type *)ETHOSU_PMU_EVNT_BASE;
29
30// Local functions & macros
31#define PMUREG0(NAME) INIT_##NAME
32
33#define ETHOSU_PMU_INIT(N) \
34 *ethosu_pmu_ctrl = (PMU_Ethosu_ctrl_Type){.PMCR = PMUREG##N(PMCR), \
35 .PMCNTENSET = PMUREG##N(PMCNTENSET), \
36 .PMCNTENCLR = PMUREG##N(PMCNTENCLR), \
37 .PMOVSSET = PMUREG##N(PMOVSSET), \
38 .PMOVSCLR = PMUREG##N(PMOVSCLR), \
39 .PMINTSET = PMUREG##N(PMINTSET), \
40 .PMINTCLR = PMUREG##N(PMINTCLR), \
41 .PMCCNTR = PMUREG##N(PMCCNTR), \
42 .PMCCNTR_CFG = PMUREG##N(PMCCNTR_CFG)};
43
44// Public interfaces
45
46#define EVTYPE(A, name) \
47 case PMU_EVENT_TYPE_##name: \
48 return ETHOSU_PMU_##name
49enum ethosu_pmu_event_type pmu_event_type(uint32_t id)
50{
51 switch (id)
52 {
53 EXPAND_PMU_EVENT_TYPE(EVTYPE, SEMICOLON);
54 }
55 return ETHOSU_PMU_SENTINEL;
56}
57
58#define EVID(A, name) (PMU_EVENT_TYPE_##name)
59static const enum pmu_event_type eventbyid[] = {EXPAND_PMU_EVENT_TYPE(EVID, COMMA)};
60uint32_t pmu_event_value(enum ethosu_pmu_event_type event)
61{
62 if (!(event < ETHOSU_PMU_SENTINEL) || (event < 0))
63 {
64 return (uint32_t)(-1);
65 }
66
67 return eventbyid[event];
68}
69
70// Driver Init/exit functions
71INIT ethosu_pmu_driver_init(void)
72{
73 ETHOSU_PMU_INIT(0)
74
75 for (int i = 0; i < ETHOSU_PMU_NCOUNTERS; i++)
76 {
77 *ethosu_pmu_cntr[i] = 0;
78 *ethosu_pmu_evnt[i] = 0;
79 }
80}
81
82EXIT ethosu_pmu_driver_exit(void) {}