NetBSD/sys/arch/sun3/stand/libsa/promdev.c

154 lines
4.0 KiB
C
Raw Normal View History

1998-02-05 07:56:24 +03:00
/* $NetBSD: promdev.c,v 1.11 1998/02/05 04:57:15 gwr Exp $ */
1995-02-15 01:56:36 +03:00
/*
* Copyright (c) 1995 Gordon W. Ross
1995-02-15 01:56:36 +03:00
* Copyright (c) 1993 Paul Kranenburg
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Paul Kranenburg.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
*/
1998-02-05 07:56:24 +03:00
#include <sys/types.h>
1995-02-15 01:56:36 +03:00
#include <machine/mon.h>
1998-02-05 07:56:24 +03:00
#include <stand.h>
1995-02-15 01:56:36 +03:00
1998-02-05 07:56:24 +03:00
#include "libsa.h"
#include "dvma.h"
#include "saio.h"
1995-02-15 01:56:36 +03:00
1998-02-05 07:56:24 +03:00
int promdev_inuse;
1995-02-15 01:56:36 +03:00
/*
* Note: caller sets the fields:
* si->si_boottab
* si->si_ctlr
* si->si_unit
* si->si_boff
*/
1995-02-15 01:56:36 +03:00
int
prom_iopen(si)
struct saioreq *si;
1995-02-15 01:56:36 +03:00
{
struct boottab *ops;
struct devinfo *dip;
int i, ctlr, error;
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
if (promdev_inuse)
return(EMFILE);
ops = si->si_boottab;
1995-02-15 01:56:36 +03:00
dip = ops->b_devinfo;
ctlr = si->si_ctlr;
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
#ifdef DEBUG_PROM
if (debug) {
printf("Boot device type: %s\n", ops->b_desc);
printf("d_devbytes=%d\n", dip->d_devbytes);
printf("d_dmabytes=%d\n", dip->d_dmabytes);
printf("d_localbytes=%d\n", dip->d_localbytes);
printf("d_devtype=%d\n", dip->d_devtype);
printf("d_maxiobytes=%d\n", dip->d_maxiobytes);
printf("d_stdcount=%d\n", dip->d_stdcount);
for (i = 0; i < dip->d_stdcount; i++)
printf("d_stdaddrs[i]=0x%x\n",
i, dip->d_stdaddrs[0]);
}
1995-06-02 00:37:44 +04:00
#endif
if (dip->d_devbytes && dip->d_stdcount) {
if (ctlr >= dip->d_stdcount) {
printf("Invalid controller number\n");
return(ENXIO);
}
si->si_devaddr = dev_mapin(dip->d_devtype,
dip->d_stdaddrs[ctlr], dip->d_devbytes);
1995-06-02 00:37:44 +04:00
#ifdef DEBUG_PROM
if (debug)
printf("prom_iopen: devaddr=0x%x\n", si->si_devaddr);
1995-02-15 01:56:36 +03:00
#endif
1995-06-02 00:37:44 +04:00
}
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
if (dip->d_dmabytes) {
si->si_dmaaddr = dvma_alloc(dip->d_dmabytes);
1995-06-02 00:37:44 +04:00
#ifdef DEBUG_PROM
if (debug)
printf("prom_iopen: dmaaddr=0x%x\n", si->si_dmaaddr);
1995-06-02 00:37:44 +04:00
#endif
1995-02-15 01:56:36 +03:00
}
1995-06-02 00:37:44 +04:00
if (dip->d_localbytes) {
si->si_devdata = alloc(dip->d_localbytes);
#ifdef DEBUG_PROM
if (debug)
printf("prom_iopen: devdata=0x%x\n", si->si_devdata);
#endif
}
1995-06-02 00:37:44 +04:00
/* OK, call the PROM device open routine. */
#ifdef DEBUG_PROM
if (debug)
printf("prom_iopen: calling prom open...\n");
#endif
1995-02-15 01:56:36 +03:00
error = (*ops->b_open)(si);
if (error != 0) {
1995-06-02 00:37:44 +04:00
printf("prom_iopen: \"%s\" error=%d\n",
ops->b_desc, error);
return (ENXIO);
1995-02-15 01:56:36 +03:00
}
1995-06-02 00:37:44 +04:00
#ifdef DEBUG_PROM
if (debug)
printf("prom_iopen: prom open returned %d\n", error);
1995-06-02 00:37:44 +04:00
#endif
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
promdev_inuse++;
return (0);
1995-02-15 01:56:36 +03:00
}
1995-06-02 00:37:44 +04:00
void
prom_iclose(si)
struct saioreq *si;
1995-02-15 01:56:36 +03:00
{
struct boottab *ops;
1995-06-02 00:37:44 +04:00
struct devinfo *dip;
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
if (promdev_inuse == 0)
return;
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
ops = si->si_boottab;
dip = ops->b_devinfo;
1995-02-15 01:56:36 +03:00
#ifdef DEBUG_PROM
if (debug)
printf("prom_iclose: calling prom close...\n");
#endif
1995-06-02 00:37:44 +04:00
(*ops->b_close)(si);
1995-02-15 01:56:36 +03:00
1995-06-02 00:37:44 +04:00
promdev_inuse = 0;
1995-02-15 01:56:36 +03:00
}