3 The implementation of I/O operation for this library instance
4 are based on EFI_CPU_IO_PROTOCOL.
6 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "SmmCpuIoLibInternal.h"
20 Reads registers in the EFI CPU I/O space.
22 Reads the I/O port specified by Port with registers width specified by Width.
23 The read value is returned. If such operations are not supported, then ASSERT().
24 This function must guarantee that all I/O read and write operations are serialized.
26 @param Port The base address of the I/O operation.
27 The caller is responsible for aligning the Address if required.
28 @param Width The width of the I/O operation.
30 @return Data read from registers in the EFI CPU I/O space.
37 IN EFI_SMM_IO_WIDTH Width
43 Status
= gSmst
->SmmIo
.Io
.Read (&gSmst
->SmmIo
, Width
, Port
, 1, &Data
);
44 ASSERT_EFI_ERROR (Status
);
50 Writes registers in the EFI CPU I/O space.
52 Writes the I/O port specified by Port with registers width and value specified by Width
53 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
54 This function must guarantee that all I/O read and write operations are serialized.
56 @param Port The base address of the I/O operation.
57 The caller is responsible for aligning the Address if required.
58 @param Width The width of the I/O operation.
59 @param Data The value to write to the I/O port.
61 @return The paramter of Data.
68 IN EFI_SMM_IO_WIDTH Width
,
74 Status
= gSmst
->SmmIo
.Io
.Write (&gSmst
->SmmIo
, Width
, Port
, 1, &Data
);
75 ASSERT_EFI_ERROR (Status
);
81 Reads memory-mapped registers in the EFI system memory space.
83 Reads the MMIO registers specified by Address with registers width specified by Width.
84 The read value is returned. If such operations are not supported, then ASSERT().
85 This function must guarantee that all MMIO read and write operations are serialized.
87 @param Address The MMIO register to read.
88 The caller is responsible for aligning the Address if required.
89 @param Width The width of the I/O operation.
91 @return Data read from registers in the EFI system memory space.
98 IN EFI_SMM_IO_WIDTH Width
104 Status
= gSmst
->SmmIo
.Mem
.Read (&gSmst
->SmmIo
, Width
, Address
, 1, &Data
);
105 ASSERT_EFI_ERROR (Status
);
111 Writes memory-mapped registers in the EFI system memory space.
113 Writes the MMIO registers specified by Address with registers width and value specified by Width
114 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
115 This function must guarantee that all MMIO read and write operations are serialized.
117 @param Address The MMIO register to read.
118 The caller is responsible for aligning the Address if required.
119 @param Width The width of the I/O operation.
120 @param Data The value to write to the I/O port.
122 @return Data read from registers in the EFI system memory space.
129 IN EFI_SMM_IO_WIDTH Width
,
135 Status
= gSmst
->SmmIo
.Mem
.Write (&gSmst
->SmmIo
, Width
, Address
, 1, &Data
);
136 ASSERT_EFI_ERROR (Status
);
142 Reads an 8-bit I/O port.
144 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
145 This function must guarantee that all I/O read and write operations are
148 If 8-bit I/O port operations are not supported, then ASSERT().
150 @param Port The I/O port to read.
152 @return The value read.
161 return (UINT8
)IoReadWorker (Port
, SMM_IO_UINT8
);
165 Writes an 8-bit I/O port.
167 Writes the 8-bit I/O port specified by Port with the value specified by Value
168 and returns Value. This function must guarantee that all I/O read and write
169 operations are serialized.
171 If 8-bit I/O port operations are not supported, then ASSERT().
173 @param Port The I/O port to write.
174 @param Value The value to write to the I/O port.
176 @return The value written the I/O port.
186 return (UINT8
)IoWriteWorker (Port
, SMM_IO_UINT8
, Value
);
190 Reads a 16-bit I/O port.
192 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
193 This function must guarantee that all I/O read and write operations are
196 If Port is not aligned on a 16-bit boundary, then ASSERT().
198 If 16-bit I/O port operations are not supported, then ASSERT().
200 @param Port The I/O port to read.
202 @return The value read.
212 // Make sure Port is aligned on a 16-bit boundary.
214 ASSERT ((Port
& 1) == 0);
215 return (UINT16
)IoReadWorker (Port
, SMM_IO_UINT16
);
219 Writes a 16-bit I/O port.
221 Writes the 16-bit I/O port specified by Port with the value specified by Value
222 and returns Value. This function must guarantee that all I/O read and write
223 operations are serialized.
225 If Port is not aligned on a 16-bit boundary, then ASSERT().
227 If 16-bit I/O port operations are not supported, then ASSERT().
229 @param Port The I/O port to write.
230 @param Value The value to write to the I/O port.
232 @return The value written the I/O port.
243 // Make sure Port is aligned on a 16-bit boundary.
245 ASSERT ((Port
& 1) == 0);
246 return (UINT16
)IoWriteWorker (Port
, SMM_IO_UINT16
, Value
);
250 Reads a 32-bit I/O port.
252 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
253 This function must guarantee that all I/O read and write operations are
256 If Port is not aligned on a 32-bit boundary, then ASSERT().
258 If 32-bit I/O port operations are not supported, then ASSERT().
260 @param Port The I/O port to read.
262 @return The value read.
272 // Make sure Port is aligned on a 32-bit boundary.
274 ASSERT ((Port
& 3) == 0);
275 return (UINT32
)IoReadWorker (Port
, SMM_IO_UINT32
);
279 Writes a 32-bit I/O port.
281 Writes the 32-bit I/O port specified by Port with the value specified by Value
282 and returns Value. This function must guarantee that all I/O read and write
283 operations are serialized.
285 If Port is not aligned on a 32-bit boundary, then ASSERT().
287 If 32-bit I/O port operations are not supported, then ASSERT().
289 @param Port The I/O port to write.
290 @param Value The value to write to the I/O port.
292 @return The value written the I/O port.
303 // Make sure Port is aligned on a 32-bit boundary.
305 ASSERT ((Port
& 3) == 0);
306 return (UINT32
)IoWriteWorker (Port
, SMM_IO_UINT32
, Value
);
310 Reads a 64-bit I/O port.
312 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
313 This function must guarantee that all I/O read and write operations are
316 If Port is not aligned on a 64-bit boundary, then ASSERT().
318 If 64-bit I/O port operations are not supported, then ASSERT().
320 @param Port The I/O port to read.
322 @return The value read.
332 // Make sure Port is aligned on a 64-bit boundary.
334 ASSERT ((Port
& 7) == 0);
335 return IoReadWorker (Port
, SMM_IO_UINT64
);
339 Writes a 64-bit I/O port.
341 Writes the 64-bit I/O port specified by Port with the value specified by Value
342 and returns Value. This function must guarantee that all I/O read and write
343 operations are serialized.
345 If Port is not aligned on a 64-bit boundary, then ASSERT().
347 If 64-bit I/O port operations are not supported, then ASSERT().
349 @param Port The I/O port to write.
350 @param Value The value to write to the I/O port.
352 @return The value written the I/O port.
363 // Make sure Port is aligned on a 64-bit boundary.
365 ASSERT ((Port
& 7) == 0);
366 return IoWriteWorker (Port
, SMM_IO_UINT64
, Value
);
370 Reads an 8-bit MMIO register.
372 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
373 returned. This function must guarantee that all MMIO read and write
374 operations are serialized.
376 If 8-bit MMIO register operations are not supported, then ASSERT().
378 @param Address The MMIO register to read.
380 @return The value read.
389 return (UINT8
)MmioReadWorker (Address
, SMM_IO_UINT8
);
393 Writes an 8-bit MMIO register.
395 Writes the 8-bit MMIO register specified by Address with the value specified
396 by Value and returns Value. This function must guarantee that all MMIO read
397 and write operations are serialized.
399 If 8-bit MMIO register operations are not supported, then ASSERT().
401 @param Address The MMIO register to write.
402 @param Value The value to write to the MMIO register.
412 return (UINT8
)MmioWriteWorker (Address
, SMM_IO_UINT8
, Value
);
416 Reads a 16-bit MMIO register.
418 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
419 returned. This function must guarantee that all MMIO read and write
420 operations are serialized.
422 If Address is not aligned on a 16-bit boundary, then ASSERT().
424 If 16-bit MMIO register operations are not supported, then ASSERT().
426 @param Address The MMIO register to read.
428 @return The value read.
438 // Make sure Address is aligned on a 16-bit boundary.
440 ASSERT ((Address
& 1) == 0);
441 return (UINT16
)MmioReadWorker (Address
, SMM_IO_UINT16
);
445 Writes a 16-bit MMIO register.
447 Writes the 16-bit MMIO register specified by Address with the value specified
448 by Value and returns Value. This function must guarantee that all MMIO read
449 and write operations are serialized.
451 If Address is not aligned on a 16-bit boundary, then ASSERT().
453 If 16-bit MMIO register operations are not supported, then ASSERT().
455 @param Address The MMIO register to write.
456 @param Value The value to write to the MMIO register.
467 // Make sure Address is aligned on a 16-bit boundary.
469 ASSERT ((Address
& 1) == 0);
470 return (UINT16
)MmioWriteWorker (Address
, SMM_IO_UINT16
, Value
);
474 Reads a 32-bit MMIO register.
476 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
477 returned. This function must guarantee that all MMIO read and write
478 operations are serialized.
480 If Address is not aligned on a 32-bit boundary, then ASSERT().
482 If 32-bit MMIO register operations are not supported, then ASSERT().
484 @param Address The MMIO register to read.
486 @return The value read.
496 // Make sure Address is aligned on a 32-bit boundary.
498 ASSERT ((Address
& 3) == 0);
499 return (UINT32
)MmioReadWorker (Address
, SMM_IO_UINT32
);
503 Writes a 32-bit MMIO register.
505 Writes the 32-bit MMIO register specified by Address with the value specified
506 by Value and returns Value. This function must guarantee that all MMIO read
507 and write operations are serialized.
509 If Address is not aligned on a 32-bit boundary, then ASSERT().
511 If 32-bit MMIO register operations are not supported, then ASSERT().
513 @param Address The MMIO register to write.
514 @param Value The value to write to the MMIO register.
525 // Make sure Address is aligned on a 32-bit boundary.
527 ASSERT ((Address
& 3) == 0);
528 return (UINT32
)MmioWriteWorker (Address
, SMM_IO_UINT32
, Value
);
532 Reads a 64-bit MMIO register.
534 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
535 returned. This function must guarantee that all MMIO read and write
536 operations are serialized.
538 If Address is not aligned on a 64-bit boundary, then ASSERT().
540 If 64-bit MMIO register operations are not supported, then ASSERT().
542 @param Address The MMIO register to read.
544 @return The value read.
554 // Make sure Address is aligned on a 64-bit boundary.
556 ASSERT ((Address
& 7) == 0);
557 return (UINT64
)MmioReadWorker (Address
, SMM_IO_UINT64
);
561 Writes a 64-bit MMIO register.
563 Writes the 64-bit MMIO register specified by Address with the value specified
564 by Value and returns Value. This function must guarantee that all MMIO read
565 and write operations are serialized.
567 If Address is not aligned on a 64-bit boundary, then ASSERT().
569 If 64-bit MMIO register operations are not supported, then ASSERT().
571 @param Address The MMIO register to write.
572 @param Value The value to write to the MMIO register.
583 // Make sure Address is aligned on a 64-bit boundary.
585 ASSERT ((Address
& 7) == 0);
586 return (UINT64
)MmioWriteWorker (Address
, SMM_IO_UINT64
, Value
);