]> git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c
UefiPayloadPkg: Enhance UEFI payload for coreboot and Slim Bootloader
[mirror_edk2.git] / UefiPayloadPkg / Library / PlatformHookLib / PlatformHookLib.c
1 /** @file
2 Platform Hook Library instance for UART device.
3
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Base.h>
10 #include <Uefi/UefiBaseType.h>
11 #include <Library/PciLib.h>
12 #include <Library/PlatformHookLib.h>
13 #include <Library/BlParseLib.h>
14 #include <Library/PcdLib.h>
15
16 typedef struct {
17 UINT16 VendorId; ///< Vendor ID to match the PCI device. The value 0xFFFF terminates the list of entries.
18 UINT16 DeviceId; ///< Device ID to match the PCI device
19 UINT32 ClockRate; ///< UART clock rate. Set to 0 for default clock rate of 1843200 Hz
20 UINT64 Offset; ///< The byte offset into to the BAR
21 UINT8 BarIndex; ///< Which BAR to get the UART base address
22 UINT8 RegisterStride; ///< UART register stride in bytes. Set to 0 for default register stride of 1 byte.
23 UINT16 ReceiveFifoDepth; ///< UART receive FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes.
24 UINT16 TransmitFifoDepth; ///< UART transmit FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes.
25 UINT8 Reserved[2];
26 } PCI_SERIAL_PARAMETER;
27
28 /**
29 Performs platform specific initialization required for the CPU to access
30 the hardware associated with a SerialPortLib instance. This function does
31 not initialize the serial port hardware itself. Instead, it initializes
32 hardware devices that are required for the CPU to access the serial port
33 hardware. This function may be called more than once.
34
35 @retval RETURN_SUCCESS The platform specific initialization succeeded.
36 @retval RETURN_DEVICE_ERROR The platform specific initialization could not be completed.
37
38 **/
39 RETURN_STATUS
40 EFIAPI
41 PlatformHookSerialPortInitialize (
42 VOID
43 )
44 {
45 RETURN_STATUS Status;
46 UINT32 DeviceVendor;
47 PCI_SERIAL_PARAMETER *SerialParam;
48 SERIAL_PORT_INFO SerialPortInfo;
49
50 Status = ParseSerialInfo (&SerialPortInfo);
51 if (RETURN_ERROR (Status)) {
52 return Status;
53 }
54
55 if (SerialPortInfo.Type == PLD_SERIAL_TYPE_MEMORY_MAPPED) {
56 Status = PcdSetBoolS (PcdSerialUseMmio, TRUE);
57 } else { //IO
58 Status = PcdSetBoolS (PcdSerialUseMmio, FALSE);
59 }
60 if (RETURN_ERROR (Status)) {
61 return Status;
62 }
63 Status = PcdSet64S (PcdSerialRegisterBase, SerialPortInfo.BaseAddr);
64 if (RETURN_ERROR (Status)) {
65 return Status;
66 }
67
68 Status = PcdSet32S (PcdSerialRegisterStride, SerialPortInfo.RegWidth);
69 if (RETURN_ERROR (Status)) {
70 return Status;
71 }
72
73 Status = PcdSet32S (PcdSerialBaudRate, SerialPortInfo.Baud);
74 if (RETURN_ERROR (Status)) {
75 return Status;
76 }
77
78 Status = PcdSet64S (PcdUartDefaultBaudRate, SerialPortInfo.Baud);
79 if (RETURN_ERROR (Status)) {
80 return Status;
81 }
82
83 Status = PcdSet32S (PcdSerialClockRate, SerialPortInfo.InputHertz);
84 if (RETURN_ERROR (Status)) {
85 return Status;
86 }
87
88 if (SerialPortInfo.UartPciAddr >= 0x80000000) {
89 DeviceVendor = PciRead32 (SerialPortInfo.UartPciAddr & 0x0ffff000);
90 SerialParam = PcdGetPtr(PcdPciSerialParameters);
91 SerialParam->VendorId = (UINT16)DeviceVendor;
92 SerialParam->DeviceId = DeviceVendor >> 16;
93 SerialParam->ClockRate = SerialPortInfo.InputHertz;
94 SerialParam->RegisterStride = (UINT8)SerialPortInfo.RegWidth;
95 }
96
97 return RETURN_SUCCESS;
98 }