123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- /*++
- Copyright (c) 2014 Minoca Corp. All Rights Reserved
- Module Name:
- dbgser.c
- Abstract:
- This module implements common debug device routines.
- Author:
- Evan Green 26-Feb-2014
- Environment:
- Kernel
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include "ueficore.h"
- #include <minoca/kernel/hmod.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- KSTATUS
- EfiCoreDebugDeviceReset (
- PVOID Context,
- ULONG BaudRate
- );
- KSTATUS
- EfiCoreDebugDeviceTransmit (
- PVOID Context,
- PVOID Data,
- ULONG Size
- );
- KSTATUS
- EfiCoreDebugDeviceReceive (
- PVOID Context,
- PVOID Data,
- PULONG Size
- );
- KSTATUS
- EfiCoreDebugDeviceGetStatus (
- PVOID Context,
- PBOOL ReceiveDataAvailable
- );
- VOID
- EfiCoreDebugDeviceDisconnect (
- PVOID Context
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // Store the EFI debug device description.
- //
- DEBUG_DEVICE_DESCRIPTION EfiDebugDevice = {
- DEBUG_DEVICE_DESCRIPTION_VERSION,
- {
- EfiCoreDebugDeviceReset,
- EfiCoreDebugDeviceTransmit,
- EfiCoreDebugDeviceReceive,
- EfiCoreDebugDeviceGetStatus,
- EfiCoreDebugDeviceDisconnect,
- },
- NULL,
- 1
- };
- //
- // ------------------------------------------------------------------ Functions
- //
- KSTATUS
- EfiCoreDebugDeviceReset (
- PVOID Context,
- ULONG BaudRate
- )
- /*++
- Routine Description:
- This routine initializes and resets a debug device, preparing it to send
- and receive data.
- Arguments:
- Context - Supplies the pointer to the port's context, provided by the
- hardware module upon initialization.
- BaudRate - Supplies the baud rate to set.
- Return Value:
- STATUS_SUCCESS on success.
- Other status codes on failure. The device will not be used if a failure
- status code is returned.
- --*/
- {
- EFI_STATUS EfiStatus;
- EfiStatus = EfiPlatformDebugDeviceReset(BaudRate);
- if (EfiStatus == EFI_UNSUPPORTED) {
- return STATUS_NOT_SUPPORTED;
- } else if (EFI_ERROR(EfiStatus)) {
- return STATUS_DEVICE_IO_ERROR;
- }
- return STATUS_SUCCESS;
- }
- KSTATUS
- EfiCoreDebugDeviceTransmit (
- PVOID Context,
- PVOID Data,
- ULONG Size
- )
- /*++
- Routine Description:
- This routine transmits data from the host out through the debug device.
- Arguments:
- Context - Supplies the pointer to the port's context, provided by the
- hardware module upon initialization.
- Data - Supplies a pointer to the data to write.
- Size - Supplies the size to write, in bytes.
- Return Value:
- STATUS_SUCCESS on success.
- STATUS_DEVICE_IO_ERROR if a device error occurred.
- --*/
- {
- EFI_STATUS EfiStatus;
- EfiStatus = EfiPlatformDebugDeviceTransmit(Data, Size);
- if (EFI_ERROR(EfiStatus)) {
- return STATUS_DEVICE_IO_ERROR;
- }
- return STATUS_SUCCESS;
- }
- KSTATUS
- EfiCoreDebugDeviceReceive (
- PVOID Context,
- PVOID Data,
- PULONG Size
- )
- /*++
- Routine Description:
- This routine receives incoming data from the debug device.
- Arguments:
- Context - Supplies the pointer to the port's context, provided by the
- hardware module upon initialization.
- Data - Supplies a pointer where the read data will be returned on success.
- Size - Supplies a pointer that on input contains the size of the receive
- buffer. On output, returns the number of bytes read.
- Return Value:
- STATUS_SUCCESS on success.
- STATUS_NO_DATA_AVAILABLE if there was no data to be read at the current
- time.
- STATUS_DEVICE_IO_ERROR if a device error occurred.
- --*/
- {
- EFI_STATUS EfiStatus;
- UINTN NaturalSize;
- NaturalSize = *Size;
- EfiStatus = EfiPlatformDebugDeviceReceive(Data, &NaturalSize);
- *Size = NaturalSize;
- if (EfiStatus == EFI_NOT_READY) {
- return STATUS_NO_DATA_AVAILABLE;
- } else if (EFI_ERROR(EfiStatus)) {
- return STATUS_DEVICE_IO_ERROR;
- }
- return STATUS_SUCCESS;
- }
- KSTATUS
- EfiCoreDebugDeviceGetStatus (
- PVOID Context,
- PBOOL ReceiveDataAvailable
- )
- /*++
- Routine Description:
- This routine returns the current device status.
- Arguments:
- Context - Supplies the pointer to the port's context, provided by the
- hardware module upon initialization.
- ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
- indicating whether or not receive data is available.
- Return Value:
- Status code.
- --*/
- {
- EFI_STATUS EfiStatus;
- BOOLEAN ReceiveAvailable;
- EfiStatus = EfiPlatformDebugDeviceGetStatus(&ReceiveAvailable);
- *ReceiveDataAvailable = ReceiveAvailable;
- if (EFI_ERROR(EfiStatus)) {
- return STATUS_DEVICE_IO_ERROR;
- }
- return STATUS_SUCCESS;
- }
- VOID
- EfiCoreDebugDeviceDisconnect (
- PVOID Context
- )
- /*++
- Routine Description:
- This routine disconnects a device, taking it offline.
- Arguments:
- Context - Supplies the pointer to the port's context, provided by the
- hardware module upon initialization.
- Return Value:
- None.
- --*/
- {
- EfiPlatformDebugDeviceDisconnect();
- return;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|