Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Spi support #6

Open
wants to merge 298 commits into
base: apu2_new_uefi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
298 commits
Select commit Hold shift + click to select a range
514fadd
edd extern guid
Sep 21, 2020
17a2730
Add libraries
Sep 21, 2020
523c1c2
fix include
Sep 21, 2020
6a20222
replace guid with NULL
Sep 21, 2020
3a683ef
fix guid
Sep 21, 2020
3dd0737
fix not initialized var
Sep 21, 2020
cb953a0
change log
Sep 21, 2020
9f8b4a4
protocol is null
Sep 21, 2020
2a82460
Add Fvb
Sep 21, 2020
27c3dec
add pkg
Sep 21, 2020
c1b8b4c
move to to guids
Sep 21, 2020
49fc4e7
add libs
Sep 21, 2020
7ac00cd
add deps
Sep 21, 2020
f65497d
remove guid
Sep 21, 2020
e488cc4
remove SMMStoreLib
Sep 21, 2020
46db81b
comment out asserts
Sep 21, 2020
3c9d032
copy some definitions
Sep 21, 2020
179cfe1
fix
Sep 21, 2020
6abaff5
fix typo
Sep 21, 2020
b0816d3
remove CB
Sep 21, 2020
1ac013e
empty problematic function
Sep 21, 2020
4384528
debug
Sep 21, 2020
d12ceff
debug 2
Sep 21, 2020
e3ea223
add debug signature to CR()
Sep 21, 2020
8dcde45
add debug sigs
Sep 21, 2020
fff59d6
remove assert
Sep 21, 2020
0c82b54
remove assert 2
Sep 21, 2020
87efeeb
restore asserts
Sep 22, 2020
a26fd1a
restore asserts
Sep 22, 2020
2df578e
copy inf from another driver
Sep 22, 2020
3c71360
debug fucntions entry
Sep 22, 2020
fa677ae
add more debug
Sep 22, 2020
2dacb59
disable SPI
Sep 22, 2020
91a463b
initialize status
Sep 22, 2020
13c3312
move some debug
Sep 22, 2020
c224848
empty protocol functions
Sep 22, 2020
7937a27
fix void fucntion
Sep 22, 2020
052fdb6
comment out unused code
Sep 22, 2020
4411d86
check guid hob
Sep 22, 2020
30221eb
change driver type to DXE
Sep 22, 2020
94ceed4
add uefi pkg
Sep 22, 2020
6b7acd6
remove redefinition
Sep 22, 2020
09807a6
add hob lib
Sep 22, 2020
3e085a6
add hob lib 2
Sep 22, 2020
ca3a271
remove unused definitions
Sep 22, 2020
87cdfba
install protocol
Sep 22, 2020
ce95917
add fvb initialization
Sep 22, 2020
c43f25e
add memoryallocation include
Sep 22, 2020
f4ed5a2
fix
Sep 22, 2020
b5bad3b
add guid
Sep 22, 2020
78d8020
cast
Sep 22, 2020
a9b3c75
empty protocol fuctions
Sep 22, 2020
b91d4d7
repair reference
Sep 22, 2020
ed69ad8
repair reference 2
Sep 22, 2020
db1c33d
remove unused code
Sep 22, 2020
cdb0b57
check unsigned int size
Sep 22, 2020
dac9430
remove SMM
Sep 23, 2020
16fbc09
add some spi
Sep 23, 2020
e0a6343
add implementation of memset
Sep 23, 2020
2542967
remove string.h
Sep 23, 2020
6dee5ae
fix types
Sep 23, 2020
e09c644
fix types 2
Sep 23, 2020
8a77a97
fix memset
Sep 23, 2020
a6df17f
define region struct
Sep 23, 2020
7319901
fixes
Sep 23, 2020
a83161d
fix types
Sep 23, 2020
997df4f
remove assert.h
Sep 23, 2020
c6e0d0e
fix includes again
Sep 23, 2020
380fd40
some fixes
Sep 23, 2020
6d67717
fix memset
Sep 23, 2020
246871b
fix missing semicolon
Sep 23, 2020
e6dcefa
fix double definition
Sep 23, 2020
76a1241
call spi_setup_slave()
Sep 23, 2020
80f7c87
print result ofcall spi_setup_slave()
Sep 23, 2020
0dbef6e
fix semicolon
Sep 23, 2020
7babc4d
add spi controller
Sep 23, 2020
e2d7994
add files to inf
Sep 23, 2020
bf3ad5f
try fix
Sep 23, 2020
61aeabd
change print format
Sep 23, 2020
6211dfe
add some functions to ctrl
Sep 23, 2020
3da0e4a
implement spi controler
Sep 24, 2020
fc8933e
fix some errors
Sep 24, 2020
e8a2ec3
fix some errors 2
Sep 24, 2020
5dcecd3
fix some errors 3
Sep 24, 2020
6c981e5
fix some errors 4
Sep 24, 2020
1e95508
fix some errors 5
Sep 24, 2020
2db3334
fix some errors 6
Sep 24, 2020
acf2df2
fix some errors 7
Sep 24, 2020
241b457
fix some errors 8
Sep 24, 2020
3ae2006
fix some errors 9
Sep 24, 2020
fa01f26
fix some errors 10
Sep 24, 2020
b2dead4
fix some errors 11
Sep 24, 2020
83ba6c0
fix some errors 12
Sep 24, 2020
9c5dc40
fix some errors 13
Sep 24, 2020
a94154a
fix some errors 14
Sep 25, 2020
8e6ee3d
fix some errors 15
Sep 25, 2020
3f5ad57
fix some errors 16
Sep 25, 2020
86112ad
fix some errors 17
Sep 25, 2020
bb8ff71
fix some errors 18
Sep 25, 2020
aaa5059
fix some errors 19
Sep 25, 2020
535c35d
fix some errors 20
Sep 25, 2020
a5cde05
fix some errors 21
Sep 25, 2020
53cebdc
fix some errors 22
Sep 25, 2020
4a6350a
fix some errors 23
Sep 25, 2020
245c86d
fix some errors 24
Sep 25, 2020
445e21c
fix some errors 25
Sep 25, 2020
eeef282
fix some errors 26
Sep 25, 2020
ed00462
fix some errors 27
Sep 25, 2020
66305cf
fix some errors 28
Sep 25, 2020
54a89f4
fix some errors 29
Sep 25, 2020
b9db4aa
fix some errors 30
Sep 25, 2020
e93baa1
fix some errors 31
Sep 25, 2020
5909a0d
fix some errors 32
Sep 25, 2020
9e6ed2e
fix some errors 33
Sep 25, 2020
05acef0
fix some errors 34
Sep 25, 2020
226a96f
fix some errors 35
Sep 25, 2020
546c762
fix some errors 36
Sep 25, 2020
f1ebf93
fix some errors 37
Sep 25, 2020
368374c
spi_setup_slave
Sep 25, 2020
e0e21bb
spi_xfer
Sep 25, 2020
f160413
change max xfer size
Sep 25, 2020
01af3d5
change max xfer size 2
Sep 25, 2020
e10f307
change max xfer size 3
Sep 25, 2020
f6ef8c2
add debug to spi_init
Sep 28, 2020
536c68a
add some debug
Sep 28, 2020
4219956
add some debug 2
Sep 28, 2020
7959037
add some debug 3
Sep 28, 2020
a95c049
call spi_init
Sep 28, 2020
3219400
typo
Sep 28, 2020
1900a02
add more debug
Sep 28, 2020
943443c
debug
Sep 28, 2020
0db62d1
fix spi_init()
Sep 28, 2020
7408837
fix redefinitions
Sep 28, 2020
b1e8e40
some debug is not working
Sep 28, 2020
85f2bca
port amd, not intel
Sep 28, 2020
87dbb90
add files to .inf
Sep 28, 2020
f40cf58
fix type
Sep 28, 2020
f950a13
missing references
Sep 28, 2020
3cd1b32
add include
Sep 28, 2020
ea423e4
add include 2
Sep 28, 2020
012ed35
add some amdSPI implementation
Sep 29, 2020
d4877a7
fixes
Sep 29, 2020
a43fa74
fixes 2
Sep 29, 2020
519d426
fixes 3
Sep 29, 2020
00add80
fixes 4
Sep 29, 2020
a69468e
fixes 5
Sep 29, 2020
1cffff2
fixes 6
Sep 29, 2020
eade647
fixes 7
Sep 29, 2020
055bd68
fixes 8
Sep 29, 2020
4ba3542
comment out Fvb
Sep 29, 2020
effefc6
implement more
Sep 29, 2020
2846511
add includes, fix types
Sep 29, 2020
75ab148
more implementation
Sep 29, 2020
a6eafb7
remove reference to nonexisiting file
Sep 29, 2020
408a5ab
fixes
Sep 29, 2020
5036966
try to add memset
Sep 29, 2020
2206129
add own memset
Sep 29, 2020
09ec8b9
fix include
Sep 29, 2020
834bd57
fixes 0
Sep 29, 2020
ecf80b2
fixes 1
Sep 29, 2020
5a9a78c
fixes 2
Sep 29, 2020
16ac87c
fixes 3
Sep 29, 2020
e611461
fixes 4
Sep 29, 2020
71528a4
fixes 5
Sep 29, 2020
f420cde
fixes 6
Sep 29, 2020
bba1649
fixes 7
Sep 29, 2020
dc737d1
fixes 8
Sep 29, 2020
f58ddc2
fixes 9
Sep 29, 2020
1e4016e
fixes 10
Sep 29, 2020
8528a9c
fixes 11
Sep 29, 2020
662a043
fixes 12
Sep 29, 2020
fdf4c5c
fixes 13
Sep 29, 2020
496fe80
fix errors
Sep 30, 2020
4270780
fix pointer type
Sep 30, 2020
6b8d057
fix include
Sep 30, 2020
8a54944
fix include
Sep 30, 2020
14d7859
fix types
Sep 30, 2020
0fee411
fix types 2
Sep 30, 2020
9cfce29
fix types 3
Sep 30, 2020
bc79abe
fix
Sep 30, 2020
0fb3629
fix type
Sep 30, 2020
f542216
fix inf
Sep 30, 2020
5670731
fixes
Sep 30, 2020
399e0ac
dummy data to pci_mmconf
Sep 30, 2020
734e5cf
fix static
Sep 30, 2020
e2a0d95
fix types
Sep 30, 2020
c477d7b
fix definitions
Sep 30, 2020
bb64d3f
fix
Sep 30, 2020
b8e1438
fix 1
Sep 30, 2020
932dc18
fix 2
Sep 30, 2020
4f70b54
fix 3
Sep 30, 2020
8a79933
fix 4
Sep 30, 2020
61f3fc8
fix compilation errors
Sep 30, 2020
44841ae
fix compilation errors 2
Sep 30, 2020
70483fa
dummy change
Sep 30, 2020
fe065b5
debug
Sep 30, 2020
90a26d7
REMOVE PROTOCOL INSTALL
Sep 30, 2020
40b62f4
UefiPayloadPkg/SPI/*: Port SPI controller, Initialize PcdFlashNvStora…
Sep 30, 2020
f41dfe1
efiPayloadPkg/SPI/fch_spi_ctrl.c: implement SPI xfer and xfer_vector
Oct 5, 2020
cd6c2b5
UefiPayloadPkg/SPI*: Fix missing SPI BAR address and start porting wi…
Oct 6, 2020
4d3d0bb
Port Winbond and Adesto specific code, fix issues with acquisition of…
Oct 8, 2020
af672bd
try to fix invalid SPI response
Oct 9, 2020
60371cc
UefiPayloadPkg/SPI/Fvb.c: Implement reading from SPI flash memory
Oct 12, 2020
9719bd7
UefiPayloadPkg/SPI/Fvb.h: fix FvbRead, first implement FvbWrite and F…
Oct 13, 2020
cfe64ee
fixes after code review
Oct 14, 2020
a227e15
UefiPayloadPkg/SPI/Fvb.c: Implement FlashErase. FlashWrite is not wor…
Oct 14, 2020
7ce6cf0
UefiPayloadPkg/SPI/Fvb.c: fix FvbWrite
Oct 15, 2020
61e718e
UefiPayloadPkg/SPI/Fvb.c: Fix FvbRead() to accept buffers up to BLOCK…
Oct 15, 2020
4308372
UefiPayloadPkg/SPI/*: Applied review suggestions
Oct 15, 2020
bfe0be8
UefiPayloadPkg/SPI/*: clean the unnecessery code
Oct 15, 2020
ac17469
Revert "UefiPayloadPkg/SPI/*: clean the unnecessery code"
Oct 16, 2020
d2715b7
UefiPayloadPkg/SPI*: cleanup the code
Oct 16, 2020
6ecb3ec
UefiPayloadPkg/SPI/pci_ops.c dekete the file and start using PciLib.h
Oct 16, 2020
1f56fc5
UefiPayloadPkg/SPI/*: delete stopwatch.h and pci_type.h
Oct 16, 2020
a5930e7
UefiPayloadPkg/SPI/* delete device.h, path.h
Oct 16, 2020
5b802f0
UefiPayloadPkg/Library/CbSMMStoreLib/CorebootSMMStore.c: fix compilat…
miczyg1 Oct 16, 2020
e97752e
UefiPayloadPkg/UefiPayloadPkgIa32.dsc: remove SMMStore from build
Oct 19, 2020
dd124d6
Merge branch 'spi' of github.com:3mdeb/edk2 into spi
Oct 19, 2020
23452e0
UefiPayloadPkg/SPI/Fvb.c: Start implementing VariableStoreHeaders
Oct 20, 2020
aa1da81
UefiPayloadPkg/SPI/Fvb.c: style changes
Oct 21, 2020
e40a530
UefiPayloadPkg/SPI/Fvb.c: fix FvbWrite writing only 0x43 bytes
Oct 21, 2020
55b4b94
UefiPayloadPkg/SPI/Fvb.c: Initialize FirmwareVolumeHeader
Oct 22, 2020
4910143
UefiPayloadPkg/SPI/FvbSPI.c Install gEdkiiNvVarStoreFormattedGuid
Oct 22, 2020
c0744ea
UefiPayloadPkg/SPI/Fvb.c: Add gEfiVariableWriteArchProtocolGuid proto…
Oct 23, 2020
0319bae
UefiPayloadPkg: fix build under coreboot-sdk
miczyg1 Oct 26, 2020
8a7bb9a
UefiPayloadPkg: strip unused packages
miczyg1 Oct 26, 2020
9ebbc35
UefiPayloadPkg/UefiPayloadPkg.fdf: fix iPXE include
miczyg1 Oct 26, 2020
1d082d6
UefiPayloadPkg: use COM2 as output port
miczyg1 Oct 27, 2020
38d69b9
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c: …
miczyg1 Oct 27, 2020
e55e77b
UefiPayloadPkg/Library/AmdSpiLib: refactor code from SPI module to Am…
miczyg1 Oct 29, 2020
337fad7
UefiPayloadPkg/AmdSpiDxe: add AmdSpiDxe module to provide FVB protocol
miczyg1 Oct 29, 2020
13d8ae7
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c: …
miczyg1 Oct 29, 2020
b57cc1d
UefiPayloadPkg/Library/AmdSpiLib: clean up the library from debug
miczyg1 Nov 2, 2020
783a152
UefiPayloadPkg/AmdSpiDxe/AmdSpiFvbDxe.c: validate header after intial…
miczyg1 Nov 2, 2020
64ef4ef
UefiPayloadPkg/Library/AmdSpiLib/SPIFlashInternal.c: fix typo
miczyg1 Nov 2, 2020
7d3ae3d
UefiPayloadPkg/AmdSpiDxe/AmdSpiFvbDxe.c: fix build issue
miczyg1 Nov 2, 2020
b948002
UefiPayloadPkg: remove obsolete modules
miczyg1 Nov 2, 2020
86c3aac
UefiPayloadPkg: bring back FaultTolerantWrite
miczyg1 Nov 2, 2020
21f61e3
UefiPayloadPkg: bring back common modules
miczyg1 Nov 2, 2020
e2e3d0d
UefiPayloadPkg: bring back UEFI capsule for DxeCore
miczyg1 Nov 2, 2020
87d9748
UefiPayloadPkg/Library/AmdSpiLib: make AMD SPI more robust
miczyg1 Nov 4, 2020
a43c3da
UefiPayloadPkg/UefiPayloadPkgIa32.dsc: use COM2
miczyg1 Nov 4, 2020
6d83bf4
UefiPayloadPkg/Library/AmdSpiLib/FchSPICtrl.c: remove obsolete function
miczyg1 Nov 4, 2020
0863dd9
UefiPayloadPkg/Library/AmdSpiLib/FchSPICtrl.c: replace spi_read32 wit…
miczyg1 Nov 4, 2020
fddb698
UefiPayloadPkg/Library/AmdSpiLib: fix bugs in the implementation
miczyg1 Nov 5, 2020
13e240a
UefiPayloadPkg/SecureBootEnrollDefaultKeys/SecureBootSetup.c: add debug
miczyg1 Nov 5, 2020
d6c0b60
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe: add debug
miczyg1 Nov 5, 2020
74aa375
UefiPayloadPkg/SecureBootEnrollDefaultKeys/SecureBootSetup: let AuthS…
miczyg1 Nov 5, 2020
a019ca1
UefiPayloadPkg/UefiPayloadPkg.fdf: remove obsolete space
miczyg1 Nov 5, 2020
95c1d9f
UefiPayloadPkg/AmdSpiDxe/AmdSpiFvbDxe.c: change to AuthFormat
miczyg1 Nov 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ InitEmuNonVolatileVariableStore (
@retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Variable Store is corrupted.

**/

EFI_STATUS
InitRealNonVolatileVariableStore (
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec

[LibraryClasses]
MemoryAllocationLib
Expand Down
20 changes: 19 additions & 1 deletion PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ PcRtcInit (
BOOLEAN Enabled;
BOOLEAN Pending;

DEBUG((DEBUG_INFO, "%a\n", __FUNCTION__));
//
// Acquire RTC Lock to make access to RTC atomic
//
Expand Down Expand Up @@ -148,6 +149,7 @@ PcRtcInit (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a: RTC not functional\n", __FUNCTION__));
//
// Set the variable with default value if the RTC is functioning incorrectly.
//
Expand Down Expand Up @@ -233,6 +235,7 @@ PcRtcInit (
//
Status = PcRtcSetTime (&Time, Global);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a: failed to set RTC time\n", __FUNCTION__));
return EFI_DEVICE_ERROR;
}

Expand Down Expand Up @@ -272,8 +275,9 @@ PcRtcInit (
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
EfiReleaseLock (&Global->RtcLock);
}
DEBUG((DEBUG_INFO, "%a: faield to update RTC\n", __FUNCTION__));
return EFI_DEVICE_ERROR;
}

Expand All @@ -293,6 +297,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
DEBUG((DEBUG_INFO, "%a: failed to set variable RTCALARM\n", __FUNCTION__));
return EFI_DEVICE_ERROR;
}

Expand Down Expand Up @@ -366,6 +371,7 @@ PcRtcGetTime (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a RTC did not update\n", __FUNCTION__));
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
Expand Down Expand Up @@ -407,6 +413,7 @@ PcRtcGetTime (
Status = RtcTimeFieldsValid (Time);
}
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a time fields invalid after convert to EFI\n", __FUNCTION__));
return EFI_DEVICE_ERROR;
}

Expand Down Expand Up @@ -458,6 +465,7 @@ PcRtcSetTime (
//
Status = RtcTimeFieldsValid (Time);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a time fields invalid\n", __FUNCTION__));
return Status;
}

Expand All @@ -474,6 +482,7 @@ PcRtcSetTime (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a RTC did not update\n", __FUNCTION__));
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
Expand Down Expand Up @@ -507,6 +516,7 @@ PcRtcSetTime (
}

if (EFI_ERROR (Status)) {
DEBUG((DEBUG_INFO, "%a failed to set variables\n", __FUNCTION__));
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
Expand Down Expand Up @@ -988,6 +998,14 @@ RtcTimeFieldsValid (
Time->Nanosecond > 999999999 ||
(!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||
((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)) {
DEBUG ((DEBUG_INFO, "Year: %04x\n", Time->Year));
DEBUG ((DEBUG_INFO, "Month: %02x\n", Time->Month));
DEBUG ((DEBUG_INFO, "Hour: %02x\n", Time->Hour));
DEBUG ((DEBUG_INFO, "Minute: %02x\n", Time->Minute));
DEBUG ((DEBUG_INFO, "Second: %02x\n", Time->Second));
DEBUG ((DEBUG_INFO, "Nanosecond: %08x\n", Time->Nanosecond));
DEBUG ((DEBUG_INFO, "TimeZone: %d\n", Time->TimeZone));
DEBUG ((DEBUG_INFO, "Daylight: %02x\n", Time->Daylight));
return EFI_INVALID_PARAMETER;
}

Expand Down
7 changes: 6 additions & 1 deletion PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ InitializePcRtc (
EFI_STATUS Status;
EFI_EVENT Event;

DEBUG((DEBUG_INFO, "%a\n", __FUNCTION__));

EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK);
mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress ();

Status = PcRtcInit (&mModuleGlobal);
ASSERT_EFI_ERROR (Status);

DEBUG((DEBUG_INFO, "%a: CreateEventEx1\n", __FUNCTION__));
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
Expand All @@ -144,6 +147,7 @@ InitializePcRtc (
);
ASSERT_EFI_ERROR (Status);

DEBUG((DEBUG_INFO, "%a: CreateEventEx2\n", __FUNCTION__));
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
Expand All @@ -158,7 +162,8 @@ InitializePcRtc (
gRT->SetTime = PcRtcEfiSetTime;
gRT->GetWakeupTime = PcRtcEfiGetWakeupTime;
gRT->SetWakeupTime = PcRtcEfiSetWakeupTime;


DEBUG((DEBUG_INFO, "%a: Install protocol interfaces\n", __FUNCTION__));
Status = gBS->InstallMultipleProtocolInterfaces (
&mHandle,
&gEfiRealTimeClockArchProtocolGuid,
Expand Down
231 changes: 231 additions & 0 deletions UefiPayloadPkg/AmdSpiDxe/AmdSpiDxe.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/** @file AmdSpiStoreDxe.c

Copyright (c) 2020, 3mdeb Embedded Systems Consulting<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Library/AmdSpiLib.h>

#include "AmdSpiDxe.h"

STATIC EFI_EVENT mAmdSpiVirtualAddrChangeEvent;

//
// Global variable declarations
//
AMD_SPI_INSTANCE *mAMDSpiInstance;

AMD_SPI_INSTANCE mAMDSpiInstanceTemplate = {
AMD_SPI_SIGNATURE, // Signature
NULL, // Handle ... NEED TO BE FILLED
{
0, // MediaId ... NEED TO BE FILLED
FALSE, // RemovableMedia
TRUE, // MediaPresent
FALSE, // LogicalPartition
FALSE, // ReadOnly
FALSE, // WriteCaching;
0, // BlockSize ... NEED TO BE FILLED
4, // IoAlign
0, // LastBlock ... NEED TO BE FILLED
0, // LowestAlignedLba
1, // LogicalBlocksPerPhysicalBlock
}, //Media;

{
FvbGetAttributes, // GetAttributes
FvbSetAttributes, // SetAttributes
FvbGetPhysicalAddress, // GetPhysicalAddress
FvbGetBlockSize, // GetBlockSize
FvbRead, // Read
FvbWrite, // Write
FvbEraseBlocks, // EraseBlocks
NULL, //ParentHandle
}, // FvbProtoccol;
{
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End)),
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8)
}
},
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED
},
0, // Index
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{ sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
}
} // DevicePath
};

STATIC
EFI_STATUS
AmdSpiCreateInstance (
IN UINTN NumberofBlocks,
IN UINTN BlockSize,
OUT AMD_SPI_INSTANCE** AMDSpiInstance
)
{
EFI_STATUS Status;
AMD_SPI_INSTANCE* Instance;

ASSERT(AMDSpiInstance != NULL);

Instance = AllocateRuntimeCopyPool (sizeof(AMD_SPI_INSTANCE),&mAMDSpiInstanceTemplate);
if (Instance == NULL) {
return EFI_OUT_OF_RESOURCES;
}

Instance->Media.MediaId = 0;
Instance->Media.BlockSize = BlockSize;
Instance->Media.LastBlock = NumberofBlocks - 1;

CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
Instance->DevicePath.Index = (UINT8)0;

Status = AmdSpiFvbInitialize (Instance);
if (EFI_ERROR(Status)) {
FreePool (Instance);
return Status;
}

Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->Handle,
&gEfiDevicePathProtocolGuid, &Instance->DevicePath,
&gEfiFirmwareVolumeBlockProtocolGuid, &Instance->FvbProtocol,
NULL
);
if (EFI_ERROR(Status)) {
FreePool (Instance);
return Status;
}

DEBUG((DEBUG_INFO, "%a: Created a new instance\n", __FUNCTION__));

*AMDSpiInstance = Instance;
return Status;
}

/**
Fixup internal data so that EFI can be call in virtual mode.
Call the passed in Child Notify event and convert any pointers in
lib to virtual mode.

@param[in] Event The Event that is being processed
@param[in] Context Event Context
**/
VOID
EFIAPI
BlAMDSpiVirtualNotifyEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
{
// Convert Fvb
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.EraseBlocks);
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.GetAttributes);
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.GetBlockSize);
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.Read);
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.SetAttributes);
EfiConvertPointer (0x0, (VOID**)&mAMDSpiInstance->FvbProtocol.Write);

return;
}

EFI_STATUS
EFIAPI
BlAmdSpiInitialise (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;

if (PcdGetBool (PcdEmuVariableNvModeEnable)) {
DEBUG ((DEBUG_WARN, "Variable emulation is active! Skipping driver init.\n"));
return EFI_SUCCESS;
}

Status = AmdSpiInitialize();
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR,"%a: Failed to initialize AmdSpi\n", __FUNCTION__));
PcdSetBoolS (PcdEmuVariableNvModeEnable, TRUE);
return Status;
}

mAMDSpiInstance = AllocateRuntimePool (sizeof(AMD_SPI_INSTANCE*));
if (!mAMDSpiInstance) {
DEBUG((EFI_D_ERROR, "%a: Out of resources\n", __FUNCTION__));
PcdSetBoolS (PcdEmuVariableNvModeEnable, TRUE);
return EFI_OUT_OF_RESOURCES;
}

Status = AmdSpiCreateInstance (3, 0x10000, &mAMDSpiInstance);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "%a: Fail to create instance for AmdSpi\n",
__FUNCTION__));
PcdSetBoolS (PcdEmuVariableNvModeEnable, TRUE);
return Status;
}

//
// Register for the virtual address change event
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
BlAMDSpiVirtualNotifyEvent,
NULL,
&gEfiEventVirtualAddressChangeGuid,
&mAmdSpiVirtualAddrChangeEvent
);
ASSERT_EFI_ERROR (Status);

//
// Mark the memory mapped store as MMIO memory
//
Status = gDS->GetMemorySpaceDescriptor (PcdGet32(PcdFlashNvStorageVariableBase), &GcdDescriptor);
if (EFI_ERROR (Status) || GcdDescriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {
DEBUG((EFI_D_INFO, "%a: No memory space descriptor for com buffer found\n",
__FUNCTION__));

//
// Add a new entry if not covered by existing mapping
//
Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeMemoryMappedIo,
PcdGet32(PcdFlashNvStorageVariableBase),
4 * 0x10000,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
);
ASSERT_EFI_ERROR (Status);
}

//
// Mark as runtime service
//
Status = gDS->SetMemorySpaceAttributes (
PcdGet32(PcdFlashNvStorageVariableBase),
4 * 0x10000,
EFI_MEMORY_RUNTIME
);
ASSERT_EFI_ERROR (Status);

return Status;
}
Loading