]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/PciRootBridgeIo.h
c55fb1592231ec9b4715c43d1b3d0284d2f8dc53
[mirror_edk2.git] / MdePkg / Include / Protocol / PciRootBridgeIo.h
1 /** @file
2 PCI Root Bridge I/O protocol as defined in the UEFI 2.0 specification.
3
4 PCI Root Bridge I/O protocol is used by PCI Bus Driver to perform PCI Memory, PCI I/O,
5 and PCI Configuration cycles on a PCI Root Bridge. It also provides services to perform
6 defferent types of bus mastering DMA
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18
19 #ifndef __PCI_ROOT_BRIDGE_IO_H__
20 #define __PCI_ROOT_BRIDGE_IO_H__
21
22 #include <PiDxe.h>
23
24 #define EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID \
25 { \
26 0x2f707ebb, 0x4a1a, 0x11d4, {0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
27 }
28
29 typedef struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL;
30
31 typedef enum {
32 EfiPciWidthUint8,
33 EfiPciWidthUint16,
34 EfiPciWidthUint32,
35 EfiPciWidthUint64,
36 EfiPciWidthFifoUint8,
37 EfiPciWidthFifoUint16,
38 EfiPciWidthFifoUint32,
39 EfiPciWidthFifoUint64,
40 EfiPciWidthFillUint8,
41 EfiPciWidthFillUint16,
42 EfiPciWidthFillUint32,
43 EfiPciWidthFillUint64,
44 EfiPciWidthMaximum
45 } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH;
46
47 typedef enum {
48 EfiPciOperationBusMasterRead,
49 EfiPciOperationBusMasterWrite,
50 EfiPciOperationBusMasterCommonBuffer,
51 EfiPciOperationBusMasterRead64,
52 EfiPciOperationBusMasterWrite64,
53 EfiPciOperationBusMasterCommonBuffer64,
54 EfiPciOperationMaximum
55 } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION;
56
57 #define EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
58 #define EFI_PCI_ATTRIBUTE_ISA_IO 0x0002
59 #define EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO 0x0004
60 #define EFI_PCI_ATTRIBUTE_VGA_MEMORY 0x0008
61 #define EFI_PCI_ATTRIBUTE_VGA_IO 0x0010
62 #define EFI_PCI_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
63 #define EFI_PCI_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
64 #define EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
65 #define EFI_PCI_ATTRIBUTE_MEMORY_CACHED 0x0800
66 #define EFI_PCI_ATTRIBUTE_MEMORY_DISABLE 0x1000
67 #define EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
68
69 #define EFI_PCI_ATTRIBUTE_VALID_FOR_ALLOCATE_BUFFER (EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_PCI_ATTRIBUTE_MEMORY_CACHED | EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE)
70
71 #define EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER (~EFI_PCI_ATTRIBUTE_VALID_FOR_ALLOCATE_BUFFER)
72
73 #define EFI_PCI_ADDRESS(bus, dev, func, reg) \
74 ((UINT64) ((((UINTN) bus) << 24) + (((UINTN) dev) << 16) + (((UINTN) func) << 8) + ((UINTN) reg)))
75
76 typedef struct {
77 UINT8 Register;
78 UINT8 Function;
79 UINT8 Device;
80 UINT8 Bus;
81 UINT32 ExtendedRegister;
82 } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS;
83
84 /**
85 Reads from the I/O space of a PCI Root Bridge. Returns when either the polling exit criteria is
86 satisfied or after a defined duration.
87
88 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
89 @param Width Signifies the width of the memory or I/O operations.
90 @param Address The base address of the memory or I/O operations.
91 @param Mask Mask used for the polling criteria.
92 @param Value The comparison value used for the polling exit criteria.
93 @param Delay The number of 100 ns units to poll.
94 @param Result Pointer to the last value read from the memory location.
95
96 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.
97 @retval EFI_TIMEOUT Delay expired before a match occurred.
98 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
99 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
100
101 **/
102 typedef
103 EFI_STATUS
104 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM) (
105 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
106 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
107 IN UINT64 Address,
108 IN UINT64 Mask,
109 IN UINT64 Value,
110 IN UINT64 Delay,
111 OUT UINT64 *Result
112 );
113
114 /**
115 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
116
117 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
118 @param Width Signifies the width of the memory operations.
119 @param Address The base address of the memory operations.
120 @param Count The number of memory operations to perform.
121 @param Buffer For read operations, the destination buffer to store the results. For write
122 operations, the source buffer to write data from.
123
124 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
125 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
126 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
127
128 **/
129 typedef
130 EFI_STATUS
131 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM) (
132 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
133 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
134 IN UINT64 Address,
135 IN UINTN Count,
136 IN OUT VOID *Buffer
137 );
138
139 typedef struct {
140 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Read;
141 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Write;
142 } EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS;
143
144 /**
145 Enables a PCI driver to copy one region of PCI root bridge memory space to another region of PCI
146 root bridge memory space.
147
148 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
149 @param Width Signifies the width of the memory operations.
150 @param DestAddress The destination address of the memory operation.
151 @param SrcAddress The source address of the memory operation.
152 @param Count The number of memory operations to perform.
153
154 @retval EFI_SUCCESS The data was copied from one memory region to another memory region.
155 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.
156 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
157
158 **/
159 typedef
160 EFI_STATUS
161 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM) (
162 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
163 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
164 IN UINT64 DestAddress,
165 IN UINT64 SrcAddress,
166 IN UINTN Count
167 );
168
169 /**
170 Provides the PCI controller-Cspecific addresses required to access system memory from a
171 DMA bus master.
172
173 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
174 @param Operation Indicates if the bus master is going to read or write to system memory.
175 @param HostAddress The system memory address to map to the PCI controller.
176 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
177 that were mapped.
178 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
179 access the hosts HostAddress.
180 @param Mapping A resulting value to pass to Unmap().
181
182 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
183 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
184 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
185 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
186 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
187
188 **/
189 typedef
190 EFI_STATUS
191 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP) (
192 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
193 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,
194 IN VOID *HostAddress,
195 IN OUT UINTN *NumberOfBytes,
196 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
197 OUT VOID **Mapping
198 );
199
200 /**
201 Completes the Map() operation and releases any corresponding resources.
202
203 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
204 @param Mapping The mapping value returned from Map().
205
206 @retval EFI_SUCCESS The range was unmapped.
207 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
208 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
209
210 **/
211 typedef
212 EFI_STATUS
213 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP) (
214 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
215 IN VOID *Mapping
216 );
217
218 /**
219 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer or
220 EfiPciOperationBusMasterCommonBuffer64 mapping.
221
222 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
223 @param Type This parameter is not used and must be ignored.
224 @param MemoryType The type of memory to allocate, EfiBootServicesData or
225 EfiRuntimeServicesData.
226 @param Pages The number of pages to allocate.
227 @param HostAddress A pointer to store the base system memory address of the
228 allocated range.
229 @param Attributes The requested bit mask of attributes for the allocated range.
230
231 @retval EFI_SUCCESS The requested memory pages were allocated.
232 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
233 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
234 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
235 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
236
237 **/
238 typedef
239 EFI_STATUS
240 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER) (
241 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
242 IN EFI_ALLOCATE_TYPE Type,
243 IN EFI_MEMORY_TYPE MemoryType,
244 IN UINTN Pages,
245 IN OUT VOID **HostAddress,
246 IN UINT64 Attributes
247 );
248
249 /**
250 Frees memory that was allocated with AllocateBuffer().
251
252 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
253 @param Pages The number of pages to free.
254 @param HostAddress The base system memory address of the allocated range.
255
256 @retval EFI_SUCCESS The requested memory pages were freed.
257 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
258 was not allocated with AllocateBuffer().
259
260 **/
261 typedef
262 EFI_STATUS
263 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER) (
264 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
265 IN UINTN Pages,
266 IN VOID *HostAddress
267 );
268
269 /**
270 Flushes all PCI posted write transactions from a PCI host bridge to system memory.
271
272 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
273
274 @retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host
275 bridge to system memory.
276 @retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI
277 host bridge due to a hardware error.
278
279 **/
280 typedef
281 EFI_STATUS
282 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH) (
283 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This
284 );
285
286 /**
287 Gets the attributes that a PCI root bridge supports setting with SetAttributes(), and the
288 attributes that a PCI root bridge is currently using.
289
290 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
291 @param Supports A pointer to the mask of attributes that this PCI root bridge supports
292 setting with SetAttributes().
293 @param Attributes A pointer to the mask of attributes that this PCI root bridge is currently
294 using.
295
296 @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI root
297 bridge supports is returned in Supports. If Attributes is
298 not NULL, then the attributes that the PCI root bridge is currently
299 using is returned in Attributes.
300 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
301
302
303 **/
304 typedef
305 EFI_STATUS
306 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES) (
307 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
308 OUT UINT64 *Supports,
309 OUT UINT64 *Attributes
310 );
311
312 /**
313 Sets attributes for a resource range on a PCI root bridge.
314
315 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
316 @param Attributes The mask of attributes to set.
317 @param ResourceBase A pointer to the base address of the resource range to be modified by the
318 attributes specified by Attributes.
319 @param ResourceLength A pointer to the length of the resource range to be modified by the
320 attributes specified by Attributes.
321
322 @retval EFI_SUCCESS The set of attributes specified by Attributes for the resource
323 range specified by ResourceBase and ResourceLength
324 were set on the PCI root bridge, and the actual resource range is
325 returned in ResuourceBase and ResourceLength.
326 @retval EFI_UNSUPPORTED A bit is set in Attributes that is not supported by the PCI Root
327 Bridge.
328 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the attributes on the
329 resource range specified by BaseAddress and Length.
330 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
331
332 **/
333 typedef
334 EFI_STATUS
335 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES) (
336 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
337 IN UINT64 Attributes,
338 IN OUT UINT64 *ResourceBase,
339 IN OUT UINT64 *ResourceLength
340 );
341
342 /**
343 Retrieves the current resource settings of this PCI root bridge in the form of a set of ACPI 2.0
344 resource descriptors.
345
346 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
347 @param Resources A pointer to the ACPI 2.0 resource descriptors that describe the current
348 configuration of this PCI root bridge.
349
350 @retval EFI_SUCCESS The current configuration of this PCI root bridge was returned in
351 Resources.
352 @retval EFI_UNSUPPORTED The current configuration of this PCI root bridge could not be
353 retrieved.
354
355 **/
356 typedef
357 EFI_STATUS
358 (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION) (
359 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
360 OUT VOID **Resources
361 );
362
363 struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL {
364 EFI_HANDLE ParentHandle;
365 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollMem;
366 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollIo;
367 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Mem;
368 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Io;
369 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Pci;
370 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM CopyMem;
371 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP Map;
372 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP Unmap;
373 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer;
374 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER FreeBuffer;
375 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH Flush;
376 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES GetAttributes;
377 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES SetAttributes;
378 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION Configuration;
379 UINT32 SegmentNumber;
380 };
381
382 extern EFI_GUID gEfiPciRootBridgeIoProtocolGuid;
383
384 #endif