summaryrefslogtreecommitdiff
path: root/sys/arch/alpha/sableio/pckbc_sableio.c
blob: 4af3f9acc7a867fe774d3825da0aa7aac44c2b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* $NetBSD: pckbc_sableio.c,v 1.15 2021/05/07 16:58:34 thorpej Exp $ */

/*-
 * Copyright (c) 1999 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jason R. Thorpe.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */

__KERNEL_RCSID(0, "$NetBSD: pckbc_sableio.c,v 1.15 2021/05/07 16:58:34 thorpej Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <sys/errno.h>
#include <sys/queue.h>
#include <sys/intr.h>
#include <sys/bus.h>

#include <dev/ic/i8042reg.h>
#include <dev/ic/pckbcvar.h>

#include <dev/pci/pcivar.h>
#include <dev/isa/isavar.h>

#include <alpha/sableio/sableiovar.h>

struct pckbc_sableio_softc {
	struct	pckbc_softc sc_pckbc;	/* real "pckbc" softc */

	/* STDIO-specific goo. */
	void	*sc_ih[PCKBC_NSLOTS];	/* interrupt handlers */
	int	sc_irq[PCKBC_NSLOTS];	/* Sable IRQs to use */
	pci_chipset_tag_t sc_pc;	/* PCI chipset for registering intrs */
};

static int	pckbc_sableio_match(device_t, cfdata_t, void *);
static void	pckbc_sableio_attach(device_t, device_t, void *);

CFATTACH_DECL_NEW(pckbc_sableio, sizeof(struct pckbc_sableio_softc),
    pckbc_sableio_match, pckbc_sableio_attach, NULL, NULL);

static void	pckbc_sableio_intr_establish(struct pckbc_softc *,
		    pckbc_slot_t);

static int
pckbc_sableio_match(device_t parent, cfdata_t match, void *aux)
{
	struct sableio_attach_args *sa = aux;

	/* Always present. */
	if (strcmp(sa->sa_name, match->cf_name) == 0)
		return (1);

	return (0);
}

static void
pckbc_sableio_attach(device_t parent, device_t self, void *aux)
{
	struct pckbc_sableio_softc *ssc = device_private(self);
	struct pckbc_softc *sc = &ssc->sc_pckbc;
	struct sableio_attach_args *sa = aux;
	struct pckbc_internal *t;
	bus_space_handle_t ioh_d, ioh_c;

	sc->sc_dv = self;
	ssc->sc_pc = sa->sa_pc;

	/*
	 * Set up IRQs.
	 */
	ssc->sc_irq[PCKBC_KBD_SLOT] = sa->sa_sableirq[0];
	ssc->sc_irq[PCKBC_AUX_SLOT] = sa->sa_sableirq[1];

	sc->intr_establish = pckbc_sableio_intr_establish;

	if (pckbc_is_console(sa->sa_iot, sa->sa_ioaddr)) {
		t = &pckbc_consdata;
		pckbc_console_attached = 1;
		/* t->t_cmdbyte was initialized by cnattach */
	} else {
		if (bus_space_map(sa->sa_iot, sa->sa_ioaddr + KBDATAP,
				  1, 0, &ioh_d) != 0 ||
		    bus_space_map(sa->sa_iot, sa->sa_ioaddr + KBCMDP,
				  1, 0, &ioh_c) != 0)
			panic("pckbc_sableio_attach: couldn't map");

		t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
		t->t_iot = sa->sa_iot;
		t->t_ioh_d = ioh_d;
		t->t_ioh_c = ioh_c;
		t->t_addr = sa->sa_ioaddr;
		t->t_cmdbyte = KC8_CPU; /* Enable ports */
	}

	t->t_sc = sc;
	sc->id = t;

	aprint_normal("\n");

	/* Finish off the attach. */
	pckbc_attach(sc);
}

static void
pckbc_sableio_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
{
	struct pckbc_sableio_softc *ssc = (void *) sc;
	const char *intrstr;
	char buf[PCI_INTRSTR_LEN];
	pci_intr_handle_t ih;

	alpha_pci_intr_handle_init(&ih, ssc->sc_irq[slot], 0);

	intrstr = pci_intr_string(ssc->sc_pc, ih, buf,
	    sizeof(buf));
	ssc->sc_ih[slot] = pci_intr_establish(ssc->sc_pc, ih,
	    IPL_TTY, pckbcintr, sc);
	if (ssc->sc_ih[slot] == NULL) {
		aprint_error_dev(sc->sc_dv,
		    "unable to establish interrupt for %s slot",
		    pckbc_slot_names[slot]);
		if (intrstr != NULL)
			aprint_error(" at %s", intrstr);
		aprint_error("\n");
		return;
	}
	aprint_normal_dev(sc->sc_dv, "%s slot interrupting at %s\n",
	    pckbc_slot_names[slot], intrstr);
}