Index: head/sys/sparc64/fhc/clkbrd.c =================================================================== --- head/sys/sparc64/fhc/clkbrd.c (revision 152960) +++ head/sys/sparc64/fhc/clkbrd.c (revision 152961) @@ -1,212 +1,211 @@ /*- * Copyright (c) 2004 Jason L. Wright (jason@thought.net) * Copyright (c) 2005 Marius Strobl * All rights reserved. * * 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 AUTHOR ``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 AUTHOR 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: OpenBSD: clkbrd.c,v 1.5 2004/10/01 18:18:49 jason Exp */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #define CLKBRD_NREG 3 #define CLKBRD_CF 0 #define CLKBRD_CLK 1 #define CLKBRD_CLKVER 2 struct clkbrd_softc { struct device *sc_dev; struct resource *sc_res[CLKBRD_NREG]; int sc_rid[CLKBRD_NREG]; bus_space_tag_t sc_bt[CLKBRD_NREG]; bus_space_handle_t sc_bh[CLKBRD_NREG]; uint8_t sc_clk_ctrl; struct cdev *sc_led_dev; int sc_flags; #define CLKBRD_HAS_CLKVER (1 << 0) }; static devclass_t clkbrd_devclass; static device_probe_t clkbrd_probe; static device_attach_t clkbrd_attach; static device_detach_t clkbrd_detach; static void clkbrd_free_resources(struct clkbrd_softc *); static void clkbrd_led_func(void *, int); static device_method_t clkbrd_methods[] = { /* Device interface */ DEVMETHOD(device_probe, clkbrd_probe), DEVMETHOD(device_attach, clkbrd_attach), DEVMETHOD(device_detach, clkbrd_detach), { 0, 0 } }; static driver_t clkbrd_driver = { "clkbrd", clkbrd_methods, sizeof(struct clkbrd_softc), }; DRIVER_MODULE(clkbrd, fhc, clkbrd_driver, clkbrd_devclass, 0, 0); static int clkbrd_probe(device_t dev) { if (strcmp(ofw_bus_get_name(dev), "clock-board") == 0) { device_set_desc(dev, "Clock Board"); return (0); } return (ENXIO); } static int clkbrd_attach(device_t dev) { struct clkbrd_softc *sc; int i, slots; uint8_t r; sc = device_get_softc(dev); - bzero(sc, sizeof(struct clkbrd_softc)); sc->sc_dev = dev; for (i = CLKBRD_CF; i <= CLKBRD_CLKVER; i++) { sc->sc_rid[i] = i; sc->sc_res[i] = bus_alloc_resource_any(sc->sc_dev, SYS_RES_MEMORY, &sc->sc_rid[i], RF_ACTIVE); if (sc->sc_res[i] == NULL) { if (i != CLKBRD_CLKVER) { device_printf(sc->sc_dev, "could not allocate resource %d\n", i); goto fail; } continue; } sc->sc_bt[i] = rman_get_bustag(sc->sc_res[i]); sc->sc_bh[i] = rman_get_bushandle(sc->sc_res[i]); if (i == CLKBRD_CLKVER) sc->sc_flags |= CLKBRD_HAS_CLKVER; } slots = 4; r = bus_space_read_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_STS1); switch (r & 0xc0) { case 0x40: slots = 16; break; case 0xc0: slots = 8; break; case 0x80: if (sc->sc_flags & CLKBRD_HAS_CLKVER) { r = bus_space_read_1(sc->sc_bt[CLKBRD_CLKVER], sc->sc_bh[CLKBRD_CLKVER], 0); if (r != 0 && (r & 0x80) == 0) slots = 5; } } device_printf(sc->sc_dev, "Sun Enterprise Exx00 machine: %d slots\n", slots); sc->sc_clk_ctrl = bus_space_read_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_CTRL); sc->sc_led_dev = led_create(clkbrd_led_func, sc, "clockboard"); return (0); fail: clkbrd_free_resources(sc); return (ENXIO); } static int clkbrd_detach(device_t dev) { struct clkbrd_softc *sc; sc = device_get_softc(dev); led_destroy(sc->sc_led_dev); bus_space_write_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_CTRL, sc->sc_clk_ctrl); bus_space_read_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_CTRL); clkbrd_free_resources(sc); return (0); } static void clkbrd_free_resources(struct clkbrd_softc *sc) { int i; for (i = CLKBRD_CF; i <= CLKBRD_CLKVER; i++) if (sc->sc_res[i] != NULL) bus_release_resource(sc->sc_dev, SYS_RES_MEMORY, sc->sc_rid[i], sc->sc_res[i]); } static void clkbrd_led_func(void *arg, int onoff) { struct clkbrd_softc *sc; uint8_t r; sc = (struct clkbrd_softc *)arg; r = bus_space_read_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_CTRL); if (onoff) r |= CLK_CTRL_RLED; else r &= ~CLK_CTRL_RLED; bus_space_write_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_CTRL, r); bus_space_read_1(sc->sc_bt[CLKBRD_CLK], sc->sc_bh[CLKBRD_CLK], CLK_CTRL); } Index: head/sys/sparc64/sparc64/eeprom.c =================================================================== --- head/sys/sparc64/sparc64/eeprom.c (revision 152960) +++ head/sys/sparc64/sparc64/eeprom.c (revision 152961) @@ -1,193 +1,192 @@ /*- * 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 */ #include __FBSDID("$FreeBSD$"); /* * clock (eeprom) attaches at EBus, FireHose or SBus */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "clock_if.h" #define IDPROM_OFFSET 40 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) { if (strcmp("eeprom", ofw_bus_get_name(dev)) == 0) { device_set_desc(dev, "EEPROM/clock"); return (0); } return (ENXIO); } static int eeprom_attach(device_t dev) { struct mk48txx_softc *sc; struct resource *res; struct timespec ts; uint32_t h; int error, i, rid; sc = device_get_softc(dev); - bzero(sc, sizeof(struct mk48txx_softc)); mtx_init(&sc->sc_mtx, "eeprom_mtx", NULL, MTX_DEF); rid = 0; res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (res == NULL) { device_printf(dev, "cannot allocate resources\n"); error = ENXIO; goto fail_mtx; } 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; if ((error = mk48txx_attach(dev)) != 0) { device_printf(dev, "cannot attach time of day clock\n"); goto fail_res; } /* * 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. */ mtx_lock(&sc->sc_mtx); 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(sc->sc_bst, sc->sc_bsh, sc->sc_nvramsz - IDPROM_OFFSET + offsetof(struct idprom, id_hostid[i])) << ((2 - i) * 8); } mtx_unlock(&sc->sc_mtx); 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, ts.tv_nsec); } return (0); fail_res: bus_release_resource(dev, SYS_RES_MEMORY, rid, res); fail_mtx: mtx_destroy(&sc->sc_mtx); return (error); } Index: head/sys/sparc64/sparc64/rtc.c =================================================================== --- head/sys/sparc64/sparc64/rtc.c (revision 152960) +++ head/sys/sparc64/sparc64/rtc.c (revision 152961) @@ -1,192 +1,191 @@ /*- * Copyright (c) 2004 Marius Strobl * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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 __FBSDID("$FreeBSD$"); /* * The `rtc' device is a MC146818 compatible clock found on the ISA bus * and EBus. The EBus version also has an interrupt property so it could * be used to drive the statclock etc. */ #include "opt_isa.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "clock_if.h" static devclass_t rtc_devclass; static int rtc_attach(device_t dev); static int rtc_ebus_probe(device_t dev); #ifdef DEV_ISA static int rtc_isa_probe(device_t dev); #endif static device_method_t rtc_ebus_methods[] = { /* Device interface */ DEVMETHOD(device_probe, rtc_ebus_probe), DEVMETHOD(device_attach, rtc_attach), /* clock interface */ DEVMETHOD(clock_gettime, mc146818_gettime), DEVMETHOD(clock_settime, mc146818_settime), { 0, 0 } }; static driver_t rtc_ebus_driver = { "rtc", rtc_ebus_methods, sizeof(struct mc146818_softc), }; DRIVER_MODULE(rtc, ebus, rtc_ebus_driver, rtc_devclass, 0, 0); #ifdef DEV_ISA static device_method_t rtc_isa_methods[] = { /* Device interface */ DEVMETHOD(device_probe, rtc_isa_probe), DEVMETHOD(device_attach, rtc_attach), /* clock interface */ DEVMETHOD(clock_gettime, mc146818_gettime), DEVMETHOD(clock_settime, mc146818_settime), { 0, 0 } }; static driver_t rtc_isa_driver = { "rtc", rtc_isa_methods, sizeof(struct mc146818_softc), }; DRIVER_MODULE(rtc, isa, rtc_isa_driver, rtc_devclass, 0, 0); #endif static int rtc_ebus_probe(device_t dev) { if (strcmp(ofw_bus_get_name(dev), "rtc") == 0) { device_set_desc(dev, "Real Time Clock"); return (0); } return (ENXIO); } #ifdef DEV_ISA static struct isa_pnp_id rtc_isa_ids[] = { { 0x000bd041, "AT realtime clock" }, /* PNP0B00 */ { 0 } }; static int rtc_isa_probe(device_t dev) { if (ISA_PNP_PROBE(device_get_parent(dev), dev, rtc_isa_ids) == 0) { device_set_desc(dev, "Real Time Clock"); return (0); } return (ENXIO); } #endif static int rtc_attach(device_t dev) { struct timespec ts; struct mc146818_softc *sc; struct resource *res; int error, rid, rtype; sc = device_get_softc(dev); - bzero(sc, sizeof(struct mc146818_softc)); mtx_init(&sc->sc_mtx, "rtc_mtx", NULL, MTX_SPIN); if (strcmp(device_get_name(device_get_parent(dev)), "isa") == 0) rtype = SYS_RES_IOPORT; else rtype = SYS_RES_MEMORY; rid = 0; res = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE); if (res == NULL) { device_printf(dev, "cannot allocate resources\n"); error = ENXIO; goto fail_mtx; } sc->sc_bst = rman_get_bustag(res); sc->sc_bsh = rman_get_bushandle(res); /* The TOD clock year 0 is 0. */ sc->sc_year0 = 0; /* Use default register read/write and century get/set functions. */ sc->sc_flag = MC146818_NO_CENT_ADJUST; if ((error = mc146818_attach(dev)) != 0) { device_printf(dev, "cannot attach time of day clock\n"); goto fail_res; } if (bootverbose) { mc146818_gettime(dev, &ts); device_printf(dev, "current time: %ld.%09ld\n", (long)ts.tv_sec, ts.tv_nsec); } return (0); fail_res: bus_release_resource(dev, rtype, rid, res); fail_mtx: mtx_destroy(&sc->sc_mtx); return (error); }