lm_pnpbios.c revision 1.9
11.9Sperry/* $NetBSD: lm_pnpbios.c,v 1.9 2005/02/03 20:08:55 perry Exp $ */ 21.1Sgroo 31.1Sgroo/*- 41.1Sgroo * Copyright (c) 2000 The NetBSD Foundation, Inc. 51.1Sgroo * All rights reserved. 61.1Sgroo * 71.1Sgroo * This code is derived from software contributed to The NetBSD Foundation 81.1Sgroo * by Bill Squier. 91.1Sgroo * 101.1Sgroo * Redistribution and use in source and binary forms, with or without 111.1Sgroo * modification, are permitted provided that the following conditions 121.1Sgroo * are met: 131.1Sgroo * 1. Redistributions of source code must retain the above copyright 141.1Sgroo * notice, this list of conditions and the following disclaimer. 151.1Sgroo * 2. Redistributions in binary form must reproduce the above copyright 161.1Sgroo * notice, this list of conditions and the following disclaimer in the 171.1Sgroo * documentation and/or other materials provided with the distribution. 181.1Sgroo * 3. All advertising materials mentioning features or use of this software 191.1Sgroo * must display the following acknowledgement: 201.1Sgroo * This product includes software developed by the NetBSD 211.1Sgroo * Foundation, Inc. and its contributors. 221.1Sgroo * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sgroo * contributors may be used to endorse or promote products derived 241.1Sgroo * from this software without specific prior written permission. 251.1Sgroo * 261.1Sgroo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sgroo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sgroo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sgroo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sgroo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sgroo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sgroo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sgroo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sgroo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sgroo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sgroo * POSSIBILITY OF SUCH DAMAGE. 371.1Sgroo */ 381.4Slukem 391.4Slukem#include <sys/cdefs.h> 401.9Sperry__KERNEL_RCSID(0, "$NetBSD: lm_pnpbios.c,v 1.9 2005/02/03 20:08:55 perry Exp $"); 411.1Sgroo 421.1Sgroo#include <sys/param.h> 431.1Sgroo#include <sys/systm.h> 441.1Sgroo#include <sys/errno.h> 451.1Sgroo#include <sys/ioctl.h> 461.1Sgroo#include <sys/syslog.h> 471.1Sgroo#include <sys/device.h> 481.1Sgroo#include <sys/proc.h> 491.1Sgroo 501.1Sgroo#include <machine/bus.h> 511.1Sgroo 521.1Sgroo#include <dev/isa/isavar.h> 531.1Sgroo#include <dev/isa/isadmavar.h> 541.1Sgroo 551.1Sgroo#include <i386/pnpbios/pnpbiosvar.h> 561.1Sgroo 571.3Sthorpej#include <dev/sysmon/sysmonvar.h> 581.3Sthorpej 591.1Sgroo#include <dev/ic/nslm7xvar.h> 601.1Sgroo 611.1Sgroo 621.9Sperryint lm_pnpbios_match(struct device *, struct cfdata *, void *); 631.9Sperryvoid lm_pnpbios_attach(struct device *, struct device *, void *); 641.9Sperryint lm_pnpbios_hints_index(const char *); 651.8Sadu_int8_t lm_pnpbios_readreg(struct lm_softc *, int); 661.8Sadvoid lm_pnpbios_writereg(struct lm_softc *, int, int); 671.1Sgroo 681.1Sgroo 691.7SthorpejCFATTACH_DECL(lm_pnpbios, sizeof(struct lm_softc), 701.7Sthorpej lm_pnpbios_match, lm_pnpbios_attach, NULL, NULL); 711.1Sgroo 721.1Sgroo/* 731.2Sgroo * XXX - no known pnpbios ids for lm series chips. 741.1Sgroo */ 751.1Sgroostruct lm_pnpbios_hint { 761.1Sgroo char idstr[8]; 771.1Sgroo int io_region_idx_lm7x; 781.1Sgroo}; 791.1Sgroo 801.2Sgroo/* 811.2Sgroo * Currently no known valid pnpbios id's - PNP0C02 is 821.2Sgroo * for reserved motherboard resources, probing it is bad. 831.2Sgroo */ 841.1Sgroostruct lm_pnpbios_hint lm_pnpbios_hints[] = { 851.1Sgroo { { 0 }, 0 } 861.1Sgroo}; 871.1Sgroo 881.1Sgroo 891.1Sgrooint 901.1Sgroolm_pnpbios_hints_index(idstr) 911.1Sgroo const char *idstr; 921.1Sgroo{ 931.1Sgroo int idx = 0; 941.1Sgroo 951.1Sgroo while (lm_pnpbios_hints[idx].idstr[0] != 0) { 961.1Sgroo if (!strcmp(lm_pnpbios_hints[idx].idstr, idstr)) 971.1Sgroo return idx; 981.1Sgroo ++idx; 991.1Sgroo } 1001.1Sgroo 1011.1Sgroo return -1; 1021.1Sgroo} 1031.1Sgroo 1041.1Sgrooint 1051.1Sgroolm_pnpbios_match(parent, match, aux) 1061.1Sgroo struct device *parent; 1071.1Sgroo struct cfdata *match; 1081.1Sgroo void *aux; 1091.1Sgroo{ 1101.1Sgroo struct pnpbiosdev_attach_args *aa = aux; 1111.2Sgroo struct lm_pnpbios_hint *wph; 1121.2Sgroo bus_space_tag_t iot; 1131.2Sgroo bus_space_handle_t ioh; 1141.2Sgroo int rv; 1151.2Sgroo 1161.2Sgroo int wphi; 1171.1Sgroo 1181.2Sgroo if ((wphi = lm_pnpbios_hints_index(aa->idstr)) == -1) 1191.1Sgroo return (0); 1201.1Sgroo 1211.2Sgroo wph = &lm_pnpbios_hints[wphi]; 1221.2Sgroo 1231.2Sgroo if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x, 1241.2Sgroo &iot, &ioh)) { 1251.2Sgroo return (0); 1261.2Sgroo } 1271.2Sgroo 1281.2Sgroo rv = lm_probe(iot, ioh); 1291.2Sgroo 1301.2Sgroo pnpbios_io_unmap(aa->pbt, aa->resc, wph->io_region_idx_lm7x, 1311.2Sgroo iot, ioh); 1321.2Sgroo 1331.2Sgroo return (rv); 1341.1Sgroo} 1351.1Sgroo 1361.1Sgroovoid 1371.1Sgroolm_pnpbios_attach(parent, self, aux) 1381.1Sgroo struct device *parent, *self; 1391.1Sgroo void *aux; 1401.1Sgroo{ 1411.1Sgroo struct lm_softc *sc = (void *)self; 1421.1Sgroo struct pnpbiosdev_attach_args *aa = aux; 1431.1Sgroo struct lm_pnpbios_hint *wph; 1441.1Sgroo 1451.1Sgroo wph = &lm_pnpbios_hints[lm_pnpbios_hints_index(aa->idstr)]; 1461.1Sgroo 1471.1Sgroo if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x, 1481.1Sgroo &sc->lm_iot, &sc->lm_ioh)) { 1491.1Sgroo printf(": can't map i/o space\n"); 1501.1Sgroo return; 1511.1Sgroo } 1521.1Sgroo 1531.1Sgroo printf("\n"); 1541.1Sgroo pnpbios_print_devres(self, aa); 1551.1Sgroo 1561.1Sgroo printf("%s", self->dv_xname); 1571.1Sgroo 1581.1Sgroo /* Bus-independant attach */ 1591.8Sad sc->lm_writereg = lm_pnpbios_writereg; 1601.8Sad sc->lm_readreg = lm_pnpbios_readreg; 1611.8Sad 1621.1Sgroo lm_attach(sc); 1631.1Sgroo} 1641.1Sgroo 1651.8Sadu_int8_t 1661.8Sadlm_pnpbios_readreg(sc, reg) 1671.8Sad struct lm_softc *sc; 1681.8Sad int reg; 1691.8Sad{ 1701.8Sad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg); 1711.8Sad return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA)); 1721.8Sad} 1731.8Sad 1741.8Sad 1751.8Sadvoid 1761.8Sadlm_pnpbios_writereg(sc, reg, val) 1771.8Sad struct lm_softc *sc; 1781.8Sad int reg; 1791.8Sad int val; 1801.8Sad{ 1811.8Sad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg); 1821.8Sad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val); 1831.8Sad} 184