1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/* $NetBSD: obio_timer.c,v 1.5 2011/07/01 19:32:28 dyoung Exp $ */
/* adapted from:
* NetBSD: obio_mputmr.c,v 1.3 2008/08/27 11:03:10 matt Exp
*/
/*
* Based on omap_mputmr.c
* Based on i80321_timer.c and arch/arm/sa11x0/sa11x0_ost.c
*
* Copyright (c) 1997 Mark Brinicombe.
* Copyright (c) 1997 Causality Limited.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by IWAMOTO Toshihiro and Ichiro FUKUHARA.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright (c) 2001, 2002 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright (c) 2007 Microsoft
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Microsoft
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obio_timer.c,v 1.5 2011/07/01 19:32:28 dyoung Exp $");
#include "opt_cpuoptions.h"
#include "opt_gemini.h"
#include "locators.h"
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/time.h>
#include <sys/device.h>
#include <dev/clock_subr.h>
#include <sys/bus.h>
#include <machine/intr.h>
#include <arm/gemini/gemini_reg.h>
#include <arm/gemini/gemini_obiovar.h>
#include <arm/gemini/gemini_timervar.h>
#if STATHZ != HZ
# error system clock HZ and stat clock STATHZ must be same
#endif
#ifndef GEMINI_TIMER_CLOCK_FREQ
# error Specify the timer frequency in Hz with option GEMINI_TIMER_CLOCK_FREQ
#endif
static int obiotimer_match(device_t, struct cfdata *, void *);
static void obiotimer_attach(device_t, device_t, void *);
struct geminitmr_softc xsc;
typedef struct {
uint timerno;
bus_addr_t addr;
uint intr;
} obiotimer_instance_t;
/* XXX
* this table can be used to match the GP Timers
* until we use config(8) locators to distinguish between
* gemini "sub-timers".
*/
#define GPT_ENTRY(n, i) { \
.timerno = (n), \
.addr = GEMINI_TIMER_BASE, \
.intr = i, \
}
static const obiotimer_instance_t obiotimer_instance_tab[] = {
GPT_ENTRY(1, 14),
GPT_ENTRY(2, 15),
GPT_ENTRY(3, 16),
};
#undef GPT_ENTRY
#define GPTIMER_INSTANCE_CNT __arraycount(obiotimer_instance_tab)
static const obiotimer_instance_t *
obiotimer_lookup(struct obio_attach_args *);
static void obiotimer_enable(struct geminitmr_softc *,
struct obio_attach_args *,
const obiotimer_instance_t *);
static int obiotimer_match(device_t, struct cfdata *, void *);
static void obiotimer_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(obiotimer, sizeof(struct geminitmr_softc),
obiotimer_match, obiotimer_attach, NULL, NULL);
static int
obiotimer_match(device_t parent, struct cfdata *match, void *aux)
{
struct obio_attach_args *obio = aux;
if ((obio->obio_addr == OBIOCF_ADDR_DEFAULT)
|| (obio->obio_intr == OBIOCF_INTR_DEFAULT))
panic("geminitmr must have addr and intr specified in config.");
if (obiotimer_lookup(obio) == NULL)
return 0;
return 1;
}
void
obiotimer_attach(device_t parent, device_t self, void *aux)
{
struct geminitmr_softc *sc = device_private(self);
struct obio_attach_args *obio = aux;
const obiotimer_instance_t *ip;
#ifndef GEMINI_SLAVE
static int once=1;
#endif
ip = obiotimer_lookup(obio);
if (ip == NULL)
panic("%s: bad lookup", device_xname(self));
/* should not fail since we already matched */
sc->sc_timerno = ip->timerno;
sc->sc_iot = obio->obio_iot;
sc->sc_intr = obio->obio_intr;
sc->sc_addr = obio->obio_addr;
sc->sc_size = (obio->obio_size == OBIOCF_SIZE_DEFAULT)
? (GEMINI_TIMER_INTRMASK + 4)
: obio->obio_size;
if (bus_space_map(sc->sc_iot, sc->sc_addr, sc->sc_size, 0, &sc->sc_ioh))
panic("%s: Cannot map registers", device_xname(self));
obiotimer_enable(sc, obio, obiotimer_lookup(obio));
aprint_normal("\n");
aprint_naive("\n");
#ifndef GEMINI_SLAVE
if (once) {
once = 0;
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
GEMINI_TIMER_TMCR, 0);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
GEMINI_TIMER_INTRMASK, (uint32_t)~TIMER_INTRMASK_Resv);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
GEMINI_TIMER_INTRSTATE, 0);
}
#endif
switch (sc->sc_timerno) {
case 1:
#ifndef GEMINI_SLAVE
/*
* timer #1 is the combined system clock and stat clock
* for the Master or Single Gemini CPU
* it gets started later
*/
profhz = stathz = hz;
stat_sc = clock_sc = sc;
#endif
break;
case 2:
#ifdef GEMINI_SLAVE
/*
* timer #2 is the combined system clock and stat clock
* for the Slave Gemini CPU
* it gets started later
*/
profhz = stathz = hz;
stat_sc = clock_sc = sc;
#endif
break;
case 3:
/*
* Timer #3 is used for microtime reference clock and delay()
* autoloading, non-interrupting, just wraps around
* we start it now to make delay() available
*/
ref_sc = sc;
#ifndef GEMINI_SLAVE
gemini_microtime_init();
#endif
break;
default:
panic("bad gemini timer number %d\n", sc->sc_timerno);
break;
}
}
static const obiotimer_instance_t *
obiotimer_lookup(struct obio_attach_args *obio)
{
const obiotimer_instance_t *ip;
uint i;
for (i = 0, ip = obiotimer_instance_tab;
i < GPTIMER_INSTANCE_CNT; i++, ip++) {
if (ip->addr == obio->obio_addr && ip->intr == obio->obio_intr)
return ip;
}
return NULL;
}
void
obiotimer_enable(
struct geminitmr_softc *sc,
struct obio_attach_args *obio,
const obiotimer_instance_t *ip)
{
/* nothing to do */
}
|