Home | History | Annotate | Line # | Download | only in dev
grf.c revision 1.17
      1 /*	$NetBSD: grf.c,v 1.17 2000/06/26 04:56:15 simonb Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1990, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the University of
     23  *	California, Berkeley and its contributors.
     24  * 4. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  * from: Utah $Hdr: grf.c 1.36 93/08/13$
     41  *
     42  *	@(#)grf.c	8.4 (Berkeley) 1/12/94
     43  */
     44 
     45 /*
     46  * Graphics display driver for the X68K machines.
     47  * This is the hardware-independent portion of the driver.
     48  * Hardware access is through the machine dependent grf switch routines.
     49  */
     50 
     51 #include "opt_compat_hpux.h"
     52 
     53 #include <sys/param.h>
     54 #include <sys/systm.h>
     55 #include <sys/device.h>
     56 #include <sys/proc.h>
     57 #include <sys/resourcevar.h>
     58 #include <sys/ioctl.h>
     59 #include <sys/file.h>
     60 #include <sys/malloc.h>
     61 #include <sys/vnode.h>
     62 #include <sys/mman.h>
     63 #include <sys/poll.h>
     64 #include <sys/conf.h>
     65 
     66 #include <machine/grfioctl.h>
     67 
     68 #include <x68k/dev/grfvar.h>
     69 #include <x68k/dev/itevar.h>
     70 
     71 #include <machine/cpu.h>
     72 
     73 #ifdef COMPAT_HPUX
     74 #include <compat/hpux/hpux.h>
     75 extern struct emul emul_hpux;
     76 #endif
     77 
     78 #include <vm/vm.h>
     79 #include <vm/vm_kern.h>
     80 #include <vm/vm_page.h>
     81 #include <vm/vm_pager.h>
     82 
     83 #include <uvm/uvm_extern.h>
     84 #include <uvm/uvm_map.h>
     85 
     86 #include <miscfs/specfs/specdev.h>
     87 
     88 #include "ite.h"
     89 #if NITE == 0
     90 #define	iteon(u,f)
     91 #define	iteoff(u,f)
     92 #define	ite_reinit(u)
     93 #endif
     94 
     95 #ifdef DEBUG
     96 int grfdebug = 0;
     97 #define GDB_DEVNO	0x01
     98 #define GDB_MMAP	0x02
     99 #define GDB_IOMAP	0x04
    100 #define GDB_LOCK	0x08
    101 #endif
    102 
    103 cdev_decl(grf);
    104 int grfon __P((dev_t));
    105 int grfoff __P((dev_t));
    106 off_t grfaddr __P((struct grf_softc *, off_t));
    107 int grfmap __P((dev_t, caddr_t *, struct proc *));
    108 int grfunmap __P((dev_t, caddr_t, struct proc *));
    109 
    110 extern struct cfdriver grf_cd;
    111 
    112 /*ARGSUSED*/
    113 int
    114 grfopen(dev, flags, mode, p)
    115 	dev_t dev;
    116 	int flags, mode;
    117 	struct proc *p;
    118 {
    119 	int unit = GRFUNIT(dev);
    120 	register struct grf_softc *gp;
    121 	int error = 0;
    122 
    123 	if (unit >= grf_cd.cd_ndevs ||
    124 	    (gp = grf_cd.cd_devs[unit]) == NULL ||
    125 	    (gp->g_flags & GF_ALIVE) == 0)
    126 		return (ENXIO);
    127 
    128 	if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
    129 		return(EBUSY);
    130 #ifdef COMPAT_HPUX
    131 	/*
    132 	 * XXX: cannot handle both HPUX and BSD processes at the same time
    133 	 */
    134 	if (p->p_emul == &emul_hpux)
    135 		if (gp->g_flags & GF_BSDOPEN)
    136 			return(EBUSY);
    137 		else
    138 			gp->g_flags |= GF_HPUXOPEN;
    139 	else
    140 		if (gp->g_flags & GF_HPUXOPEN)
    141 			return(EBUSY);
    142 		else
    143 			gp->g_flags |= GF_BSDOPEN;
    144 #endif
    145 	/*
    146 	 * First open.
    147 	 * XXX: always put in graphics mode.
    148 	 */
    149 	error = 0;
    150 	if ((gp->g_flags & GF_OPEN) == 0) {
    151 		gp->g_flags |= GF_OPEN;
    152 		error = grfon(dev);
    153 	}
    154 	return(error);
    155 }
    156 
    157 /*ARGSUSED*/
    158 int
    159 grfclose(dev, flags, mode, p)
    160 	dev_t dev;
    161 	int flags, mode;
    162 	struct proc *p;
    163 {
    164 	register struct grf_softc *gp = grf_cd.cd_devs[GRFUNIT(dev)];
    165 
    166 	if ((gp->g_flags & GF_ALIVE) == 0)
    167 		return (ENXIO);
    168 
    169 	(void) grfoff(dev);
    170 #ifdef COMPAT_HPUX
    171 	(void) grfunlock(gp);
    172 #endif
    173 	gp->g_flags &= GF_ALIVE;
    174 	return(0);
    175 }
    176 
    177 /*ARGSUSED*/
    178 int
    179 grfioctl(dev, cmd, data, flag, p)
    180 	dev_t dev;
    181 	u_long cmd;
    182 	caddr_t data;
    183 	int flag;
    184 	struct proc *p;
    185 {
    186 	int unit = GRFUNIT(dev);
    187 	register struct grf_softc *gp = grf_cd.cd_devs[unit];
    188 	int error;
    189 
    190 	if ((gp->g_flags & GF_ALIVE) == 0)
    191 		return (ENXIO);
    192 
    193 #ifdef COMPAT_HPUX
    194 	if (p->p_emul == &emul_hpux)
    195 		return(hpuxgrfioctl(dev, cmd, data, flag, p));
    196 #endif
    197 	error = 0;
    198 	switch (cmd) {
    199 
    200 	case GRFIOCGINFO:
    201 		bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
    202 		break;
    203 
    204 	case GRFIOCON:
    205 		error = grfon(dev);
    206 		break;
    207 
    208 	case GRFIOCOFF:
    209 		error = grfoff(dev);
    210 		break;
    211 
    212 	case GRFIOCMAP:
    213 		error = grfmap(dev, (caddr_t *)data, p);
    214 		break;
    215 
    216 	case GRFIOCUNMAP:
    217 		error = grfunmap(dev, *(caddr_t *)data, p);
    218 		break;
    219 
    220 	case GRFSETVMODE:
    221 		error = (*gp->g_sw->gd_mode)(gp, GM_GRFSETVMODE, data);
    222 		if (error == 0)
    223 			ite_reinit(unit);
    224 		break;
    225 
    226 	default:
    227 		error = EINVAL;
    228 		break;
    229 
    230 	}
    231 	return(error);
    232 }
    233 
    234 /*ARGSUSED*/
    235 int
    236 grfpoll(dev, events, p)
    237 	dev_t dev;
    238 	int events;
    239 	struct proc *p;
    240 {
    241 
    242 	return (events & (POLLOUT | POLLWRNORM));
    243 }
    244 
    245 /*ARGSUSED*/
    246 paddr_t
    247 grfmmap(dev, off, prot)
    248 	dev_t dev;
    249 	off_t off;
    250 	int prot;
    251 {
    252 
    253 	return (grfaddr(grf_cd.cd_devs[GRFUNIT(dev)], off));
    254 }
    255 
    256 int
    257 grfon(dev)
    258 	dev_t dev;
    259 {
    260 	int unit = GRFUNIT(dev);
    261 	struct grf_softc *gp = grf_cd.cd_devs[unit];
    262 
    263 	/*
    264 	 * XXX: iteoff call relies on devices being in same order
    265 	 * as ITEs and the fact that iteoff only uses the minor part
    266 	 * of the dev arg.
    267 	 */
    268 	iteoff(unit, 2);
    269 	return((*gp->g_sw->gd_mode)(gp,
    270 				    (dev&GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
    271 				    (caddr_t)0));
    272 }
    273 
    274 int
    275 grfoff(dev)
    276 	dev_t dev;
    277 {
    278 	int unit = GRFUNIT(dev);
    279 	struct grf_softc *gp = grf_cd.cd_devs[unit];
    280 	int error;
    281 
    282 	(void) grfunmap(dev, (caddr_t)0, curproc);
    283 	error = (*gp->g_sw->gd_mode)(gp,
    284 				     (dev&GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
    285 				     (caddr_t)0);
    286 	/* XXX: see comment for iteoff above */
    287 	iteon(unit, 2);
    288 	return(error);
    289 }
    290 
    291 off_t
    292 grfaddr(gp, off)
    293 	struct grf_softc *gp;
    294 	off_t off;
    295 {
    296 	register struct grfinfo *gi = &gp->g_display;
    297 
    298 	/* control registers */
    299 	if (off >= 0 && off < gi->gd_regsize)
    300 		return(((u_int)gi->gd_regaddr + off) >> PGSHIFT);
    301 
    302 	/* frame buffer */
    303 	if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
    304 		off -= gi->gd_regsize;
    305 		return(((u_int)gi->gd_fbaddr + off) >> PGSHIFT);
    306 	}
    307 	/* bogus */
    308 	return(-1);
    309 }
    310 
    311 /*
    312  * HP-UX compatibility routines
    313  */
    314 #ifdef COMPAT_HPUX
    315 
    316 /*ARGSUSED*/
    317 int
    318 hpuxgrfioctl(dev, cmd, data, flag, p)
    319 	dev_t dev;
    320 	int cmd;
    321 	caddr_t data;
    322 	int flag;
    323 	struct proc *p;
    324 {
    325 	register struct grf_softc *gp = grf_cd.cd_devs[GRFUNIT(dev)];
    326 	int error;
    327 
    328 	error = 0;
    329 	switch (cmd) {
    330 
    331 	case GCID:
    332 		*(int *)data = gp->g_display.gd_id;
    333 		break;
    334 
    335 	case GCON:
    336 		error = grfon(dev);
    337 		break;
    338 
    339 	case GCOFF:
    340 		error = grfoff(dev);
    341 		break;
    342 
    343 	case GCLOCK:
    344 		error = grflock(gp, 1);
    345 		break;
    346 
    347 	case GCUNLOCK:
    348 		error = grfunlock(gp);
    349 		break;
    350 
    351 	case GCAON:
    352 	case GCAOFF:
    353 		break;
    354 
    355 	/* GCSTATIC is implied by our implementation */
    356 	case GCSTATIC_CMAP:
    357 	case GCVARIABLE_CMAP:
    358 		break;
    359 
    360 	/* map in control regs and frame buffer */
    361 	case GCMAP:
    362 		error = grfmap(dev, (caddr_t *)data, p);
    363 		break;
    364 
    365 	case GCUNMAP:
    366 		error = grfunmap(dev, *(caddr_t *)data, p);
    367 		/* XXX: HP-UX uses GCUNMAP to get rid of GCSLOT memory */
    368 		if (error)
    369 			error = grflckunmmap(dev, *(caddr_t *)data);
    370 		break;
    371 
    372 	case GCSLOT:
    373 	{
    374 		struct grf_slot *sp = (struct grf_slot *)data;
    375 
    376 		sp->slot = grffindpid(gp);
    377 		if (sp->slot) {
    378 			error = grflckmmap(dev, (caddr_t *)&sp->addr);
    379 			if (error && gp->g_pid) {
    380 				free((caddr_t)gp->g_pid, M_DEVBUF);
    381 				gp->g_pid = NULL;
    382 			}
    383 		} else
    384 			error = EINVAL;		/* XXX */
    385 		break;
    386 	}
    387 
    388 	case GCDESCRIBE:
    389 		error = (*gp->g_sw->gd_mode)(gp, GM_DESCRIBE, data);
    390 		break;
    391 
    392 	/*
    393 	 * XXX: only used right now to map in rbox control registers
    394 	 * Will be replaced in the future with a real IOMAP interface.
    395 	 */
    396 	case IOMAPMAP:
    397 		error = iommap(dev, (caddr_t *)data);
    398 #if 0
    399 		/*
    400 		 * It may not be worth kludging this (using p_devtmp) to
    401 		 * make this work.  It was an undocumented side-effect
    402 		 * in HP-UX that the mapped address was the return value
    403 		 * of the ioctl.  The only thing I remember that counted
    404 		 * on this behavior was the rbox X10 server.
    405 		 */
    406 		if (!error)
    407 			u.u_r.r_val1 = *(int *)data;	/* XXX: this sux */
    408 #endif
    409 		break;
    410 
    411 	case IOMAPUNMAP:
    412 		error = iounmmap(dev, *(caddr_t *)data);
    413 		break;
    414 
    415 	default:
    416 		error = EINVAL;
    417 		break;
    418 	}
    419 	return(error);
    420 }
    421 
    422 int
    423 grflock(gp, block)
    424 	register struct grf_softc *gp;
    425 	int block;
    426 {
    427 	struct proc *p = curproc;		/* XXX */
    428 	int error;
    429 	extern char devioc[];
    430 
    431 #ifdef DEBUG
    432 	if (grfdebug & GDB_LOCK)
    433 		printf("grflock(%d): flags %x lockpid %x\n",
    434 		       p->p_pid, gp->g_flags,
    435 		       gp->g_lockp ? gp->g_lockp->p_pid : -1);
    436 #endif
    437 	if (gp->g_pid) {
    438 #ifdef DEBUG
    439 		if (grfdebug & GDB_LOCK)
    440 			printf(" lockpslot %d lockslot %d lock[lockslot] %d\n",
    441 			       gp->g_lock->gl_lockslot, gp->g_lockpslot,
    442 			       gp->g_lock->gl_locks[gp->g_lockpslot]);
    443 #endif
    444 		gp->g_lock->gl_lockslot = 0;
    445 		if (gp->g_lock->gl_locks[gp->g_lockpslot] == 0) {
    446 			gp->g_lockp = NULL;
    447 			gp->g_lockpslot = 0;
    448 		}
    449 	}
    450 	if (gp->g_lockp) {
    451 		if (gp->g_lockp == p)
    452 			return(EBUSY);
    453 		if (!block)
    454 			return(OEAGAIN);
    455 		do {
    456 			gp->g_flags |= GF_WANTED;
    457 			if ((error = tsleep((caddr_t)&gp->g_flags,
    458 					   (PZERO+1) | PCATCH, devioc, 0)))
    459 				return (error);
    460 		} while (gp->g_lockp);
    461 	}
    462 	gp->g_lockp = p;
    463 	if (gp->g_pid) {
    464 		int slot = grffindpid(gp);
    465 
    466 #ifdef DEBUG
    467 		if (grfdebug & GDB_LOCK)
    468 			printf("  slot %d\n", slot);
    469 #endif
    470 		gp->g_lockpslot = gp->g_lock->gl_lockslot = slot;
    471 		gp->g_lock->gl_locks[slot] = 1;
    472 	}
    473 	return(0);
    474 }
    475 
    476 int
    477 grfunlock(gp)
    478 	register struct grf_softc *gp;
    479 {
    480 #ifdef DEBUG
    481 	if (grfdebug & GDB_LOCK)
    482 		printf("grfunlock(%d): flags %x lockpid %d\n",
    483 		       curproc->p_pid, gp->g_flags,
    484 		       gp->g_lockp ? gp->g_lockp->p_pid : -1);
    485 #endif
    486 	if (gp->g_lockp != curproc)
    487 		return(EBUSY);
    488 	if (gp->g_pid) {
    489 #ifdef DEBUG
    490 		if (grfdebug & GDB_LOCK)
    491 			printf(" lockpslot %d lockslot %d lock[lockslot] %d\n",
    492 			       gp->g_lock->gl_lockslot, gp->g_lockpslot,
    493 			       gp->g_lock->gl_locks[gp->g_lockpslot]);
    494 #endif
    495 		gp->g_lock->gl_locks[gp->g_lockpslot] = 0;
    496 		gp->g_lockpslot = gp->g_lock->gl_lockslot = 0;
    497 	}
    498 	if (gp->g_flags & GF_WANTED) {
    499 		wakeup((caddr_t)&gp->g_flags);
    500 		gp->g_flags &= ~GF_WANTED;
    501 	}
    502 	gp->g_lockp = NULL;
    503 	return(0);
    504 }
    505 
    506 /*
    507  * Convert a BSD style minor devno to HPUX style.
    508  * We cannot just create HPUX style nodes as they require 24 bits
    509  * of minor device number and we only have 8.
    510  * XXX: This may give the wrong result for remote stats of other
    511  * machines where device 10 exists.
    512  */
    513 int
    514 grfdevno(dev)
    515 	dev_t dev;
    516 {
    517 	int unit = GRFUNIT(dev);
    518 	struct grf_softc *gp;
    519 	int newdev;
    520 
    521 	if (unit >= grf_cd.cd_ndevs ||
    522 	    (gp = grf_cd.cd_devs[unit]) == NULL ||
    523 	    (gp->g_flags&GF_ALIVE) == 0)
    524 		return(bsdtohpuxdev(dev));
    525 	/* magic major number */
    526 	newdev = 12 << 24;
    527 	/* now construct minor number */
    528 	if (gp->g_display.gd_regaddr != (caddr_t)GRFIADDR) {
    529 		int sc = patosc(gp->g_display.gd_regaddr);
    530 		newdev |= (sc << 16) | 0x200;
    531 	}
    532 	if (dev & GRFIMDEV)
    533 		newdev |= 0x02;
    534 	else if (dev & GRFOVDEV)
    535 		newdev |= 0x01;
    536 #ifdef DEBUG
    537 	if (grfdebug & GDB_DEVNO)
    538 		printf("grfdevno: dev %x newdev %x\n", dev, newdev);
    539 #endif
    540 	return(newdev);
    541 }
    542 
    543 #endif	/* COMPAT_HPUX */
    544 
    545 int
    546 grfmap(dev, addrp, p)
    547 	dev_t dev;
    548 	caddr_t *addrp;
    549 	struct proc *p;
    550 {
    551 	struct grf_softc *gp = grf_cd.cd_devs[GRFUNIT(dev)];
    552 	int len, error;
    553 	struct vnode vn;
    554 	struct specinfo si;
    555 	int flags;
    556 
    557 #ifdef DEBUG
    558 	if (grfdebug & GDB_MMAP)
    559 		printf("grfmap(%d): addr %p\n", p->p_pid, *addrp);
    560 #endif
    561 	len = gp->g_display.gd_regsize + gp->g_display.gd_fbsize;
    562 	flags = MAP_SHARED;
    563 	if (*addrp)
    564 		flags |= MAP_FIXED;
    565 	else
    566 		*addrp = (caddr_t)0x1000000;	/* XXX */
    567 	vn.v_type = VCHR;			/* XXX */
    568 	vn.v_specinfo = &si;			/* XXX */
    569 	vn.v_rdev = dev;			/* XXX */
    570 	error = uvm_mmap(&p->p_vmspace->vm_map, (vaddr_t *)addrp,
    571 			 (vsize_t)len, VM_PROT_ALL, VM_PROT_ALL,
    572 			 flags, (caddr_t)&vn, 0,
    573 			 p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
    574 	if (error == 0)
    575 		(void) (*gp->g_sw->gd_mode)(gp, GM_MAP, *addrp);
    576 	return(error);
    577 }
    578 
    579 int
    580 grfunmap(dev, addr, p)
    581 	dev_t dev;
    582 	caddr_t addr;
    583 	struct proc *p;
    584 {
    585 	struct grf_softc *gp = grf_cd.cd_devs[GRFUNIT(dev)];
    586 	vsize_t size;
    587 	int rv;
    588 
    589 #ifdef DEBUG
    590 	if (grfdebug & GDB_MMAP)
    591 		printf("grfunmap(%d): dev %x addr %p\n", p->p_pid, dev, addr);
    592 #endif
    593 	if (addr == 0)
    594 		return(EINVAL);		/* XXX: how do we deal with this? */
    595 	(void) (*gp->g_sw->gd_mode)(gp, GM_UNMAP, 0);
    596 	size = round_page(gp->g_display.gd_regsize + gp->g_display.gd_fbsize);
    597 	rv = uvm_unmap(&p->p_vmspace->vm_map, (vaddr_t)addr,
    598 	    (vaddr_t)addr + size);
    599 	return(rv == KERN_SUCCESS ? 0 : EINVAL);
    600 }
    601 
    602 #ifdef COMPAT_HPUX
    603 int
    604 iommap(dev, addrp)
    605 	dev_t dev;
    606 	caddr_t *addrp;
    607 {
    608 
    609 #ifdef DEBUG
    610 	if (grfdebug & (GDB_MMAP|GDB_IOMAP))
    611 		printf("iommap(%d): addr %p\n", curproc->p_pid, *addrp);
    612 #endif
    613 	return(EINVAL);
    614 }
    615 
    616 int
    617 iounmmap(dev, addr)
    618 	dev_t dev;
    619 	caddr_t addr;
    620 {
    621 #ifdef DEBUG
    622 	int unit = minor(dev);
    623 
    624 	if (grfdebug & (GDB_MMAP|GDB_IOMAP))
    625 		printf("iounmmap(%d): id %d addr %p\n",
    626 		       curproc->p_pid, unit, addr);
    627 #endif
    628 	return(0);
    629 }
    630 
    631 /*
    632  * Processes involved in framebuffer mapping via GCSLOT are recorded in
    633  * an array of pids.  The first element is used to record the last slot used
    634  * (for faster lookups).  The remaining elements record up to GRFMAXLCK-1
    635  * process ids.  Returns a slot number between 1 and GRFMAXLCK or 0 if no
    636  * slot is available.
    637  */
    638 int
    639 grffindpid(gp)
    640 	struct grf_softc *gp;
    641 {
    642 	register short pid, *sp;
    643 	register int i, limit;
    644 	int ni;
    645 
    646 	if (gp->g_pid == NULL) {
    647 		gp->g_pid = (short *)
    648 			malloc(GRFMAXLCK * sizeof(short), M_DEVBUF, M_WAITOK);
    649 		bzero((caddr_t)gp->g_pid, GRFMAXLCK * sizeof(short));
    650 	}
    651 	pid = curproc->p_pid;
    652 	ni = limit = gp->g_pid[0];
    653 	for (i = 1, sp = &gp->g_pid[1]; i <= limit; i++, sp++) {
    654 		if (*sp == pid)
    655 			goto done;
    656 		if (*sp == 0)
    657 			ni = i;
    658 	}
    659 	i = ni;
    660 	if (i < limit) {
    661 		gp->g_pid[i] = pid;
    662 		goto done;
    663 	}
    664 	if (++i == GRFMAXLCK)
    665 		return(0);
    666 	gp->g_pid[0] = i;
    667 	gp->g_pid[i] = pid;
    668 done:
    669 #ifdef DEBUG
    670 	if (grfdebug & GDB_LOCK)
    671 		printf("grffindpid(%d): slot %d of %d\n",
    672 		       pid, i, gp->g_pid[0]);
    673 #endif
    674 	return(i);
    675 }
    676 
    677 void
    678 grfrmpid(gp)
    679 	struct grf_softc *gp;
    680 {
    681 	register short pid, *sp;
    682 	register int limit, i;
    683 	int mi;
    684 
    685 	if (gp->g_pid == NULL || (limit = gp->g_pid[0]) == 0)
    686 		return;
    687 	pid = curproc->p_pid;
    688 	limit = gp->g_pid[0];
    689 	mi = 0;
    690 	for (i = 1, sp = &gp->g_pid[1]; i <= limit; i++, sp++) {
    691 		if (*sp == pid)
    692 			*sp = 0;
    693 		else if (*sp)
    694 			mi = i;
    695 	}
    696 	i = mi;
    697 	if (i < limit)
    698 		gp->g_pid[0] = i;
    699 #ifdef DEBUG
    700 	if (grfdebug & GDB_LOCK)
    701 		printf("grfrmpid(%d): slot %d of %d\n",
    702 		       pid, sp-gp->g_pid, gp->g_pid[0]);
    703 #endif
    704 }
    705 
    706 int
    707 grflckmmap(dev, addrp)
    708 	dev_t dev;
    709 	caddr_t *addrp;
    710 {
    711 #ifdef DEBUG
    712 	struct proc *p = curproc;		/* XXX */
    713 
    714 	if (grfdebug & (GDB_MMAP|GDB_LOCK))
    715 		printf("grflckmmap(%d): addr %p\n",
    716 		       p->p_pid, *addrp);
    717 #endif
    718 	return(EINVAL);
    719 }
    720 
    721 int
    722 grflckunmmap(dev, addr)
    723 	dev_t dev;
    724 	caddr_t addr;
    725 {
    726 #ifdef DEBUG
    727 	int unit = minor(dev);
    728 
    729 	if (grfdebug & (GDB_MMAP|GDB_LOCK))
    730 		printf("grflckunmmap(%d): id %d addr %p\n",
    731 		       curproc->p_pid, unit, addr);
    732 #endif
    733 	return(EINVAL);
    734 }
    735 #endif	/* COMPAT_HPUX */
    736