/*
* Copyright (c) 1998-2004 Michael Shalayeff
* 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.
*
* 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 OR HIS RELATIVES 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 MIND, 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.
*/
/*
* Copyright 1996 1995 by Open Software Foundation, Inc.
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appears in all copies and
* that both the copyright notice and this permission notice appear in
* supporting documentation.
*
* OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
* NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/*
* Copyright (c) 1990 mt Xinu, Inc. All rights reserved.
* Copyright (c) 1990 University of Utah. All rights reserved.
*
* This file may be freely distributed in any form as long as
* this copyright notice is included.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Utah $Hdr: pdc.c 1.8 92/03/14$
*/
/*
* Now that we (may) have an output device, if we encountered
* an error reading Stable Storage (above), let them know.
*/
#ifdef DEBUG
if (debug && err)
printf("Stable storage PDC_STABLE Read Ret'd %d\n", err);
#endif
/*
* Clear the FAULT light (so we know when we get a real one)
*/
(void) (*pdc)(PDC_CHASSIS, PDC_CHASSIS_DISP,
PDC_OSTAT(PDC_OSTAT_BOOT) | 0xCEC0);
}
/*
* Generic READ/WRITE through IODC. Takes pointer to PDC device
* information, returns (positive) number of bytes actually read or
* the (negative) error condition, or zero if at "EOF".
*/
int
iodcstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
size_t *rsize)
{
struct hppa_dev *dp = devdata;
struct pz_device *pzdev = dp->pz_dev;
int offset, xfer, ret;
xfer = 0;
/* see if we can scratch anything from buffer */
if (dp->last_blk <= blk && (dp->last_blk + dp->last_read) > blk) {
twiddle();
offset = blk - dp->last_blk;
xfer = uimin(dp->last_read - offset, size);
size -= xfer;
blk += xfer;
#ifdef PDCDEBUG
if (debug)
printf("off=%d,xfer=%d,size=%d,blk=%d\n",
offset, xfer, (int)size, (int)blk);
#endif
memcpy(buf, dp->buf + offset, xfer);
buf = (char *) buf + xfer;
}
/*
* double buffer it all the time, to cache
*/
for (; size;
size -= ret, buf = (char *) buf + ret, blk += ret, xfer += ret) {
twiddle();
offset = blk & IOPGOFSET;
if ((ret = (pzdev->pz_iodc_io)(pzdev->pz_hpa,
(rw == F_READ? IODC_IO_READ: IODC_IO_WRITE),
pzdev->pz_spa, pzdev->pz_layers, pdcbuf,
(int)blk - offset, dp->buf, IODC_MAXIOSIZ,
IODC_MAXIOSIZ)) < 0) {
#ifdef DEBUG
if (debug)
printf("iodc_read(%d,%d): %d\n",
(int)blk - offset, IODC_MAXIOSIZ, ret);
#endif
if (xfer)
break;
else
return (EIO);
}
if ((ret = pdcbuf[0]) <= 0)
break;
dp->last_blk = blk - offset;
dp->last_read = ret;
if ((ret -= offset) > size)
ret = size;
memcpy(buf, dp->buf + offset, ret);
#ifdef PDCDEBUG
if (debug)
printf("read %d(%d,%d)@%x ", ret,
(int)dp->last_blk, (int)dp->last_read, (u_int)buf);
#endif
}
#ifdef PDCDEBUG
if (debug)
printf("\n");
#endif
if (rsize)
*rsize = xfer;
return (0);
}
/*
* Find a device with specified unit number
* (any if unit == -1), and of specified class (PCL_*).
*/
struct pz_device *
pdc_findev(int unit, int class)
{
static struct pz_device pz;
int layers[sizeof(pz.pz_layers)/sizeof(pz.pz_layers[0])];
iodcio_t iodc;
struct iomod *io;
int err = 0;
#ifdef PDCDEBUG
if (debug)
printf("pdc_finddev(%d, %x)\n", unit, class);
#endif
iodc = (iodcio_t)(PAGE0->mem_free + IODC_MAXSIZE);
io = PAGE0->mem_boot.pz_hpa;
/* quick hack for boot device */
if (PAGE0->mem_boot.pz_class == class &&
(unit == -1 || PAGE0->mem_boot.pz_layers[0] == unit)) {
static inline void
fall(int c_base, int c_count, int c_loop, int c_stride, int data)
{
int loop;
for (; c_count--; c_base += c_stride)
for (loop = c_loop; loop--; )
if (data)
fdce(0, c_base);
else
fice(0, c_base);
}
/*
* fcacheall - Flush all caches.
*
* This routine is just a wrapper around the real cache flush routine.
*/
struct pdc_cache pdc_cacheinfo PDC_ALIGNMENT;