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