mem.c revision 1.1.6.2 1 /* $NetBSD: mem.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $ */
2
3 /* $OpenBSD: mem.c,v 1.30 2007/09/22 16:21:32 krw Exp $ */
4 /*
5 * Copyright (c) 1998-2004 Michael Shalayeff
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 /*
30 * Copyright (c) 1991,1992,1994, The University of Utah and
31 * the Computer Systems Laboratory (CSL). All rights reserved.
32 *
33 * Subject to your agreements with CMU,
34 * permission to use, copy, modify and distribute this software and its
35 * documentation is hereby granted, provided that both the copyright
36 * notice and this permission notice appear in all copies of the
37 * software, derivative works or modified versions, and any portions
38 * thereof, and that both notices appear in supporting documentation.
39 *
40 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
41 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
42 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 *
44 * CSL requests users of this software to return to csl-dist (at) cs.utah.edu any
45 * improvements that they make and grant CSL redistribution rights.
46 *
47 * Utah $Hdr: mem.c 1.9 94/12/16$
48 */
49 /*
50 * Mach Operating System
51 * Copyright (c) 1992 Carnegie Mellon University
52 * All Rights Reserved.
53 *
54 * Permission to use, copy, modify and distribute this software and its
55 * documentation is hereby granted, provided that both the copyright
56 * notice and this permission notice appear in all copies of the
57 * software, derivative works or modified versions, and any portions
58 * thereof, and that both notices appear in supporting documentation.
59 *
60 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
61 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
62 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
63 *
64 * Carnegie Mellon requests users of this software to return to
65 *
66 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
67 * School of Computer Science
68 * Carnegie Mellon University
69 * Pittsburgh PA 15213-3890
70 *
71 * any improvements or extensions that they make and grant Carnegie Mellon
72 * the rights to redistribute these changes.
73 */
74
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $");
77
78 #include <sys/param.h>
79 #include <sys/systm.h>
80 #include <sys/buf.h>
81 #include <sys/conf.h>
82 #include <sys/malloc.h>
83 #include <sys/proc.h>
84 #include <sys/uio.h>
85 #include <sys/types.h>
86 #include <sys/device.h>
87 #include <sys/errno.h>
88 #include <sys/ioctl.h>
89 #include <sys/file.h>
90 #include <sys/bus.h>
91 #include <sys/mutex.h>
92
93 #include <uvm/uvm.h>
94
95 #include <machine/iomod.h>
96 #include <machine/autoconf.h>
97 #include <machine/pmap.h>
98
99 #include <hppa/hppa/machdep.h>
100 #include <hppa/dev/cpudevs.h>
101 #include <hppa/dev/viper.h>
102
103 /* registers on the PCXL2 MIOC */
104 struct l2_mioc {
105 uint32_t pad[0x20]; /* 0x000 */
106 uint32_t mioc_control; /* 0x080 MIOC control bits */
107 uint32_t mioc_status; /* 0x084 MIOC status bits */
108 uint32_t pad1[6]; /* 0x088 */
109 uint32_t sltcv; /* 0x0a0 L2 cache control */
110 #define SLTCV_AVWL 0x00002000 /* extra cycle for addr valid write low */
111 #define SLTCV_UP4COUT 0x00001000 /* update cache on CPU castouts */
112 #define SLTCV_EDCEN 0x08000000 /* enable error correction */
113 #define SLTCV_EDTAG 0x10000000 /* enable diagtag */
114 #define SLTCV_CHKTP 0x20000000 /* enable parity checking */
115 #define SLTCV_LOWPWR 0x40000000 /* low power mode */
116 #define SLTCV_ENABLE 0x80000000 /* enable L2 cache */
117 #define SLTCV_BITS "\020\15avwl\16up4cout\24edcen\25edtag\26chktp\27lowpwr\30l2ena"
118 uint32_t tagmask; /* 0x0a4 L2 cache tag mask */
119 uint32_t diagtag; /* 0x0a8 L2 invalidates tag */
120 uint32_t sltestat; /* 0x0ac L2 last logged tag read */
121 uint32_t slteadd; /* 0x0b0 L2 pa of -- " -- */
122 uint32_t pad2[3]; /* 0x0b4 */
123 uint32_t mtcv; /* 0x0c0 MIOC timings */
124 uint32_t ref; /* 0x0cc MIOC refresh timings */
125 uint32_t pad3[4]; /* 0x0d0 */
126 uint32_t mderradd; /* 0x0e0 addr of most evil mem error */
127 uint32_t pad4; /* 0x0e4 */
128 uint32_t dmaerr; /* 0x0e8 addr of most evil dma error */
129 uint32_t dioerr; /* 0x0ec addr of most evil dio error */
130 uint32_t gsc_timeout; /* 0x0f0 1-compl of GSC timeout delay */
131 uint32_t hidmamem; /* 0x0f4 amount of phys mem installed */
132 uint32_t pad5[2]; /* 0x0f8 */
133 uint32_t memcomp[16]; /* 0x100 memory address comparators */
134 uint32_t memmask[16]; /* 0x140 masks for -- " -- */
135 uint32_t memtest; /* 0x180 test address decoding */
136 uint32_t pad6[0xf]; /* 0x184 */
137 uint32_t outchk; /* 0x1c0 address decoding output */
138 uint32_t pad7[0x168]; /* 0x200 */
139 uint32_t gsc15x_config; /* 0x7a0 writev enable */
140 };
141
142 struct mem_softc {
143 device_t sc_dev;
144
145 volatile struct vi_trs *sc_vp;
146 volatile struct l2_mioc *sc_l2;
147 };
148
149 int memmatch(device_t, cfdata_t, void *);
150 void memattach(device_t, device_t, void *);
151
152 CFATTACH_DECL_NEW(mem, sizeof(struct mem_softc), memmatch, memattach,
153 NULL, NULL);
154
155 int
156 memmatch(device_t parent, cfdata_t cf, void *aux)
157 {
158 struct confargs *ca = aux;
159
160 if (ca->ca_type.iodc_type != HPPA_TYPE_MEMORY ||
161 ca->ca_type.iodc_sv_model != HPPA_MEMORY_PDEP)
162 return 0;
163 return 1;
164 }
165
166 void
167 memattach(device_t parent, device_t self, void *aux)
168 {
169 struct pdc_iodc_minit pdc_minit;
170 struct confargs *ca = aux;
171 struct mem_softc *sc = device_private(self);
172 int err, pagezero_cookie;
173 char bits[128];
174
175 sc->sc_dev = self;
176
177 aprint_normal(":");
178
179 pagezero_cookie = hppa_pagezero_map();
180
181 /* XXX check if we are dealing w/ Viper */
182 if (ca->ca_hpa == (hppa_hpa_t)VIPER_HPA) {
183
184 sc->sc_vp = (struct vi_trs *)
185 &((struct iomod *)ca->ca_hpa)->priv_trs;
186
187 /* XXX other values seem to blow it up */
188 if (sc->sc_vp->vi_status.hw_rev == 0) {
189 uint32_t vic;
190 int s, settimeout;
191
192 switch (cpu_modelno) {
193 case HPPA_BOARD_HP715_33:
194 case HPPA_BOARD_HP715S_33:
195 case HPPA_BOARD_HP715T_33:
196 case HPPA_BOARD_HP715_50:
197 case HPPA_BOARD_HP715S_50:
198 case HPPA_BOARD_HP715T_50:
199 case HPPA_BOARD_HP715_75:
200 case HPPA_BOARD_HP725_50:
201 case HPPA_BOARD_HP725_75:
202 settimeout = 1;
203 break;
204 default:
205 settimeout = 0;
206 break;
207 }
208 if (device_cfdata(self)->cf_flags & 1)
209 settimeout = !settimeout;
210
211 snprintb(bits, sizeof(bits), VIPER_BITS, VI_CTRL);
212 aprint_normal(" viper rev %x, ctrl %s",
213 sc->sc_vp->vi_status.hw_rev, bits);
214
215 s = splhigh();
216 vic = VI_CTRL;
217 ((struct vi_ctrl *)&vic)->core_den = 0;
218 ((struct vi_ctrl *)&vic)->sgc0_den = 0;
219 ((struct vi_ctrl *)&vic)->sgc1_den = 0;
220 ((struct vi_ctrl *)&vic)->eisa_den = 1;
221 ((struct vi_ctrl *)&vic)->core_prf = 1;
222
223 if (settimeout &&
224 ((struct vi_ctrl *)&vic)->vsc_tout == 0)
225 /* clks */
226 ((struct vi_ctrl *)&vic)->vsc_tout = 850;
227
228 sc->sc_vp->vi_control = vic;
229
230 __asm __volatile("stwas %1, 0(%0)"
231 :: "r" (&VI_CTRL), "r" (vic) : "memory");
232 splx(s);
233 #ifdef DEBUG
234 snprintb(bits, sizeof(bits), VIPER_BITS, VI_CTRL);
235 printf (" >> %s", bits);
236 #endif
237 } else
238 sc->sc_vp = NULL;
239 } else
240 sc->sc_vp = NULL;
241
242 err = pdcproc_iodc_ninit(&pdc_minit, ca->ca_hpa, PAGE0->imm_spa_size);
243 if (err < 0)
244 pdc_minit.max_spa = PAGE0->imm_max_mem;
245
246 hppa_pagezero_unmap(pagezero_cookie);
247
248 aprint_normal(" size %d", pdc_minit.max_spa / (1024*1024));
249 if (pdc_minit.max_spa % (1024*1024))
250 aprint_normal(".%d", pdc_minit.max_spa % (1024*1024));
251 aprint_normal("MB");
252
253 /* L2 cache controller is a part of the memory controller on PCXL2 */
254 if (hppa_cpu_info->hci_cputype == hpcxl2) {
255 sc->sc_l2 = (struct l2_mioc *)ca->ca_hpa;
256 #ifdef DEBUG
257 snprintb(bits, sizeof(bits), SLTCV_BITS, sc->sc_l2->sltcv);
258 printf(", sltcv %s", bits);
259 #endif
260 /* sc->sc_l2->sltcv |= SLTCV_UP4COUT; */
261 if (sc->sc_l2->sltcv & SLTCV_ENABLE) {
262 uint32_t tagmask = sc->sc_l2->tagmask >> 20;
263 aprint_normal(", %dMB L2 cache", tagmask + 1);
264 }
265 }
266 aprint_normal("\n");
267 }
268
269 void
270 viper_setintrwnd(uint32_t mask)
271 {
272 device_t dv;
273 struct mem_softc *sc;
274
275 dv = device_find_by_driver_unit("mem", 0);
276 sc = device_private(dv);
277
278 if (sc->sc_vp)
279 sc->sc_vp->vi_intrwd;
280 }
281
282 void
283 viper_eisa_en(void)
284 {
285 device_t dv;
286 struct mem_softc *sc;
287
288 dv = device_find_by_driver_unit("mem", 0);
289 sc = device_private(dv);
290
291 if (sc->sc_vp) {
292 int pagezero_cookie;
293 uint32_t vic;
294 int s;
295
296 pagezero_cookie = hppa_pagezero_map();
297 s = splhigh();
298 vic = VI_CTRL;
299 ((struct vi_ctrl *)&vic)->eisa_den = 0;
300 sc->sc_vp->vi_control = vic;
301 __asm __volatile("stwas %1, 0(%0)"
302 :: "r" (&VI_CTRL), "r" (vic) : "memory");
303 splx(s);
304 hppa_pagezero_unmap(pagezero_cookie);
305 }
306 }
307