xref: /netbsd/sys/arch/i386/pnpbios/lm_pnpbios.c (revision bf9ec67e)
1 /*	$NetBSD: lm_pnpbios.c,v 1.4 2001/11/15 07:03:35 lukem Exp $ */
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Bill Squier.
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>
40 __KERNEL_RCSID(0, "$NetBSD: lm_pnpbios.c,v 1.4 2001/11/15 07:03:35 lukem Exp $");
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/errno.h>
45 #include <sys/ioctl.h>
46 #include <sys/syslog.h>
47 #include <sys/device.h>
48 #include <sys/proc.h>
49 
50 #include <machine/bus.h>
51 
52 #include <dev/isa/isavar.h>
53 #include <dev/isa/isadmavar.h>
54 
55 #include <i386/pnpbios/pnpbiosvar.h>
56 
57 #include <dev/sysmon/sysmonvar.h>
58 
59 #include <dev/ic/nslm7xvar.h>
60 
61 
62 int lm_pnpbios_match __P((struct device *, struct cfdata *, void *));
63 void lm_pnpbios_attach __P((struct device *, struct device *, void *));
64 int lm_pnpbios_hints_index __P((const char *));
65 
66 
67 struct cfattach lm_pnpbios_ca = {
68 	sizeof(struct lm_softc), lm_pnpbios_match, lm_pnpbios_attach
69 };
70 
71 /*
72  * XXX - no known pnpbios ids for lm series chips.
73  */
74 struct lm_pnpbios_hint {
75 	char idstr[8];
76 	int io_region_idx_lm7x;
77 };
78 
79 /*
80  * Currently no known valid pnpbios id's - PNP0C02 is
81  * for reserved motherboard resources, probing it is bad.
82  */
83 struct lm_pnpbios_hint lm_pnpbios_hints[] = {
84 	{ { 0 }, 0 }
85 };
86 
87 
88 int
89 lm_pnpbios_hints_index(idstr)
90 	const char *idstr;
91 {
92 	int idx = 0;
93 
94 	while (lm_pnpbios_hints[idx].idstr[0] != 0) {
95 		if (!strcmp(lm_pnpbios_hints[idx].idstr, idstr))
96 			return idx;
97 		++idx;
98 	}
99 
100 	return -1;
101 }
102 
103 int
104 lm_pnpbios_match(parent, match, aux)
105 	struct device *parent;
106 	struct cfdata *match;
107 	void *aux;
108 {
109 	struct pnpbiosdev_attach_args *aa = aux;
110 	struct lm_pnpbios_hint *wph;
111 	bus_space_tag_t iot;
112 	bus_space_handle_t ioh;
113 	int rv;
114 
115 	int wphi;
116 
117 	if ((wphi = lm_pnpbios_hints_index(aa->idstr)) == -1)
118 		return (0);
119 
120 	wph = &lm_pnpbios_hints[wphi];
121 
122 	if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
123 			   &iot, &ioh)) {
124 		return (0);
125 	}
126 
127 	rv = lm_probe(iot, ioh);
128 
129 	pnpbios_io_unmap(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
130 			 iot, ioh);
131 
132 	return (rv);
133 }
134 
135 void
136 lm_pnpbios_attach(parent, self, aux)
137 	struct device *parent, *self;
138 	void *aux;
139 {
140 	struct lm_softc *sc = (void *)self;
141 	struct pnpbiosdev_attach_args *aa = aux;
142 	struct lm_pnpbios_hint *wph;
143 
144 	wph = &lm_pnpbios_hints[lm_pnpbios_hints_index(aa->idstr)];
145 
146 	if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
147 			   &sc->lm_iot, &sc->lm_ioh)) {
148 		printf(": can't map i/o space\n");
149 		return;
150 	}
151 
152 	printf("\n");
153 	pnpbios_print_devres(self, aa);
154 
155 	printf("%s", self->dv_xname);
156 
157 	/* Bus-independant attach */
158 	lm_attach(sc);
159 }
160 
161