1 /* $NetBSD: grf.c,v 1.65 2008/06/13 09:41:15 cegger Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
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.36 93/08/13$
37 * @(#)grf.c 8.4 (Berkeley) 1/12/94
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.36 93/08/13$
76 * @(#)grf.c 8.4 (Berkeley) 1/12/94
80 * Graphics display driver for HP 300/400/700/800 machines.
81 * This is the hardware-independent portion of the driver.
82 * Hardware access is through the machine dependent grf switch routines.
85 #include <sys/cdefs.h>
86 __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.65 2008/06/13 09:41:15 cegger Exp $");
88 #include <sys/param.h>
89 #include <sys/systm.h>
91 #include <sys/device.h>
93 #include <sys/ioctl.h>
94 #include <sys/malloc.h>
97 #include <sys/vnode.h>
98 #include <sys/resourcevar.h>
100 #include <machine/autoconf.h>
101 #include <machine/cpu.h>
103 #include <hp300/dev/intioreg.h>
104 #include <hp300/dev/grfioctl.h>
105 #include <hp300/dev/grfvar.h>
106 #include <hp300/dev/grfreg.h>
108 #include <uvm/uvm_extern.h>
109 #include <uvm/uvm_map.h>
111 #include <miscfs/specfs/specdev.h>
115 #include <hp300/dev/itevar.h>
117 #define iteon(u,f) 0 /* noramlly returns int */
119 #endif /* NITE > 0 */
123 static int grfmatch(device_t
, cfdata_t
, void *);
124 static void grfattach(device_t
, device_t
, void *);
126 CFATTACH_DECL_NEW(grf
, sizeof(struct grf_softc
),
127 grfmatch
, grfattach
, NULL
, NULL
);
129 static dev_type_open(grfopen
);
130 static dev_type_close(grfclose
);
131 static dev_type_ioctl(grfioctl
);
132 static dev_type_mmap(grfmmap
);
134 const struct cdevsw grf_cdevsw
= {
135 grfopen
, grfclose
, nullread
, nullwrite
, grfioctl
,
136 nostop
, notty
, nopoll
, grfmmap
, nokqfilter
,
139 static int grfprint(void *, const char *);
142 * Frambuffer state information, statically allocated for benefit
145 struct grf_data grf_cn
;
149 #define GDB_DEVNO 0x01
150 #define GDB_MMAP 0x02
151 #define GDB_IOMAP 0x04
152 #define GDB_LOCK 0x08
156 grfmatch(device_t parent
, cfdata_t cf
, void *aux
)
163 grfattach(device_t parent
, device_t self
, void *aux
)
165 struct grf_softc
*sc
= device_private(self
);
166 struct grfdev_attach_args
*ga
= aux
;
171 sc
->sc_data
= ga
->ga_data
;
172 sc
->sc_scode
= ga
->ga_scode
; /* XXX */
175 (void)config_found(self
, aux
, grfprint
);
179 grfprint(void *aux
, const char *pnp
)
182 /* Only ITEs can attach to GRFs, easy... */
184 aprint_normal("ite at %s", pnp
);
191 grfopen(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
193 struct grf_softc
*sc
;
197 sc
= device_lookup_private(&grf_cd
, GRFUNIT(dev
));
203 if ((gp
->g_flags
& GF_ALIVE
) == 0)
206 if ((gp
->g_flags
& (GF_OPEN
|GF_EXCLUDE
)) == (GF_OPEN
|GF_EXCLUDE
))
210 * XXX: always put in graphics mode.
213 if ((gp
->g_flags
& GF_OPEN
) == 0) {
214 gp
->g_flags
|= GF_OPEN
;
222 grfclose(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
224 struct grf_softc
*sc
;
227 sc
= device_lookup_private(&grf_cd
, GRFUNIT(dev
));
231 if ((gp
->g_flags
& GF_ALIVE
) == 0)
235 gp
->g_flags
&= GF_ALIVE
;
241 grfioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
243 struct grf_softc
*sc
;
247 sc
= device_lookup_private(&grf_cd
, GRFUNIT(dev
));
251 if ((gp
->g_flags
& GF_ALIVE
) == 0)
258 memcpy(data
, (void *)&gp
->g_display
, sizeof(struct grfinfo
));
270 error
= grfmap(dev
, (void **)data
, l
->l_proc
);
274 error
= grfunmap(dev
, *(void **)data
, l
->l_proc
);
287 grfmmap(dev_t dev
, off_t off
, int prot
)
289 struct grf_softc
*sc
= device_lookup_private(&grf_cd
,GRFUNIT(dev
));
291 return grfaddr(sc
, off
);
295 grfon(dev_t dev
/*XXX*/)
297 struct grf_softc
*sc
;
300 sc
= device_lookup_private(&grf_cd
, GRFUNIT(dev
));
304 * XXX: iteoff call relies on devices being in same order
305 * as ITEs and the fact that iteoff only uses the minor part
308 iteoff(sc
->sc_ite
->sc_data
, 3);
309 return (*gp
->g_sw
->gd_mode
)(gp
,
310 (dev
& GRFOVDEV
) ? GM_GRFOVON
: GM_GRFON
, (void *)0);
314 grfoff(dev_t dev
/*XXX*/)
316 struct grf_softc
*sc
;
320 sc
= device_lookup_private(&grf_cd
, GRFUNIT(dev
));
323 (void) grfunmap(dev
, (void *)0, curproc
);
324 error
= (*gp
->g_sw
->gd_mode
)(gp
,
325 (dev
&GRFOVDEV
) ? GM_GRFOVOFF
: GM_GRFOFF
,
327 /* XXX: see comment for iteoff above */
328 (void) iteon(sc
->sc_ite
->sc_data
, 2);
333 grfaddr(struct grf_softc
*sc
, off_t off
)
335 struct grf_data
*gp
= sc
->sc_data
;
336 struct grfinfo
*gi
= &gp
->g_display
;
338 /* control registers */
339 if (off
>= 0 && off
< gi
->gd_regsize
)
340 return ((paddr_t
)gi
->gd_regaddr
+ off
) >> PGSHIFT
;
343 if (off
>= gi
->gd_regsize
&& off
< gi
->gd_regsize
+gi
->gd_fbsize
) {
344 off
-= gi
->gd_regsize
;
345 return ((paddr_t
)gi
->gd_fbaddr
+ off
) >> PGSHIFT
;
352 grfmap(dev_t dev
, void **addrp
, struct proc
*p
)
354 struct grf_softc
*sc
= device_lookup_private(&grf_cd
,GRFUNIT(dev
));
355 struct grf_data
*gp
= sc
->sc_data
;
361 if (grfdebug
& GDB_MMAP
)
362 printf("grfmap(%d): addr %p\n", p
->p_pid
, *addrp
);
364 len
= gp
->g_display
.gd_regsize
+ gp
->g_display
.gd_fbsize
;
370 VM_DEFAULT_ADDRESS(p
->p_vmspace
->vm_daddr
, len
);
371 vn
.v_type
= VCHR
; /* XXX */
372 vn
.v_rdev
= dev
; /* XXX */
373 error
= uvm_mmap(&p
->p_vmspace
->vm_map
, (vaddr_t
*)addrp
,
374 (vsize_t
)len
, VM_PROT_READ
|VM_PROT_WRITE
,
375 VM_PROT_READ
|VM_PROT_WRITE
,
376 flags
, (void *)&vn
, 0,
377 p
->p_rlimit
[RLIMIT_MEMLOCK
].rlim_cur
);
379 (void) (*gp
->g_sw
->gd_mode
)(gp
, GM_MAP
, *addrp
);
384 grfunmap(dev_t dev
, void *addr
, struct proc
*p
)
386 struct grf_softc
*sc
= device_lookup_private(&grf_cd
,GRFUNIT(dev
));
387 struct grf_data
*gp
= sc
->sc_data
;
391 if (grfdebug
& GDB_MMAP
)
392 printf("grfunmap(%d): dev %x addr %p\n", p
->p_pid
, dev
, addr
);
395 return EINVAL
; /* XXX: how do we deal with this? */
396 (void) (*gp
->g_sw
->gd_mode
)(gp
, GM_UNMAP
, 0);
397 size
= round_page(gp
->g_display
.gd_regsize
+ gp
->g_display
.gd_fbsize
);
398 uvm_unmap(&p
->p_vmspace
->vm_map
, (vaddr_t
)addr
, (vaddr_t
)addr
+ size
);