Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / i386 / pnpbios / lm_pnpbios.c
blobef3cfd26807bef00bfd539965e68ed2fcf842d37
1 /* $NetBSD: lm_pnpbios.c,v 1.13 2008/03/05 15:41:31 xtraeme Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bill Squier.
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: lm_pnpbios.c,v 1.13 2008/03/05 15:41:31 xtraeme Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/errno.h>
38 #include <sys/ioctl.h>
39 #include <sys/syslog.h>
40 #include <sys/device.h>
41 #include <sys/proc.h>
43 #include <machine/bus.h>
45 #include <dev/isa/isavar.h>
46 #include <dev/isa/isadmavar.h>
48 #include <i386/pnpbios/pnpbiosvar.h>
50 #include <dev/sysmon/sysmonvar.h>
52 #include <dev/ic/nslm7xvar.h>
55 int lm_pnpbios_match(device_t, cfdata_t, void *);
56 void lm_pnpbios_attach(device_t, device_t, void *);
58 int lm_pnpbios_hints_index(const char *);
59 uint8_t lm_pnpbios_readreg(struct lm_softc *, int);
60 void lm_pnpbios_writereg(struct lm_softc *, int, int);
63 CFATTACH_DECL_NEW(lm_pnpbios, sizeof(struct lm_softc),
64 lm_pnpbios_match, lm_pnpbios_attach, NULL, NULL);
67 * XXX - no known pnpbios ids for lm series chips.
69 struct lm_pnpbios_hint {
70 char idstr[8];
71 int io_region_idx_lm7x;
75 * Currently no known valid pnpbios id's - PNP0C02 is
76 * for reserved motherboard resources, probing it is bad.
78 struct lm_pnpbios_hint lm_pnpbios_hints[] = {
79 { { 0 }, 0 }
83 int
84 lm_pnpbios_hints_index(const char *idstr)
86 int idx = 0;
88 while (lm_pnpbios_hints[idx].idstr[0] != 0) {
89 if (!strcmp(lm_pnpbios_hints[idx].idstr, idstr))
90 return idx;
91 ++idx;
94 return -1;
97 int
98 lm_pnpbios_match(device_t parent, cfdata_t match, void *aux)
100 struct pnpbiosdev_attach_args *aa = aux;
101 struct lm_pnpbios_hint *wph;
102 bus_space_tag_t iot;
103 bus_space_handle_t ioh;
104 int rv;
106 int wphi;
108 if ((wphi = lm_pnpbios_hints_index(aa->idstr)) == -1)
109 return 0;
111 wph = &lm_pnpbios_hints[wphi];
113 if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
114 &iot, &ioh)) {
115 return 0;
118 rv = lm_probe(iot, ioh);
120 pnpbios_io_unmap(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
121 iot, ioh);
123 return rv;
126 void
127 lm_pnpbios_attach(device_t parent, device_t self, void *aux)
129 struct lm_softc *sc = device_private(self);
130 struct pnpbiosdev_attach_args *aa = aux;
131 struct lm_pnpbios_hint *wph;
133 wph = &lm_pnpbios_hints[lm_pnpbios_hints_index(aa->idstr)];
135 if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
136 &sc->lm_iot, &sc->lm_ioh)) {
137 aprint_error(": can't map i/o space\n");
138 return;
141 aprint_naive("\n");
142 aprint_normal("\n");
143 pnpbios_print_devres(self, aa);
145 /* Bus-independent attach */
146 sc->lm_writereg = lm_pnpbios_writereg;
147 sc->lm_readreg = lm_pnpbios_readreg;
149 lm_attach(sc);
152 uint8_t
153 lm_pnpbios_readreg(struct lm_softc *sc, int reg)
155 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
156 return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA));
160 void
161 lm_pnpbios_writereg(struct lm_softc *sc, int reg, int val)
163 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
164 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);