1 /* $NetBSD: grf.c,v 1.51 2009/03/18 17:06:41 cegger Exp $ */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * from: Utah $Hdr: grf.c 1.31 91/01/21$
37 * @(#)grf.c 7.8 (Berkeley) 5/7/91
40 * Copyright (c) 1988 University of Utah.
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * from: Utah $Hdr: grf.c 1.31 91/01/21$
76 * @(#)grf.c 7.8 (Berkeley) 5/7/91
79 #include <sys/cdefs.h>
80 __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.51 2009/03/18 17:06:41 cegger Exp $");
83 * Graphics display driver for the Amiga
84 * This is the hardware-independent portion of the driver.
85 * Hardware access is through the grf_softc->g_mode routine.
88 #include <sys/param.h>
90 #include <sys/ioctl.h>
91 #include <sys/device.h>
93 #include <sys/malloc.h>
94 #include <sys/systm.h>
95 #include <sys/vnode.h>
97 #include <uvm/uvm_extern.h>
98 #include <machine/cpu.h>
99 #include <dev/sun/fbio.h>
100 #include <amiga/amiga/color.h> /* DEBUG */
101 #include <amiga/amiga/device.h>
102 #include <amiga/dev/grfioctl.h>
103 #include <amiga/dev/grfvar.h>
104 #include <amiga/dev/itevar.h>
105 #include <amiga/dev/viewioctl.h>
107 #include <sys/conf.h>
117 #define ite_reinit(d)
122 int grfsinfo(dev_t
, struct grfdyninfo
*);
124 void grfattach(struct device
*, struct device
*, void *);
125 int grfmatch(struct device
*, struct cfdata
*, void *);
126 int grfprint(void *, const char *);
128 * pointers to grf drivers device structs
130 struct grf_softc
*grfsp
[NGRF
];
132 CFATTACH_DECL(grf
, sizeof(struct device
),
133 grfmatch
, grfattach
, NULL
, NULL
);
135 dev_type_open(grfopen
);
136 dev_type_close(grfclose
);
137 dev_type_ioctl(grfioctl
);
138 dev_type_mmap(grfmmap
);
140 const struct cdevsw grf_cdevsw
= {
141 grfopen
, grfclose
, nullread
, nullwrite
, grfioctl
,
142 nostop
, notty
, nopoll
, grfmmap
, nokqfilter
,
146 * only used in console init.
148 static struct cfdata
*cfdata
;
151 * match if the unit of grf matches its perspective
152 * low level board driver.
155 grfmatch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
158 if (cfp
->cf_unit
!= ((struct grf_softc
*)pdp
)->g_unit
)
165 * attach.. plug pointer in and print some info.
166 * then try and attach an ite to us. note: dp is NULL
167 * durring console init.
170 grfattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
172 struct grf_softc
*gp
;
175 gp
= (struct grf_softc
*)pdp
;
176 grfsp
[gp
->g_unit
] = (struct grf_softc
*)pdp
;
179 * find our major device number
181 maj
= cdevsw_lookup_major(&grf_cdevsw
);
183 gp
->g_grfdev
= makedev(maj
, gp
->g_unit
);
185 printf(": width %d height %d", gp
->g_display
.gd_dwidth
,
186 gp
->g_display
.gd_dheight
);
187 if (gp
->g_display
.gd_colors
== 2)
188 printf(" monochrome\n");
190 printf(" colors %d\n", gp
->g_display
.gd_colors
);
194 * try and attach an ite
196 amiga_config_found(cfdata
, dp
, gp
, grfprint
);
200 grfprint(void *auxp
, const char *pnp
)
203 aprint_normal("ite at %s", pnp
);
209 grfopen(dev_t dev
, int flags
, int devtype
, struct lwp
*l
)
211 struct grf_softc
*gp
;
213 if (GRFUNIT(dev
) >= NGRF
|| (gp
= grfsp
[GRFUNIT(dev
)]) == NULL
)
216 if ((gp
->g_flags
& GF_ALIVE
) == 0)
219 if ((gp
->g_flags
& (GF_OPEN
|GF_EXCLUDE
)) == (GF_OPEN
|GF_EXCLUDE
))
227 grfclose(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
229 struct grf_softc
*gp
;
231 gp
= grfsp
[GRFUNIT(dev
)];
233 gp
->g_flags
&= GF_ALIVE
;
239 grfioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
241 struct grf_softc
*gp
;
244 gp
= grfsp
[GRFUNIT(dev
)];
249 /* argl.. no bank-member.. */
250 memcpy(data
, (void *)&gp
->g_display
, sizeof(struct grfinfo
)-4);
253 memcpy(data
, (void *)&gp
->g_display
, sizeof(struct grfinfo
));
262 error
= grfsinfo(dev
, (struct grfdyninfo
*) data
);
265 return(gp
->g_mode(gp
, GM_GRFGETVMODE
, data
, 0, 0));
267 error
= gp
->g_mode(gp
, GM_GRFSETVMODE
, data
, 0, 0);
268 if (error
== 0 && gp
->g_itedev
&& !(gp
->g_flags
& GF_GRFON
))
269 ite_reinit(gp
->g_itedev
);
272 return(gp
->g_mode(gp
, GM_GRFGETNUMVM
, data
, 0, 0));
274 * these are all hardware dependant, and have to be resolved
275 * in the respective driver.
279 case GRFIOCSSPRITEPOS
:
280 case GRFIOCGSPRITEPOS
:
281 case GRFIOCSSPRITEINF
:
282 case GRFIOCGSPRITEINF
:
283 case GRFIOCGSPRITEMAX
:
286 case GRFTOGGLE
: /* Toggles between Cirrus boards and native ECS on
287 Amiga. 15/11/94 ill */
289 * We need the minor dev number to get the overlay/image
290 * information for grf_ul.
292 return(gp
->g_mode(gp
, GM_GRFIOCTL
, data
, cmd
, dev
));
294 case GRFIOCBLANK
: /* blank ioctl, IOCON/OFF will turn ite on */
296 error
= gp
->g_mode(gp
, GM_GRFIOCTL
, data
, GRFIOCBLANK
, dev
);
298 gp
->g_blank
= *(int *)data
;
302 *(int *)data
= gp
->g_blank
;
308 * check to see whether it's a command recognized by the
309 * view code if the unit is 0
312 if (GRFUNIT(dev
) == 0) {
313 extern const struct cdevsw view_cdevsw
;
315 return((*view_cdevsw
.d_ioctl
)(dev
, cmd
, data
, flag
, l
));
318 error
= EPASSTHROUGH
;
326 * map the contents of a graphics display card into process'
330 grfmmap(dev_t dev
, off_t off
, int prot
)
332 struct grf_softc
*gp
;
335 gp
= grfsp
[GRFUNIT(dev
)];
341 if (off
>= 0 && off
< gi
->gd_regsize
)
342 return(((paddr_t
)gi
->gd_regaddr
+ off
) >> PGSHIFT
);
347 if (off
>= gi
->gd_regsize
&& off
< gi
->gd_regsize
+gi
->gd_fbsize
) {
348 off
-= gi
->gd_regsize
;
349 return(((paddr_t
)gi
->gd_fbaddr
+ off
) >> PGSHIFT
);
358 struct grf_softc
*gp
;
360 gp
= grfsp
[GRFUNIT(dev
)];
362 if (gp
->g_flags
& GF_GRFON
)
365 gp
->g_flags
|= GF_GRFON
;
366 if (gp
->g_itedev
!= NODEV
)
367 ite_off(gp
->g_itedev
, 3);
369 return(gp
->g_mode(gp
, (dev
& GRFOVDEV
) ? GM_GRFOVON
: GM_GRFON
,
376 struct grf_softc
*gp
;
379 gp
= grfsp
[GRFUNIT(dev
)];
381 if ((gp
->g_flags
& GF_GRFON
) == 0)
384 gp
->g_flags
&= ~GF_GRFON
;
385 error
= gp
->g_mode(gp
, (dev
& GRFOVDEV
) ? GM_GRFOVOFF
: GM_GRFOFF
,
389 * Closely tied together no X's
391 if (gp
->g_itedev
!= NODEV
)
392 ite_on(gp
->g_itedev
, 2);
398 grfsinfo(dev_t dev
, struct grfdyninfo
*dyninfo
)
400 struct grf_softc
*gp
;
403 gp
= grfsp
[GRFUNIT(dev
)];
404 error
= gp
->g_mode(gp
, GM_GRFCONFIG
, dyninfo
, 0, 0);
407 * Closely tied together no X's
409 if (gp
->g_itedev
!= NODEV
)
410 ite_reinit(gp
->g_itedev
);
414 #endif /* NGRF > 0 */