]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiPciLibPciRootBridgeIo/PciLib.c
Update the copyright notice format
[mirror_edk2.git] / MdePkg / Library / UefiPciLibPciRootBridgeIo / PciLib.c
CommitLineData
1a3eaf06 1/** @file\r
2 PCI Library using PCI Root Bridge I/O Protocol.\r
3\r
19388d29
HT
4 Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials are\r
1a3eaf06 6 licensed and made available under the terms and conditions of\r
7 the BSD License which accompanies this distribution. The full\r
8 text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <PiDxe.h>\r
17\r
18#include <Protocol/PciRootBridgeIo.h>\r
19\r
20#include <Library/PciLib.h>\r
21#include <Library/BaseLib.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23#include <Library/DebugLib.h>\r
24\r
25/**\r
26 Assert the validity of a PCI address. A valid PCI address should contain 1's\r
27 only in the low 28 bits.\r
28\r
29 @param A The address to validate.\r
30 @param M Additional bits to assert to be zero.\r
31\r
32**/\r
33#define ASSERT_INVALID_PCI_ADDRESS(A,M) \\r
34 ASSERT (((A) & (~0xfffffff | (M))) == 0)\r
35\r
36/**\r
e43e4b3e 37 Translate PCI Lib address into format of PCI Root Bridge I/O Protocol.\r
1a3eaf06 38\r
39 @param A Address that encodes the PCI Bus, Device, Function and\r
40 Register.\r
41\r
42**/\r
e43e4b3e 43#define PCI_TO_PCI_ROOT_BRIDGE_IO_ADDRESS(A) \\r
44 ((((A) << 4) & 0xff000000) | (((A) >> 4) & 0x00000700) | (((A) << 1) & 0x001f0000) | (LShiftU64((A) & 0xfff, 32)))\r
1a3eaf06 45\r
46//\r
47// Global varible to cache pointer to PCI Root Bridge I/O protocol.\r
48//\r
49EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *mPciRootBridgeIo = NULL; \r
50\r
51/**\r
52 The constructor function caches the pointer to PCI Root Bridge I/O protocol.\r
53 \r
54 The constructor function locates PCI Root Bridge I/O protocol from protocol database.\r
55 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
56\r
57 @param ImageHandle The firmware allocated handle for the EFI image.\r
58 @param SystemTable A pointer to the EFI System Table.\r
59 \r
60 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
61\r
62**/\r
63EFI_STATUS\r
64EFIAPI\r
65PciLibConstructor (\r
66 IN EFI_HANDLE ImageHandle,\r
67 IN EFI_SYSTEM_TABLE *SystemTable\r
68 )\r
69{\r
70 EFI_STATUS Status;\r
71 \r
72 Status = gBS->LocateProtocol (&gEfiPciRootBridgeIoProtocolGuid, NULL, (VOID**) &mPciRootBridgeIo);\r
73 ASSERT_EFI_ERROR (Status);\r
74 ASSERT (mPciRootBridgeIo != NULL);\r
75\r
76 return EFI_SUCCESS;\r
77}\r
78\r
79/**\r
80 Internal worker function to read a PCI configuration register.\r
81\r
82 This function wraps EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Pci.Read() service.\r
83 It reads and returns the PCI configuration register specified by Address,\r
84 the width of data is specified by Width.\r
85\r
86 @param Address Address that encodes the PCI Bus, Device, Function and\r
87 Register.\r
88 @param Width Width of data to read\r
89\r
90 @return The value read from the PCI configuration register.\r
91\r
92**/\r
93UINT32\r
94DxePciLibPciRootBridgeIoReadWorker (\r
95 IN UINTN Address,\r
96 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width\r
97 )\r
98{\r
99 UINT32 Data;\r
100\r
101 mPciRootBridgeIo->Pci.Read (\r
102 mPciRootBridgeIo,\r
103 Width,\r
e43e4b3e 104 PCI_TO_PCI_ROOT_BRIDGE_IO_ADDRESS (Address),\r
1a3eaf06 105 1,\r
106 &Data\r
107 );\r
108\r
109 return Data;\r
110}\r
111\r
112/**\r
113 Internal worker function to writes a PCI configuration register.\r
114\r
115 This function wraps EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Pci.Write() service.\r
116 It writes the PCI configuration register specified by Address with the\r
117 value specified by Data. The width of data is specifed by Width.\r
118 Data is returned.\r
119\r
120 @param Address Address that encodes the PCI Bus, Device, Function and\r
121 Register.\r
122 @param Width Width of data to write\r
123 @param Data The value to write.\r
124\r
125 @return The value written to the PCI configuration register.\r
126\r
127**/\r
128UINT32\r
129DxePciLibPciRootBridgeIoWriteWorker (\r
130 IN UINTN Address,\r
131 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
132 IN UINT32 Data\r
133 )\r
134{\r
135 mPciRootBridgeIo->Pci.Write (\r
136 mPciRootBridgeIo,\r
137 Width,\r
e43e4b3e 138 PCI_TO_PCI_ROOT_BRIDGE_IO_ADDRESS (Address),\r
1a3eaf06 139 1,\r
140 &Data\r
141 );\r
142 return Data;\r
143}\r
144\r
3e3ae634 145/**\r
070a76b1 146 Registers a PCI device so PCI configuration registers may be accessed after \r
3e3ae634 147 SetVirtualAddressMap().\r
148 \r
070a76b1 149 Registers the PCI device specified by Address so all the PCI configuration registers \r
150 associated with that PCI device may be accessed after SetVirtualAddressMap() is called.\r
151 \r
3e3ae634 152 If Address > 0x0FFFFFFF, then ASSERT().\r
153\r
154 @param Address Address that encodes the PCI Bus, Device, Function and\r
155 Register.\r
156 \r
157 @retval RETURN_SUCCESS The PCI device was registered for runtime access.\r
158 @retval RETURN_UNSUPPORTED An attempt was made to call this function \r
159 after ExitBootServices().\r
160 @retval RETURN_UNSUPPORTED The resources required to access the PCI device\r
161 at runtime could not be mapped.\r
162 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to\r
163 complete the registration.\r
164\r
165**/\r
166RETURN_STATUS\r
167EFIAPI\r
168PciRegisterForRuntimeAccess (\r
169 IN UINTN Address\r
170 )\r
171{\r
59ceeabe 172 ASSERT_INVALID_PCI_ADDRESS (Address, 0);\r
3e3ae634 173 return RETURN_UNSUPPORTED;\r
174}\r
175\r
1a3eaf06 176/**\r
177 Reads an 8-bit PCI configuration register.\r
178\r
179 Reads and returns the 8-bit PCI configuration register specified by Address.\r
180 This function must guarantee that all PCI read and write operations are\r
181 serialized.\r
182\r
183 If Address > 0x0FFFFFFF, then ASSERT().\r
184\r
185 @param Address Address that encodes the PCI Bus, Device, Function and\r
186 Register.\r
187\r
070a76b1 188 @return The read value from the PCI configuration register.\r
1a3eaf06 189\r
190**/\r
191UINT8\r
192EFIAPI\r
193PciRead8 (\r
194 IN UINTN Address\r
195 )\r
196{\r
197 ASSERT_INVALID_PCI_ADDRESS (Address, 0);\r
198\r
199 return (UINT8) DxePciLibPciRootBridgeIoReadWorker (Address, EfiPciWidthUint8);\r
200}\r
201\r
202/**\r
203 Writes an 8-bit PCI configuration register.\r
204\r
205 Writes the 8-bit PCI configuration register specified by Address with the\r
206 value specified by Value. Value is returned. This function must guarantee\r
207 that all PCI read and write operations are serialized.\r
208\r
209 If Address > 0x0FFFFFFF, then ASSERT().\r
210\r
211 @param Address Address that encodes the PCI Bus, Device, Function and\r
212 Register.\r
070a76b1 213 @param Value The value to write.\r
1a3eaf06 214\r
215 @return The value written to the PCI configuration register.\r
216\r
217**/\r
218UINT8\r
219EFIAPI\r
220PciWrite8 (\r
221 IN UINTN Address,\r
070a76b1 222 IN UINT8 Value\r
1a3eaf06 223 )\r
224{\r
225 ASSERT_INVALID_PCI_ADDRESS (Address, 0);\r
226\r
070a76b1 227 return (UINT8) DxePciLibPciRootBridgeIoWriteWorker (Address, EfiPciWidthUint8, Value);\r
1a3eaf06 228}\r
229\r
230/**\r
62991af2 231 Performs a bitwise OR of an 8-bit PCI configuration register with\r
1a3eaf06 232 an 8-bit value.\r
233\r
234 Reads the 8-bit PCI configuration register specified by Address, performs a\r
62991af2 235 bitwise OR between the read result and the value specified by\r
1a3eaf06 236 OrData, and writes the result to the 8-bit PCI configuration register\r
237 specified by Address. The value written to the PCI configuration register is\r
238 returned. This function must guarantee that all PCI read and write operations\r
239 are serialized.\r
240\r
241 If Address > 0x0FFFFFFF, then ASSERT().\r
242\r
243 @param Address Address that encodes the PCI Bus, Device, Function and\r
244 Register.\r
245 @param OrData The value to OR with the PCI configuration register.\r
246\r
247 @return The value written back to the PCI configuration register.\r
248\r
249**/\r
250UINT8\r
251EFIAPI\r
252PciOr8 (\r
253 IN UINTN Address,\r
254 IN UINT8 OrData\r
255 )\r
256{\r
257 return PciWrite8 (Address, (UINT8) (PciRead8 (Address) | OrData));\r
258}\r
259\r
260/**\r
261 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit\r
262 value.\r
263\r
264 Reads the 8-bit PCI configuration register specified by Address, performs a\r
265 bitwise AND between the read result and the value specified by AndData, and\r
266 writes the result to the 8-bit PCI configuration register specified by\r
267 Address. The value written to the PCI configuration register is returned.\r
268 This function must guarantee that all PCI read and write operations are\r
269 serialized.\r
270\r
271 If Address > 0x0FFFFFFF, then ASSERT().\r
272\r
273 @param Address Address that encodes the PCI Bus, Device, Function and\r
274 Register.\r
275 @param AndData The value to AND with the PCI configuration register.\r
276\r
277 @return The value written back to the PCI configuration register.\r
278\r
279**/\r
280UINT8\r
281EFIAPI\r
282PciAnd8 (\r
283 IN UINTN Address,\r
284 IN UINT8 AndData\r
285 )\r
286{\r
287 return PciWrite8 (Address, (UINT8) (PciRead8 (Address) & AndData));\r
288}\r
289\r
290/**\r
291 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit\r
62991af2 292 value, followed a bitwise OR with another 8-bit value.\r
1a3eaf06 293\r
294 Reads the 8-bit PCI configuration register specified by Address, performs a\r
295 bitwise AND between the read result and the value specified by AndData,\r
62991af2 296 performs a bitwise OR between the result of the AND operation and\r
1a3eaf06 297 the value specified by OrData, and writes the result to the 8-bit PCI\r
298 configuration register specified by Address. The value written to the PCI\r
299 configuration register is returned. This function must guarantee that all PCI\r
300 read and write operations are serialized.\r
301\r
302 If Address > 0x0FFFFFFF, then ASSERT().\r
303\r
304 @param Address Address that encodes the PCI Bus, Device, Function and\r
305 Register.\r
306 @param AndData The value to AND with the PCI configuration register.\r
307 @param OrData The value to OR with the result of the AND operation.\r
308\r
309 @return The value written back to the PCI configuration register.\r
310\r
311**/\r
312UINT8\r
313EFIAPI\r
314PciAndThenOr8 (\r
315 IN UINTN Address,\r
316 IN UINT8 AndData,\r
317 IN UINT8 OrData\r
318 )\r
319{\r
320 return PciWrite8 (Address, (UINT8) ((PciRead8 (Address) & AndData) | OrData));\r
321}\r
322\r
323/**\r
324 Reads a bit field of a PCI configuration register.\r
325\r
326 Reads the bit field in an 8-bit PCI configuration register. The bit field is\r
327 specified by the StartBit and the EndBit. The value of the bit field is\r
328 returned.\r
329\r
330 If Address > 0x0FFFFFFF, then ASSERT().\r
331 If StartBit is greater than 7, then ASSERT().\r
332 If EndBit is greater than 7, then ASSERT().\r
333 If EndBit is less than StartBit, then ASSERT().\r
334\r
335 @param Address PCI configuration register to read.\r
336 @param StartBit The ordinal of the least significant bit in the bit field.\r
337 Range 0..7.\r
338 @param EndBit The ordinal of the most significant bit in the bit field.\r
339 Range 0..7.\r
340\r
341 @return The value of the bit field read from the PCI configuration register.\r
342\r
343**/\r
344UINT8\r
345EFIAPI\r
346PciBitFieldRead8 (\r
347 IN UINTN Address,\r
348 IN UINTN StartBit,\r
349 IN UINTN EndBit\r
350 )\r
351{\r
352 return BitFieldRead8 (PciRead8 (Address), StartBit, EndBit);\r
353}\r
354\r
355/**\r
356 Writes a bit field to a PCI configuration register.\r
357\r
358 Writes Value to the bit field of the PCI configuration register. The bit\r
359 field is specified by the StartBit and the EndBit. All other bits in the\r
360 destination PCI configuration register are preserved. The new value of the\r
361 8-bit register is returned.\r
362\r
363 If Address > 0x0FFFFFFF, then ASSERT().\r
364 If StartBit is greater than 7, then ASSERT().\r
365 If EndBit is greater than 7, then ASSERT().\r
366 If EndBit is less than StartBit, then ASSERT().\r
367\r
368 @param Address PCI configuration register to write.\r
369 @param StartBit The ordinal of the least significant bit in the bit field.\r
370 Range 0..7.\r
371 @param EndBit The ordinal of the most significant bit in the bit field.\r
372 Range 0..7.\r
373 @param Value New value of the bit field.\r
374\r
375 @return The value written back to the PCI configuration register.\r
376\r
377**/\r
378UINT8\r
379EFIAPI\r
380PciBitFieldWrite8 (\r
381 IN UINTN Address,\r
382 IN UINTN StartBit,\r
383 IN UINTN EndBit,\r
384 IN UINT8 Value\r
385 )\r
386{\r
387 return PciWrite8 (\r
388 Address,\r
389 BitFieldWrite8 (PciRead8 (Address), StartBit, EndBit, Value)\r
390 );\r
391}\r
392\r
393/**\r
394 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and\r
395 writes the result back to the bit field in the 8-bit port.\r
396\r
397 Reads the 8-bit PCI configuration register specified by Address, performs a\r
62991af2 398 bitwise OR between the read result and the value specified by\r
1a3eaf06 399 OrData, and writes the result to the 8-bit PCI configuration register\r
400 specified by Address. The value written to the PCI configuration register is\r
401 returned. This function must guarantee that all PCI read and write operations\r
402 are serialized. Extra left bits in OrData are stripped.\r
403\r
404 If Address > 0x0FFFFFFF, then ASSERT().\r
405 If StartBit is greater than 7, then ASSERT().\r
406 If EndBit is greater than 7, then ASSERT().\r
407 If EndBit is less than StartBit, then ASSERT().\r
408\r
409 @param Address PCI configuration register to write.\r
410 @param StartBit The ordinal of the least significant bit in the bit field.\r
411 Range 0..7.\r
412 @param EndBit The ordinal of the most significant bit in the bit field.\r
413 Range 0..7.\r
414 @param OrData The value to OR with the PCI configuration register.\r
415\r
416 @return The value written back to the PCI configuration register.\r
417\r
418**/\r
419UINT8\r
420EFIAPI\r
421PciBitFieldOr8 (\r
422 IN UINTN Address,\r
423 IN UINTN StartBit,\r
424 IN UINTN EndBit,\r
425 IN UINT8 OrData\r
426 )\r
427{\r
428 return PciWrite8 (\r
429 Address,\r
430 BitFieldOr8 (PciRead8 (Address), StartBit, EndBit, OrData)\r
431 );\r
432}\r
433\r
434/**\r
435 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise\r
436 AND, and writes the result back to the bit field in the 8-bit register.\r
437\r
438 Reads the 8-bit PCI configuration register specified by Address, performs a\r
439 bitwise AND between the read result and the value specified by AndData, and\r
440 writes the result to the 8-bit PCI configuration register specified by\r
441 Address. The value written to the PCI configuration register is returned.\r
442 This function must guarantee that all PCI read and write operations are\r
443 serialized. Extra left bits in AndData are stripped.\r
444\r
445 If Address > 0x0FFFFFFF, then ASSERT().\r
446 If StartBit is greater than 7, then ASSERT().\r
447 If EndBit is greater than 7, then ASSERT().\r
448 If EndBit is less than StartBit, then ASSERT().\r
449\r
450 @param Address PCI configuration register to write.\r
451 @param StartBit The ordinal of the least significant bit in the bit field.\r
452 Range 0..7.\r
453 @param EndBit The ordinal of the most significant bit in the bit field.\r
454 Range 0..7.\r
455 @param AndData The value to AND with the PCI configuration register.\r
456\r
457 @return The value written back to the PCI configuration register.\r
458\r
459**/\r
460UINT8\r
461EFIAPI\r
462PciBitFieldAnd8 (\r
463 IN UINTN Address,\r
464 IN UINTN StartBit,\r
465 IN UINTN EndBit,\r
466 IN UINT8 AndData\r
467 )\r
468{\r
469 return PciWrite8 (\r
470 Address,\r
471 BitFieldAnd8 (PciRead8 (Address), StartBit, EndBit, AndData)\r
472 );\r
473}\r
474\r
475/**\r
476 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a\r
62991af2 477 bitwise OR, and writes the result back to the bit field in the\r
1a3eaf06 478 8-bit port.\r
479\r
480 Reads the 8-bit PCI configuration register specified by Address, performs a\r
62991af2 481 bitwise AND followed by a bitwise OR between the read result and\r
1a3eaf06 482 the value specified by AndData, and writes the result to the 8-bit PCI\r
483 configuration register specified by Address. The value written to the PCI\r
484 configuration register is returned. This function must guarantee that all PCI\r
485 read and write operations are serialized. Extra left bits in both AndData and\r
486 OrData are stripped.\r
487\r
488 If Address > 0x0FFFFFFF, then ASSERT().\r
489 If StartBit is greater than 7, then ASSERT().\r
490 If EndBit is greater than 7, then ASSERT().\r
491 If EndBit is less than StartBit, then ASSERT().\r
492\r
493 @param Address PCI configuration register to write.\r
494 @param StartBit The ordinal of the least significant bit in the bit field.\r
495 Range 0..7.\r
496 @param EndBit The ordinal of the most significant bit in the bit field.\r
497 Range 0..7.\r
498 @param AndData The value to AND with the PCI configuration register.\r
499 @param OrData The value to OR with the result of the AND operation.\r
500\r
501 @return The value written back to the PCI configuration register.\r
502\r
503**/\r
504UINT8\r
505EFIAPI\r
506PciBitFieldAndThenOr8 (\r
507 IN UINTN Address,\r
508 IN UINTN StartBit,\r
509 IN UINTN EndBit,\r
510 IN UINT8 AndData,\r
511 IN UINT8 OrData\r
512 )\r
513{\r
514 return PciWrite8 (\r
515 Address,\r
516 BitFieldAndThenOr8 (PciRead8 (Address), StartBit, EndBit, AndData, OrData)\r
517 );\r
518}\r
519\r
520/**\r
521 Reads a 16-bit PCI configuration register.\r
522\r
523 Reads and returns the 16-bit PCI configuration register specified by Address.\r
524 This function must guarantee that all PCI read and write operations are\r
525 serialized.\r
526\r
527 If Address > 0x0FFFFFFF, then ASSERT().\r
528 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
529\r
530 @param Address Address that encodes the PCI Bus, Device, Function and\r
531 Register.\r
532\r
070a76b1 533 @return The read value from the PCI configuration register.\r
1a3eaf06 534\r
535**/\r
536UINT16\r
537EFIAPI\r
538PciRead16 (\r
539 IN UINTN Address\r
540 )\r
541{\r
542 ASSERT_INVALID_PCI_ADDRESS (Address, 1);\r
543\r
544 return (UINT16) DxePciLibPciRootBridgeIoReadWorker (Address, EfiPciWidthUint16);\r
545}\r
546\r
547/**\r
548 Writes a 16-bit PCI configuration register.\r
549\r
550 Writes the 16-bit PCI configuration register specified by Address with the\r
551 value specified by Value. Value is returned. This function must guarantee\r
552 that all PCI read and write operations are serialized.\r
553\r
554 If Address > 0x0FFFFFFF, then ASSERT().\r
555 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
556\r
557 @param Address Address that encodes the PCI Bus, Device, Function and\r
558 Register.\r
070a76b1 559 @param Value The value to write.\r
1a3eaf06 560\r
561 @return The value written to the PCI configuration register.\r
562\r
563**/\r
564UINT16\r
565EFIAPI\r
566PciWrite16 (\r
567 IN UINTN Address,\r
070a76b1 568 IN UINT16 Value\r
1a3eaf06 569 )\r
570{\r
571 ASSERT_INVALID_PCI_ADDRESS (Address, 1);\r
572\r
070a76b1 573 return (UINT16) DxePciLibPciRootBridgeIoWriteWorker (Address, EfiPciWidthUint16, Value);\r
1a3eaf06 574}\r
575\r
576/**\r
62991af2 577 Performs a bitwise OR of a 16-bit PCI configuration register with\r
1a3eaf06 578 a 16-bit value.\r
579\r
580 Reads the 16-bit PCI configuration register specified by Address, performs a\r
62991af2 581 bitwise OR between the read result and the value specified by\r
1a3eaf06 582 OrData, and writes the result to the 16-bit PCI configuration register\r
583 specified by Address. The value written to the PCI configuration register is\r
584 returned. This function must guarantee that all PCI read and write operations\r
585 are serialized.\r
586\r
587 If Address > 0x0FFFFFFF, then ASSERT().\r
588 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
589\r
590 @param Address Address that encodes the PCI Bus, Device, Function and\r
591 Register.\r
592 @param OrData The value to OR with the PCI configuration register.\r
593\r
594 @return The value written back to the PCI configuration register.\r
595\r
596**/\r
597UINT16\r
598EFIAPI\r
599PciOr16 (\r
600 IN UINTN Address,\r
601 IN UINT16 OrData\r
602 )\r
603{\r
604 return PciWrite16 (Address, (UINT16) (PciRead16 (Address) | OrData));\r
605}\r
606\r
607/**\r
608 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit\r
609 value.\r
610\r
611 Reads the 16-bit PCI configuration register specified by Address, performs a\r
612 bitwise AND between the read result and the value specified by AndData, and\r
613 writes the result to the 16-bit PCI configuration register specified by\r
614 Address. The value written to the PCI configuration register is returned.\r
615 This function must guarantee that all PCI read and write operations are\r
616 serialized.\r
617\r
618 If Address > 0x0FFFFFFF, then ASSERT().\r
619 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
620\r
621 @param Address Address that encodes the PCI Bus, Device, Function and\r
622 Register.\r
623 @param AndData The value to AND with the PCI configuration register.\r
624\r
625 @return The value written back to the PCI configuration register.\r
626\r
627**/\r
628UINT16\r
629EFIAPI\r
630PciAnd16 (\r
631 IN UINTN Address,\r
632 IN UINT16 AndData\r
633 )\r
634{\r
635 return PciWrite16 (Address, (UINT16) (PciRead16 (Address) & AndData));\r
636}\r
637\r
638/**\r
639 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit\r
62991af2 640 value, followed a bitwise OR with another 16-bit value.\r
1a3eaf06 641\r
642 Reads the 16-bit PCI configuration register specified by Address, performs a\r
643 bitwise AND between the read result and the value specified by AndData,\r
62991af2 644 performs a bitwise OR between the result of the AND operation and\r
1a3eaf06 645 the value specified by OrData, and writes the result to the 16-bit PCI\r
646 configuration register specified by Address. The value written to the PCI\r
647 configuration register is returned. This function must guarantee that all PCI\r
648 read and write operations are serialized.\r
649\r
650 If Address > 0x0FFFFFFF, then ASSERT().\r
651 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
652\r
653 @param Address Address that encodes the PCI Bus, Device, Function and\r
654 Register.\r
655 @param AndData The value to AND with the PCI configuration register.\r
656 @param OrData The value to OR with the result of the AND operation.\r
657\r
658 @return The value written back to the PCI configuration register.\r
659\r
660**/\r
661UINT16\r
662EFIAPI\r
663PciAndThenOr16 (\r
664 IN UINTN Address,\r
665 IN UINT16 AndData,\r
666 IN UINT16 OrData\r
667 )\r
668{\r
669 return PciWrite16 (Address, (UINT16) ((PciRead16 (Address) & AndData) | OrData));\r
670}\r
671\r
672/**\r
673 Reads a bit field of a PCI configuration register.\r
674\r
675 Reads the bit field in a 16-bit PCI configuration register. The bit field is\r
676 specified by the StartBit and the EndBit. The value of the bit field is\r
677 returned.\r
678\r
679 If Address > 0x0FFFFFFF, then ASSERT().\r
680 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
681 If StartBit is greater than 15, then ASSERT().\r
682 If EndBit is greater than 15, then ASSERT().\r
683 If EndBit is less than StartBit, then ASSERT().\r
684\r
685 @param Address PCI configuration register to read.\r
686 @param StartBit The ordinal of the least significant bit in the bit field.\r
687 Range 0..15.\r
688 @param EndBit The ordinal of the most significant bit in the bit field.\r
689 Range 0..15.\r
690\r
691 @return The value of the bit field read from the PCI configuration register.\r
692\r
693**/\r
694UINT16\r
695EFIAPI\r
696PciBitFieldRead16 (\r
697 IN UINTN Address,\r
698 IN UINTN StartBit,\r
699 IN UINTN EndBit\r
700 )\r
701{\r
702 return BitFieldRead16 (PciRead16 (Address), StartBit, EndBit);\r
703}\r
704\r
705/**\r
706 Writes a bit field to a PCI configuration register.\r
707\r
708 Writes Value to the bit field of the PCI configuration register. The bit\r
709 field is specified by the StartBit and the EndBit. All other bits in the\r
710 destination PCI configuration register are preserved. The new value of the\r
711 16-bit register is returned.\r
712\r
713 If Address > 0x0FFFFFFF, then ASSERT().\r
714 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
715 If StartBit is greater than 15, then ASSERT().\r
716 If EndBit is greater than 15, then ASSERT().\r
717 If EndBit is less than StartBit, then ASSERT().\r
718\r
719 @param Address PCI configuration register to write.\r
720 @param StartBit The ordinal of the least significant bit in the bit field.\r
721 Range 0..15.\r
722 @param EndBit The ordinal of the most significant bit in the bit field.\r
723 Range 0..15.\r
724 @param Value New value of the bit field.\r
725\r
726 @return The value written back to the PCI configuration register.\r
727\r
728**/\r
729UINT16\r
730EFIAPI\r
731PciBitFieldWrite16 (\r
732 IN UINTN Address,\r
733 IN UINTN StartBit,\r
734 IN UINTN EndBit,\r
735 IN UINT16 Value\r
736 )\r
737{\r
738 return PciWrite16 (\r
739 Address,\r
740 BitFieldWrite16 (PciRead16 (Address), StartBit, EndBit, Value)\r
741 );\r
742}\r
743\r
744/**\r
745 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and\r
746 writes the result back to the bit field in the 16-bit port.\r
747\r
748 Reads the 16-bit PCI configuration register specified by Address, performs a\r
62991af2 749 bitwise OR between the read result and the value specified by\r
1a3eaf06 750 OrData, and writes the result to the 16-bit PCI configuration register\r
751 specified by Address. The value written to the PCI configuration register is\r
752 returned. This function must guarantee that all PCI read and write operations\r
753 are serialized. Extra left bits in OrData are stripped.\r
754\r
755 If Address > 0x0FFFFFFF, then ASSERT().\r
756 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
757 If StartBit is greater than 15, then ASSERT().\r
758 If EndBit is greater than 15, then ASSERT().\r
759 If EndBit is less than StartBit, then ASSERT().\r
760\r
761 @param Address PCI configuration register to write.\r
762 @param StartBit The ordinal of the least significant bit in the bit field.\r
763 Range 0..15.\r
764 @param EndBit The ordinal of the most significant bit in the bit field.\r
765 Range 0..15.\r
766 @param OrData The value to OR with the PCI configuration register.\r
767\r
768 @return The value written back to the PCI configuration register.\r
769\r
770**/\r
771UINT16\r
772EFIAPI\r
773PciBitFieldOr16 (\r
774 IN UINTN Address,\r
775 IN UINTN StartBit,\r
776 IN UINTN EndBit,\r
777 IN UINT16 OrData\r
778 )\r
779{\r
780 return PciWrite16 (\r
781 Address,\r
782 BitFieldOr16 (PciRead16 (Address), StartBit, EndBit, OrData)\r
783 );\r
784}\r
785\r
786/**\r
787 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise\r
788 AND, and writes the result back to the bit field in the 16-bit register.\r
789\r
790 Reads the 16-bit PCI configuration register specified by Address, performs a\r
791 bitwise AND between the read result and the value specified by AndData, and\r
792 writes the result to the 16-bit PCI configuration register specified by\r
793 Address. The value written to the PCI configuration register is returned.\r
794 This function must guarantee that all PCI read and write operations are\r
795 serialized. Extra left bits in AndData are stripped.\r
796\r
797 If Address > 0x0FFFFFFF, then ASSERT().\r
798 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
799 If StartBit is greater than 15, then ASSERT().\r
800 If EndBit is greater than 15, then ASSERT().\r
801 If EndBit is less than StartBit, then ASSERT().\r
802\r
803 @param Address PCI configuration register to write.\r
804 @param StartBit The ordinal of the least significant bit in the bit field.\r
805 Range 0..15.\r
806 @param EndBit The ordinal of the most significant bit in the bit field.\r
807 Range 0..15.\r
808 @param AndData The value to AND with the PCI configuration register.\r
809\r
810 @return The value written back to the PCI configuration register.\r
811\r
812**/\r
813UINT16\r
814EFIAPI\r
815PciBitFieldAnd16 (\r
816 IN UINTN Address,\r
817 IN UINTN StartBit,\r
818 IN UINTN EndBit,\r
819 IN UINT16 AndData\r
820 )\r
821{\r
822 return PciWrite16 (\r
823 Address,\r
824 BitFieldAnd16 (PciRead16 (Address), StartBit, EndBit, AndData)\r
825 );\r
826}\r
827\r
828/**\r
829 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a\r
62991af2 830 bitwise OR, and writes the result back to the bit field in the\r
1a3eaf06 831 16-bit port.\r
832\r
833 Reads the 16-bit PCI configuration register specified by Address, performs a\r
62991af2 834 bitwise AND followed by a bitwise OR between the read result and\r
1a3eaf06 835 the value specified by AndData, and writes the result to the 16-bit PCI\r
836 configuration register specified by Address. The value written to the PCI\r
837 configuration register is returned. This function must guarantee that all PCI\r
838 read and write operations are serialized. Extra left bits in both AndData and\r
839 OrData are stripped.\r
840\r
841 If Address > 0x0FFFFFFF, then ASSERT().\r
842 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
843 If StartBit is greater than 15, then ASSERT().\r
844 If EndBit is greater than 15, then ASSERT().\r
845 If EndBit is less than StartBit, then ASSERT().\r
846\r
847 @param Address PCI configuration register to write.\r
848 @param StartBit The ordinal of the least significant bit in the bit field.\r
849 Range 0..15.\r
850 @param EndBit The ordinal of the most significant bit in the bit field.\r
851 Range 0..15.\r
852 @param AndData The value to AND with the PCI configuration register.\r
853 @param OrData The value to OR with the result of the AND operation.\r
854\r
855 @return The value written back to the PCI configuration register.\r
856\r
857**/\r
858UINT16\r
859EFIAPI\r
860PciBitFieldAndThenOr16 (\r
861 IN UINTN Address,\r
862 IN UINTN StartBit,\r
863 IN UINTN EndBit,\r
864 IN UINT16 AndData,\r
865 IN UINT16 OrData\r
866 )\r
867{\r
868 return PciWrite16 (\r
869 Address,\r
870 BitFieldAndThenOr16 (PciRead16 (Address), StartBit, EndBit, AndData, OrData)\r
871 );\r
872}\r
873\r
874/**\r
875 Reads a 32-bit PCI configuration register.\r
876\r
877 Reads and returns the 32-bit PCI configuration register specified by Address.\r
878 This function must guarantee that all PCI read and write operations are\r
879 serialized.\r
880\r
881 If Address > 0x0FFFFFFF, then ASSERT().\r
882 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
883\r
884 @param Address Address that encodes the PCI Bus, Device, Function and\r
885 Register.\r
886\r
070a76b1 887 @return The read value from the PCI configuration register.\r
1a3eaf06 888\r
889**/\r
890UINT32\r
891EFIAPI\r
892PciRead32 (\r
893 IN UINTN Address\r
894 )\r
895{\r
896 ASSERT_INVALID_PCI_ADDRESS (Address, 3);\r
897\r
898 return DxePciLibPciRootBridgeIoReadWorker (Address, EfiPciWidthUint32);\r
899}\r
900\r
901/**\r
902 Writes a 32-bit PCI configuration register.\r
903\r
904 Writes the 32-bit PCI configuration register specified by Address with the\r
905 value specified by Value. Value is returned. This function must guarantee\r
906 that all PCI read and write operations are serialized.\r
907\r
908 If Address > 0x0FFFFFFF, then ASSERT().\r
909 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
910\r
911 @param Address Address that encodes the PCI Bus, Device, Function and\r
912 Register.\r
070a76b1 913 @param Value The value to write.\r
1a3eaf06 914\r
915 @return The value written to the PCI configuration register.\r
916\r
917**/\r
918UINT32\r
919EFIAPI\r
920PciWrite32 (\r
921 IN UINTN Address,\r
070a76b1 922 IN UINT32 Value\r
1a3eaf06 923 )\r
924{\r
925 ASSERT_INVALID_PCI_ADDRESS (Address, 3);\r
926\r
070a76b1 927 return DxePciLibPciRootBridgeIoWriteWorker (Address, EfiPciWidthUint32, Value);\r
1a3eaf06 928}\r
929\r
930/**\r
62991af2 931 Performs a bitwise OR of a 32-bit PCI configuration register with\r
1a3eaf06 932 a 32-bit value.\r
933\r
934 Reads the 32-bit PCI configuration register specified by Address, performs a\r
62991af2 935 bitwise OR between the read result and the value specified by\r
1a3eaf06 936 OrData, and writes the result to the 32-bit PCI configuration register\r
937 specified by Address. The value written to the PCI configuration register is\r
938 returned. This function must guarantee that all PCI read and write operations\r
939 are serialized.\r
940\r
941 If Address > 0x0FFFFFFF, then ASSERT().\r
942 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
943\r
944 @param Address Address that encodes the PCI Bus, Device, Function and\r
945 Register.\r
946 @param OrData The value to OR with the PCI configuration register.\r
947\r
948 @return The value written back to the PCI configuration register.\r
949\r
950**/\r
951UINT32\r
952EFIAPI\r
953PciOr32 (\r
954 IN UINTN Address,\r
955 IN UINT32 OrData\r
956 )\r
957{\r
958 return PciWrite32 (Address, PciRead32 (Address) | OrData);\r
959}\r
960\r
961/**\r
962 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit\r
963 value.\r
964\r
965 Reads the 32-bit PCI configuration register specified by Address, performs a\r
966 bitwise AND between the read result and the value specified by AndData, and\r
967 writes the result to the 32-bit PCI configuration register specified by\r
968 Address. The value written to the PCI configuration register is returned.\r
969 This function must guarantee that all PCI read and write operations are\r
970 serialized.\r
971\r
972 If Address > 0x0FFFFFFF, then ASSERT().\r
973 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
974\r
975 @param Address Address that encodes the PCI Bus, Device, Function and\r
976 Register.\r
977 @param AndData The value to AND with the PCI configuration register.\r
978\r
979 @return The value written back to the PCI configuration register.\r
980\r
981**/\r
982UINT32\r
983EFIAPI\r
984PciAnd32 (\r
985 IN UINTN Address,\r
986 IN UINT32 AndData\r
987 )\r
988{\r
989 return PciWrite32 (Address, PciRead32 (Address) & AndData);\r
990}\r
991\r
992/**\r
993 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit\r
62991af2 994 value, followed a bitwise OR with another 32-bit value.\r
1a3eaf06 995\r
996 Reads the 32-bit PCI configuration register specified by Address, performs a\r
997 bitwise AND between the read result and the value specified by AndData,\r
62991af2 998 performs a bitwise OR between the result of the AND operation and\r
1a3eaf06 999 the value specified by OrData, and writes the result to the 32-bit PCI\r
1000 configuration register specified by Address. The value written to the PCI\r
1001 configuration register is returned. This function must guarantee that all PCI\r
1002 read and write operations are serialized.\r
1003\r
1004 If Address > 0x0FFFFFFF, then ASSERT().\r
1005 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
1006\r
1007 @param Address Address that encodes the PCI Bus, Device, Function and\r
1008 Register.\r
1009 @param AndData The value to AND with the PCI configuration register.\r
1010 @param OrData The value to OR with the result of the AND operation.\r
1011\r
1012 @return The value written back to the PCI configuration register.\r
1013\r
1014**/\r
1015UINT32\r
1016EFIAPI\r
1017PciAndThenOr32 (\r
1018 IN UINTN Address,\r
1019 IN UINT32 AndData,\r
1020 IN UINT32 OrData\r
1021 )\r
1022{\r
1023 return PciWrite32 (Address, (PciRead32 (Address) & AndData) | OrData);\r
1024}\r
1025\r
1026/**\r
1027 Reads a bit field of a PCI configuration register.\r
1028\r
1029 Reads the bit field in a 32-bit PCI configuration register. The bit field is\r
1030 specified by the StartBit and the EndBit. The value of the bit field is\r
1031 returned.\r
1032\r
1033 If Address > 0x0FFFFFFF, then ASSERT().\r
1034 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
1035 If StartBit is greater than 31, then ASSERT().\r
1036 If EndBit is greater than 31, then ASSERT().\r
1037 If EndBit is less than StartBit, then ASSERT().\r
1038\r
1039 @param Address PCI configuration register to read.\r
1040 @param StartBit The ordinal of the least significant bit in the bit field.\r
1041 Range 0..31.\r
1042 @param EndBit The ordinal of the most significant bit in the bit field.\r
1043 Range 0..31.\r
1044\r
1045 @return The value of the bit field read from the PCI configuration register.\r
1046\r
1047**/\r
1048UINT32\r
1049EFIAPI\r
1050PciBitFieldRead32 (\r
1051 IN UINTN Address,\r
1052 IN UINTN StartBit,\r
1053 IN UINTN EndBit\r
1054 )\r
1055{\r
1056 return BitFieldRead32 (PciRead32 (Address), StartBit, EndBit);\r
1057}\r
1058\r
1059/**\r
1060 Writes a bit field to a PCI configuration register.\r
1061\r
1062 Writes Value to the bit field of the PCI configuration register. The bit\r
1063 field is specified by the StartBit and the EndBit. All other bits in the\r
1064 destination PCI configuration register are preserved. The new value of the\r
1065 32-bit register is returned.\r
1066\r
1067 If Address > 0x0FFFFFFF, then ASSERT().\r
1068 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
1069 If StartBit is greater than 31, then ASSERT().\r
1070 If EndBit is greater than 31, then ASSERT().\r
1071 If EndBit is less than StartBit, then ASSERT().\r
1072\r
1073 @param Address PCI configuration register to write.\r
1074 @param StartBit The ordinal of the least significant bit in the bit field.\r
1075 Range 0..31.\r
1076 @param EndBit The ordinal of the most significant bit in the bit field.\r
1077 Range 0..31.\r
1078 @param Value New value of the bit field.\r
1079\r
1080 @return The value written back to the PCI configuration register.\r
1081\r
1082**/\r
1083UINT32\r
1084EFIAPI\r
1085PciBitFieldWrite32 (\r
1086 IN UINTN Address,\r
1087 IN UINTN StartBit,\r
1088 IN UINTN EndBit,\r
1089 IN UINT32 Value\r
1090 )\r
1091{\r
1092 return PciWrite32 (\r
1093 Address,\r
1094 BitFieldWrite32 (PciRead32 (Address), StartBit, EndBit, Value)\r
1095 );\r
1096}\r
1097\r
1098/**\r
1099 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and\r
1100 writes the result back to the bit field in the 32-bit port.\r
1101\r
1102 Reads the 32-bit PCI configuration register specified by Address, performs a\r
62991af2 1103 bitwise OR between the read result and the value specified by\r
1a3eaf06 1104 OrData, and writes the result to the 32-bit PCI configuration register\r
1105 specified by Address. The value written to the PCI configuration register is\r
1106 returned. This function must guarantee that all PCI read and write operations\r
1107 are serialized. Extra left bits in OrData are stripped.\r
1108\r
1109 If Address > 0x0FFFFFFF, then ASSERT().\r
1110 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
1111 If StartBit is greater than 31, then ASSERT().\r
1112 If EndBit is greater than 31, then ASSERT().\r
1113 If EndBit is less than StartBit, then ASSERT().\r
1114\r
1115 @param Address PCI configuration register to write.\r
1116 @param StartBit The ordinal of the least significant bit in the bit field.\r
1117 Range 0..31.\r
1118 @param EndBit The ordinal of the most significant bit in the bit field.\r
1119 Range 0..31.\r
1120 @param OrData The value to OR with the PCI configuration register.\r
1121\r
1122 @return The value written back to the PCI configuration register.\r
1123\r
1124**/\r
1125UINT32\r
1126EFIAPI\r
1127PciBitFieldOr32 (\r
1128 IN UINTN Address,\r
1129 IN UINTN StartBit,\r
1130 IN UINTN EndBit,\r
1131 IN UINT32 OrData\r
1132 )\r
1133{\r
1134 return PciWrite32 (\r
1135 Address,\r
1136 BitFieldOr32 (PciRead32 (Address), StartBit, EndBit, OrData)\r
1137 );\r
1138}\r
1139\r
1140/**\r
1141 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise\r
1142 AND, and writes the result back to the bit field in the 32-bit register.\r
1143\r
1144 Reads the 32-bit PCI configuration register specified by Address, performs a\r
1145 bitwise AND between the read result and the value specified by AndData, and\r
1146 writes the result to the 32-bit PCI configuration register specified by\r
1147 Address. The value written to the PCI configuration register is returned.\r
1148 This function must guarantee that all PCI read and write operations are\r
1149 serialized. Extra left bits in AndData are stripped.\r
1150\r
1151 If Address > 0x0FFFFFFF, then ASSERT().\r
1152 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
1153 If StartBit is greater than 31, then ASSERT().\r
1154 If EndBit is greater than 31, then ASSERT().\r
1155 If EndBit is less than StartBit, then ASSERT().\r
1156\r
1157 @param Address PCI configuration register to write.\r
1158 @param StartBit The ordinal of the least significant bit in the bit field.\r
1159 Range 0..31.\r
1160 @param EndBit The ordinal of the most significant bit in the bit field.\r
1161 Range 0..31.\r
1162 @param AndData The value to AND with the PCI configuration register.\r
1163\r
1164 @return The value written back to the PCI configuration register.\r
1165\r
1166**/\r
1167UINT32\r
1168EFIAPI\r
1169PciBitFieldAnd32 (\r
1170 IN UINTN Address,\r
1171 IN UINTN StartBit,\r
1172 IN UINTN EndBit,\r
1173 IN UINT32 AndData\r
1174 )\r
1175{\r
1176 return PciWrite32 (\r
1177 Address,\r
1178 BitFieldAnd32 (PciRead32 (Address), StartBit, EndBit, AndData)\r
1179 );\r
1180}\r
1181\r
1182/**\r
1183 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a\r
62991af2 1184 bitwise OR, and writes the result back to the bit field in the\r
1a3eaf06 1185 32-bit port.\r
1186\r
1187 Reads the 32-bit PCI configuration register specified by Address, performs a\r
62991af2 1188 bitwise AND followed by a bitwise OR between the read result and\r
1a3eaf06 1189 the value specified by AndData, and writes the result to the 32-bit PCI\r
1190 configuration register specified by Address. The value written to the PCI\r
1191 configuration register is returned. This function must guarantee that all PCI\r
1192 read and write operations are serialized. Extra left bits in both AndData and\r
1193 OrData are stripped.\r
1194\r
1195 If Address > 0x0FFFFFFF, then ASSERT().\r
1196 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
1197 If StartBit is greater than 31, then ASSERT().\r
1198 If EndBit is greater than 31, then ASSERT().\r
1199 If EndBit is less than StartBit, then ASSERT().\r
1200\r
1201 @param Address PCI configuration register to write.\r
1202 @param StartBit The ordinal of the least significant bit in the bit field.\r
1203 Range 0..31.\r
1204 @param EndBit The ordinal of the most significant bit in the bit field.\r
1205 Range 0..31.\r
1206 @param AndData The value to AND with the PCI configuration register.\r
1207 @param OrData The value to OR with the result of the AND operation.\r
1208\r
1209 @return The value written back to the PCI configuration register.\r
1210\r
1211**/\r
1212UINT32\r
1213EFIAPI\r
1214PciBitFieldAndThenOr32 (\r
1215 IN UINTN Address,\r
1216 IN UINTN StartBit,\r
1217 IN UINTN EndBit,\r
1218 IN UINT32 AndData,\r
1219 IN UINT32 OrData\r
1220 )\r
1221{\r
1222 return PciWrite32 (\r
1223 Address,\r
1224 BitFieldAndThenOr32 (PciRead32 (Address), StartBit, EndBit, AndData, OrData)\r
1225 );\r
1226}\r
1227\r
1228/**\r
1229 Reads a range of PCI configuration registers into a caller supplied buffer.\r
1230\r
1231 Reads the range of PCI configuration registers specified by StartAddress and\r
1232 Size into the buffer specified by Buffer. This function only allows the PCI\r
1233 configuration registers from a single PCI function to be read. Size is\r
1234 returned. When possible 32-bit PCI configuration read cycles are used to read\r
1235 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit\r
1236 and 16-bit PCI configuration read cycles may be used at the beginning and the\r
1237 end of the range.\r
1238\r
1239 If StartAddress > 0x0FFFFFFF, then ASSERT().\r
1240 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().\r
1241 If Size > 0 and Buffer is NULL, then ASSERT().\r
1242\r
1243 @param StartAddress Starting address that encodes the PCI Bus, Device,\r
1244 Function and Register.\r
1245 @param Size Size in bytes of the transfer.\r
1246 @param Buffer Pointer to a buffer receiving the data read.\r
1247\r
1248 @return Size\r
1249\r
1250**/\r
1251UINTN\r
1252EFIAPI\r
1253PciReadBuffer (\r
1254 IN UINTN StartAddress,\r
1255 IN UINTN Size,\r
1256 OUT VOID *Buffer\r
1257 )\r
1258{\r
1259 UINTN ReturnValue;\r
1260\r
1261 ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
e43e4b3e 1262 ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
1a3eaf06 1263\r
1264 if (Size == 0) {\r
1265 return Size;\r
1266 }\r
1267\r
1268 ASSERT (Buffer != NULL);\r
1269\r
1270 //\r
1271 // Save Size for return\r
1272 //\r
1273 ReturnValue = Size;\r
1274\r
e43e4b3e 1275 if ((StartAddress & BIT0) != 0) {\r
1a3eaf06 1276 //\r
1277 // Read a byte if StartAddress is byte aligned\r
1278 //\r
1279 *(volatile UINT8 *)Buffer = PciRead8 (StartAddress);\r
1280 StartAddress += sizeof (UINT8);\r
1281 Size -= sizeof (UINT8);\r
1282 Buffer = (UINT8*)Buffer + 1;\r
1283 }\r
1284\r
e43e4b3e 1285 if (Size >= sizeof (UINT16) && (StartAddress & BIT1) != 0) {\r
1a3eaf06 1286 //\r
1287 // Read a word if StartAddress is word aligned\r
1288 //\r
5dc4fd78 1289 WriteUnaligned16 (Buffer, PciRead16 (StartAddress));\r
1a3eaf06 1290 StartAddress += sizeof (UINT16);\r
1291 Size -= sizeof (UINT16);\r
1292 Buffer = (UINT16*)Buffer + 1;\r
1293 }\r
1294\r
1295 while (Size >= sizeof (UINT32)) {\r
1296 //\r
1297 // Read as many double words as possible\r
1298 //\r
5dc4fd78 1299 WriteUnaligned32 (Buffer, PciRead32 (StartAddress));\r
1a3eaf06 1300 StartAddress += sizeof (UINT32);\r
1301 Size -= sizeof (UINT32);\r
1302 Buffer = (UINT32*)Buffer + 1;\r
1303 }\r
1304\r
1305 if (Size >= sizeof (UINT16)) {\r
1306 //\r
1307 // Read the last remaining word if exist\r
1308 //\r
5dc4fd78 1309 WriteUnaligned16 (Buffer, PciRead16 (StartAddress));\r
1a3eaf06 1310 StartAddress += sizeof (UINT16);\r
1311 Size -= sizeof (UINT16);\r
1312 Buffer = (UINT16*)Buffer + 1;\r
1313 }\r
1314\r
1315 if (Size >= sizeof (UINT8)) {\r
1316 //\r
1317 // Read the last remaining byte if exist\r
1318 //\r
1319 *(volatile UINT8 *)Buffer = PciRead8 (StartAddress);\r
1320 }\r
1321\r
1322 return ReturnValue;\r
1323}\r
1324\r
1325/**\r
1326 Copies the data in a caller supplied buffer to a specified range of PCI\r
1327 configuration space.\r
1328\r
1329 Writes the range of PCI configuration registers specified by StartAddress and\r
1330 Size from the buffer specified by Buffer. This function only allows the PCI\r
1331 configuration registers from a single PCI function to be written. Size is\r
1332 returned. When possible 32-bit PCI configuration write cycles are used to\r
1333 write from StartAdress to StartAddress + Size. Due to alignment restrictions,\r
1334 8-bit and 16-bit PCI configuration write cycles may be used at the beginning\r
1335 and the end of the range.\r
1336\r
1337 If StartAddress > 0x0FFFFFFF, then ASSERT().\r
1338 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().\r
1339 If Size > 0 and Buffer is NULL, then ASSERT().\r
1340\r
1341 @param StartAddress Starting address that encodes the PCI Bus, Device,\r
1342 Function and Register.\r
1343 @param Size Size in bytes of the transfer.\r
1344 @param Buffer Pointer to a buffer containing the data to write.\r
1345\r
070a76b1 1346 @return Size written to StartAddress.\r
1a3eaf06 1347\r
1348**/\r
1349UINTN\r
1350EFIAPI\r
1351PciWriteBuffer (\r
1352 IN UINTN StartAddress,\r
1353 IN UINTN Size,\r
1354 IN VOID *Buffer\r
1355 )\r
1356{\r
1357 UINTN ReturnValue;\r
1358\r
1359 ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
e43e4b3e 1360 ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
1a3eaf06 1361\r
1362 if (Size == 0) {\r
1363 return 0;\r
1364 }\r
1365\r
1366 ASSERT (Buffer != NULL);\r
1367\r
1368 //\r
1369 // Save Size for return\r
1370 //\r
1371 ReturnValue = Size;\r
1372\r
e43e4b3e 1373 if ((StartAddress & BIT0) != 0) {\r
1a3eaf06 1374 //\r
1375 // Write a byte if StartAddress is byte aligned\r
1376 //\r
1377 PciWrite8 (StartAddress, *(UINT8*)Buffer);\r
1378 StartAddress += sizeof (UINT8);\r
1379 Size -= sizeof (UINT8);\r
1380 Buffer = (UINT8*)Buffer + 1;\r
1381 }\r
1382\r
e43e4b3e 1383 if (Size >= sizeof (UINT16) && (StartAddress & BIT1) != 0) {\r
1a3eaf06 1384 //\r
1385 // Write a word if StartAddress is word aligned\r
1386 //\r
5dc4fd78 1387 PciWrite16 (StartAddress, ReadUnaligned16 (Buffer));\r
1a3eaf06 1388 StartAddress += sizeof (UINT16);\r
1389 Size -= sizeof (UINT16);\r
1390 Buffer = (UINT16*)Buffer + 1;\r
1391 }\r
1392\r
1393 while (Size >= sizeof (UINT32)) {\r
1394 //\r
1395 // Write as many double words as possible\r
1396 //\r
5dc4fd78 1397 PciWrite32 (StartAddress, ReadUnaligned32 (Buffer));\r
1a3eaf06 1398 StartAddress += sizeof (UINT32);\r
1399 Size -= sizeof (UINT32);\r
1400 Buffer = (UINT32*)Buffer + 1;\r
1401 }\r
1402\r
1403 if (Size >= sizeof (UINT16)) {\r
1404 //\r
1405 // Write the last remaining word if exist\r
1406 //\r
5dc4fd78 1407 PciWrite16 (StartAddress, ReadUnaligned16 (Buffer));\r
1a3eaf06 1408 StartAddress += sizeof (UINT16);\r
1409 Size -= sizeof (UINT16);\r
1410 Buffer = (UINT16*)Buffer + 1;\r
1411 }\r
1412\r
1413 if (Size >= sizeof (UINT8)) {\r
1414 //\r
1415 // Write the last remaining byte if exist\r
1416 //\r
1417 PciWrite8 (StartAddress, *(UINT8*)Buffer);\r
1418 }\r
1419\r
1420 return ReturnValue;\r
1421}\r