lm_pnpbios.c revision 1.15
1/* $NetBSD: lm_pnpbios.c,v 1.15 2011/07/01 18:14:15 dyoung 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 * 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: lm_pnpbios.c,v 1.15 2011/07/01 18:14:15 dyoung Exp $"); 34 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> 42 43#include <sys/bus.h> 44 45#include <dev/isa/isavar.h> 46#include <dev/isa/isadmavar.h> 47 48#include <i386/pnpbios/pnpbiosvar.h> 49 50#include <dev/sysmon/sysmonvar.h> 51 52#include <dev/ic/nslm7xvar.h> 53 54 55int lm_pnpbios_match(device_t, cfdata_t, void *); 56void lm_pnpbios_attach(device_t, device_t, void *); 57 58int lm_pnpbios_hints_index(const char *); 59uint8_t lm_pnpbios_readreg(struct lm_softc *, int); 60void lm_pnpbios_writereg(struct lm_softc *, int, int); 61 62 63CFATTACH_DECL_NEW(lm_pnpbios, sizeof(struct lm_softc), 64 lm_pnpbios_match, lm_pnpbios_attach, NULL, NULL); 65 66/* 67 * XXX - no known pnpbios ids for lm series chips. 68 */ 69struct lm_pnpbios_hint { 70 char idstr[8]; 71 int io_region_idx_lm7x; 72}; 73 74/* 75 * Currently no known valid pnpbios id's - PNP0C02 is 76 * for reserved motherboard resources, probing it is bad. 77 */ 78struct lm_pnpbios_hint lm_pnpbios_hints[] = { 79 { { 0 }, 0 } 80}; 81 82 83int 84lm_pnpbios_hints_index(const char *idstr) 85{ 86 int idx = 0; 87 88 while (lm_pnpbios_hints[idx].idstr[0] != 0) { 89 if (!strcmp(lm_pnpbios_hints[idx].idstr, idstr)) 90 return idx; 91 ++idx; 92 } 93 94 return -1; 95} 96 97int 98lm_pnpbios_match(device_t parent, cfdata_t match, void *aux) 99{ 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; 105 106 int wphi; 107 108 if ((wphi = lm_pnpbios_hints_index(aa->idstr)) == -1) 109 return 0; 110 111 wph = &lm_pnpbios_hints[wphi]; 112 113 if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x, 114 &iot, &ioh)) { 115 return 0; 116 } 117 118 rv = lm_probe(iot, ioh); 119 120 pnpbios_io_unmap(aa->pbt, aa->resc, wph->io_region_idx_lm7x, 121 iot, ioh); 122 123 return rv; 124} 125 126void 127lm_pnpbios_attach(device_t parent, device_t self, void *aux) 128{ 129 struct lm_softc *sc = device_private(self); 130 struct pnpbiosdev_attach_args *aa = aux; 131 struct lm_pnpbios_hint *wph; 132 133 wph = &lm_pnpbios_hints[lm_pnpbios_hints_index(aa->idstr)]; 134 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; 139 } 140 141 aprint_naive("\n"); 142 aprint_normal("\n"); 143 pnpbios_print_devres(self, aa); 144 145 /* Bus-independent attach */ 146 sc->lm_writereg = lm_pnpbios_writereg; 147 sc->lm_readreg = lm_pnpbios_readreg; 148 149 lm_attach(sc); 150} 151 152uint8_t 153lm_pnpbios_readreg(struct lm_softc *sc, int reg) 154{ 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)); 157} 158 159 160void 161lm_pnpbios_writereg(struct lm_softc *sc, int reg, int val) 162{ 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); 165} 166