1 /* $NetBSD: sram.c,v 1.17 2008/12/14 02:16:51 isaki Exp $ */
4 * Copyright (c) 1994 Kazuhisa Shimizu.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: sram.c,v 1.17 2008/12/14 02:16:51 isaki Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/ioctl.h>
43 #include <sys/device.h>
45 #include <machine/sram.h>
46 #include <x68k/dev/intiovar.h>
47 #include <x68k/dev/sramvar.h>
49 #define SRAM_ADDR (0xed0000)
52 #define SRAM_DEBUG_OPEN 0x01
53 #define SRAM_DEBUG_CLOSE 0x02
54 #define SRAM_DEBUG_IOCTL 0x04
55 #define SRAM_DEBUG_DONTDOIT 0x08
56 int sramdebug
= SRAM_DEBUG_IOCTL
;
57 #define DPRINTF(flag, msg) do { \
58 if ((sramdebug & (flag))) \
62 #define DPRINTF(flag, msg) /* nothing */
65 int srammatch(device_t
, cfdata_t
, void *);
66 void sramattach(device_t
, device_t
, void *);
68 extern struct cfdriver sram_cd
;
70 dev_type_open(sramopen
);
71 dev_type_close(sramclose
);
72 dev_type_ioctl(sramioctl
);
74 CFATTACH_DECL_NEW(sram
, sizeof(struct sram_softc
),
75 srammatch
, sramattach
, NULL
, NULL
);
77 const struct cdevsw sram_cdevsw
= {
78 sramopen
, sramclose
, noread
, nowrite
, sramioctl
,
79 nostop
, notty
, nopoll
, nommap
, nokqfilter
,
82 static int sram_attached
;
85 * functions for probeing.
88 srammatch(device_t parent
, cfdata_t cf
, void *aux
)
90 struct intio_attach_args
*ia
= aux
;
95 if (ia
->ia_addr
== INTIOCF_ADDR_DEFAULT
)
96 ia
->ia_addr
= SRAM_ADDR
;
99 if (ia
->ia_addr
!= SRAM_ADDR
)
106 sramattach(device_t parent
, device_t self
, void *aux
)
108 struct sram_softc
*sc
= device_private(self
);
109 struct intio_attach_args
*ia
= aux
;
111 bus_space_handle_t ioh
;
115 if (bus_space_map(iot
, ia
->ia_addr
, SRAM_SIZE
, 0, &ioh
))
123 aprint_normal(": 16k bytes accessible\n");
128 aprint_normal(": not accessible\n");
134 sramopen(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
136 struct sram_softc
*sc
;
138 DPRINTF(SRAM_DEBUG_OPEN
, ("Sram open\n"));
140 sc
= device_lookup_private(&sram_cd
, minor(dev
));
144 if (sc
->sc_flags
& SRF_OPEN
)
147 sc
->sc_flags
|= SRF_OPEN
;
149 sc
->sc_flags
|= SRF_READ
;
151 sc
->sc_flags
|= SRF_WRITE
;
158 sramclose(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
160 struct sram_softc
*sc
;
162 DPRINTF(SRAM_DEBUG_CLOSE
, ("Sram close\n"));
164 sc
= device_lookup_private(&sram_cd
, minor(dev
));
168 if (sc
->sc_flags
& SRF_OPEN
) {
171 sc
->sc_flags
&= ~(SRF_READ
|SRF_WRITE
);
178 sramioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
181 struct sram_io
*sram_io
;
182 struct sram_softc
*sc
;
184 DPRINTF(SRAM_DEBUG_IOCTL
, ("Sram ioctl cmd=%lx\n", cmd
));
186 sc
= device_lookup_private(&sram_cd
, minor(dev
));
190 sram_io
= (struct sram_io
*)data
;
196 if ((sc
->sc_flags
& SRF_READ
) == 0)
198 DPRINTF(SRAM_DEBUG_IOCTL
,
199 ("Sram ioctl SIOGSRAM address=%p\n", data
));
200 DPRINTF(SRAM_DEBUG_IOCTL
,
201 ("Sram ioctl SIOGSRAM offset=%x\n", sram_io
->offset
));
202 if (sram_io
->offset
+ SRAM_IO_SIZE
> SRAM_SIZE
)
204 bus_space_read_region_1(sc
->sc_iot
, sc
->sc_ioh
, sram_io
->offset
,
205 (uint8_t *)&sram_io
->sram
, SRAM_IO_SIZE
);
208 if ((sc
->sc_flags
& SRF_WRITE
) == 0)
210 DPRINTF(SRAM_DEBUG_IOCTL
,
211 ("Sram ioctl SIOPSRAM address=%p\n", data
));
212 DPRINTF(SRAM_DEBUG_IOCTL
,
213 ("Sram ioctl SIOPSRAM offset=%x\n", sram_io
->offset
));
214 if (sram_io
->offset
+ SRAM_IO_SIZE
> SRAM_SIZE
)
217 if (sramdebug
& SRAM_DEBUG_DONTDOIT
) {
218 printf("Sram ioctl SIOPSRAM: skipping actual write\n");
222 intio_set_sysport_sramwp(0x31);
223 bus_space_write_region_1(sc
->sc_iot
, sc
->sc_ioh
,
224 sram_io
->offset
, (uint8_t *)&sram_io
->sram
,
226 intio_set_sysport_sramwp(0x00);