diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2008-07-06 07:27:44 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2008-07-06 07:27:44 +0000 |
commit | 2303e703bf92cae6d198befa649f103275fa4606 (patch) | |
tree | 4158944d512d1b9529f82d09d32036155ac1faca /sys | |
parent | c7f8d23312c14ad4ba557a3597b7d7397f045991 (diff) |
Add sbbc(4), a driver for the BootBus controller on Serengeti and StarCat
systems that provides time of day services and (in the future) console
services.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/sparc64/conf/GENERIC | 3 | ||||
-rw-r--r-- | sys/arch/sparc64/conf/RAMDISK | 3 | ||||
-rw-r--r-- | sys/arch/sparc64/conf/files.sparc64 | 6 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/sbbc.c | 201 |
4 files changed, 210 insertions, 3 deletions
diff --git a/sys/arch/sparc64/conf/GENERIC b/sys/arch/sparc64/conf/GENERIC index 54214eaf960..5d47b2ac31f 100644 --- a/sys/arch/sparc64/conf/GENERIC +++ b/sys/arch/sparc64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.213 2008/06/27 05:40:21 brad Exp $ +# $OpenBSD: GENERIC,v 1.214 2008/07/06 07:27:43 kettenis Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -52,6 +52,7 @@ ppb* at pci? ebus* at mainbus0 ebus* at pci? vbus0 at mainbus0 +sbbc* at pci? # PCI Ethernet lmc* at pci? # Lan Media Corp SSI/T3/HSSI diff --git a/sys/arch/sparc64/conf/RAMDISK b/sys/arch/sparc64/conf/RAMDISK index 4d0a0bdae68..bf516126db9 100644 --- a/sys/arch/sparc64/conf/RAMDISK +++ b/sys/arch/sparc64/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.73 2008/07/01 04:50:59 brad Exp $ +# $OpenBSD: RAMDISK,v 1.74 2008/07/06 07:27:43 kettenis Exp $ # Machine architecture; required by config(8) machine sparc64 @@ -63,6 +63,7 @@ ppb* at pci? ebus* at mainbus0 ebus* at pci? vbus0 at mainbus0 +sbbc* at pci? # PCI Ethernet hme* at pci? # Sun Happy Meal 10/100 diff --git a/sys/arch/sparc64/conf/files.sparc64 b/sys/arch/sparc64/conf/files.sparc64 index f687c16acc5..b7ffe67e729 100644 --- a/sys/arch/sparc64/conf/files.sparc64 +++ b/sys/arch/sparc64/conf/files.sparc64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.sparc64,v 1.106 2008/06/10 00:02:09 kettenis Exp $ +# $OpenBSD: files.sparc64,v 1.107 2008/07/06 07:27:43 kettenis Exp $ # $NetBSD: files.sparc64,v 1.50 2001/08/10 20:53:50 eeh Exp $ # maxpartitions must be first item in files.${ARCH} @@ -117,6 +117,10 @@ device ifb: wsemuldisplaydev, rasops8 attach ifb at pci file arch/sparc64/dev/ifb.c ifb +device sbbc +attach sbbc at pci +file arch/sparc64/dev/sbbc.c sbbc + # IOMMU is for both sbus and pci file arch/sparc64/dev/iommu.c sbus | psycho | schizo | pyro | vpci file arch/sparc64/dev/viommu.c vpci diff --git a/sys/arch/sparc64/dev/sbbc.c b/sys/arch/sparc64/dev/sbbc.c new file mode 100644 index 00000000000..9bc9e033def --- /dev/null +++ b/sys/arch/sparc64/dev/sbbc.c @@ -0,0 +1,201 @@ +/* $OpenBSD: sbbc.c,v 1.1 2008/07/06 07:27:43 kettenis Exp $ */ +/* + * Copyright (c) 2008 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/device.h> +#include <sys/malloc.h> +#include <sys/systm.h> + +#include <machine/autoconf.h> +#include <machine/openfirm.h> + +#include <dev/pci/pcidevs.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcivar.h> + +#include <dev/clock_subr.h> + +extern todr_chip_handle_t todr_handle; + +#define SBBC_PCI_BAR PCI_MAPREG_START + +#define SBBC_REGS_OFFSET 0x800000 +#define SBBC_REGS_SIZE 0x6230 +#define SBBC_SRAM_OFFSET 0x900000 +#define SBBC_SRAM_SIZE 0x20000 /* 128KB SRAM */ + +#define SBBC_MAX_TAGS 32 + +struct sbbc_sram_tag { + char tag_key[8]; + uint32_t tag_size; + uint32_t tag_offset; +}; + +struct sbbc_sram_toc { + char toc_magic[8]; + uint8_t toc_reserved; + uint8_t toc_type; + uint16_t toc_version; + uint32_t toc_ntags; + struct sbbc_sram_tag toc_tag[SBBC_MAX_TAGS]; +}; + +/* Time of day service. */ +struct sbbc_sram_tod { + uint32_t tod_magic; + uint32_t tod_version; + uint64_t tod_time; + uint64_t tod_skew; + uint32_t tod_reserved; + uint32_t tod_heartbeat; + uint32_t tod_timeout; +}; + +#define SBBC_TOD_MAGIC 0x54443100 +#define SBBC_TOD_VERSION 1 + +struct sbbc_softc { + struct device sc_dv; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_reg_ioh; + bus_space_handle_t sc_sram_ioh; + caddr_t sc_sram; + uint32_t sc_sram_toc; + + struct sparc_bus_space_tag sc_bbt; +}; + +int sbbc_match(struct device *, void *, void *); +void sbbc_attach(struct device *, struct device *, void *); + +struct cfattach sbbc_ca = { + sizeof(struct sbbc_softc), sbbc_match, sbbc_attach +}; + +struct cfdriver sbbc_cd = { + NULL, "sbbc", DV_DULL +}; + +void sbbc_attach_tod(struct sbbc_softc *, uint32_t); +int sbbc_tod_gettime(todr_chip_handle_t, struct timeval *); +int sbbc_tod_settime(todr_chip_handle_t, struct timeval *); + +int +sbbc_match(struct device *parent, void *match, void *aux) +{ + struct pci_attach_args *pa = aux; + + if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN && + (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_SBBC)) + return (1); + + return (0); +} + +void +sbbc_attach(struct device *parent, struct device *self, void *aux) +{ + struct sbbc_softc *sc = (void *)self; + struct pci_attach_args *pa = aux; + struct sbbc_sram_toc *toc; + bus_addr_t base; + bus_size_t size; + int chosen, iosram; + int i; + + /* XXX Don't byteswap. */ + sc->sc_bbt = *pa->pa_memt; + sc->sc_bbt.sasi = ASI_PRIMARY; + sc->sc_iot = &sc->sc_bbt; + + if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, SBBC_PCI_BAR, + PCI_MAPREG_TYPE_MEM, &base, &size, NULL)) { + printf(": can't find register space\n"); + return; + } + + if (bus_space_map(sc->sc_iot, base + SBBC_SRAM_OFFSET, + SBBC_SRAM_SIZE, 0, &sc->sc_sram_ioh)) { + printf(": can't map SRAM\n"); + return; + } + + printf("\n"); + + /* Check if we are the chosen one. */ + chosen = OF_finddevice("/chosen"); + if (OF_getprop(chosen, "iosram", &iosram, sizeof(iosram)) <= 0 || + PCITAG_NODE(pa->pa_tag) != iosram) + return; + + /* SRAM TOC offset defaults to 0. */ + if (OF_getprop(chosen, "iosram-toc", &sc->sc_sram_toc, + sizeof(sc->sc_sram_toc)) <= 0) + sc->sc_sram_toc = 0; + + sc->sc_sram = bus_space_vaddr(sc->sc_iot, sc->sc_sram_ioh); + toc = (struct sbbc_sram_toc *)(sc->sc_sram + sc->sc_sram_toc); + + for (i = 0; i < toc->toc_ntags; i++) { + if (strcmp(toc->toc_tag[i].tag_key, "TODDATA") == 0) + sbbc_attach_tod(sc, toc->toc_tag[i].tag_offset); + } +} + +void +sbbc_attach_tod(struct sbbc_softc *sc, uint32_t offset) +{ + struct sbbc_sram_tod *tod; + todr_chip_handle_t handle; + + tod = (struct sbbc_sram_tod *)(sc->sc_sram + offset); + if (tod->tod_magic != SBBC_TOD_MAGIC || + tod->tod_version < SBBC_TOD_VERSION) + return; + + handle = malloc(sizeof(struct todr_chip_handle), M_DEVBUF, M_NOWAIT); + if (handle == NULL) + panic("couldn't allocate todr_handle"); + + handle->cookie = tod; + handle->todr_gettime = sbbc_tod_gettime; + handle->todr_settime = sbbc_tod_settime; + + handle->bus_cookie = NULL; + handle->todr_setwen = NULL; + todr_handle = handle; +} + +int +sbbc_tod_gettime(todr_chip_handle_t handle, struct timeval *tv) +{ + struct sbbc_sram_tod *tod = handle->cookie; + + tv->tv_sec = tod->tod_time + tod->tod_skew; + tv->tv_usec = 0; + return (0); +} + +int +sbbc_tod_settime(todr_chip_handle_t handle, struct timeval *tv) +{ + struct sbbc_sram_tod *tod = handle->cookie; + + tod->tod_skew = tv->tv_sec - tod->tod_time; + return (0); +} |