/*-
* Copyright (c) 1996, 1997, 1998 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.
*/
/*
* Autoconfiguration and mapping support for the DIO bus.
*/
for (scode = 0; scode < scmax; ) {
if (DIO_INHOLE(scode)) {
scode++;
continue;
}
/*
* Temporarily map the space corresponding to
* the current select code unless:
*/
pa = (bus_addr_t)dio_scodetopa(scode);
if (bus_space_map(bst, pa, PAGE_SIZE, 0, &bsh)) {
aprint_error_dev(self, "can't map scode %d\n", scode);
scode++;
continue;
}
va = bus_space_vaddr(bst, bsh);
/* Check for hardware. */
if (badaddr(va)) {
bus_space_unmap(bst, bsh, PAGE_SIZE);
scode++;
continue;
}
/* Fill out attach args. */
memset(&da, 0, sizeof(da));
da.da_bst = bst;
da.da_scode = scode;
/*
* Return the select code size for this device, defaulting to 1
* if we don't know what kind of device we have.
*/
static int
dio_scodesize(struct dio_attach_args *da)
{
int i;
/*
* Find the dio_devdata matchind the primary id.
* If we're a framebuffer, we also check the secondary id.
*/
for (i = 0; i < DIO_NDEVICES; i++) {
if (da->da_id == dio_devdatas[i].dd_id) {
if (DIO_ISFRAMEBUFFER(da->da_id)) {
if (da->da_secid == dio_devdatas[i].dd_secid) {
goto foundit;
}
} else {
foundit:
return dio_devdatas[i].dd_nscode;
}
}
}
/*
* Device is unknown. Print a warning and assume a default.
*/
aprint_error("WARNING: select code size unknown "
"for id = 0x%x secid = 0x%x\n",
da->da_id, da->da_secid);
return 1;
}
/*
* Return a reasonable description of a DIO device.
*/
static const char *
dio_devinfo(struct dio_attach_args *da, char *buf, size_t buflen)
{
#ifdef DIOVERBOSE
int i;
#endif
memset(buf, 0, buflen);
#ifdef DIOVERBOSE
/*
* Find the description matching our primary id.
* If we're a framebuffer, we also check the secondary id.
*/
for (i = 0; i < DIO_NDEVICES; i++) {
if (da->da_id == dio_devdescs[i].dd_id) {
if (DIO_ISFRAMEBUFFER(da->da_id)) {
if (da->da_secid == dio_devdescs[i].dd_secid) {
goto foundit;
}
} else {
foundit:
snprintf(buf, buflen, "%s",
dio_devdescs[i].dd_desc);
return buf;
}
}
}
#endif /* DIOVERBOSE */
/*
* Enumerate the list of DMA controller users (the HPIB and SCSI
* controllers, essentially), and calculate what the highest
* auto-vector level used by those devices is. Then tell the DMA
* controller to interrupt at that level.
*/
static void
dio_dma_users_changed(void)
{
struct hp300_intrhand *ih;
int ipl = 0;
/*
* Establish an interrupt handler for a DIO device.
*/
void *
dio_intr_establish(int (*func)(void *), void *arg, int ipl, int isrpri)
{
struct hp300_intrhand *ih;
/*
* Remove an interrupt handler for a DIO device.
*/
void
dio_intr_disestablish(void *arg)
{
struct hp300_intrhand *ih = arg;
int isrpri = ih->ih_super.ih_isrpri;
if (isrpri == ISRPRI_BIO) {
LIST_REMOVE(ih, ih_dio_link);
}
intr_disestablish(arg);
if (isrpri == ISRPRI_BIO) {
dio_dma_users_changed();
}
}
/*
* DIO specific bus_space(9) support functions.
*/
static uint8_t dio_bus_space_read_oddbyte_1(bus_space_tag_t,
bus_space_handle_t, bus_size_t);
static void dio_bus_space_write_oddbyte_1(bus_space_tag_t,
bus_space_handle_t, bus_size_t, uint8_t);