plumisa_machdep.c revision 1.11
1/*	$NetBSD: plumisa_machdep.c,v 1.11 2009/08/19 15:12:31 dyoung 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 UCHIYAMA Yasushi.
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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: plumisa_machdep.c,v 1.11 2009/08/19 15:12:31 dyoung Exp $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37
38#include <machine/bus.h>
39
40#include <dev/isa/isavar.h>
41#include <dev/isa/isareg.h>
42
43#include <machine/platid.h>
44#include <machine/platid_mask.h>
45
46#include <hpcmips/tx/tx39var.h>
47#include <hpcmips/dev/plumvar.h>
48#include <hpcmips/dev/plumicuvar.h>
49#include <hpcmips/dev/plumiobusvar.h>
50
51#include "locators.h"
52
53int	plumisabprint(void *, const char *);
54int	plumisabmatch(struct device *, struct cfdata *, void *);
55void	plumisabattach(struct device *, struct device *, void *);
56
57struct plumisab_softc {
58	struct device sc_dev;
59	plum_chipset_tag_t sc_pc;
60	bus_space_tag_t sc_iot;
61	int sc_irq;
62	void *sc_ih;
63};
64
65CFATTACH_DECL(plumisab, sizeof(struct plumisab_softc),
66    plumisabmatch, plumisabattach, NULL, NULL);
67
68int
69plumisabmatch(struct device *parent, struct cfdata *match, void *aux)
70{
71	struct plumiobus_attach_args *pba = aux;
72	platid_mask_t mask;
73
74	if (strcmp(pba->pba_busname, match->cf_name)) {
75		return (0);
76	}
77
78	if (match->cf_loc[PLUMIOBUSIFCF_PLATFORM] ==
79	    PLUMIOBUSIFCF_PLATFORM_DEFAULT) {
80		return (1);
81	}
82
83	mask = PLATID_DEREF(match->cf_loc[PLUMIOBUSIFCF_PLATFORM]);
84	if (platid_match(&platid, &mask)) {
85		return (2);
86	}
87
88	return (0);
89}
90
91void
92plumisabattach(struct device *parent, struct device *self, void *aux)
93{
94	struct plumiobus_attach_args *pba = aux;
95	struct plumisab_softc *sc = (void*)self;
96	struct isabus_attach_args iba;
97
98	printf("\n");
99	sc->sc_pc = pba->pba_pc;
100	sc->sc_iot = pba->pba_iot;
101	sc->sc_irq = pba->pba_irq;
102	printf(" base=%#x irq=%d\n", sc->sc_iot->t_base, sc->sc_irq);
103#if 0
104	/* Reset I/O bus */
105	plum_power_ioreset(sc->sc_pc);
106#endif
107	/* Dump I/O port */
108	if (0) {
109		bus_space_handle_t ioh;
110		int i;
111		bus_space_map(sc->sc_iot, 0, 0x400, 0, &ioh);
112		for(i = 0; i < 0x400; i += 4) {
113			printf("[%03x]%02x", i, bus_space_read_1(sc->sc_iot, ioh, i + 3));
114			printf("%02x", bus_space_read_1(sc->sc_iot, ioh, i + 2));
115			printf("%02x", bus_space_read_1(sc->sc_iot, ioh, i + 1));
116			printf("%02x", bus_space_read_1(sc->sc_iot, ioh, i + 0));
117		}
118		bus_space_unmap(sc->sc_iot, ioh, 0x400);
119	}
120
121	iba.iba_ic	= sc;
122	/* Plum ISA-bus don't have memory space! */
123	/* Plum ISA port space */
124	iba.iba_iot     = sc->sc_iot;
125	config_found_ia(self, "isabus", &iba, plumisabprint);
126}
127
128int
129plumisabprint(void *aux, const char *pnp)
130{
131
132	return (pnp ? QUIET : UNCONF);
133}
134
135void
136isa_attach_hook(struct device *parent, struct device *self,
137    struct isabus_attach_args *iba)
138{
139
140}
141
142void
143isa_detach_hook(isa_chipset_tag_t, device_t self)
144{
145}
146
147void *
148isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level,
149    int (*ih_fun)(void *), void *ih_arg)
150{
151	struct plumisab_softc *sc = (void*)ic;
152
153	sc->sc_ih = plum_intr_establish(sc->sc_pc, sc->sc_irq, type, level,
154					ih_fun, ih_arg);
155	return (sc->sc_ih);
156}
157
158void
159isa_intr_disestablish(isa_chipset_tag_t ic, void *arg)
160{
161	struct plumisab_softc *sc = (void*)ic;
162
163	plum_intr_disestablish(sc->sc_pc, arg);
164}
165
166int
167isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq)
168{
169	struct plumisab_softc *sc = (void*)ic;
170
171	*irq = sc->sc_irq;
172
173	return (0);
174}
175