/*-
* Copyright (c) 1998, 1999 Nicolas Souchu
* 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 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.
*
* FreeBSD: src/sys/dev/ppbus/ppb_msq.c,v 1.9.2.1 2000/05/24 00:20:57 n_hibma Exp
*
*/
/*
* ppbus_MS_init_msq()
*
* Initialize a microsequence - see macros in ppbus_msq.h
* KNF does not work here, since using '...' requires you use the
* standard C way of function definotion.
*
*/
int
ppbus_MS_init_msq(struct ppbus_microseq * msq, int nbparam, ...)
{
int i;
int param, ins, arg, type;
va_list p_list;
va_start(p_list, nbparam);
for(i = 0; i < nbparam; i++) {
/* retrieve the parameter descriptor */
param = va_arg(p_list, int);
ins = MS_INS(param);
arg = MS_ARG(param);
type = MS_TYP(param);
/* check the instruction position */
if (arg >= PPBUS_MS_MAXARGS)
panic("%s: parameter out of range (0x%x)!", __func__,
param);
#if 0
printf("%s: param = %d, ins = %d, arg = %d, type = %d\n",
__func__, param, ins, arg, type);
#endif
/* properly cast the parameter */
switch (type) {
case MS_TYP_INT:
msq[ins].arg[arg].i = va_arg(p_list, int);
break;
case MS_TYP_CHA:
/* XXX was:
msq[ins].arg[arg].i = (int)va_arg(p_list, char);
which gives warning with gcc 3.3
*/
msq[ins].arg[arg].i = (int)va_arg(p_list, int);
break;
case MS_TYP_PTR:
msq[ins].arg[arg].p = va_arg(p_list, void *);
break;
case MS_TYP_FUN:
msq[ins].arg[arg].f = va_arg(p_list, void *);
break;
/*
* ppbus_MS_microseq()
*
* Interpret a microsequence. Some microinstructions are executed at adapter
* level to avoid function call overhead between ppbus and the adapter
*/
int
ppbus_MS_microseq(device_t dev, device_t busdev,
struct ppbus_microseq * msq, int * ret)
{
struct ppbus_device_softc * ppbdev = device_private(busdev);
struct ppbus_softc * bus = device_private(dev);
struct ppbus_microseq * mi; /* current microinstruction */
size_t cnt;
int error;
struct ppbus_xfer * xfer;
/* microsequence executed to initialize the transfer */
struct ppbus_microseq initxfer[] = {
MS_PTR(MS_UNKNOWN), /* set ptr to buffer */
MS_SET(MS_UNKNOWN), /* set transfer size */
MS_RET(0)
};
mi = msq;
again:
for (;;) {
switch (mi->opcode) {
case MS_OP_PUT:
case MS_OP_GET:
/* attempt to choose the best mode for the device */
xfer = mode2xfer(bus, ppbdev, mi->opcode);
/* figure out if we should use ieee1284 code */
if (!xfer->loop) {
if (mi->opcode == MS_OP_PUT) {
if ((error = ppbus_write(
bus->sc_dev,
(char *)mi->arg[0].p,
mi->arg[1].i, 0, &cnt))) {
goto error;
}
/* XXX should use ppbus_MS_init_msq() */
initxfer[0].arg[0].p = mi->arg[0].p;
initxfer[1].arg[0].i = mi->arg[1].i;
/* initialize transfer */
ppbus_MS_microseq(dev, busdev, initxfer, &error);
if (error)
goto error;
/* the xfer microsequence should not contain any
* MS_OP_PUT or MS_OP_GET!
*/
ppbus_MS_microseq(dev, busdev, xfer->loop, &error);
if (error)
goto error;
INCR_PC;
break;
case MS_OP_RET:
if (ret)
*ret = mi->arg[0].i; /* return code */
return (0);
break;
default:
/* executing microinstructions at ppc level is
* faster. This is the default if the microinstr
* is unknown here
*/
if((error =
bus->ppbus_exec_microseq(
bus->sc_dev, &mi))) {