pckbc_sableio.c revision 1.5 1 /* $NetBSD: pckbc_sableio.c,v 1.5 2002/10/02 04:06:39 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
40
41 __KERNEL_RCSID(0, "$NetBSD: pckbc_sableio.c,v 1.5 2002/10/02 04:06:39 thorpej Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/proc.h>
47 #include <sys/device.h>
48 #include <sys/malloc.h>
49 #include <sys/errno.h>
50 #include <sys/queue.h>
51 #include <sys/lock.h>
52
53 #include <machine/intr.h>
54 #include <machine/bus.h>
55
56 #include <dev/ic/i8042reg.h>
57 #include <dev/ic/pckbcvar.h>
58
59 #include <dev/pci/pcivar.h>
60 #include <dev/isa/isavar.h>
61
62 #include <alpha/sableio/sableiovar.h>
63
64 struct pckbc_sableio_softc {
65 struct pckbc_softc sc_pckbc; /* real "pckbc" softc */
66
67 /* STDIO-specific goo. */
68 void *sc_ih[PCKBC_NSLOTS]; /* interrupt handlers */
69 int sc_irq[PCKBC_NSLOTS]; /* Sable IRQs to use */
70 pci_chipset_tag_t sc_pc; /* PCI chipset for registering intrs */
71 };
72
73 int pckbc_sableio_match(struct device *, struct cfdata *, void *);
74 void pckbc_sableio_attach(struct device *, struct device *, void *);
75
76 CFATTACH_DECL(pckbc_sableio, sizeof(struct pckbc_sableio_softc),
77 pckbc_sableio_match, pckbc_sableio_attach, NULL, NULL);
78
79 void pckbc_sableio_intr_establish(struct pckbc_softc *, pckbc_slot_t);
80
81 int
82 pckbc_sableio_match(struct device *parent, struct cfdata *match, void *aux)
83 {
84 struct sableio_attach_args *sa = aux;
85
86 /* Always present. */
87 if (strcmp(sa->sa_name, match->cf_name) == 0)
88 return (1);
89
90 return (0);
91 }
92
93 void
94 pckbc_sableio_attach(struct device *parent, struct device *self, void *aux)
95 {
96 struct pckbc_sableio_softc *ssc = (void *)self;
97 struct pckbc_softc *sc = &ssc->sc_pckbc;
98 struct sableio_attach_args *sa = aux;
99 struct pckbc_internal *t;
100 bus_space_handle_t ioh_d, ioh_c;
101
102 ssc->sc_pc = sa->sa_pc;
103
104 /*
105 * Set up IRQs.
106 */
107 ssc->sc_irq[PCKBC_KBD_SLOT] = sa->sa_sableirq[0];
108 ssc->sc_irq[PCKBC_AUX_SLOT] = sa->sa_sableirq[1];
109
110 sc->intr_establish = pckbc_sableio_intr_establish;
111
112 if (pckbc_is_console(sa->sa_iot, sa->sa_ioaddr)) {
113 t = &pckbc_consdata;
114 pckbc_console_attached = 1;
115 /* t->t_cmdbyte was initialized by cnattach */
116 } else {
117 if (bus_space_map(sa->sa_iot, sa->sa_ioaddr + KBDATAP,
118 1, 0, &ioh_d) != 0 ||
119 bus_space_map(sa->sa_iot, sa->sa_ioaddr + KBCMDP,
120 1, 0, &ioh_c) != 0)
121 panic("pckbc_sableio_attach: couldn't map");
122
123 t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
124 memset(t, 0, sizeof(struct pckbc_internal));
125 t->t_iot = sa->sa_iot;
126 t->t_ioh_d = ioh_d;
127 t->t_ioh_c = ioh_c;
128 t->t_addr = sa->sa_ioaddr;
129 t->t_cmdbyte = KC8_CPU; /* Enable ports */
130 }
131
132 t->t_sc = sc;
133 sc->id = t;
134
135 printf("\n");
136
137 /* Finish off the attach. */
138 pckbc_attach(sc);
139 }
140
141 void
142 pckbc_sableio_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
143 {
144 struct pckbc_sableio_softc *ssc = (void *) sc;
145 const char *intrstr;
146
147 intrstr = pci_intr_string(ssc->sc_pc, ssc->sc_irq[slot]);
148 ssc->sc_ih[slot] = pci_intr_establish(ssc->sc_pc, ssc->sc_irq[slot],
149 IPL_TTY, pckbcintr, sc);
150 if (ssc->sc_ih[slot] == NULL) {
151 printf("%s: unable to establish interrupt for %s slot",
152 sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
153 if (intrstr != NULL)
154 printf(" at %s", intrstr);
155 printf("\n");
156 return;
157 }
158 printf("%s: %s slot interrupting at %s\n", sc->sc_dv.dv_xname,
159 pckbc_slot_names[slot], intrstr);
160 }
161