[FREELDR] Partially implement docking station detection (#4751)

This commit is contained in:
Dmitry Borisov 2022-10-19 20:48:27 +06:00 committed by GitHub
parent 774c3b3c92
commit 9d06e79373
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 175 additions and 33 deletions

View file

@ -1,21 +1,9 @@
/*
* FreeLoader
* Copyright (C) 2003 Eric Kohl
* Copyright (C) 2011 Timo Kreuzer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* PROJECT: FreeLoader
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: PnP BIOS helper functions
* COPYRIGHT: Copyright 2003 Eric Kohl <eric.kohl@reactos.org>
* Copyright 2011 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <asm.inc>
@ -170,5 +158,38 @@ PnpBiosGetDeviceNode:
ret
/*
* U32 PnpBiosGetDockStationInformation(U8 *DockingStationInfo<rcx>);
*
* RETURNS:
*/
PUBLIC PnpBiosGetDockStationInformation
PnpBiosGetDockStationInformation:
/* Convert pointer to info structure to segment/offset */
mov rax, rcx
shr eax, 4
mov word ptr [BSS_PnpBiosBufferSegment], ax
mov rax, rcx
and eax, HEX(0f)
mov word ptr [BSS_PnpBiosBufferOffset], ax
/* Save registers */
push rcx
push rbx
/* Call the real mode function */
mov bx, FNID_PnpBiosGetDockStationInformation
call CallRealMode
/* Restore registers */
pop rbx
pop rcx
mov eax, dword ptr [BSS_PnpResult]
ret
END
/* EOF */

View file

@ -177,6 +177,63 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize)
return PartialResourceList;
}
static
VOID
DetectDockingStation(
_Inout_ PCONFIGURATION_COMPONENT_DATA BusKey)
{
PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
PCONFIGURATION_COMPONENT_DATA PeripheralKey;
PDOCKING_STATE_INFORMATION DockingState;
ULONG Size, Result;
Result = PnpBiosGetDockStationInformation(DiskReadBuffer);
/* Build full device descriptor */
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
sizeof(DOCKING_STATE_INFORMATION);
PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
if (PartialResourceList == NULL)
{
ERR("Failed to allocate resource descriptor\n");
return;
}
/* Initialize resource descriptor */
RtlZeroMemory(PartialResourceList, Size);
PartialResourceList->Version = 0;
PartialResourceList->Revision = 0;
PartialResourceList->Count = 1;
/* Set device specific data */
PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
PartialDescriptor->Flags = 0;
PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(DOCKING_STATE_INFORMATION);
DockingState = (PDOCKING_STATE_INFORMATION)&PartialResourceList->PartialDescriptors[1];
DockingState->ReturnCode = Result;
if (Result == 0)
{
/* FIXME: Add more device specific data */
ERR("FIXME: System docked\n");
}
/* Create controller key */
FldrCreateComponentKey(BusKey,
PeripheralClass,
DockingInformation,
0,
0,
0xFFFFFFFF,
"Docking State Information",
PartialResourceList,
Size,
&PeripheralKey);
}
static
VOID
DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
@ -308,6 +365,8 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Size,
&BusKey);
DetectDockingStation(BusKey);
(*BusNumber)++;
}

View file

@ -1,20 +1,8 @@
/*
* FreeLoader
* Copyright (C) 2003 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* PROJECT: FreeLoader
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: PnP BIOS helper functions
* COPYRIGHT: Copyright 2003 Eric Kohl <eric.kohl@reactos.org>
*/
#include <asm.inc>
@ -179,6 +167,43 @@ _PnpBiosGetDeviceNode:
ret
/*
* U32 PnpBiosGetDockStationInformation(U8 *DockingStationInfo);
*
* RETURNS:
*/
PUBLIC _PnpBiosGetDockStationInformation
_PnpBiosGetDockStationInformation:
push ebp
mov ebp, esp
pusha
push es
/* Convert pointer to info structure to segment/offset */
mov eax, [ebp + 8]
shr eax, 4
and eax, HEX(0f000)
mov word ptr ds:[BSS_PnpBiosBufferSegment], ax
mov eax, [ebp + 8]
and eax, HEX(0ffff)
mov word ptr ds:[BSS_PnpBiosBufferOffset], ax
mov bx, FNID_PnpBiosGetDockStationInformation
call i386CallRealMode
pop es
popa
mov esp, ebp
pop ebp
mov eax, [BSS_PnpResult]
ret
END
/* EOF */

View file

@ -360,6 +360,7 @@ LongModeEntryPoint:
int HEX(16)
jmp Reboot
/* FNID_* functions */
CallbackTable:
.word Int386
.word Reboot
@ -367,6 +368,7 @@ CallbackTable:
.word PxeCallApi
.word PnpBiosGetDeviceNodeCount
.word PnpBiosGetDeviceNode
.word PnpBiosGetDockStationInformation
/* 16-bit stack pointer */
stack16:

View file

@ -140,6 +140,7 @@ pm_entrypoint:
.long 0 // receives address of PE entry point
nop
/* FNID_* functions */
CallbackTable:
.word Int386
.word Reboot
@ -147,6 +148,7 @@ CallbackTable:
.word PxeCallApi
.word PnpBiosGetDeviceNodeCount
.word PnpBiosGetDeviceNode
.word PnpBiosGetDockStationInformation
/* 16-bit stack pointer */

View file

@ -54,3 +54,28 @@ PnpBiosGetDeviceNode:
mov dword ptr ds:[BSS_PnpResult], ecx
ret
PnpBiosGetDockStationInformation:
/* push bios segment */
mov ax, word ptr ds:[BSS_PnpBiosDataSegment]
push ax
/* push pointer to info structure (segment/offset) */
mov ax, word ptr ds:[BSS_PnpBiosBufferSegment]
push ax
mov ax, word ptr ds:[BSS_PnpBiosBufferOffset]
push ax
/* push function number */
push 5
/* call entry point */
call dword ptr ds:[BSS_PnpBiosEntryPoint]
add sp, 8
movzx ecx, ax
mov dword ptr ds:[BSS_PnpResult], ecx
ret

View file

@ -87,6 +87,7 @@ ULONG __cdecl PnpBiosGetDeviceNodeCount(ULONG *NodeSize,
ULONG *NodeCount);
ULONG __cdecl PnpBiosGetDeviceNode(UCHAR *NodeId,
UCHAR *NodeBuffer);
ULONG __cdecl PnpBiosGetDockStationInformation(UCHAR *DockingStationInfo);
/* i386pxe.S */
USHORT __cdecl PxeCallApi(USHORT Segment, USHORT Offset, USHORT Service, VOID* Parameter);

View file

@ -79,6 +79,12 @@ typedef struct _ACPI_BIOS_DATA
BIOS_MEMORY_MAP MemoryMap[1]; /* Count of BIOS memory map entries */
} ACPI_BIOS_DATA, *PACPI_BIOS_DATA;
typedef struct _DOCKING_STATE_INFORMATION
{
USHORT Unused[5];
USHORT ReturnCode;
} DOCKING_STATE_INFORMATION, *PDOCKING_STATE_INFORMATION;
#include <pshpack1.h>
typedef struct
{

View file

@ -58,6 +58,7 @@
#define FNID_PxeCallApi 3
#define FNID_PnpBiosGetDeviceNodeCount 4
#define FNID_PnpBiosGetDeviceNode 5
#define FNID_PnpBiosGetDockStationInformation 6
/* Flag Masks */
#define CR0_PE_SET HEX(00000001) /* OR this value with CR0 to enable pmode */