Home | History | Annotate | Line # | Download | only in dev
sram.c revision 1.4.10.1
      1  1.4.10.1   thorpej /*	$NetBSD: sram.c,v 1.4.10.1 1997/10/14 10:20:38 thorpej Exp $	*/
      2       1.1       oki 
      3       1.1       oki /*
      4       1.1       oki  * Copyright (c) 1994 Kazuhisa Shimizu.
      5       1.1       oki  * All rights reserved.
      6       1.1       oki  *
      7       1.1       oki  * Redistribution and use in source and binary forms, with or without
      8       1.1       oki  * modification, are permitted provided that the following conditions
      9       1.1       oki  * are met:
     10       1.1       oki  * 1. Redistributions of source code must retain the above copyright
     11       1.1       oki  *    notice, this list of conditions and the following disclaimer.
     12       1.1       oki  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1       oki  *    notice, this list of conditions and the following disclaimer in the
     14       1.1       oki  *    documentation and/or other materials provided with the distribution.
     15       1.1       oki  * 3. All advertising materials mentioning features or use of this software
     16       1.1       oki  *    must display the following acknowledgement:
     17       1.1       oki  *      This product includes software developed by Kazuhisa Shimizu.
     18       1.1       oki  * 4. The name of the author may not be used to endorse or promote products
     19       1.1       oki  *    derived from this software without specific prior written permission
     20       1.1       oki  *
     21       1.1       oki  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22       1.1       oki  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1       oki  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1       oki  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1       oki  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1       oki  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1       oki  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1       oki  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1       oki  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1       oki  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1       oki  */
     32       1.1       oki 
     33       1.1       oki #include <sys/param.h>
     34       1.1       oki #include <sys/proc.h>
     35       1.1       oki #include <sys/ioctl.h>
     36       1.1       oki #include <sys/file.h>
     37       1.1       oki #include <sys/malloc.h>
     38       1.1       oki #include <sys/systm.h>
     39       1.1       oki 
     40       1.1       oki #include <machine/sram.h>
     41       1.1       oki #include <x68k/dev/sramvar.h>
     42       1.1       oki #include <x68k/x68k/iodevice.h>
     43       1.1       oki 
     44       1.1       oki struct sram_softc sram_softc;
     45       1.1       oki 
     46       1.1       oki #ifdef DEBUG
     47       1.1       oki #define SRAM_DEBUG_OPEN		0x01
     48       1.1       oki #define SRAM_DEBUG_CLOSE	0x02
     49       1.1       oki #define SRAM_DEBUG_IOCTL	0x03
     50       1.1       oki int sramdebug = SRAM_DEBUG_IOCTL;
     51       1.1       oki #endif
     52  1.4.10.1   thorpej 
     53  1.4.10.1   thorpej void sramattach __P((int));
     54  1.4.10.1   thorpej int sramopen __P((dev_t, int));
     55  1.4.10.1   thorpej void sramclose __P((dev_t, int));
     56  1.4.10.1   thorpej int sramioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
     57       1.1       oki 
     58       1.1       oki /*
     59       1.1       oki  *  functions for probeing.
     60       1.1       oki  */
     61       1.1       oki /* ARGSUSED */
     62       1.2       oki void
     63       1.1       oki sramattach(num)
     64       1.1       oki 	int num;
     65       1.1       oki {
     66       1.1       oki 	sram_softc.flags = 0;
     67       1.4  christos 	printf("sram0: 16k bytes accessible\n");
     68       1.1       oki }
     69       1.1       oki 
     70       1.1       oki 
     71       1.1       oki /*
     72       1.1       oki  *  functions made available by conf.c
     73       1.1       oki  */
     74       1.1       oki 
     75       1.1       oki /*ARGSUSED*/
     76       1.1       oki int
     77       1.1       oki sramopen(dev, flags)
     78       1.1       oki 	dev_t dev;
     79       1.1       oki 	int flags;
     80       1.1       oki {
     81       1.1       oki 	struct sram_softc *su = &sram_softc;
     82       1.1       oki 
     83       1.1       oki #ifdef DEBUG
     84       1.1       oki 	if (sramdebug & SRAM_DEBUG_OPEN)
     85       1.4  christos 		printf ("Sram open\n");
     86       1.1       oki #endif
     87       1.1       oki 
     88       1.1       oki 	if (minor(dev) >= 1)
     89       1.1       oki 		return EXDEV;
     90       1.1       oki 
     91       1.1       oki 	if (su->flags & SRF_OPEN) {
     92       1.1       oki 		return (EBUSY);
     93       1.1       oki 	}
     94       1.1       oki 
     95       1.1       oki 	su->flags |= SRF_OPEN;
     96       1.1       oki 	return (0);
     97       1.1       oki }
     98       1.1       oki 
     99       1.1       oki /*ARGSUSED*/
    100       1.1       oki void
    101       1.1       oki sramclose (dev, flags)
    102       1.1       oki 	dev_t dev;
    103       1.1       oki 	int flags;
    104       1.1       oki {
    105       1.1       oki 	struct sram_softc *su = &sram_softc;
    106       1.1       oki 
    107       1.1       oki #ifdef DEBUG
    108       1.1       oki 	if (sramdebug & SRAM_DEBUG_CLOSE)
    109       1.4  christos 		printf ("Sram close\n");
    110       1.1       oki #endif
    111       1.1       oki 
    112       1.1       oki 	if (su->flags & SRF_OPEN) {
    113       1.1       oki 		su->flags = 0;
    114       1.1       oki 	}
    115       1.1       oki }
    116       1.1       oki 
    117       1.1       oki 
    118       1.1       oki /*ARGSUSED*/
    119       1.1       oki int
    120       1.1       oki sramioctl (dev, cmd, data, flag, p)
    121       1.1       oki 	dev_t dev;
    122       1.1       oki 	u_long cmd;
    123       1.1       oki 	caddr_t data;
    124       1.1       oki 	int flag;
    125       1.1       oki 	struct proc *p;
    126       1.1       oki {
    127       1.1       oki 	int error = 0;
    128       1.1       oki 	struct sram_io *sram_io;
    129       1.1       oki 	register char *sramtop = IODEVbase->io_sram;
    130       1.1       oki 
    131       1.1       oki #ifdef DEBUG
    132       1.1       oki 	if (sramdebug & SRAM_DEBUG_IOCTL)
    133       1.4  christos 		printf("Sram ioctl cmd=%lx\n", cmd);
    134       1.1       oki #endif
    135       1.1       oki 	sram_io = (struct sram_io *)data;
    136       1.1       oki 
    137       1.1       oki 	switch (cmd) {
    138       1.1       oki 	case SIOGSRAM:
    139       1.1       oki #ifdef DEBUG
    140       1.2       oki 		if (sramdebug & SRAM_DEBUG_IOCTL) {
    141       1.4  christos     			printf("Sram ioctl SIOGSRAM address=%p\n", data);
    142       1.4  christos     			printf("Sram ioctl SIOGSRAM offset=%x\n", sram_io->offset);
    143       1.2       oki 		}
    144       1.1       oki #endif
    145       1.1       oki 		if (sram_io == NULL ||
    146       1.1       oki 		    sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
    147       1.1       oki 			return(EFAULT);
    148       1.1       oki 		bcopy(sramtop + sram_io->offset, &(sram_io->sram), SRAM_IO_SIZE);
    149       1.1       oki 		break;
    150       1.1       oki 	case SIOPSRAM:
    151       1.1       oki #ifdef DEBUG
    152       1.2       oki 		if (sramdebug & SRAM_DEBUG_IOCTL) {
    153       1.4  christos     			printf("Sram ioctl SIOSSRAM address=%p\n", data);
    154       1.4  christos     			printf("Sram ioctl SIOSSRAM offset=%x\n", sram_io->offset);
    155       1.2       oki 		}
    156       1.1       oki #endif
    157       1.1       oki 		if (sram_io == NULL ||
    158       1.1       oki 		    sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
    159       1.1       oki 			return(EFAULT);
    160       1.1       oki 		sysport.sramwp = 0x31;
    161       1.1       oki 		bcopy(&(sram_io->sram), sramtop + sram_io->offset,SRAM_IO_SIZE);
    162       1.1       oki 		sysport.sramwp = 0x00;
    163       1.1       oki 		break;
    164       1.1       oki 	default:
    165       1.1       oki 		error = EINVAL;
    166       1.1       oki 		break;
    167       1.1       oki 	}
    168       1.2       oki 	return (error);
    169       1.1       oki }
    170