]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkNorthCluster/Spi/Smm/PchSpi.c
fe5cde3de7fd33f6888cf129dac18e742277189c
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Spi / Smm / PchSpi.c
1 /** @file
2
3 PCH SPI SMM Driver implements the SPI Host Controller Compatibility Interface.
4
5 Copyright (c) 2013-2015 Intel Corporation.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9
10 **/
11 #include "PchSpi.h"
12
13 SPI_INSTANCE *mSpiInstance;
14
15 CONST UINT32 mSpiRegister[] = {
16 R_QNC_RCRB_SPIS,
17 R_QNC_RCRB_SPIPREOP,
18 R_QNC_RCRB_SPIOPMENU,
19 R_QNC_RCRB_SPIOPMENU + 4
20 };
21
22 EFI_STATUS
23 EFIAPI
24 InstallPchSpi (
25 IN EFI_HANDLE ImageHandle,
26 IN EFI_SYSTEM_TABLE *SystemTable
27 )
28 /*++
29
30 Routine Description:
31
32 Entry point for the SPI host controller driver.
33
34 Arguments:
35
36 ImageHandle Image handle of this driver.
37 SystemTable Global system service table.
38
39 Returns:
40
41 EFI_SUCCESS Initialization complete.
42 EFI_UNSUPPORTED The chipset is unsupported by this driver.
43 EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
44 EFI_DEVICE_ERROR Device error, driver exits abnormally.
45
46 --*/
47 {
48 EFI_STATUS Status;
49
50 //
51 // Allocate pool for SPI protocol instance
52 //
53 Status = gSmst->SmmAllocatePool (
54 EfiRuntimeServicesData, // MemoryType don't care
55 sizeof (SPI_INSTANCE),
56 (VOID **) &mSpiInstance
57 );
58 if (EFI_ERROR (Status)) {
59 return Status;
60 }
61 if (mSpiInstance == NULL) {
62 return EFI_OUT_OF_RESOURCES;
63 }
64 ZeroMem ((VOID *) mSpiInstance, sizeof (SPI_INSTANCE));
65 //
66 // Initialize the SPI protocol instance
67 //
68 Status = SpiProtocolConstructor (mSpiInstance);
69 if (EFI_ERROR (Status)) {
70 return Status;
71 }
72
73 //
74 // Install the SMM EFI_SPI_PROTOCOL interface
75 //
76 Status = gSmst->SmmInstallProtocolInterface (
77 &(mSpiInstance->Handle),
78 &gEfiSmmSpiProtocolGuid,
79 EFI_NATIVE_INTERFACE,
80 &(mSpiInstance->SpiProtocol)
81 );
82 if (EFI_ERROR (Status)) {
83 gSmst->SmmFreePool (mSpiInstance);
84 return EFI_DEVICE_ERROR;
85 }
86
87 return EFI_SUCCESS;
88 }
89
90 VOID
91 EFIAPI
92 SpiPhaseInit (
93 VOID
94 )
95 /*++
96 Routine Description:
97
98 This function is a a hook for Spi Smm phase specific initialization
99
100 Arguments:
101
102 None
103
104 Returns:
105
106 None
107
108 --*/
109 {
110 UINTN Index;
111
112 //
113 // Save SPI Registers for S3 resume usage
114 //
115 for (Index = 0; Index < sizeof (mSpiRegister) / sizeof (UINT32); Index++) {
116 S3BootScriptSaveMemWrite (
117 S3BootScriptWidthUint32,
118 (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index]),
119 1,
120 (VOID *) (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index])
121 );
122 }
123 }