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<BR>
7 All rights reserved. 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 // Globle varible to cache pointer to CpuIo protocol.
22 EFI_SMM_CPU_IO2_PROTOCOL
*mCpuIo2
= NULL
;
25 The constructor function caches the pointer to CpuIo protocol.
27 The constructor function locates CpuIo protocol from protocol database.
28 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
30 @param ImageHandle The firmware allocated handle for the EFI image.
31 @param SystemTable A pointer to the EFI System Table.
33 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
39 IN EFI_HANDLE ImageHandle
,
40 IN EFI_SYSTEM_TABLE
*SystemTable
45 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid
, NULL
, (VOID
**) &mCpuIo2
);
46 ASSERT_EFI_ERROR (Status
);
52 Reads registers in the EFI CPU I/O space.
54 Reads the I/O port specified by Port with registers width specified by Width.
55 The read value is returned. If such operations are not supported, then ASSERT().
56 This function must guarantee that all I/O read and write operations are serialized.
58 @param Port The base address of the I/O operation.
59 The caller is responsible for aligning the Address if required.
60 @param Width The width of the I/O operation.
62 @return Data read from registers in the EFI CPU I/O space.
69 IN EFI_SMM_IO_WIDTH Width
75 Status
= mCpuIo2
->Io
.Read (mCpuIo2
, Width
, Port
, 1, &Data
);
76 ASSERT_EFI_ERROR (Status
);
82 Writes registers in the EFI CPU I/O space.
84 Writes the I/O port specified by Port with registers width and value specified by Width
85 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
86 This function must guarantee that all I/O read and write operations are serialized.
88 @param Port The base address of the I/O operation.
89 The caller is responsible for aligning the Address if required.
90 @param Width The width of the I/O operation.
91 @param Data The value to write to the I/O port.
93 @return The paramter of Data.
100 IN EFI_SMM_IO_WIDTH Width
,
106 Status
= mCpuIo2
->Io
.Write (mCpuIo2
, Width
, Port
, 1, &Data
);
107 ASSERT_EFI_ERROR (Status
);
113 Reads memory-mapped registers in the EFI system memory space.
115 Reads the MMIO registers specified by Address with registers width specified by Width.
116 The read value is returned. If such operations are not supported, then ASSERT().
117 This function must guarantee that all MMIO read and write operations are serialized.
119 @param Address The MMIO register to read.
120 The caller is responsible for aligning the Address if required.
121 @param Width The width of the I/O operation.
123 @return Data read from registers in the EFI system memory space.
130 IN EFI_SMM_IO_WIDTH Width
136 Status
= mCpuIo2
->Mem
.Read (mCpuIo2
, Width
, Address
, 1, &Data
);
137 ASSERT_EFI_ERROR (Status
);
143 Writes memory-mapped registers in the EFI system memory space.
145 Writes the MMIO registers specified by Address with registers width and value specified by Width
146 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
147 This function must guarantee that all MMIO read and write operations are serialized.
149 @param Address The MMIO register to read.
150 The caller is responsible for aligning the Address if required.
151 @param Width The width of the I/O operation.
152 @param Data The value to write to the I/O port.
154 @return Data read from registers in the EFI system memory space.
161 IN EFI_SMM_IO_WIDTH Width
,
167 Status
= mCpuIo2
->Mem
.Write (mCpuIo2
, Width
, Address
, 1, &Data
);
168 ASSERT_EFI_ERROR (Status
);
174 Reads an 8-bit I/O port.
176 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
177 This function must guarantee that all I/O read and write operations are
180 If 8-bit I/O port operations are not supported, then ASSERT().
182 @param Port The I/O port to read.
184 @return The value read.
193 return (UINT8
)IoReadWorker (Port
, SMM_IO_UINT8
);
197 Writes an 8-bit I/O port.
199 Writes the 8-bit I/O port specified by Port with the value specified by Value
200 and returns Value. This function must guarantee that all I/O read and write
201 operations are serialized.
203 If 8-bit I/O port operations are not supported, then ASSERT().
205 @param Port The I/O port to write.
206 @param Value The value to write to the I/O port.
208 @return The value written the I/O port.
218 return (UINT8
)IoWriteWorker (Port
, SMM_IO_UINT8
, Value
);
222 Reads a 16-bit I/O port.
224 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
225 This function must guarantee that all I/O read and write operations are
228 If Port is not aligned on a 16-bit boundary, then ASSERT().
230 If 16-bit I/O port operations are not supported, then ASSERT().
232 @param Port The I/O port to read.
234 @return The value read.
244 // Make sure Port is aligned on a 16-bit boundary.
246 ASSERT ((Port
& 1) == 0);
247 return (UINT16
)IoReadWorker (Port
, SMM_IO_UINT16
);
251 Writes a 16-bit I/O port.
253 Writes the 16-bit I/O port specified by Port with the value specified by Value
254 and returns Value. This function must guarantee that all I/O read and write
255 operations are serialized.
257 If Port is not aligned on a 16-bit boundary, then ASSERT().
259 If 16-bit I/O port operations are not supported, then ASSERT().
261 @param Port The I/O port to write.
262 @param Value The value to write to the I/O port.
264 @return The value written the I/O port.
275 // Make sure Port is aligned on a 16-bit boundary.
277 ASSERT ((Port
& 1) == 0);
278 return (UINT16
)IoWriteWorker (Port
, SMM_IO_UINT16
, Value
);
282 Reads a 32-bit I/O port.
284 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
285 This function must guarantee that all I/O read and write operations are
288 If Port is not aligned on a 32-bit boundary, then ASSERT().
290 If 32-bit I/O port operations are not supported, then ASSERT().
292 @param Port The I/O port to read.
294 @return The value read.
304 // Make sure Port is aligned on a 32-bit boundary.
306 ASSERT ((Port
& 3) == 0);
307 return (UINT32
)IoReadWorker (Port
, SMM_IO_UINT32
);
311 Writes a 32-bit I/O port.
313 Writes the 32-bit I/O port specified by Port with the value specified by Value
314 and returns Value. This function must guarantee that all I/O read and write
315 operations are serialized.
317 If Port is not aligned on a 32-bit boundary, then ASSERT().
319 If 32-bit I/O port operations are not supported, then ASSERT().
321 @param Port The I/O port to write.
322 @param Value The value to write to the I/O port.
324 @return The value written the I/O port.
335 // Make sure Port is aligned on a 32-bit boundary.
337 ASSERT ((Port
& 3) == 0);
338 return (UINT32
)IoWriteWorker (Port
, SMM_IO_UINT32
, Value
);
342 Reads a 64-bit I/O port.
344 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
345 This function must guarantee that all I/O read and write operations are
348 If Port is not aligned on a 64-bit boundary, then ASSERT().
350 If 64-bit I/O port operations are not supported, then ASSERT().
352 @param Port The I/O port to read.
354 @return The value read.
364 // Make sure Port is aligned on a 64-bit boundary.
366 ASSERT ((Port
& 7) == 0);
367 return IoReadWorker (Port
, SMM_IO_UINT64
);
371 Writes a 64-bit I/O port.
373 Writes the 64-bit I/O port specified by Port with the value specified by Value
374 and returns Value. This function must guarantee that all I/O read and write
375 operations are serialized.
377 If Port is not aligned on a 64-bit boundary, then ASSERT().
379 If 64-bit I/O port operations are not supported, then ASSERT().
381 @param Port The I/O port to write.
382 @param Value The value to write to the I/O port.
384 @return The value written the I/O port.
395 // Make sure Port is aligned on a 64-bit boundary.
397 ASSERT ((Port
& 7) == 0);
398 return IoWriteWorker (Port
, SMM_IO_UINT64
, Value
);
402 Reads an 8-bit MMIO register.
404 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
405 returned. This function must guarantee that all MMIO read and write
406 operations are serialized.
408 If 8-bit MMIO register operations are not supported, then ASSERT().
410 @param Address The MMIO register to read.
412 @return The value read.
421 return (UINT8
)MmioReadWorker (Address
, SMM_IO_UINT8
);
425 Writes an 8-bit MMIO register.
427 Writes the 8-bit MMIO register specified by Address with the value specified
428 by Value and returns Value. This function must guarantee that all MMIO read
429 and write operations are serialized.
431 If 8-bit MMIO register operations are not supported, then ASSERT().
433 @param Address The MMIO register to write.
434 @param Value The value to write to the MMIO register.
444 return (UINT8
)MmioWriteWorker (Address
, SMM_IO_UINT8
, Value
);
448 Reads a 16-bit MMIO register.
450 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
451 returned. This function must guarantee that all MMIO read and write
452 operations are serialized.
454 If Address is not aligned on a 16-bit boundary, then ASSERT().
456 If 16-bit MMIO register operations are not supported, then ASSERT().
458 @param Address The MMIO register to read.
460 @return The value read.
470 // Make sure Address is aligned on a 16-bit boundary.
472 ASSERT ((Address
& 1) == 0);
473 return (UINT16
)MmioReadWorker (Address
, SMM_IO_UINT16
);
477 Writes a 16-bit MMIO register.
479 Writes the 16-bit MMIO register specified by Address with the value specified
480 by Value and returns Value. This function must guarantee that all MMIO read
481 and write operations are serialized.
483 If Address is not aligned on a 16-bit boundary, then ASSERT().
485 If 16-bit MMIO register operations are not supported, then ASSERT().
487 @param Address The MMIO register to write.
488 @param Value The value to write to the MMIO register.
499 // Make sure Address is aligned on a 16-bit boundary.
501 ASSERT ((Address
& 1) == 0);
502 return (UINT16
)MmioWriteWorker (Address
, SMM_IO_UINT16
, Value
);
506 Reads a 32-bit MMIO register.
508 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
509 returned. This function must guarantee that all MMIO read and write
510 operations are serialized.
512 If Address is not aligned on a 32-bit boundary, then ASSERT().
514 If 32-bit MMIO register operations are not supported, then ASSERT().
516 @param Address The MMIO register to read.
518 @return The value read.
528 // Make sure Address is aligned on a 32-bit boundary.
530 ASSERT ((Address
& 3) == 0);
531 return (UINT32
)MmioReadWorker (Address
, SMM_IO_UINT32
);
535 Writes a 32-bit MMIO register.
537 Writes the 32-bit MMIO register specified by Address with the value specified
538 by Value and returns Value. This function must guarantee that all MMIO read
539 and write operations are serialized.
541 If Address is not aligned on a 32-bit boundary, then ASSERT().
543 If 32-bit MMIO register operations are not supported, then ASSERT().
545 @param Address The MMIO register to write.
546 @param Value The value to write to the MMIO register.
557 // Make sure Address is aligned on a 32-bit boundary.
559 ASSERT ((Address
& 3) == 0);
560 return (UINT32
)MmioWriteWorker (Address
, SMM_IO_UINT32
, Value
);
564 Reads a 64-bit MMIO register.
566 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
567 returned. This function must guarantee that all MMIO read and write
568 operations are serialized.
570 If Address is not aligned on a 64-bit boundary, then ASSERT().
572 If 64-bit MMIO register operations are not supported, then ASSERT().
574 @param Address The MMIO register to read.
576 @return The value read.
586 // Make sure Address is aligned on a 64-bit boundary.
588 ASSERT ((Address
& 7) == 0);
589 return (UINT64
)MmioReadWorker (Address
, SMM_IO_UINT64
);
593 Writes a 64-bit MMIO register.
595 Writes the 64-bit MMIO register specified by Address with the value specified
596 by Value and returns Value. This function must guarantee that all MMIO read
597 and write operations are serialized.
599 If Address is not aligned on a 64-bit boundary, then ASSERT().
601 If 64-bit MMIO register operations are not supported, then ASSERT().
603 @param Address The MMIO register to write.
604 @param Value The value to write to the MMIO register.
615 // Make sure Address is aligned on a 64-bit boundary.
617 ASSERT ((Address
& 7) == 0);
618 return (UINT64
)MmioWriteWorker (Address
, SMM_IO_UINT64
, Value
);