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