darwin-xnu/bsd/dev/ppc/nvram.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
   3 *
   4 * @APPLE_LICENSE_HEADER_START@
   5 * 
   6 * The contents of this file constitute Original Code as defined in and
   7 * are subject to the Apple Public Source License Version 1.1 (the
   8 * "License").  You may not use this file except in compliance with the
   9 * License.  Please obtain a copy of the License at
  10 * http://www.apple.com/publicsource and read it before using this file.
  11 * 
  12 * This Original Code and all software distributed under the License are
  13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17 * License for the specific language governing rights and limitations
  18 * under the License.
  19 * 
  20 * @APPLE_LICENSE_HEADER_END@
  21 */
  22/*
  23 * BSD driver for Non-volatile RAM.
  24 * Stub functions call the real thing in the Platform Expert.
  25 *
  26 * Suurballe 11 Feb 1999
  27 */
  28
  29#include <sys/types.h>
  30#include <sys/param.h>
  31
  32extern int PEnvopen ( dev_t, int, int, struct proc * );
  33extern int PEnvclose ( dev_t, int, int, struct proc * );
  34extern int PEnvread ( long, int, unsigned char *);
  35extern int PEnvwrite ( long, int, unsigned char * );
  36
  37
  38nvopen(dev, flag, devtype, pp)
  39        dev_t dev;
  40        int flag, devtype;
  41        struct proc *pp;
  42{
  43    return PEnvopen(dev,flag,devtype,pp);
  44}
  45
  46
  47
  48nvclose(dev, flag, mode, pp)
  49        dev_t dev;
  50        int flag, mode;
  51        struct proc *pp;
  52{
  53    return PEnvclose(dev,flag,mode,pp);
  54}
  55
  56
  57
  58nvread(dev, uio, ioflag)
  59        dev_t dev;
  60        struct uio *uio;
  61        int ioflag;
  62{
  63    long offset;
  64    long size;
  65    int c;
  66    unsigned char cc;
  67    long        read = 0;
  68    int error = 0;
  69
  70    offset = uio->uio_offset;
  71    size = uio_resid(uio);
  72
  73    for (read = 0; read < size; read++, offset++)  {
  74        error = PEnvread(offset, 1, &cc);
  75        if ( error ) {
  76            return error;
  77        }
  78        c = (int)cc;
  79        error = ureadc(c, uio);
  80        if (error) {
  81            return error;
  82        }
  83    }
  84    return error;
  85}
  86
  87
  88
  89nvwrite(dev_t dev,  struct uio *uio, int ioflag)
  90{
  91        long offset;
  92        long size;
  93        int c;
  94        unsigned char cc;
  95        long    wrote = 0;
  96        int error = 0;
  97
  98        offset = uio->uio_offset;
  99        size = uio_resid(uio);
 100
 101        for (wrote = 0; wrote < size; wrote++, offset++) {
 102            c = uwritec(uio);
 103            if (c < 0) {
 104                return 0;
 105            }
 106            cc = (unsigned char)c;
 107            error = PEnvwrite(offset, 1, &cc);
 108        }
 109        return error;
 110}
 111
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.