]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/ppc/nvram.c
xnu-1228.5.18.tar.gz
[apple/xnu.git] / bsd / dev / ppc / nvram.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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
38extern int PEnvopen ( dev_t, int, int, struct proc * );
39extern int PEnvclose ( dev_t, int, int, struct proc * );
40extern int PEnvread ( long, int, unsigned char *);
41extern int PEnvwrite ( long, int, unsigned char * );
42
43
44nvopen(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
54nvclose(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
64nvread(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;
91447636 77 size = uio_resid(uio);
1c79356b
A
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
95nvwrite(dev_t dev, struct uio *uio, int ioflag)
96{
1c79356b
A
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;
91447636 105 size = uio_resid(uio);
1c79356b
A
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}