summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halppc/ppc/pxenviro.c
blob: 92a3f2aa2e00b0a4aed12c6234c62e125139d4ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*++

Copyright (c) 1991-1993  Microsoft Corporation

Module Name:

    pxenviro.c

Abstract:

    This module implements the interface to the HAL get and set
    environment variable routines for a Power PC system.


Author:

    Jim Wooldridge Ported to PowerPC


Environment:

    Kernel mode

Revision History:

--*/


#include "halp.h"
#include "arccodes.h"

#include "prepnvr.h"
#include "fwstatus.h"
#include "fwnvr.h"



KSPIN_LOCK NVRAM_Spinlock;



ARC_STATUS
HalGetEnvironmentVariable (
    IN PCHAR Variable,
    IN USHORT Length,
    OUT PCHAR Buffer
    )

/*++

Routine Description:

    This function locates an environment variable and returns its value.

Arguments:

    Variable - Supplies a pointer to a zero terminated environment variable
        name.

    Length - Supplies the length of the value buffer in bytes.

    Buffer - Supplies a pointer to a buffer that receives the variable value.

Return Value:

    ESUCCESS is returned if the enviroment variable is located. Otherwise,
    ENOENT is returned.

--*/


{

KIRQL Irql;
PUCHAR tmpbuffer;


  //
  // Check input parameters
  //
  if (Variable == NULL ||
     *Variable == 0 ||
     Length < 1 ||
     Buffer == NULL)
    return(ENOENT);

  //
  // Grab control of NVRAM
  //

  KeAcquireSpinLock(&NVRAM_Spinlock, &Irql);

  (VOID)nvr_initialize_object(0, 0);

  if ((tmpbuffer = nvr_get_GE_variable(Variable)) == NULL) {
     KeReleaseSpinLock(&NVRAM_Spinlock, Irql);
     return(ENOENT);
  }

  //
  // Copy the environment variable's value to Buffer
  //

  do {
    *Buffer = *tmpbuffer++;
    if (*Buffer++ == 0) {

      nvr_delete_object();
      KeReleaseSpinLock(&NVRAM_Spinlock, Irql);
      return(ESUCCESS);
    }
  } while (--Length);

  //
  // Truncate the returned string.  The buffer was too short.
  //
  *--Buffer = 0;

  nvr_delete_object();
  KeReleaseSpinLock(&NVRAM_Spinlock, Irql);
  return(ENOMEM);
}

ARC_STATUS
HalSetEnvironmentVariable (
    IN PCHAR Variable,
    IN PCHAR Value
    )

/*++

Routine Description:

    This function creates an environment variable with the specified value.

Arguments:

    Variable - Supplies a pointer to an environment variable name.

    Value - Supplies a pointer to the environment variable value.

Return Value:

    ESUCCESS is returned if the environment variable is created. Otherwise,
    ENOMEM is returned.

--*/


{
 ARC_STATUS ReturnValue;
 KIRQL Irql;



 if (Value == NULL) return(ENOENT);

 KeAcquireSpinLock(&NVRAM_Spinlock, &Irql);     // Grab control of NVRAM

 (VOID)nvr_initialize_object(0, 0);
// (VOID)nvr_initialize_object(nvr_system_type);

 ReturnValue = nvr_set_GE_variable(Variable,Value);

 nvr_delete_object();  // free object created by nvr_init_object

 KeReleaseSpinLock(&NVRAM_Spinlock, Irql);

 return(ReturnValue);
}