]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/PciExpressLib.h
Add ASSERT() for BitField operations to make sure the input value is valid.
[mirror_edk2.git] / MdePkg / Include / Library / PciExpressLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides services to access PCI Configuration Space using the MMIO PCI Express window.\r
badcbfb2 3 \r
4 This library is identical to the PCI Library, except the access method for performing PCI \r
1a2f870c 5 configuration cycles must be through the 256 MB PCI Express MMIO window whose base address\r
badcbfb2 6 is defined by PcdPciExpressBaseAddress.\r
fb3df220 7\r
94952554 8Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
9df063a0 9This program and the accompanying materials\r
50a64e5b 10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
fb3df220 13\r
50a64e5b 14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
fb3df220 16\r
fb3df220 17**/\r
18\r
19#ifndef __PCI_EXPRESS_LIB_H__\r
20#define __PCI_EXPRESS_LIB_H__\r
21\r
fb3df220 22/**\r
23 Macro that converts PCI Bus, PCI Device, PCI Function and PCI Register to an\r
24 address that can be passed to the PCI Library functions.\r
25\r
26 Computes an address that is compatible with the PCI Library functions. The\r
27 unused upper bits of Bus, Device, Function and Register are stripped prior to\r
28 the generation of the address.\r
29\r
30 @param Bus PCI Bus number. Range 0..255.\r
31 @param Device PCI Device number. Range 0..31.\r
32 @param Function PCI Function number. Range 0..7.\r
33 @param Register PCI Register number. Range 0..4095.\r
34\r
35 @return The encode PCI address.\r
36\r
37**/\r
38#define PCI_EXPRESS_LIB_ADDRESS(Bus,Device,Function,Offset) \\r
39 (((Offset) & 0xfff) | (((Function) & 0x07) << 12) | (((Device) & 0x1f) << 15) | (((Bus) & 0xff) << 20))\r
40\r
f926e538 41/**\r
d11195a3 42 Registers a PCI device so PCI configuration registers may be accessed after \r
f926e538 43 SetVirtualAddressMap().\r
44 \r
d11195a3 45 Registers the PCI device specified by Address so all the PCI configuration \r
46 registers associated with that PCI device may be accessed after SetVirtualAddressMap() \r
47 is called.\r
48 \r
f926e538 49 If Address > 0x0FFFFFFF, then ASSERT().\r
50\r
51 @param Address Address that encodes the PCI Bus, Device, Function and\r
52 Register.\r
53 \r
54 @retval RETURN_SUCCESS The PCI device was registered for runtime access.\r
55 @retval RETURN_UNSUPPORTED An attempt was made to call this function \r
56 after ExitBootServices().\r
57 @retval RETURN_UNSUPPORTED The resources required to access the PCI device\r
58 at runtime could not be mapped.\r
59 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to\r
60 complete the registration.\r
61\r
62**/\r
63RETURN_STATUS\r
64EFIAPI\r
65PciExpressRegisterForRuntimeAccess (\r
66 IN UINTN Address\r
67 );\r
68\r
fb3df220 69/**\r
70 Reads an 8-bit PCI configuration register.\r
71\r
72 Reads and returns the 8-bit PCI configuration register specified by Address.\r
73 This function must guarantee that all PCI read and write operations are\r
74 serialized.\r
75\r
76 If Address > 0x0FFFFFFF, then ASSERT().\r
77\r
78 @param Address Address that encodes the PCI Bus, Device, Function and\r
79 Register.\r
80\r
81 @return The read value from the PCI configuration register.\r
82\r
83**/\r
84UINT8\r
85EFIAPI\r
86PciExpressRead8 (\r
87 IN UINTN Address\r
88 );\r
89\r
90/**\r
91 Writes an 8-bit PCI configuration register.\r
92\r
93 Writes the 8-bit PCI configuration register specified by Address with the\r
94 value specified by Value. Value is returned. This function must guarantee\r
95 that all PCI read and write operations are serialized.\r
96\r
97 If Address > 0x0FFFFFFF, then ASSERT().\r
98\r
99 @param Address Address that encodes the PCI Bus, Device, Function and\r
100 Register.\r
101 @param Value The value to write.\r
102\r
103 @return The value written to the PCI configuration register.\r
104\r
105**/\r
106UINT8\r
107EFIAPI\r
108PciExpressWrite8 (\r
109 IN UINTN Address,\r
94646ec0 110 IN UINT8 Value\r
fb3df220 111 );\r
112\r
113/**\r
62991af2 114 Performs a bitwise OR of an 8-bit PCI configuration register with\r
fb3df220 115 an 8-bit value.\r
116\r
117 Reads the 8-bit PCI configuration register specified by Address, performs a\r
62991af2 118 bitwise OR between the read result and the value specified by\r
fb3df220 119 OrData, and writes the result to the 8-bit PCI configuration register\r
120 specified by Address. The value written to the PCI configuration register is\r
121 returned. This function must guarantee that all PCI read and write operations\r
122 are serialized.\r
123\r
124 If Address > 0x0FFFFFFF, then ASSERT().\r
125\r
126 @param Address Address that encodes the PCI Bus, Device, Function and\r
127 Register.\r
128 @param OrData The value to OR with the PCI configuration register.\r
129\r
130 @return The value written back to the PCI configuration register.\r
131\r
132**/\r
133UINT8\r
134EFIAPI\r
135PciExpressOr8 (\r
136 IN UINTN Address,\r
137 IN UINT8 OrData\r
138 );\r
139\r
140/**\r
141 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit\r
142 value.\r
143\r
144 Reads the 8-bit PCI configuration register specified by Address, performs a\r
145 bitwise AND between the read result and the value specified by AndData, and\r
146 writes the result to the 8-bit PCI configuration register specified by\r
147 Address. The value written to the PCI configuration register is returned.\r
148 This function must guarantee that all PCI read and write operations are\r
149 serialized.\r
150\r
151 If Address > 0x0FFFFFFF, then ASSERT().\r
152\r
153 @param Address Address that encodes the PCI Bus, Device, Function and\r
154 Register.\r
155 @param AndData The value to AND with the PCI configuration register.\r
156\r
157 @return The value written back to the PCI configuration register.\r
158\r
159**/\r
160UINT8\r
161EFIAPI\r
162PciExpressAnd8 (\r
163 IN UINTN Address,\r
164 IN UINT8 AndData\r
165 );\r
166\r
167/**\r
168 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit\r
62991af2 169 value, followed a bitwise OR with another 8-bit value.\r
fb3df220 170\r
171 Reads the 8-bit PCI configuration register specified by Address, performs a\r
172 bitwise AND between the read result and the value specified by AndData,\r
62991af2 173 performs a bitwise OR between the result of the AND operation and\r
fb3df220 174 the value specified by OrData, and writes the result to the 8-bit PCI\r
175 configuration register specified by Address. The value written to the PCI\r
176 configuration register is returned. This function must guarantee that all PCI\r
177 read and write operations are serialized.\r
178\r
179 If Address > 0x0FFFFFFF, then ASSERT().\r
180\r
181 @param Address Address that encodes the PCI Bus, Device, Function and\r
182 Register.\r
183 @param AndData The value to AND with the PCI configuration register.\r
184 @param OrData The value to OR with the result of the AND operation.\r
185\r
186 @return The value written back to the PCI configuration register.\r
187\r
188**/\r
189UINT8\r
190EFIAPI\r
191PciExpressAndThenOr8 (\r
192 IN UINTN Address,\r
193 IN UINT8 AndData,\r
194 IN UINT8 OrData\r
195 );\r
196\r
197/**\r
198 Reads a bit field of a PCI configuration register.\r
199\r
200 Reads the bit field in an 8-bit PCI configuration register. The bit field is\r
201 specified by the StartBit and the EndBit. The value of the bit field is\r
202 returned.\r
203\r
204 If Address > 0x0FFFFFFF, then ASSERT().\r
205 If StartBit is greater than 7, then ASSERT().\r
206 If EndBit is greater than 7, then ASSERT().\r
207 If EndBit is less than StartBit, then ASSERT().\r
208\r
209 @param Address PCI configuration register to read.\r
210 @param StartBit The ordinal of the least significant bit in the bit field.\r
211 Range 0..7.\r
212 @param EndBit The ordinal of the most significant bit in the bit field.\r
213 Range 0..7.\r
214\r
215 @return The value of the bit field read from the PCI configuration register.\r
216\r
217**/\r
218UINT8\r
219EFIAPI\r
220PciExpressBitFieldRead8 (\r
221 IN UINTN Address,\r
222 IN UINTN StartBit,\r
223 IN UINTN EndBit\r
224 );\r
225\r
226/**\r
227 Writes a bit field to a PCI configuration register.\r
228\r
229 Writes Value to the bit field of the PCI configuration register. The bit\r
230 field is specified by the StartBit and the EndBit. All other bits in the\r
231 destination PCI configuration register are preserved. The new value of the\r
232 8-bit register is returned.\r
233\r
234 If Address > 0x0FFFFFFF, then ASSERT().\r
235 If StartBit is greater than 7, then ASSERT().\r
236 If EndBit is greater than 7, then ASSERT().\r
237 If EndBit is less than StartBit, then ASSERT().\r
94952554 238 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 239\r
240 @param Address PCI configuration register to write.\r
241 @param StartBit The ordinal of the least significant bit in the bit field.\r
242 Range 0..7.\r
243 @param EndBit The ordinal of the most significant bit in the bit field.\r
244 Range 0..7.\r
245 @param Value New value of the bit field.\r
246\r
247 @return The value written back to the PCI configuration register.\r
248\r
249**/\r
250UINT8\r
251EFIAPI\r
252PciExpressBitFieldWrite8 (\r
253 IN UINTN Address,\r
254 IN UINTN StartBit,\r
255 IN UINTN EndBit,\r
256 IN UINT8 Value\r
257 );\r
258\r
259/**\r
260 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and\r
261 writes the result back to the bit field in the 8-bit port.\r
262\r
263 Reads the 8-bit PCI configuration register specified by Address, performs a\r
62991af2 264 bitwise OR between the read result and the value specified by\r
fb3df220 265 OrData, and writes the result to the 8-bit PCI configuration register\r
266 specified by Address. The value written to the PCI configuration register is\r
267 returned. This function must guarantee that all PCI read and write operations\r
268 are serialized. Extra left bits in OrData are stripped.\r
269\r
270 If Address > 0x0FFFFFFF, then ASSERT().\r
271 If StartBit is greater than 7, then ASSERT().\r
272 If EndBit is greater than 7, then ASSERT().\r
273 If EndBit is less than StartBit, then ASSERT().\r
94952554 274 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 275\r
276 @param Address PCI configuration register to write.\r
277 @param StartBit The ordinal of the least significant bit in the bit field.\r
278 Range 0..7.\r
279 @param EndBit The ordinal of the most significant bit in the bit field.\r
280 Range 0..7.\r
281 @param OrData The value to OR with the PCI configuration register.\r
282\r
283 @return The value written back to the PCI configuration register.\r
284\r
285**/\r
286UINT8\r
287EFIAPI\r
288PciExpressBitFieldOr8 (\r
289 IN UINTN Address,\r
290 IN UINTN StartBit,\r
291 IN UINTN EndBit,\r
292 IN UINT8 OrData\r
293 );\r
294\r
295/**\r
296 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise\r
297 AND, and writes the result back to the bit field in the 8-bit register.\r
298\r
299 Reads the 8-bit PCI configuration register specified by Address, performs a\r
300 bitwise AND between the read result and the value specified by AndData, and\r
301 writes the result to the 8-bit PCI configuration register specified by\r
302 Address. The value written to the PCI configuration register is returned.\r
303 This function must guarantee that all PCI read and write operations are\r
304 serialized. Extra left bits in AndData are stripped.\r
305\r
306 If Address > 0x0FFFFFFF, then ASSERT().\r
307 If StartBit is greater than 7, then ASSERT().\r
308 If EndBit is greater than 7, then ASSERT().\r
309 If EndBit is less than StartBit, then ASSERT().\r
94952554 310 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 311\r
312 @param Address PCI configuration register to write.\r
313 @param StartBit The ordinal of the least significant bit in the bit field.\r
314 Range 0..7.\r
315 @param EndBit The ordinal of the most significant bit in the bit field.\r
316 Range 0..7.\r
317 @param AndData The value to AND with the PCI configuration register.\r
318\r
319 @return The value written back to the PCI configuration register.\r
320\r
321**/\r
322UINT8\r
323EFIAPI\r
324PciExpressBitFieldAnd8 (\r
325 IN UINTN Address,\r
326 IN UINTN StartBit,\r
327 IN UINTN EndBit,\r
328 IN UINT8 AndData\r
329 );\r
330\r
331/**\r
332 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a\r
62991af2 333 bitwise OR, and writes the result back to the bit field in the\r
fb3df220 334 8-bit port.\r
335\r
336 Reads the 8-bit PCI configuration register specified by Address, performs a\r
62991af2 337 bitwise AND followed by a bitwise OR between the read result and\r
fb3df220 338 the value specified by AndData, and writes the result to the 8-bit PCI\r
339 configuration register specified by Address. The value written to the PCI\r
340 configuration register is returned. This function must guarantee that all PCI\r
341 read and write operations are serialized. Extra left bits in both AndData and\r
342 OrData are stripped.\r
343\r
344 If Address > 0x0FFFFFFF, then ASSERT().\r
345 If StartBit is greater than 7, then ASSERT().\r
346 If EndBit is greater than 7, then ASSERT().\r
347 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
348 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
349 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 350\r
351 @param Address PCI configuration register to write.\r
352 @param StartBit The ordinal of the least significant bit in the bit field.\r
353 Range 0..7.\r
354 @param EndBit The ordinal of the most significant bit in the bit field.\r
355 Range 0..7.\r
356 @param AndData The value to AND with the PCI configuration register.\r
357 @param OrData The value to OR with the result of the AND operation.\r
358\r
359 @return The value written back to the PCI configuration register.\r
360\r
361**/\r
362UINT8\r
363EFIAPI\r
364PciExpressBitFieldAndThenOr8 (\r
365 IN UINTN Address,\r
366 IN UINTN StartBit,\r
367 IN UINTN EndBit,\r
368 IN UINT8 AndData,\r
369 IN UINT8 OrData\r
370 );\r
371\r
372/**\r
373 Reads a 16-bit PCI configuration register.\r
374\r
375 Reads and returns the 16-bit PCI configuration register specified by Address.\r
376 This function must guarantee that all PCI read and write operations are\r
377 serialized.\r
378\r
379 If Address > 0x0FFFFFFF, then ASSERT().\r
380 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
381\r
382 @param Address Address that encodes the PCI Bus, Device, Function and\r
383 Register.\r
384\r
385 @return The read value from the PCI configuration register.\r
386\r
387**/\r
388UINT16\r
389EFIAPI\r
390PciExpressRead16 (\r
391 IN UINTN Address\r
392 );\r
393\r
394/**\r
395 Writes a 16-bit PCI configuration register.\r
396\r
397 Writes the 16-bit PCI configuration register specified by Address with the\r
398 value specified by Value. Value is returned. This function must guarantee\r
399 that all PCI read and write operations are serialized.\r
400\r
401 If Address > 0x0FFFFFFF, then ASSERT().\r
402 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
403\r
404 @param Address Address that encodes the PCI Bus, Device, Function and\r
405 Register.\r
406 @param Value The value to write.\r
407\r
408 @return The value written to the PCI configuration register.\r
409\r
410**/\r
411UINT16\r
412EFIAPI\r
413PciExpressWrite16 (\r
414 IN UINTN Address,\r
94646ec0 415 IN UINT16 Value\r
fb3df220 416 );\r
417\r
418/**\r
62991af2 419 Performs a bitwise OR of a 16-bit PCI configuration register with\r
fb3df220 420 a 16-bit value.\r
421\r
422 Reads the 16-bit PCI configuration register specified by Address, performs a\r
62991af2 423 bitwise OR between the read result and the value specified by\r
fb3df220 424 OrData, and writes the result to the 16-bit PCI configuration register\r
425 specified by Address. The value written to the PCI configuration register is\r
426 returned. This function must guarantee that all PCI read and write operations\r
427 are serialized.\r
428\r
429 If Address > 0x0FFFFFFF, then ASSERT().\r
430 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
431\r
432 @param Address Address that encodes the PCI Bus, Device, Function and\r
433 Register.\r
434 @param OrData The value to OR with the PCI configuration register.\r
435\r
436 @return The value written back to the PCI configuration register.\r
437\r
438**/\r
439UINT16\r
440EFIAPI\r
441PciExpressOr16 (\r
442 IN UINTN Address,\r
443 IN UINT16 OrData\r
444 );\r
445\r
446/**\r
447 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit\r
448 value.\r
449\r
450 Reads the 16-bit PCI configuration register specified by Address, performs a\r
451 bitwise AND between the read result and the value specified by AndData, and\r
452 writes the result to the 16-bit PCI configuration register specified by\r
453 Address. The value written to the PCI configuration register is returned.\r
454 This function must guarantee that all PCI read and write operations are\r
455 serialized.\r
456\r
457 If Address > 0x0FFFFFFF, then ASSERT().\r
458 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
459\r
460 @param Address Address that encodes the PCI Bus, Device, Function and\r
461 Register.\r
462 @param AndData The value to AND with the PCI configuration register.\r
463\r
464 @return The value written back to the PCI configuration register.\r
465\r
466**/\r
467UINT16\r
468EFIAPI\r
469PciExpressAnd16 (\r
470 IN UINTN Address,\r
471 IN UINT16 AndData\r
472 );\r
473\r
474/**\r
475 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit\r
62991af2 476 value, followed a bitwise OR with another 16-bit value.\r
fb3df220 477\r
478 Reads the 16-bit PCI configuration register specified by Address, performs a\r
479 bitwise AND between the read result and the value specified by AndData,\r
62991af2 480 performs a bitwise OR between the result of the AND operation and\r
fb3df220 481 the value specified by OrData, and writes the result to the 16-bit PCI\r
482 configuration register specified by Address. The value written to the PCI\r
483 configuration register is returned. This function must guarantee that all PCI\r
484 read and write operations are serialized.\r
485\r
486 If Address > 0x0FFFFFFF, then ASSERT().\r
487 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
488\r
489 @param Address Address that encodes the PCI Bus, Device, Function and\r
490 Register.\r
491 @param AndData The value to AND with the PCI configuration register.\r
492 @param OrData The value to OR with the result of the AND operation.\r
493\r
494 @return The value written back to the PCI configuration register.\r
495\r
496**/\r
497UINT16\r
498EFIAPI\r
499PciExpressAndThenOr16 (\r
500 IN UINTN Address,\r
501 IN UINT16 AndData,\r
502 IN UINT16 OrData\r
503 );\r
504\r
505/**\r
506 Reads a bit field of a PCI configuration register.\r
507\r
508 Reads the bit field in a 16-bit PCI configuration register. The bit field is\r
509 specified by the StartBit and the EndBit. The value of the bit field is\r
510 returned.\r
511\r
512 If Address > 0x0FFFFFFF, then ASSERT().\r
513 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
514 If StartBit is greater than 15, then ASSERT().\r
515 If EndBit is greater than 15, then ASSERT().\r
516 If EndBit is less than StartBit, then ASSERT().\r
517\r
518 @param Address PCI configuration register to read.\r
519 @param StartBit The ordinal of the least significant bit in the bit field.\r
520 Range 0..15.\r
521 @param EndBit The ordinal of the most significant bit in the bit field.\r
522 Range 0..15.\r
523\r
524 @return The value of the bit field read from the PCI configuration register.\r
525\r
526**/\r
527UINT16\r
528EFIAPI\r
529PciExpressBitFieldRead16 (\r
530 IN UINTN Address,\r
531 IN UINTN StartBit,\r
532 IN UINTN EndBit\r
533 );\r
534\r
535/**\r
536 Writes a bit field to a PCI configuration register.\r
537\r
538 Writes Value to the bit field of the PCI configuration register. The bit\r
539 field is specified by the StartBit and the EndBit. All other bits in the\r
540 destination PCI configuration register are preserved. The new value of the\r
541 16-bit register is returned.\r
542\r
543 If Address > 0x0FFFFFFF, then ASSERT().\r
544 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
545 If StartBit is greater than 15, then ASSERT().\r
546 If EndBit is greater than 15, then ASSERT().\r
547 If EndBit is less than StartBit, then ASSERT().\r
94952554 548 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 549\r
550 @param Address PCI configuration register to write.\r
551 @param StartBit The ordinal of the least significant bit in the bit field.\r
552 Range 0..15.\r
553 @param EndBit The ordinal of the most significant bit in the bit field.\r
554 Range 0..15.\r
555 @param Value New value of the bit field.\r
556\r
557 @return The value written back to the PCI configuration register.\r
558\r
559**/\r
560UINT16\r
561EFIAPI\r
562PciExpressBitFieldWrite16 (\r
563 IN UINTN Address,\r
564 IN UINTN StartBit,\r
565 IN UINTN EndBit,\r
566 IN UINT16 Value\r
567 );\r
568\r
569/**\r
570 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and\r
571 writes the result back to the bit field in the 16-bit port.\r
572\r
573 Reads the 16-bit PCI configuration register specified by Address, performs a\r
62991af2 574 bitwise OR between the read result and the value specified by\r
fb3df220 575 OrData, and writes the result to the 16-bit PCI configuration register\r
576 specified by Address. The value written to the PCI configuration register is\r
577 returned. This function must guarantee that all PCI read and write operations\r
578 are serialized. Extra left bits in OrData are stripped.\r
579\r
580 If Address > 0x0FFFFFFF, then ASSERT().\r
581 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
582 If StartBit is greater than 15, then ASSERT().\r
583 If EndBit is greater than 15, then ASSERT().\r
584 If EndBit is less than StartBit, then ASSERT().\r
94952554 585 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 586\r
587 @param Address PCI configuration register to write.\r
588 @param StartBit The ordinal of the least significant bit in the bit field.\r
589 Range 0..15.\r
590 @param EndBit The ordinal of the most significant bit in the bit field.\r
591 Range 0..15.\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
599PciExpressBitFieldOr16 (\r
600 IN UINTN Address,\r
601 IN UINTN StartBit,\r
602 IN UINTN EndBit,\r
603 IN UINT16 OrData\r
604 );\r
605\r
606/**\r
607 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise\r
608 AND, and writes the result back to the bit field in the 16-bit register.\r
609\r
610 Reads the 16-bit PCI configuration register specified by Address, performs a\r
611 bitwise AND between the read result and the value specified by AndData, and\r
612 writes the result to the 16-bit PCI configuration register specified by\r
613 Address. The value written to the PCI configuration register is returned.\r
614 This function must guarantee that all PCI read and write operations are\r
615 serialized. Extra left bits in AndData are stripped.\r
616\r
617 If Address > 0x0FFFFFFF, then ASSERT().\r
618 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
619 If StartBit is greater than 15, then ASSERT().\r
620 If EndBit is greater than 15, then ASSERT().\r
621 If EndBit is less than StartBit, then ASSERT().\r
94952554 622 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 623\r
624 @param Address PCI configuration register to write.\r
625 @param StartBit The ordinal of the least significant bit in the bit field.\r
626 Range 0..15.\r
627 @param EndBit The ordinal of the most significant bit in the bit field.\r
628 Range 0..15.\r
629 @param AndData The value to AND with the PCI configuration register.\r
630\r
631 @return The value written back to the PCI configuration register.\r
632\r
633**/\r
634UINT16\r
635EFIAPI\r
636PciExpressBitFieldAnd16 (\r
637 IN UINTN Address,\r
638 IN UINTN StartBit,\r
639 IN UINTN EndBit,\r
640 IN UINT16 AndData\r
641 );\r
642\r
643/**\r
644 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a\r
62991af2 645 bitwise OR, and writes the result back to the bit field in the\r
fb3df220 646 16-bit port.\r
647\r
648 Reads the 16-bit PCI configuration register specified by Address, performs a\r
62991af2 649 bitwise AND followed by a bitwise OR between the read result and\r
fb3df220 650 the value specified by AndData, and writes the result to the 16-bit PCI\r
651 configuration register specified by Address. The value written to the PCI\r
652 configuration register is returned. This function must guarantee that all PCI\r
653 read and write operations are serialized. Extra left bits in both AndData and\r
654 OrData are stripped.\r
655\r
656 If Address > 0x0FFFFFFF, then ASSERT().\r
657 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
658 If StartBit is greater than 15, then ASSERT().\r
659 If EndBit is greater than 15, then ASSERT().\r
660 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
661 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
662 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 663\r
664 @param Address PCI configuration register to write.\r
665 @param StartBit The ordinal of the least significant bit in the bit field.\r
666 Range 0..15.\r
667 @param EndBit The ordinal of the most significant bit in the bit field.\r
668 Range 0..15.\r
669 @param AndData The value to AND with the PCI configuration register.\r
670 @param OrData The value to OR with the result of the AND operation.\r
671\r
672 @return The value written back to the PCI configuration register.\r
673\r
674**/\r
675UINT16\r
676EFIAPI\r
677PciExpressBitFieldAndThenOr16 (\r
678 IN UINTN Address,\r
679 IN UINTN StartBit,\r
680 IN UINTN EndBit,\r
681 IN UINT16 AndData,\r
682 IN UINT16 OrData\r
683 );\r
684\r
685/**\r
686 Reads a 32-bit PCI configuration register.\r
687\r
688 Reads and returns the 32-bit PCI configuration register specified by Address.\r
689 This function must guarantee that all PCI read and write operations are\r
690 serialized.\r
691\r
692 If Address > 0x0FFFFFFF, then ASSERT().\r
693 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
694\r
695 @param Address Address that encodes the PCI Bus, Device, Function and\r
696 Register.\r
697\r
698 @return The read value from the PCI configuration register.\r
699\r
700**/\r
701UINT32\r
702EFIAPI\r
703PciExpressRead32 (\r
704 IN UINTN Address\r
705 );\r
706\r
707/**\r
708 Writes a 32-bit PCI configuration register.\r
709\r
710 Writes the 32-bit PCI configuration register specified by Address with the\r
711 value specified by Value. Value is returned. This function must guarantee\r
712 that all PCI read and write operations are serialized.\r
713\r
714 If Address > 0x0FFFFFFF, then ASSERT().\r
715 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
716\r
717 @param Address Address that encodes the PCI Bus, Device, Function and\r
718 Register.\r
719 @param Value The value to write.\r
720\r
721 @return The value written to the PCI configuration register.\r
722\r
723**/\r
724UINT32\r
725EFIAPI\r
726PciExpressWrite32 (\r
727 IN UINTN Address,\r
94646ec0 728 IN UINT32 Value\r
fb3df220 729 );\r
730\r
731/**\r
62991af2 732 Performs a bitwise OR of a 32-bit PCI configuration register with\r
fb3df220 733 a 32-bit value.\r
734\r
735 Reads the 32-bit PCI configuration register specified by Address, performs a\r
62991af2 736 bitwise OR between the read result and the value specified by\r
fb3df220 737 OrData, and writes the result to the 32-bit PCI configuration register\r
738 specified by Address. The value written to the PCI configuration register is\r
739 returned. This function must guarantee that all PCI read and write operations\r
740 are serialized.\r
741\r
742 If Address > 0x0FFFFFFF, then ASSERT().\r
743 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
744\r
745 @param Address Address that encodes the PCI Bus, Device, Function and\r
746 Register.\r
747 @param OrData The value to OR with the PCI configuration register.\r
748\r
749 @return The value written back to the PCI configuration register.\r
750\r
751**/\r
752UINT32\r
753EFIAPI\r
754PciExpressOr32 (\r
755 IN UINTN Address,\r
756 IN UINT32 OrData\r
757 );\r
758\r
759/**\r
760 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit\r
761 value.\r
762\r
763 Reads the 32-bit PCI configuration register specified by Address, performs a\r
764 bitwise AND between the read result and the value specified by AndData, and\r
765 writes the result to the 32-bit PCI configuration register specified by\r
766 Address. The value written to the PCI configuration register is returned.\r
767 This function must guarantee that all PCI read and write operations are\r
768 serialized.\r
769\r
770 If Address > 0x0FFFFFFF, then ASSERT().\r
771 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
772\r
773 @param Address Address that encodes the PCI Bus, Device, Function and\r
774 Register.\r
775 @param AndData The value to AND with the PCI configuration register.\r
776\r
777 @return The value written back to the PCI configuration register.\r
778\r
779**/\r
780UINT32\r
781EFIAPI\r
782PciExpressAnd32 (\r
783 IN UINTN Address,\r
784 IN UINT32 AndData\r
785 );\r
786\r
787/**\r
788 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit\r
62991af2 789 value, followed a bitwise OR with another 32-bit value.\r
fb3df220 790\r
791 Reads the 32-bit PCI configuration register specified by Address, performs a\r
792 bitwise AND between the read result and the value specified by AndData,\r
62991af2 793 performs a bitwise OR between the result of the AND operation and\r
fb3df220 794 the value specified by OrData, and writes the result to the 32-bit PCI\r
795 configuration register specified by Address. The value written to the PCI\r
796 configuration register is returned. This function must guarantee that all PCI\r
797 read and write operations are serialized.\r
798\r
799 If Address > 0x0FFFFFFF, then ASSERT().\r
800 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
801\r
802 @param Address Address that encodes the PCI Bus, Device, Function and\r
803 Register.\r
804 @param AndData The value to AND with the PCI configuration register.\r
805 @param OrData The value to OR with the result of the AND operation.\r
806\r
807 @return The value written back to the PCI configuration register.\r
808\r
809**/\r
810UINT32\r
811EFIAPI\r
812PciExpressAndThenOr32 (\r
813 IN UINTN Address,\r
814 IN UINT32 AndData,\r
815 IN UINT32 OrData\r
816 );\r
817\r
818/**\r
819 Reads a bit field of a PCI configuration register.\r
820\r
821 Reads the bit field in a 32-bit PCI configuration register. The bit field is\r
822 specified by the StartBit and the EndBit. The value of the bit field is\r
823 returned.\r
824\r
825 If Address > 0x0FFFFFFF, then ASSERT().\r
826 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
827 If StartBit is greater than 31, then ASSERT().\r
828 If EndBit is greater than 31, then ASSERT().\r
829 If EndBit is less than StartBit, then ASSERT().\r
830\r
831 @param Address PCI configuration register to read.\r
832 @param StartBit The ordinal of the least significant bit in the bit field.\r
833 Range 0..31.\r
834 @param EndBit The ordinal of the most significant bit in the bit field.\r
835 Range 0..31.\r
836\r
837 @return The value of the bit field read from the PCI configuration register.\r
838\r
839**/\r
840UINT32\r
841EFIAPI\r
842PciExpressBitFieldRead32 (\r
843 IN UINTN Address,\r
844 IN UINTN StartBit,\r
845 IN UINTN EndBit\r
846 );\r
847\r
848/**\r
849 Writes a bit field to a PCI configuration register.\r
850\r
851 Writes Value to the bit field of the PCI configuration register. The bit\r
852 field is specified by the StartBit and the EndBit. All other bits in the\r
853 destination PCI configuration register are preserved. The new value of the\r
854 32-bit register is returned.\r
855\r
856 If Address > 0x0FFFFFFF, then ASSERT().\r
857 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
858 If StartBit is greater than 31, then ASSERT().\r
859 If EndBit is greater than 31, then ASSERT().\r
860 If EndBit is less than StartBit, then ASSERT().\r
94952554 861 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 862\r
863 @param Address PCI configuration register to write.\r
864 @param StartBit The ordinal of the least significant bit in the bit field.\r
865 Range 0..31.\r
866 @param EndBit The ordinal of the most significant bit in the bit field.\r
867 Range 0..31.\r
868 @param Value New value of the bit field.\r
869\r
870 @return The value written back to the PCI configuration register.\r
871\r
872**/\r
873UINT32\r
874EFIAPI\r
875PciExpressBitFieldWrite32 (\r
876 IN UINTN Address,\r
877 IN UINTN StartBit,\r
878 IN UINTN EndBit,\r
879 IN UINT32 Value\r
880 );\r
881\r
882/**\r
883 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and\r
884 writes the result back to the bit field in the 32-bit port.\r
885\r
886 Reads the 32-bit PCI configuration register specified by Address, performs a\r
62991af2 887 bitwise OR between the read result and the value specified by\r
fb3df220 888 OrData, and writes the result to the 32-bit PCI configuration register\r
889 specified by Address. The value written to the PCI configuration register is\r
890 returned. This function must guarantee that all PCI read and write operations\r
891 are serialized. Extra left bits in OrData are stripped.\r
892\r
893 If Address > 0x0FFFFFFF, then ASSERT().\r
894 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
895 If StartBit is greater than 31, then ASSERT().\r
896 If EndBit is greater than 31, then ASSERT().\r
897 If EndBit is less than StartBit, then ASSERT().\r
94952554 898 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 899\r
900 @param Address PCI configuration register to write.\r
901 @param StartBit The ordinal of the least significant bit in the bit field.\r
902 Range 0..31.\r
903 @param EndBit The ordinal of the most significant bit in the bit field.\r
904 Range 0..31.\r
905 @param OrData The value to OR with the PCI configuration register.\r
906\r
907 @return The value written back to the PCI configuration register.\r
908\r
909**/\r
910UINT32\r
911EFIAPI\r
912PciExpressBitFieldOr32 (\r
913 IN UINTN Address,\r
914 IN UINTN StartBit,\r
915 IN UINTN EndBit,\r
916 IN UINT32 OrData\r
917 );\r
918\r
919/**\r
920 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise\r
921 AND, and writes the result back to the bit field in the 32-bit register.\r
922\r
923 Reads the 32-bit PCI configuration register specified by Address, performs a\r
924 bitwise AND between the read result and the value specified by AndData, and\r
925 writes the result to the 32-bit PCI configuration register specified by\r
926 Address. The value written to the PCI configuration register is returned.\r
927 This function must guarantee that all PCI read and write operations are\r
928 serialized. Extra left bits in AndData are stripped.\r
929\r
930 If Address > 0x0FFFFFFF, then ASSERT().\r
931 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
932 If StartBit is greater than 31, then ASSERT().\r
933 If EndBit is greater than 31, then ASSERT().\r
934 If EndBit is less than StartBit, then ASSERT().\r
94952554 935 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 936\r
937 @param Address PCI configuration register to write.\r
938 @param StartBit The ordinal of the least significant bit in the bit field.\r
939 Range 0..31.\r
940 @param EndBit The ordinal of the most significant bit in the bit field.\r
941 Range 0..31.\r
942 @param AndData The value to AND with the PCI configuration register.\r
943\r
944 @return The value written back to the PCI configuration register.\r
945\r
946**/\r
947UINT32\r
948EFIAPI\r
949PciExpressBitFieldAnd32 (\r
950 IN UINTN Address,\r
951 IN UINTN StartBit,\r
952 IN UINTN EndBit,\r
953 IN UINT32 AndData\r
954 );\r
955\r
956/**\r
957 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a\r
62991af2 958 bitwise OR, and writes the result back to the bit field in the\r
fb3df220 959 32-bit port.\r
960\r
961 Reads the 32-bit PCI configuration register specified by Address, performs a\r
62991af2 962 bitwise AND followed by a bitwise OR between the read result and\r
fb3df220 963 the value specified by AndData, and writes the result to the 32-bit PCI\r
964 configuration register specified by Address. The value written to the PCI\r
965 configuration register is returned. This function must guarantee that all PCI\r
966 read and write operations are serialized. Extra left bits in both AndData and\r
967 OrData are stripped.\r
968\r
969 If Address > 0x0FFFFFFF, then ASSERT().\r
970 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
971 If StartBit is greater than 31, then ASSERT().\r
972 If EndBit is greater than 31, then ASSERT().\r
973 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
974 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
975 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
fb3df220 976\r
977 @param Address PCI configuration register to write.\r
978 @param StartBit The ordinal of the least significant bit in the bit field.\r
979 Range 0..31.\r
980 @param EndBit The ordinal of the most significant bit in the bit field.\r
981 Range 0..31.\r
982 @param AndData The value to AND with the PCI configuration register.\r
983 @param OrData The value to OR with the result of the AND operation.\r
984\r
985 @return The value written back to the PCI configuration register.\r
986\r
987**/\r
988UINT32\r
989EFIAPI\r
990PciExpressBitFieldAndThenOr32 (\r
991 IN UINTN Address,\r
992 IN UINTN StartBit,\r
993 IN UINTN EndBit,\r
994 IN UINT32 AndData,\r
995 IN UINT32 OrData\r
996 );\r
997\r
998/**\r
999 Reads a range of PCI configuration registers into a caller supplied buffer.\r
1000\r
1001 Reads the range of PCI configuration registers specified by StartAddress and\r
1002 Size into the buffer specified by Buffer. This function only allows the PCI\r
1003 configuration registers from a single PCI function to be read. Size is\r
1004 returned. When possible 32-bit PCI configuration read cycles are used to read\r
1005 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit\r
1006 and 16-bit PCI configuration read cycles may be used at the beginning and the\r
1007 end of the range.\r
1008\r
1009 If StartAddress > 0x0FFFFFFF, then ASSERT().\r
1010 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().\r
1011 If Size > 0 and Buffer is NULL, then ASSERT().\r
1012\r
1013 @param StartAddress Starting address that encodes the PCI Bus, Device,\r
1014 Function and Register.\r
1015 @param Size Size in bytes of the transfer.\r
1016 @param Buffer Pointer to a buffer receiving the data read.\r
1017\r
badcbfb2 1018 @return Size read data from StartAddress.\r
fb3df220 1019\r
1020**/\r
1021UINTN\r
1022EFIAPI\r
1023PciExpressReadBuffer (\r
1024 IN UINTN StartAddress,\r
1025 IN UINTN Size,\r
1026 OUT VOID *Buffer\r
1027 );\r
1028\r
1029/**\r
1030 Copies the data in a caller supplied buffer to a specified range of PCI\r
1031 configuration space.\r
1032\r
1033 Writes the range of PCI configuration registers specified by StartAddress and\r
1034 Size from the buffer specified by Buffer. This function only allows the PCI\r
1035 configuration registers from a single PCI function to be written. Size is\r
1036 returned. When possible 32-bit PCI configuration write cycles are used to\r
1037 write from StartAdress to StartAddress + Size. Due to alignment restrictions,\r
1038 8-bit and 16-bit PCI configuration write cycles may be used at the beginning\r
1039 and the end of the range.\r
1040\r
1041 If StartAddress > 0x0FFFFFFF, then ASSERT().\r
1042 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().\r
1043 If Size > 0 and Buffer is NULL, then ASSERT().\r
1044\r
1045 @param StartAddress Starting address that encodes the PCI Bus, Device,\r
1046 Function and Register.\r
1047 @param Size Size in bytes of the transfer.\r
1048 @param Buffer Pointer to a buffer containing the data to write.\r
1049\r
9199040c 1050 @return Size written to StartAddress.\r
fb3df220 1051\r
1052**/\r
1053UINTN\r
1054EFIAPI\r
1055PciExpressWriteBuffer (\r
1056 IN UINTN StartAddress,\r
1057 IN UINTN Size,\r
1058 IN VOID *Buffer\r
1059 );\r
1060\r
1061#endif\r