Automatic date update in version.in
[binutils-gdb.git] / sim / bfin / dv-bfin_pfmon.c
blob1c728889d916e2afca846431997872a6e30fd67f
1 /* Blackfin Performance Monitor model.
3 Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
6 This file is part of simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* This must come before any other includes. */
22 #include "defs.h"
24 #include "sim-main.h"
25 #include "devices.h"
26 #include "dv-bfin_pfmon.h"
28 /* XXX: This is mostly a stub. */
30 struct bfin_pfmon
32 bu32 base;
34 /* Order after here is important -- matches hardware MMR layout. */
35 bu32 ctl;
36 bu32 _pad0[63];
37 bu32 cntr0, cntr1;
39 #define mmr_base() offsetof(struct bfin_pfmon, ctl)
40 #define mmr_offset(mmr) (offsetof(struct bfin_pfmon, mmr) - mmr_base())
42 static const char * const mmr_names[] =
44 "PFCTL", [mmr_offset (cntr0)] = "PFCNTR0", "PFCNTR1",
46 #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
48 static unsigned
49 bfin_pfmon_io_write_buffer (struct hw *me, const void *source, int space,
50 address_word addr, unsigned nr_bytes)
52 struct bfin_pfmon *pfmon = hw_data (me);
53 bu32 mmr_off;
54 bu32 value;
55 bu32 *valuep;
57 /* Invalid access mode is higher priority than missing register. */
58 if (!dv_bfin_mmr_require_32 (me, addr, nr_bytes, true))
59 return 0;
61 value = dv_load_4 (source);
62 mmr_off = addr - pfmon->base;
63 valuep = (void *)((uintptr_t)pfmon + mmr_base() + mmr_off);
65 HW_TRACE_WRITE ();
67 switch (mmr_off)
69 case mmr_offset(ctl):
70 case mmr_offset(cntr0):
71 case mmr_offset(cntr1):
72 *valuep = value;
73 break;
74 default:
75 dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
76 return 0;
79 return nr_bytes;
82 static unsigned
83 bfin_pfmon_io_read_buffer (struct hw *me, void *dest, int space,
84 address_word addr, unsigned nr_bytes)
86 struct bfin_pfmon *pfmon = hw_data (me);
87 bu32 mmr_off;
88 bu32 value;
89 bu32 *valuep;
91 /* Invalid access mode is higher priority than missing register. */
92 if (!dv_bfin_mmr_require_32 (me, addr, nr_bytes, false))
93 return 0;
95 mmr_off = addr - pfmon->base;
96 valuep = (void *)((uintptr_t)pfmon + mmr_base() + mmr_off);
98 HW_TRACE_READ ();
100 switch (mmr_off)
102 case mmr_offset(ctl):
103 case mmr_offset(cntr0):
104 case mmr_offset(cntr1):
105 value = *valuep;
106 break;
107 default:
108 dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
109 return 0;
112 dv_store_4 (dest, value);
114 return nr_bytes;
117 static void
118 attach_bfin_pfmon_regs (struct hw *me, struct bfin_pfmon *pfmon)
120 address_word attach_address;
121 int attach_space;
122 unsigned attach_size;
123 reg_property_spec reg;
125 if (hw_find_property (me, "reg") == NULL)
126 hw_abort (me, "Missing \"reg\" property");
128 if (!hw_find_reg_array_property (me, "reg", 0, &reg))
129 hw_abort (me, "\"reg\" property must contain three addr/size entries");
131 hw_unit_address_to_attach_address (hw_parent (me),
132 &reg.address,
133 &attach_space, &attach_address, me);
134 hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
136 if (attach_size != BFIN_COREMMR_PFMON_SIZE)
137 hw_abort (me, "\"reg\" size must be %#x", BFIN_COREMMR_PFMON_SIZE);
139 hw_attach_address (hw_parent (me),
140 0, attach_space, attach_address, attach_size, me);
142 pfmon->base = attach_address;
145 static void
146 bfin_pfmon_finish (struct hw *me)
148 struct bfin_pfmon *pfmon;
150 pfmon = HW_ZALLOC (me, struct bfin_pfmon);
152 set_hw_data (me, pfmon);
153 set_hw_io_read_buffer (me, bfin_pfmon_io_read_buffer);
154 set_hw_io_write_buffer (me, bfin_pfmon_io_write_buffer);
156 attach_bfin_pfmon_regs (me, pfmon);
159 const struct hw_descriptor dv_bfin_pfmon_descriptor[] =
161 {"bfin_pfmon", bfin_pfmon_finish,},
162 {NULL, NULL},