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