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