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