]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/bfin/dv-bfin_gptimer.c
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / sim / bfin / dv-bfin_gptimer.c
1 /* Blackfin General Purpose Timers (GPtimer) model
2
3 Copyright (C) 2010-2013 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
5
6 This file is part of simulators.
7
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.
12
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.
17
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/>. */
20
21 #include "config.h"
22
23 #include "sim-main.h"
24 #include "devices.h"
25 #include "dv-bfin_gptimer.h"
26
27 /* XXX: This is merely a stub. */
28
29 struct bfin_gptimer
30 {
31 /* This top portion matches common dv_bfin struct. */
32 bu32 base;
33 struct hw *dma_master;
34 bool acked;
35
36 struct hw_event *handler;
37 char saved_byte;
38 int saved_count;
39
40 /* Order after here is important -- matches hardware MMR layout. */
41 bu16 BFIN_MMR_16(config);
42 bu32 counter, period, width;
43 };
44 #define mmr_base() offsetof(struct bfin_gptimer, config)
45 #define mmr_offset(mmr) (offsetof(struct bfin_gptimer, mmr) - mmr_base())
46
47 static const char * const mmr_names[] =
48 {
49 "TIMER_CONFIG", "TIMER_COUNTER", "TIMER_PERIOD", "TIMER_WIDTH",
50 };
51 #define mmr_name(off) mmr_names[(off) / 4]
52
53 static unsigned
54 bfin_gptimer_io_write_buffer (struct hw *me, const void *source, int space,
55 address_word addr, unsigned nr_bytes)
56 {
57 struct bfin_gptimer *gptimer = hw_data (me);
58 bu32 mmr_off;
59 bu32 value;
60 bu16 *value16p;
61 bu32 *value32p;
62 void *valuep;
63
64 if (nr_bytes == 4)
65 value = dv_load_4 (source);
66 else
67 value = dv_load_2 (source);
68
69 mmr_off = addr - gptimer->base;
70 valuep = (void *)((unsigned long)gptimer + mmr_base() + mmr_off);
71 value16p = valuep;
72 value32p = valuep;
73
74 HW_TRACE_WRITE ();
75
76 switch (mmr_off)
77 {
78 case mmr_offset(config):
79 dv_bfin_mmr_require_16 (me, addr, nr_bytes, true);
80 *value16p = value;
81 break;
82 case mmr_offset(counter):
83 case mmr_offset(period):
84 case mmr_offset(width):
85 dv_bfin_mmr_require_32 (me, addr, nr_bytes, true);
86 *value32p = value;
87 break;
88 default:
89 dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
90 break;
91 }
92
93 return nr_bytes;
94 }
95
96 static unsigned
97 bfin_gptimer_io_read_buffer (struct hw *me, void *dest, int space,
98 address_word addr, unsigned nr_bytes)
99 {
100 struct bfin_gptimer *gptimer = hw_data (me);
101 bu32 mmr_off;
102 bu16 *value16p;
103 bu32 *value32p;
104 void *valuep;
105
106 mmr_off = addr - gptimer->base;
107 valuep = (void *)((unsigned long)gptimer + mmr_base() + mmr_off);
108 value16p = valuep;
109 value32p = valuep;
110
111 HW_TRACE_READ ();
112
113 switch (mmr_off)
114 {
115 case mmr_offset(config):
116 dv_bfin_mmr_require_16 (me, addr, nr_bytes, false);
117 dv_store_2 (dest, *value16p);
118 break;
119 case mmr_offset(counter):
120 case mmr_offset(period):
121 case mmr_offset(width):
122 dv_bfin_mmr_require_32 (me, addr, nr_bytes, false);
123 dv_store_4 (dest, *value32p);
124 break;
125 default:
126 dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
127 break;
128 }
129
130 return nr_bytes;
131 }
132
133 static const struct hw_port_descriptor bfin_gptimer_ports[] =
134 {
135 { "stat", 0, 0, output_port, },
136 { NULL, 0, 0, 0, },
137 };
138
139 static void
140 attach_bfin_gptimer_regs (struct hw *me, struct bfin_gptimer *gptimer)
141 {
142 address_word attach_address;
143 int attach_space;
144 unsigned attach_size;
145 reg_property_spec reg;
146
147 if (hw_find_property (me, "reg") == NULL)
148 hw_abort (me, "Missing \"reg\" property");
149
150 if (!hw_find_reg_array_property (me, "reg", 0, &reg))
151 hw_abort (me, "\"reg\" property must contain three addr/size entries");
152
153 hw_unit_address_to_attach_address (hw_parent (me),
154 &reg.address,
155 &attach_space, &attach_address, me);
156 hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
157
158 if (attach_size != BFIN_MMR_GPTIMER_SIZE)
159 hw_abort (me, "\"reg\" size must be %#x", BFIN_MMR_GPTIMER_SIZE);
160
161 hw_attach_address (hw_parent (me),
162 0, attach_space, attach_address, attach_size, me);
163
164 gptimer->base = attach_address;
165 }
166
167 static void
168 bfin_gptimer_finish (struct hw *me)
169 {
170 struct bfin_gptimer *gptimer;
171
172 gptimer = HW_ZALLOC (me, struct bfin_gptimer);
173
174 set_hw_data (me, gptimer);
175 set_hw_io_read_buffer (me, bfin_gptimer_io_read_buffer);
176 set_hw_io_write_buffer (me, bfin_gptimer_io_write_buffer);
177 set_hw_ports (me, bfin_gptimer_ports);
178
179 attach_bfin_gptimer_regs (me, gptimer);
180 }
181
182 const struct hw_descriptor dv_bfin_gptimer_descriptor[] =
183 {
184 {"bfin_gptimer", bfin_gptimer_finish,},
185 {NULL, NULL},
186 };