--- /dev/null 2003-11-03 00:07:10.000000000 +0900 +++ dev/mcclock_ebus.c 2003-11-02 23:28:57.000000000 +0900 @@ -0,0 +1,223 @@ +/* $NetBSD$ */ + +/* + * 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. + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * 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 the University of + * California, Berkeley and its contributors. + * 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. + * + * @(#)clock.c 8.1 (Berkeley) 6/11/93 + * + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +#include "opt_multiprocessor.h" + +/* + * ebus attachment of M5819 time-of-day clock found Netra X1 and Fire V100. + */ + + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +static int mcclock_ebus_match __P((struct device *, struct cfdata *, void *)); +static void mcclock_ebus_attach __P((struct device *, struct device *, void *)); + +CFATTACH_DECL(mcclock_ebus, sizeof(struct mc146818_softc), + mcclock_ebus_match, mcclock_ebus_attach, NULL, NULL); + +extern struct cfdriver mcclock_cd; + +static u_int mcclock_ebus_read(struct mc146818_softc *, u_int); +static void mcclock_ebus_write(struct mc146818_softc *, u_int, u_int); +static u_int mcclock_ebus_getcent(struct mc146818_softc *); +static void mcclock_ebus_setcent(struct mc146818_softc *, u_int); + +/* + * `rtc' is a ds1287 on an ebus (actually an isa bus, but we use the + * ebus driver for isa.) So we can use ebus_wenable() but need to do + * different attach work and use different todr routines. It does not + * incorporate an IDPROM. + */ + +static int +mcclock_ebus_match(parent, cf, aux) + struct device *parent; + struct cfdata *cf; + void *aux; +{ + struct ebus_attach_args *ea = aux; + + return (strcmp("rtc", ea->ea_name) == 0); +} + +/* ARGSUSED */ +static void +mcclock_ebus_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct mc146818_softc *sc = (void *)self; + struct ebus_attach_args *ea = aux; + char *model; + int sz; + + sc->sc_bst = ea->ea_bustag; + + /* hard code to 8K? */ + sz = ea->ea_reg[0].size; + + if (bus_space_map(sc->sc_bst, + EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), + sz, + BUS_SPACE_MAP_LINEAR, + &sc->sc_bsh) != 0) { + printf("%s: can't map register\n", self->dv_xname); + return; + } + + model = PROM_getpropstring(ea->ea_node, "model"); +#ifdef DIAGNOSTIC + if (model == NULL) + panic("mcclock_ebus_attach: no model property"); +#endif + + /* Our TOD clock year 0 is 0 */ + sc->sc_year0 = 0; + sc->sc_flag = MC146818_NO_CENT_ADJUST; + sc->sc_mcread = mcclock_ebus_read; + sc->sc_mcwrite = mcclock_ebus_write; + sc->sc_getcent = mcclock_ebus_getcent; + sc->sc_setcent = mcclock_ebus_setcent; + mc146818_attach(sc); + + printf(": %s\n", model); + + /* + * Turn interrupts off, just in case. (Although they shouldn't + * be wired to an interrupt controller on sparcs). + */ + mcclock_ebus_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); + + /* + * Apparently on some machines the TOD registers are on the same + * physical page as the COM registers. So we won't protect them. + */ + /*sc->sc_handle.todr_setwen = NULL;*/ + + todr_attach(&sc->sc_handle); +} + +/* + * MD mc146818 RTC todr routines. + */ + +/* + * XXX the stupid ds1287 is not mapped directly but uses an address + * and a data reg so we cannot access the stuuupid thing w/o having + * write access to the registers. + * + * XXXX We really need to mutex register access! + */ +#define RTC_ADDR 0 +#define RTC_DATA 1 + +static u_int +mcclock_ebus_read(struct mc146818_softc *sc, u_int reg) +{ + + bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg); + return bus_space_read_1(sc->sc_bst, sc->sc_bsh, RTC_DATA); +} + +static void +mcclock_ebus_write(struct mc146818_softc *sc, u_int reg, u_int val) +{ + + bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg); + bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_DATA, val); +} + + +/* Loooks like Sun stores the century info somewhere in CMOS RAM */ +#define MC_CENT 0x32 + +static u_int +mcclock_ebus_getcent(sc) + struct mc146818_softc *sc; +{ + + return mcclock_ebus_read(sc, MC_CENT); +} + +static void +mcclock_ebus_setcent(sc, cent) + struct mc146818_softc *sc; + u_int cent; +{ + + mcclock_ebus_write(sc, MC_CENT, cent); +} --- /dev/null 2003-11-03 00:07:10.000000000 +0900 +++ dev/mkclock.c 2003-11-02 23:47:44.000000000 +0900 @@ -0,0 +1,178 @@ +/* $NetBSD$ */ + +/* + * 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. + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * 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 the University of + * California, Berkeley and its contributors. + * 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. + * + * @(#)clock.c 8.1 (Berkeley) 6/11/93 + * + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +/* + * common part of sbus and ebus attachments for mk48txx(4). + */ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +int clock_wenable __P((struct todr_chip_handle *, int)); + +/* + * Attach a clock (really `eeprom') to the sbus or ebus. + * + * We ignore any existing virtual address as we need to map + * this read-only and make it read-write only temporarily, + * whenever we read or write the clock chip. The clock also + * contains the ID ``PROM'', and I have already had the pleasure + * of reloading the cpu type, Ethernet address, etc, by hand from + * the console FORTH interpreter. I intend not to enjoy it again. + * + * the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is + * supposed to be identical to it. + * + * This is *UGLY*! We probably have multiple mappings. But I do + * know that this all fits inside an 8K page, so I'll just map in + * once. + * + * What we really need is some way to record the bus attach args + * so we can call *_bus_map() later with BUS_SPACE_MAP_READONLY + * or not to write enable/disable the device registers. This is + * a non-trivial operation. + */ + +/* + * Write en/dis-able clock registers. We coordinate so that several + * writers can run simultaneously. + */ +int +clock_wenable(handle, onoff) + struct todr_chip_handle *handle; + int onoff; +{ + struct mk48txx_softc *sc; + vm_prot_t prot; + vaddr_t va; + int s, err = 0; + static int writers; + + s = splhigh(); + if (onoff) + prot = writers++ == 0 ? VM_PROT_READ|VM_PROT_WRITE : 0; + else + prot = --writers == 0 ? VM_PROT_READ : 0; + splx(s); + if (prot == VM_PROT_NONE) { + return 0; + } + sc = handle->cookie; + va = (vaddr_t)bus_space_vaddr(sc->sc_bst, sc->sc_bsh); + if (va == 0UL) { + printf("clock_wenable: WARNING -- cannot get va\n"); + return EIO; + } + pmap_kprotect(va, prot); + return (err); +} + +void +mkclock_common_attach(sc, node) + struct mk48txx_softc *sc; + int node; +{ + struct idprom *idp; + int h; + + sc->sc_model = PROM_getpropstring(node, "model"); + +#ifdef DIAGNOSTIC + if (sc->sc_model == NULL) + panic("clockattach: no model property"); +#endif + + /* Our TOD clock year 0 is 1968 */ + sc->sc_year0 = 1968; + mk48txx_attach(sc); + +#define IDPROM_OFFSET (8*1024 - 40) /* XXX - get nvram sz from driver */ + idp = (struct idprom *)((vaddr_t)bus_space_vaddr(sc->sc_bst, + sc->sc_bsh) + IDPROM_OFFSET); + + h = idp->id_machine << 24; + h |= idp->id_hostid[0] << 16; + h |= idp->id_hostid[1] << 8; + h |= idp->id_hostid[2]; + hostid = h; + printf(": hostid %x\n", (u_int)hostid); + + idprom = idp; + + /* Save info for the clock wenable call. */ + sc->sc_handle.todr_setwen = clock_wenable; + + todr_attach(&sc->sc_handle); +} --- /dev/null 2003-11-03 00:07:10.000000000 +0900 +++ dev/mkclockvar.h 2003-11-02 22:53:55.000000000 +0900 @@ -0,0 +1,28 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2003 Izumi Tsutsui. 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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. + */ +void mkclock_common_attach(struct mk48txx_softc *, int); --- /dev/null 2003-11-03 00:07:10.000000000 +0900 +++ dev/mkclock_ebus.c 2003-11-02 22:48:55.000000000 +0900 @@ -0,0 +1,154 @@ +/* $NetBSD$ */ + +/* + * 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. + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * 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 the University of + * California, Berkeley and its contributors. + * 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. + * + * @(#)clock.c 8.1 (Berkeley) 6/11/93 + * + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +/* + * ebus mk48txx attachment. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +static int mkclock_ebus_match __P((struct device *, struct cfdata *, void *)); +static void mkclock_ebus_attach __P((struct device *, struct device *, void *)); + +CFATTACH_DECL(mkclock_ebus, sizeof(struct mk48txx_softc), + mkclock_ebus_match, mkclock_ebus_attach, NULL, NULL); + +extern struct cfdriver mkclock_cd; + +/* + * The OPENPROM calls the clock the "eeprom", so we have to have our + * own special match function to call it the "mkclock". + */ +static int +mkclock_ebus_match(parent, cf, aux) + struct device *parent; + struct cfdata *cf; + void *aux; +{ + struct ebus_attach_args *ea = aux; + + return (strcmp("eeprom", ea->ea_name) == 0); +} + +/* + * Attach a clock (really `eeprom') to the ebus. + * + * We ignore any existing virtual address as we need to map + * this read-only and make it read-write only temporarily, + * whenever we read or write the clock chip. The clock also + * contains the ID ``PROM'', and I have already had the pleasure + * of reloading the cpu type, Ethernet address, etc, by hand from + * the console FORTH interpreter. I intend not to enjoy it again. + * + * the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is + * supposed to be identical to it. + * + * This is *UGLY*! We probably have multiple mappings. But I do + * know that this all fits inside an 8K page, so I'll just map in + * once. + * + * What we really need is some way to record the bus attach args + * so we can call *_bus_map() later with BUS_SPACE_MAP_READONLY + * or not to write enable/disable the device registers. This is + * a non-trivial operation. + */ + +/* ARGSUSED */ +static void +mkclock_ebus_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct mk48txx_softc *sc = (void *)self; + struct ebus_attach_args *ea = aux; + int sz; + + sc->sc_bst = ea->ea_bustag; + + /* hard code to 8K? */ + sz = ea->ea_reg[0].size; + + if (bus_space_map(sc->sc_bst, + EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), + sz, + BUS_SPACE_MAP_LINEAR, + &sc->sc_bsh) != 0) { + printf("%s: can't map register\n", self->dv_xname); + return; + } + + mkclock_common_attach(sc, ea->ea_node); +} --- /dev/null 2003-11-03 00:07:10.000000000 +0900 +++ dev/mkclock_sbus.c 2003-11-02 23:13:55.000000000 +0900 @@ -0,0 +1,159 @@ +/* $NetBSD$ */ + +/* + * 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. + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * 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 the University of + * California, Berkeley and its contributors. + * 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. + * + * @(#)clock.c 8.1 (Berkeley) 6/11/93 + * + */ + +#include +__KERNEL_RCSID(0, "$NetBSD$"); + +/* + * sbus mk48txx attachment. + */ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +static int mkclock_sbus_match __P((struct device *, struct cfdata *, void *)); +static void mkclock_sbus_attach __P((struct device *, struct device *, void *)); + +CFATTACH_DECL(mkclock_sbus, sizeof(struct mk48txx_softc), + mkclock_sbus_match, mkclock_sbus_attach, NULL, NULL); + +extern struct cfdriver mkclock_cd; + +/* + * The OPENPROM calls the clock the "eeprom", so we have to have our + * own special match function to call it the "mkclock". + */ +static int +mkclock_sbus_match(parent, cf, aux) + struct device *parent; + struct cfdata *cf; + void *aux; +{ + struct sbus_attach_args *sa = aux; + + return (strcmp("eeprom", sa->sa_name) == 0); +} + +/* + * Attach a clock (really `eeprom') to the sbus. + * + * We ignore any existing virtual address as we need to map + * this read-only and make it read-write only temporarily, + * whenever we read or write the clock chip. The clock also + * contains the ID ``PROM'', and I have already had the pleasure + * of reloading the cpu type, Ethernet address, etc, by hand from + * the console FORTH interpreter. I intend not to enjoy it again. + * + * the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is + * supposed to be identical to it. + * + * This is *UGLY*! We probably have multiple mappings. But I do + * know that this all fits inside an 8K page, so I'll just map in + * once. + * + * What we really need is some way to record the bus attach args + * so we can call *_bus_map() later with BUS_SPACE_MAP_READONLY + * or not to write enable/disable the device registers. This is + * a non-trivial operation. + */ + +/* ARGSUSED */ +static void +mkclock_sbus_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct mk48txx_softc *sc = (void *)self; + struct sbus_attach_args *sa = aux; + int sz; + + sc->sc_bst = sa->sa_bustag; + + /* use sa->sa_regs[0].size? */ + sz = 8192; + + if (sbus_bus_map(sc->sc_bst, + sa->sa_slot, + (sa->sa_offset & ~(PAGE_SIZE - 1)), + sz, + BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_READONLY, + &sc->sc_bsh) != 0) { + printf("%s: can't map register\n", self->dv_xname); + return; + } + + mkclock_common_attach(sc, sa->sa_node); +} Index: conf/GENERIC32 =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/conf/GENERIC32,v retrieving revision 1.74 diff -u -r1.74 GENERIC32 --- conf/GENERIC32 27 Oct 2003 05:34:48 -0000 1.74 +++ conf/GENERIC32 2 Nov 2003 15:10:18 -0000 @@ -230,9 +230,11 @@ ## Mostek clock found on 4/300, sun4c, sun4m and sun4u systems. ## The Mostek clock NVRAM is the "eeprom" on sun4/300 systems. -clock* at sbus? slot ? offset ? -clock* at ebus? -rtc* at ebus? +mkclock* at sbus? slot ? offset ? +mkclock* at ebus? + +## M5819 (MC146818 compatible) clock found on Netra X1 and Fire V100. +mcclock* at ebus? ## Timer chip found on 4/300, sun4c, sun4m and (some) sun4u systems. timer* at mainbus0 # sun4c Index: conf/files.sparc64 =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/conf/files.sparc64,v retrieving revision 1.86 diff -u -r1.86 files.sparc64 --- conf/files.sparc64 2 Nov 2003 09:33:56 -0000 1.86 +++ conf/files.sparc64 2 Nov 2003 15:10:18 -0000 @@ -40,19 +40,21 @@ attach ebus at pci file arch/sparc64/dev/ebus.c ebus -device clock: mk48txx, mc146818 -attach clock at mainbus, sbus with clock_sbus -attach clock at ebus with clock_ebus - -device rtc: mc146818 -attach rtc at ebus with rtc_ebus +device mkclock: mk48txx +attach mkclock at mainbus, sbus with mkclock_sbus +attach mkclock at ebus with mkclock_ebus +file arch/sparc64/dev/mkclock.c mkclock +file arch/sparc64/dev/mkclock_sbus.c mkclock_sbus +file arch/sparc64/dev/mkclock_ebus.c mkclock_ebus + +device mcclock: mc146818 +attach mcclock at ebus with mcclock_ebus +file arch/sparc64/dev/mcclock_ebus.c mcclock_ebus device timer attach timer at mainbus, sbus - -device eeprom -attach eeprom at sbus, ebus -file arch/sparc64/sparc64/clock.c +# XXX should be split from arch/sparc64/sparc64/clock.c +#file arch/sparc64/dev/timer.c timer device power attach power at sbus, ebus @@ -193,6 +195,7 @@ file arch/sparc64/sparc64/trap.c file arch/sparc64/sparc64/vm_machdep.c file arch/sparc64/sparc64/disksubr.c +file arch/sparc64/sparc64/clock.c file arch/sparc64/sparc64/db_interface.c ddb | kgdb file arch/sparc64/sparc64/db_trace.c ddb Index: include/eeprom.h =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/include/eeprom.h,v retrieving revision 1.3 diff -u -r1.3 eeprom.h --- include/eeprom.h 20 Jul 2002 11:52:21 -0000 1.3 +++ include/eeprom.h 2 Nov 2003 15:10:18 -0000 @@ -1,3 +1,6 @@ /* $NetBSD: eeprom.h,v 1.3 2002/07/20 11:52:21 mrg Exp $ */ #include + +/* XXX should be in */ +extern struct idprom *idprom; Index: sparc64/clock.c =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/sparc64/clock.c,v retrieving revision 1.66 diff -u -r1.66 clock.c --- sparc64/clock.c 1 Nov 2003 23:04:32 -0000 1.66 +++ sparc64/clock.c 2 Nov 2003 15:10:20 -0000 @@ -60,8 +60,7 @@ #include "opt_multiprocessor.h" /* - * Clock driver. This is the id prom and eeprom driver as well - * and includes the timer register functions too. + * Clock driver. This driver includes the timer register functions too. */ /* Define this for a 1/4s clock to ease debugging */ @@ -87,10 +86,6 @@ #include #include -#include -#include -#include -#include #include #include @@ -122,32 +117,9 @@ static struct intrhand level14 = { statintr }; static struct intrhand schedint = { schedintr }; -/* - * clock (eeprom) attaches at the sbus or the ebus (PCI) - */ -static int clockmatch_sbus __P((struct device *, struct cfdata *, void *)); -static void clockattach_sbus __P((struct device *, struct device *, void *)); -static int clockmatch_ebus __P((struct device *, struct cfdata *, void *)); -static void clockattach_ebus __P((struct device *, struct device *, void *)); -static int clockmatch_rtc __P((struct device *, struct cfdata *, void *)); -static void clockattach_rtc __P((struct device *, struct device *, void *)); -static void clockattach __P((struct mk48txx_softc *, int)); - - -CFATTACH_DECL(clock_sbus, sizeof(struct mk48txx_softc), - clockmatch_sbus, clockattach_sbus, NULL, NULL); - -CFATTACH_DECL(clock_ebus, sizeof(struct mk48txx_softc), - clockmatch_ebus, clockattach_ebus, NULL, NULL); - -CFATTACH_DECL(rtc_ebus, sizeof(struct mc146818_softc), - clockmatch_rtc, clockattach_rtc, NULL, NULL); - -extern struct cfdriver clock_cd; - /* Global TOD clock handle & idprom pointer */ static todr_chip_handle_t todr_handle = NULL; -static struct idprom *idprom; +struct idprom *idprom; static int timermatch __P((struct device *, struct cfdata *, void *)); static void timerattach __P((struct device *, struct device *, void *)); @@ -157,7 +129,6 @@ CFATTACH_DECL(timer, sizeof(struct device), timermatch, timerattach, NULL, NULL); -int clock_wenable __P((struct todr_chip_handle *, int)); struct chiptime; void myetheraddr __P((u_char *)); int chiptotime __P((int, int, int, int, int, int)); @@ -166,291 +137,6 @@ int timerblurb = 10; /* Guess a value; used before clock is attached */ -u_int rtc_read_reg(struct mc146818_softc *, u_int); -void rtc_write_reg(struct mc146818_softc *, u_int, u_int); -u_int rtc_getcent(struct mc146818_softc *); -void rtc_setcent(struct mc146818_softc *, u_int); - -/* - * The OPENPROM calls the clock the "eeprom", so we have to have our - * own special match function to call it the "clock". - */ -static int -clockmatch_sbus(parent, cf, aux) - struct device *parent; - struct cfdata *cf; - void *aux; -{ - struct sbus_attach_args *sa = aux; - - return (strcmp("eeprom", sa->sa_name) == 0); -} - -static int -clockmatch_ebus(parent, cf, aux) - struct device *parent; - struct cfdata *cf; - void *aux; -{ - struct ebus_attach_args *ea = aux; - - return (strcmp("eeprom", ea->ea_name) == 0); -} - -static int -clockmatch_rtc(parent, cf, aux) - struct device *parent; - struct cfdata *cf; - void *aux; -{ - struct ebus_attach_args *ea = aux; - - return (strcmp("rtc", ea->ea_name) == 0); -} - -/* - * Attach a clock (really `eeprom') to the sbus or ebus. - * - * We ignore any existing virtual address as we need to map - * this read-only and make it read-write only temporarily, - * whenever we read or write the clock chip. The clock also - * contains the ID ``PROM'', and I have already had the pleasure - * of reloading the cpu type, Ethernet address, etc, by hand from - * the console FORTH interpreter. I intend not to enjoy it again. - * - * the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is - * supposed to be identical to it. - * - * This is *UGLY*! We probably have multiple mappings. But I do - * know that this all fits inside an 8K page, so I'll just map in - * once. - * - * What we really need is some way to record the bus attach args - * so we can call *_bus_map() later with BUS_SPACE_MAP_READONLY - * or not to write enable/disable the device registers. This is - * a non-trivial operation. - */ - -/* ARGSUSED */ -static void -clockattach_sbus(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct mk48txx_softc *sc = (void *)self; - struct sbus_attach_args *sa = aux; - int sz; - - sc->sc_bst = sa->sa_bustag; - - /* use sa->sa_regs[0].size? */ - sz = 8192; - - if (sbus_bus_map(sc->sc_bst, - sa->sa_slot, - (sa->sa_offset & ~(PAGE_SIZE - 1)), - sz, - BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_READONLY, - &sc->sc_bsh) != 0) { - printf("%s: can't map register\n", self->dv_xname); - return; - } - clockattach(sc, sa->sa_node); - - /* Save info for the clock wenable call. */ - todr_handle->todr_setwen = clock_wenable; -} - -/* - * Write en/dis-able clock registers. We coordinate so that several - * writers can run simultaneously. - */ -int -clock_wenable(handle, onoff) - struct todr_chip_handle *handle; - int onoff; -{ - struct mk48txx_softc *sc; - vm_prot_t prot; - vaddr_t va; - int s, err = 0; - static int writers; - - s = splhigh(); - if (onoff) - prot = writers++ == 0 ? VM_PROT_READ|VM_PROT_WRITE : 0; - else - prot = --writers == 0 ? VM_PROT_READ : 0; - splx(s); - if (prot == VM_PROT_NONE) { - return 0; - } - sc = handle->cookie; - va = (vaddr_t)bus_space_vaddr(sc->sc_bst, sc->sc_bsh); - if (va == 0UL) { - printf("clock_wenable: WARNING -- cannot get va\n"); - return EIO; - } - pmap_kprotect(va, prot); - return (err); -} - - -/* ARGSUSED */ -static void -clockattach_ebus(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct mk48txx_softc *sc = (void *)self; - struct ebus_attach_args *ea = aux; - int sz; - - sc->sc_bst = ea->ea_bustag; - - /* hard code to 8K? */ - sz = ea->ea_reg[0].size; - - if (bus_space_map(sc->sc_bst, - EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), - sz, - BUS_SPACE_MAP_LINEAR, - &sc->sc_bsh) != 0) { - printf("%s: can't map register\n", self->dv_xname); - return; - } - clockattach(sc, ea->ea_node); - - /* Save info for the clock wenable call. */ - todr_handle->todr_setwen = clock_wenable; -} - - -static void -clockattach(sc, node) - struct mk48txx_softc *sc; - int node; -{ - struct idprom *idp; - int h; - - sc->sc_model = PROM_getpropstring(node, "model"); - -#ifdef DIAGNOSTIC - if (sc->sc_model == NULL) - panic("clockattach: no model property"); -#endif - - /* Our TOD clock year 0 is 1968 */ - sc->sc_year0 = 1968; - mk48txx_attach(sc); - -#define IDPROM_OFFSET (8*1024 - 40) /* XXX - get nvram sz from driver */ - idp = (struct idprom *)((vaddr_t)bus_space_vaddr(sc->sc_bst, - sc->sc_bsh) + IDPROM_OFFSET); - - h = idp->id_machine << 24; - h |= idp->id_hostid[0] << 16; - h |= idp->id_hostid[1] << 8; - h |= idp->id_hostid[2]; - hostid = h; - printf(": hostid %x\n", (u_int)hostid); - - idprom = idp; - - /* XXX should be done by todr_attach() */ - todr_handle = &sc->sc_handle; -} - -/* - * `rtc' is a ds1287 on an ebus (actually an isa bus, but we use the - * ebus driver for isa.) So we can use ebus_wenable() but need to do - * different attach work and use different todr routines. It does not - * incorporate an IDPROM. - */ - -/* - * XXX the stupid ds1287 is not mapped directly but uses an address - * and a data reg so we cannot access the stuuupid thing w/o having - * write access to the registers. - * - * XXXX We really need to mutex register access! - */ -#define RTC_ADDR 0 -#define RTC_DATA 1 -u_int -rtc_read_reg(struct mc146818_softc *sc, u_int reg) -{ - - bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg); - return (bus_space_read_1(sc->sc_bst, sc->sc_bsh, RTC_DATA)); -} -void -rtc_write_reg(struct mc146818_softc *sc, u_int reg, u_int val) -{ - - bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg); - bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_DATA, val); -} - -/* ARGSUSED */ -static void -clockattach_rtc(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct mc146818_softc *sc = (void *)self; - struct ebus_attach_args *ea = aux; - char *model; - int sz; - - sc->sc_bst = ea->ea_bustag; - - /* hard code to 8K? */ - sz = ea->ea_reg[0].size; - - if (bus_space_map(sc->sc_bst, - EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), - sz, - BUS_SPACE_MAP_LINEAR, - &sc->sc_bsh) != 0) { - printf("%s: can't map register\n", self->dv_xname); - return; - } - - model = PROM_getpropstring(ea->ea_node, "model"); -#ifdef DIAGNOSTIC - if (model == NULL) - panic("clockattach_rtc: no model property"); -#endif - - /* Our TOD clock year 0 is 0 */ - sc->sc_year0 = 0; - sc->sc_flag = MC146818_NO_CENT_ADJUST; - sc->sc_mcread = rtc_read_reg; - sc->sc_mcwrite = rtc_write_reg; - sc->sc_getcent = rtc_getcent; - sc->sc_setcent = rtc_setcent; - mc146818_attach(sc); - - printf(": %s\n", model); - - /* - * Turn interrupts off, just in case. (Although they shouldn't - * be wired to an interrupt controller on sparcs). - */ - rtc_write_reg(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); - - /* - * Apparently on some machines the TOD registers are on the same - * physical page as the COM registers. So we won't protect them. - */ - /*sc->sc_handle.todr_setwen = NULL;*/ - - /* XXX should be done by todr_attach() */ - todr_handle = &sc->sc_handle; -} - /* * The sun4u OPENPROMs call the timer the "counter-timer", except for * the lame UltraSPARC IIi PCI machines that don't have them. @@ -900,6 +586,20 @@ int sparc_clock_time_is_ok; /* + * Common parts of todclock autoconfiguration. + */ +void +todr_attach(handle) + todr_chip_handle_t handle; +{ + + if (todr_handle) + panic("todr_attach: too many todclocks configured"); + + todr_handle = handle; +} + +/* * Set up the system's time, given a `reasonable' time value. */ void @@ -972,41 +672,4 @@ if (todr_handle == 0 || todr_settime(todr_handle, (struct timeval *)&time) != 0) printf("Cannot set time in time-of-day clock\n"); -} - -/* - * XXX: these may actually belong somewhere else, but since the - * EEPROM is so closely tied to the clock on some models, perhaps - * it needs to stay here... - */ -int -eeprom_uio(uio) - struct uio *uio; -{ - return (ENODEV); -} - - -/* - * MD mc146818 RTC todr routines. - */ - -/* Loooks like Sun stores the century info somewhere in CMOS RAM */ -#define MC_CENT 0x32 - -u_int -rtc_getcent(sc) - struct mc146818_softc *sc; -{ - - return rtc_read_reg(sc, MC_CENT); -} - -void -rtc_setcent(sc, cent) - struct mc146818_softc *sc; - u_int cent; -{ - - rtc_write_reg(sc, MC_CENT, cent); }