1*c7fb772bSthorpej /* $NetBSD: geode.c,v 1.17 2021/08/07 16:18:55 thorpej Exp $ */
265eb4295Sdyoung
365eb4295Sdyoung /*-
465eb4295Sdyoung * Copyright (c) 2005 David Young. All rights reserved.
565eb4295Sdyoung *
609b51ec9Skardel * This code was written by David Young and merged with geodecntr code
709b51ec9Skardel * by Frank Kardel.
865eb4295Sdyoung *
965eb4295Sdyoung * Redistribution and use in source and binary forms, with or without
1065eb4295Sdyoung * modification, are permitted provided that the following conditions
1165eb4295Sdyoung * are met:
1265eb4295Sdyoung * 1. Redistributions of source code must retain the above copyright
1365eb4295Sdyoung * notice, this list of conditions and the following disclaimer.
1465eb4295Sdyoung * 2. Redistributions in binary form must reproduce the above copyright
1565eb4295Sdyoung * notice, this list of conditions and the following disclaimer in the
1665eb4295Sdyoung * documentation and/or other materials provided with the distribution.
1765eb4295Sdyoung *
1865eb4295Sdyoung * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
1965eb4295Sdyoung * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2065eb4295Sdyoung * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
2165eb4295Sdyoung * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
2265eb4295Sdyoung * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2365eb4295Sdyoung * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2465eb4295Sdyoung * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2565eb4295Sdyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2665eb4295Sdyoung * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2765eb4295Sdyoung * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2865eb4295Sdyoung * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2965eb4295Sdyoung * OF SUCH DAMAGE.
3065eb4295Sdyoung */
3165eb4295Sdyoung /*-
3265eb4295Sdyoung * Copyright (c) 2002 The NetBSD Foundation, Inc.
3365eb4295Sdyoung * All rights reserved.
3465eb4295Sdyoung *
3565eb4295Sdyoung * This code is derived from software contributed to The NetBSD Foundation
3665eb4295Sdyoung * by Jason R. Thorpe.
3765eb4295Sdyoung *
3865eb4295Sdyoung * Redistribution and use in source and binary forms, with or without
3965eb4295Sdyoung * modification, are permitted provided that the following conditions
4065eb4295Sdyoung * are met:
4165eb4295Sdyoung * 1. Redistributions of source code must retain the above copyright
4265eb4295Sdyoung * notice, this list of conditions and the following disclaimer.
4365eb4295Sdyoung * 2. Redistributions in binary form must reproduce the above copyright
4465eb4295Sdyoung * notice, this list of conditions and the following disclaimer in the
4565eb4295Sdyoung * documentation and/or other materials provided with the distribution.
4665eb4295Sdyoung *
4765eb4295Sdyoung * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
4865eb4295Sdyoung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
4965eb4295Sdyoung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
5065eb4295Sdyoung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
5165eb4295Sdyoung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5265eb4295Sdyoung * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5365eb4295Sdyoung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5465eb4295Sdyoung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5565eb4295Sdyoung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5665eb4295Sdyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5765eb4295Sdyoung * POSSIBILITY OF SUCH DAMAGE.
5865eb4295Sdyoung */
5965eb4295Sdyoung
6065eb4295Sdyoung /*
6109b51ec9Skardel * Device driver for the special devices attached to the GBA (watchdog, high
6209b51ec9Skardel * resolution counter, ...) in the AMD Geode SC1100 processor.
6365eb4295Sdyoung */
6465eb4295Sdyoung
6565eb4295Sdyoung #include <sys/cdefs.h>
6665eb4295Sdyoung
67*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: geode.c,v 1.17 2021/08/07 16:18:55 thorpej Exp $");
6865eb4295Sdyoung
6965eb4295Sdyoung #include <sys/param.h>
7065eb4295Sdyoung #include <sys/systm.h>
7165eb4295Sdyoung #include <sys/device.h>
7265eb4295Sdyoung #include <sys/wdog.h>
7365eb4295Sdyoung #include <uvm/uvm_extern.h>
74f5b064eeSdyoung #include <sys/bus.h>
7565eb4295Sdyoung #include <dev/pci/pcivar.h>
7665eb4295Sdyoung #include <dev/pci/pcidevs.h>
7709b51ec9Skardel #include <arch/i386/pci/geodevar.h>
7865eb4295Sdyoung #include <arch/i386/pci/geodereg.h>
7965eb4295Sdyoung #include <dev/sysmon/sysmonvar.h>
8065eb4295Sdyoung
8165eb4295Sdyoung #ifdef GEODE_DEBUG
8265eb4295Sdyoung #define GEODE_DPRINTF(__x) printf __x
8365eb4295Sdyoung #else /* GEODE_DEBUG */
8465eb4295Sdyoung #define GEODE_DPRINTF(__x) /* nothing */
8565eb4295Sdyoung #endif
8665eb4295Sdyoung
8765eb4295Sdyoung static int
geode_gcb_match(device_t parent,cfdata_t match,void * aux)88ed38b748Sxtraeme geode_gcb_match(device_t parent, cfdata_t match, void *aux)
8965eb4295Sdyoung {
9065eb4295Sdyoung struct pci_attach_args *pa = aux;
9165eb4295Sdyoung
9265eb4295Sdyoung if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS &&
9365eb4295Sdyoung PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NS_SC1100_XBUS)
9465eb4295Sdyoung return (10); /* XXX beat pchb? -dyoung */
9565eb4295Sdyoung
9665eb4295Sdyoung return (0);
9765eb4295Sdyoung }
9865eb4295Sdyoung
9965eb4295Sdyoung static void
geode_gcb_attach(device_t parent,device_t self,void * aux)100ed38b748Sxtraeme geode_gcb_attach(device_t parent, device_t self, void *aux)
10165eb4295Sdyoung {
102ed38b748Sxtraeme struct geode_gcb_softc *sc = device_private(self);
10365eb4295Sdyoung struct pci_attach_args *pa = aux;
10465eb4295Sdyoung uint32_t cba;
10509b51ec9Skardel u_int rev;
10665eb4295Sdyoung
10765eb4295Sdyoung cba = pci_conf_read(pa->pa_pc, pa->pa_tag, SC1100_XBUS_CBA_SCRATCHPAD);
10865eb4295Sdyoung sc->sc_iot = pa->pa_iot;
10965eb4295Sdyoung if (bus_space_map(sc->sc_iot, (bus_addr_t)cba, SC1100_GCB_SIZE, 0,
11065eb4295Sdyoung &sc->sc_ioh) != 0) {
1111c1d16a9Sjmcneill aprint_error(": unable to map registers\n");
11265eb4295Sdyoung return;
11365eb4295Sdyoung }
11465eb4295Sdyoung
11565eb4295Sdyoung GEODE_DPRINTF(("%s: mapped %u bytes at %#08" PRIx32 "\n",
116ed38b748Sxtraeme device_xname(self), SC1100_GCB_SIZE, cba));
11765eb4295Sdyoung
11809b51ec9Skardel rev = bus_space_read_1(sc->sc_iot, sc->sc_ioh, SC1100_GCB_REV_B);
11965eb4295Sdyoung
1201c1d16a9Sjmcneill aprint_naive("\n");
12109b51ec9Skardel aprint_normal(": AMD Geode GCB (rev. 0x%02x)\n", rev);
12265eb4295Sdyoung
123*c7fb772bSthorpej while (config_found(self, NULL, NULL, CFARGS_NONE) != NULL)
12409b51ec9Skardel /* empty */;
12565eb4295Sdyoung }
1268d9f58eaSdyoung static int
geode_gcb_detach(device_t self,int flags)1278d9f58eaSdyoung geode_gcb_detach(device_t self, int flags)
1288d9f58eaSdyoung {
1298d9f58eaSdyoung int rc;
1308d9f58eaSdyoung struct geode_gcb_softc *sc = device_private(self);
13165eb4295Sdyoung
1328d9f58eaSdyoung if ((rc = config_detach_children(self, flags)) != 0)
1338d9f58eaSdyoung return rc;
1348d9f58eaSdyoung
1358d9f58eaSdyoung bus_space_unmap(sc->sc_iot, sc->sc_ioh, SC1100_GCB_SIZE);
1368d9f58eaSdyoung return 0;
1378d9f58eaSdyoung }
1388d9f58eaSdyoung
1398d9f58eaSdyoung static void
geode_gcb_childdetached(device_t parent,device_t child)1408d9f58eaSdyoung geode_gcb_childdetached(device_t parent, device_t child)
1418d9f58eaSdyoung {
1428d9f58eaSdyoung /* We hold no references to child devices, so there is nothing
1438d9f58eaSdyoung * to do.
1448d9f58eaSdyoung */
1458d9f58eaSdyoung }
1468d9f58eaSdyoung
147ed38b748Sxtraeme CFATTACH_DECL2_NEW(geodegcb, sizeof(struct geode_gcb_softc),
1488d9f58eaSdyoung geode_gcb_match, geode_gcb_attach, geode_gcb_detach, NULL, NULL,
1498d9f58eaSdyoung geode_gcb_childdetached);
150