1 | /** @file
|
---|
2 | Functions in this library instance make use of MMIO functions in IoLib to
|
---|
3 | access memory mapped PCI configuration space.
|
---|
4 |
|
---|
5 | All assertions for I/O operations are handled in MMIO functions in the IoLib
|
---|
6 | Library.
|
---|
7 |
|
---|
8 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
9 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
10 |
|
---|
11 | **/
|
---|
12 |
|
---|
13 |
|
---|
14 | #include <Base.h>
|
---|
15 |
|
---|
16 | #include <Library/BaseLib.h>
|
---|
17 | #include <Library/PciExpressLib.h>
|
---|
18 | #include <Library/IoLib.h>
|
---|
19 | #include <Library/DebugLib.h>
|
---|
20 | #include <Library/PcdLib.h>
|
---|
21 |
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Assert the validity of a PCI address. A valid PCI address should contain 1's
|
---|
25 | only in the low 28 bits. PcdPciExpressBaseSize limits the size to the real
|
---|
26 | number of PCI busses in this segment.
|
---|
27 |
|
---|
28 | @param A The address to validate.
|
---|
29 |
|
---|
30 | **/
|
---|
31 | #define ASSERT_INVALID_PCI_ADDRESS(A) \
|
---|
32 | ASSERT (((A) & ~0xfffffff) == 0)
|
---|
33 |
|
---|
34 | #ifdef VBOX
|
---|
35 |
|
---|
36 | STATIC UINT64 mPciExpressBaseAddress;
|
---|
37 |
|
---|
38 | RETURN_STATUS
|
---|
39 | EFIAPI
|
---|
40 | PciExpressLibConstructor (
|
---|
41 | VOID
|
---|
42 | )
|
---|
43 | {
|
---|
44 | //
|
---|
45 | // Accessing PciExpressBaseAddress as a dynamic PCD does not work
|
---|
46 | // because LibPcdGet64() worker tries to raise the TPL to 16 when
|
---|
47 | // it was already set to 31 by caller further up the chain. We need
|
---|
48 | // to read the value (which won't change) and cache it here.
|
---|
49 | //
|
---|
50 | mPciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);
|
---|
51 | if (!mPciExpressBaseAddress)
|
---|
52 | return RETURN_LOAD_ERROR;
|
---|
53 |
|
---|
54 | return RETURN_SUCCESS;
|
---|
55 | }
|
---|
56 | #endif
|
---|
57 |
|
---|
58 |
|
---|
59 | /**
|
---|
60 | Registers a PCI device so PCI configuration registers may be accessed after
|
---|
61 | SetVirtualAddressMap().
|
---|
62 |
|
---|
63 | Registers the PCI device specified by Address so all the PCI configuration
|
---|
64 | registers associated with that PCI device may be accessed after SetVirtualAddressMap()
|
---|
65 | is called.
|
---|
66 |
|
---|
67 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
68 |
|
---|
69 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
70 | Register.
|
---|
71 |
|
---|
72 | @retval RETURN_SUCCESS The PCI device was registered for runtime access.
|
---|
73 | @retval RETURN_UNSUPPORTED An attempt was made to call this function
|
---|
74 | after ExitBootServices().
|
---|
75 | @retval RETURN_UNSUPPORTED The resources required to access the PCI device
|
---|
76 | at runtime could not be mapped.
|
---|
77 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
|
---|
78 | complete the registration.
|
---|
79 |
|
---|
80 | **/
|
---|
81 | RETURN_STATUS
|
---|
82 | EFIAPI
|
---|
83 | PciExpressRegisterForRuntimeAccess (
|
---|
84 | IN UINTN Address
|
---|
85 | )
|
---|
86 | {
|
---|
87 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
88 | return RETURN_UNSUPPORTED;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | Gets the base address of PCI Express.
|
---|
93 |
|
---|
94 | This internal functions retrieves PCI Express Base Address via a PCD entry
|
---|
95 | PcdPciExpressBaseAddress.
|
---|
96 |
|
---|
97 | @return The base address of PCI Express.
|
---|
98 |
|
---|
99 | **/
|
---|
100 | VOID*
|
---|
101 | GetPciExpressBaseAddress (
|
---|
102 | VOID
|
---|
103 | )
|
---|
104 | {
|
---|
105 | #ifdef VBOX
|
---|
106 | return (VOID*)(UINTN) mPciExpressBaseAddress;
|
---|
107 | #else
|
---|
108 | return (VOID*)(UINTN) PcdGet64 (PcdPciExpressBaseAddress);
|
---|
109 | #endif
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | Gets the size of PCI Express.
|
---|
114 |
|
---|
115 | This internal functions retrieves PCI Express Base Size via a PCD entry
|
---|
116 | PcdPciExpressBaseSize.
|
---|
117 |
|
---|
118 | @return The base size of PCI Express.
|
---|
119 |
|
---|
120 | **/
|
---|
121 | STATIC
|
---|
122 | UINTN
|
---|
123 | PcdPciExpressBaseSize (
|
---|
124 | VOID
|
---|
125 | )
|
---|
126 | {
|
---|
127 | return (UINTN) PcdGet64 (PcdPciExpressBaseSize);
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | Reads an 8-bit PCI configuration register.
|
---|
132 |
|
---|
133 | Reads and returns the 8-bit PCI configuration register specified by Address.
|
---|
134 | This function must guarantee that all PCI read and write operations are
|
---|
135 | serialized.
|
---|
136 |
|
---|
137 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
138 |
|
---|
139 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
140 | Register.
|
---|
141 |
|
---|
142 | @retval 0xFF Invalid PCI address.
|
---|
143 | @retval other The read value from the PCI configuration register.
|
---|
144 |
|
---|
145 | **/
|
---|
146 | UINT8
|
---|
147 | EFIAPI
|
---|
148 | PciExpressRead8 (
|
---|
149 | IN UINTN Address
|
---|
150 | )
|
---|
151 | {
|
---|
152 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
153 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
154 | return (UINT8) -1;
|
---|
155 | }
|
---|
156 | return MmioRead8 ((UINTN) GetPciExpressBaseAddress () + Address);
|
---|
157 | }
|
---|
158 |
|
---|
159 | /**
|
---|
160 | Writes an 8-bit PCI configuration register.
|
---|
161 |
|
---|
162 | Writes the 8-bit PCI configuration register specified by Address with the
|
---|
163 | value specified by Value. Value is returned. This function must guarantee
|
---|
164 | that all PCI read and write operations are serialized.
|
---|
165 |
|
---|
166 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
167 |
|
---|
168 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
169 | Register.
|
---|
170 | @param Value The value to write.
|
---|
171 |
|
---|
172 | @retval 0xFF Invalid PCI address.
|
---|
173 | @retval other The value written to the PCI configuration register.
|
---|
174 |
|
---|
175 | **/
|
---|
176 | UINT8
|
---|
177 | EFIAPI
|
---|
178 | PciExpressWrite8 (
|
---|
179 | IN UINTN Address,
|
---|
180 | IN UINT8 Value
|
---|
181 | )
|
---|
182 | {
|
---|
183 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
184 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
185 | return (UINT8) -1;
|
---|
186 | }
|
---|
187 | return MmioWrite8 ((UINTN) GetPciExpressBaseAddress () + Address, Value);
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | Performs a bitwise OR of an 8-bit PCI configuration register with
|
---|
192 | an 8-bit value.
|
---|
193 |
|
---|
194 | Reads the 8-bit PCI configuration register specified by Address, performs a
|
---|
195 | bitwise OR between the read result and the value specified by
|
---|
196 | OrData, and writes the result to the 8-bit PCI configuration register
|
---|
197 | specified by Address. The value written to the PCI configuration register is
|
---|
198 | returned. This function must guarantee that all PCI read and write operations
|
---|
199 | are serialized.
|
---|
200 |
|
---|
201 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
202 |
|
---|
203 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
204 | Register.
|
---|
205 | @param OrData The value to OR with the PCI configuration register.
|
---|
206 |
|
---|
207 | @retval 0xFF Invalid PCI address.
|
---|
208 | @retval other The value written to the PCI configuration register.
|
---|
209 |
|
---|
210 | **/
|
---|
211 | UINT8
|
---|
212 | EFIAPI
|
---|
213 | PciExpressOr8 (
|
---|
214 | IN UINTN Address,
|
---|
215 | IN UINT8 OrData
|
---|
216 | )
|
---|
217 | {
|
---|
218 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
219 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
220 | return (UINT8) -1;
|
---|
221 | }
|
---|
222 | return MmioOr8 ((UINTN) GetPciExpressBaseAddress () + Address, OrData);
|
---|
223 | }
|
---|
224 |
|
---|
225 | /**
|
---|
226 | Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
|
---|
227 | value.
|
---|
228 |
|
---|
229 | Reads the 8-bit PCI configuration register specified by Address, performs a
|
---|
230 | bitwise AND between the read result and the value specified by AndData, and
|
---|
231 | writes the result to the 8-bit PCI configuration register specified by
|
---|
232 | Address. The value written to the PCI configuration register is returned.
|
---|
233 | This function must guarantee that all PCI read and write operations are
|
---|
234 | serialized.
|
---|
235 |
|
---|
236 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
237 |
|
---|
238 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
239 | Register.
|
---|
240 | @param AndData The value to AND with the PCI configuration register.
|
---|
241 |
|
---|
242 | @retval 0xFF Invalid PCI address.
|
---|
243 | @retval other The value written back to the PCI configuration register.
|
---|
244 |
|
---|
245 | **/
|
---|
246 | UINT8
|
---|
247 | EFIAPI
|
---|
248 | PciExpressAnd8 (
|
---|
249 | IN UINTN Address,
|
---|
250 | IN UINT8 AndData
|
---|
251 | )
|
---|
252 | {
|
---|
253 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
254 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
255 | return (UINT8) -1;
|
---|
256 | }
|
---|
257 | return MmioAnd8 ((UINTN) GetPciExpressBaseAddress () + Address, AndData);
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
|
---|
262 | value, followed a bitwise OR with another 8-bit value.
|
---|
263 |
|
---|
264 | Reads the 8-bit PCI configuration register specified by Address, performs a
|
---|
265 | bitwise AND between the read result and the value specified by AndData,
|
---|
266 | performs a bitwise OR between the result of the AND operation and
|
---|
267 | the value specified by OrData, and writes the result to the 8-bit PCI
|
---|
268 | configuration register specified by Address. The value written to the PCI
|
---|
269 | configuration register is returned. This function must guarantee that all PCI
|
---|
270 | read and write operations are serialized.
|
---|
271 |
|
---|
272 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
273 |
|
---|
274 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
275 | Register.
|
---|
276 | @param AndData The value to AND with the PCI configuration register.
|
---|
277 | @param OrData The value to OR with the result of the AND operation.
|
---|
278 |
|
---|
279 | @retval 0xFF Invalid PCI address.
|
---|
280 | @retval other The value written back to the PCI configuration register.
|
---|
281 |
|
---|
282 | **/
|
---|
283 | UINT8
|
---|
284 | EFIAPI
|
---|
285 | PciExpressAndThenOr8 (
|
---|
286 | IN UINTN Address,
|
---|
287 | IN UINT8 AndData,
|
---|
288 | IN UINT8 OrData
|
---|
289 | )
|
---|
290 | {
|
---|
291 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
292 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
293 | return (UINT8) -1;
|
---|
294 | }
|
---|
295 | return MmioAndThenOr8 (
|
---|
296 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
297 | AndData,
|
---|
298 | OrData
|
---|
299 | );
|
---|
300 | }
|
---|
301 |
|
---|
302 | /**
|
---|
303 | Reads a bit field of a PCI configuration register.
|
---|
304 |
|
---|
305 | Reads the bit field in an 8-bit PCI configuration register. The bit field is
|
---|
306 | specified by the StartBit and the EndBit. The value of the bit field is
|
---|
307 | returned.
|
---|
308 |
|
---|
309 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
310 | If StartBit is greater than 7, then ASSERT().
|
---|
311 | If EndBit is greater than 7, then ASSERT().
|
---|
312 | If EndBit is less than StartBit, then ASSERT().
|
---|
313 |
|
---|
314 | @param Address The PCI configuration register to read.
|
---|
315 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
316 | Range 0..7.
|
---|
317 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
318 | Range 0..7.
|
---|
319 |
|
---|
320 | @retval 0xFF Invalid PCI address.
|
---|
321 | @retval other The value of the bit field read from the PCI configuration
|
---|
322 | register.
|
---|
323 |
|
---|
324 | **/
|
---|
325 | UINT8
|
---|
326 | EFIAPI
|
---|
327 | PciExpressBitFieldRead8 (
|
---|
328 | IN UINTN Address,
|
---|
329 | IN UINTN StartBit,
|
---|
330 | IN UINTN EndBit
|
---|
331 | )
|
---|
332 | {
|
---|
333 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
334 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
335 | return (UINT8) -1;
|
---|
336 | }
|
---|
337 | return MmioBitFieldRead8 (
|
---|
338 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
339 | StartBit,
|
---|
340 | EndBit
|
---|
341 | );
|
---|
342 | }
|
---|
343 |
|
---|
344 | /**
|
---|
345 | Writes a bit field to a PCI configuration register.
|
---|
346 |
|
---|
347 | Writes Value to the bit field of the PCI configuration register. The bit
|
---|
348 | field is specified by the StartBit and the EndBit. All other bits in the
|
---|
349 | destination PCI configuration register are preserved. The new value of the
|
---|
350 | 8-bit register is returned.
|
---|
351 |
|
---|
352 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
353 | If StartBit is greater than 7, then ASSERT().
|
---|
354 | If EndBit is greater than 7, then ASSERT().
|
---|
355 | If EndBit is less than StartBit, then ASSERT().
|
---|
356 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
357 |
|
---|
358 | @param Address The PCI configuration register to write.
|
---|
359 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
360 | Range 0..7.
|
---|
361 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
362 | Range 0..7.
|
---|
363 | @param Value The new value of the bit field.
|
---|
364 |
|
---|
365 | @retval 0xFF Invalid PCI address.
|
---|
366 | @retval other The value written back to the PCI configuration register.
|
---|
367 |
|
---|
368 | **/
|
---|
369 | UINT8
|
---|
370 | EFIAPI
|
---|
371 | PciExpressBitFieldWrite8 (
|
---|
372 | IN UINTN Address,
|
---|
373 | IN UINTN StartBit,
|
---|
374 | IN UINTN EndBit,
|
---|
375 | IN UINT8 Value
|
---|
376 | )
|
---|
377 | {
|
---|
378 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
379 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
380 | return (UINT8) -1;
|
---|
381 | }
|
---|
382 | return MmioBitFieldWrite8 (
|
---|
383 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
384 | StartBit,
|
---|
385 | EndBit,
|
---|
386 | Value
|
---|
387 | );
|
---|
388 | }
|
---|
389 |
|
---|
390 | /**
|
---|
391 | Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and
|
---|
392 | writes the result back to the bit field in the 8-bit port.
|
---|
393 |
|
---|
394 | Reads the 8-bit PCI configuration register specified by Address, performs a
|
---|
395 | bitwise OR between the read result and the value specified by
|
---|
396 | OrData, and writes the result to the 8-bit PCI configuration register
|
---|
397 | specified by Address. The value written to the PCI configuration register is
|
---|
398 | returned. This function must guarantee that all PCI read and write operations
|
---|
399 | are serialized. Extra left bits in OrData are stripped.
|
---|
400 |
|
---|
401 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
402 | If StartBit is greater than 7, then ASSERT().
|
---|
403 | If EndBit is greater than 7, then ASSERT().
|
---|
404 | If EndBit is less than StartBit, then ASSERT().
|
---|
405 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
406 |
|
---|
407 | @param Address The PCI configuration register to write.
|
---|
408 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
409 | Range 0..7.
|
---|
410 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
411 | Range 0..7.
|
---|
412 | @param OrData The value to OR with the PCI configuration register.
|
---|
413 |
|
---|
414 | @retval 0xFF Invalid PCI address.
|
---|
415 | @retval other The value written back to the PCI configuration register.
|
---|
416 |
|
---|
417 | **/
|
---|
418 | UINT8
|
---|
419 | EFIAPI
|
---|
420 | PciExpressBitFieldOr8 (
|
---|
421 | IN UINTN Address,
|
---|
422 | IN UINTN StartBit,
|
---|
423 | IN UINTN EndBit,
|
---|
424 | IN UINT8 OrData
|
---|
425 | )
|
---|
426 | {
|
---|
427 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
428 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
429 | return (UINT8) -1;
|
---|
430 | }
|
---|
431 | return MmioBitFieldOr8 (
|
---|
432 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
433 | StartBit,
|
---|
434 | EndBit,
|
---|
435 | OrData
|
---|
436 | );
|
---|
437 | }
|
---|
438 |
|
---|
439 | /**
|
---|
440 | Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
|
---|
441 | AND, and writes the result back to the bit field in the 8-bit register.
|
---|
442 |
|
---|
443 | Reads the 8-bit PCI configuration register specified by Address, performs a
|
---|
444 | bitwise AND between the read result and the value specified by AndData, and
|
---|
445 | writes the result to the 8-bit PCI configuration register specified by
|
---|
446 | Address. The value written to the PCI configuration register is returned.
|
---|
447 | This function must guarantee that all PCI read and write operations are
|
---|
448 | serialized. Extra left bits in AndData are stripped.
|
---|
449 |
|
---|
450 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
451 | If StartBit is greater than 7, then ASSERT().
|
---|
452 | If EndBit is greater than 7, then ASSERT().
|
---|
453 | If EndBit is less than StartBit, then ASSERT().
|
---|
454 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
455 |
|
---|
456 | @param Address The PCI configuration register to write.
|
---|
457 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
458 | Range 0..7.
|
---|
459 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
460 | Range 0..7.
|
---|
461 | @param AndData The value to AND with the PCI configuration register.
|
---|
462 |
|
---|
463 | @retval 0xFF Invalid PCI address.
|
---|
464 | @retval other The value written back to the PCI configuration register.
|
---|
465 |
|
---|
466 | **/
|
---|
467 | UINT8
|
---|
468 | EFIAPI
|
---|
469 | PciExpressBitFieldAnd8 (
|
---|
470 | IN UINTN Address,
|
---|
471 | IN UINTN StartBit,
|
---|
472 | IN UINTN EndBit,
|
---|
473 | IN UINT8 AndData
|
---|
474 | )
|
---|
475 | {
|
---|
476 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
477 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
478 | return (UINT8) -1;
|
---|
479 | }
|
---|
480 | return MmioBitFieldAnd8 (
|
---|
481 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
482 | StartBit,
|
---|
483 | EndBit,
|
---|
484 | AndData
|
---|
485 | );
|
---|
486 | }
|
---|
487 |
|
---|
488 | /**
|
---|
489 | Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
|
---|
490 | bitwise OR, and writes the result back to the bit field in the
|
---|
491 | 8-bit port.
|
---|
492 |
|
---|
493 | Reads the 8-bit PCI configuration register specified by Address, performs a
|
---|
494 | bitwise AND followed by a bitwise OR between the read result and
|
---|
495 | the value specified by AndData, and writes the result to the 8-bit PCI
|
---|
496 | configuration register specified by Address. The value written to the PCI
|
---|
497 | configuration register is returned. This function must guarantee that all PCI
|
---|
498 | read and write operations are serialized. Extra left bits in both AndData and
|
---|
499 | OrData are stripped.
|
---|
500 |
|
---|
501 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
502 | If StartBit is greater than 7, then ASSERT().
|
---|
503 | If EndBit is greater than 7, then ASSERT().
|
---|
504 | If EndBit is less than StartBit, then ASSERT().
|
---|
505 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
506 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
507 |
|
---|
508 | @param Address The PCI configuration register to write.
|
---|
509 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
510 | Range 0..7.
|
---|
511 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
512 | Range 0..7.
|
---|
513 | @param AndData The value to AND with the PCI configuration register.
|
---|
514 | @param OrData The value to OR with the result of the AND operation.
|
---|
515 |
|
---|
516 | @retval 0xFF Invalid PCI address.
|
---|
517 | @retval other The value written back to the PCI configuration register.
|
---|
518 |
|
---|
519 | **/
|
---|
520 | UINT8
|
---|
521 | EFIAPI
|
---|
522 | PciExpressBitFieldAndThenOr8 (
|
---|
523 | IN UINTN Address,
|
---|
524 | IN UINTN StartBit,
|
---|
525 | IN UINTN EndBit,
|
---|
526 | IN UINT8 AndData,
|
---|
527 | IN UINT8 OrData
|
---|
528 | )
|
---|
529 | {
|
---|
530 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
531 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
532 | return (UINT8) -1;
|
---|
533 | }
|
---|
534 | return MmioBitFieldAndThenOr8 (
|
---|
535 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
536 | StartBit,
|
---|
537 | EndBit,
|
---|
538 | AndData,
|
---|
539 | OrData
|
---|
540 | );
|
---|
541 | }
|
---|
542 |
|
---|
543 | /**
|
---|
544 | Reads a 16-bit PCI configuration register.
|
---|
545 |
|
---|
546 | Reads and returns the 16-bit PCI configuration register specified by Address.
|
---|
547 | This function must guarantee that all PCI read and write operations are
|
---|
548 | serialized.
|
---|
549 |
|
---|
550 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
551 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
552 |
|
---|
553 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
554 | Register.
|
---|
555 |
|
---|
556 | @retval 0xFF Invalid PCI address.
|
---|
557 | @retval other The read value from the PCI configuration register.
|
---|
558 |
|
---|
559 | **/
|
---|
560 | UINT16
|
---|
561 | EFIAPI
|
---|
562 | PciExpressRead16 (
|
---|
563 | IN UINTN Address
|
---|
564 | )
|
---|
565 | {
|
---|
566 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
567 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
568 | return (UINT16) -1;
|
---|
569 | }
|
---|
570 | return MmioRead16 ((UINTN) GetPciExpressBaseAddress () + Address);
|
---|
571 | }
|
---|
572 |
|
---|
573 | /**
|
---|
574 | Writes a 16-bit PCI configuration register.
|
---|
575 |
|
---|
576 | Writes the 16-bit PCI configuration register specified by Address with the
|
---|
577 | value specified by Value. Value is returned. This function must guarantee
|
---|
578 | that all PCI read and write operations are serialized.
|
---|
579 |
|
---|
580 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
581 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
582 |
|
---|
583 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
584 | Register.
|
---|
585 | @param Value The value to write.
|
---|
586 |
|
---|
587 | @retval 0xFFFF Invalid PCI address.
|
---|
588 | @retval other The value written to the PCI configuration register.
|
---|
589 |
|
---|
590 | **/
|
---|
591 | UINT16
|
---|
592 | EFIAPI
|
---|
593 | PciExpressWrite16 (
|
---|
594 | IN UINTN Address,
|
---|
595 | IN UINT16 Value
|
---|
596 | )
|
---|
597 | {
|
---|
598 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
599 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
600 | return (UINT16) -1;
|
---|
601 | }
|
---|
602 | return MmioWrite16 ((UINTN) GetPciExpressBaseAddress () + Address, Value);
|
---|
603 | }
|
---|
604 |
|
---|
605 | /**
|
---|
606 | Performs a bitwise OR of a 16-bit PCI configuration register with
|
---|
607 | a 16-bit value.
|
---|
608 |
|
---|
609 | Reads the 16-bit PCI configuration register specified by Address, performs a
|
---|
610 | bitwise OR between the read result and the value specified by
|
---|
611 | OrData, and writes the result to the 16-bit PCI configuration register
|
---|
612 | specified by Address. The value written to the PCI configuration register is
|
---|
613 | returned. This function must guarantee that all PCI read and write operations
|
---|
614 | are serialized.
|
---|
615 |
|
---|
616 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
617 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
618 |
|
---|
619 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
620 | Register.
|
---|
621 | @param OrData The value to OR with the PCI configuration register.
|
---|
622 |
|
---|
623 | @retval 0xFFFF Invalid PCI address.
|
---|
624 | @retval other The value written back to the PCI configuration register.
|
---|
625 |
|
---|
626 | **/
|
---|
627 | UINT16
|
---|
628 | EFIAPI
|
---|
629 | PciExpressOr16 (
|
---|
630 | IN UINTN Address,
|
---|
631 | IN UINT16 OrData
|
---|
632 | )
|
---|
633 | {
|
---|
634 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
635 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
636 | return (UINT16) -1;
|
---|
637 | }
|
---|
638 | return MmioOr16 ((UINTN) GetPciExpressBaseAddress () + Address, OrData);
|
---|
639 | }
|
---|
640 |
|
---|
641 | /**
|
---|
642 | Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
|
---|
643 | value.
|
---|
644 |
|
---|
645 | Reads the 16-bit PCI configuration register specified by Address, performs a
|
---|
646 | bitwise AND between the read result and the value specified by AndData, and
|
---|
647 | writes the result to the 16-bit PCI configuration register specified by
|
---|
648 | Address. The value written to the PCI configuration register is returned.
|
---|
649 | This function must guarantee that all PCI read and write operations are
|
---|
650 | serialized.
|
---|
651 |
|
---|
652 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
653 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
654 |
|
---|
655 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
656 | Register.
|
---|
657 | @param AndData The value to AND with the PCI configuration register.
|
---|
658 |
|
---|
659 | @retval 0xFFFF Invalid PCI address.
|
---|
660 | @retval other The value written back to the PCI configuration register.
|
---|
661 |
|
---|
662 | **/
|
---|
663 | UINT16
|
---|
664 | EFIAPI
|
---|
665 | PciExpressAnd16 (
|
---|
666 | IN UINTN Address,
|
---|
667 | IN UINT16 AndData
|
---|
668 | )
|
---|
669 | {
|
---|
670 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
671 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
672 | return (UINT16) -1;
|
---|
673 | }
|
---|
674 | return MmioAnd16 ((UINTN) GetPciExpressBaseAddress () + Address, AndData);
|
---|
675 | }
|
---|
676 |
|
---|
677 | /**
|
---|
678 | Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
|
---|
679 | value, followed a bitwise OR with another 16-bit value.
|
---|
680 |
|
---|
681 | Reads the 16-bit PCI configuration register specified by Address, performs a
|
---|
682 | bitwise AND between the read result and the value specified by AndData,
|
---|
683 | performs a bitwise OR between the result of the AND operation and
|
---|
684 | the value specified by OrData, and writes the result to the 16-bit PCI
|
---|
685 | configuration register specified by Address. The value written to the PCI
|
---|
686 | configuration register is returned. This function must guarantee that all PCI
|
---|
687 | read and write operations are serialized.
|
---|
688 |
|
---|
689 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
690 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
691 |
|
---|
692 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
693 | Register.
|
---|
694 | @param AndData The value to AND with the PCI configuration register.
|
---|
695 | @param OrData The value to OR with the result of the AND operation.
|
---|
696 |
|
---|
697 | @retval 0xFFFF Invalid PCI address.
|
---|
698 | @retval other The value written back to the PCI configuration register.
|
---|
699 |
|
---|
700 | **/
|
---|
701 | UINT16
|
---|
702 | EFIAPI
|
---|
703 | PciExpressAndThenOr16 (
|
---|
704 | IN UINTN Address,
|
---|
705 | IN UINT16 AndData,
|
---|
706 | IN UINT16 OrData
|
---|
707 | )
|
---|
708 | {
|
---|
709 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
710 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
711 | return (UINT16) -1;
|
---|
712 | }
|
---|
713 | return MmioAndThenOr16 (
|
---|
714 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
715 | AndData,
|
---|
716 | OrData
|
---|
717 | );
|
---|
718 | }
|
---|
719 |
|
---|
720 | /**
|
---|
721 | Reads a bit field of a PCI configuration register.
|
---|
722 |
|
---|
723 | Reads the bit field in a 16-bit PCI configuration register. The bit field is
|
---|
724 | specified by the StartBit and the EndBit. The value of the bit field is
|
---|
725 | returned.
|
---|
726 |
|
---|
727 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
728 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
729 | If StartBit is greater than 15, then ASSERT().
|
---|
730 | If EndBit is greater than 15, then ASSERT().
|
---|
731 | If EndBit is less than StartBit, then ASSERT().
|
---|
732 |
|
---|
733 | @param Address The PCI configuration register to read.
|
---|
734 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
735 | Range 0..15.
|
---|
736 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
737 | Range 0..15.
|
---|
738 |
|
---|
739 | @retval 0xFFFF Invalid PCI address.
|
---|
740 | @retval other The value of the bit field read from the PCI configuration
|
---|
741 | register.
|
---|
742 |
|
---|
743 | **/
|
---|
744 | UINT16
|
---|
745 | EFIAPI
|
---|
746 | PciExpressBitFieldRead16 (
|
---|
747 | IN UINTN Address,
|
---|
748 | IN UINTN StartBit,
|
---|
749 | IN UINTN EndBit
|
---|
750 | )
|
---|
751 | {
|
---|
752 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
753 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
754 | return (UINT16) -1;
|
---|
755 | }
|
---|
756 | return MmioBitFieldRead16 (
|
---|
757 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
758 | StartBit,
|
---|
759 | EndBit
|
---|
760 | );
|
---|
761 | }
|
---|
762 |
|
---|
763 | /**
|
---|
764 | Writes a bit field to a PCI configuration register.
|
---|
765 |
|
---|
766 | Writes Value to the bit field of the PCI configuration register. The bit
|
---|
767 | field is specified by the StartBit and the EndBit. All other bits in the
|
---|
768 | destination PCI configuration register are preserved. The new value of the
|
---|
769 | 16-bit register is returned.
|
---|
770 |
|
---|
771 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
772 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
773 | If StartBit is greater than 15, then ASSERT().
|
---|
774 | If EndBit is greater than 15, then ASSERT().
|
---|
775 | If EndBit is less than StartBit, then ASSERT().
|
---|
776 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
777 |
|
---|
778 | @param Address The PCI configuration register to write.
|
---|
779 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
780 | Range 0..15.
|
---|
781 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
782 | Range 0..15.
|
---|
783 | @param Value The new value of the bit field.
|
---|
784 |
|
---|
785 | @retval 0xFFFF Invalid PCI address.
|
---|
786 | @retval other The value written back to the PCI configuration register.
|
---|
787 |
|
---|
788 | **/
|
---|
789 | UINT16
|
---|
790 | EFIAPI
|
---|
791 | PciExpressBitFieldWrite16 (
|
---|
792 | IN UINTN Address,
|
---|
793 | IN UINTN StartBit,
|
---|
794 | IN UINTN EndBit,
|
---|
795 | IN UINT16 Value
|
---|
796 | )
|
---|
797 | {
|
---|
798 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
799 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
800 | return (UINT16) -1;
|
---|
801 | }
|
---|
802 | return MmioBitFieldWrite16 (
|
---|
803 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
804 | StartBit,
|
---|
805 | EndBit,
|
---|
806 | Value
|
---|
807 | );
|
---|
808 | }
|
---|
809 |
|
---|
810 | /**
|
---|
811 | Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and
|
---|
812 | writes the result back to the bit field in the 16-bit port.
|
---|
813 |
|
---|
814 | Reads the 16-bit PCI configuration register specified by Address, performs a
|
---|
815 | bitwise OR between the read result and the value specified by
|
---|
816 | OrData, and writes the result to the 16-bit PCI configuration register
|
---|
817 | specified by Address. The value written to the PCI configuration register is
|
---|
818 | returned. This function must guarantee that all PCI read and write operations
|
---|
819 | are serialized. Extra left bits in OrData are stripped.
|
---|
820 |
|
---|
821 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
822 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
823 | If StartBit is greater than 15, then ASSERT().
|
---|
824 | If EndBit is greater than 15, then ASSERT().
|
---|
825 | If EndBit is less than StartBit, then ASSERT().
|
---|
826 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
827 |
|
---|
828 | @param Address The PCI configuration register to write.
|
---|
829 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
830 | Range 0..15.
|
---|
831 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
832 | Range 0..15.
|
---|
833 | @param OrData The value to OR with the PCI configuration register.
|
---|
834 |
|
---|
835 | @retval 0xFFFF Invalid PCI address.
|
---|
836 | @retval other The value written back to the PCI configuration register.
|
---|
837 |
|
---|
838 | **/
|
---|
839 | UINT16
|
---|
840 | EFIAPI
|
---|
841 | PciExpressBitFieldOr16 (
|
---|
842 | IN UINTN Address,
|
---|
843 | IN UINTN StartBit,
|
---|
844 | IN UINTN EndBit,
|
---|
845 | IN UINT16 OrData
|
---|
846 | )
|
---|
847 | {
|
---|
848 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
849 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
850 | return (UINT16) -1;
|
---|
851 | }
|
---|
852 | return MmioBitFieldOr16 (
|
---|
853 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
854 | StartBit,
|
---|
855 | EndBit,
|
---|
856 | OrData
|
---|
857 | );
|
---|
858 | }
|
---|
859 |
|
---|
860 | /**
|
---|
861 | Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
|
---|
862 | AND, and writes the result back to the bit field in the 16-bit register.
|
---|
863 |
|
---|
864 | Reads the 16-bit PCI configuration register specified by Address, performs a
|
---|
865 | bitwise AND between the read result and the value specified by AndData, and
|
---|
866 | writes the result to the 16-bit PCI configuration register specified by
|
---|
867 | Address. The value written to the PCI configuration register is returned.
|
---|
868 | This function must guarantee that all PCI read and write operations are
|
---|
869 | serialized. Extra left bits in AndData are stripped.
|
---|
870 |
|
---|
871 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
872 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
873 | If StartBit is greater than 15, then ASSERT().
|
---|
874 | If EndBit is greater than 15, then ASSERT().
|
---|
875 | If EndBit is less than StartBit, then ASSERT().
|
---|
876 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
877 |
|
---|
878 | @param Address The PCI configuration register to write.
|
---|
879 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
880 | Range 0..15.
|
---|
881 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
882 | Range 0..15.
|
---|
883 | @param AndData The value to AND with the PCI configuration register.
|
---|
884 |
|
---|
885 | @retval 0xFFFF Invalid PCI address.
|
---|
886 | @retval other The value written back to the PCI configuration register.
|
---|
887 |
|
---|
888 | **/
|
---|
889 | UINT16
|
---|
890 | EFIAPI
|
---|
891 | PciExpressBitFieldAnd16 (
|
---|
892 | IN UINTN Address,
|
---|
893 | IN UINTN StartBit,
|
---|
894 | IN UINTN EndBit,
|
---|
895 | IN UINT16 AndData
|
---|
896 | )
|
---|
897 | {
|
---|
898 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
899 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
900 | return (UINT16) -1;
|
---|
901 | }
|
---|
902 | return MmioBitFieldAnd16 (
|
---|
903 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
904 | StartBit,
|
---|
905 | EndBit,
|
---|
906 | AndData
|
---|
907 | );
|
---|
908 | }
|
---|
909 |
|
---|
910 | /**
|
---|
911 | Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
|
---|
912 | bitwise OR, and writes the result back to the bit field in the
|
---|
913 | 16-bit port.
|
---|
914 |
|
---|
915 | Reads the 16-bit PCI configuration register specified by Address, performs a
|
---|
916 | bitwise AND followed by a bitwise OR between the read result and
|
---|
917 | the value specified by AndData, and writes the result to the 16-bit PCI
|
---|
918 | configuration register specified by Address. The value written to the PCI
|
---|
919 | configuration register is returned. This function must guarantee that all PCI
|
---|
920 | read and write operations are serialized. Extra left bits in both AndData and
|
---|
921 | OrData are stripped.
|
---|
922 |
|
---|
923 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
924 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
925 | If StartBit is greater than 15, then ASSERT().
|
---|
926 | If EndBit is greater than 15, then ASSERT().
|
---|
927 | If EndBit is less than StartBit, then ASSERT().
|
---|
928 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
929 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
930 |
|
---|
931 | @param Address The PCI configuration register to write.
|
---|
932 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
933 | Range 0..15.
|
---|
934 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
935 | Range 0..15.
|
---|
936 | @param AndData The value to AND with the PCI configuration register.
|
---|
937 | @param OrData The value to OR with the result of the AND operation.
|
---|
938 |
|
---|
939 | @retval 0xFFFF Invalid PCI address.
|
---|
940 | @retval other The value written back to the PCI configuration register.
|
---|
941 |
|
---|
942 | **/
|
---|
943 | UINT16
|
---|
944 | EFIAPI
|
---|
945 | PciExpressBitFieldAndThenOr16 (
|
---|
946 | IN UINTN Address,
|
---|
947 | IN UINTN StartBit,
|
---|
948 | IN UINTN EndBit,
|
---|
949 | IN UINT16 AndData,
|
---|
950 | IN UINT16 OrData
|
---|
951 | )
|
---|
952 | {
|
---|
953 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
954 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
955 | return (UINT16) -1;
|
---|
956 | }
|
---|
957 | return MmioBitFieldAndThenOr16 (
|
---|
958 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
959 | StartBit,
|
---|
960 | EndBit,
|
---|
961 | AndData,
|
---|
962 | OrData
|
---|
963 | );
|
---|
964 | }
|
---|
965 |
|
---|
966 | /**
|
---|
967 | Reads a 32-bit PCI configuration register.
|
---|
968 |
|
---|
969 | Reads and returns the 32-bit PCI configuration register specified by Address.
|
---|
970 | This function must guarantee that all PCI read and write operations are
|
---|
971 | serialized.
|
---|
972 |
|
---|
973 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
974 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
975 |
|
---|
976 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
977 | Register.
|
---|
978 |
|
---|
979 | @retval 0xFFFF Invalid PCI address.
|
---|
980 | @retval other The read value from the PCI configuration register.
|
---|
981 |
|
---|
982 | **/
|
---|
983 | UINT32
|
---|
984 | EFIAPI
|
---|
985 | PciExpressRead32 (
|
---|
986 | IN UINTN Address
|
---|
987 | )
|
---|
988 | {
|
---|
989 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
990 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
991 | return (UINT32) -1;
|
---|
992 | }
|
---|
993 | return MmioRead32 ((UINTN) GetPciExpressBaseAddress () + Address);
|
---|
994 | }
|
---|
995 |
|
---|
996 | /**
|
---|
997 | Writes a 32-bit PCI configuration register.
|
---|
998 |
|
---|
999 | Writes the 32-bit PCI configuration register specified by Address with the
|
---|
1000 | value specified by Value. Value is returned. This function must guarantee
|
---|
1001 | that all PCI read and write operations are serialized.
|
---|
1002 |
|
---|
1003 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1004 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1005 |
|
---|
1006 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
1007 | Register.
|
---|
1008 | @param Value The value to write.
|
---|
1009 |
|
---|
1010 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1011 | @retval other The value written to the PCI configuration register.
|
---|
1012 |
|
---|
1013 | **/
|
---|
1014 | UINT32
|
---|
1015 | EFIAPI
|
---|
1016 | PciExpressWrite32 (
|
---|
1017 | IN UINTN Address,
|
---|
1018 | IN UINT32 Value
|
---|
1019 | )
|
---|
1020 | {
|
---|
1021 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1022 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1023 | return (UINT32) -1;
|
---|
1024 | }
|
---|
1025 | return MmioWrite32 ((UINTN) GetPciExpressBaseAddress () + Address, Value);
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | /**
|
---|
1029 | Performs a bitwise OR of a 32-bit PCI configuration register with
|
---|
1030 | a 32-bit value.
|
---|
1031 |
|
---|
1032 | Reads the 32-bit PCI configuration register specified by Address, performs a
|
---|
1033 | bitwise OR between the read result and the value specified by
|
---|
1034 | OrData, and writes the result to the 32-bit PCI configuration register
|
---|
1035 | specified by Address. The value written to the PCI configuration register is
|
---|
1036 | returned. This function must guarantee that all PCI read and write operations
|
---|
1037 | are serialized.
|
---|
1038 |
|
---|
1039 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1040 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1041 |
|
---|
1042 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
1043 | Register.
|
---|
1044 | @param OrData The value to OR with the PCI configuration register.
|
---|
1045 |
|
---|
1046 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1047 | @retval other The value written back to the PCI configuration register.
|
---|
1048 |
|
---|
1049 | **/
|
---|
1050 | UINT32
|
---|
1051 | EFIAPI
|
---|
1052 | PciExpressOr32 (
|
---|
1053 | IN UINTN Address,
|
---|
1054 | IN UINT32 OrData
|
---|
1055 | )
|
---|
1056 | {
|
---|
1057 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1058 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1059 | return (UINT32) -1;
|
---|
1060 | }
|
---|
1061 | return MmioOr32 ((UINTN) GetPciExpressBaseAddress () + Address, OrData);
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | /**
|
---|
1065 | Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
|
---|
1066 | value.
|
---|
1067 |
|
---|
1068 | Reads the 32-bit PCI configuration register specified by Address, performs a
|
---|
1069 | bitwise AND between the read result and the value specified by AndData, and
|
---|
1070 | writes the result to the 32-bit PCI configuration register specified by
|
---|
1071 | Address. The value written to the PCI configuration register is returned.
|
---|
1072 | This function must guarantee that all PCI read and write operations are
|
---|
1073 | serialized.
|
---|
1074 |
|
---|
1075 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1076 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1077 |
|
---|
1078 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
1079 | Register.
|
---|
1080 | @param AndData The value to AND with the PCI configuration register.
|
---|
1081 |
|
---|
1082 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1083 | @retval other The value written back to the PCI configuration register.
|
---|
1084 |
|
---|
1085 | **/
|
---|
1086 | UINT32
|
---|
1087 | EFIAPI
|
---|
1088 | PciExpressAnd32 (
|
---|
1089 | IN UINTN Address,
|
---|
1090 | IN UINT32 AndData
|
---|
1091 | )
|
---|
1092 | {
|
---|
1093 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1094 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1095 | return (UINT32) -1;
|
---|
1096 | }
|
---|
1097 | return MmioAnd32 ((UINTN) GetPciExpressBaseAddress () + Address, AndData);
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | /**
|
---|
1101 | Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
|
---|
1102 | value, followed a bitwise OR with another 32-bit value.
|
---|
1103 |
|
---|
1104 | Reads the 32-bit PCI configuration register specified by Address, performs a
|
---|
1105 | bitwise AND between the read result and the value specified by AndData,
|
---|
1106 | performs a bitwise OR between the result of the AND operation and
|
---|
1107 | the value specified by OrData, and writes the result to the 32-bit PCI
|
---|
1108 | configuration register specified by Address. The value written to the PCI
|
---|
1109 | configuration register is returned. This function must guarantee that all PCI
|
---|
1110 | read and write operations are serialized.
|
---|
1111 |
|
---|
1112 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1113 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1114 |
|
---|
1115 | @param Address The address that encodes the PCI Bus, Device, Function and
|
---|
1116 | Register.
|
---|
1117 | @param AndData The value to AND with the PCI configuration register.
|
---|
1118 | @param OrData The value to OR with the result of the AND operation.
|
---|
1119 |
|
---|
1120 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1121 | @retval other The value written back to the PCI configuration register.
|
---|
1122 |
|
---|
1123 | **/
|
---|
1124 | UINT32
|
---|
1125 | EFIAPI
|
---|
1126 | PciExpressAndThenOr32 (
|
---|
1127 | IN UINTN Address,
|
---|
1128 | IN UINT32 AndData,
|
---|
1129 | IN UINT32 OrData
|
---|
1130 | )
|
---|
1131 | {
|
---|
1132 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1133 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1134 | return (UINT32) -1;
|
---|
1135 | }
|
---|
1136 | return MmioAndThenOr32 (
|
---|
1137 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
1138 | AndData,
|
---|
1139 | OrData
|
---|
1140 | );
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | /**
|
---|
1144 | Reads a bit field of a PCI configuration register.
|
---|
1145 |
|
---|
1146 | Reads the bit field in a 32-bit PCI configuration register. The bit field is
|
---|
1147 | specified by the StartBit and the EndBit. The value of the bit field is
|
---|
1148 | returned.
|
---|
1149 |
|
---|
1150 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1151 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1152 | If StartBit is greater than 31, then ASSERT().
|
---|
1153 | If EndBit is greater than 31, then ASSERT().
|
---|
1154 | If EndBit is less than StartBit, then ASSERT().
|
---|
1155 |
|
---|
1156 | @param Address The PCI configuration register to read.
|
---|
1157 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
1158 | Range 0..31.
|
---|
1159 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
1160 | Range 0..31.
|
---|
1161 |
|
---|
1162 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1163 | @retval other The value of the bit field read from the PCI
|
---|
1164 | configuration register.
|
---|
1165 |
|
---|
1166 | **/
|
---|
1167 | UINT32
|
---|
1168 | EFIAPI
|
---|
1169 | PciExpressBitFieldRead32 (
|
---|
1170 | IN UINTN Address,
|
---|
1171 | IN UINTN StartBit,
|
---|
1172 | IN UINTN EndBit
|
---|
1173 | )
|
---|
1174 | {
|
---|
1175 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1176 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1177 | return (UINT32) -1;
|
---|
1178 | }
|
---|
1179 | return MmioBitFieldRead32 (
|
---|
1180 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
1181 | StartBit,
|
---|
1182 | EndBit
|
---|
1183 | );
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | /**
|
---|
1187 | Writes a bit field to a PCI configuration register.
|
---|
1188 |
|
---|
1189 | Writes Value to the bit field of the PCI configuration register. The bit
|
---|
1190 | field is specified by the StartBit and the EndBit. All other bits in the
|
---|
1191 | destination PCI configuration register are preserved. The new value of the
|
---|
1192 | 32-bit register is returned.
|
---|
1193 |
|
---|
1194 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1195 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1196 | If StartBit is greater than 31, then ASSERT().
|
---|
1197 | If EndBit is greater than 31, then ASSERT().
|
---|
1198 | If EndBit is less than StartBit, then ASSERT().
|
---|
1199 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
1200 |
|
---|
1201 | @param Address The PCI configuration register to write.
|
---|
1202 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
1203 | Range 0..31.
|
---|
1204 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
1205 | Range 0..31.
|
---|
1206 | @param Value The new value of the bit field.
|
---|
1207 |
|
---|
1208 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1209 | @retval other The value written back to the PCI configuration register.
|
---|
1210 |
|
---|
1211 | **/
|
---|
1212 | UINT32
|
---|
1213 | EFIAPI
|
---|
1214 | PciExpressBitFieldWrite32 (
|
---|
1215 | IN UINTN Address,
|
---|
1216 | IN UINTN StartBit,
|
---|
1217 | IN UINTN EndBit,
|
---|
1218 | IN UINT32 Value
|
---|
1219 | )
|
---|
1220 | {
|
---|
1221 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1222 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1223 | return (UINT32) -1;
|
---|
1224 | }
|
---|
1225 | return MmioBitFieldWrite32 (
|
---|
1226 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
1227 | StartBit,
|
---|
1228 | EndBit,
|
---|
1229 | Value
|
---|
1230 | );
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | /**
|
---|
1234 | Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and
|
---|
1235 | writes the result back to the bit field in the 32-bit port.
|
---|
1236 |
|
---|
1237 | Reads the 32-bit PCI configuration register specified by Address, performs a
|
---|
1238 | bitwise OR between the read result and the value specified by
|
---|
1239 | OrData, and writes the result to the 32-bit PCI configuration register
|
---|
1240 | specified by Address. The value written to the PCI configuration register is
|
---|
1241 | returned. This function must guarantee that all PCI read and write operations
|
---|
1242 | are serialized. Extra left bits in OrData are stripped.
|
---|
1243 |
|
---|
1244 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1245 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1246 | If StartBit is greater than 31, then ASSERT().
|
---|
1247 | If EndBit is greater than 31, then ASSERT().
|
---|
1248 | If EndBit is less than StartBit, then ASSERT().
|
---|
1249 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
1250 |
|
---|
1251 | @param Address The PCI configuration register to write.
|
---|
1252 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
1253 | Range 0..31.
|
---|
1254 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
1255 | Range 0..31.
|
---|
1256 | @param OrData The value to OR with the PCI configuration register.
|
---|
1257 |
|
---|
1258 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1259 | @retval other The value written back to the PCI configuration register.
|
---|
1260 |
|
---|
1261 | **/
|
---|
1262 | UINT32
|
---|
1263 | EFIAPI
|
---|
1264 | PciExpressBitFieldOr32 (
|
---|
1265 | IN UINTN Address,
|
---|
1266 | IN UINTN StartBit,
|
---|
1267 | IN UINTN EndBit,
|
---|
1268 | IN UINT32 OrData
|
---|
1269 | )
|
---|
1270 | {
|
---|
1271 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1272 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1273 | return (UINT32) -1;
|
---|
1274 | }
|
---|
1275 | return MmioBitFieldOr32 (
|
---|
1276 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
1277 | StartBit,
|
---|
1278 | EndBit,
|
---|
1279 | OrData
|
---|
1280 | );
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | /**
|
---|
1284 | Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
|
---|
1285 | AND, and writes the result back to the bit field in the 32-bit register.
|
---|
1286 |
|
---|
1287 | Reads the 32-bit PCI configuration register specified by Address, performs a
|
---|
1288 | bitwise AND between the read result and the value specified by AndData, and
|
---|
1289 | writes the result to the 32-bit PCI configuration register specified by
|
---|
1290 | Address. The value written to the PCI configuration register is returned.
|
---|
1291 | This function must guarantee that all PCI read and write operations are
|
---|
1292 | serialized. Extra left bits in AndData are stripped.
|
---|
1293 |
|
---|
1294 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1295 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1296 | If StartBit is greater than 31, then ASSERT().
|
---|
1297 | If EndBit is greater than 31, then ASSERT().
|
---|
1298 | If EndBit is less than StartBit, then ASSERT().
|
---|
1299 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
1300 |
|
---|
1301 | @param Address The PCI configuration register to write.
|
---|
1302 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
1303 | Range 0..31.
|
---|
1304 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
1305 | Range 0..31.
|
---|
1306 | @param AndData The value to AND with the PCI configuration register.
|
---|
1307 |
|
---|
1308 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1309 | @retval other The value written back to the PCI configuration register.
|
---|
1310 |
|
---|
1311 | **/
|
---|
1312 | UINT32
|
---|
1313 | EFIAPI
|
---|
1314 | PciExpressBitFieldAnd32 (
|
---|
1315 | IN UINTN Address,
|
---|
1316 | IN UINTN StartBit,
|
---|
1317 | IN UINTN EndBit,
|
---|
1318 | IN UINT32 AndData
|
---|
1319 | )
|
---|
1320 | {
|
---|
1321 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1322 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1323 | return (UINT32) -1;
|
---|
1324 | }
|
---|
1325 | return MmioBitFieldAnd32 (
|
---|
1326 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
1327 | StartBit,
|
---|
1328 | EndBit,
|
---|
1329 | AndData
|
---|
1330 | );
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | /**
|
---|
1334 | Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
|
---|
1335 | bitwise OR, and writes the result back to the bit field in the
|
---|
1336 | 32-bit port.
|
---|
1337 |
|
---|
1338 | Reads the 32-bit PCI configuration register specified by Address, performs a
|
---|
1339 | bitwise AND followed by a bitwise OR between the read result and
|
---|
1340 | the value specified by AndData, and writes the result to the 32-bit PCI
|
---|
1341 | configuration register specified by Address. The value written to the PCI
|
---|
1342 | configuration register is returned. This function must guarantee that all PCI
|
---|
1343 | read and write operations are serialized. Extra left bits in both AndData and
|
---|
1344 | OrData are stripped.
|
---|
1345 |
|
---|
1346 | If Address > 0x0FFFFFFF, then ASSERT().
|
---|
1347 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
1348 | If StartBit is greater than 31, then ASSERT().
|
---|
1349 | If EndBit is greater than 31, then ASSERT().
|
---|
1350 | If EndBit is less than StartBit, then ASSERT().
|
---|
1351 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
1352 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
---|
1353 |
|
---|
1354 | @param Address The PCI configuration register to write.
|
---|
1355 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
1356 | Range 0..31.
|
---|
1357 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
1358 | Range 0..31.
|
---|
1359 | @param AndData The value to AND with the PCI configuration register.
|
---|
1360 | @param OrData The value to OR with the result of the AND operation.
|
---|
1361 |
|
---|
1362 | @retval 0xFFFFFFFF Invalid PCI address.
|
---|
1363 | @retval other The value written back to the PCI configuration register.
|
---|
1364 |
|
---|
1365 | **/
|
---|
1366 | UINT32
|
---|
1367 | EFIAPI
|
---|
1368 | PciExpressBitFieldAndThenOr32 (
|
---|
1369 | IN UINTN Address,
|
---|
1370 | IN UINTN StartBit,
|
---|
1371 | IN UINTN EndBit,
|
---|
1372 | IN UINT32 AndData,
|
---|
1373 | IN UINT32 OrData
|
---|
1374 | )
|
---|
1375 | {
|
---|
1376 | ASSERT_INVALID_PCI_ADDRESS (Address);
|
---|
1377 | if (Address >= PcdPciExpressBaseSize()) {
|
---|
1378 | return (UINT32) -1;
|
---|
1379 | }
|
---|
1380 | return MmioBitFieldAndThenOr32 (
|
---|
1381 | (UINTN) GetPciExpressBaseAddress () + Address,
|
---|
1382 | StartBit,
|
---|
1383 | EndBit,
|
---|
1384 | AndData,
|
---|
1385 | OrData
|
---|
1386 | );
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | /**
|
---|
1390 | Reads a range of PCI configuration registers into a caller supplied buffer.
|
---|
1391 |
|
---|
1392 | Reads the range of PCI configuration registers specified by StartAddress and
|
---|
1393 | Size into the buffer specified by Buffer. This function only allows the PCI
|
---|
1394 | configuration registers from a single PCI function to be read. Size is
|
---|
1395 | returned. When possible 32-bit PCI configuration read cycles are used to read
|
---|
1396 | from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
|
---|
1397 | and 16-bit PCI configuration read cycles may be used at the beginning and the
|
---|
1398 | end of the range.
|
---|
1399 |
|
---|
1400 | If StartAddress > 0x0FFFFFFF, then ASSERT().
|
---|
1401 | If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
|
---|
1402 | If Size > 0 and Buffer is NULL, then ASSERT().
|
---|
1403 |
|
---|
1404 | @param StartAddress The starting address that encodes the PCI Bus, Device,
|
---|
1405 | Function and Register.
|
---|
1406 | @param Size The size in bytes of the transfer.
|
---|
1407 | @param Buffer The pointer to a buffer receiving the data read.
|
---|
1408 |
|
---|
1409 | @retval (UINTN)-1 Invalid PCI address.
|
---|
1410 | @retval other Size read data from StartAddress.
|
---|
1411 |
|
---|
1412 | **/
|
---|
1413 | UINTN
|
---|
1414 | EFIAPI
|
---|
1415 | PciExpressReadBuffer (
|
---|
1416 | IN UINTN StartAddress,
|
---|
1417 | IN UINTN Size,
|
---|
1418 | OUT VOID *Buffer
|
---|
1419 | )
|
---|
1420 | {
|
---|
1421 | UINTN ReturnValue;
|
---|
1422 |
|
---|
1423 | ASSERT_INVALID_PCI_ADDRESS (StartAddress);
|
---|
1424 | if (StartAddress >= PcdPciExpressBaseSize()) {
|
---|
1425 | return (UINTN) -1;
|
---|
1426 | }
|
---|
1427 | ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
|
---|
1428 |
|
---|
1429 | if (Size == 0) {
|
---|
1430 | return Size;
|
---|
1431 | }
|
---|
1432 |
|
---|
1433 | ASSERT (Buffer != NULL);
|
---|
1434 |
|
---|
1435 | //
|
---|
1436 | // Save Size for return
|
---|
1437 | //
|
---|
1438 | ReturnValue = Size;
|
---|
1439 |
|
---|
1440 | if ((StartAddress & 1) != 0) {
|
---|
1441 | //
|
---|
1442 | // Read a byte if StartAddress is byte aligned
|
---|
1443 | //
|
---|
1444 | *(volatile UINT8 *)Buffer = PciExpressRead8 (StartAddress);
|
---|
1445 | StartAddress += sizeof (UINT8);
|
---|
1446 | Size -= sizeof (UINT8);
|
---|
1447 | Buffer = (UINT8*)Buffer + 1;
|
---|
1448 | }
|
---|
1449 |
|
---|
1450 | if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) {
|
---|
1451 | //
|
---|
1452 | // Read a word if StartAddress is word aligned
|
---|
1453 | //
|
---|
1454 | WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) PciExpressRead16 (StartAddress));
|
---|
1455 |
|
---|
1456 | StartAddress += sizeof (UINT16);
|
---|
1457 | Size -= sizeof (UINT16);
|
---|
1458 | Buffer = (UINT16*)Buffer + 1;
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 | while (Size >= sizeof (UINT32)) {
|
---|
1462 | //
|
---|
1463 | // Read as many double words as possible
|
---|
1464 | //
|
---|
1465 | WriteUnaligned32 ((UINT32 *) Buffer, (UINT32) PciExpressRead32 (StartAddress));
|
---|
1466 |
|
---|
1467 | StartAddress += sizeof (UINT32);
|
---|
1468 | Size -= sizeof (UINT32);
|
---|
1469 | Buffer = (UINT32*)Buffer + 1;
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | if (Size >= sizeof (UINT16)) {
|
---|
1473 | //
|
---|
1474 | // Read the last remaining word if exist
|
---|
1475 | //
|
---|
1476 | WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) PciExpressRead16 (StartAddress));
|
---|
1477 | StartAddress += sizeof (UINT16);
|
---|
1478 | Size -= sizeof (UINT16);
|
---|
1479 | Buffer = (UINT16*)Buffer + 1;
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 | if (Size >= sizeof (UINT8)) {
|
---|
1483 | //
|
---|
1484 | // Read the last remaining byte if exist
|
---|
1485 | //
|
---|
1486 | *(volatile UINT8 *)Buffer = PciExpressRead8 (StartAddress);
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | return ReturnValue;
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | /**
|
---|
1493 | Copies the data in a caller supplied buffer to a specified range of PCI
|
---|
1494 | configuration space.
|
---|
1495 |
|
---|
1496 | Writes the range of PCI configuration registers specified by StartAddress and
|
---|
1497 | Size from the buffer specified by Buffer. This function only allows the PCI
|
---|
1498 | configuration registers from a single PCI function to be written. Size is
|
---|
1499 | returned. When possible 32-bit PCI configuration write cycles are used to
|
---|
1500 | write from StartAdress to StartAddress + Size. Due to alignment restrictions,
|
---|
1501 | 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
|
---|
1502 | and the end of the range.
|
---|
1503 |
|
---|
1504 | If StartAddress > 0x0FFFFFFF, then ASSERT().
|
---|
1505 | If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
|
---|
1506 | If Size > 0 and Buffer is NULL, then ASSERT().
|
---|
1507 |
|
---|
1508 | @param StartAddress The starting address that encodes the PCI Bus, Device,
|
---|
1509 | Function and Register.
|
---|
1510 | @param Size The size in bytes of the transfer.
|
---|
1511 | @param Buffer The pointer to a buffer containing the data to write.
|
---|
1512 |
|
---|
1513 | @retval (UINTN)-1 Invalid PCI address.
|
---|
1514 | @retval other Size written to StartAddress.
|
---|
1515 |
|
---|
1516 | **/
|
---|
1517 | UINTN
|
---|
1518 | EFIAPI
|
---|
1519 | PciExpressWriteBuffer (
|
---|
1520 | IN UINTN StartAddress,
|
---|
1521 | IN UINTN Size,
|
---|
1522 | IN VOID *Buffer
|
---|
1523 | )
|
---|
1524 | {
|
---|
1525 | UINTN ReturnValue;
|
---|
1526 |
|
---|
1527 | ASSERT_INVALID_PCI_ADDRESS (StartAddress);
|
---|
1528 | if (StartAddress >= PcdPciExpressBaseSize()) {
|
---|
1529 | return (UINTN) -1;
|
---|
1530 | }
|
---|
1531 | ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
|
---|
1532 |
|
---|
1533 | if (Size == 0) {
|
---|
1534 | return 0;
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | ASSERT (Buffer != NULL);
|
---|
1538 |
|
---|
1539 | //
|
---|
1540 | // Save Size for return
|
---|
1541 | //
|
---|
1542 | ReturnValue = Size;
|
---|
1543 |
|
---|
1544 | if ((StartAddress & 1) != 0) {
|
---|
1545 | //
|
---|
1546 | // Write a byte if StartAddress is byte aligned
|
---|
1547 | //
|
---|
1548 | PciExpressWrite8 (StartAddress, *(UINT8*)Buffer);
|
---|
1549 | StartAddress += sizeof (UINT8);
|
---|
1550 | Size -= sizeof (UINT8);
|
---|
1551 | Buffer = (UINT8*)Buffer + 1;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) {
|
---|
1555 | //
|
---|
1556 | // Write a word if StartAddress is word aligned
|
---|
1557 | //
|
---|
1558 | PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));
|
---|
1559 | StartAddress += sizeof (UINT16);
|
---|
1560 | Size -= sizeof (UINT16);
|
---|
1561 | Buffer = (UINT16*)Buffer + 1;
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 | while (Size >= sizeof (UINT32)) {
|
---|
1565 | //
|
---|
1566 | // Write as many double words as possible
|
---|
1567 | //
|
---|
1568 | PciExpressWrite32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer));
|
---|
1569 | StartAddress += sizeof (UINT32);
|
---|
1570 | Size -= sizeof (UINT32);
|
---|
1571 | Buffer = (UINT32*)Buffer + 1;
|
---|
1572 | }
|
---|
1573 |
|
---|
1574 | if (Size >= sizeof (UINT16)) {
|
---|
1575 | //
|
---|
1576 | // Write the last remaining word if exist
|
---|
1577 | //
|
---|
1578 | PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));
|
---|
1579 | StartAddress += sizeof (UINT16);
|
---|
1580 | Size -= sizeof (UINT16);
|
---|
1581 | Buffer = (UINT16*)Buffer + 1;
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | if (Size >= sizeof (UINT8)) {
|
---|
1585 | //
|
---|
1586 | // Write the last remaining byte if exist
|
---|
1587 | //
|
---|
1588 | PciExpressWrite8 (StartAddress, *(UINT8*)Buffer);
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | return ReturnValue;
|
---|
1592 | }
|
---|