/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
/*
* Copyright (c) 1982, 1990, 1993
* The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)hpib.c 8.2 (Berkeley) 1/12/94
*/
int hpibtimeout = 100000; /* # of status tests before we give up */
int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */
int hpibdmathresh = 3; /* byte count beyond which to attempt dma */
/*
* HP-IB is essentially an IEEE 488 bus, with an HP command
* set (CS/80 on `newer' devices, Amigo on before-you-were-born
* devices) thrown on top. Devices that respond to CS/80 (and
* probably Amigo, too) are tagged with a 16-bit ID.
*
* HP-IB has a 2-level addressing scheme; slave, the analog
* of a SCSI ID, and punit, the analog of a SCSI LUN. Unforunately,
* IDs are on a per-slave basis; punits are often used for disk
* drives that have an accompanying tape drive on the second punit.
*
* In addition, not all HP-IB devices speak CS/80 or Amigo.
* Examples of such devices are HP-IB plotters, which simply
* take raw plotter commands over 488. These devices do not
* have ID tags, and often the host cannot even tell if such
* a device is attached to the system!
*
* * We nevertheless probe the whole (slave, punit) tuple space, since
* drivers for devices with a unique ID know exactly where to attach;
* and we disallow ``star'' locators for other drivers.
*/
static int
hpibbusmatch(device_t parent, cfdata_t cf, void *aux)
{
/* Initialize the slave request queue. */
TAILQ_INIT(&sc->sc_queue);
/* Attach any devices on the bus. */
hpibbus_attach_children(sc);
}
static void
hpibbus_attach_children(struct hpibbus_softc *sc)
{
struct hpibbus_attach_args ha;
int id, slave, punit;
int i;
for (slave = 0; slave < HPIB_NSLAVES; slave++) {
/*
* Get the ID tag for the device, if any.
* Plotters won't identify themselves, and
* get the same value as non-existent devices.
* However, aging HP-IB drives are slow to respond; try up
* to three times to get a valid ID.
*/
for (i = 0; i < 3; i++) {
id = hpibid(device_unit(sc->sc_dev), slave);
if ((id & 0x200) != 0)
break;
delay(10000);
}
for (punit = 0; punit < HPIB_NPUNITS; punit++) {
/*
* Search through all configured children for this bus.
*/
ha.ha_id = id;
ha.ha_slave = slave;
ha.ha_punit = punit;
config_found(sc->sc_dev, &ha, hpibbusprint,
CFARGS(.submatch = hpibbussubmatch));
}
}
}
static int
hpibbussubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
struct hpibbus_attach_args *ha = aux;
if (cf->hpibbuscf_slave != HPIBBUSCF_SLAVE_DEFAULT &&
cf->hpibbuscf_slave != ha->ha_slave)
return 0;
if (cf->hpibbuscf_punit != HPIBBUSCF_PUNIT_DEFAULT &&
cf->hpibbuscf_punit != ha->ha_punit)
return 0;
int
hpibswait(int unit, int slave)
{
struct hpibbus_softc *sc = device_lookup_private(&hpibbus_cd, unit);
int timo = hpibtimeout;
int mask, (*ppoll)(struct hpibbus_softc *);
void
hpibgo(int unit, int slave, int sec, void *vbuf, int count, int rw, int timo)
{
struct hpibbus_softc *sc = device_lookup_private(&hpibbus_cd,unit);