did some stuff, will probably refactor later
This commit is contained in:
parent
10ee4fcbd9
commit
bc4ec556e2
46 changed files with 1013 additions and 35635 deletions
|
@ -25,143 +25,71 @@
|
|||
#include <lib/string.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <sounds/chime.h>
|
||||
#include <hda.h>
|
||||
#include <pciconf.h>
|
||||
#define INI_IMPLEMENTATION
|
||||
#include <config/ini.h>
|
||||
|
||||
|
||||
EFI_HANDLE gImageHandle;
|
||||
EFI_SYSTEM_TABLE *gSystemTable;
|
||||
EFI_BOOT_SERVICES *gBootServices;
|
||||
|
||||
#define INITIAL_VOLUME 12
|
||||
|
||||
uint8_t *AlignedDataBufferBdlEntry = NULL;
|
||||
uint8_t *SoundData = NULL;
|
||||
uint64_t SoundDataSize = 0;
|
||||
|
||||
EFI_STATUS InitHdaControllerCodecAndBuffers(PCI_HDA_REGION *PcieDeviceConfigSpace, HDA_CONTROLLER_REGISTER_SET *ControllerRegisterSet)
|
||||
{
|
||||
uint32_t WriteValue = 0;
|
||||
uint32_t Response = 0;
|
||||
|
||||
DisablePcieInterrupts(PcieDeviceConfigSpace);
|
||||
EnablePcieNoSnoop(PcieDeviceConfigSpace);
|
||||
|
||||
// traffic priority -> TC0
|
||||
WriteValue = 0;
|
||||
WriteControllerRegister(PcieDeviceConfigSpace, HDA_OFFSET_PCIE_TCSEL, (void *)&WriteValue, 1, 0, EfiPciWidthUint8);
|
||||
|
||||
AllocateRIRBBuffer(PcieDeviceConfigSpace);
|
||||
AllocateCORBBuffer(PcieDeviceConfigSpace);
|
||||
|
||||
// Turn all nodes on
|
||||
SendCommandToAllWidgets8BitPayload(PcieDeviceConfigSpace, HDA_VRB_SET_POWER_STATE, 0x0);
|
||||
|
||||
// Set initial volume to output widgets
|
||||
GetCodecData8BitPayloadCorbRirb(PcieDeviceConfigSpace, 0x0, 0x10, HDA_VRB_SET_AMPLIFIER_GAIN_MUTE, INITIAL_VOLUME, &Response);
|
||||
GetCodecData8BitPayloadCorbRirb(PcieDeviceConfigSpace, 0x0, 0x11, HDA_VRB_SET_AMPLIFIER_GAIN_MUTE, INITIAL_VOLUME, &Response);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS AllocateResourcesBasedOnFile(PCI_HDA_REGION *PcieDeviceConfigSpace, HDA_CONTROLLER_REGISTER_SET *ControllerRegisterSet, EFI_UINTN FileSize, EFI_UINTN DataAddress)
|
||||
{
|
||||
uint8_t WriteValue8 = 0;
|
||||
uint16_t WriteValue16 = 0;
|
||||
uint32_t WriteValue = 0;
|
||||
uint32_t Response = 0;
|
||||
|
||||
void *AlignedDataMapping = NULL;
|
||||
|
||||
uint64_t BdlEntriesRequired = 0;
|
||||
uint64_t BdlEntriesRequiredCurrentEntry = 0;
|
||||
|
||||
AllocateStreamsPages(PcieDeviceConfigSpace, ControllerRegisterSet);
|
||||
if (SoundDataSize < 0xFFFFFFFF) {
|
||||
BdlEntriesRequired = 1;
|
||||
} else {
|
||||
BdlEntriesRequired = SoundDataSize / 0xFFFFFFFF;
|
||||
if (SoundDataSize % 0xFFFFFFFF > 0) {
|
||||
BdlEntriesRequired += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (BdlEntriesRequiredCurrentEntry = 0; BdlEntriesRequiredCurrentEntry < 2; BdlEntriesRequiredCurrentEntry++) {
|
||||
SetupCommonBuffer(&AlignedDataBufferBdlEntry, SoundDataSize / BdlEntriesRequired, &AlignedDataMapping, 2);
|
||||
|
||||
memcpy(AlignedDataBufferBdlEntry, SoundData, SoundDataSize / BdlEntriesRequired);
|
||||
AddDescriptorListEntryOss0(PcieDeviceConfigSpace, ControllerRegisterSet, (uint64_t)AlignedDataBufferBdlEntry, SoundDataSize / BdlEntriesRequired, BdlEntriesRequiredCurrentEntry, BdlEntriesRequiredCurrentEntry + 1);
|
||||
}
|
||||
|
||||
// Write cyclic buffer length
|
||||
WriteValue = SoundDataSize * 2;
|
||||
WriteControllerRegister(PcieDeviceConfigSpace, CALCULATE_OSSN_OFFSET(0, ControllerRegisterSet->GCAP) + HDA_RELATIVE_OFFSET_SDXCBL, (void *)&WriteValue, 1, 0, EfiPciWidthUint32);
|
||||
|
||||
// Setup stream ID on codec nodes
|
||||
WriteValue8 = 0x10;
|
||||
GetCodecData8BitPayloadCorbRirb(PcieDeviceConfigSpace, 0, 0x10, HDA_VRB_SET_CHANNEL_STREAM_ID, WriteValue8, &Response);
|
||||
|
||||
// Set stream ID
|
||||
WriteValue = 0x100000;
|
||||
WriteControllerRegister(PcieDeviceConfigSpace, CALCULATE_OSSN_OFFSET(0, ControllerRegisterSet->GCAP) + HDA_RELATIVE_OFFSET_SDXCTL, (void *)&WriteValue, 1, 0, EfiPciWidthUint32);
|
||||
|
||||
// Set FIFO size
|
||||
WriteValue = 0x04;
|
||||
WriteControllerRegister(PcieDeviceConfigSpace, CALCULATE_OSSN_OFFSET(0, ControllerRegisterSet->GCAP) + HDA_RELATIVE_OFFSET_SDXFIFOS, (void *)&WriteValue, 1, 0, EfiPciWidthUint32);
|
||||
|
||||
// Set stream format (2 channel, 16 bits, 44.1kHz)
|
||||
WriteValue16 = 0x4011;
|
||||
GetCodecData16BitPayloadCorbRirb(PcieDeviceConfigSpace, 0x0, 0x11, HDA_VRB_SET_STREAM_FORMAT, WriteValue16, &Response);
|
||||
WriteControllerRegister(PcieDeviceConfigSpace, CALCULATE_OSSN_OFFSET(0, ControllerRegisterSet->GCAP) + HDA_RELATIVE_OFFSET_SDXFMT, (void *)&WriteValue16, 1, 0, EfiPciWidthUint16);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
EFI_SIMPLE_POINTER_PROTOCOL *gPointerProtocol;
|
||||
uint16_t mouse_resx;
|
||||
uint16_t mouse_resy;
|
||||
|
||||
EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle,
|
||||
EFI_SYSTEM_TABLE *SystemTable)
|
||||
EFI_SYSTEM_TABLE *SystemTable)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
EFI_GUID spp_guid = EFI_SIMPLE_POINTER_PROTOCOL_GUID;
|
||||
EFI_SIMPLE_POINTER_PROTOCOL *spp[5];
|
||||
|
||||
gImageHandle = ImageHandle;
|
||||
gSystemTable = SystemTable;
|
||||
gBootServices = SystemTable->BootServices;
|
||||
gImageHandle = ImageHandle;
|
||||
gSystemTable = SystemTable;
|
||||
gBootServices = SystemTable->BootServices;
|
||||
|
||||
// clear the screen
|
||||
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
|
||||
// clear the screen
|
||||
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
|
||||
|
||||
// disable UEFI watchdog
|
||||
Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("Couldn't disable UEFI watchdog: %s (%x)\n", efi_status_to_str(Status), Status);
|
||||
}
|
||||
// disable UEFI watchdog
|
||||
Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("Couldn't disable UEFI watchdog: %s (%x)\n", efi_status_to_str(Status), Status);
|
||||
}
|
||||
|
||||
// load Intel HDA driver
|
||||
HDA_CONTROLLER_REGISTER_SET ControllerRegisterSet;
|
||||
PCI_HDA_REGION PcieDeviceConfigSpace;
|
||||
uint32_t WriteValue = 0;
|
||||
uint16_t CurrentVolume = 12;
|
||||
// load that mouse up
|
||||
EFI_UINTN spp_handles = 0;
|
||||
EFI_HANDLE *spp_handle_buf = NULL;
|
||||
Status = gBootServices->LocateHandleBuffer(ByProtocol, &spp_guid, NULL, &spp_handles, &spp_handle_buf);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Failed to locate Simple Pointer Protocol handle buffer: %s (%x).", efi_status_to_str(Status), Status);
|
||||
} else {
|
||||
debug("uefi_entry(): Found %u handle%s\n", spp_handles, spp_handles == 1 ? "" : "s");
|
||||
for (EFI_UINTN i = 0; i < spp_handles; i++) {
|
||||
Status = gBootServices->OpenProtocol(spp_handle_buf[i], &spp_guid, (void **)&spp[i], gImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Failed to open Simple Pointer Protocol on handle: %s (%x)\n", efi_status_to_str(Status), Status);
|
||||
continue;
|
||||
}
|
||||
|
||||
SoundData = chime_data;
|
||||
SoundDataSize = chime_len;
|
||||
debug("Found SPP with ResX=%u, ResY=%u\n", spp[i]->Mode->ResolutionX, spp[i]->Mode->ResolutionY);
|
||||
if (spp[i]->Reset(spp[i], EFI_TRUE) == EFI_DEVICE_ERROR) {
|
||||
debug("uefi_entry(): Failed to reset device\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
Status = InitHda();
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Failed to initialize HDA driver!\n");
|
||||
} else {
|
||||
Status = GetPcieConfigSpace(HDA_BUS, HDA_DEV, HDA_FUNC, &PcieDeviceConfigSpace);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Failed to initialize HDA driver!\n");
|
||||
} else {
|
||||
GetControllerRegisterSet(&PcieDeviceConfigSpace, &ControllerRegisterSet);
|
||||
InitHdaControllerCodecAndBuffers(&PcieDeviceConfigSpace, &ControllerRegisterSet);
|
||||
AllocateResourcesBasedOnFile(&PcieDeviceConfigSpace, &ControllerRegisterSet, 0, 0);
|
||||
if (spp[i]->Mode->ResolutionX < 65536) {
|
||||
gPointerProtocol = spp[i];
|
||||
mouse_resx = spp[i]->Mode->ResolutionX;
|
||||
mouse_resy = spp[i]->Mode->ResolutionY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WriteValue = 0x100002;
|
||||
WriteControllerRegister(&PcieDeviceConfigSpace, CALCULATE_OSSN_OFFSET(0, ControllerRegisterSet.GCAP) + HDA_RELATIVE_OFFSET_SDXCTL, (void *)&WriteValue, 1, 0, EfiPciWidthUint32);
|
||||
}
|
||||
}
|
||||
|
||||
axboot_init();
|
||||
UNREACHABLE();
|
||||
axboot_init();
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue