1 /* $NetBSD: view.c,v 1.28 2009/03/18 17:06:42 cegger Exp $ */
4 * Copyright (c) 1994 Christian E. Hopps
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christian E. Hopps.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* The view major device is a placeholder device. It serves
34 * simply to map the semantics of a graphics dipslay to
35 * the semantics of a character block device. In other
36 * words the graphics system as currently built does not like to be
37 * refered to by open/close/ioctl. This device serves as
38 * a interface to graphics. */
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: view.c,v 1.28 2009/03/18 17:06:42 cegger Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/ioctl.h>
48 #include <sys/device.h>
49 #include <sys/malloc.h>
50 #include <sys/queue.h>
52 #include <machine/cpu.h>
53 #include <amiga/dev/grfabs_reg.h>
54 #include <amiga/dev/viewioctl.h>
55 #include <amiga/dev/viewvar.h>
59 static void view_display(struct view_softc
*);
60 static void view_remove(struct view_softc
*);
61 static int view_setsize(struct view_softc
*, struct view_size
*);
63 int view_get_colormap(struct view_softc
*, colormap_t
*);
64 int view_set_colormap(struct view_softc
*, colormap_t
*);
68 struct view_softc views
[NVIEW
];
69 int view_inited
; /* also checked in ite_cc.c */
73 int view_default_width
= 640;
74 int view_default_height
= 400;
75 int view_default_depth
= 2;
77 dev_type_open(viewopen
);
78 dev_type_close(viewclose
);
79 dev_type_ioctl(viewioctl
);
80 dev_type_mmap(viewmmap
);
82 const struct cdevsw view_cdevsw
= {
83 viewopen
, viewclose
, nullread
, nullwrite
, viewioctl
,
84 nostop
, notty
, nopoll
, viewmmap
, nokqfilter
,
88 * functions for probeing.
95 printf("%d view%s configured\n", NVIEW
, NVIEW
> 1 ? "s" : "");
98 /* this function is called early to set up a display. */
109 for (i
=0; i
<NVIEW
; i
++) {
110 views
[i
].view
= NULL
;
118 * Internal functions.
122 view_display(struct view_softc
*vu
)
132 * mark views that share this monitor as not displaying
134 for (i
=0; i
<NVIEW
; i
++) {
135 if ((views
[i
].flags
& VUF_DISPLAY
) &&
136 views
[i
].monitor
== vu
->monitor
)
137 views
[i
].flags
&= ~VUF_DISPLAY
;
140 vu
->flags
|= VUF_ADDED
;
142 vu
->view
->display
.x
= vu
->size
.x
;
143 vu
->view
->display
.y
= vu
->size
.y
;
145 grf_display_view(vu
->view
);
147 vu
->size
.x
= vu
->view
->display
.x
;
148 vu
->size
.y
= vu
->view
->display
.y
;
149 vu
->flags
|= VUF_DISPLAY
;
155 * remove a view from our added list if it is marked as displaying
156 * switch to a new display.
159 view_remove(struct view_softc
*vu
)
163 if ((vu
->flags
& VUF_ADDED
) == 0)
166 vu
->flags
&= ~VUF_ADDED
;
167 if (vu
->flags
& VUF_DISPLAY
) {
168 for (i
= 0; i
< NVIEW
; i
++) {
169 if ((views
[i
].flags
& VUF_ADDED
) && &views
[i
] != vu
&&
170 views
[i
].monitor
== vu
->monitor
) {
171 view_display(&views
[i
]);
176 vu
->flags
&= ~VUF_DISPLAY
;
177 grf_remove_view(vu
->view
);
181 view_setsize(struct view_softc
*vu
, struct view_size
*vs
)
189 if (vs
->x
!= vu
->size
.x
|| vs
->y
!= vu
->size
.y
)
192 if (vs
->width
!= vu
->size
.width
|| vs
->height
!= vu
->size
.height
||
193 vs
->depth
!= vu
->size
.depth
)
196 if (cs
== 0 && co
== 0)
199 ns
.width
= vs
->width
;
200 ns
.height
= vs
->height
;
202 new = grf_alloc_view(NULL
, &ns
, vs
->depth
);
208 vu
->size
.x
= new->display
.x
;
209 vu
->size
.y
= new->display
.y
;
210 vu
->size
.width
= new->display
.width
;
211 vu
->size
.height
= new->display
.height
;
212 vu
->size
.depth
= new->bitmap
->depth
;
213 vu
->mode
= grf_get_display_mode(vu
->view
);
214 vu
->monitor
= grf_get_monitor(vu
->mode
);
219 * we need a custom remove here to avoid letting
220 * another view display mark as not added or displayed
222 if (vu
->flags
& VUF_DISPLAY
) {
223 vu
->flags
&= ~(VUF_ADDED
|VUF_DISPLAY
);
231 * functions made available by conf.c
236 viewopen(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
239 struct view_softc
*vu
;
241 vu
= &views
[minor(dev
)];
243 if (minor(dev
) >= NVIEW
)
246 if (vu
->flags
& VUF_OPEN
)
249 vu
->size
.x
= view_default_x
;
250 vu
->size
.y
= view_default_y
;
251 size
.width
= vu
->size
.width
= view_default_width
;
252 size
.height
= vu
->size
.height
= view_default_height
;
253 vu
->size
.depth
= view_default_depth
;
255 vu
->view
= grf_alloc_view(NULL
, &size
, vu
->size
.depth
);
256 if (vu
->view
== NULL
)
259 vu
->size
.x
= vu
->view
->display
.x
;
260 vu
->size
.y
= vu
->view
->display
.y
;
261 vu
->size
.width
= vu
->view
->display
.width
;
262 vu
->size
.height
= vu
->view
->display
.height
;
263 vu
->size
.depth
= vu
->view
->bitmap
->depth
;
264 vu
->flags
|= VUF_OPEN
;
265 vu
->mode
= grf_get_display_mode(vu
->view
);
266 vu
->monitor
= grf_get_monitor(vu
->mode
);
272 viewclose(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
274 struct view_softc
*vu
;
276 vu
= &views
[minor(dev
)];
278 if ((vu
->flags
& VUF_OPEN
) == 0)
281 grf_free_view (vu
->view
);
292 viewioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
294 struct view_softc
*vu
;
298 vu
= &views
[minor(dev
)];
309 memcpy(data
, &vu
->size
, sizeof (struct view_size
));
312 error
= view_setsize(vu
, (struct view_size
*)data
);
316 memcpy(bm
, vu
->view
->bitmap
, sizeof(bmap_t
));
320 bm
->hardware_address
= 0;
324 error
= view_get_colormap(vu
, (colormap_t
*)data
);
327 error
= view_set_colormap(vu
, (colormap_t
*)data
);
330 error
= EPASSTHROUGH
;
337 view_get_colormap(struct view_softc
*vu
, colormap_t
*ucm
)
343 /* add one incase of zero, ick. */
344 if (ucm
->size
+ 1 > SIZE_T_MAX
/ sizeof(u_long
))
346 cme
= malloc(sizeof (u_long
)*(ucm
->size
+ 1), M_TEMP
, M_WAITOK
);
352 ucm
->entry
= cme
; /* set entry to out alloc. */
353 if (vu
->view
== NULL
|| grf_get_colormap(vu
->view
, ucm
))
356 error
= copyout(cme
, uep
, sizeof(u_long
) * ucm
->size
);
357 ucm
->entry
= uep
; /* set entry back to users. */
363 view_set_colormap(struct view_softc
*vu
, colormap_t
*ucm
)
369 cm
= malloc(sizeof(u_long
) * ucm
->size
+ sizeof (*cm
), M_TEMP
,
374 bcopy (ucm
, cm
, sizeof(colormap_t
));
375 cm
->entry
= (u_long
*)&cm
[1]; /* table directly after. */
377 copyin(ucm
->entry
, cm
->entry
, sizeof (u_long
) * ucm
->size
)) == 0)
378 && (vu
->view
== NULL
|| grf_use_colormap(vu
->view
, cm
)))
386 viewmmap(dev_t dev
, off_t off
, int prot
)
388 struct view_softc
*vu
;
393 vu
= &views
[minor(dev
)];
394 bm
= vu
->view
->bitmap
;
395 bmd_start
= bm
->hardware_address
;
396 bmd_size
= bm
->bytes_per_row
*bm
->rows
*bm
->depth
;
398 if (off
>= 0 && off
< bmd_size
)
399 return(((paddr_t
)bmd_start
+ off
) >> PGSHIFT
);