summaryrefslogtreecommitdiff
path: root/sys/arch/pc532/dev/rd.c
blob: e32ea8ec8a5eb6e0d19b73138188c0d3ce6df3ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Copyright (c) 1995 Philip A. Nelson.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Philip A. Nelson.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *	$Id: rd.c,v 1.2 1996/01/12 20:20:38 deraadt Exp $
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/disk.h>

static int rdmatch(struct device *parent, void *cf, void *aux);
static void rdattach(struct device *parent, struct device *self, void *aux);

struct rdsoftc {
	struct	device sc_dev;		/* generic device glue */
	struct	disk sc_dkdev;		/* generic disk glue */
};

struct cfdriver rdcd = {
	NULL,
	"rd",
	rdmatch,
	rdattach,
	DV_DISK,
	sizeof(struct rdsoftc),
	NULL,
	0
};

void rdstrategy __P((struct buf *));

struct dkdriver rddkdriver = { rdstrategy };

#if !defined(RD_SIZE)
#  define RD_SIZE	0x200000
#endif

u_char ram_disk[RD_SIZE] = "Ramdiskorigin";

static int
rdmatch(parent, cf, aux)
	struct device	*parent;
	void		*cf, *aux;
{
	return(((struct cfdata *)cf)->cf_unit == 0);
}

static void
rdattach(parent, self, aux)
	struct device	*parent, *self;
	void		*aux;
{
	struct rdsoftc *sc = (struct rdsoftc *)self;

	printf(" addr 0x%x, size 0x%x\n", ram_disk, RD_SIZE);

	/*
	 * Initialize and attach the disk structure.
	 */
	bzero(&sc->sc_dkdev, sizeof(sc->sc_dkdev));
	sc->sc_dkdev.dk_driver = &rddkdriver;
	sc->sc_dkdev.dk_name = sc->sc_dev.dv_xname;
	disk_attach(&sc->sc_dkdev);
}


/* operational routines */

int
rdopen(dev, flags, devtype, p)
	dev_t		dev;
	int		flags, devtype;
	struct proc	*p;
{
	if (minor(dev) == 0)
		  return(0);
	else
		  return(ENXIO);
}

int
rdclose(dev, flags, devtype, p)
	dev_t		dev;
	int		flags, devtype;
	struct proc	*p;
{
	return(0);
}

int
rdioctl(dev, cmd, addr, flag, p)
	dev_t		dev;
	u_long		cmd;
	int		flag;
	caddr_t 	addr;
	struct proc	*p;
{
	return(ENOTTY);
}

int
rdsize(dev)
	dev_t dev;
{
	if (minor(dev) == 0)
		return(RD_SIZE / DEV_BSIZE);
	else
		return(0);
}

int
rddump(dev, blkno, va, size)
	dev_t dev;
	daddr_t blkno;
	caddr_t va;
	size_t size;
{
	return(ENXIO);
}

void
rdstrategy(bp)
	struct buf *bp;
{
	int loc, size;
	char *adr;

	if (minor(bp->b_dev) == 0)
		loc = bp->b_blkno * DEV_BSIZE;
	else {
		bp->b_error = EINVAL;
		bp->b_flags |= B_ERROR;
		return;
	}
	size = bp->b_bcount;
	adr = (char *) bp->b_un.b_addr;
	if (loc + size > sizeof(ram_disk)) {
		bp->b_error = EINVAL;
		bp->b_flags |= B_ERROR;
		return;
	}
	if (bp->b_flags & B_READ)
	      bcopy(&ram_disk[loc], adr, size);
	else
	      bcopy(adr, &ram_disk[loc], size);
	biodone(bp);
}

int
rdread(dev, uio)
	dev_t		dev;
	struct uio	*uio;
{
	return(physio(rdstrategy, NULL, dev, B_READ, minphys, uio));
}

int
rdwrite(dev, uio)
	dev_t		dev;
	struct uio	*uio;
{
	return(physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio));
}