Modularize lm_isa and lm_wbsio, splitting the common part out

into a 3rd module.  Add wbsio module too.
This commit is contained in:
jakllsch 2012-01-17 16:50:07 +00:00
parent 70c82e3eee
commit 4dd99ce884
12 changed files with 418 additions and 111 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lm_isa.c,v 1.23 2010/02/21 05:16:29 cnst Exp $ */
/* $NetBSD: lm_isa.c,v 1.24 2012/01/17 16:50:07 jakllsch Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -30,12 +30,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.23 2010/02/21 05:16:29 cnst Exp $");
__KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.24 2012/01/17 16:50:07 jakllsch Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/bus.h>
@ -43,121 +44,36 @@ __KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.23 2010/02/21 05:16:29 cnst Exp $");
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/ic/nslm7xvar.h>
int lm_isa_match(device_t, cfdata_t, void *);
void lm_isa_attach(device_t, device_t, void *);
int lm_isa_detach(device_t, int);
uint8_t lm_isa_readreg(struct lm_softc *, int);
void lm_isa_writereg(struct lm_softc *, int, int);
struct lm_isa_softc {
struct lm_softc lmsc;
bus_space_tag_t lm_iot;
bus_space_handle_t lm_ioh;
};
#include <dev/isa/lm_isa_common_var.h>
CFATTACH_DECL_NEW(lm_isa, sizeof(struct lm_isa_softc),
lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
CFATTACH_DECL_NEW(lm_wbsio, sizeof(struct lm_isa_softc),
lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
MODULE(MODULE_CLASS_DRIVER, lm_isa, "lm_isa_common");
int
lm_isa_match(device_t parent, cfdata_t match, void *aux)
#ifdef _MODULE
#include "ioconf.c"
#endif
static int
lm_isa_modcmd(modcmd_t cmd, void *priv)
{
bus_space_handle_t ioh;
struct isa_attach_args *ia = aux;
struct lm_isa_softc sc;
int rv;
int error = 0;
/* Must supply an address */
if (ia->ia_nio < 1)
return 0;
if (ISA_DIRECT_CONFIG(ia))
return 0;
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
return 0;
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
return 0;
/* Bus independent probe */
sc.lm_iot = ia->ia_iot;
sc.lm_ioh = ioh;
sc.lmsc.lm_writereg = lm_isa_writereg;
sc.lmsc.lm_readreg = lm_isa_readreg;
rv = lm_probe(&sc.lmsc);
bus_space_unmap(ia->ia_iot, ioh, 8);
if (rv) {
ia->ia_nio = 1;
ia->ia_io[0].ir_size = 8;
ia->ia_niomem = 0;
ia->ia_nirq = 0;
ia->ia_ndrq = 0;
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
error = config_init_component(cfdriver_ioconf_lm_isa,
cfattach_ioconf_lm_isa, cfdata_ioconf_lm_isa);
#endif
return error;
case MODULE_CMD_FINI:
#ifdef _MODULE
error = config_fini_component(cfdriver_ioconf_lm_isa,
cfattach_ioconf_lm_isa, cfdata_ioconf_lm_isa);
#endif
return error;
default:
return ENOTTY;
}
return rv;
}
void
lm_isa_attach(device_t parent, device_t self, void *aux)
{
struct lm_isa_softc *sc = device_private(self);
struct isa_attach_args *ia = aux;
sc->lm_iot = ia->ia_iot;
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
&sc->lm_ioh)) {
aprint_error(": can't map i/o space\n");
return;
}
/* Bus-independent attachment */
sc->lmsc.sc_dev = self;
sc->lmsc.lm_writereg = lm_isa_writereg;
sc->lmsc.lm_readreg = lm_isa_readreg;
lm_attach(&sc->lmsc);
}
int
lm_isa_detach(device_t self, int flags)
{
struct lm_isa_softc *sc = device_private(self);
lm_detach(&sc->lmsc);
bus_space_unmap(sc->lm_iot, sc->lm_ioh, 8);
return 0;
}
uint8_t
lm_isa_readreg(struct lm_softc *lmsc, int reg)
{
struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
}
void
lm_isa_writereg(struct lm_softc *lmsc, int reg, int val)
{
struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
}

172
sys/dev/isa/lm_isa_common.c Normal file
View File

@ -0,0 +1,172 @@
/* $NetBSD: lm_isa_common.c,v 1.1 2012/01/17 16:50:07 jakllsch Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Squier.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.1 2012/01/17 16:50:07 jakllsch Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/bus.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/ic/nslm7xvar.h>
int lm_isa_match(device_t, cfdata_t, void *);
void lm_isa_attach(device_t, device_t, void *);
int lm_isa_detach(device_t, int);
static uint8_t lm_isa_readreg(struct lm_softc *, int);
static void lm_isa_writereg(struct lm_softc *, int, int);
struct lm_isa_softc {
struct lm_softc lmsc;
bus_space_tag_t lm_iot;
bus_space_handle_t lm_ioh;
};
#if 0
CFATTACH_DECL_NEW(lm_isa, sizeof(struct lm_isa_softc),
lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
CFATTACH_DECL_NEW(lm_wbsio, sizeof(struct lm_isa_softc),
lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
#endif
int
lm_isa_match(device_t parent, cfdata_t match, void *aux)
{
bus_space_handle_t ioh;
struct isa_attach_args *ia = aux;
struct lm_isa_softc sc;
int rv;
/* Must supply an address */
if (ia->ia_nio < 1)
return 0;
if (ISA_DIRECT_CONFIG(ia))
return 0;
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
return 0;
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
return 0;
/* Bus independent probe */
sc.lm_iot = ia->ia_iot;
sc.lm_ioh = ioh;
sc.lmsc.lm_writereg = lm_isa_writereg;
sc.lmsc.lm_readreg = lm_isa_readreg;
rv = lm_probe(&sc.lmsc);
bus_space_unmap(ia->ia_iot, ioh, 8);
if (rv) {
ia->ia_nio = 1;
ia->ia_io[0].ir_size = 8;
ia->ia_niomem = 0;
ia->ia_nirq = 0;
ia->ia_ndrq = 0;
}
return rv;
}
void
lm_isa_attach(device_t parent, device_t self, void *aux)
{
struct lm_isa_softc *sc = device_private(self);
struct isa_attach_args *ia = aux;
sc->lm_iot = ia->ia_iot;
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
&sc->lm_ioh)) {
aprint_error(": can't map i/o space\n");
return;
}
/* Bus-independent attachment */
sc->lmsc.sc_dev = self;
sc->lmsc.lm_writereg = lm_isa_writereg;
sc->lmsc.lm_readreg = lm_isa_readreg;
lm_attach(&sc->lmsc);
}
int
lm_isa_detach(device_t self, int flags)
{
struct lm_isa_softc *sc = device_private(self);
lm_detach(&sc->lmsc);
bus_space_unmap(sc->lm_iot, sc->lm_ioh, 8);
return 0;
}
static uint8_t
lm_isa_readreg(struct lm_softc *lmsc, int reg)
{
struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
}
static void
lm_isa_writereg(struct lm_softc *lmsc, int reg, int val)
{
struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
}
MODULE(MODULE_CLASS_DRIVER, lm_isa_common, "");
static int
lm_isa_common_modcmd(modcmd_t cmd, void *priv)
{
if ((cmd == MODULE_CMD_INIT) || (cmd == MODULE_CMD_FINI))
return 0;
return ENOTTY;
}

View File

@ -0,0 +1,46 @@
/* $NetBSD: lm_isa_common_var.h,v 1.1 2012/01/17 16:50:07 jakllsch Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Squier.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LM_ISA_COMMON_VAR_H_
#define _LM_ISA_COMMON_VAR_H_
#include <dev/ic/nslm7xvar.h>
int lm_isa_match(device_t, cfdata_t, void *);
void lm_isa_attach(device_t, device_t, void *);
int lm_isa_detach(device_t, int);
struct lm_isa_softc {
struct lm_softc lmsc;
bus_space_tag_t lm_iot;
bus_space_handle_t lm_ioh;
};
#endif /* _LM_ISA_COMMON_VAR_H_ */

79
sys/dev/isa/lm_wbsio.c Normal file
View File

@ -0,0 +1,79 @@
/* $NetBSD: lm_wbsio.c,v 1.1 2012/01/17 16:50:07 jakllsch Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Squier.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lm_wbsio.c,v 1.1 2012/01/17 16:50:07 jakllsch Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/bus.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/isa/lm_isa_common_var.h>
CFATTACH_DECL_NEW(lm_wbsio, sizeof(struct lm_isa_softc),
lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
MODULE(MODULE_CLASS_DRIVER, lm_wbsio, "lm_isa_common");
#ifdef _MODULE
#include "ioconf.c"
#endif
static int
lm_wbsio_modcmd(modcmd_t cmd, void *priv)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
error = config_init_component(cfdriver_ioconf_lm_wbsio,
cfattach_ioconf_lm_wbsio, cfdata_ioconf_lm_wbsio);
#endif
return error;
case MODULE_CMD_FINI:
#ifdef _MODULE
error = config_fini_component(cfdriver_ioconf_lm_wbsio,
cfattach_ioconf_lm_wbsio, cfdata_ioconf_lm_wbsio);
#endif
return error;
default:
return ENOTTY;
}
}

12
sys/modules/lm/Makefile Normal file
View File

@ -0,0 +1,12 @@
# $NetBSD: Makefile,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev/ic
KMOD= lm
SRCS= nslm7x.c
WARNS?= 4
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev/isa
KMOD= lm_isa
IOCONF= lm_isa.ioconf
SRCS= lm_isa.c
WARNS?= 4
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,10 @@
# $NetBSD: lm_isa.ioconf,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
ioconf lm_isa
include "conf/files"
include "dev/isa/files.isa"
pseudo-root isa*
lm* at isa? port 0x290

View File

@ -0,0 +1,12 @@
# $NetBSD: Makefile,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev/isa
KMOD= lm_isa_common
SRCS= lm_isa_common.c
WARNS?= 4
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev/isa
KMOD= lm_wbsio
IOCONF= lm_wbsio.ioconf
SRCS= lm_wbsio.c
WARNS?= 4
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,10 @@
# $NetBSD: lm_wbsio.ioconf,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
ioconf lm_wbsio
include "conf/files"
include "dev/isa/files.isa"
pseudo-root wbsio*
lm* at wbsio?

View File

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
.include "../Makefile.inc"
.PATH: ${S}/dev/isa
KMOD= wbsio
IOCONF= wbsio.ioconf
SRCS= wbsio.c
WARNS?= 4
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,11 @@
# $NetBSD: wbsio.ioconf,v 1.1 2012/01/17 16:50:07 jakllsch Exp $
ioconf wbsio
include "conf/files"
include "dev/isa/files.isa"
pseudo-root isa*
wbsio* at isa? port 0x2e
wbsio* at isa? port 0x4e