1 /* $NetBSD: sram.c,v 1.4 1996/10/13 03:35:08 christos 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 void 59 sramattach(num) 60 int num; 61 { 62 sram_softc.flags = 0; 63 printf("sram0: 16k bytes accessible\n"); 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 int error = 0; 124 struct sram_io *sram_io; 125 register char *sramtop = IODEVbase->io_sram; 126 127 #ifdef DEBUG 128 if (sramdebug & SRAM_DEBUG_IOCTL) 129 printf("Sram ioctl cmd=%lx\n", cmd); 130 #endif 131 sram_io = (struct sram_io *)data; 132 133 switch (cmd) { 134 case SIOGSRAM: 135 #ifdef DEBUG 136 if (sramdebug & SRAM_DEBUG_IOCTL) { 137 printf("Sram ioctl SIOGSRAM address=%p\n", data); 138 printf("Sram ioctl SIOGSRAM offset=%x\n", sram_io->offset); 139 } 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=%p\n", data); 150 printf("Sram ioctl SIOSSRAM offset=%x\n", sram_io->offset); 151 } 152 #endif 153 if (sram_io == NULL || 154 sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE) 155 return(EFAULT); 156 sysport.sramwp = 0x31; 157 bcopy(&(sram_io->sram), sramtop + sram_io->offset,SRAM_IO_SIZE); 158 sysport.sramwp = 0x00; 159 break; 160 default: 161 error = EINVAL; 162 break; 163 } 164 return (error); 165 } 166