]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/nvram.c
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / dev / ppc / nvram.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * BSD driver for Non-volatile RAM.
30 * Stub functions call the real thing in the Platform Expert.
31 *
32 * Suurballe 11 Feb 1999
33 */
34
35 #include <sys/types.h>
36 #include <sys/param.h>
37
38 extern int PEnvopen ( dev_t, int, int, struct proc * );
39 extern int PEnvclose ( dev_t, int, int, struct proc * );
40 extern int PEnvread ( long, int, unsigned char *);
41 extern int PEnvwrite ( long, int, unsigned char * );
42
43
44 nvopen(dev, flag, devtype, pp)
45 dev_t dev;
46 int flag, devtype;
47 struct proc *pp;
48 {
49 return PEnvopen(dev,flag,devtype,pp);
50 }
51
52
53
54 nvclose(dev, flag, mode, pp)
55 dev_t dev;
56 int flag, mode;
57 struct proc *pp;
58 {
59 return PEnvclose(dev,flag,mode,pp);
60 }
61
62
63
64 nvread(dev, uio, ioflag)
65 dev_t dev;
66 struct uio *uio;
67 int ioflag;
68 {
69 long offset;
70 long size;
71 int c;
72 unsigned char cc;
73 long read = 0;
74 int error = 0;
75
76 offset = uio->uio_offset;
77 size = uio_resid(uio);
78
79 for (read = 0; read < size; read++, offset++) {
80 error = PEnvread(offset, 1, &cc);
81 if ( error ) {
82 return error;
83 }
84 c = (int)cc;
85 error = ureadc(c, uio);
86 if (error) {
87 return error;
88 }
89 }
90 return error;
91 }
92
93
94
95 nvwrite(dev_t dev, struct uio *uio, int ioflag)
96 {
97 long offset;
98 long size;
99 int c;
100 unsigned char cc;
101 long wrote = 0;
102 int error = 0;
103
104 offset = uio->uio_offset;
105 size = uio_resid(uio);
106
107 for (wrote = 0; wrote < size; wrote++, offset++) {
108 c = uwritec(uio);
109 if (c < 0) {
110 return 0;
111 }
112 cc = (unsigned char)c;
113 error = PEnvwrite(offset, 1, &cc);
114 }
115 return error;
116 }