/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Minoura Makoto.
*
* 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.
*/
static int
scsirom_find(device_t parent, struct intio_attach_args *ia)
{
bus_space_handle_t ioh;
char buf[10];
int which;
int r = -1;
if (ia->ia_addr == scsirom_descr[INTERNAL].addr)
which = INTERNAL;
else if (ia->ia_addr == scsirom_descr[EXTERNAL].addr)
which = EXTERNAL;
else
return -1;
ia->ia_size = 0x1fe0;
if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
return -1;
if (bus_space_map(ia->ia_bst, ia->ia_addr, ia->ia_size, 0, &ioh) < 0)
return -1;
if (badaddr((void *)IIOV(ia->ia_addr+SCSIROM_ID))) {
bus_space_unmap(ia->ia_bst, ioh, ia->ia_size);
return -1;
}
bus_space_read_region_1(ia->ia_bst, ioh, SCSIROM_ID, buf, 6);
if (memcmp(buf, scsirom_descr[which].id, 6) == 0)
r = which;
bus_space_unmap(ia->ia_bst, ioh, ia->ia_size);
return r;
}
static int
scsirom_match(device_t parent, cfdata_t cf, void *aux)
{
struct intio_attach_args *ia = aux;
int r;
if (strcmp(ia->ia_name, "scsirom") != 0)
return 0;
if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) {
ia->ia_addr = scsirom_descr[0].addr;
r = scsirom_find(parent, ia);
if (r == INTERNAL)
return 1;
ia->ia_addr = scsirom_descr[1].addr;
r = scsirom_find(parent, ia);
if (r == EXTERNAL)
return 1;
return 0;
} else if (scsirom_find(parent, ia) >= 0)
return 1;
else
return 0;
}