sram.c revision 1.5 1 /* $NetBSD: sram.c,v 1.5 1997/10/10 21:45:18 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
44 struct sram_softc sram_softc;
45
46 #ifdef DEBUG
47 #define SRAM_DEBUG_OPEN 0x01
48 #define SRAM_DEBUG_CLOSE 0x02
49 #define SRAM_DEBUG_IOCTL 0x03
50 int sramdebug = SRAM_DEBUG_IOCTL;
51 #endif
52
53 void sramattach __P((int));
54 int sramopen __P((dev_t, int));
55 void sramclose __P((dev_t, int));
56 int sramioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
57
58 /*
59 * functions for probeing.
60 */
61 /* ARGSUSED */
62 void
63 sramattach(num)
64 int num;
65 {
66 sram_softc.flags = 0;
67 printf("sram0: 16k bytes accessible\n");
68 }
69
70
71 /*
72 * functions made available by conf.c
73 */
74
75 /*ARGSUSED*/
76 int
77 sramopen(dev, flags)
78 dev_t dev;
79 int flags;
80 {
81 struct sram_softc *su = &sram_softc;
82
83 #ifdef DEBUG
84 if (sramdebug & SRAM_DEBUG_OPEN)
85 printf ("Sram open\n");
86 #endif
87
88 if (minor(dev) >= 1)
89 return EXDEV;
90
91 if (su->flags & SRF_OPEN) {
92 return (EBUSY);
93 }
94
95 su->flags |= SRF_OPEN;
96 return (0);
97 }
98
99 /*ARGSUSED*/
100 void
101 sramclose (dev, flags)
102 dev_t dev;
103 int flags;
104 {
105 struct sram_softc *su = &sram_softc;
106
107 #ifdef DEBUG
108 if (sramdebug & SRAM_DEBUG_CLOSE)
109 printf ("Sram close\n");
110 #endif
111
112 if (su->flags & SRF_OPEN) {
113 su->flags = 0;
114 }
115 }
116
117
118 /*ARGSUSED*/
119 int
120 sramioctl (dev, cmd, data, flag, p)
121 dev_t dev;
122 u_long cmd;
123 caddr_t data;
124 int flag;
125 struct proc *p;
126 {
127 int error = 0;
128 struct sram_io *sram_io;
129 register char *sramtop = IODEVbase->io_sram;
130
131 #ifdef DEBUG
132 if (sramdebug & SRAM_DEBUG_IOCTL)
133 printf("Sram ioctl cmd=%lx\n", cmd);
134 #endif
135 sram_io = (struct sram_io *)data;
136
137 switch (cmd) {
138 case SIOGSRAM:
139 #ifdef DEBUG
140 if (sramdebug & SRAM_DEBUG_IOCTL) {
141 printf("Sram ioctl SIOGSRAM address=%p\n", data);
142 printf("Sram ioctl SIOGSRAM offset=%x\n", sram_io->offset);
143 }
144 #endif
145 if (sram_io == NULL ||
146 sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
147 return(EFAULT);
148 bcopy(sramtop + sram_io->offset, &(sram_io->sram), SRAM_IO_SIZE);
149 break;
150 case SIOPSRAM:
151 #ifdef DEBUG
152 if (sramdebug & SRAM_DEBUG_IOCTL) {
153 printf("Sram ioctl SIOSSRAM address=%p\n", data);
154 printf("Sram ioctl SIOSSRAM offset=%x\n", sram_io->offset);
155 }
156 #endif
157 if (sram_io == NULL ||
158 sram_io->offset + SRAM_IO_SIZE > SRAM_SIZE)
159 return(EFAULT);
160 sysport.sramwp = 0x31;
161 bcopy(&(sram_io->sram), sramtop + sram_io->offset,SRAM_IO_SIZE);
162 sysport.sramwp = 0x00;
163 break;
164 default:
165 error = EINVAL;
166 break;
167 }
168 return (error);
169 }
170