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