2011-07-26 12:56:26 +04:00
|
|
|
/* $NetBSD: ofrom.c,v 1.23 2011/07/26 08:56:26 mrg Exp $ */
|
1998-05-02 01:18:39 +04:00
|
|
|
|
1998-05-02 01:08:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright 1998
|
|
|
|
* Digital Equipment Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is furnished under license and may be used and
|
|
|
|
* copied only in accordance with the following terms and conditions.
|
|
|
|
* Subject to these conditions, you may download, copy, install,
|
|
|
|
* use, modify and distribute this software in source and/or binary
|
|
|
|
* form. No title or ownership is transferred hereby.
|
|
|
|
*
|
|
|
|
* 1) Any source code used, modified or distributed must reproduce
|
|
|
|
* and retain this copyright notice and list of conditions as
|
|
|
|
* they appear in the source file.
|
|
|
|
*
|
|
|
|
* 2) No right is granted to use any trade name, trademark, or logo of
|
|
|
|
* Digital Equipment Corporation. Neither the "Digital Equipment
|
|
|
|
* Corporation" name nor any trademark or logo of Digital Equipment
|
|
|
|
* Corporation may be used to endorse or promote products derived
|
|
|
|
* from this software without the prior written permission of
|
|
|
|
* Digital Equipment Corporation.
|
|
|
|
*
|
|
|
|
* 3) This software is provided "AS-IS" and any express or implied
|
|
|
|
* warranties, including but not limited to, any implied warranties
|
|
|
|
* of merchantability, fitness for a particular purpose, or
|
|
|
|
* non-infringement are disclaimed. In no event shall DIGITAL be
|
|
|
|
* liable for any damages whatsoever, and in particular, DIGITAL
|
|
|
|
* shall not be liable for special, indirect, consequential, or
|
|
|
|
* incidental damages or damages for lost profits, loss of
|
|
|
|
* revenue or loss of use, whether such damages arise in contract,
|
|
|
|
* negligence, tort, under statute, in equity, at law or otherwise,
|
|
|
|
* even if advised of the possibility of such damage.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX open for writing (for user programs to mmap, and write contents)
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
2011-07-26 12:56:26 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ofrom.c,v 1.23 2011/07/26 08:56:26 mrg Exp $");
|
2003-07-15 06:54:31 +04:00
|
|
|
|
1998-05-02 01:08:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
1998-05-02 01:13:53 +04:00
|
|
|
#include <sys/systm.h>
|
1998-05-02 01:08:55 +04:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
2011-07-19 19:07:42 +04:00
|
|
|
#include <sys/bus.h>
|
2000-06-29 12:44:03 +04:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
1998-05-02 01:08:55 +04:00
|
|
|
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
|
|
|
|
struct ofrom_softc {
|
|
|
|
int enabled;
|
2005-01-05 13:25:43 +03:00
|
|
|
paddr_t base;
|
|
|
|
paddr_t size;
|
1998-05-02 01:08:55 +04:00
|
|
|
};
|
|
|
|
|
2011-07-26 12:56:26 +04:00
|
|
|
int ofromprobe(device_t, cfdata_t, void *);
|
|
|
|
void ofromattach(device_t, device_t, void *);
|
1998-05-02 01:08:55 +04:00
|
|
|
|
2011-07-26 12:56:26 +04:00
|
|
|
CFATTACH_DECL_NEW(ofrom, sizeof(struct ofrom_softc),
|
2002-10-02 19:52:22 +04:00
|
|
|
ofromprobe, ofromattach, NULL, NULL);
|
1998-05-02 01:08:55 +04:00
|
|
|
|
1998-05-02 01:13:53 +04:00
|
|
|
extern struct cfdriver ofrom_cd;
|
1998-05-02 01:08:55 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(ofromopen);
|
|
|
|
dev_type_read(ofromrw);
|
|
|
|
dev_type_mmap(ofrommmap);
|
|
|
|
|
|
|
|
const struct cdevsw ofrom_cdevsw = {
|
|
|
|
ofromopen, nullclose, ofromrw, ofromrw, noioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, nopoll, ofrommmap, nokqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1998-05-02 01:08:55 +04:00
|
|
|
|
|
|
|
int
|
2011-07-26 12:56:26 +04:00
|
|
|
ofromprobe(device_t parent, cfdata_t cf, void *aux)
|
1998-05-02 01:08:55 +04:00
|
|
|
{
|
1998-05-02 01:13:53 +04:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
2002-06-08 20:44:14 +04:00
|
|
|
static const char *const compatible_strings[] = { "rom", NULL };
|
1998-05-02 01:08:55 +04:00
|
|
|
|
1998-05-02 01:13:53 +04:00
|
|
|
return (of_compatible(oba->oba_phandle, compatible_strings) == -1) ?
|
1998-05-02 01:08:55 +04:00
|
|
|
0 : 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-07-26 12:56:26 +04:00
|
|
|
ofromattach(device_t parent, device_t self, void *aux)
|
1998-05-02 01:08:55 +04:00
|
|
|
{
|
2011-07-26 12:56:26 +04:00
|
|
|
struct ofrom_softc *sc = device_private(self);
|
1998-05-02 01:13:53 +04:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
1998-05-02 01:08:55 +04:00
|
|
|
char regbuf[8];
|
|
|
|
|
1998-05-02 01:13:53 +04:00
|
|
|
if (OF_getproplen(oba->oba_phandle, "reg") != 8) {
|
1998-05-02 01:08:55 +04:00
|
|
|
printf(": invalid reg property\n");
|
|
|
|
return;
|
|
|
|
}
|
1998-05-02 01:13:53 +04:00
|
|
|
if (OF_getprop(oba->oba_phandle, "reg", regbuf, sizeof regbuf) != 8) {
|
1998-05-02 01:08:55 +04:00
|
|
|
printf(": couldn't read reg property\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->base = of_decode_int(®buf[0]);
|
|
|
|
sc->size = of_decode_int(®buf[4]);
|
|
|
|
sc->enabled = 1;
|
|
|
|
|
1998-05-02 01:13:53 +04:00
|
|
|
printf(": %#lx-%#lx\n", sc->base, sc->base + sc->size - 1);
|
1998-05-02 01:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-12 01:16:28 +04:00
|
|
|
ofromopen(dev_t dev, int oflags, int devtype, struct lwp *l)
|
1998-05-02 01:08:55 +04:00
|
|
|
{
|
|
|
|
struct ofrom_softc *sc;
|
|
|
|
|
2008-06-12 01:16:28 +04:00
|
|
|
sc = device_lookup_private(&ofrom_cd, minor(dev));
|
1998-05-02 01:08:55 +04:00
|
|
|
if (!sc || !sc->enabled)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (oflags & FWRITE)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-12 01:16:28 +04:00
|
|
|
ofromrw(dev_t dev, struct uio *uio, int flags)
|
1998-05-02 01:08:55 +04:00
|
|
|
{
|
|
|
|
struct ofrom_softc *sc;
|
2008-06-12 01:16:28 +04:00
|
|
|
int c, error = 0;
|
1998-05-02 01:08:55 +04:00
|
|
|
struct iovec *iov;
|
2005-01-05 13:25:43 +03:00
|
|
|
paddr_t v;
|
|
|
|
psize_t o;
|
2008-11-08 13:18:10 +03:00
|
|
|
extern kmutex_t memlock;
|
1998-05-02 01:08:55 +04:00
|
|
|
extern char *memhook;
|
|
|
|
|
2008-06-12 01:16:28 +04:00
|
|
|
sc = device_lookup_private(&ofrom_cd, minor(dev));
|
1998-05-02 01:08:55 +04:00
|
|
|
if (!sc || !sc->enabled)
|
|
|
|
return (ENXIO); /* XXX PANIC */
|
|
|
|
|
2008-11-08 13:18:10 +03:00
|
|
|
mutex_enter(&memlock);
|
1998-05-02 01:08:55 +04:00
|
|
|
while (uio->uio_resid > 0 && error == 0) {
|
|
|
|
iov = uio->uio_iov;
|
|
|
|
if (iov->iov_len == 0) {
|
|
|
|
uio->uio_iov++;
|
|
|
|
uio->uio_iovcnt--;
|
|
|
|
if (uio->uio_iovcnt < 0)
|
|
|
|
panic("ofromrw");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since everything is page aligned and no more
|
|
|
|
* than the rest of a page is done at once, we
|
|
|
|
* can just check that the offset isn't too big.
|
|
|
|
*/
|
|
|
|
if (uio->uio_offset >= sc->size)
|
|
|
|
break;
|
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
/* XXX: Use unamanged mapping. */
|
1998-05-02 01:08:55 +04:00
|
|
|
v = sc->base + uio->uio_offset;
|
2005-01-05 13:25:43 +03:00
|
|
|
pmap_enter(pmap_kernel(), (vaddr_t)memhook,
|
1998-05-02 01:08:55 +04:00
|
|
|
trunc_page(v), uio->uio_rw == UIO_READ ?
|
1999-11-13 03:30:26 +03:00
|
|
|
VM_PROT_READ : VM_PROT_WRITE, PMAP_WIRED);
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(pmap_kernel());
|
1998-05-02 01:08:55 +04:00
|
|
|
o = uio->uio_offset & PGOFSET;
|
2003-04-02 08:17:50 +04:00
|
|
|
c = min(uio->uio_resid, (int)(PAGE_SIZE - o));
|
2007-03-04 13:21:25 +03:00
|
|
|
error = uiomove((char *)memhook + o, c, uio);
|
2005-01-05 13:25:43 +03:00
|
|
|
pmap_remove(pmap_kernel(), (vaddr_t)memhook,
|
|
|
|
(vaddr_t)memhook + PAGE_SIZE);
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(pmap_kernel());
|
1998-05-02 01:08:55 +04:00
|
|
|
}
|
2008-11-08 13:18:10 +03:00
|
|
|
mutex_exit(&memlock);
|
1998-05-02 01:08:55 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2000-06-26 08:55:19 +04:00
|
|
|
paddr_t
|
2008-06-12 01:16:28 +04:00
|
|
|
ofrommmap(dev_t dev, off_t off, int prot)
|
1998-05-02 01:08:55 +04:00
|
|
|
{
|
|
|
|
struct ofrom_softc *sc;
|
|
|
|
|
2008-06-12 01:16:28 +04:00
|
|
|
sc = device_lookup_private(&ofrom_cd, minor(dev));
|
1998-05-02 01:08:55 +04:00
|
|
|
if (!sc || !sc->enabled)
|
|
|
|
return (-1); /* XXX PANIC */
|
|
|
|
|
1998-11-19 18:38:20 +03:00
|
|
|
if ((u_int)off >= sc->size)
|
1998-05-02 01:08:55 +04:00
|
|
|
return (-1);
|
|
|
|
|
2002-03-24 06:37:18 +03:00
|
|
|
return arm_btop(sc->base + off);
|
1998-05-02 01:08:55 +04:00
|
|
|
}
|