From 2686579ad5a500820a0201b64388f2961bb1f9fc Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 17 Nov 2004 12:54:12 +0000 Subject: o Sync with the NetBSD mk48txx driver (the result simplyfies some changes I have in mind for the genclock interface): - Recognize the MK48T18 as well (differs from the MK48T08 only in packaging options and voltages). - Allow MD code to provide functions for reading/writing NVRAM/RTC locations. If passed NULL, the old behaviour using bus_space_{read,write}_1() is used. Otherwise, all access to the chip goes via the MD functions. This is necessary for mvmeppc boards where the mk48txx NVRAM/RTC is not directly addressable. - Cleanup MI mk48txx(4) todclock driver: - Prepare mk48txxvar.h and leave only register definitions in mk48txxreg.h. - Define struct mk48txx_softc as usual devices and allocate necessary members in it. - Change mk48txx_attach() to only take a device_t. o While converting the sparc64 eeprom driver to the above changes: - Remove some dead code and stale comments. - Use the NVRAM size provided by the mk48txx driver instead of hardcoding it as suggested by a comment. - Add a comment about why it doesn't make much sense to read the hostid directly from the NVRAM except for displaying it when attaching. - Don't print the hostid if it reads all zero because it's stored elsewhere. --- sys/sparc64/include/eeprom.h | 6 +---- sys/sparc64/sparc64/eeprom.c | 48 +++++++++++++++++++++++---------------- sys/sparc64/sparc64/eeprom_ebus.c | 21 +++++++++-------- sys/sparc64/sparc64/eeprom_sbus.c | 21 +++++++++-------- 4 files changed, 52 insertions(+), 44 deletions(-) (limited to 'sys/sparc64') diff --git a/sys/sparc64/include/eeprom.h b/sys/sparc64/include/eeprom.h index 57a7ff5..21bd3d3 100644 --- a/sys/sparc64/include/eeprom.h +++ b/sys/sparc64/include/eeprom.h @@ -53,13 +53,9 @@ #ifndef _MACHINE_EEPROM_H_ #define _MACHINE_EEPROM_H_ -struct eeprom_softc { - struct mk48txx_softc *sc_mksoftc; -}; - extern devclass_t eeprom_devclass; int eeprom_probe(device_t); -int eeprom_attach(device_t, bus_space_tag_t, bus_space_handle_t); +int eeprom_attach(device_t); #endif /* _MACHINE_EEPROM_H_ */ diff --git a/sys/sparc64/sparc64/eeprom.c b/sys/sparc64/sparc64/eeprom.c index 5f67a31..8a81101 100644 --- a/sys/sparc64/sparc64/eeprom.c +++ b/sys/sparc64/sparc64/eeprom.c @@ -54,7 +54,6 @@ #include #include #include -#include #include #include @@ -67,13 +66,13 @@ #include -#include +#include #include "clock_if.h" devclass_t eeprom_devclass; -#define IDPROM_OFFSET (8 * 1024 - 40) /* XXX - get nvram size from driver */ +#define IDPROM_OFFSET 40 int eeprom_probe(device_t dev) @@ -87,34 +86,45 @@ eeprom_probe(device_t dev) } int -eeprom_attach(device_t dev, bus_space_tag_t bt, bus_space_handle_t bh) +eeprom_attach(device_t dev) { + struct mk48txx_softc *sc; struct timespec ts; - struct idprom *idp; - const char *model; - int error, i; u_int32_t h; + int error, i; - if ((model = ofw_bus_get_model(dev)) == NULL) + sc = device_get_softc(dev); + + if ((sc->sc_model = ofw_bus_get_model(dev)) == NULL) panic("eeprom_attach: no model property"); /* Our TOD clock year 0 is 1968 */ - if ((error = mk48txx_attach(dev, bt, bh, model, 1968)) != 0) { - device_printf(dev, "Can't attach %s tod clock", model); + sc->sc_year0 = 1968; + 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); } - /* XXX: register clock device */ - /* Get the host ID from the prom. */ - idp = (struct idprom *)((u_long)bh + IDPROM_OFFSET); - h = bus_space_read_1(bt, bh, IDPROM_OFFSET + - offsetof(struct idprom, id_machine)) << 24; + /* + * Get the hostid from the NVRAM. This serves no real purpose other + * than being able to display it below as not all sparc64 models + * have an `eeprom' device and even some that do store the hostid + * elsewhere. The hostid in the NVRAM of the MK48Txx reads all zero + * on the latter models. A generic way to retrieve the hostid is to + * use the `idprom' node. + */ + h = bus_space_read_1(sc->sc_bst, sc->sc_bsh, sc->sc_nvramsz - + IDPROM_OFFSET + offsetof(struct idprom, id_machine)) << 24; for (i = 0; i < 3; i++) { - h |= bus_space_read_1(bt, bh, IDPROM_OFFSET + - offsetof(struct idprom, id_hostid[i])) << ((2 - i) * 8); + h |= bus_space_read_1(sc->sc_bst, sc->sc_bsh, sc->sc_nvramsz - + IDPROM_OFFSET + offsetof(struct idprom, id_hostid[i])) << + ((2 - i) * 8); } - /* XXX: register host id */ - device_printf(dev, "hostid %x\n", (u_int)h); + if (h != 0) + device_printf(dev, "hostid %x\n", (u_int)h); + if (bootverbose) { mk48txx_gettime(dev, &ts); device_printf(dev, "current time: %ld.%09ld\n", (long)ts.tv_sec, diff --git a/sys/sparc64/sparc64/eeprom_ebus.c b/sys/sparc64/sparc64/eeprom_ebus.c index 645602b..a614ec4 100644 --- a/sys/sparc64/sparc64/eeprom_ebus.c +++ b/sys/sparc64/sparc64/eeprom_ebus.c @@ -54,21 +54,17 @@ #include #include #include -#include #include #include -#include - #include -#include #include #include #include -#include +#include #include "clock_if.h" @@ -93,7 +89,7 @@ static device_method_t eeprom_ebus_methods[] = { static driver_t eeprom_ebus_driver = { "eeprom", eeprom_ebus_methods, - 0, + sizeof(struct mk48txx_softc), }; DRIVER_MODULE(eeprom, ebus, eeprom_ebus_driver, eeprom_devclass, 0, 0); @@ -110,8 +106,12 @@ DRIVER_MODULE(eeprom, ebus, eeprom_ebus_driver, eeprom_devclass, 0, 0); static int eeprom_ebus_attach(device_t dev) { + struct mk48txx_softc *sc; struct resource *res; - int rid, error; + 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); @@ -119,7 +119,8 @@ eeprom_ebus_attach(device_t dev) device_printf(dev, "could not allocate resources\n"); return (ENXIO); } - error = eeprom_attach(dev, rman_get_bustag(res), - rman_get_bushandle(res)); - return (error); + sc->sc_bst = rman_get_bustag(res); + sc->sc_bsh = rman_get_bushandle(res); + + return (eeprom_attach(dev)); } diff --git a/sys/sparc64/sparc64/eeprom_sbus.c b/sys/sparc64/sparc64/eeprom_sbus.c index 9273193..7732573 100644 --- a/sys/sparc64/sparc64/eeprom_sbus.c +++ b/sys/sparc64/sparc64/eeprom_sbus.c @@ -54,21 +54,17 @@ #include #include #include -#include #include #include -#include - #include -#include #include #include #include -#include +#include #include "clock_if.h" @@ -89,7 +85,7 @@ static device_method_t eeprom_sbus_methods[] = { static driver_t eeprom_sbus_driver = { "eeprom", eeprom_sbus_methods, - 0, + sizeof(struct mk48txx_softc), }; DRIVER_MODULE(eeprom, fhc, eeprom_sbus_driver, eeprom_devclass, 0, 0); @@ -107,8 +103,12 @@ DRIVER_MODULE(eeprom, sbus, eeprom_sbus_driver, eeprom_devclass, 0, 0); static int eeprom_sbus_attach(device_t dev) { + struct mk48txx_softc *sc; struct resource *res; - int rid, error; + 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); @@ -116,7 +116,8 @@ eeprom_sbus_attach(device_t dev) device_printf(dev, "could not allocate resources\n"); return (ENXIO); } - error = eeprom_attach(dev, rman_get_bustag(res), - rman_get_bushandle(res)); - return (error); + sc->sc_bst = rman_get_bustag(res); + sc->sc_bsh = rman_get_bushandle(res); + + return (eeprom_attach(dev)); } -- cgit v1.1