From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web12.83.1573079959653773655 for ; Wed, 06 Nov 2019 14:39:19 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: nathaniel.l.desimone@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2019 14:39:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,275,1569308400"; d="scan'208";a="200849626" Received: from orsmsx104.amr.corp.intel.com ([10.22.225.131]) by fmsmga008.fm.intel.com with ESMTP; 06 Nov 2019 14:39:19 -0800 Received: from orsmsx116.amr.corp.intel.com (10.22.240.14) by ORSMSX104.amr.corp.intel.com (10.22.225.131) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 6 Nov 2019 14:39:18 -0800 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.28]) by ORSMSX116.amr.corp.intel.com ([169.254.7.79]) with mapi id 14.03.0439.000; Wed, 6 Nov 2019 14:39:18 -0800 From: "Nate DeSimone" To: "Agyeman, Prince" , "devel@edk2.groups.io" CC: "Kubacki, Michael A" , "Chiu, Chasel" Subject: Re: [edk2-platforms] [Patch v2 6/9] BoardModulePkg: Add Ps2 Keyboard Library Thread-Topic: [edk2-platforms] [Patch v2 6/9] BoardModulePkg: Add Ps2 Keyboard Library Thread-Index: AQHVlEEq1mprn/tZoE6VJ/3Q8Xfa0ad+vTfQ Date: Wed, 6 Nov 2019 22:39:18 +0000 Message-ID: <02A34F284D1DA44BB705E61F7180EF0AB5BA472E@ORSMSX113.amr.corp.intel.com> References: <20191106012603.4724-1-prince.agyeman@intel.com> <20191106012603.4724-7-prince.agyeman@intel.com> In-Reply-To: <20191106012603.4724-7-prince.agyeman@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZTFjNWJhODItODBjNy00YTRmLTlmNDEtZWQyYzQ5MjQ5MmRiIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiWjR1NEdwSXRyNDMwdUJZYXdMYnEwWU14Wm5SdTFKdzl2UHpvOHhmaTlMQWpOS1pUbEF6M09OZFluc2JESHNkNiJ9 x-ctpclassification: CTP_NT x-originating-ip: [10.22.254.139] MIME-Version: 1.0 Return-Path: nathaniel.l.desimone@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Nate DeSimone -----Original Message----- From: Agyeman, Prince =20 Sent: Tuesday, November 5, 2019 5:26 PM To: devel@edk2.groups.io Cc: Kubacki, Michael A ; Chiu, Chasel ; Desimone, Nathaniel L Subject: [edk2-platforms] [Patch v2 6/9] BoardModulePkg: Add Ps2 Keyboard L= ibrary Added a generic Ps2 keyboard library that adds ps2 device path to ConIn and ConInDev Uefi variables Cc: Michael Kubacki Cc: Chasel Chiu Cc: Nate DeSimone Signed-off-by: Prince Agyeman --- .../Intel/BoardModulePkg/BoardModulePkg.dsc | 1 + .../Library/BdsPs2KbcLib/BdsPs2KbcLib.c | 202 ++++++++++++++++++ .../Library/BdsPs2KbcLib/BdsPs2KbcLib.h | 65 ++++++ .../Library/BdsPs2KbcLib/BdsPs2KbcLib.inf | 38 ++++ 4 files changed, 306 insertions(+) create mode 100644 Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsP= s2KbcLib.c create mode 100644 Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsP= s2KbcLib.h create mode 100644 Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsP= s2KbcLib.inf diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc b/Platform/In= tel/BoardModulePkg/BoardModulePkg.dsc index 5af26eb97e..bcc2dfbfeb 100644 --- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc +++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc @@ -88,3 +88,4 @@ BoardModulePkg/Library/BiosIdLib/PeiBiosIdLib.inf =20 BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaI= nfoLib.inf + BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.inf diff --git a/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLi= b.c b/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.c new file mode 100644 index 0000000000..3a885e0d71 --- /dev/null +++ b/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.c @@ -0,0 +1,202 @@ +/** @file + Main file for Ps2 keyboard controller library. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BdsPs2KbcLib.h" + +GLOBAL_REMOVE_IF_UNREFERENCED PLATFORM_KEYBOARD_DEVICE_PATH =20 +gKeyboardDevicePath =3D { + gPciRootBridge, + { + { + HARDWARE_DEVICE_PATH, + HW_PCI_DP, + { + (UINT8) (sizeof (PCI_DEVICE_PATH)), + (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) + } + }, + 0, // Function, patched in EnumPs2Keyboard + 0 // Device, patched in EnumPs2Keyboard + }, + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) + } + }, + EISA_PNP_ID(0x0303), + 0 + }, + gEndEntire +}; + +/** + Check if PS2 keyboard is conntected, by sending ECHO command. + @retval TRUE if connected FALSE otherwise +**/ +BOOLEAN +DetectPs2Keyboard ( + VOID + ) +{ + UINT32 TimeOut; + UINT32 RegEmptied; + UINT8 Data; + UINT32 SumTimeOut; + BOOLEAN FoundPs2Kbc; + + TimeOut =3D 0; + RegEmptied =3D 0; + FoundPs2Kbc =3D FALSE; + + // + // Wait for input buffer empty + // + for (TimeOut =3D 0; TimeOut < PS2_KEYBOARD_TIMEOUT; TimeOut +=3D 30) { + if ((IoRead8 (KEYBOARD_8042_STATUS_REGISTER) & 0x02) =3D=3D 0) { + FoundPs2Kbc =3D TRUE; + break; + } + MicroSecondDelay (30); + } + + if (FoundPs2Kbc =3D=3D FALSE) { + return FALSE; + } + + // + // Send echo command + // + IoWrite8 (KEYBOARD_8042_DATA_REGISTER, KBC_INPBUF_VIA60_KBECHO); + + // + // Init variables + // + FoundPs2Kbc =3D FALSE; + TimeOut =3D 0; + SumTimeOut =3D 0; + Data =3D 0; + + // + // Read from 8042 (multiple times if needed) // until the expected=20 + value appears // use SumTimeOut to control the iteration // while=20 + (1) { + // + // Perform a read + // + for (TimeOut =3D 0; TimeOut < PS2_KEYBOARD_TIMEOUT; TimeOut +=3D 30) { + if (IoRead8 (KEYBOARD_8042_STATUS_REGISTER) & 0x01) { + Data =3D IoRead8 (KEYBOARD_8042_DATA_REGISTER); + break; + } + MicroSecondDelay (30); + } + + SumTimeOut +=3D TimeOut; + + if (Data =3D=3D KBC_INPBUF_VIA60_KBECHO) { + FoundPs2Kbc =3D TRUE; + break; + } + + if (SumTimeOut >=3D PS2_KEYBOARD_WAITFORVALUE_TIMEOUT) { + break; + } + } + return FoundPs2Kbc; +} + +/** + Check if PS2 keyboard is conntected. If the result of first time is + error, it will retry again. + @retval TRUE if connected FALSE otherwise +**/ +BOOLEAN +IsPs2KeyboardConnected ( + VOID + ) +{ + BOOLEAN Result; + Result =3D DetectPs2Keyboard (); + + if (Result =3D=3D FALSE) { + // + // If there is no ps2 keyboard detected for the 1st time, retry again. + // + Result =3D DetectPs2Keyboard (); + } + return Result; +} + + +/** + Updates the ConIn variable with Ps2 Keyboard device path, + if it doesn't already exists in ConIn and ConInDev **/ VOID=20 +AddPs2Keyboard ( + VOID + ) +{ + SIO_PCI_ISA_BRIDGE_DEVICE_INFO *SioIsaInfo; + + DEBUG ((DEBUG_INFO, "[AddPs2Keyboard]\n")); + + SioIsaInfo =3D (SIO_PCI_ISA_BRIDGE_DEVICE_INFO*) FixedPcdGetPtr=20 + (PcdSuperIoPciIsaBridgeDevice); + + // + // patch IsaBridge device and and function // =20 + gKeyboardDevicePath.IsaBridge.Device =3D SioIsaInfo->Device; =20 + gKeyboardDevicePath.IsaBridge.Function =3D SioIsaInfo->Funtion; + + // + // Append Ps2 Keyboard into "ConIn" + // + EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL=20 + *) &gKeyboardDevicePath, NULL); + + // + // Append Ps2 Keyboard into "ConInDev" + // + EfiBootManagerUpdateConsoleVariable (ConInDev,=20 +(EFI_DEVICE_PATH_PROTOCOL *) &gKeyboardDevicePath, NULL); } + + +/** + Constructor for the Ps2 keyboard controller library. + + @param ImageHandle the image handle of the process + @param SystemTable the EFI System Table pointer + + @retval EFI_SUCCESS the shell command handlers were installed suc= essfully + @retval EFI_UNSUPPORTED the shell level required was not found. +**/ +EFI_STATUS +EFIAPI +BdsPs2KbcLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + UINT8 Ps2KbMsEnable; + + Ps2KbMsEnable =3D PcdGet8 (PcdPs2KbMsEnable); + + if (Ps2KbMsEnable =3D=3D 0x1 + && IsPs2KeyboardConnected()) + { + // add ps2 device path to ConIn and ConInDev + AddPs2Keyboard (); + } + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLi= b.h b/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.h new file mode 100644 index 0000000000..d9a27e6681 --- /dev/null +++ b/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.h @@ -0,0 +1,65 @@ +/** @file + Header file for the Ps2 keyboard controller library. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _PS2_KBC_LIB_H +#define _PS2_KBC_LIB_H + +#include +#include +#include +#include +#include +#include +#include + +// +// Below is the platform console device path // typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH IsaBridge; + ACPI_HID_DEVICE_PATH Keyboard; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_KEYBOARD_DEVICE_PATH; + +typedef struct { + UINT8 Segment; + UINT8 Bus; + UINT8 Device; + UINT8 Funtion; +} SIO_PCI_ISA_BRIDGE_DEVICE_INFO; + +#define gPciRootBridge \ + { \ + { \ + ACPI_DEVICE_PATH, \ + ACPI_DP, \ + { \ + (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \ + (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \ + }, \ + }, \ + EISA_PNP_ID (0x0A03), \ + 0 \ + } + +#define gEndEntire \ + { \ + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, {=20 +END_DEVICE_PATH_LENGTH, 0 } \ + } + +#define KBC_INPBUF_VIA60_KBECHO 0xEE +#define KEYBOARD_8042_DATA_REGISTER 0x60 +#define KEYBOARD_8042_STATUS_REGISTER 0x64 + +#define PS2_KEYBOARD_TIMEOUT 65536 // 0.07s +#define PS2_KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s +#define PS2_KEYBOARD_KBEN 0xF4 +#define PS2_KEYBOARD_CMDECHO_ACK 0xFA + +#endif diff --git a/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLi= b.inf b/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.inf new file mode 100644 index 0000000000..e00638daa7 --- /dev/null +++ b/Platform/Intel/BoardModulePkg/Library/BdsPs2KbcLib/BdsPs2KbcLib.in +++ f @@ -0,0 +1,38 @@ +## @file +# Component information file for Ps2 keyboard controller library # #=20 +Copyright (c) 2019, Intel Corporation. All rights reserved.
# #=20 +SPDX-License-Identifier: BSD-2-Clause-Patent # ## [Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D BdsPs2KbcLib + FILE_GUID =3D E94EA52E-E84C-42E7-B863-EA1327EFA265 + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 1.2 + LIBRARY_CLASS =3D NULL|UEFI_DRIVER + CONSTRUCTOR =3D BdsPs2KbcLibConstructor + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + BoardModulePkg/BoardModulePkg.dec + +[Sources] + BdsPs2KbcLib.c + BdsPs2KbcLib.h + +[LibraryClasses] + DevicePathLib + DebugLib + IoLib + UefiDriverEntryPoint + UefiBootManagerLib + UefiLib + TimerLib + +[Pcd] + gBoardModulePkgTokenSpaceGuid.PcdPs2KbMsEnable + gBoardModulePkgTokenSpaceGuid.PcdSuperIoPciIsaBridgeDevice -- 2.19.1.windows.1