public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abdul Lateef Attar via groups.io" <AbdulLateef.Attar=amd.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>,
	Abner Chang <abner.chang@amd.com>,
	Paul Grimes <paul.grimes@amd.com>
Subject: [edk2-devel] [PATCH 3/6] AmdPlatformPkg: Implements SerialPortLib for simulator
Date: Tue, 14 May 2024 13:45:45 +0530	[thread overview]
Message-ID: <2338cae1522b5141f145a738a4f11b6ea0469967.1715674395.git.AbdulLateef.Attar@amd.com> (raw)
In-Reply-To: <cover.1715674395.git.AbdulLateef.Attar@amd.com>

Implements SerialPortLib library class for simulator.
It redirects the output to the port 80.

Cc: Abner Chang <abner.chang@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
 .../AMD/AmdPlatformPkg/AmdPlatformPkg.dsc     |   3 +-
 .../SimulatorSerialPortLibPort80.c            | 208 ++++++++++++++++++
 .../SimulatorSerialPortLibPort80.inf          |  31 +++
 3 files changed, 241 insertions(+), 1 deletion(-)
 create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.c
 create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.inf

diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
index e39ad93c83..2c959fb614 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
@@ -48,6 +48,7 @@
 
 [Components]
   AmdPlatformPkg/Library/BaseAlwaysFalseDepexLib/BaseAlwaysFalseDepexLib.inf
+  AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.inf
   AmdPlatformPkg/Universal/LogoDxe/JpegLogoDxe.inf                                           # Server platform JPEG logo driver
   AmdPlatformPkg/Universal/LogoDxe/LogoDxe.inf                                               # Server platfrom Bitmap logo driver
-  AmdPlatformPkg/Universal/LogoDxe/S3LogoDxe.inf
+  AmdPlatformPkg/Universal/LogoDxe/S3LogoDxe.inf
\ No newline at end of file
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.c b/Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.c
new file mode 100644
index 0000000000..35842ecddc
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.c
@@ -0,0 +1,208 @@
+/** @file
+  AMD simulator port80 serial port library functions.
+
+  Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/IoLib.h>
+#include <Library/SerialPortLib.h>
+#include <Uefi.h>
+
+/**
+  Initialize the serial device hardware.
+
+  If no initialization is required, then return RETURN_SUCCESS.
+  If the serial device was successfully initialized, then return RETURN_SUCCESS.
+  If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
+
+  @retval RETURN_SUCCESS        The serial device was initialized.
+  @retval RETURN_DEVICE_ERROR   The serial device could not be initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+  VOID
+  )
+{
+  // Chipset defaults properly decoding port 80 to eSPI
+  return EFI_SUCCESS;
+}
+
+/**
+  Write data from buffer to serial device.
+
+  Writes NumberOfBytes data bytes from Buffer to the serial device.
+  The number of bytes actually written to the serial device is returned.
+  If the return value is less than NumberOfBytes, then the write operation failed.
+  If Buffer is NULL, then ASSERT().
+  If NumberOfBytes is zero, then return 0.
+
+  @param[in]  Buffer           The pointer to the data buffer to be written.
+  @param[in]  NumberOfBytes    The number of bytes to written to the serial device.
+
+  @retval 0                NumberOfBytes is 0.
+  @retval >0               The number of bytes written to the serial device.
+                           If this value is less than NumberOfBytes, then the read operation failed.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+  IN UINT8  *Buffer,
+  IN UINTN  NumberOfBytes
+  )
+{
+  UINTN  ByteCount;
+
+  if ((Buffer == NULL) || (NumberOfBytes == 0)) {
+    return 0;
+  }
+
+  IoWrite32 (0x80, SIGNATURE_32 ('R', 'T', 'S', '_'));
+
+  ByteCount = NumberOfBytes;
+  for ( ; ByteCount != 0; ByteCount--, Buffer++) {
+    IoWrite8 (0x80, *Buffer);
+  }
+
+  IoWrite32 (0x80, SIGNATURE_32 ('D', 'N', 'E', '_'));
+
+  return NumberOfBytes;
+}
+
+/**
+  Read data from serial device and save the data in buffer.
+
+  Reads NumberOfBytes data bytes from a serial device into the buffer
+  specified by Buffer. The number of bytes actually read is returned.
+  If the return value is less than NumberOfBytes, then the rest operation failed.
+  If Buffer is NULL, then ASSERT().
+  If NumberOfBytes is zero, then return 0.
+
+  @param[out]  Buffer           The pointer to the data buffer to store the data read from the serial device.
+  @param[in]   NumberOfBytes    The number of bytes which will be read.
+
+  @retval 0                Read data failed; No data is to be read.
+  @retval >0               The actual number of bytes read from serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+  OUT UINT8  *Buffer,
+  IN  UINTN  NumberOfBytes
+  )
+{
+  return 0;
+}
+
+/**
+  Polls a serial device to see if there is any data waiting to be read.
+
+  Polls a serial device to see if there is any data waiting to be read.
+  If there is data waiting to be read from the serial device, then TRUE is returned.
+  If there is no data waiting to be read from the serial device, then FALSE is returned.
+
+  @retval TRUE             Data is waiting to be read from the serial device.
+  @retval FALSE            There is no data waiting to be read from the serial device.
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+  VOID
+  )
+{
+  return FALSE;
+}
+
+/**
+  Sets the control bits on a serial device.
+
+  @param[in] Control                Sets the bits of Control that are settable.
+
+  @retval RETURN_SUCCESS        The new control bits were set on the serial device.
+  @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
+  @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetControl (
+  IN UINT32  Control
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Retrieve the status of the control bits on a serial device.
+
+  @param[out] Control                A pointer to return the current control signals from the serial device.
+
+  @retval RETURN_SUCCESS        The control bits were read from the serial device.
+  @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
+  @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortGetControl (
+  OUT UINT32  *Control
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
+  data bits, and stop bits on a serial device.
+
+  @param[in,out] BaudRate          The requested baud rate. A BaudRate value of 0 will use the
+                                   device's default interface speed.
+                                   On output, the value actually set.
+  @param[in,out] ReceiveFifoDepth  The requested depth of the FIFO on the receive side of the
+                                   serial interface. A ReceiveFifoDepth value of 0 will use
+                                   the device's default FIFO depth.
+                                   On output, the value actually set.
+  @param[in,out] Timeout           The requested time out for a single character in microseconds.
+                                   This timeout applies to both the transmit and receive side of the
+                                   interface. A Timeout value of 0 will use the device's default time
+                                   out value.
+                                   On output, the value actually set.
+  @param[in,out] Parity            The type of parity to use on this serial device. A Parity value of
+                                   DefaultParity will use the device's default parity value.
+                                   On output, the value actually set.
+  @param[in,out] DataBits          The number of data bits to use on the serial device. A DataBits
+                                   value of 0 will use the device's default data bit setting.
+                                   On output, the value actually set.
+  @param[in,out] StopBits          The number of stop bits to use on this serial device. A StopBits
+                                   value of DefaultStopBits will use the device's default number of
+                                   stop bits.
+                                   On output, the value actually set.
+
+  @retval RETURN_SUCCESS            The new attributes were set on the serial device.
+  @retval RETURN_UNSUPPORTED        The serial device does not support this operation.
+  @retval RETURN_INVALID_PARAMETER  One or more of the attributes has an unsupported value.
+  @retval RETURN_DEVICE_ERROR       The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetAttributes (
+  IN OUT UINT64              *BaudRate,
+  IN OUT UINT32              *ReceiveFifoDepth,
+  IN OUT UINT32              *Timeout,
+  IN OUT EFI_PARITY_TYPE     *Parity,
+  IN OUT UINT8               *DataBits,
+  IN OUT EFI_STOP_BITS_TYPE  *StopBits
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.inf b/Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.inf
new file mode 100644
index 0000000000..61e2d77f46
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SimulatorSerialPortLibPort80/SimulatorSerialPortLibPort80.inf
@@ -0,0 +1,31 @@
+## @file
+#  Simlator port80 instance of serial port library functions.
+#
+#  Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = SimulatorSerialPortLibPort80
+  FILE_GUID                      = 35217E20-489E-64F9-4E42-1EAFABE0A86F
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = SerialPortLib
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64
+#
+
+[Sources]
+  SimulatorSerialPortLibPort80.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
+  IoLib
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#118885): https://edk2.groups.io/g/devel/message/118885
Mute This Topic: https://groups.io/mt/106090923/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2024-05-14  8:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14  8:15 [edk2-devel] [PATCH 0/6] AmdPlatformPkg: Adds board independent modules Abdul Lateef Attar via groups.io
2024-05-14  8:15 ` [edk2-devel] [PATCH 1/6] AmdPlatformPkg: Adds LogoDxe driver Abdul Lateef Attar via groups.io
2024-05-14  8:15 ` [edk2-devel] [PATCH 2/6] AmdPlatformPkg: Adds BaseAlwaysFalseDepexLib Library Abdul Lateef Attar via groups.io
2024-05-14  8:15 ` Abdul Lateef Attar via groups.io [this message]
2024-05-14  8:15 ` [edk2-devel] [PATCH 4/6] AmdPlatformPkg: Adds PlatformSocLib library class Abdul Lateef Attar via groups.io
2024-05-14  8:15 ` [edk2-devel] [PATCH 5/6] AmdPlatformPkg: Adds AmdConfigRouting driver Abdul Lateef Attar via groups.io
2024-05-14  8:15 ` [edk2-devel] [PATCH 6/6] AmdPlatformPkg: Adds SecureBootDefaultKeysInit driver Abdul Lateef Attar via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2338cae1522b5141f145a738a4f11b6ea0469967.1715674395.git.AbdulLateef.Attar@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox