1998-09-05 19:28:07 +04:00
|
|
|
/* $NetBSD: dev_disk.c,v 1.7 1998/09/05 15:28:07 pk Exp $ */
|
1995-06-02 00:37:44 +04:00
|
|
|
|
1998-09-05 19:28:07 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
1995-06-02 00:37:44 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-09-05 19:28:07 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
1995-06-02 00:37:44 +04:00
|
|
|
* 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:
|
1998-09-05 19:28:07 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1995-06-02 00:37:44 +04:00
|
|
|
*
|
1998-09-05 19:28:07 +04:00
|
|
|
* 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.
|
1995-06-02 00:37:44 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This module implements a "raw device" interface suitable for
|
|
|
|
* use by the stand-alone I/O library UFS file-system code, and
|
|
|
|
* possibly for direct access (i.e. boot from tape).
|
|
|
|
*
|
|
|
|
* The implementation is deceptively simple because it uses the
|
|
|
|
* drivers provided by the Sun PROM monitor. Note that only the
|
|
|
|
* PROM driver used to load the boot program is available here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <machine/mon.h>
|
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
#include <stand.h>
|
1995-06-02 00:37:44 +04:00
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
#include "libsa.h"
|
1995-06-02 00:37:44 +04:00
|
|
|
#include "dvma.h"
|
1998-02-05 07:56:24 +03:00
|
|
|
#include "saio.h"
|
|
|
|
|
|
|
|
/* #include "dev_disk.h" XXX - stdarg woes */
|
|
|
|
|
1996-04-10 22:31:14 +04:00
|
|
|
#define RETRY_COUNT 5
|
1995-06-02 00:37:44 +04:00
|
|
|
|
1996-04-10 22:31:14 +04:00
|
|
|
int disk_opencount;
|
1995-10-14 00:44:57 +03:00
|
|
|
struct saioreq disk_ioreq;
|
|
|
|
|
1995-06-02 00:37:44 +04:00
|
|
|
int
|
|
|
|
disk_open(f, devname)
|
|
|
|
struct open_file *f;
|
|
|
|
char *devname; /* Device part of file name (or NULL). */
|
|
|
|
{
|
1995-10-14 00:44:57 +03:00
|
|
|
struct bootparam *bp;
|
|
|
|
struct saioreq *si;
|
1995-06-02 00:37:44 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef DEBUG_PROM
|
1996-04-10 22:31:14 +04:00
|
|
|
if (debug)
|
|
|
|
printf("disk_open: %s\n", devname);
|
1995-06-02 00:37:44 +04:00
|
|
|
#endif
|
|
|
|
|
1995-10-14 00:44:57 +03:00
|
|
|
si = &disk_ioreq;
|
1996-04-10 22:31:14 +04:00
|
|
|
if (disk_opencount == 0) {
|
|
|
|
/*
|
|
|
|
* Setup our part of the saioreq.
|
|
|
|
* (determines what gets opened)
|
|
|
|
*/
|
1997-02-05 20:39:21 +03:00
|
|
|
bp = *romVectorPtr->bootParam;
|
1996-04-10 22:31:14 +04:00
|
|
|
si->si_boottab = bp->bootDevice;
|
|
|
|
si->si_ctlr = bp->ctlrNum;
|
|
|
|
si->si_unit = bp->unitNum;
|
|
|
|
si->si_boff = bp->partNum;
|
|
|
|
if ((error = prom_iopen(si)) != 0)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
disk_opencount++;
|
1995-06-02 00:37:44 +04:00
|
|
|
|
1995-10-14 00:44:57 +03:00
|
|
|
f->f_devdata = si;
|
1995-06-02 00:37:44 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
disk_close(f)
|
|
|
|
struct open_file *f;
|
|
|
|
{
|
1995-10-14 00:44:57 +03:00
|
|
|
struct saioreq *si;
|
1995-06-02 00:37:44 +04:00
|
|
|
|
1996-04-10 22:31:14 +04:00
|
|
|
#ifdef DEBUG_PROM
|
|
|
|
if (debug)
|
|
|
|
printf("disk_close: ocnt=%d\n", disk_opencount);
|
|
|
|
#endif
|
|
|
|
|
1995-10-14 00:44:57 +03:00
|
|
|
si = f->f_devdata;
|
1995-06-02 00:37:44 +04:00
|
|
|
f->f_devdata = NULL;
|
1996-04-10 22:31:14 +04:00
|
|
|
if (disk_opencount <= 0)
|
|
|
|
return 0;
|
|
|
|
if (--disk_opencount == 0)
|
|
|
|
prom_iclose(si);
|
1995-06-02 00:37:44 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
disk_strategy(devdata, flag, dblk, size, buf, rsize)
|
|
|
|
void *devdata;
|
|
|
|
int flag;
|
|
|
|
daddr_t dblk;
|
|
|
|
u_int size;
|
|
|
|
char *buf;
|
|
|
|
u_int *rsize;
|
|
|
|
{
|
|
|
|
struct saioreq *si;
|
|
|
|
struct boottab *ops;
|
|
|
|
char *dmabuf;
|
1996-04-10 22:31:14 +04:00
|
|
|
int retry, si_flag, xcnt;
|
1995-06-02 00:37:44 +04:00
|
|
|
|
|
|
|
si = devdata;
|
|
|
|
ops = si->si_boottab;
|
|
|
|
|
|
|
|
#ifdef DEBUG_PROM
|
1996-04-10 22:31:14 +04:00
|
|
|
if (debug > 1)
|
|
|
|
printf("disk_strategy: size=%d dblk=%d\n", size, dblk);
|
1995-06-02 00:37:44 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
dmabuf = dvma_mapin(buf, size);
|
1996-04-10 22:31:14 +04:00
|
|
|
si_flag = (flag == F_READ) ? SAIO_F_READ : SAIO_F_WRITE;
|
1995-06-02 00:37:44 +04:00
|
|
|
|
1996-04-10 22:31:14 +04:00
|
|
|
/*
|
|
|
|
* The PROM strategy will occasionally return -1 and expect
|
|
|
|
* us to try again. From mouse@Collatz.McRCIM.McGill.EDU
|
|
|
|
*/
|
|
|
|
retry = RETRY_COUNT;
|
|
|
|
do {
|
|
|
|
si->si_bn = dblk;
|
|
|
|
si->si_ma = dmabuf;
|
|
|
|
si->si_cc = size;
|
|
|
|
xcnt = (*ops->b_strategy)(si, si_flag);
|
|
|
|
} while ((xcnt <= 0) && (--retry > 0));
|
1995-06-02 00:37:44 +04:00
|
|
|
|
|
|
|
dvma_mapout(dmabuf, size);
|
|
|
|
|
|
|
|
#ifdef DEBUG_PROM
|
1996-04-10 22:31:14 +04:00
|
|
|
if (debug > 1)
|
|
|
|
printf("disk_strategy: xcnt = %x retries=%d\n",
|
|
|
|
xcnt, RETRY_COUNT - retry);
|
1995-06-02 00:37:44 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (xcnt <= 0)
|
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
*rsize = xcnt;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
disk_ioctl()
|
|
|
|
{
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|