gten.c revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: gten.c,v 1.2.2.2 2000/12/08 09:30:21 bouyer Exp $ */
2 1.2.2.2 bouyer
3 1.2.2.2 bouyer /*-
4 1.2.2.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.2.2.2 bouyer * All rights reserved.
6 1.2.2.2 bouyer *
7 1.2.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 bouyer * by Matt Thomas <matt (at) 3am-software.com>
9 1.2.2.2 bouyer *
10 1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.2.2.2 bouyer * are met:
13 1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 bouyer * must display the following acknowledgement:
20 1.2.2.2 bouyer * This product includes software developed by the NetBSD
21 1.2.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.2.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.2.2.2 bouyer *
26 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 bouyer */
38 1.2.2.2 bouyer
39 1.2.2.2 bouyer #include <sys/param.h>
40 1.2.2.2 bouyer #include <sys/buf.h>
41 1.2.2.2 bouyer #include <sys/conf.h>
42 1.2.2.2 bouyer #include <sys/device.h>
43 1.2.2.2 bouyer #include <sys/ioctl.h>
44 1.2.2.2 bouyer #include <sys/kernel.h>
45 1.2.2.2 bouyer #include <sys/malloc.h>
46 1.2.2.2 bouyer #include <sys/systm.h>
47 1.2.2.2 bouyer
48 1.2.2.2 bouyer #include <uvm/uvm_extern.h>
49 1.2.2.2 bouyer
50 1.2.2.2 bouyer #include <dev/pci/pcidevs.h>
51 1.2.2.2 bouyer #include <dev/pci/pcireg.h>
52 1.2.2.2 bouyer #include <dev/pci/pcivar.h>
53 1.2.2.2 bouyer
54 1.2.2.2 bouyer #include <dev/wscons/wsconsio.h>
55 1.2.2.2 bouyer #include <dev/wscons/wsdisplayvar.h>
56 1.2.2.2 bouyer #include <dev/rasops/rasops.h>
57 1.2.2.2 bouyer
58 1.2.2.2 bouyer #include <machine/bus.h>
59 1.2.2.2 bouyer #include <machine/gtenvar.h>
60 1.2.2.2 bouyer
61 1.2.2.2 bouyer static int gten_match (struct device *, struct cfdata *, void *);
62 1.2.2.2 bouyer static void gten_attach (struct device *, struct device *, void *);
63 1.2.2.2 bouyer static int gten_print (void *, const char *);
64 1.2.2.2 bouyer
65 1.2.2.2 bouyer struct cfattach gten_ca = {
66 1.2.2.2 bouyer sizeof(struct gten_softc), gten_match, gten_attach,
67 1.2.2.2 bouyer };
68 1.2.2.2 bouyer
69 1.2.2.2 bouyer static struct rasops_info gten_console_ri;
70 1.2.2.2 bouyer static pcitag_t gten_console_pcitag;
71 1.2.2.2 bouyer
72 1.2.2.2 bouyer static struct wsscreen_descr gten_stdscreen = {
73 1.2.2.2 bouyer "std",
74 1.2.2.2 bouyer 0, 0,
75 1.2.2.2 bouyer 0,
76 1.2.2.2 bouyer 0, 0,
77 1.2.2.2 bouyer WSSCREEN_REVERSE
78 1.2.2.2 bouyer };
79 1.2.2.2 bouyer
80 1.2.2.2 bouyer static const struct wsscreen_descr *_gten_scrlist[] = {
81 1.2.2.2 bouyer >en_stdscreen,
82 1.2.2.2 bouyer /* XXX other formats, graphics screen? */
83 1.2.2.2 bouyer };
84 1.2.2.2 bouyer
85 1.2.2.2 bouyer static struct wsscreen_list gten_screenlist = {
86 1.2.2.2 bouyer sizeof(_gten_scrlist) / sizeof(struct wsscreen_descr *), _gten_scrlist
87 1.2.2.2 bouyer };
88 1.2.2.2 bouyer
89 1.2.2.2 bouyer static int gten_ioctl (void *, u_long, caddr_t, int, struct proc *);
90 1.2.2.2 bouyer static paddr_t gten_mmap (void *, off_t, int);
91 1.2.2.2 bouyer static int gten_alloc_screen (void *, const struct wsscreen_descr *,
92 1.2.2.2 bouyer void **, int *, int *, long *);
93 1.2.2.2 bouyer static void gten_free_screen (void *, void *);
94 1.2.2.2 bouyer static int gten_show_screen (void *, void *, int,
95 1.2.2.2 bouyer void (*) (void *, int, int), void *);
96 1.2.2.2 bouyer
97 1.2.2.2 bouyer static struct wsdisplay_accessops gten_accessops = {
98 1.2.2.2 bouyer gten_ioctl,
99 1.2.2.2 bouyer gten_mmap,
100 1.2.2.2 bouyer gten_alloc_screen,
101 1.2.2.2 bouyer gten_free_screen,
102 1.2.2.2 bouyer gten_show_screen,
103 1.2.2.2 bouyer 0 /* load_font */
104 1.2.2.2 bouyer };
105 1.2.2.2 bouyer
106 1.2.2.2 bouyer static void gten_common_init (struct rasops_info *);
107 1.2.2.2 bouyer static int gten_getcmap (struct gten_softc *, struct wsdisplay_cmap *);
108 1.2.2.2 bouyer static int gten_putcmap (struct gten_softc *, struct wsdisplay_cmap *);
109 1.2.2.2 bouyer
110 1.2.2.2 bouyer #define GTEN_VRAM_OFFSET 0xf00000
111 1.2.2.2 bouyer
112 1.2.2.2 bouyer static int
113 1.2.2.2 bouyer gten_match(struct device *parent, struct cfdata *match, void *aux)
114 1.2.2.2 bouyer {
115 1.2.2.2 bouyer struct pci_attach_args *pa = aux;
116 1.2.2.2 bouyer
117 1.2.2.2 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WD &&
118 1.2.2.2 bouyer PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_WD_90C)
119 1.2.2.2 bouyer return 2;
120 1.2.2.2 bouyer
121 1.2.2.2 bouyer return 0;
122 1.2.2.2 bouyer }
123 1.2.2.2 bouyer
124 1.2.2.2 bouyer static void
125 1.2.2.2 bouyer gten_attach(struct device *parent, struct device *self, void *aux)
126 1.2.2.2 bouyer {
127 1.2.2.2 bouyer struct gten_softc *gt = (struct gten_softc *)self;
128 1.2.2.2 bouyer struct pci_attach_args *pa = aux;
129 1.2.2.2 bouyer struct wsemuldisplaydev_attach_args a;
130 1.2.2.2 bouyer int console = (pa->pa_tag == gten_console_pcitag);
131 1.2.2.2 bouyer int error;
132 1.2.2.2 bouyer char devinfo[256], pbuf[10];
133 1.2.2.2 bouyer
134 1.2.2.2 bouyer error = pci_mapreg_info(pa->pa_pc, pa->pa_tag, 0x14,
135 1.2.2.2 bouyer PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
136 1.2.2.2 bouyer >->gt_memaddr, >->gt_memsize, NULL);
137 1.2.2.2 bouyer if (error) {
138 1.2.2.2 bouyer printf(": can't determine memory size: error=%d\n",
139 1.2.2.2 bouyer error);
140 1.2.2.2 bouyer return;
141 1.2.2.2 bouyer }
142 1.2.2.2 bouyer if (console) {
143 1.2.2.2 bouyer gt->gt_ri = >en_console_ri;
144 1.2.2.2 bouyer gt->gt_nscreens = 1;
145 1.2.2.2 bouyer } else {
146 1.2.2.2 bouyer MALLOC(gt->gt_ri, struct rasops_info *, sizeof(*gt->gt_ri),
147 1.2.2.2 bouyer M_DEVBUF, M_NOWAIT);
148 1.2.2.2 bouyer if (gt->gt_ri == NULL) {
149 1.2.2.2 bouyer printf(": can't alloc memory\n");
150 1.2.2.2 bouyer return;
151 1.2.2.2 bouyer }
152 1.2.2.2 bouyer memset(gt->gt_ri, 0, sizeof(*gt->gt_ri));
153 1.2.2.2 bouyer #if 0
154 1.2.2.2 bouyer error = pci_mapreg_map(pa, 0x14,
155 1.2.2.2 bouyer PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
156 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR, NULL,
157 1.2.2.2 bouyer (bus_space_handle_t *) >->gt_ri->ri_bits,
158 1.2.2.2 bouyer NULL, NULL);
159 1.2.2.2 bouyer #else
160 1.2.2.2 bouyer error = bus_space_map(pa->pa_memt, gt->gt_memaddr + GTEN_VRAM_OFFSET,
161 1.2.2.2 bouyer 960*1024, BUS_SPACE_MAP_LINEAR,
162 1.2.2.2 bouyer (bus_space_handle_t *) >->gt_ri->ri_bits);
163 1.2.2.2 bouyer #endif
164 1.2.2.2 bouyer if (error) {
165 1.2.2.2 bouyer printf(": can't map frame buffer: error=%d\n", error);
166 1.2.2.2 bouyer return;
167 1.2.2.2 bouyer }
168 1.2.2.2 bouyer
169 1.2.2.2 bouyer gten_common_init(gt->gt_ri);
170 1.2.2.2 bouyer }
171 1.2.2.2 bouyer
172 1.2.2.2 bouyer gt->gt_paddr = vtophys((vaddr_t)gt->gt_ri->ri_bits);
173 1.2.2.2 bouyer if (gt->gt_paddr == 0) {
174 1.2.2.2 bouyer printf(": cannot map framebuffer\n");
175 1.2.2.2 bouyer return;
176 1.2.2.2 bouyer }
177 1.2.2.2 bouyer gt->gt_psize = gt->gt_memsize - GTEN_VRAM_OFFSET;
178 1.2.2.2 bouyer
179 1.2.2.2 bouyer pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
180 1.2.2.2 bouyer printf(": %s\n", devinfo);
181 1.2.2.2 bouyer format_bytes(pbuf, sizeof(pbuf), gt->gt_psize);
182 1.2.2.2 bouyer printf("%s: %s, %dx%d, %dbpp\n", self->dv_xname, pbuf,
183 1.2.2.2 bouyer gt->gt_ri->ri_width, gt->gt_ri->ri_height,
184 1.2.2.2 bouyer gt->gt_ri->ri_depth);
185 1.2.2.2 bouyer #if defined(DEBUG)
186 1.2.2.2 bouyer printf("%s: text %dx%d, =+%d+%d\n", self->dv_xname,
187 1.2.2.2 bouyer gt->gt_ri->ri_cols, gt->gt_ri->ri_rows,
188 1.2.2.2 bouyer gt->gt_ri->ri_xorigin, gt->gt_ri->ri_yorigin);
189 1.2.2.2 bouyer
190 1.2.2.2 bouyer { int i;
191 1.2.2.2 bouyer struct rasops_info *ri = gt->gt_ri;
192 1.2.2.2 bouyer for (i = 0; i < 64; i++) {
193 1.2.2.2 bouyer int j = i * ri->ri_stride;
194 1.2.2.2 bouyer int k = (ri->ri_height - i - 1) * gt->gt_ri->ri_stride;
195 1.2.2.2 bouyer memset(ri->ri_bits + j, 0, 64 - i);
196 1.2.2.2 bouyer memset(ri->ri_bits + j + 64 - i, 255, i);
197 1.2.2.2 bouyer
198 1.2.2.2 bouyer memset(ri->ri_bits + j + ri->ri_width - 64 + i, 0, 64 - i);
199 1.2.2.2 bouyer memset(ri->ri_bits + j + ri->ri_width - 64, 255, i);
200 1.2.2.2 bouyer
201 1.2.2.2 bouyer memset(ri->ri_bits + k, 0, 64 - i);
202 1.2.2.2 bouyer memset(ri->ri_bits + k + 64 - i, 255, i);
203 1.2.2.2 bouyer
204 1.2.2.2 bouyer memset(ri->ri_bits + k + ri->ri_width - 64 + i, 0, 64 - i);
205 1.2.2.2 bouyer memset(ri->ri_bits + k + ri->ri_width - 64, 255, i);
206 1.2.2.2 bouyer }}
207 1.2.2.2 bouyer #endif
208 1.2.2.2 bouyer
209 1.2.2.2 bouyer gt->gt_cmap_red[0] = gt->gt_cmap_green[0] = gt->gt_cmap_blue[0] = 0;
210 1.2.2.2 bouyer gt->gt_cmap_red[15] = gt->gt_cmap_red[255] = 0xff;
211 1.2.2.2 bouyer gt->gt_cmap_green[15] = gt->gt_cmap_green[255] = 0xff;
212 1.2.2.2 bouyer gt->gt_cmap_blue[15] = gt->gt_cmap_blue[255] = 0xff;
213 1.2.2.2 bouyer
214 1.2.2.2 bouyer a.console = console;
215 1.2.2.2 bouyer a.scrdata = >en_screenlist;
216 1.2.2.2 bouyer a.accessops = >en_accessops;
217 1.2.2.2 bouyer a.accesscookie = gt;
218 1.2.2.2 bouyer
219 1.2.2.2 bouyer config_found(self, &a, wsemuldisplaydevprint);
220 1.2.2.2 bouyer }
221 1.2.2.2 bouyer
222 1.2.2.2 bouyer static void
223 1.2.2.2 bouyer gten_common_init(struct rasops_info *ri)
224 1.2.2.2 bouyer {
225 1.2.2.2 bouyer int32_t addr, width, height, linebytes, depth;
226 1.2.2.2 bouyer int i, screenbytes;
227 1.2.2.2 bouyer
228 1.2.2.2 bouyer /* initialize rasops */
229 1.2.2.2 bouyer ri->ri_width = 640;
230 1.2.2.2 bouyer ri->ri_height = 480;
231 1.2.2.2 bouyer ri->ri_depth = 8;
232 1.2.2.2 bouyer ri->ri_stride = 640;
233 1.2.2.2 bouyer ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR;
234 1.2.2.2 bouyer
235 1.2.2.2 bouyer rasops_init(ri, 30, 80);
236 1.2.2.2 bouyer /* black on white */
237 1.2.2.2 bouyer ri->ri_devcmap[0] = 0xffffffff; /* bg */
238 1.2.2.2 bouyer ri->ri_devcmap[1] = 0; /* fg */
239 1.2.2.2 bouyer
240 1.2.2.2 bouyer memset(ri->ri_bits, 0xff, ri->ri_stride * ri->ri_height);
241 1.2.2.2 bouyer
242 1.2.2.2 bouyer gten_stdscreen.nrows = ri->ri_rows;
243 1.2.2.2 bouyer gten_stdscreen.ncols = ri->ri_cols;
244 1.2.2.2 bouyer gten_stdscreen.textops = &ri->ri_ops;
245 1.2.2.2 bouyer gten_stdscreen.capabilities = ri->ri_caps;
246 1.2.2.2 bouyer }
247 1.2.2.2 bouyer
248 1.2.2.2 bouyer static int
249 1.2.2.2 bouyer gten_ioctl(v, cmd, data, flag, p)
250 1.2.2.2 bouyer void *v;
251 1.2.2.2 bouyer u_long cmd;
252 1.2.2.2 bouyer caddr_t data;
253 1.2.2.2 bouyer int flag;
254 1.2.2.2 bouyer struct proc *p;
255 1.2.2.2 bouyer {
256 1.2.2.2 bouyer struct gten_softc *gt = v;
257 1.2.2.2 bouyer struct wsdisplay_fbinfo *wdf;
258 1.2.2.2 bouyer struct grfinfo *gm;
259 1.2.2.2 bouyer
260 1.2.2.2 bouyer switch (cmd) {
261 1.2.2.2 bouyer case WSDISPLAYIO_GTYPE:
262 1.2.2.2 bouyer *(u_int *)data = WSDISPLAY_TYPE_PCIMISC; /* XXX ? */
263 1.2.2.2 bouyer return 0;
264 1.2.2.2 bouyer
265 1.2.2.2 bouyer case WSDISPLAYIO_GINFO:
266 1.2.2.2 bouyer wdf = (void *)data;
267 1.2.2.2 bouyer wdf->height = gt->gt_ri->ri_height;
268 1.2.2.2 bouyer wdf->width = gt->gt_ri->ri_width;
269 1.2.2.2 bouyer wdf->depth = gt->gt_ri->ri_depth;
270 1.2.2.2 bouyer wdf->cmsize = 256;
271 1.2.2.2 bouyer return 0;
272 1.2.2.2 bouyer
273 1.2.2.2 bouyer case WSDISPLAYIO_GETCMAP:
274 1.2.2.2 bouyer return gten_getcmap(gt, (struct wsdisplay_cmap *)data);
275 1.2.2.2 bouyer
276 1.2.2.2 bouyer case WSDISPLAYIO_PUTCMAP:
277 1.2.2.2 bouyer return gten_putcmap(gt, (struct wsdisplay_cmap *)data);
278 1.2.2.2 bouyer }
279 1.2.2.2 bouyer return -1;
280 1.2.2.2 bouyer }
281 1.2.2.2 bouyer
282 1.2.2.2 bouyer static paddr_t
283 1.2.2.2 bouyer gten_mmap(v, offset, prot)
284 1.2.2.2 bouyer void *v;
285 1.2.2.2 bouyer off_t offset;
286 1.2.2.2 bouyer int prot;
287 1.2.2.2 bouyer {
288 1.2.2.2 bouyer struct gten_softc *gt = v;
289 1.2.2.2 bouyer
290 1.2.2.2 bouyer if (offset >= 0 && offset < gt->gt_psize)
291 1.2.2.2 bouyer return gt->gt_paddr + offset;
292 1.2.2.2 bouyer if (offset >= 0x1000000 && offset < gt->gt_memsize)
293 1.2.2.2 bouyer return gt->gt_memaddr + offset - 0x1000000;
294 1.2.2.2 bouyer
295 1.2.2.2 bouyer return -1;
296 1.2.2.2 bouyer }
297 1.2.2.2 bouyer
298 1.2.2.2 bouyer static int
299 1.2.2.2 bouyer gten_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
300 1.2.2.2 bouyer void *v;
301 1.2.2.2 bouyer const struct wsscreen_descr *type;
302 1.2.2.2 bouyer void **cookiep;
303 1.2.2.2 bouyer int *curxp, *curyp;
304 1.2.2.2 bouyer long *attrp;
305 1.2.2.2 bouyer {
306 1.2.2.2 bouyer struct gten_softc *gt = v;
307 1.2.2.2 bouyer struct rasops_info *ri = gt->gt_ri;
308 1.2.2.2 bouyer long defattr;
309 1.2.2.2 bouyer
310 1.2.2.2 bouyer if (gt->gt_nscreens > 0)
311 1.2.2.2 bouyer return (ENOMEM);
312 1.2.2.2 bouyer
313 1.2.2.2 bouyer *cookiep = ri; /* one and only for now */
314 1.2.2.2 bouyer *curxp = 0;
315 1.2.2.2 bouyer *curyp = 0;
316 1.2.2.2 bouyer (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
317 1.2.2.2 bouyer *attrp = defattr;
318 1.2.2.2 bouyer gt->gt_nscreens++;
319 1.2.2.2 bouyer return 0;
320 1.2.2.2 bouyer }
321 1.2.2.2 bouyer
322 1.2.2.2 bouyer static void
323 1.2.2.2 bouyer gten_free_screen(v, cookie)
324 1.2.2.2 bouyer void *v;
325 1.2.2.2 bouyer void *cookie;
326 1.2.2.2 bouyer {
327 1.2.2.2 bouyer struct gten_softc *gt = v;
328 1.2.2.2 bouyer
329 1.2.2.2 bouyer if (gt->gt_ri == >en_console_ri)
330 1.2.2.2 bouyer panic("gten_free_screen: console");
331 1.2.2.2 bouyer
332 1.2.2.2 bouyer gt->gt_nscreens--;
333 1.2.2.2 bouyer }
334 1.2.2.2 bouyer
335 1.2.2.2 bouyer static int
336 1.2.2.2 bouyer gten_show_screen(v, cookie, waitok, cb, cbarg)
337 1.2.2.2 bouyer void *v;
338 1.2.2.2 bouyer void *cookie;
339 1.2.2.2 bouyer int waitok;
340 1.2.2.2 bouyer void (*cb) (void *, int, int);
341 1.2.2.2 bouyer void *cbarg;
342 1.2.2.2 bouyer {
343 1.2.2.2 bouyer return (0);
344 1.2.2.2 bouyer }
345 1.2.2.2 bouyer
346 1.2.2.2 bouyer int
347 1.2.2.2 bouyer gten_cnattach(bus_space_tag_t memt)
348 1.2.2.2 bouyer {
349 1.2.2.2 bouyer struct rasops_info *ri = >en_console_ri;
350 1.2.2.2 bouyer u_int32_t mapreg, id, mask, mapsize;
351 1.2.2.2 bouyer long defattr;
352 1.2.2.2 bouyer pcitag_t tag;
353 1.2.2.2 bouyer int s, error;
354 1.2.2.2 bouyer bus_size_t bussize;
355 1.2.2.2 bouyer bus_addr_t busaddr;
356 1.2.2.2 bouyer
357 1.2.2.2 bouyer tag = pci_make_tag(NULL, 0, 14, 0);
358 1.2.2.2 bouyer
359 1.2.2.2 bouyer id = pci_conf_read(NULL, tag, PCI_ID_REG);
360 1.2.2.2 bouyer if (PCI_VENDOR(id) != PCI_VENDOR_WD ||
361 1.2.2.2 bouyer PCI_PRODUCT(id) != PCI_PRODUCT_WD_90C)
362 1.2.2.2 bouyer return ENXIO;
363 1.2.2.2 bouyer
364 1.2.2.2 bouyer mapreg = pci_conf_read(NULL, tag, 0x14);
365 1.2.2.2 bouyer if (PCI_MAPREG_TYPE(mapreg) != PCI_MAPREG_TYPE_MEM ||
366 1.2.2.2 bouyer PCI_MAPREG_MEM_TYPE(mapreg) != PCI_MAPREG_MEM_TYPE_32BIT)
367 1.2.2.2 bouyer return ENXIO;
368 1.2.2.2 bouyer
369 1.2.2.2 bouyer s = splhigh();
370 1.2.2.2 bouyer pci_conf_write(NULL, tag, 0x14, 0xffffffff);
371 1.2.2.2 bouyer mask = pci_conf_read(NULL, tag, 0x14);
372 1.2.2.2 bouyer pci_conf_write(NULL, tag, 0x14, mapreg);
373 1.2.2.2 bouyer splx(s);
374 1.2.2.2 bouyer bussize = PCI_MAPREG_MEM_SIZE(mask);
375 1.2.2.2 bouyer busaddr = PCI_MAPREG_MEM_ADDR(mapreg);
376 1.2.2.2 bouyer
377 1.2.2.2 bouyer error = bus_space_map(memt, busaddr + GTEN_VRAM_OFFSET, 960*1024,
378 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR, (bus_space_handle_t *) &ri->ri_bits);
379 1.2.2.2 bouyer if (error)
380 1.2.2.2 bouyer return error;
381 1.2.2.2 bouyer
382 1.2.2.2 bouyer gten_common_init(ri);
383 1.2.2.2 bouyer
384 1.2.2.2 bouyer (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
385 1.2.2.2 bouyer wsdisplay_cnattach(>en_stdscreen, ri, 0, 0, defattr);
386 1.2.2.2 bouyer
387 1.2.2.2 bouyer gten_console_pcitag = tag;
388 1.2.2.2 bouyer
389 1.2.2.2 bouyer return 0;
390 1.2.2.2 bouyer }
391 1.2.2.2 bouyer
392 1.2.2.2 bouyer static int
393 1.2.2.2 bouyer gten_getcmap(gt, cm)
394 1.2.2.2 bouyer struct gten_softc *gt;
395 1.2.2.2 bouyer struct wsdisplay_cmap *cm;
396 1.2.2.2 bouyer {
397 1.2.2.2 bouyer u_int index = cm->index;
398 1.2.2.2 bouyer u_int count = cm->count;
399 1.2.2.2 bouyer int error;
400 1.2.2.2 bouyer
401 1.2.2.2 bouyer if (index >= 256 || count > 256 || index + count > 256)
402 1.2.2.2 bouyer return EINVAL;
403 1.2.2.2 bouyer
404 1.2.2.2 bouyer error = copyout(>->gt_cmap_red[index], cm->red, count);
405 1.2.2.2 bouyer if (error)
406 1.2.2.2 bouyer return error;
407 1.2.2.2 bouyer error = copyout(>->gt_cmap_green[index], cm->green, count);
408 1.2.2.2 bouyer if (error)
409 1.2.2.2 bouyer return error;
410 1.2.2.2 bouyer error = copyout(>->gt_cmap_blue[index], cm->blue, count);
411 1.2.2.2 bouyer if (error)
412 1.2.2.2 bouyer return error;
413 1.2.2.2 bouyer
414 1.2.2.2 bouyer return 0;
415 1.2.2.2 bouyer }
416 1.2.2.2 bouyer
417 1.2.2.2 bouyer static int
418 1.2.2.2 bouyer gten_putcmap(gt, cm)
419 1.2.2.2 bouyer struct gten_softc *gt;
420 1.2.2.2 bouyer struct wsdisplay_cmap *cm;
421 1.2.2.2 bouyer {
422 1.2.2.2 bouyer int index = cm->index;
423 1.2.2.2 bouyer int count = cm->count;
424 1.2.2.2 bouyer int i;
425 1.2.2.2 bouyer u_char *r, *g, *b;
426 1.2.2.2 bouyer
427 1.2.2.2 bouyer if (cm->index >= 256 || cm->count > 256 ||
428 1.2.2.2 bouyer (cm->index + cm->count) > 256)
429 1.2.2.2 bouyer return EINVAL;
430 1.2.2.2 bouyer if (!uvm_useracc(cm->red, cm->count, B_READ) ||
431 1.2.2.2 bouyer !uvm_useracc(cm->green, cm->count, B_READ) ||
432 1.2.2.2 bouyer !uvm_useracc(cm->blue, cm->count, B_READ))
433 1.2.2.2 bouyer return EFAULT;
434 1.2.2.2 bouyer copyin(cm->red, >->gt_cmap_red[index], count);
435 1.2.2.2 bouyer copyin(cm->green, >->gt_cmap_green[index], count);
436 1.2.2.2 bouyer copyin(cm->blue, >->gt_cmap_blue[index], count);
437 1.2.2.2 bouyer
438 1.2.2.2 bouyer r = >->gt_cmap_red[index];
439 1.2.2.2 bouyer g = >->gt_cmap_green[index];
440 1.2.2.2 bouyer b = >->gt_cmap_blue[index];
441 1.2.2.2 bouyer
442 1.2.2.2 bouyer #if 0
443 1.2.2.2 bouyer for (i = 0; i < count; i++) {
444 1.2.2.2 bouyer OF_call_method_1("color!", dc->dc_ih, 4, *r, *g, *b, index);
445 1.2.2.2 bouyer r++, g++, b++, index++;
446 1.2.2.2 bouyer }
447 1.2.2.2 bouyer #endif
448 1.2.2.2 bouyer
449 1.2.2.2 bouyer return 0;
450 1.2.2.2 bouyer }
451