Home | History | Annotate | Line # | Download | only in dev
sram.c revision 1.1
      1 /*	$NetBSD: sram.c,v 1.1 1996/05/05 12:17:05 oki Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Kazuhisa Shimizu.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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 Kazuhisa Shimizu.
     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
     20  *
     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.
     31  */
     32 
     33 #include <sys/param.h>
     34 #include <sys/proc.h>
     35 #include <sys/ioctl.h>
     36 #include <sys/file.h>
     37 #include <sys/malloc.h>
     38 #include <sys/systm.h>
     39 
     40 #include <machine/sram.h>
     41 #include <x68k/dev/sramvar.h>
     42 #include <x68k/x68k/iodevice.h>
     43 #include "sram.h"
     44 
     45 struct sram_softc sram_softc;
     46 
     47 #ifdef DEBUG
     48 #define SRAM_DEBUG_OPEN		0x01
     49 #define SRAM_DEBUG_CLOSE	0x02
     50 #define SRAM_DEBUG_IOCTL	0x03
     51 int sramdebug = SRAM_DEBUG_IOCTL;
     52 #endif
     53 
     54 /*
     55  *  functions for probeing.
     56  */
     57 /* ARGSUSED */
     58 sramattach(num)
     59 	int num;
     60 {
     61 	sram_softc.flags = 0;
     62 	printf("sram0: 16k bytes accessible\n");
     63 	return (1);
     64 }
     65 
     66 
     67 /*
     68  *  functions made available by conf.c
     69  */
     70 
     71 /*ARGSUSED*/
     72 int
     73 sramopen(dev, flags)
     74 	dev_t dev;
     75 	int flags;
     76 {
     77 	struct sram_softc *su = &sram_softc;
     78 
     79 #ifdef DEBUG
     80 	if (sramdebug & SRAM_DEBUG_OPEN)
     81 		printf ("Sram open\n");
     82 #endif
     83 
     84 	if (minor(dev) >= 1)
     85 		return EXDEV;
     86 
     87 	if (su->flags & SRF_OPEN) {
     88 		return (EBUSY);
     89 	}
     90 
     91 	su->flags |= SRF_OPEN;
     92 	return (0);
     93 }
     94 
     95 /*ARGSUSED*/
     96 void
     97 sramclose (dev, flags)
     98 	dev_t dev;
     99 	int flags;
    100 {
    101 	struct sram_softc *su = &sram_softc;
    102 
    103 #ifdef DEBUG
    104 	if (sramdebug & SRAM_DEBUG_CLOSE)
    105 		printf ("Sram close\n");
    106 #endif
    107 
    108 	if (su->flags & SRF_OPEN) {
    109 		su->flags = 0;
    110 	}
    111 }
    112 
    113 
    114 /*ARGSUSED*/
    115 int
    116 sramioctl (dev, cmd, data, flag, p)
    117 	dev_t dev;
    118 	u_long cmd;
    119 	caddr_t data;
    120 	int flag;
    121 	struct proc *p;
    122 {
    123 	struct sram_softc *su = &sram_softc;
    124 	int error = 0;
    125 	struct sram_io *sram_io;
    126 	register char *sramtop = IODEVbase->io_sram;
    127 
    128 #ifdef DEBUG
    129 	if (sramdebug & SRAM_DEBUG_IOCTL)
    130 		printf ("Sram ioctl cmd=%x\n",cmd);
    131 #endif
    132 	sram_io = (struct sram_io *)data;
    133 
    134 	switch (cmd) {
    135 	case SIOGSRAM:
    136 #ifdef DEBUG
    137 		if (sramdebug & SRAM_DEBUG_IOCTL)
    138     			printf ("Sram ioctl SIOGSRAM address=%x\n",data);
    139     			printf ("Sram ioctl SIOGSRAM offset=%x\n",sram_io->offset);
    140 #endif
    141 		if (sram_io == NULL ||
    142 		    sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
    143 			return(EFAULT);
    144 		bcopy(sramtop + sram_io->offset, &(sram_io->sram), SRAM_IO_SIZE);
    145 		break;
    146 	case SIOPSRAM:
    147 #ifdef DEBUG
    148 		if (sramdebug & SRAM_DEBUG_IOCTL)
    149     			printf ("Sram ioctl SIOSSRAM address=%x\n",data);
    150     			printf ("Sram ioctl SIOSSRAM offset=%x\n",sram_io->offset);
    151 #endif
    152 		if (sram_io == NULL ||
    153 		    sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
    154 			return(EFAULT);
    155 		sysport.sramwp = 0x31;
    156 		bcopy(&(sram_io->sram), sramtop + sram_io->offset,SRAM_IO_SIZE);
    157 		sysport.sramwp = 0x00;
    158 		break;
    159 	default:
    160 		error = EINVAL;
    161 		break;
    162 	}
    163 	return(error);
    164 }
    165