NetBSD/sys/dev/vme/vme.c

344 lines
8.2 KiB
C
Raw Normal View History

/* $NetBSD: vme.c,v 1.10 2003/01/01 00:10:27 thorpej Exp $ */
1999-06-30 19:06:05 +04:00
/*
* Copyright (c) 1999
* Matthias Drochner. 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.
1999-06-30 19:06:05 +04:00
* 3. 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.
*
*/
2001-11-13 09:08:32 +03:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vme.c,v 1.10 2003/01/01 00:10:27 thorpej Exp $");
2001-11-13 09:08:32 +03:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
1999-06-30 19:06:05 +04:00
#include <sys/extent.h>
#include <machine/bus.h>
1999-06-30 19:06:05 +04:00
#include <dev/vme/vmereg.h>
#include <dev/vme/vmevar.h>
1999-06-30 19:06:05 +04:00
static void vme_extractlocators __P((int*, struct vme_attach_args*));
static int vmeprint __P((struct vme_attach_args*, char*));
static int vmesubmatch1 __P((struct device*, struct cfdata*, void*));
static int vmesubmatch __P((struct device*, struct cfdata*, void*));
int vmematch __P((struct device *, struct cfdata *, void *));
void vmeattach __P((struct device*, struct device*,void*));
static struct extent *vme_select_map __P((struct vmebus_softc*, vme_am_t));
1999-06-30 19:06:05 +04:00
#ifdef notyet
int vmedetach __P((struct device*));
#endif
1999-06-30 19:06:05 +04:00
#define VME_SLAVE_DUMMYDRV "vme_slv"
#define VME_NUMCFRANGES 3 /* cf. "files.vme" */
2002-10-01 05:25:25 +04:00
CFATTACH_DECL(vme, sizeof(struct vmebus_softc),
2002-10-02 20:51:16 +04:00
vmematch, vmeattach, NULL, NULL);
1999-06-30 19:06:05 +04:00
2002-09-28 00:41:46 +04:00
const struct cfattach vme_slv_ca = {
1999-06-30 19:06:05 +04:00
0 /* never used */
};
static void
vme_extractlocators(loc, aa)
int *loc;
struct vme_attach_args *aa;
{
1999-06-30 19:06:05 +04:00
int i = 0;
1999-06-30 19:06:05 +04:00
/* XXX can't use constants in locators.h this way */
1999-06-30 19:06:05 +04:00
while (i < VME_NUMCFRANGES && i < VME_MAXCFRANGES &&
loc[i] != -1) {
aa->r[i].offset = (vme_addr_t)loc[i];
aa->r[i].size = (vme_size_t)loc[3 + i];
aa->r[i].am = (vme_am_t)loc[6 + i];
i++;
}
aa->numcfranges = i;
aa->ilevel = loc[9];
aa->ivector = loc[10];
}
static int
vmeprint(v, dummy)
struct vme_attach_args *v;
char *dummy;
{
int i;
for (i = 0; i < v->numcfranges; i++) {
aprint_normal(" addr %x", v->r[i].offset);
1999-06-30 19:06:05 +04:00
if (v->r[i].size != -1)
aprint_normal("-%x", v->r[i].offset + v->r[i].size - 1);
1999-06-30 19:06:05 +04:00
if (v->r[i].am != -1)
aprint_normal(" am %02x", v->r[i].am);
1999-06-30 19:06:05 +04:00
}
if (v->ilevel != -1) {
aprint_normal(" irq %d", v->ilevel);
1999-06-30 19:06:05 +04:00
if (v->ivector != -1)
aprint_normal(" vector %x", v->ivector);
1999-06-30 19:06:05 +04:00
}
return (UNCONF);
}
1999-06-30 19:06:05 +04:00
/*
* This looks for a (dummy) vme device "VME_SLAVE_DUMMYDRV".
* A callback provided by the bus's parent is called for every such
* entry in the config database.
* This is a special hack allowing to communicate the address settings
* of the VME master's slave side to its driver via the normal
* configuration mechanism.
* Needed in following cases:
* -DMA windows are hardware settable but not readable by software
* (driver gets offsets for DMA address calculations this way)
* -DMA windows are software settable, but not persistent
* (hardware is set up from config file entry)
* -other adapter VME slave ranges which should be kept track of
* for address space accounting
* In any case, the adapter driver must get the data before VME
* devices are attached.
*/
static int
vmesubmatch1(bus, dev, aux)
struct device *bus;
struct cfdata *dev;
void *aux;
{
struct vmebus_softc *sc = (struct vmebus_softc*)bus;
struct vme_attach_args v;
if (strcmp(dev->cf_name, VME_SLAVE_DUMMYDRV))
1999-06-30 19:06:05 +04:00
return (0);
vme_extractlocators(dev->cf_loc, &v);
v.va_vct = sc->sc_vct; /* for space allocation */
(*sc->slaveconfig)(bus->dv_parent, &v);
return (0);
}
static int
vmesubmatch(bus, dev, aux)
struct device *bus;
struct cfdata *dev;
void *aux;
{
struct vmebus_softc *sc = (struct vmebus_softc*)bus;
struct vme_attach_args v;
if (!strcmp(dev->cf_name, VME_SLAVE_DUMMYDRV))
1999-06-30 19:06:05 +04:00
return (0);
vme_extractlocators(dev->cf_loc, &v);
v.va_vct = sc->sc_vct;
v.va_bdt = sc->sc_bdt;
if (config_match(bus, dev, &v)) {
1999-06-30 19:06:05 +04:00
config_attach(bus, dev, &v, (cfprint_t)vmeprint);
return (1);
}
return (0);
}
int
1999-06-30 19:06:05 +04:00
vmematch(parent, match, aux)
struct device *parent;
1999-06-30 19:06:05 +04:00
struct cfdata *match;
void *aux;
{
1999-06-30 19:06:05 +04:00
return (1);
}
void
vmeattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct vmebus_softc *sc = (struct vmebus_softc *)self;
1999-06-30 19:06:05 +04:00
struct vmebus_attach_args *aa =
(struct vmebus_attach_args*)aux;
1999-06-30 19:06:05 +04:00
sc->sc_vct = aa->va_vct;
sc->sc_bdt = aa->va_bdt;
1999-06-30 19:06:05 +04:00
/* the "bus" are we ourselves */
sc->sc_vct->bus = sc;
1999-06-30 19:06:05 +04:00
sc->slaveconfig = aa->va_slaveconfig;
printf("\n");
/*
* set up address space accounting - assume incomplete decoding
*/
sc->vme32ext = extent_create("vme32", 0, 0xffffffff,
M_DEVBUF, 0, 0, 0);
if (!sc->vme32ext) {
printf("error creating A32 map\n");
return;
}
sc->vme24ext = extent_create("vme24", 0, 0x00ffffff,
M_DEVBUF, 0, 0, 0);
if (!sc->vme24ext) {
printf("error creating A24 map\n");
return;
}
sc->vme16ext = extent_create("vme16", 0, 0x0000ffff,
M_DEVBUF, 0, 0, 0);
if (!sc->vme16ext) {
printf("error creating A16 map\n");
return;
}
if (sc->slaveconfig) {
/* first get info about the bus master's slave side,
if present */
config_search((cfmatch_t)vmesubmatch1, self, 0);
}
config_search((cfmatch_t)vmesubmatch, self, 0);
#ifdef VMEDEBUG
if (sc->vme32ext)
extent_print(sc->vme32ext);
if (sc->vme24ext)
extent_print(sc->vme24ext);
if (sc->vme16ext)
extent_print(sc->vme16ext);
#endif
}
#ifdef notyet
int
vmedetach(dev)
struct device *dev;
{
struct vmebus_softc *sc = (struct vmebus_softc*)dev;
if (sc->slaveconfig) {
/* allow bus master to free its bus ressources */
(*sc->slaveconfig)(dev->dv_parent, 0);
}
/* extent maps should be empty now */
if (sc->vme32ext) {
#ifdef VMEDEBUG
extent_print(sc->vme32ext);
#endif
extent_destroy(sc->vme32ext);
}
if (sc->vme24ext) {
#ifdef VMEDEBUG
extent_print(sc->vme24ext);
#endif
extent_destroy(sc->vme24ext);
}
if (sc->vme16ext) {
#ifdef VMEDEBUG
extent_print(sc->vme16ext);
#endif
extent_destroy(sc->vme16ext);
}
return (0);
}
1999-06-30 19:06:05 +04:00
#endif
static struct extent *
vme_select_map(sc, ams)
struct vmebus_softc *sc;
vme_am_t ams;
{
if ((ams & VME_AM_ADRSIZEMASK) == VME_AM_A32)
return (sc->vme32ext);
else if ((ams & VME_AM_ADRSIZEMASK) == VME_AM_A24)
return (sc->vme24ext);
else if ((ams & VME_AM_ADRSIZEMASK) == VME_AM_A16)
return (sc->vme16ext);
else
return (0);
}
int
_vme_space_alloc(sc, addr, len, ams)
struct vmebus_softc *sc;
vme_addr_t addr;
vme_size_t len;
vme_am_t ams;
{
struct extent *ex;
ex = vme_select_map(sc, ams);
if (!ex)
return (EINVAL);
return (extent_alloc_region(ex, addr, len, EX_NOWAIT));
}
void
_vme_space_free(sc, addr, len, ams)
struct vmebus_softc *sc;
vme_addr_t addr;
vme_size_t len;
vme_am_t ams;
{
struct extent *ex;
ex = vme_select_map(sc, ams);
if (!ex) {
panic("vme_space_free: invalid am %x", ams);
return;
}
extent_free(ex, addr, len, EX_NOWAIT);
}
int
_vme_space_get(sc, len, ams, align, addr)
struct vmebus_softc *sc;
vme_size_t len;
vme_am_t ams;
u_long align;
vme_addr_t *addr;
{
struct extent *ex;
ex = vme_select_map(sc, ams);
if (!ex)
return (EINVAL);
return (extent_alloc(ex, len, align, EX_NOBOUNDARY, EX_NOWAIT,
(u_long *)addr));
}