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