Annotation of sys/arch/mvme88k/dev/sram.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: sram.c,v 1.18 2006/04/26 21:09:48 miod Exp $ */
2:
3: /*
4: * Copyright (c) 1995 Theo de Raadt
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: *
16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: */
27:
28: #include <sys/param.h>
29: #include <sys/ioctl.h>
30: #include <sys/buf.h>
31: #include <sys/systm.h>
32: #include <sys/uio.h>
33: #include <sys/malloc.h>
34: #include <sys/device.h>
35:
36: #include <machine/autoconf.h>
37: #include <machine/conf.h>
38: #include <machine/cpu.h>
39: #include <machine/mioctl.h>
40:
41: #include <mvme88k/dev/memdevs.h>
42:
43: #include <uvm/uvm_extern.h>
44:
45: struct sramsoftc {
46: struct device sc_dev;
47: paddr_t sc_base;
48: size_t sc_len;
49: bus_space_tag_t sc_iot;
50: bus_space_handle_t sc_ioh;
51: };
52:
53: void sramattach(struct device *, struct device *, void *);
54: int srammatch(struct device *, void *, void *);
55:
56: struct cfattach sram_ca = {
57: sizeof(struct sramsoftc), srammatch, sramattach
58: };
59:
60: struct cfdriver sram_cd = {
61: NULL, "sram", DV_DULL
62: };
63:
64: int
65: srammatch(parent, vcf, args)
66: struct device *parent;
67: void *vcf, *args;
68: {
69: if (brdtyp != BRD_187 && brdtyp != BRD_8120) /* The only ones... */
70: return (0);
71:
72: return (1);
73: }
74:
75: void
76: sramattach(parent, self, args)
77: struct device *parent, *self;
78: void *args;
79: {
80: struct confargs *ca = args;
81: struct sramsoftc *sc = (struct sramsoftc *)self;
82: bus_space_handle_t ioh;
83:
84: sc->sc_iot = ca->ca_iot;
85: sc->sc_base = ca->ca_paddr;
86: sc->sc_len = 128 * 1024; /* always 128K */
87:
88: if (bus_space_map(sc->sc_iot, sc->sc_base, sc->sc_len,
89: BUS_SPACE_MAP_LINEAR, &ioh) != 0) {
90: printf(": can't map memory!\n");
91: return;
92: }
93:
94: sc->sc_ioh = ioh;
95:
96: printf(": %dKB\n", sc->sc_len / 1024);
97: }
98:
99: /*ARGSUSED*/
100: int
101: sramopen(dev, flag, mode, p)
102: dev_t dev;
103: int flag, mode;
104: struct proc *p;
105: {
106: if (minor(dev) >= sram_cd.cd_ndevs ||
107: sram_cd.cd_devs[minor(dev)] == NULL)
108: return (ENODEV);
109: return (0);
110: }
111:
112: /*ARGSUSED*/
113: int
114: sramclose(dev, flag, mode, p)
115: dev_t dev;
116: int flag, mode;
117: struct proc *p;
118: {
119:
120: return (0);
121: }
122:
123: /*ARGSUSED*/
124: int
125: sramioctl(dev, cmd, data, flag, p)
126: dev_t dev;
127: u_long cmd;
128: caddr_t data;
129: int flag;
130: struct proc *p;
131: {
132: int unit = minor(dev);
133: struct sramsoftc *sc = (struct sramsoftc *) sram_cd.cd_devs[unit];
134: int error = 0;
135:
136: switch (cmd) {
137: case MIOCGSIZ:
138: *(int *)data = sc->sc_len;
139: break;
140: default:
141: error = ENOTTY;
142: break;
143: }
144: return (error);
145: }
146:
147: /*ARGSUSED*/
148: int
149: sramrw(dev, uio, flags)
150: dev_t dev;
151: struct uio *uio;
152: int flags;
153: {
154: int unit = minor(dev);
155: struct sramsoftc *sc = (struct sramsoftc *) sram_cd.cd_devs[unit];
156:
157: return memdevrw(bus_space_vaddr(sc->sc_iot, sc->sc_ioh),
158: sc->sc_len, uio, flags);
159: }
160:
161: paddr_t
162: srammmap(dev, off, prot)
163: dev_t dev;
164: off_t off;
165: int prot;
166: {
167: int unit = minor(dev);
168: struct sramsoftc *sc = (struct sramsoftc *) sram_cd.cd_devs[unit];
169:
170: if (minor(dev) != 0)
171: return (-1);
172:
173: /* allow access only in RAM */
174: if (off < 0 || off > sc->sc_len)
175: return (-1);
176: return (atop(sc->sc_base + off));
177: }
CVSweb