Update the copyright notice format
[mirror_edk2.git] / Omap35xxPkg / PciEmulation / PciEmulation.h
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _PCI_ROOT_BRIDGE_H_
16 #define _PCI_ROOT_BRIDGE_H_
17
18 #include <PiDxe.h>
19
20 #include <TPS65950.h>
21
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/DxeServicesTableLib.h>
26 #include <Library/IoLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/PciLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UncachedMemoryAllocationLib.h>
32
33 #include <Protocol/EmbeddedExternalDevice.h>
34 #include <Protocol/Cpu.h>
35 #include <Protocol/DevicePath.h>
36 #include <Protocol/PciIo.h>
37 #include <Protocol/PciRootBridgeIo.h>
38 #include <Protocol/PciHostBridgeResourceAllocation.h>
39
40 #include <IndustryStandard/Pci22.h>
41 #include <IndustryStandard/Acpi.h>
42
43 extern EFI_CPU_ARCH_PROTOCOL *gCpu;
44
45 #define EFI_RESOURCE_NONEXISTENT 0xFFFFFFFFFFFFFFFFULL
46 #define EFI_RESOURCE_LESS 0xFFFFFFFFFFFFFFFEULL
47 #define EFI_RESOURCE_SATISFIED 0x0000000000000000ULL
48
49
50 typedef struct {
51 ACPI_HID_DEVICE_PATH AcpiDevicePath;
52 EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
53 } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
54
55
56 #define ACPI_CONFIG_IO 0
57 #define ACPI_CONFIG_MMIO 1
58 #define ACPI_CONFIG_BUS 2
59
60 typedef struct {
61 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR Desc[3];
62 EFI_ACPI_END_TAG_DESCRIPTOR EndDesc;
63 } ACPI_CONFIG_INFO;
64
65
66 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('P', 'c', 'i', 'F')
67
68 typedef struct {
69 UINT32 Signature;
70 EFI_HANDLE Handle;
71 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL Io;
72 EFI_PCI_ROOT_BRIDGE_DEVICE_PATH DevicePath;
73
74 UINT8 StartBus;
75 UINT8 EndBus;
76 UINT16 Type;
77 UINT32 MemoryStart;
78 UINT32 MemorySize;
79 UINTN IoOffset;
80 UINT32 IoStart;
81 UINT32 IoSize;
82 UINT64 PciAttributes;
83
84 ACPI_CONFIG_INFO *Config;
85
86 } PCI_ROOT_BRIDGE;
87
88
89 #define INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) CR (a, PCI_ROOT_BRIDGE, Io, PCI_ROOT_BRIDGE_SIGNATURE)
90
91
92 typedef union {
93 UINT8 volatile *buf;
94 UINT8 volatile *ui8;
95 UINT16 volatile *ui16;
96 UINT32 volatile *ui32;
97 UINT64 volatile *ui64;
98 UINTN volatile ui;
99 } PTR;
100
101
102 typedef struct {
103 EFI_PHYSICAL_ADDRESS HostAddress;
104 EFI_PHYSICAL_ADDRESS DeviceAddress;
105 UINTN NumberOfBytes;
106 EFI_PCI_IO_PROTOCOL_OPERATION Operation;
107
108 } MAP_INFO_INSTANCE;
109
110
111 typedef struct {
112 EFI_PHYSICAL_ADDRESS HostAddress;
113 EFI_PHYSICAL_ADDRESS DeviceAddress;
114 UINTN NumberOfBytes;
115 EFI_PCI_IO_PROTOCOL_OPERATION Operation;
116 } PCI_DMA_MAP;
117
118 EFI_STATUS
119 EFIAPI
120 PciRootBridgeIoPollMem (
121 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
122 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
123 IN UINT64 Address,
124 IN UINT64 Mask,
125 IN UINT64 Value,
126 IN UINT64 Delay,
127 OUT UINT64 *Result
128 );
129
130 EFI_STATUS
131 EFIAPI
132 PciRootBridgeIoPollIo (
133 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
134 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
135 IN UINT64 Address,
136 IN UINT64 Mask,
137 IN UINT64 Value,
138 IN UINT64 Delay,
139 OUT UINT64 *Result
140 );
141
142 EFI_STATUS
143 EFIAPI
144 PciRootBridgeIoMemRead (
145 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
146 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
147 IN UINT64 Address,
148 IN UINTN Count,
149 IN OUT VOID *Buffer
150 );
151
152 EFI_STATUS
153 EFIAPI
154 PciRootBridgeIoMemWrite (
155 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
156 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
157 IN UINT64 Address,
158 IN UINTN Count,
159 IN OUT VOID *Buffer
160 );
161
162 EFI_STATUS
163 EFIAPI
164 PciRootBridgeIoIoRead (
165 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
166 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
167 IN UINT64 UserAddress,
168 IN UINTN Count,
169 IN OUT VOID *UserBuffer
170 );
171
172 EFI_STATUS
173 EFIAPI
174 PciRootBridgeIoIoWrite (
175 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
176 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
177 IN UINT64 UserAddress,
178 IN UINTN Count,
179 IN OUT VOID *UserBuffer
180 );
181
182 EFI_STATUS
183 EFIAPI
184 PciRootBridgeIoCopyMem (
185 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
186 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
187 IN UINT64 DestAddress,
188 IN UINT64 SrcAddress,
189 IN UINTN Count
190 );
191
192 EFI_STATUS
193 EFIAPI
194 PciRootBridgeIoPciRead (
195 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
196 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
197 IN UINT64 Address,
198 IN UINTN Count,
199 IN OUT VOID *Buffer
200 );
201
202 EFI_STATUS
203 EFIAPI
204 PciRootBridgeIoPciWrite (
205 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
206 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
207 IN UINT64 Address,
208 IN UINTN Count,
209 IN OUT VOID *Buffer
210 );
211
212 EFI_STATUS
213 EFIAPI
214 PciRootBridgeIoMap (
215 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
216 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,
217 IN VOID *HostAddress,
218 IN OUT UINTN *NumberOfBytes,
219 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
220 OUT VOID **Mapping
221 );
222
223 EFI_STATUS
224 EFIAPI
225 PciRootBridgeIoUnmap (
226 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
227 IN VOID *Mapping
228 );
229
230 EFI_STATUS
231 EFIAPI
232 PciRootBridgeIoAllocateBuffer (
233 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
234 IN EFI_ALLOCATE_TYPE Type,
235 IN EFI_MEMORY_TYPE MemoryType,
236 IN UINTN Pages,
237 OUT VOID **HostAddress,
238 IN UINT64 Attributes
239 );
240
241 EFI_STATUS
242 EFIAPI
243 PciRootBridgeIoFreeBuffer (
244 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
245 IN UINTN Pages,
246 OUT VOID *HostAddress
247 );
248
249 EFI_STATUS
250 EFIAPI
251 PciRootBridgeIoFlush (
252 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This
253 );
254
255 EFI_STATUS
256 EFIAPI
257 PciRootBridgeIoGetAttributes (
258 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
259 OUT UINT64 *Supported,
260 OUT UINT64 *Attributes
261 );
262
263 EFI_STATUS
264 EFIAPI
265 PciRootBridgeIoSetAttributes (
266 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
267 IN UINT64 Attributes,
268 IN OUT UINT64 *ResourceBase,
269 IN OUT UINT64 *ResourceLength
270 );
271
272 EFI_STATUS
273 EFIAPI
274 PciRootBridgeIoConfiguration (
275 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
276 OUT VOID **Resources
277 );
278
279 //
280 // Private Function Prototypes
281 //
282 EFI_STATUS
283 EFIAPI
284 PciRootBridgeIoMemRW (
285 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
286 IN UINTN Count,
287 IN BOOLEAN InStrideFlag,
288 IN PTR In,
289 IN BOOLEAN OutStrideFlag,
290 OUT PTR Out
291 );
292
293 BOOLEAN
294 PciIoMemAddressValid (
295 IN EFI_PCI_IO_PROTOCOL *This,
296 IN UINT64 Address
297 );
298
299 EFI_STATUS
300 EmulatePciIoForEhci (
301 INTN MvPciIfMaxIf
302 );
303
304 #endif
305