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