/*-
* Copyright (c) 1998, 2001, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum; by Jason R. Thorpe of Wasabi Systems, Inc.
*
* 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.
*/
int
isarescan(device_t self, const char *ifattr, const int *locators)
{
prop_dictionary_t dict;
int locs[ISACF_NLOCS];
bool no_legacy_devices = false;
dict = device_properties(self);
if (prop_dictionary_get_bool(dict, "no-legacy-devices",
&no_legacy_devices) == true) {
aprint_debug_dev(self, "platform reports no legacy devices\n");
return 0;
}
memcpy(locs, locators, sizeof(locs));
/*
* XXX Bus independent code calling this function does not
* know the locator default values. It assumes "-1" for now.
* (should be made available by "config" one day)
* So fixup where the "-1" is not correct.
*/
if (locs[ISACF_SIZE] == -1)
locs[ISACF_SIZE] = ISACF_SIZE_DEFAULT;
if (locs[ISACF_IOSIZ] == -1)
locs[ISACF_IOSIZ] = ISACF_IOSIZ_DEFAULT;
static int
checkattachargs(struct isa_attach_args *ia, const int *loc)
{
int i;
if (ia->ia_nio == 0) {
if (loc[ISACF_PORT] != ISACF_PORT_DEFAULT)
return (0);
} else {
if (loc[ISACF_PORT] != ISACF_PORT_DEFAULT &&
loc[ISACF_PORT] != ia->ia_io[0].ir_addr)
return (0);
}
if (ia->ia_niomem == 0) {
if (loc[ISACF_IOMEM] != ISACF_IOMEM_DEFAULT)
return (0);
} else {
if (loc[ISACF_IOMEM] != ISACF_IOMEM_DEFAULT &&
loc[ISACF_IOMEM] != ia->ia_iomem[0].ir_addr)
return (0);
}
if (ia->ia_nirq == 0) {
if (loc[ISACF_IRQ] != ISACF_IRQ_DEFAULT)
return (0);
} else {
if (loc[ISACF_IRQ] != ISACF_IRQ_DEFAULT &&
loc[ISACF_IRQ] != ia->ia_irq[0].ir_irq)
return (0);
}
if (ia->ia_ndrq == 0) {
if (loc[ISACF_DRQ] != ISACF_DRQ_DEFAULT)
return (0);
if (loc[ISACF_DRQ2] != ISACF_DRQ2_DEFAULT)
return (0);
} else {
for (i = 0; i < 2; i++) {
if (i == ia->ia_ndrq)
break;
if (loc[ISACF_DRQ + i] != ISACF_DRQ_DEFAULT &&
loc[ISACF_DRQ + i] != ia->ia_drq[i].ir_drq)
return (0);
}
for (; i < 2; i++) {
if (loc[ISACF_DRQ + i] != ISACF_DRQ_DEFAULT)
return (0);
}
}
return (1);
}
int
isasubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
struct isa_attach_args *ia = aux;
if (!checkattachargs(ia, cf->cf_loc))
return (0);
return (config_match(parent, cf, aux));
}
int
isaprint(void *aux, const char *isa)
{
struct isa_attach_args *ia = aux;
const char *sep;
int i;
/*
* This block of code only fires if we have a direct-config'd
* device for which there is no driver match.
*/
if (isa != NULL) {
struct isa_pnpname *ipn;