- Collapse eeprom_ebus.c and eeprom_sbus.c into eeprom.c and

eeprom_ebus_attach() and eeprom_sbus_attach() into eeprom_attach()
  respectively. Since the introduction of the ofw_bus interface some
  time ago and now that ebus(4) also uses SYS_RES_MEMORY for the
  memory resources since ebus.c rev. 1.22 there is no longer a
  need to have separate front-ends for ebus(4), fhc(4) and sbus(4).
- Fail gracefully instead of panicing when the model can't be
  determined.
- Don't leak resources when mk48txx_attach() fails.
- Use FBSDID.
This commit is contained in:
Marius Strobl 2005-05-19 18:15:37 +00:00
parent 437bc968c0
commit a0b2f8d7fc
5 changed files with 65 additions and 328 deletions

View file

@ -81,10 +81,9 @@ sparc64/sparc64/db_hwwatch.c optional ddb
sparc64/sparc64/dump_machdep.c standard
sparc64/sparc64/elf_machdep.c standard
sparc64/sparc64/exception.S standard no-obj
sparc64/sparc64/eeprom.c optional eeprom
sparc64/sparc64/eeprom_ebus.c optional eeprom ebus
sparc64/sparc64/eeprom_sbus.c optional eeprom fhc
sparc64/sparc64/eeprom_sbus.c optional eeprom sbus
sparc64/sparc64/eeprom.c optional eeprom ebus
sparc64/sparc64/eeprom.c optional eeprom fhc
sparc64/sparc64/eeprom.c optional eeprom sbus
sparc64/sparc64/gdb_machdep.c optional gdb
sparc64/sparc64/identcpu.c standard
sparc64/sparc64/in_cksum.c optional inet

View file

@ -1,61 +0,0 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1994 Gordon W. Ross
* Copyright (c) 1993 Adam Glass
* Copyright (c) 1996 Paul Kranenburg
* Copyright (c) 1996
* The President and Fellows of Harvard College. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Harvard University.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Paul Kranenburg.
* This product includes software developed by Harvard University.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)clock.c 8.1 (Berkeley) 6/11/93
* from: NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp
*
* $FreeBSD$
*/
#ifndef _MACHINE_EEPROM_H_
#define _MACHINE_EEPROM_H_
extern devclass_t eeprom_devclass;
int eeprom_probe(device_t);
int eeprom_attach(device_t);
#endif /* _MACHINE_EEPROM_H_ */

View file

@ -46,14 +46,20 @@
*
* from: @(#)clock.c 8.1 (Berkeley) 6/11/93
* from: NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp
*
* $FreeBSD$
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* clock (eeprom) attaches at EBus, FireHose or SBus
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/resource.h>
#include <dev/ofw/ofw_bus.h>
@ -64,17 +70,40 @@
#include <sys/rman.h>
#include <machine/eeprom.h>
#include <dev/mk48txx/mk48txxvar.h>
#include "clock_if.h"
devclass_t eeprom_devclass;
#define IDPROM_OFFSET 40
int
static devclass_t eeprom_devclass;
static device_probe_t eeprom_probe;
static device_attach_t eeprom_attach;
static device_method_t eeprom_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, eeprom_probe),
DEVMETHOD(device_attach, eeprom_attach),
/* clock interface */
DEVMETHOD(clock_gettime, mk48txx_gettime),
DEVMETHOD(clock_settime, mk48txx_settime),
{ 0, 0 }
};
static driver_t eeprom_driver = {
"eeprom",
eeprom_methods,
sizeof(struct mk48txx_softc),
};
DRIVER_MODULE(eeprom, ebus, eeprom_driver, eeprom_devclass, 0, 0);
DRIVER_MODULE(eeprom, fhc, eeprom_driver, eeprom_devclass, 0, 0);
DRIVER_MODULE(eeprom, sbus, eeprom_driver, eeprom_devclass, 0, 0);
static int
eeprom_probe(device_t dev)
{
@ -85,26 +114,40 @@ eeprom_probe(device_t dev)
return (ENXIO);
}
int
static int
eeprom_attach(device_t dev)
{
struct mk48txx_softc *sc;
struct resource *res;
struct timespec ts;
u_int32_t h;
int error, i;
uint32_t h;
int error, i, rid;
sc = device_get_softc(dev);
bzero(sc, sizeof(struct mk48txx_softc));
if ((sc->sc_model = ofw_bus_get_model(dev)) == NULL)
panic("eeprom_attach: no model property");
rid = 0;
res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "cannot allocate resources\n");
return (ENXIO);
}
sc->sc_bst = rman_get_bustag(res);
sc->sc_bsh = rman_get_bushandle(res);
if ((sc->sc_model = ofw_bus_get_model(dev)) == NULL) {
device_printf(dev, "cannot determine model\n");
error = ENXIO;
goto fail_res;
}
/* Our TOD clock year 0 is 1968 */
sc->sc_year0 = 1968;
/* Use default register read/write functions. */
sc->sc_flag = 0;
/* Default register read/write functions are used. */
if ((error = mk48txx_attach(dev)) != 0) {
device_printf(dev, "cannot attach time of day clock\n");
return (error);
goto fail_res;
}
/*
@ -132,4 +175,9 @@ eeprom_attach(device_t dev)
}
return (0);
fail_res:
bus_release_resource(dev, SYS_RES_MEMORY, rid, res);
return (error);
}

View file

@ -1,126 +0,0 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1994 Gordon W. Ross
* Copyright (c) 1993 Adam Glass
* Copyright (c) 1996 Paul Kranenburg
* Copyright (c) 1996
* The President and Fellows of Harvard College. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Harvard University.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Paul Kranenburg.
* This product includes software developed by Harvard University.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)clock.c 8.1 (Berkeley) 6/11/93
* from: NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/resource.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <machine/eeprom.h>
#include <dev/mk48txx/mk48txxvar.h>
#include "clock_if.h"
/*
* clock (eeprom) attaches at the sbus or the ebus
*/
static int eeprom_ebus_attach(device_t);
static device_method_t eeprom_ebus_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, eeprom_probe),
DEVMETHOD(device_attach, eeprom_ebus_attach),
/* clock interface */
DEVMETHOD(clock_gettime, mk48txx_gettime),
DEVMETHOD(clock_settime, mk48txx_settime),
{ 0, 0 }
};
static driver_t eeprom_ebus_driver = {
"eeprom",
eeprom_ebus_methods,
sizeof(struct mk48txx_softc),
};
DRIVER_MODULE(eeprom, ebus, eeprom_ebus_driver, eeprom_devclass, 0, 0);
/*
* Attach a clock (really `eeprom') to the ebus.
*
* This is mapped read-only on NetBSD for safety, but this is not possible
* with the current FreeBSD bus code.
*
* the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is supposed to be
* identical to it.
*/
static int
eeprom_ebus_attach(device_t dev)
{
struct mk48txx_softc *sc;
struct resource *res;
int rid;
sc = device_get_softc(dev);
bzero(sc, sizeof(struct mk48txx_softc));
rid = 0;
res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "could not allocate resources\n");
return (ENXIO);
}
sc->sc_bst = rman_get_bustag(res);
sc->sc_bsh = rman_get_bushandle(res);
return (eeprom_attach(dev));
}

View file

@ -1,123 +0,0 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1994 Gordon W. Ross
* Copyright (c) 1993 Adam Glass
* Copyright (c) 1996 Paul Kranenburg
* Copyright (c) 1996
* The President and Fellows of Harvard College. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Harvard University.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Paul Kranenburg.
* This product includes software developed by Harvard University.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)clock.c 8.1 (Berkeley) 6/11/93
* from: NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/resource.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <machine/eeprom.h>
#include <dev/mk48txx/mk48txxvar.h>
#include "clock_if.h"
static int eeprom_sbus_attach(device_t);
static device_method_t eeprom_sbus_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, eeprom_probe),
DEVMETHOD(device_attach, eeprom_sbus_attach),
/* clock interface */
DEVMETHOD(clock_gettime, mk48txx_gettime),
DEVMETHOD(clock_settime, mk48txx_settime),
{ 0, 0 }
};
static driver_t eeprom_sbus_driver = {
"eeprom",
eeprom_sbus_methods,
sizeof(struct mk48txx_softc),
};
DRIVER_MODULE(eeprom, fhc, eeprom_sbus_driver, eeprom_devclass, 0, 0);
DRIVER_MODULE(eeprom, sbus, eeprom_sbus_driver, eeprom_devclass, 0, 0);
/*
* Attach a clock (really `eeprom') to fhc or sbus.
*
* This is mapped read-only on NetBSD for safety, but this is not possible
* with the current FreeBSD bus code.
*
* the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is supposed to be
* identical to it.
*/
static int
eeprom_sbus_attach(device_t dev)
{
struct mk48txx_softc *sc;
struct resource *res;
int rid;
sc = device_get_softc(dev);
bzero(sc, sizeof(struct mk48txx_softc));
rid = 0;
res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "could not allocate resources\n");
return (ENXIO);
}
sc->sc_bst = rman_get_bustag(res);
sc->sc_bsh = rman_get_bushandle(res);
return (eeprom_attach(dev));
}