xref: /netbsd-src/sys/arch/evbppc/virtex/consinit.c (revision 0ded96f53971bbc6b45e00f37f37be3beef30ed0)
1 /*	$NetBSD: consinit.c,v 1.4 2021/03/29 13:14:13 rin Exp $ */
2 
3 /*
4  * Copyright (c) 2006 Jachym Holecek
5  * All rights reserved.
6  *
7  * Written for DFC Design, s.r.o.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "opt_cons.h"
33 #include "xlcom.h"
34 
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.4 2021/03/29 13:14:13 rin Exp $");
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 
42 #include <sys/bus.h>
43 
44 #include <evbppc/virtex/virtex.h>
45 
46 #include <dev/cons.h>
47 
48 
49 #if NXLCOM > 0
50 extern struct consdev 	consdev_xlcom;
51 void    		xlcom_cninit(struct consdev *, bus_addr_t);
52 #if defined(KGDB)
53 void 			xlcom_kgdbinit(void);
54 #endif
55 #endif
56 
57 bus_space_tag_t 	consdev_iot;
58 bus_space_handle_t 	consdev_ioh;
59 
60 #if defined(KGDB)
61 bus_space_tag_t 	kgdb_iot;
62 bus_space_handle_t 	kgdb_ioh;
63 #endif
64 
65 
66 /*
67  * Initialize the system console (hmm, as if anyone can see those panics).
68  */
69 void
consinit(void)70 consinit(void)
71 {
72 	static int 	initted = 0;
73 
74 	if (initted)
75 		return;
76 
77 	/* Pick MD knowledge about console. */
78 	if (virtex_bus_space_tag(CONS_NAME, &consdev_iot))
79 		panic("No bus space for %s console", CONS_NAME);
80 
81 #if defined(KGDB)
82 	if (virtex_bus_space_tag(KGDB_NAME, &kgdb_iot))
83 		panic("No bus space for %s kgdb", KGDB_NAME);
84 #endif
85 
86 #if NXLCOM > 0
87 #if defined(KGDB)
88 	if (strncmp("xlcom", KGDB_NAME, 5)) {
89 		xlcom_kgdbinit();
90 
91 		/* Overtake console device, we're higher priority. */
92 		if (strcmp(KGDB_NAME, CONS_NAME) == 0 &&
93 		    KGDB_ADDR == CONS_ADDR)
94 			goto done;
95 	}
96 #endif
97 	if (strncmp("xlcom", CONS_NAME, 5) == 0) {
98 		cn_tab = &consdev_xlcom;
99 		xlcom_cninit(cn_tab, CONS_ADDR);
100 
101 		goto done;
102 	}
103 #endif
104 
105 	panic("No console"); 	/* XXX really panic? */
106  done:
107 	/* If kgdb overtook console, cn_tab is NULL and dev/cons.c deals. */
108 	initted = 1;
109 }
110