Home | History | Annotate | Line # | Download | only in pci
      1 /*	$NetBSD: geode.c,v 1.17 2021/08/07 16:18:55 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2005 David Young.  All rights reserved.
      5  *
      6  * This code was written by David Young and merged with geodecntr code
      7  * by Frank Kardel.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     21  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DAVID
     22  * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     24  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     29  * OF SUCH DAMAGE.
     30  */
     31 /*-
     32  * Copyright (c) 2002 The NetBSD Foundation, Inc.
     33  * All rights reserved.
     34  *
     35  * This code is derived from software contributed to The NetBSD Foundation
     36  * by Jason R. Thorpe.
     37  *
     38  * Redistribution and use in source and binary forms, with or without
     39  * modification, are permitted provided that the following conditions
     40  * are met:
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  * 2. Redistributions in binary form must reproduce the above copyright
     44  *    notice, this list of conditions and the following disclaimer in the
     45  *    documentation and/or other materials provided with the distribution.
     46  *
     47  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     48  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     49  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     50  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     51  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     57  * POSSIBILITY OF SUCH DAMAGE.
     58  */
     59 
     60 /*
     61  * Device driver for the special devices attached to the GBA (watchdog, high
     62  * resolution counter, ...) in the AMD Geode SC1100 processor.
     63  */
     64 
     65 #include <sys/cdefs.h>
     66 
     67 __KERNEL_RCSID(0, "$NetBSD: geode.c,v 1.17 2021/08/07 16:18:55 thorpej Exp $");
     68 
     69 #include <sys/param.h>
     70 #include <sys/systm.h>
     71 #include <sys/device.h>
     72 #include <sys/wdog.h>
     73 #include <uvm/uvm_extern.h>
     74 #include <sys/bus.h>
     75 #include <dev/pci/pcivar.h>
     76 #include <dev/pci/pcidevs.h>
     77 #include <arch/i386/pci/geodevar.h>
     78 #include <arch/i386/pci/geodereg.h>
     79 #include <dev/sysmon/sysmonvar.h>
     80 
     81 #ifdef GEODE_DEBUG
     82 #define	GEODE_DPRINTF(__x) printf __x
     83 #else /* GEODE_DEBUG */
     84 #define	GEODE_DPRINTF(__x) /* nothing */
     85 #endif
     86 
     87 static int
     88 geode_gcb_match(device_t parent, cfdata_t match, void *aux)
     89 {
     90 	struct pci_attach_args *pa = aux;
     91 
     92 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS &&
     93 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NS_SC1100_XBUS)
     94 		return (10);	/* XXX beat pchb? -dyoung */
     95 
     96 	return (0);
     97 }
     98 
     99 static void
    100 geode_gcb_attach(device_t parent, device_t self, void *aux)
    101 {
    102 	struct geode_gcb_softc *sc = device_private(self);
    103 	struct pci_attach_args *pa = aux;
    104 	uint32_t cba;
    105 	u_int rev;
    106 
    107 	cba = pci_conf_read(pa->pa_pc, pa->pa_tag, SC1100_XBUS_CBA_SCRATCHPAD);
    108 	sc->sc_iot = pa->pa_iot;
    109 	if (bus_space_map(sc->sc_iot, (bus_addr_t)cba, SC1100_GCB_SIZE, 0,
    110 	    &sc->sc_ioh) != 0) {
    111 		aprint_error(": unable to map registers\n");
    112 		return;
    113 	}
    114 
    115 	GEODE_DPRINTF(("%s: mapped %u bytes at %#08" PRIx32 "\n",
    116 	    device_xname(self), SC1100_GCB_SIZE, cba));
    117 
    118 	rev = bus_space_read_1(sc->sc_iot, sc->sc_ioh, SC1100_GCB_REV_B);
    119 
    120 	aprint_naive("\n");
    121 	aprint_normal(": AMD Geode GCB (rev. 0x%02x)\n", rev);
    122 
    123 	while (config_found(self, NULL, NULL, CFARGS_NONE) != NULL)
    124 		/* empty */;
    125 }
    126 static int
    127 geode_gcb_detach(device_t self, int flags)
    128 {
    129 	int rc;
    130 	struct geode_gcb_softc *sc = device_private(self);
    131 
    132 	if ((rc = config_detach_children(self, flags)) != 0)
    133 		return rc;
    134 
    135 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, SC1100_GCB_SIZE);
    136 	return 0;
    137 }
    138 
    139 static void
    140 geode_gcb_childdetached(device_t parent, device_t child)
    141 {
    142 	/* We hold no references to child devices, so there is nothing
    143 	 * to do.
    144 	 */
    145 }
    146 
    147 CFATTACH_DECL2_NEW(geodegcb, sizeof(struct geode_gcb_softc),
    148     geode_gcb_match, geode_gcb_attach, geode_gcb_detach, NULL, NULL,
    149     geode_gcb_childdetached);
    150