]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Pci/Dxe/PciPlatform/PciPlatform.c
QuarkPlatformPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkPlatformPkg / Pci / Dxe / PciPlatform / PciPlatform.c
1 /** @file
2 Registers onboard PCI ROMs with PCI.IO
3
4 Copyright (c) 2013-2015 Intel Corporation.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8
9 **/
10
11 #include "CommonHeader.h"
12
13 #include "PciPlatform.h"
14
15
16 PCI_OPTION_ROM_TABLE mPciOptionRomTable[] = {
17 { NULL_ROM_FILE_GUID, 0, 0, 0, 0, 0xffff, 0xffff }
18 };
19 EFI_PCI_PLATFORM_PROTOCOL mPciPlatform = {
20 PhaseNotify,
21 PlatformPrepController,
22 GetPlatformPolicy,
23 GetPciRom
24 };
25
26 EFI_HANDLE mPciPlatformHandle = NULL;
27 EFI_HANDLE mImageHandle = NULL;
28
29
30 EFI_STATUS
31 PhaseNotify (
32 IN EFI_PCI_PLATFORM_PROTOCOL *This,
33 IN EFI_HANDLE HostBridge,
34 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase,
35 IN EFI_PCI_CHIPSET_EXECUTION_PHASE ChipsetPhase
36 )
37 {
38 UINT8 UsbHostBusNumber = IOH_BUS;
39 if (Phase == EfiPciHostBridgeEndResourceAllocation) {
40 // Required for QuarkSouthCluster.
41 // Enable USB controller memory, io and bus master before Ehci driver.
42 EnableUsbMemIoBusMaster (UsbHostBusNumber);
43 return EFI_SUCCESS;
44 }
45 return EFI_UNSUPPORTED;
46 }
47
48
49 EFI_STATUS
50 PlatformPrepController (
51 IN EFI_PCI_PLATFORM_PROTOCOL *This,
52 IN EFI_HANDLE HostBridge,
53 IN EFI_HANDLE RootBridge,
54 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress,
55 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase,
56 IN EFI_PCI_CHIPSET_EXECUTION_PHASE ChipsetPhase
57 )
58 {
59 return EFI_UNSUPPORTED;
60 }
61
62 EFI_STATUS
63 GetPlatformPolicy (
64 IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
65 OUT EFI_PCI_PLATFORM_POLICY *PciPolicy
66 )
67 {
68 if (PciPolicy == NULL) {
69 return EFI_INVALID_PARAMETER;
70 }
71
72 return EFI_UNSUPPORTED;
73 }
74
75 EFI_STATUS
76 GetPciRom (
77 IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
78 IN EFI_HANDLE PciHandle,
79 OUT VOID **RomImage,
80 OUT UINTN *RomSize
81 )
82 /*++
83
84 Routine Description:
85 Return a PCI ROM image for the onboard device represented by PciHandle
86
87 Arguments:
88 This - Protocol instance pointer.
89 PciHandle - PCI device to return the ROM image for.
90 RomImage - PCI Rom Image for onboard device
91 RomSize - Size of RomImage in bytes
92
93 Returns:
94 EFI_SUCCESS - RomImage is valid
95 EFI_NOT_FOUND - No RomImage
96
97 --*/
98 {
99 EFI_STATUS Status;
100 EFI_PCI_IO_PROTOCOL *PciIo;
101 UINTN Segment;
102 UINTN Bus;
103 UINTN Device;
104 UINTN Function;
105 UINT16 VendorId;
106 UINT16 DeviceId;
107 UINT16 DeviceClass;
108 UINTN TableIndex;
109
110 Status = gBS->HandleProtocol (
111 PciHandle,
112 &gEfiPciIoProtocolGuid,
113 (VOID **) &PciIo
114 );
115 if (EFI_ERROR (Status)) {
116 return EFI_NOT_FOUND;
117 }
118
119 PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function);
120
121 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0x0A, 1, &DeviceClass);
122
123 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0, 1, &VendorId);
124
125 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 2, 1, &DeviceId);
126
127 //
128 // Loop through table of video option rom descriptions
129 //
130 for (TableIndex = 0; mPciOptionRomTable[TableIndex].VendorId != 0xffff; TableIndex++) {
131
132 //
133 // See if the PCI device specified by PciHandle matches at device in mPciOptionRomTable
134 //
135 if (VendorId != mPciOptionRomTable[TableIndex].VendorId ||
136 DeviceId != mPciOptionRomTable[TableIndex].DeviceId ||
137 Segment != mPciOptionRomTable[TableIndex].Segment ||
138 Bus != mPciOptionRomTable[TableIndex].Bus ||
139 Device != mPciOptionRomTable[TableIndex].Device ||
140 Function != mPciOptionRomTable[TableIndex].Function) {
141 continue;
142 }
143
144 Status = GetSectionFromFv (
145 &mPciOptionRomTable[TableIndex].FileName,
146 EFI_SECTION_RAW,
147 0,
148 RomImage,
149 RomSize
150 );
151
152 if (EFI_ERROR (Status)) {
153 continue;
154 }
155
156 return EFI_SUCCESS;
157 }
158
159 return EFI_NOT_FOUND;
160 }
161
162 EFI_STATUS
163 PciPlatformDriverEntry (
164 IN EFI_HANDLE ImageHandle,
165 IN EFI_SYSTEM_TABLE *SystemTable
166 )
167 /*++
168
169 Routine Description:
170
171 Arguments:
172 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
173
174 Returns:
175 EFI_STATUS
176
177 --*/
178 {
179 EFI_STATUS Status;
180
181 mImageHandle = ImageHandle;
182
183 //
184 // Install on a new handle
185 //
186 Status = gBS->InstallProtocolInterface (
187 &mPciPlatformHandle,
188 &gEfiPciPlatformProtocolGuid,
189 EFI_NATIVE_INTERFACE,
190 &mPciPlatform
191 );
192
193 return Status;
194 }