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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 
16 **/
17 #include "PchSpi.h"
18 
19 SPI_INSTANCE          *mSpiInstance;
20 
21 CONST UINT32  mSpiRegister[] = {
22     R_QNC_RCRB_SPIS,
23     R_QNC_RCRB_SPIPREOP,
24     R_QNC_RCRB_SPIOPMENU,
25     R_QNC_RCRB_SPIOPMENU + 4
26   };
27 
28 EFI_STATUS
29 EFIAPI
InstallPchSpi(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)30 InstallPchSpi (
31   IN EFI_HANDLE            ImageHandle,
32   IN EFI_SYSTEM_TABLE      *SystemTable
33   )
34 /*++
35 
36 Routine Description:
37 
38   Entry point for the SPI host controller driver.
39 
40 Arguments:
41 
42   ImageHandle       Image handle of this driver.
43   SystemTable       Global system service table.
44 
45 Returns:
46 
47   EFI_SUCCESS           Initialization complete.
48   EFI_UNSUPPORTED       The chipset is unsupported by this driver.
49   EFI_OUT_OF_RESOURCES  Do not have enough resources to initialize the driver.
50   EFI_DEVICE_ERROR      Device error, driver exits abnormally.
51 
52 --*/
53 {
54   EFI_STATUS    Status;
55 
56   //
57   // Allocate pool for SPI protocol instance
58   //
59   Status = gSmst->SmmAllocatePool (
60                     EfiRuntimeServicesData, // MemoryType don't care
61                     sizeof (SPI_INSTANCE),
62                     (VOID **) &mSpiInstance
63                     );
64   if (EFI_ERROR (Status)) {
65     return Status;
66   }
67   if (mSpiInstance == NULL) {
68     return EFI_OUT_OF_RESOURCES;
69   }
70   ZeroMem ((VOID *) mSpiInstance, sizeof (SPI_INSTANCE));
71   //
72   // Initialize the SPI protocol instance
73   //
74   Status = SpiProtocolConstructor (mSpiInstance);
75   if (EFI_ERROR (Status)) {
76     return Status;
77   }
78 
79   //
80   // Install the SMM EFI_SPI_PROTOCOL interface
81   //
82   Status = gSmst->SmmInstallProtocolInterface (
83             &(mSpiInstance->Handle),
84             &gEfiSmmSpiProtocolGuid,
85             EFI_NATIVE_INTERFACE,
86             &(mSpiInstance->SpiProtocol)
87             );
88   if (EFI_ERROR (Status)) {
89     gSmst->SmmFreePool (mSpiInstance);
90     return EFI_DEVICE_ERROR;
91   }
92 
93   return EFI_SUCCESS;
94 }
95 
96 VOID
97 EFIAPI
SpiPhaseInit(VOID)98 SpiPhaseInit (
99   VOID
100   )
101 /*++
102 Routine Description:
103 
104   This function is a a hook for Spi Smm phase specific initialization
105 
106 Arguments:
107 
108   None
109 
110 Returns:
111 
112   None
113 
114 --*/
115 {
116   UINTN  Index;
117 
118   //
119   // Save SPI Registers for S3 resume usage
120   //
121   for (Index = 0; Index < sizeof (mSpiRegister) / sizeof (UINT32); Index++) {
122     S3BootScriptSaveMemWrite (
123       S3BootScriptWidthUint32,
124       (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index]),
125       1,
126       (VOID *) (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index])
127       );
128   }
129 }
130