1d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel/** @file 2d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel Xen console SerialPortLib instance 3d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 4d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR> 5ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> 6d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 7d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel This program and the accompanying materials 8d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel are licensed and made available under the terms and conditions of the BSD License 9d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel which accompanies this distribution. The full text of the license may be found at 10d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel http://opensource.org/licenses/bsd-license.php 11d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 12d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 14d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 15d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel**/ 16d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 17d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <Base.h> 18d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <Uefi/UefiBaseType.h> 19d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 20d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <Library/BaseLib.h> 21d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <Library/SerialPortLib.h> 22d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <Library/XenHypercallLib.h> 23d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 24d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <IndustryStandard/Xen/io/console.h> 25d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <IndustryStandard/Xen/hvm/params.h> 26d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel#include <IndustryStandard/Xen/event_channel.h> 27d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 28d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// 29c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel// We can't use DebugLib due to a constructor dependency cycle between DebugLib 30c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel// and ourselves. 31c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel// 32c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel#define ASSERT(Expression) \ 33c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel do { \ 34c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel if (!(Expression)) { \ 35c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel CpuDeadLoop (); \ 36c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel } \ 37c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel } while (FALSE) 38c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 39c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel// 40d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// The code below expects these global variables to be mutable, even in the case 41d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// that we have been incorporated into SEC or PEIM phase modules (which is 42d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// allowed by our INF description). While this is a dangerous assumption to make 43d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// in general, it is actually fine for the Xen domU (guest) environment that 44d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// this module is intended for, as UEFI always executes from DRAM in that case. 45d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel// 46d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelSTATIC evtchn_send_t mXenConsoleEventChain; 47d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelSTATIC struct xencons_interface *mXenConsoleInterface; 48d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 49c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel/** 50c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Initialize the serial device hardware. 51c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 52c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If no initialization is required, then return RETURN_SUCCESS. 53c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If the serial device was successfully initialized, then return RETURN_SUCCESS. 54c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If the serial device could not be initialized, then return RETURN_DEVICE_ERROR. 55c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 56c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval RETURN_SUCCESS The serial device was initialized. 57c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval RETURN_DEVICE_ERROR The serial device could not be initialized. 58c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 59c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel**/ 60d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelRETURN_STATUS 61d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelEFIAPI 62d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelSerialPortInitialize ( 63d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel VOID 64d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel ) 65d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel{ 6648b3ff047929aa5bd4f94128c9a3ac04d6b3b31bLaszlo Ersek if (! XenHypercallIsAvailable ()) { 67c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel return RETURN_DEVICE_ERROR; 6848b3ff047929aa5bd4f94128c9a3ac04d6b3b31bLaszlo Ersek } 6948b3ff047929aa5bd4f94128c9a3ac04d6b3b31bLaszlo Ersek 70d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel if (!mXenConsoleInterface) { 71d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel mXenConsoleEventChain.port = (UINT32)XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_EVTCHN); 72d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel mXenConsoleInterface = (struct xencons_interface *)(UINTN) 73d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel (XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_PFN) << EFI_PAGE_SHIFT); 74d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 75d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel // 76d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel // No point in ASSERT'ing here as we won't be seeing the output 77d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel // 78d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel } 79d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel return RETURN_SUCCESS; 80d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel} 81d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 82d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel/** 83c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Write data from buffer to serial device. 84c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 85c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Writes NumberOfBytes data bytes from Buffer to the serial device. 86c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel The number of bytes actually written to the serial device is returned. 87c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If the return value is less than NumberOfBytes, then the write operation failed. 88c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If Buffer is NULL, then ASSERT(). 89c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If NumberOfBytes is zero, then return 0. 90d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 91c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @param Buffer Pointer to the data buffer to be written. 92c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @param NumberOfBytes Number of bytes to written to the serial device. 93d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 94c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval 0 NumberOfBytes is 0. 95c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval >0 The number of bytes written to the serial device. 96c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If this value is less than NumberOfBytes, then the write operation failed. 97d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 98d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel**/ 99d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelUINTN 100d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelEFIAPI 101d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelSerialPortWrite ( 102d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel IN UINT8 *Buffer, 103d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel IN UINTN NumberOfBytes 104d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel ) 105d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel{ 106d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel XENCONS_RING_IDX Consumer, Producer; 107d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel UINTN Sent; 108d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 109c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel ASSERT (Buffer != NULL); 110c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 111c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel if (NumberOfBytes == 0) { 112c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel return 0; 113c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel } 114c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 115d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel if (!mXenConsoleInterface) { 116d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel return 0; 117d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel } 118d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 119c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Sent = 0; 120c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel do { 121c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Consumer = mXenConsoleInterface->out_cons; 122c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Producer = mXenConsoleInterface->out_prod; 123d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 124c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel MemoryFence (); 125d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 126c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel while (Sent < NumberOfBytes && ((Producer - Consumer) < sizeof (mXenConsoleInterface->out))) 127c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel mXenConsoleInterface->out[MASK_XENCONS_IDX(Producer++, mXenConsoleInterface->out)] = Buffer[Sent++]; 128d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 129c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel MemoryFence (); 130d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 131c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel mXenConsoleInterface->out_prod = Producer; 132d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 133d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain); 134c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 135c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel } while (Sent < NumberOfBytes); 136d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 137d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel return Sent; 138d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel} 139d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 140d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel/** 141c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Read data from serial device and save the datas in buffer. 142c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 143c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Reads NumberOfBytes data bytes from a serial device into the buffer 144c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel specified by Buffer. The number of bytes actually read is returned. 145c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If Buffer is NULL, then ASSERT(). 146c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel If NumberOfBytes is zero, then return 0. 147d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 148c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @param Buffer Pointer to the data buffer to store the data read from the serial device. 149c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @param NumberOfBytes Number of bytes which will be read. 150d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 151c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval 0 Read data failed, no data is to be read. 152c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval >0 Actual number of bytes read from serial device. 153d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 154d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel**/ 155d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelUINTN 156d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelEFIAPI 157d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelSerialPortRead ( 158d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel OUT UINT8 *Buffer, 159d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel IN UINTN NumberOfBytes 160d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel) 161d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel{ 162d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel XENCONS_RING_IDX Consumer, Producer; 163d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel UINTN Received; 164d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 165c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel ASSERT (Buffer != NULL); 166c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 167c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel if (NumberOfBytes == 0) { 168c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel return 0; 169c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel } 170c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel 171d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel if (!mXenConsoleInterface) { 172d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel return 0; 173d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel } 174d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 175d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel Consumer = mXenConsoleInterface->in_cons; 176d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel Producer = mXenConsoleInterface->in_prod; 177d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 178d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel MemoryFence (); 179d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 180d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel Received = 0; 181d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel while (Received < NumberOfBytes && Consumer < Producer) 182d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel Buffer[Received++] = mXenConsoleInterface->in[MASK_XENCONS_IDX(Consumer++, mXenConsoleInterface->in)]; 183d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 184d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel MemoryFence (); 185d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 186d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel mXenConsoleInterface->in_cons = Consumer; 187d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 188d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain); 189d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 190d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel return Received; 191d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel} 192d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 193d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel/** 194c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel Polls a serial device to see if there is any data waiting to be read. 195d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 196c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval TRUE Data is waiting to be read from the serial device. 197c6d2972645187f5829cd8a3903de73710752e3f0Ard Biesheuvel @retval FALSE There is no data waiting to be read from the serial device. 198d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel 199d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel**/ 200d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelBOOLEAN 201d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelEFIAPI 202d401a487416926594f5176cb8acf75eed4bea0f0Ard BiesheuvelSerialPortPoll ( 203d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel VOID 204d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel ) 205d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel{ 206d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel return mXenConsoleInterface && 207d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel mXenConsoleInterface->in_cons != mXenConsoleInterface->in_prod; 208d401a487416926594f5176cb8acf75eed4bea0f0Ard Biesheuvel} 209ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 210ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng/** 211ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng Sets the control bits on a serial device. 212ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 213ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param Control Sets the bits of Control that are settable. 214ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 215ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_SUCCESS The new control bits were set on the serial device. 216ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_UNSUPPORTED The serial device does not support this operation. 217ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. 218ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 219ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng**/ 220ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengRETURN_STATUS 221ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengEFIAPI 222ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengSerialPortSetControl ( 223ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN UINT32 Control 224ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng ) 225ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng{ 226ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng return RETURN_UNSUPPORTED; 227ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng} 228ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 229ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng/** 230ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng Retrieve the status of the control bits on a serial device. 231ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 232ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param Control A pointer to return the current control signals from the serial device. 233ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 234ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_SUCCESS The control bits were read from the serial device. 235ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_UNSUPPORTED The serial device does not support this operation. 236ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. 237ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 238ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng**/ 239ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengRETURN_STATUS 240ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengEFIAPI 241ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengSerialPortGetControl ( 242ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng OUT UINT32 *Control 243ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng ) 244ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng{ 245ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng if (!mXenConsoleInterface) { 246ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng return RETURN_UNSUPPORTED; 247ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng } 248ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 249ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng *Control = 0; 250ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng if (!SerialPortPoll ()) { 251ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY; 252ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng } 253ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng return RETURN_SUCCESS; 254ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng} 255ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 256ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng/** 257ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, 258ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng data bits, and stop bits on a serial device. 259ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 260ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param BaudRate The requested baud rate. A BaudRate value of 0 will use the 261ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng device's default interface speed. 262ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng On output, the value actually set. 263ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the 264ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng serial interface. A ReceiveFifoDepth value of 0 will use 265ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng the device's default FIFO depth. 266ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng On output, the value actually set. 267ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param Timeout The requested time out for a single character in microseconds. 268ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng This timeout applies to both the transmit and receive side of the 269ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng interface. A Timeout value of 0 will use the device's default time 270ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng out value. 271ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng On output, the value actually set. 272ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param Parity The type of parity to use on this serial device. A Parity value of 273ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng DefaultParity will use the device's default parity value. 274ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng On output, the value actually set. 275ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param DataBits The number of data bits to use on the serial device. A DataBits 276ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng vaule of 0 will use the device's default data bit setting. 277ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng On output, the value actually set. 278ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @param StopBits The number of stop bits to use on this serial device. A StopBits 279ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng value of DefaultStopBits will use the device's default number of 280ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng stop bits. 281ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng On output, the value actually set. 282ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 283ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_SUCCESS The new attributes were set on the serial device. 284ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_UNSUPPORTED The serial device does not support this operation. 285ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value. 286ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. 287ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 288ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng**/ 289ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengRETURN_STATUS 290ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengEFIAPI 291ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star ZengSerialPortSetAttributes ( 292ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN OUT UINT64 *BaudRate, 293ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN OUT UINT32 *ReceiveFifoDepth, 294ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN OUT UINT32 *Timeout, 295ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN OUT EFI_PARITY_TYPE *Parity, 296ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN OUT UINT8 *DataBits, 297ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng IN OUT EFI_STOP_BITS_TYPE *StopBits 298ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng ) 299ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng{ 300ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng return RETURN_UNSUPPORTED; 301ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng} 302ece2806d02a5a5fd863bf0911af0b795ddacf3b0Star Zeng 303