xref: /netbsd-src/sys/arch/evbppc/virtex/consinit.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: consinit.c,v 1.3 2011/07/01 19:03:50 dyoung 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.3 2011/07/01 19:03:50 dyoung 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 struct consdev 		*cn_tab = NULL;
58 bus_space_tag_t 	consdev_iot;
59 bus_space_handle_t 	consdev_ioh;
60 
61 #if defined(KGDB)
62 bus_space_tag_t 	kgdb_iot;
63 bus_space_handle_t 	kgdb_ioh;
64 #endif
65 
66 
67 /*
68  * Initialize the system console (hmm, as if anyone can see those panics).
69  */
70 void
71 consinit(void)
72 {
73 	static int 	initted = 0;
74 
75 	if (initted)
76 		return;
77 
78 	/* Pick MD knowledge about console. */
79 	if (virtex_bus_space_tag(CONS_NAME, &consdev_iot))
80 		panic("No bus space for %s console", CONS_NAME);
81 
82 #if defined(KGDB)
83 	if (virtex_bus_space_tag(KGDB_NAME, &kgdb_iot))
84 		panic("No bus space for %s kgdb", KGDB_NAME);
85 #endif
86 
87 #if NXLCOM > 0
88 #if defined(KGDB)
89 	if (strncmp("xlcom", KGDB_NAME, 5)) {
90 		xlcom_kgdbinit();
91 
92 		/* Overtake console device, we're higher priority. */
93 		if (strcmp(KGDB_NAME, CONS_NAME) == 0 &&
94 		    KGDB_ADDR == CONS_ADDR)
95 			goto done;
96 	}
97 #endif
98 	if (strncmp("xlcom", CONS_NAME, 5) == 0) {
99 		cn_tab = &consdev_xlcom;
100 		xlcom_cninit(cn_tab, CONS_ADDR);
101 
102 		goto done;
103 	}
104 #endif
105 
106 	panic("No console"); 	/* XXX really panic? */
107  done:
108 	/* If kgdb overtook console, cn_tab is NULL and dev/cons.c deals. */
109 	initted = 1;
110 }
111