2003-01-01 03:10:15 +03:00
|
|
|
/* $NetBSD: ofisa.c,v 1.13 2003/01/01 00:10:22 thorpej Exp $ */
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997, 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:24:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-01-01 03:10:15 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ofisa.c,v 1.13 2003/01/01 00:10:22 thorpej Exp $");
|
2001-11-13 10:24:43 +03:00
|
|
|
|
1998-02-07 03:46:45 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/ofisa/ofisavar.h>
|
|
|
|
|
1998-06-11 12:43:01 +04:00
|
|
|
#include "isadma.h"
|
|
|
|
|
1998-02-07 03:46:45 +03:00
|
|
|
#define OFW_MAX_STACK_BUF_SIZE 256
|
|
|
|
|
|
|
|
static int ofisamatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
static void ofisaattach __P((struct device *, struct device *, void *));
|
|
|
|
|
2002-10-01 01:57:46 +04:00
|
|
|
CFATTACH_DECL(ofisa, sizeof(struct device),
|
2002-10-02 20:33:28 +04:00
|
|
|
ofisamatch, ofisaattach, NULL, NULL);
|
1998-02-07 03:46:45 +03:00
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
extern struct cfdriver ofisa_cd;
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
static int ofisaprint __P((void *, const char *));
|
|
|
|
|
|
|
|
static int
|
|
|
|
ofisaprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
1998-03-21 05:06:17 +03:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
1998-02-07 03:46:45 +03:00
|
|
|
char name[64];
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
(void)of_packagename(oba->oba_phandle, name, sizeof name);
|
1998-02-07 03:46:45 +03:00
|
|
|
if (pnp)
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("%s at %s", name, pnp);
|
1998-02-07 03:46:45 +03:00
|
|
|
else
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal(" (%s)", name);
|
1998-02-07 03:46:45 +03:00
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ofisamatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
1998-03-21 05:06:17 +03:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
2002-06-08 21:07:53 +04:00
|
|
|
static const char *const compatible_strings[] = { "pnpPNP,a00", NULL };
|
1998-02-07 03:46:45 +03:00
|
|
|
int rv = 0;
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
if (of_compatible(oba->oba_phandle, compatible_strings) != -1)
|
1998-02-07 03:46:45 +03:00
|
|
|
rv = 5;
|
|
|
|
|
|
|
|
#ifdef _OFISA_MD_MATCH
|
|
|
|
if (!rv)
|
|
|
|
rv = ofisa_md_match(parent, cf, aux);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-10 20:48:21 +04:00
|
|
|
ofisaattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
1998-02-07 03:46:45 +03:00
|
|
|
void *aux;
|
|
|
|
{
|
1998-03-21 05:06:17 +03:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
1998-02-07 03:46:45 +03:00
|
|
|
struct isabus_attach_args iba;
|
|
|
|
struct ofisa_attach_args aa;
|
|
|
|
int child;
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
if (ofisa_get_isabus_data(oba->oba_phandle, &iba) < 0) {
|
1998-02-07 03:46:45 +03:00
|
|
|
printf(": couldn't get essential bus data\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
1998-06-11 12:43:01 +04:00
|
|
|
#if NISADMA > 0
|
1998-06-09 04:02:43 +04:00
|
|
|
/*
|
|
|
|
* Initialize our DMA state.
|
|
|
|
*/
|
|
|
|
isa_dmainit(iba.iba_ic, iba.iba_iot, iba.iba_dmat, self);
|
1998-06-11 12:43:01 +04:00
|
|
|
#endif
|
1998-06-09 04:02:43 +04:00
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
for (child = OF_child(oba->oba_phandle); child;
|
1998-02-07 03:46:45 +03:00
|
|
|
child = OF_peer(child)) {
|
1998-03-21 05:06:17 +03:00
|
|
|
if (ofisa_ignore_child(oba->oba_phandle, child))
|
1998-02-07 03:46:45 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bzero(&aa, sizeof aa);
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
aa.oba.oba_busname = "ofw"; /* XXX */
|
|
|
|
aa.oba.oba_phandle = child;
|
1998-02-07 03:46:45 +03:00
|
|
|
aa.iot = iba.iba_iot;
|
|
|
|
aa.memt = iba.iba_memt;
|
|
|
|
aa.dmat = iba.iba_dmat;
|
|
|
|
aa.ic = iba.iba_ic;
|
|
|
|
|
1998-06-10 20:48:21 +04:00
|
|
|
config_found(self, &aa, ofisaprint);
|
1998-02-07 03:46:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ofisa_reg_count(phandle)
|
|
|
|
int phandle;
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = OF_getproplen(phandle, "reg");
|
|
|
|
|
2001-06-19 17:42:07 +04:00
|
|
|
/* nonexistent or obviously malformed "reg" property */
|
1998-02-07 03:46:45 +03:00
|
|
|
if (len < 0 || (len % 12) != 0)
|
|
|
|
return (-1);
|
|
|
|
return (len / 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ofisa_reg_get(phandle, descp, ndescs)
|
|
|
|
int phandle;
|
|
|
|
struct ofisa_reg_desc *descp;
|
|
|
|
int ndescs;
|
|
|
|
{
|
|
|
|
char *buf, *bp;
|
1998-06-30 04:09:36 +04:00
|
|
|
int i, proplen, allocated, rv;
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
i = ofisa_reg_count(phandle);
|
|
|
|
if (i < 0)
|
|
|
|
return (-1);
|
1998-06-30 04:09:36 +04:00
|
|
|
proplen = i * 12;
|
1998-02-07 03:46:45 +03:00
|
|
|
ndescs = min(ndescs, i);
|
|
|
|
|
|
|
|
i = ndescs * 12;
|
|
|
|
if (i > OFW_MAX_STACK_BUF_SIZE) {
|
|
|
|
buf = malloc(i, M_TEMP, M_WAITOK);
|
|
|
|
allocated = 1;
|
|
|
|
} else {
|
|
|
|
buf = alloca(i);
|
|
|
|
allocated = 0;
|
|
|
|
}
|
|
|
|
|
1998-06-30 04:09:36 +04:00
|
|
|
if (OF_getprop(phandle, "reg", buf, i) != proplen) {
|
1998-02-07 03:46:45 +03:00
|
|
|
rv = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, bp = buf; i < ndescs; i++, bp += 12) {
|
|
|
|
if (of_decode_int(&bp[0]) & 1)
|
|
|
|
descp[i].type = OFISA_REG_TYPE_IO;
|
|
|
|
else
|
|
|
|
descp[i].type = OFISA_REG_TYPE_MEM;
|
|
|
|
descp[i].addr = of_decode_int(&bp[4]);
|
|
|
|
descp[i].len = of_decode_int(&bp[8]);
|
|
|
|
}
|
|
|
|
rv = i; /* number of descriptors processed (== ndescs) */
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (allocated)
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ofisa_reg_print(descp, ndescs)
|
|
|
|
struct ofisa_reg_desc *descp;
|
|
|
|
int ndescs;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ndescs == 0) {
|
|
|
|
printf("none");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ndescs; i++) {
|
|
|
|
printf("%s%s 0x%lx/%ld", i ? ", " : "",
|
|
|
|
descp[i].type == OFISA_REG_TYPE_IO ? "io" : "mem",
|
|
|
|
(long)descp[i].addr, (long)descp[i].len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ofisa_intr_count(phandle)
|
|
|
|
int phandle;
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = OF_getproplen(phandle, "interrupts");
|
|
|
|
|
2001-06-19 17:42:07 +04:00
|
|
|
/* nonexistent or obviously malformed "reg" property */
|
1998-02-07 03:46:45 +03:00
|
|
|
if (len < 0 || (len % 8) != 0)
|
|
|
|
return (-1);
|
|
|
|
return (len / 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ofisa_intr_get(phandle, descp, ndescs)
|
|
|
|
int phandle;
|
|
|
|
struct ofisa_intr_desc *descp;
|
|
|
|
int ndescs;
|
|
|
|
{
|
|
|
|
char *buf, *bp;
|
1998-06-30 04:09:36 +04:00
|
|
|
int i, proplen, allocated, rv;
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
i = ofisa_intr_count(phandle);
|
|
|
|
if (i < 0)
|
|
|
|
return (-1);
|
1998-06-30 04:09:36 +04:00
|
|
|
proplen = i * 8;
|
1998-02-07 03:46:45 +03:00
|
|
|
ndescs = min(ndescs, i);
|
|
|
|
|
|
|
|
i = ndescs * 8;
|
|
|
|
if (i > OFW_MAX_STACK_BUF_SIZE) {
|
|
|
|
buf = malloc(i, M_TEMP, M_WAITOK);
|
|
|
|
allocated = 1;
|
|
|
|
} else {
|
|
|
|
buf = alloca(i);
|
|
|
|
allocated = 0;
|
|
|
|
}
|
|
|
|
|
1998-06-30 04:09:36 +04:00
|
|
|
if (OF_getprop(phandle, "interrupts", buf, i) != proplen) {
|
1998-02-07 03:46:45 +03:00
|
|
|
rv = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, bp = buf; i < ndescs; i++, bp += 8) {
|
|
|
|
descp[i].irq = of_decode_int(&bp[0]);
|
|
|
|
switch (of_decode_int(&bp[4])) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
descp[i].share = IST_LEVEL;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
descp[i].share = IST_EDGE;
|
|
|
|
break;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
default:
|
|
|
|
/* Dunno what to do, so fail. */
|
|
|
|
printf("ofisa_intr_get: unknown intrerrupt type %d\n",
|
|
|
|
of_decode_int(&bp[4]));
|
|
|
|
rv = -1;
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv = i; /* number of descriptors processed (== ndescs) */
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (allocated)
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ofisa_intr_print(descp, ndescs)
|
|
|
|
struct ofisa_intr_desc *descp;
|
|
|
|
int ndescs;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ndescs == 0) {
|
|
|
|
printf("none");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ndescs; i++) {
|
|
|
|
printf("%s%d (%s)", i ? ", " : "", descp[i].irq,
|
|
|
|
descp[i].share == IST_LEVEL ? "level" : "edge");
|
|
|
|
}
|
|
|
|
}
|
1998-06-30 04:09:36 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
ofisa_dma_count(phandle)
|
|
|
|
int phandle;
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = OF_getproplen(phandle, "dma");
|
|
|
|
|
2001-06-19 17:42:07 +04:00
|
|
|
/* nonexistent or obviously malformed "reg" property */
|
1998-06-30 04:09:36 +04:00
|
|
|
if (len < 0 || (len % 20) != 0)
|
|
|
|
return (-1);
|
|
|
|
return (len / 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ofisa_dma_get(phandle, descp, ndescs)
|
|
|
|
int phandle;
|
|
|
|
struct ofisa_dma_desc *descp;
|
|
|
|
int ndescs;
|
|
|
|
{
|
|
|
|
char *buf, *bp;
|
|
|
|
int i, proplen, allocated, rv;
|
|
|
|
|
|
|
|
i = ofisa_dma_count(phandle);
|
|
|
|
if (i < 0)
|
|
|
|
return (-1);
|
|
|
|
proplen = i * 20;
|
|
|
|
ndescs = min(ndescs, i);
|
|
|
|
|
|
|
|
i = ndescs * 20;
|
|
|
|
if (i > OFW_MAX_STACK_BUF_SIZE) {
|
|
|
|
buf = malloc(i, M_TEMP, M_WAITOK);
|
|
|
|
allocated = 1;
|
|
|
|
} else {
|
|
|
|
buf = alloca(i);
|
|
|
|
allocated = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OF_getprop(phandle, "dma", buf, i) != proplen) {
|
|
|
|
rv = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, bp = buf; i < ndescs; i++, bp += 20) {
|
|
|
|
descp[i].drq = of_decode_int(&bp[0]);
|
|
|
|
descp[i].mode = of_decode_int(&bp[4]);
|
|
|
|
descp[i].width = of_decode_int(&bp[8]);
|
|
|
|
descp[i].countwidth = of_decode_int(&bp[12]);
|
|
|
|
descp[i].busmaster = of_decode_int(&bp[16]);
|
|
|
|
}
|
|
|
|
rv = i; /* number of descriptors processed (== ndescs) */
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (allocated)
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ofisa_dma_print(descp, ndescs)
|
|
|
|
struct ofisa_dma_desc *descp;
|
|
|
|
int ndescs;
|
|
|
|
{
|
|
|
|
char unkmode[16];
|
|
|
|
const char *modestr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ndescs == 0) {
|
|
|
|
printf("none");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ndescs; i++) {
|
|
|
|
switch (descp[i].mode) {
|
|
|
|
case OFISA_DMA_MODE_COMPAT:
|
|
|
|
modestr = "compat";
|
|
|
|
break;
|
|
|
|
case OFISA_DMA_MODE_A:
|
|
|
|
modestr = "A";
|
|
|
|
break;
|
|
|
|
case OFISA_DMA_MODE_B:
|
|
|
|
modestr = "B";
|
|
|
|
break;
|
|
|
|
case OFISA_DMA_MODE_F:
|
|
|
|
modestr = "F";
|
|
|
|
break;
|
|
|
|
case OFISA_DMA_MODE_C:
|
|
|
|
modestr = "C";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(unkmode, "??? (%d)", descp[i].mode);
|
|
|
|
modestr = unkmode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s%d %s mode %d-bit (%d-bit count)%s", i ? ", " : "",
|
|
|
|
descp[i].drq, modestr, descp[i].width,
|
|
|
|
descp[i].countwidth,
|
|
|
|
descp[i].busmaster ? " busmaster" : "");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|