isapnp.c revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 1998, Michael Smith
* Copyright (c) 1996, Sujal M. Patel
* 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
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
__FBSDID("$FreeBSD$");
/*
* Machine-independant ISA PnP enumerator implementing a subset of the
* ISA PnP specification.
*/
#include <stand.h>
#include <string.h>
#include <bootstrap.h>
#include <isapnp.h>
static void isapnp_write(int d, int r);
static void isapnp_send_Initiation_LFSR(void);
static int isapnp_get_serial(u_int8_t *p);
static int isapnp_isolation_protocol(void);
static void isapnp_enumerate(void);
/* PnP read data port */
int isapnp_readport = 0;
#define _PNP_ID_LEN 9
struct pnphandler isapnphandler =
{
"ISA bus",
};
static void
isapnp_write(int d, int r)
{
outb (_PNP_ADDRESS, d);
outb (_PNP_WRITE_DATA, r);
}
/*
* Send Initiation LFSR as described in "Plug and Play ISA Specification",
* Intel May 94.
*/
static void
{
int cur, i;
/* Reset the LSFR */
outb(_PNP_ADDRESS, 0);
cur = 0x6a;
for (i = 1; i < 32; i++) {
}
}
/*
* Get the device's serial number. Returns 1 if the serial is valid.
*/
static int
{
for (i = 0; i < 72; i++) {
/* Can't Short Circuit the next evaluation, so 'and' is last */
if (i < 64)
}
return valid;
}
/*
* Fills the buffer with resource info from the device.
* Returns nonzero if the device fails to report
*/
static int
{
int i, j;
for (i = 0; i < len; i++) {
for (j = 0; j < 100; j++) {
break;
delay(1);
}
if (j == 100) {
printf("PnP device failed to report resource data\n");
return(1);
}
}
return(0);
}
/*
* Scan Resource Data for useful information.
*
* We scan the resource data for compatible device IDs and
* identifier strings; we only take the first identifier string
* and assume it's for the card as a whole.
*
* Returns 0 if the scan completed OK, nonzero on error.
*/
static int
{
limit = 1000;
if (PNP_RES_TYPE(tag) == 0) {
/* Small resource */
switch (PNP_SRES_NUM(tag)) {
case COMP_DEVICE_ID:
/* Got a compatible device id resource */
return(1);
case END_TAG:
return(0);
break;
default:
/* Skip this resource */
return(1);
break;
}
} else {
/* Large resource */
return(1);
switch(PNP_LRES_NUM(tag)) {
case ID_STRING_ANSI:
return(1);
}
} else {
}
break;
default:
/* Large resource, skip it */
return(1);
}
}
}
return(1);
}
/*
* Run the isolation protocol. Upon exiting, all cards are aware that
* they should use isapnp_readport as the READ_DATA port.
*/
static int
{
int csn;
int ndevs;
ndevs = 0;
/* Wake up cards without a CSN (ie. all of them) */
isapnp_write(WAKE, 0);
if (isapnp_get_serial(cardid)) {
pi = pnp_allocinfo();
ndevs++;
/* scan the card obtaining all the identifiers it holds */
if (isapnp_scan_resdata(pi)) {
} else {
}
} else {
break;
}
}
/* Move all cards to wait-for-key state */
while (--csn > 0) {
csn--;
}
return(ndevs);
}
/*
* Locate ISA-PnP devices and populate the supplied list.
*/
static void
isapnp_enumerate(void)
{
int pnp_rd_port;
/* Check for I/O port access */
return;
/*
* Validate a possibly-suggested read port value. If the autoscan failed
* last time, this will return us to autoscan mode again.
*/
if ((isapnp_readport > 0) &&
(((isapnp_readport < 0x203) ||
(isapnp_readport > 0x3ff) ||
/* invalid, go look for ourselves */
isapnp_readport = 0;
if (isapnp_readport < 0) {
/* someone is telling us there is no ISA in the system */
return;
} else if (isapnp_readport > 0) {
} else {
/* No clues, look for it ourselves */
/* Look for something, quit when we find it */
if (isapnp_isolation_protocol() > 0)
break;
}
}
}