linux/arch/ppc/boot/of1275/call_prom.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 1996-2005 Paul Mackerras.
   3 *
   4 * This program is free software; you can redistribute it and/or
   5 * modify it under the terms of the GNU General Public License
   6 * as published by the Free Software Foundation; either version
   7 * 2 of the License, or (at your option) any later version.
   8 */
   9
  10#include "of1275.h"
  11#include <stdarg.h>
  12
  13int call_prom(const char *service, int nargs, int nret, ...)
  14{
  15        int i;
  16        struct prom_args {
  17                const char *service;
  18                int nargs;
  19                int nret;
  20                unsigned int args[12];
  21        } args;
  22        va_list list;
  23
  24        args.service = service;
  25        args.nargs = nargs;
  26        args.nret = nret;
  27
  28        va_start(list, nret);
  29        for (i = 0; i < nargs; i++)
  30                args.args[i] = va_arg(list, unsigned int);
  31        va_end(list);
  32
  33        for (i = 0; i < nret; i++)
  34                args.args[nargs+i] = 0;
  35
  36        if (of_prom_entry(&args) < 0)
  37                return -1;
  38
  39        return (nret > 0)? args.args[nargs]: 0;
  40}
  41
  42int call_prom_ret(const char *service, int nargs, int nret,
  43                  unsigned int *rets, ...)
  44{
  45        int i;
  46        struct prom_args {
  47                const char *service;
  48                int nargs;
  49                int nret;
  50                unsigned int args[12];
  51        } args;
  52        va_list list;
  53
  54        args.service = service;
  55        args.nargs = nargs;
  56        args.nret = nret;
  57
  58        va_start(list, rets);
  59        for (i = 0; i < nargs; i++)
  60                args.args[i] = va_arg(list, unsigned int);
  61        va_end(list);
  62
  63        for (i = 0; i < nret; i++)
  64                args.args[nargs+i] = 0;
  65
  66        if (of_prom_entry(&args) < 0)
  67                return -1;
  68
  69        if (rets != (void *) 0)
  70                for (i = 1; i < nret; ++i)
  71                        rets[i-1] = args.args[nargs+i];
  72
  73        return (nret > 0)? args.args[nargs]: 0;
  74}
  75