machdep.c revision 1.4 1 1.4 matt /* $NetBSD: machdep.c,v 1.4 2003/03/16 07:07:19 matt Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 matt * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 matt * All rights reserved.
7 1.1 matt *
8 1.1 matt * Redistribution and use in source and binary forms, with or without
9 1.1 matt * modification, are permitted provided that the following conditions
10 1.1 matt * are met:
11 1.1 matt * 1. Redistributions of source code must retain the above copyright
12 1.1 matt * notice, this list of conditions and the following disclaimer.
13 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer in the
15 1.1 matt * documentation and/or other materials provided with the distribution.
16 1.1 matt * 3. All advertising materials mentioning features or use of this software
17 1.1 matt * must display the following acknowledgement:
18 1.1 matt * This product includes software developed by TooLs GmbH.
19 1.1 matt * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 matt * derived from this software without specific prior written permission.
21 1.1 matt *
22 1.1 matt * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 matt * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 matt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 matt * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 matt * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 matt * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 matt * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 matt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 matt */
33 1.1 matt
34 1.1 matt #include "opt_marvell.h"
35 1.1 matt #include "opt_compat_netbsd.h"
36 1.1 matt #include "opt_ddb.h"
37 1.1 matt #include "opt_inet.h"
38 1.1 matt #include "opt_ccitt.h"
39 1.1 matt #include "opt_iso.h"
40 1.1 matt #include "opt_ns.h"
41 1.1 matt #include "opt_ipkdb.h"
42 1.1 matt
43 1.1 matt #include <sys/param.h>
44 1.1 matt #include <sys/conf.h>
45 1.1 matt #include <sys/device.h>
46 1.1 matt #include <sys/kernel.h>
47 1.1 matt #include <sys/malloc.h>
48 1.1 matt #include <sys/mount.h>
49 1.1 matt #include <sys/msgbuf.h>
50 1.1 matt #include <sys/proc.h>
51 1.1 matt #include <sys/reboot.h>
52 1.4 matt #include <sys/extent.h>
53 1.1 matt #include <sys/syslog.h>
54 1.1 matt #include <sys/systm.h>
55 1.1 matt
56 1.1 matt #include <uvm/uvm.h>
57 1.1 matt #include <uvm/uvm_extern.h>
58 1.1 matt
59 1.1 matt #include <net/netisr.h>
60 1.1 matt
61 1.1 matt #include <machine/bus.h>
62 1.1 matt #include <machine/db_machdep.h>
63 1.1 matt #include <machine/intr.h>
64 1.1 matt #include <machine/pmap.h>
65 1.1 matt #include <machine/powerpc.h>
66 1.1 matt #include <machine/trap.h>
67 1.1 matt
68 1.1 matt #include <powerpc/oea/bat.h>
69 1.1 matt #include <powerpc/marvell/watchdog.h>
70 1.1 matt
71 1.1 matt #include <ddb/db_extern.h>
72 1.1 matt
73 1.1 matt #include <dev/cons.h>
74 1.1 matt
75 1.1 matt #include "vga.h"
76 1.1 matt #if (NVGA > 0)
77 1.1 matt #include <dev/ic/mc6845reg.h>
78 1.1 matt #include <dev/ic/pcdisplayvar.h>
79 1.1 matt #include <dev/ic/vgareg.h>
80 1.1 matt #include <dev/ic/vgavar.h>
81 1.1 matt #endif
82 1.1 matt
83 1.1 matt #include "isa.h"
84 1.1 matt #if (NISA > 0)
85 1.1 matt void isa_intr_init(void);
86 1.1 matt #endif
87 1.1 matt
88 1.1 matt #include "pckbc.h"
89 1.1 matt #if (NPCKBC > 0)
90 1.1 matt #include <dev/isa/isareg.h>
91 1.1 matt #include <dev/ic/i8042reg.h>
92 1.1 matt #include <dev/ic/pckbcvar.h>
93 1.1 matt #endif
94 1.1 matt
95 1.1 matt #include "com.h"
96 1.1 matt #if (NCOM > 0)
97 1.1 matt #include <sys/termios.h>
98 1.1 matt #include <dev/ic/comreg.h>
99 1.1 matt #include <dev/ic/comvar.h>
100 1.1 matt #endif
101 1.1 matt
102 1.2 matt #include <dev/marvell/gtreg.h>
103 1.1 matt #include <dev/marvell/gtvar.h>
104 1.1 matt
105 1.1 matt /*
106 1.1 matt * Global variables used here and there
107 1.1 matt */
108 1.1 matt extern struct user *proc0paddr;
109 1.1 matt
110 1.1 matt #define PMONMEMREGIONS 32
111 1.1 matt struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
112 1.1 matt
113 1.1 matt char *bootpath;
114 1.1 matt
115 1.1 matt paddr_t avail_end; /* XXX temporary */
116 1.1 matt
117 1.1 matt void initppc(u_int, u_int, u_int, void *); /* Called from locore */
118 1.1 matt void strayintr(int);
119 1.1 matt int lcsplx(int);
120 1.4 matt void gt_bus_space_init(void);
121 1.4 matt extern void return_to_dink(int);
122 1.4 matt
123 1.4 matt struct powerpc_bus_space gt_pci0_mem_bs_tag = {
124 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
125 1.4 matt 0x00000000, 0x00000000, 0x00000000,
126 1.4 matt };
127 1.4 matt struct powerpc_bus_space gt_pci0_io_bs_tag = {
128 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
129 1.4 matt 0x00000000, 0x00000000, 0x00000000,
130 1.4 matt };
131 1.4 matt struct powerpc_bus_space gt_pci1_mem_bs_tag = {
132 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
133 1.4 matt 0x00000000, 0x00000000, 0x00000000,
134 1.4 matt };
135 1.4 matt struct powerpc_bus_space gt_pci1_io_bs_tag = {
136 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
137 1.4 matt 0x00000000, 0x00000000, 0x00000000,
138 1.4 matt };
139 1.4 matt struct powerpc_bus_space gt_obio2_bs_tag = {
140 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE|2,
141 1.4 matt 0x00000000, 0x00000000, 0x00000000,
142 1.4 matt };
143 1.4 matt struct powerpc_bus_space gt_mem_bs_tag = {
144 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
145 1.4 matt GT_BASE, 0x00000000, 0x00010000,
146 1.4 matt };
147 1.4 matt
148 1.4 matt bus_space_handle_t gt_memh;
149 1.4 matt
150 1.4 matt bus_space_tag_t obio_bs_tags[5] = {
151 1.4 matt NULL, NULL, >_obio2_bs_tag, NULL, NULL
152 1.4 matt };
153 1.1 matt
154 1.4 matt static char ex_storage[6][EXTENT_FIXED_STORAGE_SIZE(8)]
155 1.4 matt __attribute__((aligned(8)));
156 1.4 matt
157 1.4 matt #if 0
158 1.1 matt cons_decl(gtmpsc);
159 1.1 matt
160 1.1 matt struct consdev constab[] = {
161 1.1 matt cons_init_halt(gtmpsc),
162 1.1 matt { 0 }
163 1.1 matt };
164 1.4 matt #endif
165 1.1 matt
166 1.1 matt void
167 1.1 matt initppc(startkernel, endkernel, args, btinfo)
168 1.1 matt u_int startkernel, endkernel, args;
169 1.1 matt void *btinfo;
170 1.1 matt {
171 1.1 matt #ifdef DDB
172 1.1 matt extern void *startsym, *endsym;
173 1.1 matt #endif
174 1.1 matt
175 1.1 matt /*
176 1.1 matt * Hardcode 32MB for now--we should probe for this or get it
177 1.1 matt * from a boot loader, but for now, we are booting via an
178 1.1 matt * S-record loader.
179 1.1 matt */
180 1.1 matt { /* XXX AKB */
181 1.1 matt u_int32_t physmemsize;
182 1.1 matt
183 1.4 matt physmemsize = 92 * 1024 * 1024;
184 1.1 matt physmemr[0].start = 0;
185 1.1 matt physmemr[0].size = physmemsize;
186 1.1 matt physmemr[1].size = 0;
187 1.1 matt availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET;
188 1.1 matt availmemr[0].size = physmemsize - availmemr[0].start;
189 1.1 matt availmemr[1].size = 0;
190 1.1 matt }
191 1.1 matt avail_end = physmemr[0].start + physmemr[0].size; /* XXX temporary */
192 1.1 matt
193 1.1 matt /*
194 1.1 matt * Get CPU clock
195 1.1 matt */
196 1.1 matt { /* XXX AKB */
197 1.1 matt extern u_long ticks_per_sec, ns_per_tick;
198 1.1 matt extern void calc_delayconst(void);
199 1.1 matt
200 1.1 matt ticks_per_sec = 100000000; /* 100 MHz */
201 1.1 matt /* ticks_per_sec = 66000000; * 66 MHz */
202 1.1 matt ticks_per_sec /= 4; /* 4 cycles per DEC tick */
203 1.1 matt cpu_timebase = ticks_per_sec;
204 1.1 matt ns_per_tick = 1000000000 / ticks_per_sec;
205 1.1 matt calc_delayconst();
206 1.1 matt }
207 1.1 matt
208 1.4 matt oea_batinit(0xf0000000, BAT_BL_256M);
209 1.4 matt oea_init((void (*)(void))ext_intr);
210 1.1 matt
211 1.4 matt gt_bus_space_init();
212 1.1 matt
213 1.4 matt consinit();
214 1.1 matt
215 1.1 matt #if (NISA > 0)
216 1.1 matt isa_intr_init();
217 1.1 matt #endif
218 1.1 matt
219 1.1 matt /*
220 1.1 matt * Set the page size.
221 1.1 matt */
222 1.1 matt uvm_setpagesize();
223 1.1 matt
224 1.1 matt /*
225 1.1 matt * Initialize pmap module.
226 1.1 matt */
227 1.1 matt pmap_bootstrap(startkernel, endkernel);
228 1.1 matt
229 1.1 matt #ifdef DDB
230 1.1 matt ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
231 1.1 matt #endif
232 1.1 matt #ifdef IPKDB
233 1.1 matt /*
234 1.1 matt * Now trap to IPKDB
235 1.1 matt */
236 1.1 matt ipkdb_init();
237 1.1 matt if (boothowto & RB_KDB)
238 1.1 matt ipkdb_connect(0);
239 1.1 matt #endif
240 1.1 matt }
241 1.1 matt
242 1.1 matt void
243 1.1 matt mem_regions(mem, avail)
244 1.1 matt struct mem_region **mem, **avail;
245 1.1 matt {
246 1.1 matt *mem = physmemr;
247 1.1 matt *avail = availmemr;
248 1.1 matt }
249 1.1 matt
250 1.1 matt /*
251 1.1 matt * Machine dependent startup code.
252 1.1 matt */
253 1.1 matt void
254 1.1 matt cpu_startup()
255 1.1 matt {
256 1.1 matt register_t msr;
257 1.1 matt
258 1.1 matt oea_startup(NULL);
259 1.1 matt
260 1.1 matt /*
261 1.1 matt * Now that we have VM, malloc()s are OK in bus_space.
262 1.1 matt */
263 1.3 matt bus_space_mallocok();
264 1.1 matt
265 1.1 matt /*
266 1.1 matt * Now allow hardware interrupts.
267 1.1 matt */
268 1.1 matt splhigh();
269 1.1 matt __asm __volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
270 1.1 matt : "=r"(msr)
271 1.1 matt : "K"(PSL_EE));
272 1.1 matt }
273 1.1 matt
274 1.1 matt /*
275 1.1 matt * consinit
276 1.1 matt * Initialize system console.
277 1.1 matt */
278 1.1 matt void
279 1.1 matt consinit()
280 1.1 matt {
281 1.4 matt #if 1
282 1.4 matt /* PPCBOOT using COM1 @ 57600 */
283 1.4 matt comcnattach(>_obio2_bs_tag, 0, 57600, COM_FREQ*2,
284 1.4 matt (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
285 1.4 matt #else
286 1.1 matt cninit();
287 1.4 matt #endif
288 1.1 matt }
289 1.1 matt
290 1.1 matt #if (NPCKBC > 0) && (NPCKBD == 0)
291 1.1 matt /*
292 1.1 matt * glue code to support old console code with the
293 1.1 matt * mi keyboard controller driver
294 1.1 matt */
295 1.1 matt int
296 1.1 matt pckbc_machdep_cnattach(kbctag, kbcslot)
297 1.1 matt pckbc_tag_t kbctag;
298 1.1 matt pckbc_slot_t kbcslot;
299 1.1 matt {
300 1.1 matt #if (NPC > 0)
301 1.1 matt return (pcconskbd_cnattach(kbctag, kbcslot));
302 1.1 matt #else
303 1.1 matt return (ENXIO);
304 1.1 matt #endif
305 1.1 matt }
306 1.1 matt #endif
307 1.1 matt
308 1.1 matt /*
309 1.1 matt * Stray interrupts.
310 1.1 matt */
311 1.1 matt void
312 1.1 matt strayintr(int irq)
313 1.1 matt {
314 1.1 matt log(LOG_ERR, "stray interrupt %d\n", irq);
315 1.1 matt }
316 1.1 matt
317 1.1 matt /*
318 1.1 matt * Halt or reboot the machine after syncing/dumping according to howto.
319 1.1 matt */
320 1.1 matt void
321 1.1 matt cpu_reboot(howto, what)
322 1.1 matt int howto;
323 1.1 matt char *what;
324 1.1 matt {
325 1.1 matt static int syncing;
326 1.1 matt static char str[256];
327 1.1 matt char *ap = str, *ap1 = ap;
328 1.1 matt
329 1.1 matt boothowto = howto;
330 1.1 matt if (!cold && !(howto & RB_NOSYNC) && !syncing) {
331 1.1 matt syncing = 1;
332 1.1 matt vfs_shutdown(); /* sync */
333 1.1 matt resettodr(); /* set wall clock */
334 1.1 matt }
335 1.1 matt splhigh();
336 1.1 matt if (howto & RB_HALT) {
337 1.1 matt doshutdownhooks();
338 1.1 matt printf("halted\n\n");
339 1.1 matt cnhalt();
340 1.1 matt while(1);
341 1.1 matt }
342 1.1 matt if (!cold && (howto & RB_DUMP))
343 1.1 matt oea_dumpsys();
344 1.1 matt doshutdownhooks();
345 1.1 matt printf("rebooting\n\n");
346 1.1 matt if (what && *what) {
347 1.1 matt if (strlen(what) > sizeof str - 5)
348 1.1 matt printf("boot string too large, ignored\n");
349 1.1 matt else {
350 1.1 matt strcpy(str, what);
351 1.1 matt ap1 = ap = str + strlen(str);
352 1.1 matt *ap++ = ' ';
353 1.1 matt }
354 1.1 matt }
355 1.1 matt *ap++ = '-';
356 1.1 matt if (howto & RB_SINGLE)
357 1.1 matt *ap++ = 's';
358 1.1 matt if (howto & RB_KDB)
359 1.1 matt *ap++ = 'd';
360 1.1 matt *ap++ = 0;
361 1.1 matt if (ap[-2] == '-')
362 1.1 matt *ap1 = 0;
363 1.1 matt #if 0
364 1.1 matt {
365 1.1 matt void mvpppc_reboot(void);
366 1.1 matt mvpppc_reboot();
367 1.1 matt }
368 1.1 matt #endif
369 1.1 matt gt_watchdog_reset();
370 1.1 matt /* NOTREACHED */
371 1.1 matt while (1);
372 1.1 matt }
373 1.1 matt
374 1.1 matt int
375 1.1 matt lcsplx(ipl)
376 1.1 matt int ipl;
377 1.1 matt {
378 1.1 matt return spllower(ipl);
379 1.1 matt }
380 1.1 matt
381 1.1 matt int
382 1.1 matt gtget_macaddr(struct gt_softc *gt, int macno, char *enaddr)
383 1.1 matt {
384 1.1 matt enaddr[0] = 0x02;
385 1.1 matt enaddr[1] = 0x00;
386 1.1 matt enaddr[2] = 0x04;
387 1.1 matt enaddr[3] = 0x00;
388 1.1 matt enaddr[4] = 0x00;
389 1.1 matt enaddr[5] = 0x04 + macno;
390 1.1 matt
391 1.1 matt return 0;
392 1.1 matt }
393 1.4 matt
394 1.4 matt void
395 1.4 matt gt_bus_space_init(void)
396 1.4 matt {
397 1.4 matt bus_space_tag_t gt_memt = >_mem_bs_tag;
398 1.4 matt uint32_t datal, datah;
399 1.4 matt int error;
400 1.4 matt
401 1.4 matt error = bus_space_init(>_mem_bs_tag, "gtmem",
402 1.4 matt ex_storage[1], sizeof(ex_storage[0]));
403 1.4 matt
404 1.4 matt
405 1.4 matt error = bus_space_map(gt_memt, 0, 4096, 0, >_memh);
406 1.4 matt
407 1.4 matt datal = bus_space_read_4(gt_memt, gt_memh, GT_CS2_Low_Decode);
408 1.4 matt datah = bus_space_read_4(gt_memt, gt_memh, GT_CS2_High_Decode);
409 1.4 matt gt_obio2_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
410 1.4 matt gt_obio2_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
411 1.4 matt gt_obio2_bs_tag.pbs_offset;
412 1.4 matt
413 1.4 matt error = bus_space_init(>_obio2_bs_tag, "obio2",
414 1.4 matt ex_storage[1], sizeof(ex_storage[1]));
415 1.4 matt
416 1.4 matt datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_Mem0_Low_Decode);
417 1.4 matt datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_Mem0_High_Decode);
418 1.4 matt gt_pci0_mem_bs_tag.pbs_base = GT_LowAddr_GET(datal);
419 1.4 matt gt_pci0_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
420 1.4 matt
421 1.4 matt error = bus_space_init(>_pci0_mem_bs_tag, "pci0-mem",
422 1.4 matt ex_storage[2], sizeof(ex_storage[2]));
423 1.4 matt
424 1.4 matt datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_IO_Low_Decode);
425 1.4 matt datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI0_IO_High_Decode);
426 1.4 matt gt_pci0_io_bs_tag.pbs_base = GT_LowAddr_GET(datal);
427 1.4 matt gt_pci0_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
428 1.4 matt gt_pci0_io_bs_tag.pbs_offset;
429 1.4 matt
430 1.4 matt error = bus_space_init(>_pci0_io_bs_tag, "pci0-ioport",
431 1.4 matt ex_storage[3], sizeof(ex_storage[3]));
432 1.4 matt
433 1.4 matt #if 0
434 1.4 matt error = extent_alloc_region(gt_pci0_io_bs_tag.pbs_extent,
435 1.4 matt 0x10000, 0x7F0000, EX_NOWAIT);
436 1.4 matt if (error)
437 1.4 matt panic("gt_bus_space_init: can't block out reserved "
438 1.4 matt "I/O space 0x10000-0x7fffff: error=%d\n", error);
439 1.4 matt #endif
440 1.4 matt
441 1.4 matt datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_Mem0_Low_Decode);
442 1.4 matt datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_Mem0_High_Decode);
443 1.4 matt gt_pci1_mem_bs_tag.pbs_base = GT_LowAddr_GET(datal);
444 1.4 matt gt_pci1_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
445 1.4 matt
446 1.4 matt error = bus_space_init(>_pci1_mem_bs_tag, "pci1-mem",
447 1.4 matt ex_storage[4], sizeof(ex_storage[4]));
448 1.4 matt
449 1.4 matt datal = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_IO_Low_Decode);
450 1.4 matt datah = bus_space_read_4(gt_memt, gt_memh, GT_PCI1_IO_High_Decode);
451 1.4 matt gt_pci1_io_bs_tag.pbs_base = GT_LowAddr_GET(datal);
452 1.4 matt gt_pci1_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
453 1.4 matt
454 1.4 matt error = bus_space_init(>_pci1_io_bs_tag, "pci1-ioport",
455 1.4 matt ex_storage[5], sizeof(ex_storage[5]));
456 1.4 matt
457 1.4 matt #if 0
458 1.4 matt error = extent_alloc_region(gt_pci1_io_bs_tag.pbs_extent,
459 1.4 matt 0x10000, 0x7F0000, EX_NOWAIT);
460 1.4 matt if (error)
461 1.4 matt panic("gt_bus_space_init: can't block out reserved "
462 1.4 matt "I/O space 0x10000-0x7fffff: error=%d\n", error);
463 1.4 matt #endif
464 1.4 matt }
465 1.4 matt #if 1
466 1.4 matt #define ISSET(t, f) ((t) & (f))
467 1.4 matt
468 1.4 matt #define KCOM_BASE 0xfd000000 /* XXX COM1 */
469 1.4 matt #define KCOM_REGSIZE 0x00001000 /* XXX */
470 1.4 matt
471 1.4 matt unsigned char *kcombase = (unsigned char *)KCOM_BASE;
472 1.4 matt
473 1.4 matt void kcomcninit(struct consdev *);
474 1.4 matt int kcomcngetc(dev_t);
475 1.4 matt void kcomcnpollc(dev_t, int);
476 1.4 matt void kcomcnputc(dev_t, int);
477 1.4 matt
478 1.4 matt static unsigned char kcom_reg_read(int);
479 1.4 matt static void kcom_reg_write(int, unsigned char);
480 1.4 matt
481 1.4 matt /*
482 1.4 matt * The following functions are polled getc and putc routines,
483 1.4 matt * the core of the "kludge" in the Kludge Com driver :-)
484 1.4 matt */
485 1.4 matt
486 1.4 matt static inline unsigned char
487 1.4 matt kcom_reg_read(int off)
488 1.4 matt {
489 1.4 matt unsigned char rv;
490 1.4 matt
491 1.4 matt __asm __volatile ("eieio; lbzx %0,%1,%2; eieio;"
492 1.4 matt : "=r"(rv) : "b"(off << 2), "r"(kcombase));
493 1.4 matt return rv;
494 1.4 matt }
495 1.4 matt
496 1.4 matt static __inline void
497 1.4 matt kcom_reg_write(int off, unsigned char val)
498 1.4 matt {
499 1.4 matt __asm __volatile ("eieio; stbx %0,%1,%2; eieio;"
500 1.4 matt :: "r"(val), "b"(off << 2), "r"(kcombase));
501 1.4 matt
502 1.4 matt }
503 1.4 matt
504 1.4 matt void
505 1.4 matt kcomcninit(struct consdev *cd)
506 1.4 matt {
507 1.4 matt kcom_reg_write(com_ier, 0);
508 1.4 matt kcom_reg_write(com_mcr, MCR_RTS|MCR_DTR);
509 1.4 matt }
510 1.4 matt
511 1.4 matt int
512 1.4 matt kcomcngetc(dev_t dev)
513 1.4 matt {
514 1.4 matt u_char stat, c;
515 1.4 matt
516 1.4 matt /* block until a character becomes available */
517 1.4 matt while (!ISSET(stat = kcom_reg_read(com_lsr), LSR_RXRDY))
518 1.4 matt ;
519 1.4 matt
520 1.4 matt c = kcom_reg_read(com_data);
521 1.4 matt stat = kcom_reg_read(com_iir);
522 1.4 matt return (int)c;
523 1.4 matt }
524 1.4 matt
525 1.4 matt void
526 1.4 matt kcomcnputc(dev_t dev, int c)
527 1.4 matt {
528 1.4 matt int timo;
529 1.4 matt
530 1.4 matt /* wait for any pending transmission to finish */
531 1.4 matt timo = 150000;
532 1.4 matt while ((!ISSET(kcom_reg_read(com_lsr), LSR_TXRDY)) && --timo)
533 1.4 matt continue;
534 1.4 matt
535 1.4 matt kcom_reg_write(com_data, c);
536 1.4 matt
537 1.4 matt /* wait for this transmission to complete */
538 1.4 matt timo = 150000;
539 1.4 matt while ((!ISSET(kcom_reg_read(com_lsr), LSR_TXRDY)) && --timo)
540 1.4 matt continue;
541 1.4 matt }
542 1.4 matt
543 1.4 matt void
544 1.4 matt kcomcnpollc(dev_t dev, int on)
545 1.4 matt {
546 1.4 matt }
547 1.4 matt
548 1.4 matt struct consdev consdev_kcom = {
549 1.4 matt NULL,
550 1.4 matt kcomcninit,
551 1.4 matt kcomcngetc,
552 1.4 matt kcomcnputc,
553 1.4 matt kcomcnpollc,
554 1.4 matt NULL,
555 1.4 matt };
556 1.4 matt
557 1.4 matt #if 1
558 1.4 matt struct consdev *cn_tab = &consdev_kcom;
559 1.4 matt #endif
560 1.4 matt #endif
561