]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseS3PciSegmentLib/S3PciSegmentLib.c
MdePkg/BasePrintLib: Fix incomplete print output
[mirror_edk2.git] / MdePkg / Library / BaseS3PciSegmentLib / S3PciSegmentLib.c
1 /** @file
2 The multiple segments PCI configuration Library Services that carry out
3 PCI configuration and enable the PCI operations to be replayed during an
4 S3 resume. This library class maps directly on top of the PciSegmentLib class.
5
6 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17
18 #include <Base.h>
19
20 #include <Library/DebugLib.h>
21 #include <Library/S3BootScriptLib.h>
22 #include <Library/PciSegmentLib.h>
23
24 /**
25 Macro that converts address in PciSegmentLib format to the new address that can be pass
26 to the S3 Boot Script Library functions. The Segment is dropped.
27
28 @param Address Address in PciSegmentLib format.
29
30 @retval New address that can be pass to the S3 Boot Script Library functions.
31 **/
32 #define PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS(Address) \
33 ((((UINT32)(Address) >> 20) & 0xff) << 24) | \
34 ((((UINT32)(Address) >> 15) & 0x1f) << 16) | \
35 ((((UINT32)(Address) >> 12) & 0x07) << 8) | \
36 LShiftU64 ((Address) & 0xfff, 32) // Always put Register in high four bytes.
37
38 /**
39 Saves a PCI configuration value to the boot script.
40
41 This internal worker function saves a PCI configuration value in
42 the S3 script to be replayed on S3 resume.
43
44 If the saving process fails, then ASSERT().
45
46 @param Width The width of PCI configuration.
47 @param Address Address that encodes the PCI Bus, Device, Function and
48 Register.
49 @param Buffer The buffer containing value.
50
51 **/
52 VOID
53 InternalSavePciSegmentWriteValueToBootScript (
54 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
55 IN UINT64 Address,
56 IN VOID *Buffer
57 )
58 {
59 RETURN_STATUS Status;
60
61 Status = S3BootScriptSavePciCfg2Write (
62 Width,
63 RShiftU64 ((Address), 32) & 0xffff,
64 PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS (Address),
65 1,
66 Buffer
67 );
68 ASSERT_RETURN_ERROR (Status);
69 }
70
71 /**
72 Saves an 8-bit PCI configuration value to the boot script.
73
74 This internal worker function saves an 8-bit PCI configuration value in
75 the S3 script to be replayed on S3 resume.
76
77 If the saving process fails, then ASSERT().
78
79 @param Address Address that encodes the PCI Bus, Device, Function and
80 Register.
81 @param Value The value saved to boot script.
82
83 @return Value.
84
85 **/
86 UINT8
87 InternalSavePciSegmentWrite8ValueToBootScript (
88 IN UINT64 Address,
89 IN UINT8 Value
90 )
91 {
92 InternalSavePciSegmentWriteValueToBootScript (S3BootScriptWidthUint8, Address, &Value);
93
94 return Value;
95 }
96
97 /**
98 Reads an 8-bit PCI configuration register, and saves the value in the S3 script to
99 be replayed on S3 resume.
100
101 Reads and returns the 8-bit PCI configuration register specified by Address.
102 This function must guarantee that all PCI read and write operations are serialized.
103
104 If any reserved bits in Address are set, then ASSERT().
105
106 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
107
108 @return The 8-bit PCI configuration register specified by Address.
109
110 **/
111 UINT8
112 EFIAPI
113 S3PciSegmentRead8 (
114 IN UINT64 Address
115 )
116 {
117 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentRead8 (Address));
118 }
119
120 /**
121 Writes an 8-bit PCI configuration register, and saves the value in the S3 script to
122 be replayed on S3 resume.
123
124 Writes the 8-bit PCI configuration register specified by Address with the value specified by Value.
125 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
126
127 If any reserved bits in Address are set, then ASSERT().
128
129 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
130 @param Value The value to write.
131
132 @return The value written to the PCI configuration register.
133
134 **/
135 UINT8
136 EFIAPI
137 S3PciSegmentWrite8 (
138 IN UINT64 Address,
139 IN UINT8 Value
140 )
141 {
142 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentWrite8 (Address, Value));
143 }
144
145 /**
146 Performs a bitwise OR of an 8-bit PCI configuration register with an 8-bit value, and saves
147 the value in the S3 script to be replayed on S3 resume.
148
149 Reads the 8-bit PCI configuration register specified by Address,
150 performs a bitwise OR between the read result and the value specified by OrData,
151 and writes the result to the 8-bit PCI configuration register specified by Address.
152 The value written to the PCI configuration register is returned.
153 This function must guarantee that all PCI read and write operations are serialized.
154
155 If any reserved bits in Address are set, then ASSERT().
156
157 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
158 @param OrData The value to OR with the PCI configuration register.
159
160 @return The value written to the PCI configuration register.
161
162 **/
163 UINT8
164 EFIAPI
165 S3PciSegmentOr8 (
166 IN UINT64 Address,
167 IN UINT8 OrData
168 )
169 {
170 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentOr8 (Address, OrData));
171 }
172
173 /**
174 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value, and
175 saves the value in the S3 script to be replayed on S3 resume.
176
177 Reads the 8-bit PCI configuration register specified by Address,
178 performs a bitwise AND between the read result and the value specified by AndData,
179 and writes the result to the 8-bit PCI configuration register specified by Address.
180 The value written to the PCI configuration register is returned.
181 This function must guarantee that all PCI read and write operations are serialized.
182 If any reserved bits in Address are set, then ASSERT().
183
184 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
185 @param AndData The value to AND with the PCI configuration register.
186
187 @return The value written to the PCI configuration register.
188
189 **/
190 UINT8
191 EFIAPI
192 S3PciSegmentAnd8 (
193 IN UINT64 Address,
194 IN UINT8 AndData
195 )
196 {
197 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentAnd8 (Address, AndData));
198 }
199
200 /**
201 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value,
202 followed a bitwise OR with another 8-bit value, and saves the value in the S3 script to
203 be replayed on S3 resume.
204
205 Reads the 8-bit PCI configuration register specified by Address,
206 performs a bitwise AND between the read result and the value specified by AndData,
207 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
208 and writes the result to the 8-bit PCI configuration register specified by Address.
209 The value written to the PCI configuration register is returned.
210 This function must guarantee that all PCI read and write operations are serialized.
211
212 If any reserved bits in Address are set, then ASSERT().
213
214 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
215 @param AndData The value to AND with the PCI configuration register.
216 @param OrData The value to OR with the PCI configuration register.
217
218 @return The value written to the PCI configuration register.
219
220 **/
221 UINT8
222 EFIAPI
223 S3PciSegmentAndThenOr8 (
224 IN UINT64 Address,
225 IN UINT8 AndData,
226 IN UINT8 OrData
227 )
228 {
229 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentAndThenOr8 (Address, AndData, OrData));
230 }
231
232 /**
233 Reads a bit field of a PCI configuration register, and saves the value in the
234 S3 script to be replayed on S3 resume.
235
236 Reads the bit field in an 8-bit PCI configuration register. The bit field is
237 specified by the StartBit and the EndBit. The value of the bit field is
238 returned.
239
240 If any reserved bits in Address are set, then ASSERT().
241 If StartBit is greater than 7, then ASSERT().
242 If EndBit is greater than 7, then ASSERT().
243 If EndBit is less than StartBit, then ASSERT().
244
245 @param Address PCI configuration register to read.
246 @param StartBit The ordinal of the least significant bit in the bit field.
247 Range 0..7.
248 @param EndBit The ordinal of the most significant bit in the bit field.
249 Range 0..7.
250
251 @return The value of the bit field read from the PCI configuration register.
252
253 **/
254 UINT8
255 EFIAPI
256 S3PciSegmentBitFieldRead8 (
257 IN UINT64 Address,
258 IN UINTN StartBit,
259 IN UINTN EndBit
260 )
261 {
262 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentBitFieldRead8 (Address, StartBit, EndBit));
263 }
264
265 /**
266 Writes a bit field to a PCI configuration register, and saves the value in
267 the S3 script to be replayed on S3 resume.
268
269 Writes Value to the bit field of the PCI configuration register. The bit
270 field is specified by the StartBit and the EndBit. All other bits in the
271 destination PCI configuration register are preserved. The new value of the
272 8-bit register is returned.
273
274 If any reserved bits in Address are set, then ASSERT().
275 If StartBit is greater than 7, then ASSERT().
276 If EndBit is greater than 7, then ASSERT().
277 If EndBit is less than StartBit, then ASSERT().
278 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
279
280 @param Address PCI configuration register to write.
281 @param StartBit The ordinal of the least significant bit in the bit field.
282 Range 0..7.
283 @param EndBit The ordinal of the most significant bit in the bit field.
284 Range 0..7.
285 @param Value New value of the bit field.
286
287 @return The value written back to the PCI configuration register.
288
289 **/
290 UINT8
291 EFIAPI
292 S3PciSegmentBitFieldWrite8 (
293 IN UINT64 Address,
294 IN UINTN StartBit,
295 IN UINTN EndBit,
296 IN UINT8 Value
297 )
298 {
299 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentBitFieldWrite8 (Address, StartBit, EndBit, Value));
300 }
301
302 /**
303 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, writes
304 the result back to the bit field in the 8-bit port, and saves the value in the
305 S3 script to be replayed on S3 resume.
306
307 Reads the 8-bit PCI configuration register specified by Address, performs a
308 bitwise OR between the read result and the value specified by
309 OrData, and writes the result to the 8-bit PCI configuration register
310 specified by Address. The value written to the PCI configuration register is
311 returned. This function must guarantee that all PCI read and write operations
312 are serialized. Extra left bits in OrData are stripped.
313
314 If any reserved bits in Address are set, then ASSERT().
315 If StartBit is greater than 7, then ASSERT().
316 If EndBit is greater than 7, then ASSERT().
317 If EndBit is less than StartBit, then ASSERT().
318 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
319
320 @param Address PCI configuration register to write.
321 @param StartBit The ordinal of the least significant bit in the bit field.
322 Range 0..7.
323 @param EndBit The ordinal of the most significant bit in the bit field.
324 Range 0..7.
325 @param OrData The value to OR with the PCI configuration register.
326
327 @return The value written back to the PCI configuration register.
328
329 **/
330 UINT8
331 EFIAPI
332 S3PciSegmentBitFieldOr8 (
333 IN UINT64 Address,
334 IN UINTN StartBit,
335 IN UINTN EndBit,
336 IN UINT8 OrData
337 )
338 {
339 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentBitFieldOr8 (Address, StartBit, EndBit, OrData));
340 }
341
342 /**
343 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
344 AND, writes the result back to the bit field in the 8-bit register, and
345 saves the value in the S3 script to be replayed on S3 resume.
346
347 Reads the 8-bit PCI configuration register specified by Address, performs a
348 bitwise AND between the read result and the value specified by AndData, and
349 writes the result to the 8-bit PCI configuration register specified by
350 Address. The value written to the PCI configuration register is returned.
351 This function must guarantee that all PCI read and write operations are
352 serialized. Extra left bits in AndData are stripped.
353
354 If any reserved bits in Address are set, then ASSERT().
355 If StartBit is greater than 7, then ASSERT().
356 If EndBit is greater than 7, then ASSERT().
357 If EndBit is less than StartBit, then ASSERT().
358 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
359
360 @param Address PCI configuration register to write.
361 @param StartBit The ordinal of the least significant bit in the bit field.
362 Range 0..7.
363 @param EndBit The ordinal of the most significant bit in the bit field.
364 Range 0..7.
365 @param AndData The value to AND with the PCI configuration register.
366
367 @return The value written back to the PCI configuration register.
368
369 **/
370 UINT8
371 EFIAPI
372 S3PciSegmentBitFieldAnd8 (
373 IN UINT64 Address,
374 IN UINTN StartBit,
375 IN UINTN EndBit,
376 IN UINT8 AndData
377 )
378 {
379 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentBitFieldAnd8 (Address, StartBit, EndBit, AndData));
380 }
381
382 /**
383 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
384 bitwise OR, writes the result back to the bit field in the 8-bit port,
385 and saves the value in the S3 script to be replayed on S3 resume.
386
387 Reads the 8-bit PCI configuration register specified by Address, performs a
388 bitwise AND followed by a bitwise OR between the read result and
389 the value specified by AndData, and writes the result to the 8-bit PCI
390 configuration register specified by Address. The value written to the PCI
391 configuration register is returned. This function must guarantee that all PCI
392 read and write operations are serialized. Extra left bits in both AndData and
393 OrData are stripped.
394
395 If any reserved bits in Address are set, then ASSERT().
396 If StartBit is greater than 7, then ASSERT().
397 If EndBit is greater than 7, then ASSERT().
398 If EndBit is less than StartBit, then ASSERT().
399 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
400 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
401
402 @param Address PCI configuration register to write.
403 @param StartBit The ordinal of the least significant bit in the bit field.
404 Range 0..7.
405 @param EndBit The ordinal of the most significant bit in the bit field.
406 Range 0..7.
407 @param AndData The value to AND with the PCI configuration register.
408 @param OrData The value to OR with the result of the AND operation.
409
410 @return The value written back to the PCI configuration register.
411
412 **/
413 UINT8
414 EFIAPI
415 S3PciSegmentBitFieldAndThenOr8 (
416 IN UINT64 Address,
417 IN UINTN StartBit,
418 IN UINTN EndBit,
419 IN UINT8 AndData,
420 IN UINT8 OrData
421 )
422 {
423 return InternalSavePciSegmentWrite8ValueToBootScript (Address, PciSegmentBitFieldAndThenOr8 (Address, StartBit, EndBit, AndData, OrData));
424 }
425
426 /**
427 Saves a 16-bit PCI configuration value to the boot script.
428
429 This internal worker function saves a 16-bit PCI configuration value in
430 the S3 script to be replayed on S3 resume.
431
432 If the saving process fails, then ASSERT().
433
434 @param Address Address that encodes the PCI Bus, Device, Function and
435 Register.
436 @param Value The value saved to boot script.
437
438 @return Value.
439
440 **/
441 UINT16
442 InternalSavePciSegmentWrite16ValueToBootScript (
443 IN UINT64 Address,
444 IN UINT16 Value
445 )
446 {
447 InternalSavePciSegmentWriteValueToBootScript (S3BootScriptWidthUint16, Address, &Value);
448
449 return Value;
450 }
451
452 /**
453 Reads a 16-bit PCI configuration register, and saves the value in the S3 script
454 to be replayed on S3 resume.
455
456 Reads and returns the 16-bit PCI configuration register specified by Address.
457 This function must guarantee that all PCI read and write operations are serialized.
458
459 If any reserved bits in Address are set, then ASSERT().
460 If Address is not aligned on a 16-bit boundary, then ASSERT().
461
462 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
463
464 @return The 16-bit PCI configuration register specified by Address.
465
466 **/
467 UINT16
468 EFIAPI
469 S3PciSegmentRead16 (
470 IN UINT64 Address
471 )
472 {
473 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentRead16 (Address));
474 }
475
476 /**
477 Writes a 16-bit PCI configuration register, and saves the value in the S3 script to
478 be replayed on S3 resume.
479
480 Writes the 16-bit PCI configuration register specified by Address with the value specified by Value.
481 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
482
483 If any reserved bits in Address are set, then ASSERT().
484 If Address is not aligned on a 16-bit boundary, then ASSERT().
485
486 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
487 @param Value The value to write.
488
489 @return The parameter of Value.
490
491 **/
492 UINT16
493 EFIAPI
494 S3PciSegmentWrite16 (
495 IN UINT64 Address,
496 IN UINT16 Value
497 )
498 {
499 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentWrite16 (Address, Value));
500 }
501
502 /**
503 Performs a bitwise OR of a 16-bit PCI configuration register with a 16-bit
504 value, and saves the value in the S3 script to be replayed on S3 resume.
505
506 Reads the 16-bit PCI configuration register specified by Address, performs a
507 bitwise OR between the read result and the value specified by OrData, and
508 writes the result to the 16-bit PCI configuration register specified by Address.
509 The value written to the PCI configuration register is returned. This function
510 must guarantee that all PCI read and write operations are serialized.
511
512 If any reserved bits in Address are set, then ASSERT().
513 If Address is not aligned on a 16-bit boundary, then ASSERT().
514
515 @param Address Address that encodes the PCI Segment, Bus, Device, Function and
516 Register.
517 @param OrData The value to OR with the PCI configuration register.
518
519 @return The value written back to the PCI configuration register.
520
521 **/
522 UINT16
523 EFIAPI
524 S3PciSegmentOr16 (
525 IN UINT64 Address,
526 IN UINT16 OrData
527 )
528 {
529 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentOr16 (Address, OrData));
530 }
531
532 /**
533 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value, and
534 saves the value in the S3 script to be replayed on S3 resume.
535
536 Reads the 16-bit PCI configuration register specified by Address,
537 performs a bitwise AND between the read result and the value specified by AndData,
538 and writes the result to the 16-bit PCI configuration register specified by Address.
539 The value written to the PCI configuration register is returned.
540 This function must guarantee that all PCI read and write operations are serialized.
541
542 If any reserved bits in Address are set, then ASSERT().
543 If Address is not aligned on a 16-bit boundary, then ASSERT().
544
545 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
546 @param AndData The value to AND with the PCI configuration register.
547
548 @return The value written to the PCI configuration register.
549
550 **/
551 UINT16
552 EFIAPI
553 S3PciSegmentAnd16 (
554 IN UINT64 Address,
555 IN UINT16 AndData
556 )
557 {
558 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentAnd16 (Address, AndData));
559 }
560
561 /**
562 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value,
563 followed a bitwise OR with another 16-bit value, and saves the value in the S3 script to
564 be replayed on S3 resume.
565
566 Reads the 16-bit PCI configuration register specified by Address,
567 performs a bitwise AND between the read result and the value specified by AndData,
568 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
569 and writes the result to the 16-bit PCI configuration register specified by Address.
570 The value written to the PCI configuration register is returned.
571 This function must guarantee that all PCI read and write operations are serialized.
572
573 If any reserved bits in Address are set, then ASSERT().
574 If Address is not aligned on a 16-bit boundary, then ASSERT().
575
576 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
577 @param AndData The value to AND with the PCI configuration register.
578 @param OrData The value to OR with the PCI configuration register.
579
580 @return The value written to the PCI configuration register.
581
582 **/
583 UINT16
584 EFIAPI
585 S3PciSegmentAndThenOr16 (
586 IN UINT64 Address,
587 IN UINT16 AndData,
588 IN UINT16 OrData
589 )
590 {
591 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentAndThenOr16 (Address, AndData, OrData));
592 }
593
594 /**
595 Reads a bit field of a PCI configuration register, and saves the value in the
596 S3 script to be replayed on S3 resume.
597
598 Reads the bit field in a 16-bit PCI configuration register. The bit field is
599 specified by the StartBit and the EndBit. The value of the bit field is
600 returned.
601
602 If any reserved bits in Address are set, then ASSERT().
603 If Address is not aligned on a 16-bit boundary, then ASSERT().
604 If StartBit is greater than 15, then ASSERT().
605 If EndBit is greater than 15, then ASSERT().
606 If EndBit is less than StartBit, then ASSERT().
607
608 @param Address PCI configuration register to read.
609 @param StartBit The ordinal of the least significant bit in the bit field.
610 Range 0..15.
611 @param EndBit The ordinal of the most significant bit in the bit field.
612 Range 0..15.
613
614 @return The value of the bit field read from the PCI configuration register.
615
616 **/
617 UINT16
618 EFIAPI
619 S3PciSegmentBitFieldRead16 (
620 IN UINT64 Address,
621 IN UINTN StartBit,
622 IN UINTN EndBit
623 )
624 {
625 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentBitFieldRead16 (Address, StartBit, EndBit));
626 }
627
628 /**
629 Writes a bit field to a PCI configuration register, and saves the value in
630 the S3 script to be replayed on S3 resume.
631
632 Writes Value to the bit field of the PCI configuration register. The bit
633 field is specified by the StartBit and the EndBit. All other bits in the
634 destination PCI configuration register are preserved. The new value of the
635 16-bit register is returned.
636
637 If any reserved bits in Address are set, then ASSERT().
638 If Address is not aligned on a 16-bit boundary, then ASSERT().
639 If StartBit is greater than 15, then ASSERT().
640 If EndBit is greater than 15, then ASSERT().
641 If EndBit is less than StartBit, then ASSERT().
642 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
643
644 @param Address PCI configuration register to write.
645 @param StartBit The ordinal of the least significant bit in the bit field.
646 Range 0..15.
647 @param EndBit The ordinal of the most significant bit in the bit field.
648 Range 0..15.
649 @param Value New value of the bit field.
650
651 @return The value written back to the PCI configuration register.
652
653 **/
654 UINT16
655 EFIAPI
656 S3PciSegmentBitFieldWrite16 (
657 IN UINT64 Address,
658 IN UINTN StartBit,
659 IN UINTN EndBit,
660 IN UINT16 Value
661 )
662 {
663 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentBitFieldWrite16 (Address, StartBit, EndBit, Value));
664 }
665
666 /**
667 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, writes
668 the result back to the bit field in the 16-bit port, and saves the value in the
669 S3 script to be replayed on S3 resume.
670
671 Reads the 16-bit PCI configuration register specified by Address, performs a
672 bitwise OR between the read result and the value specified by
673 OrData, and writes the result to the 16-bit PCI configuration register
674 specified by Address. The value written to the PCI configuration register is
675 returned. This function must guarantee that all PCI read and write operations
676 are serialized. Extra left bits in OrData are stripped.
677
678 If any reserved bits in Address are set, then ASSERT().
679 If Address is not aligned on a 16-bit boundary, then ASSERT().
680 If StartBit is greater than 15, then ASSERT().
681 If EndBit is greater than 15, then ASSERT().
682 If EndBit is less than StartBit, then ASSERT().
683 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
684
685 @param Address PCI configuration register to write.
686 @param StartBit The ordinal of the least significant bit in the bit field.
687 Range 0..15.
688 @param EndBit The ordinal of the most significant bit in the bit field.
689 Range 0..15.
690 @param OrData The value to OR with the PCI configuration register.
691
692 @return The value written back to the PCI configuration register.
693
694 **/
695 UINT16
696 EFIAPI
697 S3PciSegmentBitFieldOr16 (
698 IN UINT64 Address,
699 IN UINTN StartBit,
700 IN UINTN EndBit,
701 IN UINT16 OrData
702 )
703 {
704 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentBitFieldOr16 (Address, StartBit, EndBit, OrData));
705 }
706
707 /**
708 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
709 AND, writes the result back to the bit field in the 16-bit register, and
710 saves the value in the S3 script to be replayed on S3 resume.
711
712 Reads the 16-bit PCI configuration register specified by Address, performs a
713 bitwise AND between the read result and the value specified by AndData, and
714 writes the result to the 16-bit PCI configuration register specified by
715 Address. The value written to the PCI configuration register is returned.
716 This function must guarantee that all PCI read and write operations are
717 serialized. Extra left bits in AndData are stripped.
718
719 If any reserved bits in Address are set, then ASSERT().
720 If Address is not aligned on a 16-bit boundary, then ASSERT().
721 If StartBit is greater than 15, then ASSERT().
722 If EndBit is greater than 15, then ASSERT().
723 If EndBit is less than StartBit, then ASSERT().
724 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
725
726 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
727 @param StartBit The ordinal of the least significant bit in the bit field.
728 Range 0..15.
729 @param EndBit The ordinal of the most significant bit in the bit field.
730 Range 0..15.
731 @param AndData The value to AND with the PCI configuration register.
732
733 @return The value written back to the PCI configuration register.
734
735 **/
736 UINT16
737 EFIAPI
738 S3PciSegmentBitFieldAnd16 (
739 IN UINT64 Address,
740 IN UINTN StartBit,
741 IN UINTN EndBit,
742 IN UINT16 AndData
743 )
744 {
745 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentBitFieldAnd16 (Address, StartBit, EndBit, AndData));
746 }
747
748 /**
749 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
750 bitwise OR, writes the result back to the bit field in the 16-bit port,
751 and saves the value in the S3 script to be replayed on S3 resume.
752
753 Reads the 16-bit PCI configuration register specified by Address, performs a
754 bitwise AND followed by a bitwise OR between the read result and
755 the value specified by AndData, and writes the result to the 16-bit PCI
756 configuration register specified by Address. The value written to the PCI
757 configuration register is returned. This function must guarantee that all PCI
758 read and write operations are serialized. Extra left bits in both AndData and
759 OrData are stripped.
760
761 If any reserved bits in Address are set, then ASSERT().
762 If StartBit is greater than 15, then ASSERT().
763 If EndBit is greater than 15, then ASSERT().
764 If EndBit is less than StartBit, then ASSERT().
765 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
766 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
767
768 @param Address PCI configuration register to write.
769 @param StartBit The ordinal of the least significant bit in the bit field.
770 Range 0..15.
771 @param EndBit The ordinal of the most significant bit in the bit field.
772 Range 0..15.
773 @param AndData The value to AND with the PCI configuration register.
774 @param OrData The value to OR with the result of the AND operation.
775
776 @return The value written back to the PCI configuration register.
777
778 **/
779 UINT16
780 EFIAPI
781 S3PciSegmentBitFieldAndThenOr16 (
782 IN UINT64 Address,
783 IN UINTN StartBit,
784 IN UINTN EndBit,
785 IN UINT16 AndData,
786 IN UINT16 OrData
787 )
788 {
789 return InternalSavePciSegmentWrite16ValueToBootScript (Address, PciSegmentBitFieldAndThenOr16 (Address, StartBit, EndBit, AndData, OrData));
790 }
791
792
793
794 /**
795 Saves a 32-bit PCI configuration value to the boot script.
796
797 This internal worker function saves a 32-bit PCI configuration value in the S3 script
798 to be replayed on S3 resume.
799
800 If the saving process fails, then ASSERT().
801
802 @param Address Address that encodes the PCI Bus, Device, Function and
803 Register.
804 @param Value The value saved to boot script.
805
806 @return Value.
807
808 **/
809 UINT32
810 InternalSavePciSegmentWrite32ValueToBootScript (
811 IN UINT64 Address,
812 IN UINT32 Value
813 )
814 {
815 InternalSavePciSegmentWriteValueToBootScript (S3BootScriptWidthUint32, Address, &Value);
816
817 return Value;
818 }
819
820 /**
821 Reads a 32-bit PCI configuration register, and saves the value in the S3 script
822 to be replayed on S3 resume.
823
824 Reads and returns the 32-bit PCI configuration register specified by Address.
825 This function must guarantee that all PCI read and write operations are serialized.
826
827 If any reserved bits in Address are set, then ASSERT().
828 If Address is not aligned on a 32-bit boundary, then ASSERT().
829
830 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
831
832 @return The 32-bit PCI configuration register specified by Address.
833
834 **/
835 UINT32
836 EFIAPI
837 S3PciSegmentRead32 (
838 IN UINT64 Address
839 )
840 {
841 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentRead32 (Address));
842 }
843
844 /**
845 Writes a 32-bit PCI configuration register, and saves the value in the S3 script to
846 be replayed on S3 resume.
847
848 Writes the 32-bit PCI configuration register specified by Address with the value specified by Value.
849 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
850
851 If any reserved bits in Address are set, then ASSERT().
852 If Address is not aligned on a 32-bit boundary, then ASSERT().
853
854 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
855 @param Value The value to write.
856
857 @return The parameter of Value.
858
859 **/
860 UINT32
861 EFIAPI
862 S3PciSegmentWrite32 (
863 IN UINT64 Address,
864 IN UINT32 Value
865 )
866 {
867 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentWrite32 (Address, Value));
868 }
869
870 /**
871 Performs a bitwise OR of a 32-bit PCI configuration register with a 32-bit
872 value, and saves the value in the S3 script to be replayed on S3 resume.
873
874 Reads the 32-bit PCI configuration register specified by Address, performs a
875 bitwise OR between the read result and the value specified by OrData, and
876 writes the result to the 32-bit PCI configuration register specified by Address.
877 The value written to the PCI configuration register is returned. This function
878 must guarantee that all PCI read and write operations are serialized.
879
880 If any reserved bits in Address are set, then ASSERT().
881 If Address is not aligned on a 32-bit boundary, then ASSERT().
882
883 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and
884 Register.
885 @param OrData The value to OR with the PCI configuration register.
886
887 @return The value written back to the PCI configuration register.
888
889 **/
890 UINT32
891 EFIAPI
892 S3PciSegmentOr32 (
893 IN UINT64 Address,
894 IN UINT32 OrData
895 )
896 {
897 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentOr32 (Address, OrData));
898 }
899
900 /**
901 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value, and
902 saves the value in the S3 script to be replayed on S3 resume.
903
904 Reads the 32-bit PCI configuration register specified by Address,
905 performs a bitwise AND between the read result and the value specified by AndData,
906 and writes the result to the 32-bit PCI configuration register specified by Address.
907 The value written to the PCI configuration register is returned.
908 This function must guarantee that all PCI read and write operations are serialized.
909
910 If any reserved bits in Address are set, then ASSERT().
911 If Address is not aligned on a 32-bit boundary, then ASSERT().
912
913 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
914 @param AndData The value to AND with the PCI configuration register.
915
916 @return The value written to the PCI configuration register.
917
918 **/
919 UINT32
920 EFIAPI
921 S3PciSegmentAnd32 (
922 IN UINT64 Address,
923 IN UINT32 AndData
924 )
925 {
926 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentAnd32 (Address, AndData));
927 }
928
929 /**
930 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value,
931 followed a bitwise OR with another 32-bit value, and saves the value in the S3 script to
932 be replayed on S3 resume.
933
934 Reads the 32-bit PCI configuration register specified by Address,
935 performs a bitwise AND between the read result and the value specified by AndData,
936 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
937 and writes the result to the 32-bit PCI configuration register specified by Address.
938 The value written to the PCI configuration register is returned.
939 This function must guarantee that all PCI read and write operations are serialized.
940
941 If any reserved bits in Address are set, then ASSERT().
942 If Address is not aligned on a 32-bit boundary, then ASSERT().
943
944 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
945 @param AndData The value to AND with the PCI configuration register.
946 @param OrData The value to OR with the PCI configuration register.
947
948 @return The value written to the PCI configuration register.
949
950 **/
951 UINT32
952 EFIAPI
953 S3PciSegmentAndThenOr32 (
954 IN UINT64 Address,
955 IN UINT32 AndData,
956 IN UINT32 OrData
957 )
958 {
959 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentAndThenOr32 (Address, AndData, OrData));
960 }
961
962 /**
963 Reads a bit field of a PCI configuration register, and saves the value in the
964 S3 script to be replayed on S3 resume.
965
966 Reads the bit field in a 32-bit PCI configuration register. The bit field is
967 specified by the StartBit and the EndBit. The value of the bit field is
968 returned.
969
970 If any reserved bits in Address are set, then ASSERT().
971 If Address is not aligned on a 32-bit boundary, then ASSERT().
972 If StartBit is greater than 31, then ASSERT().
973 If EndBit is greater than 31, then ASSERT().
974 If EndBit is less than StartBit, then ASSERT().
975
976 @param Address PCI configuration register to read.
977 @param StartBit The ordinal of the least significant bit in the bit field.
978 Range 0..31.
979 @param EndBit The ordinal of the most significant bit in the bit field.
980 Range 0..31.
981
982 @return The value of the bit field read from the PCI configuration register.
983
984 **/
985 UINT32
986 EFIAPI
987 S3PciSegmentBitFieldRead32 (
988 IN UINT64 Address,
989 IN UINTN StartBit,
990 IN UINTN EndBit
991 )
992 {
993 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentBitFieldRead32 (Address, StartBit, EndBit));
994 }
995
996 /**
997 Writes a bit field to a PCI configuration register, and saves the value in
998 the S3 script to be replayed on S3 resume.
999
1000 Writes Value to the bit field of the PCI configuration register. The bit
1001 field is specified by the StartBit and the EndBit. All other bits in the
1002 destination PCI configuration register are preserved. The new value of the
1003 32-bit register is returned.
1004
1005 If any reserved bits in Address are set, then ASSERT().
1006 If Address is not aligned on a 32-bit boundary, then ASSERT().
1007 If StartBit is greater than 31, then ASSERT().
1008 If EndBit is greater than 31, then ASSERT().
1009 If EndBit is less than StartBit, then ASSERT().
1010 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1011
1012 @param Address PCI configuration register to write.
1013 @param StartBit The ordinal of the least significant bit in the bit field.
1014 Range 0..31.
1015 @param EndBit The ordinal of the most significant bit in the bit field.
1016 Range 0..31.
1017 @param Value New value of the bit field.
1018
1019 @return The value written back to the PCI configuration register.
1020
1021 **/
1022 UINT32
1023 EFIAPI
1024 S3PciSegmentBitFieldWrite32 (
1025 IN UINT64 Address,
1026 IN UINTN StartBit,
1027 IN UINTN EndBit,
1028 IN UINT32 Value
1029 )
1030 {
1031 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentBitFieldWrite32 (Address, StartBit, EndBit, Value));
1032 }
1033
1034 /**
1035 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, writes
1036 the result back to the bit field in the 32-bit port, and saves the value in the
1037 S3 script to be replayed on S3 resume.
1038
1039 Reads the 32-bit PCI configuration register specified by Address, performs a
1040 bitwise OR between the read result and the value specified by
1041 OrData, and writes the result to the 32-bit PCI configuration register
1042 specified by Address. The value written to the PCI configuration register is
1043 returned. This function must guarantee that all PCI read and write operations
1044 are serialized. Extra left bits in OrData are stripped.
1045
1046 If any reserved bits in Address are set, then ASSERT().
1047 If Address is not aligned on a 32-bit boundary, then ASSERT().
1048 If StartBit is greater than 31, then ASSERT().
1049 If EndBit is greater than 31, then ASSERT().
1050 If EndBit is less than StartBit, then ASSERT().
1051 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1052
1053 @param Address PCI configuration register to write.
1054 @param StartBit The ordinal of the least significant bit in the bit field.
1055 Range 0..31.
1056 @param EndBit The ordinal of the most significant bit in the bit field.
1057 Range 0..31.
1058 @param OrData The value to OR with the PCI configuration register.
1059
1060 @return The value written back to the PCI configuration register.
1061
1062 **/
1063 UINT32
1064 EFIAPI
1065 S3PciSegmentBitFieldOr32 (
1066 IN UINT64 Address,
1067 IN UINTN StartBit,
1068 IN UINTN EndBit,
1069 IN UINT32 OrData
1070 )
1071 {
1072 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentBitFieldOr32 (Address, StartBit, EndBit, OrData));
1073 }
1074
1075 /**
1076 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
1077 AND, and writes the result back to the bit field in the 32-bit register, and
1078 saves the value in the S3 script to be replayed on S3 resume.
1079
1080 Reads the 32-bit PCI configuration register specified by Address, performs a
1081 bitwise AND between the read result and the value specified by AndData, and
1082 writes the result to the 32-bit PCI configuration register specified by
1083 Address. The value written to the PCI configuration register is returned.
1084 This function must guarantee that all PCI read and write operations are
1085 serialized. Extra left bits in AndData are stripped.
1086
1087 If any reserved bits in Address are set, then ASSERT().
1088 If Address is not aligned on a 32-bit boundary, then ASSERT().
1089 If StartBit is greater than 31, then ASSERT().
1090 If EndBit is greater than 31, then ASSERT().
1091 If EndBit is less than StartBit, then ASSERT().
1092 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1093
1094 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
1095 @param StartBit The ordinal of the least significant bit in the bit field.
1096 Range 0..31.
1097 @param EndBit The ordinal of the most significant bit in the bit field.
1098 Range 0..31.
1099 @param AndData The value to AND with the PCI configuration register.
1100
1101 @return The value written back to the PCI configuration register.
1102
1103 **/
1104 UINT32
1105 EFIAPI
1106 S3PciSegmentBitFieldAnd32 (
1107 IN UINT64 Address,
1108 IN UINTN StartBit,
1109 IN UINTN EndBit,
1110 IN UINT32 AndData
1111 )
1112 {
1113 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentBitFieldAnd32 (Address, StartBit, EndBit, AndData));
1114 }
1115
1116 /**
1117 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
1118 bitwise OR, writes the result back to the bit field in the 32-bit port,
1119 and saves the value in the S3 script to be replayed on S3 resume.
1120
1121 Reads the 32-bit PCI configuration register specified by Address, performs a
1122 bitwise AND followed by a bitwise OR between the read result and
1123 the value specified by AndData, and writes the result to the 32-bit PCI
1124 configuration register specified by Address. The value written to the PCI
1125 configuration register is returned. This function must guarantee that all PCI
1126 read and write operations are serialized. Extra left bits in both AndData and
1127 OrData are stripped.
1128
1129 If any reserved bits in Address are set, then ASSERT().
1130 If StartBit is greater than 31, then ASSERT().
1131 If EndBit is greater than 31, then ASSERT().
1132 If EndBit is less than StartBit, then ASSERT().
1133 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1134 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1135
1136 @param Address PCI configuration register to write.
1137 @param StartBit The ordinal of the least significant bit in the bit field.
1138 Range 0..31.
1139 @param EndBit The ordinal of the most significant bit in the bit field.
1140 Range 0..31.
1141 @param AndData The value to AND with the PCI configuration register.
1142 @param OrData The value to OR with the result of the AND operation.
1143
1144 @return The value written back to the PCI configuration register.
1145
1146 **/
1147 UINT32
1148 EFIAPI
1149 S3PciSegmentBitFieldAndThenOr32 (
1150 IN UINT64 Address,
1151 IN UINTN StartBit,
1152 IN UINTN EndBit,
1153 IN UINT32 AndData,
1154 IN UINT32 OrData
1155 )
1156 {
1157 return InternalSavePciSegmentWrite32ValueToBootScript (Address, PciSegmentBitFieldAndThenOr32 (Address, StartBit, EndBit, AndData, OrData));
1158 }
1159
1160 /**
1161 Reads a range of PCI configuration registers into a caller supplied buffer,
1162 and saves the value in the S3 script to be replayed on S3 resume.
1163
1164 Reads the range of PCI configuration registers specified by StartAddress and
1165 Size into the buffer specified by Buffer. This function only allows the PCI
1166 configuration registers from a single PCI function to be read. Size is
1167 returned. When possible 32-bit PCI configuration read cycles are used to read
1168 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
1169 and 16-bit PCI configuration read cycles may be used at the beginning and the
1170 end of the range.
1171
1172 If any reserved bits in StartAddress are set, then ASSERT().
1173 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1174 If Size > 0 and Buffer is NULL, then ASSERT().
1175
1176 @param StartAddress Starting address that encodes the PCI Segment, Bus, Device,
1177 Function and Register.
1178 @param Size Size in bytes of the transfer.
1179 @param Buffer Pointer to a buffer receiving the data read.
1180
1181 @return Size
1182
1183 **/
1184 UINTN
1185 EFIAPI
1186 S3PciSegmentReadBuffer (
1187 IN UINT64 StartAddress,
1188 IN UINTN Size,
1189 OUT VOID *Buffer
1190 )
1191 {
1192 RETURN_STATUS Status;
1193
1194 Status = S3BootScriptSavePciCfg2Write (
1195 S3BootScriptWidthUint8,
1196 RShiftU64 (StartAddress, 32) & 0xffff,
1197 PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS (StartAddress),
1198 PciSegmentReadBuffer (StartAddress, Size, Buffer),
1199 Buffer
1200 );
1201 ASSERT_RETURN_ERROR (Status);
1202 return Size;
1203 }
1204
1205 /**
1206 Copies the data in a caller supplied buffer to a specified range of PCI
1207 configuration space, and saves the value in the S3 script to be replayed on S3
1208 resume.
1209
1210 Writes the range of PCI configuration registers specified by StartAddress and
1211 Size from the buffer specified by Buffer. This function only allows the PCI
1212 configuration registers from a single PCI function to be written. Size is
1213 returned. When possible 32-bit PCI configuration write cycles are used to
1214 write from StartAdress to StartAddress + Size. Due to alignment restrictions,
1215 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1216 and the end of the range.
1217
1218 If any reserved bits in StartAddress are set, then ASSERT().
1219 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1220 If Size > 0 and Buffer is NULL, then ASSERT().
1221
1222 @param StartAddress Starting address that encodes the PCI Segment, Bus, Device,
1223 Function and Register.
1224 @param Size Size in bytes of the transfer.
1225 @param Buffer Pointer to a buffer containing the data to write.
1226
1227 @return The parameter of Size.
1228
1229 **/
1230 UINTN
1231 EFIAPI
1232 S3PciSegmentWriteBuffer (
1233 IN UINT64 StartAddress,
1234 IN UINTN Size,
1235 IN VOID *Buffer
1236 )
1237 {
1238 RETURN_STATUS Status;
1239
1240 Status = S3BootScriptSavePciCfg2Write (
1241 S3BootScriptWidthUint8,
1242 RShiftU64 (StartAddress, 32) & 0xffff,
1243 PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS (StartAddress),
1244 PciSegmentWriteBuffer (StartAddress, Size, Buffer),
1245 Buffer
1246 );
1247 ASSERT_RETURN_ERROR (Status);
1248 return Size;
1249 }