summaryrefslogtreecommitdiff
path: root/Platform/BroxtonPlatformPkg/Common/Application/SsdtUpdate/SsdtUpdate.c
blob: f63df950bb7885337ae82fa73519ec05978687cc (plain)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/** @file
  Update SSDT table to ACPI table.

  Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include "SsdtUpdate.h"

FV_INPUT_DATA mInputData = {0};

/**
  Read file data from given file name.

  @param[in]  FileName        Pointer the readed given file name.
  @param[out] Buffer          The buffer which read the given file name's data.
  @param[out] BufferSize      The buffer size which read the given file name's data.

  @retval     EFI_SUCCESS     The file data is successfully readed.
  @retval     EFI_ERROR       The file data is unsuccessfully readed.

**/
STATIC
EFI_STATUS
ReadFileData (
  IN  CHAR16   *FileName,
  OUT UINT8    **Buffer,
  OUT UINT32   *BufferSize
  )
{
  EFI_STATUS             Status;
  SHELL_FILE_HANDLE      FileHandle;
  UINT64                 Size;
  VOID                   *NewBuffer;
  UINTN                  ReadSize;

  FileHandle = NULL;
  NewBuffer  = NULL;
  Size = 0;

  Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
  if (EFI_ERROR (Status)) {
    goto Done;
  }

  Status = FileHandleIsDirectory (FileHandle);
  if (!EFI_ERROR (Status)) {
    Status = EFI_NOT_FOUND;
    goto Done;
  }

  Status = FileHandleGetSize (FileHandle, &Size);
  if (EFI_ERROR (Status)) {
    goto Done;
  }

  NewBuffer = AllocatePool ((UINTN) Size);

  ReadSize = (UINTN) Size;
  Status = FileHandleRead (FileHandle, &ReadSize, NewBuffer);
  if (EFI_ERROR (Status)) {
    goto Done;
  } else if (ReadSize != (UINTN) Size) {
    Status = EFI_INVALID_PARAMETER;
    goto Done;
  }

Done:
  if (FileHandle != NULL) {
    ShellCloseFile (&FileHandle);
  }

  if (EFI_ERROR (Status)) {
    if (NewBuffer != NULL) {
      FreePool (NewBuffer);
    }
  } else {
    *Buffer = NewBuffer;
    *BufferSize = (UINT32) Size;
  }

  return Status;
}


/**
  Initialize and publish device in ACPI table.

  @param[in] Table           The pointer to the ACPI table which will be published.
  @param[in] TableSize       The size of ACPI table which will be published.

  @retval    EFI_SUCCESS     The ACPI table is published successfully.
  @retval    Others          The ACPI table is not published.

**/
EFI_STATUS
PublishAcpiTable (
  IN UINT8       *Table,
  IN UINT32      TableSize
  )
{
  EFI_STATUS                     Status;
  EFI_ACPI_TABLE_PROTOCOL        *AcpiTable;
  UINTN                          TableKey;

  //
  // Publish the  ACPI table
  //
  Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable);
  DEBUG ((DEBUG_INFO, " Publish ACPI Table-3\n"));
  ASSERT_EFI_ERROR (Status);

  TableKey = 0;
  Status = AcpiTable->InstallAcpiTable (
                        AcpiTable,
                        (EFI_ACPI_DESCRIPTION_HEADER *) Table,
                        TableSize,
                        &TableKey
                        );
  DEBUG ((DEBUG_INFO, " Publish ACPI Table-4\n"));
  ASSERT_EFI_ERROR (Status);

  return Status;
}


/**
  Init device

  @retval EFI_SUCCESS     Init Devices successfully
  @retval Others          Some error occurs

**/
EFI_STATUS
InitDevice (
  )
{
  //
  // Add device Init here if needed
  //
  return EFI_SUCCESS;
}


/**
  UEFI application entry point which has an interface similar to a
  standard C main function.

  The ShellCEntryLib library instance wrappers the actual UEFI application
  entry point and calls this ShellAppMain function.

  @param[in] Argc        The number of items in Argv.
  @param[in] Argv        Array of pointers to strings.

  @retval    Status

**/
INTN
EFIAPI
 ShellAppMain (
  IN  UINTN      Argc,
  IN  CHAR16     **Argv
  )
{
  EFI_STATUS                     Status;
  UINT8                          *FileBuffer;
  UINT32                         TableSize;

  TableSize         = 0;
  FileBuffer        = NULL;

  //
  // Necessary device Initialization
  //
  Status = InitDevice ();
  if (EFI_ERROR (Status)) {
    return EFI_DEVICE_ERROR;
  }

  StrCpy (mInputData.FileName, Argv[1]);
  Status = ReadFileData (mInputData.FileName, &FileBuffer, &TableSize);

  //
  // Update and publish ACPI table
  //
  Status = PublishAcpiTable (FileBuffer, TableSize);
  ASSERT_EFI_ERROR (Status);

  return Status;
}