blob: cc0d546190d14871cf640e90efa0fb818903c3cc [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/*++
2
3Caution: This file is used for Duet platform only, do not use them in real platform.
4All variable code, variable metadata, and variable data used by Duet platform are on
5disk. They can be changed by user. BIOS is not able to protoect those.
6Duet trusts all meta data from disk. If variable code, variable metadata and variable
7data is modified in inproper way, the behavior is undefined.
8
9Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
10This program and the accompanying materials
11are licensed and made available under the terms and conditions of the BSD License
12which accompanies this distribution. The full text of the license may be found at
13http://opensource.org/licenses/bsd-license.php
14
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17
18Module Name:
19
20 MemStorage.c
21
22Abstract:
23
24 handles variable store/reads with emulated memory
25
26Revision History
27
28--*/
29#include "FSVariable.h"
30
31VOID
32EFIAPI
33OnVirtualAddressChangeMs (
34 IN EFI_EVENT Event,
35 IN VOID *Context
36 );
37
38EFI_STATUS
39EFIAPI
40MemEraseStore(
41 IN VARIABLE_STORAGE *This
42 );
43
44EFI_STATUS
45EFIAPI
46MemWriteStore (
47 IN VARIABLE_STORAGE *This,
48 IN UINTN Offset,
49 IN UINTN BufferSize,
50 IN VOID *Buffer
51 );
52
53EFI_STATUS
54MemStorageConstructor (
55 OUT VARIABLE_STORAGE **VarStore,
56 OUT EFI_EVENT_NOTIFY *GoVirtualEvent,
57 IN UINTN Size
58 )
59{
60 EFI_STATUS Status;
61 VS_DEV *Dev;
62
63 Status = gBS->AllocatePool (EfiRuntimeServicesData, sizeof(VS_DEV), (VOID **) &Dev);
64 ASSERT_EFI_ERROR (Status);
65
66 ZeroMem (Dev, sizeof(VS_DEV));
67
68 Dev->Signature = VS_DEV_SIGNATURE;
69 Dev->Size = Size;
70
71 Dev->VarStore.Erase = MemEraseStore;
72 Dev->VarStore.Write = MemWriteStore;
73
74 Status = gBS->AllocatePool (EfiRuntimeServicesData, Size, (VOID **) &VAR_DATA_PTR (Dev));
75 ASSERT_EFI_ERROR (Status);
76
77 DEBUG ((EFI_D_ERROR, "VStorage: Size = 0x%x\n", Size));
78
79 *VarStore = &Dev->VarStore;
80 *GoVirtualEvent = OnVirtualAddressChangeMs;
81
82 return EFI_SUCCESS;
83}
84
85VOID
86EFIAPI
87OnVirtualAddressChangeMs (
88 IN EFI_EVENT Event,
89 IN VOID *Context
90 )
91{
92 VS_DEV *Dev;
93
94 Dev = DEV_FROM_THIS (Context);
95
96 EfiConvertPointer (0, (VOID **)&VAR_DATA_PTR (Dev));
97 EfiConvertPointer (0, (VOID **)&Dev->VarStore.Erase);
98 EfiConvertPointer (0, (VOID **)&Dev->VarStore.Write);
99}
100
101EFI_STATUS
102EFIAPI
103MemEraseStore(
104 IN VARIABLE_STORAGE *This
105 )
106{
107 VS_DEV *Dev;
108
109 Dev = DEV_FROM_THIS(This);
110 SetMem (VAR_DATA_PTR (Dev), Dev->Size, VAR_DEFAULT_VALUE);
111 return EFI_SUCCESS;
112}
113
114
115EFI_STATUS
116EFIAPI
117MemWriteStore (
118 IN VARIABLE_STORAGE *This,
119 IN UINTN Offset,
120 IN UINTN BufferSize,
121 IN VOID *UserBuffer
122 )
123{
124 VS_DEV *Dev;
125
126 Dev = DEV_FROM_THIS(This);
127
128 ASSERT (Offset + BufferSize < Dev->Size);
129
130 // For better performance
131 if (VAR_DATA_PTR (Dev) + Offset != UserBuffer) {
132 CopyMem (VAR_DATA_PTR (Dev) + Offset, UserBuffer, BufferSize);
133 }
134 return EFI_SUCCESS;
135}