NetBSD/sys/dev/eisa/eisa.c

246 lines
6.7 KiB
C
Raw Normal View History

2000-09-01 21:18:20 +04:00
/* $NetBSD: eisa.c,v 1.23 2000/09/01 17:18:20 ad Exp $ */
/*
* Copyright (c) 1995, 1996 Christopher G. Demetriou
* 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 Christopher G. Demetriou
* for the NetBSD Project.
* 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.
*/
/*
* EISA Bus device
*
* Makes sure an EISA bus is present, and finds and attaches devices
* living on it.
*/
#include "opt_eisaverbose.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/bus.h>
#include <dev/eisa/eisareg.h>
#include <dev/eisa/eisavar.h>
#include <dev/eisa/eisadevs.h>
2000-09-01 21:18:20 +04:00
int eisamatch(struct device *, struct cfdata *, void *);
void eisaattach(struct device *, struct device *, void *);
struct cfattach eisa_ca = {
sizeof(struct device), eisamatch, eisaattach
};
2000-09-01 21:18:20 +04:00
int eisasubmatch(struct device *, struct cfdata *, void *);
int eisaprint(void *, const char *);
void eisa_devinfo(const char *, char *);
int
2000-09-01 21:18:20 +04:00
eisamatch(struct device *parent, struct cfdata *cf, void *aux)
{
struct eisabus_attach_args *eba = aux;
if (strcmp(eba->eba_busname, cf->cf_driver->cd_name))
return (0);
/* XXX check other indicators */
1996-04-06 06:04:00 +04:00
return (1);
}
int
2000-09-01 21:18:20 +04:00
eisaprint(void *aux, const char *pnp)
{
2000-03-30 16:41:09 +04:00
struct eisa_attach_args *ea = aux;
char devinfo[256];
if (pnp) {
eisa_devinfo(ea->ea_idstring, devinfo);
1996-10-13 05:37:04 +04:00
printf("%s at %s", devinfo, pnp);
}
1996-10-13 05:37:04 +04:00
printf(" slot %d", ea->ea_slot);
return (UNCONF);
}
int
2000-09-01 21:18:20 +04:00
eisasubmatch(struct device *parent, struct cfdata *cf, void *aux)
{
struct eisa_attach_args *ea = aux;
if (cf->eisacf_slot != EISA_UNKNOWN_SLOT &&
cf->eisacf_slot != ea->ea_slot)
2000-09-01 21:18:20 +04:00
return (0);
return ((*cf->cf_attach->ca_match)(parent, cf, aux));
}
void
2000-09-01 21:18:20 +04:00
eisaattach(struct device *parent, struct device *self, void *aux)
{
struct eisabus_attach_args *eba = aux;
bus_space_tag_t iot, memt;
bus_dma_tag_t dmat;
eisa_chipset_tag_t ec;
int slot, maxnslots;
eisa_attach_hook(parent, self, eba);
1996-10-13 05:37:04 +04:00
printf("\n");
iot = eba->eba_iot;
memt = eba->eba_memt;
ec = eba->eba_ec;
dmat = eba->eba_dmat;
/*
* Search for and attach subdevices.
*
* Slot 0 is the "motherboard" slot, and the code attaching
* the EISA bus should have already attached an ISA bus there.
*/
maxnslots = eisa_maxslots(ec);
for (slot = 1; slot < maxnslots; slot++) {
struct eisa_attach_args ea;
u_int slotaddr;
bus_space_handle_t slotioh;
int i;
ea.ea_iot = iot;
ea.ea_memt = memt;
ea.ea_ec = ec;
ea.ea_dmat = dmat;
ea.ea_slot = slot;
slotaddr = EISA_SLOT_ADDR(slot);
/*
* Get a mapping for the whole slot-specific address
* space. If we can't, assume nothing's there but warn
* about it.
*/
if (bus_space_map(iot, slotaddr, EISA_SLOT_SIZE, 0, &slotioh)) {
1996-10-13 05:37:04 +04:00
printf("%s: can't map I/O space for slot %d\n",
self->dv_xname, slot);
continue;
}
/* Get the vendor ID bytes */
for (i = 0; i < EISA_NVIDREGS; i++)
ea.ea_vid[i] = bus_space_read_1(iot, slotioh,
EISA_SLOTOFF_VID + i);
/* Check for device existence */
if (EISA_VENDID_NODEV(ea.ea_vid)) {
#if 0
1996-10-13 05:37:04 +04:00
printf("no device at %s slot %d\n", self->dv_xname,
slot);
1996-10-13 05:37:04 +04:00
printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
ea.ea_vid[1]);
#endif
bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
continue;
}
/* And check that the firmware didn't biff something badly */
if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
1996-10-13 05:37:04 +04:00
printf("%s slot %d not configured by BIOS?\n",
self->dv_xname, slot);
bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
continue;
}
/* Get the product ID bytes */
for (i = 0; i < EISA_NPIDREGS; i++)
ea.ea_pid[i] = bus_space_read_1(iot, slotioh,
EISA_SLOTOFF_PID + i);
/* Create the ID string from the vendor and product IDs */
ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
ea.ea_idstring[7] = '\0'; /* sanity */
/* We no longer need the I/O handle; free it. */
bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
/* Attach matching device. */
config_found_sm(self, &ea, eisaprint, eisasubmatch);
}
}
#ifdef EISAVERBOSE
1996-04-06 06:04:00 +04:00
/*
* Descriptions of of known vendors and devices ("products").
1996-04-06 06:04:00 +04:00
*/
struct eisa_knowndev {
int flags;
const char *id, *name;
1996-04-06 06:04:00 +04:00
};
#define EISA_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
#include <dev/eisa/eisadevs_data.h>
2000-09-01 21:18:20 +04:00
#endif /* EISAVEBSOSE */
void
2000-09-01 21:18:20 +04:00
eisa_devinfo(const char *id, char *cp)
{
#ifdef EISAVERBOSE
2000-09-01 21:18:20 +04:00
const char *name;
struct eisa_knowndev *edp;
2000-09-01 21:18:20 +04:00
int match, onlyvendor;
onlyvendor = 0;
name = NULL;
/* find the device in the table, if possible. */
2000-09-01 21:18:20 +04:00
for (edp = eisa_knowndevs; edp->id != NULL; edp++) {
if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
2000-09-01 21:18:20 +04:00
match = (strncmp(edp->id, id, 3) == 0);
else
2000-09-01 21:18:20 +04:00
match = (strcmp(edp->id, id) == 0);
if (match) {
name = edp->name;
onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
break;
}
}
if (name == NULL)
2000-09-01 21:18:20 +04:00
sprintf(cp, "unknown device %s", id);
else if (onlyvendor)
sprintf(cp, "unknown %s device %s", name, id);
else
2000-09-01 21:18:20 +04:00
sprintf(cp, "%s", name);
#else /* EISAVERBOSE */
sprintf(cp, "device %s", id);
#endif /* EISAVERBOSE */
}