This source file includes following definitions.
- io_write_1
- io_write_2
- io_write_4
- io_write_bytes
- io_read_1
- io_read_2
- io_read_4
- io_read_bytes
- mem_write_1
- mem_write_2
- mem_write_4
- mem_write_bytes
- mem_read_1
- mem_read_2
- mem_read_4
- mem_read_bytes
- am79c930_gcr_setbits
- am79c930_gcr_clearbits
- am79c930_gcr_read
- am79c930_regdump
- am79c930_chip_init
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 #include <sys/param.h>
65 #include <sys/systm.h>
66 #ifndef __FreeBSD__
67 #include <sys/device.h>
68 #endif
69
70 #include <machine/cpu.h>
71 #ifdef __FreeBSD__
72 #include <machine/bus_pio.h>
73 #include <machine/bus_memio.h>
74 #endif
75 #include <machine/bus.h>
76 #ifdef __NetBSD__
77 #include <machine/intr.h>
78 #endif
79
80 #if defined(__NetBSD__) || defined(__OpenBSD__)
81 #include <dev/ic/am79c930reg.h>
82 #include <dev/ic/am79c930var.h>
83 #endif
84 #ifdef __FreeBSD__
85 #include <dev/awi/am79c930reg.h>
86 #include <dev/awi/am79c930var.h>
87 #endif
88
89 #define AM930_DELAY(x)
90
91 void am79c930_regdump(struct am79c930_softc *sc);
92
93 static void io_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
94 static void io_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
95 static void io_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
96 static void io_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
97
98 static u_int8_t io_read_1(struct am79c930_softc *, u_int32_t);
99 static u_int16_t io_read_2(struct am79c930_softc *, u_int32_t);
100 static u_int32_t io_read_4(struct am79c930_softc *, u_int32_t);
101 static void io_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
102
103 static void mem_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
104 static void mem_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
105 static void mem_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
106 static void mem_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
107
108 static u_int8_t mem_read_1(struct am79c930_softc *, u_int32_t);
109 static u_int16_t mem_read_2(struct am79c930_softc *, u_int32_t);
110 static u_int32_t mem_read_4(struct am79c930_softc *, u_int32_t);
111 static void mem_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
112
113 static struct am79c930_ops iospace_ops = {
114 io_write_1,
115 io_write_2,
116 io_write_4,
117 io_write_bytes,
118 io_read_1,
119 io_read_2,
120 io_read_4,
121 io_read_bytes
122 };
123
124 struct am79c930_ops memspace_ops = {
125 mem_write_1,
126 mem_write_2,
127 mem_write_4,
128 mem_write_bytes,
129 mem_read_1,
130 mem_read_2,
131 mem_read_4,
132 mem_read_bytes
133 };
134
135 static void io_write_1 (sc, off, val)
136 struct am79c930_softc *sc;
137 u_int32_t off;
138 u_int8_t val;
139 {
140 AM930_DELAY(1);
141 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
142 ((off>>8)& 0x7f));
143 AM930_DELAY(1);
144 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
145 AM930_DELAY(1);
146 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
147 AM930_DELAY(1);
148 }
149
150 static void io_write_2 (sc, off, val)
151 struct am79c930_softc *sc;
152 u_int32_t off;
153 u_int16_t val;
154 {
155 AM930_DELAY(1);
156 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
157 ((off>>8)& 0x7f));
158 AM930_DELAY(1);
159 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
160 AM930_DELAY(1);
161 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
162 AM930_DELAY(1);
163 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
164 AM930_DELAY(1);
165 }
166
167 static void io_write_4 (sc, off, val)
168 struct am79c930_softc *sc;
169 u_int32_t off;
170 u_int32_t val;
171 {
172 AM930_DELAY(1);
173 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
174 ((off>>8)& 0x7f));
175 AM930_DELAY(1);
176 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
177 AM930_DELAY(1);
178 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
179 AM930_DELAY(1);
180 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
181 AM930_DELAY(1);
182 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
183 AM930_DELAY(1);
184 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
185 AM930_DELAY(1);
186 }
187
188 static void io_write_bytes (sc, off, ptr, len)
189 struct am79c930_softc *sc;
190 u_int32_t off;
191 u_int8_t *ptr;
192 size_t len;
193 {
194 int i;
195
196 AM930_DELAY(1);
197 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
198 ((off>>8)& 0x7f));
199 AM930_DELAY(1);
200 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
201 AM930_DELAY(1);
202 for (i=0; i<len; i++)
203 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
204 }
205
206 static u_int8_t io_read_1 (sc, off)
207 struct am79c930_softc *sc;
208 u_int32_t off;
209 {
210 u_int8_t val;
211
212 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
213 ((off>>8)& 0x7f));
214 AM930_DELAY(1);
215 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
216 AM930_DELAY(1);
217 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
218 AM930_DELAY(1);
219 return val;
220 }
221
222 static u_int16_t io_read_2 (sc, off)
223 struct am79c930_softc *sc;
224 u_int32_t off;
225 {
226 u_int16_t val;
227
228 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
229 ((off>>8)& 0x7f));
230 AM930_DELAY(1);
231 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
232 AM930_DELAY(1);
233 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
234 AM930_DELAY(1);
235 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
236 AM930_DELAY(1);
237 return val;
238 }
239
240 static u_int32_t io_read_4 (sc, off)
241 struct am79c930_softc *sc;
242 u_int32_t off;
243 {
244 u_int32_t val;
245
246 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
247 ((off>>8)& 0x7f));
248 AM930_DELAY(1);
249 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
250 AM930_DELAY(1);
251 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
252 AM930_DELAY(1);
253 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
254 AM930_DELAY(1);
255 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
256 AM930_DELAY(1);
257 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
258 AM930_DELAY(1);
259 return val;
260 }
261
262 static void io_read_bytes (sc, off, ptr, len)
263 struct am79c930_softc *sc;
264 u_int32_t off;
265 u_int8_t *ptr;
266 size_t len;
267 {
268 int i;
269
270 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
271 ((off>>8)& 0x7f));
272 AM930_DELAY(1);
273 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
274 AM930_DELAY(1);
275 for (i=0; i<len; i++)
276 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
277 AM79C930_IODPA);
278 }
279
280 static void mem_write_1 (sc, off, val)
281 struct am79c930_softc *sc;
282 u_int32_t off;
283 u_int8_t val;
284 {
285 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
286 }
287
288 static void mem_write_2 (sc, off, val)
289 struct am79c930_softc *sc;
290 u_int32_t off;
291 u_int16_t val;
292 {
293 bus_space_tag_t t = sc->sc_memt;
294 bus_space_handle_t h = sc->sc_memh;
295
296
297 if ((off & 0x1) == 0)
298 bus_space_write_2(t, h, off, val);
299 else {
300 bus_space_write_1(t, h, off, val & 0xff);
301 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
302 }
303 }
304
305 static void mem_write_4 (sc, off, val)
306 struct am79c930_softc *sc;
307 u_int32_t off;
308 u_int32_t val;
309 {
310 bus_space_tag_t t = sc->sc_memt;
311 bus_space_handle_t h = sc->sc_memh;
312
313
314 if ((off & 0x3) == 0)
315 bus_space_write_4(t, h, off, val);
316 else {
317 bus_space_write_1(t, h, off, val & 0xff);
318 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
319 bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
320 bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
321 }
322 }
323
324 static void mem_write_bytes (sc, off, ptr, len)
325 struct am79c930_softc *sc;
326 u_int32_t off;
327 u_int8_t *ptr;
328 size_t len;
329 {
330 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
331 }
332
333
334 static u_int8_t mem_read_1 (sc, off)
335 struct am79c930_softc *sc;
336 u_int32_t off;
337 {
338 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
339 }
340
341 static u_int16_t mem_read_2 (sc, off)
342 struct am79c930_softc *sc;
343 u_int32_t off;
344 {
345
346 if ((off & 0x1) == 0)
347 return bus_space_read_2(sc->sc_memt, sc->sc_memh, off);
348 else
349 return
350 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
351 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
352 }
353
354 static u_int32_t mem_read_4 (sc, off)
355 struct am79c930_softc *sc;
356 u_int32_t off;
357 {
358
359 if ((off & 0x3) == 0)
360 return bus_space_read_4(sc->sc_memt, sc->sc_memh, off);
361 else
362 return
363 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
364 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
365 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
366 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
367 }
368
369
370
371 static void mem_read_bytes (sc, off, ptr, len)
372 struct am79c930_softc *sc;
373 u_int32_t off;
374 u_int8_t *ptr;
375 size_t len;
376 {
377 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
378 }
379
380
381
382
383
384
385
386
387 void am79c930_gcr_setbits (sc, bits)
388 struct am79c930_softc *sc;
389 u_int8_t bits;
390 {
391 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
392
393 gcr |= bits;
394
395 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
396 }
397
398
399
400
401
402 void am79c930_gcr_clearbits (sc, bits)
403 struct am79c930_softc *sc;
404 u_int8_t bits;
405 {
406 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
407
408 gcr &= ~bits;
409
410 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
411 }
412
413 u_int8_t am79c930_gcr_read (sc)
414 struct am79c930_softc *sc;
415 {
416 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
417 }
418
419 #if 0
420 void am79c930_regdump (sc)
421 struct am79c930_softc *sc;
422 {
423 u_int8_t buf[8];
424 int i;
425
426 AM930_DELAY(5);
427 for (i=0; i<8; i++) {
428 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
429 AM930_DELAY(5);
430 }
431 printf("am79c930: regdump:");
432 for (i=0; i<8; i++) {
433 printf(" %02x", buf[i]);
434 }
435 printf("\n");
436 }
437 #endif
438
439 void am79c930_chip_init (sc, how)
440 struct am79c930_softc *sc;
441 {
442
443 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
444 if (how)
445 sc->sc_ops = &memspace_ops;
446 else
447 sc->sc_ops = &iospace_ops;
448 }
449
450