xref: /openbsd/sys/arch/luna88k/dev/sio.c (revision 0408a2d2)
1 /* $OpenBSD: sio.c,v 1.7 2021/10/24 09:18:51 deraadt Exp $ */
2 /* $NetBSD: sio.c,v 1.1 2000/01/05 08:48:55 nisimura Exp $ */
3 
4 /*-
5  * Copyright (c) 2000 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Tohru Nishimura.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /* from NetBSD/luna68k dev/sio.c */
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <machine/cpu.h>
40 #include <machine/autoconf.h>
41 
42 #include <luna88k/luna88k/isr.h>
43 #include <luna88k/dev/siovar.h>
44 
45 int  sio_match(struct device *, void *, void *);
46 void sio_attach(struct device *, struct device *, void *);
47 int  sio_print(void *, const char *);
48 
49 const struct cfattach sio_ca = {
50 	sizeof(struct sio_softc), sio_match, sio_attach
51 };
52 
53 struct cfdriver sio_cd = {
54 	NULL, "sio", DV_DULL,
55 };
56 
57 void nullintr(void *);
58 int xsiointr(void *);
59 
60 int
sio_match(struct device * parent,void * cf,void * aux)61 sio_match(struct device *parent, void *cf, void *aux)
62 {
63 	struct mainbus_attach_args *ma = aux;
64 
65 	if (strcmp(ma->ma_name, sio_cd.cd_name))
66 		return 0;
67 	if (badaddr((vaddr_t)ma->ma_addr, 4))
68 		return 0;
69 	return 1;
70 }
71 
72 void
sio_attach(struct device * parent,struct device * self,void * aux)73 sio_attach(struct device *parent, struct device *self, void *aux)
74 {
75 	struct sio_softc *sc = (void *)self;
76 	struct mainbus_attach_args *ma = aux;
77 	struct sio_attach_args sio_args;
78 	int channel;
79 	extern int sysconsole; /* console: 0 for ttya, 1 for desktop */
80 
81 	printf(": 7201a\n");
82 
83 	sc->sc_ctl = (void *)ma->ma_addr;
84 	for (channel = 0; channel < 2; channel++) {
85 		sc->sc_intrhand[channel].ih_func = nullintr;
86 		sio_args.channel = channel;
87 		sio_args.hwflags = (channel == sysconsole);
88 		config_found(self, (void *)&sio_args, sio_print);
89 	}
90 
91 	isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF,
92 	    self->dv_xname);
93 }
94 
95 int
sio_print(void * aux,const char * name)96 sio_print(void *aux, const char *name)
97 {
98 	struct sio_attach_args *args = aux;
99 
100 	if (name != NULL)
101 		printf("%s: ", name);
102 
103 	if (args->channel != -1)
104 		printf(" channel %d", args->channel);
105 
106 	return UNCONF;
107 }
108 
109 int
xsiointr(void * arg)110 xsiointr(void *arg)
111 {
112 	struct sio_softc *sc = arg;
113 
114 	/* channel 0: ttya system serial port */
115 	(*sc->sc_intrhand[0].ih_func)(sc->sc_intrhand[0].ih_arg);
116 
117 	/* channel 1: keyboard and mouse */
118 	(*sc->sc_intrhand[1].ih_func)(sc->sc_intrhand[1].ih_arg);
119 
120 	return 1;
121 }
122 
123 void
nullintr(void * arg)124 nullintr(void *arg)
125 {
126 }
127