*/
#include <freeldr.h>
-#include <arch.h>
-#include <rtl.h>
#include <debug.h>
-#include <mm.h>
-#include <portio.h>
-
-#include "../../reactos/registry.h"
-#include "hardware.h"
BOOLEAN AcpiPresent = FALSE;
-static BOOL
+static PRSDP_DESCRIPTOR
FindAcpiBios(VOID)
{
- PUCHAR Ptr;
+ PUCHAR Ptr;
- /* Find the 'Root System Descriptor Table Pointer' */
- Ptr = (PUCHAR)0xE0000;
- while ((ULONG)Ptr < 0x100000)
+ /* Find the 'Root System Descriptor Table Pointer' */
+ Ptr = (PUCHAR)0xE0000;
+ while ((ULONG)Ptr < 0x100000)
{
- if (!memcmp(Ptr, "RSD PTR ", 8))
- {
- DbgPrint((DPRINT_HWDETECT, "ACPI supported\n"));
+ if (!memcmp(Ptr, "RSD PTR ", 8))
+ {
+ DbgPrint((DPRINT_HWDETECT, "ACPI supported\n"));
- return TRUE;
- }
+ return (PRSDP_DESCRIPTOR)Ptr;
+ }
- Ptr = (PUCHAR)((ULONG)Ptr + 0x10);
+ Ptr = (PUCHAR)((ULONG)Ptr + 0x10);
}
- DbgPrint((DPRINT_HWDETECT, "ACPI not supported\n"));
+ DbgPrint((DPRINT_HWDETECT, "ACPI not supported\n"));
- return FALSE;
+ return NULL;
}
VOID
-DetectAcpiBios(FRLDRHKEY SystemKey, ULONG *BusNumber)
+DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
{
- char Buffer[80];
- FRLDRHKEY BiosKey;
- LONG Error;
+ PCONFIGURATION_COMPONENT_DATA BiosKey;
+ PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
+ PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
+ PRSDP_DESCRIPTOR Rsdp;
+ PACPI_BIOS_DATA AcpiBiosData;
+ BIOS_MEMORY_MAP BiosMemoryMap[32];
+ ULONG BiosMemoryMapEntryCount, TableSize;
- if (FindAcpiBios())
- {
- AcpiPresent = TRUE;
- /* Create new bus key */
- sprintf(Buffer,
- "MultifunctionAdapter\\%u", *BusNumber);
- Error = RegCreateKey(SystemKey,
- Buffer,
- &BiosKey);
- if (Error != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_HWDETECT, "RegCreateKey() failed (Error %u)\n", (int)Error));
- return;
- }
-
-#if 0
- /* Set 'Component Information' */
- SetComponentInformation(BiosKey,
- 0x0,
- 0x0,
- 0xFFFFFFFF);
-#endif
-
- /* Increment bus number */
- (*BusNumber)++;
-
- /* Set 'Identifier' value */
- Error = RegSetValue(BiosKey,
- "Identifier",
- REG_SZ,
- "ACPI BIOS",
- 10);
- if (Error != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_HWDETECT, "RegSetValue() failed (Error %u)\n", (int)Error));
- return;
- }
+ Rsdp = FindAcpiBios();
+ if (Rsdp)
+ {
+ /* Set up the flag in the loader block */
+ AcpiPresent = TRUE;
+ LoaderBlock.Flags |= MB_FLAGS_ACPI_TABLE;
+
+ /* Create new bus key */
+ FldrCreateComponentKey(SystemKey,
+ L"MultifunctionAdapter",
+ *BusNumber,
+ AdapterClass,
+ MultiFunctionAdapter,
+ &BiosKey);
+
+ /* Set 'Component Information' */
+ FldrSetComponentInformation(BiosKey,
+ 0x0,
+ 0x0,
+ 0xFFFFFFFF);
+
+ /* Get BIOS memory map */
+ RtlZeroMemory(BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32);
+ BiosMemoryMapEntryCount = MachGetMemoryMap(BiosMemoryMap,
+ sizeof(BiosMemoryMap) / sizeof(BIOS_MEMORY_MAP));
+
+ /* Calculate the table size */
+ TableSize = BiosMemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP) +
+ sizeof(ACPI_BIOS_DATA) - sizeof(BIOS_MEMORY_MAP);
+
+ /* Set 'Configuration Data' value */
+ PartialResourceList =
+ MmHeapAlloc(sizeof(CM_PARTIAL_RESOURCE_LIST) + TableSize);
+ memset(PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST) + TableSize);
+ PartialResourceList->Version = 0;
+ PartialResourceList->Revision = 0;
+ PartialResourceList->Count = 1;
+
+ PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
+ PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
+ PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
+ PartialDescriptor->u.DeviceSpecificData.DataSize = TableSize;
+
+ /* Fill the table */
+ AcpiBiosData = (PACPI_BIOS_DATA)&PartialResourceList->PartialDescriptors[1];
+ AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address;
+ AcpiBiosData->Count = BiosMemoryMapEntryCount;
+ memcpy(AcpiBiosData->MemoryMap, BiosMemoryMap,
+ BiosMemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
+
+ DbgPrint((DPRINT_HWDETECT, "RSDT %p, data size %x\n", Rsdp->rsdt_physical_address,
+ TableSize));
+
+ FldrSetConfigurationData(BiosKey,
+ PartialResourceList,
+ sizeof(CM_PARTIAL_RESOURCE_LIST) + TableSize
+ );
+
+ /* Increment bus number */
+ (*BusNumber)++;
+
+ /* Set 'Identifier' value */
+ FldrSetIdentifier(BiosKey, "ACPI BIOS");
+ MmFreeMemory(PartialResourceList);
}
}