From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web12.108398.1597925389887836406 for ; Thu, 20 Aug 2020 05:09:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=AO49xP8y; spf=pass (domain: nuviainc.com, ip: 209.85.221.66, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f66.google.com with SMTP id r2so1775935wrs.8 for ; Thu, 20 Aug 2020 05:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=cZJcWbZ5BgJh/3rP0EiFbr5hoRrOhRB+9sc0bdgg1lY=; b=AO49xP8yNK55/SFXxrhbl21Ug9fDqgRw6+binOXN52CW6Zrie/qZmc3KB++MFv1DYt UI1Dfi3KmW6yLVyYR7TCI2DuGgIf6uMyxHjl5ROMsua2H98JjBVgE1axap7enIBEPvYn WEJXaAmPvHoVpLfcdSv1/VSLGOL4Lt5s9JfOFhnLD6N8PfwzkIwu69ynKWzCaNwnGSFn XK7WSmTGVyXXQdVzzZ6LVNRR3gEA2mITut+X19qs9cVazk6DKVU2od+a/FZSNL0qsuwm vRMHF+XFKWUItVj/d9VdTsYz8z6ABTJRrW/SsVGnNo6At9HfRCWc0skOMVrKEiQkRmn7 ENgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cZJcWbZ5BgJh/3rP0EiFbr5hoRrOhRB+9sc0bdgg1lY=; b=kuydi26jjYss7abEwvJQgxXWb1I/6nH2smb41AYOFchydzphpube3lFSzByerHJKKF CRG9znIIs2S6nbm1XaLEhG4f8qZFWh/GI+20gT80Ed1yek7YUTXX9PGng+OojJlW9NzQ /yq2I9gIarXmDC+3unDv08EFZtPRUHYIy49ILeB/48caahp3l3TU5x1SUnZy843ufa7D 1t/FIS9unII042gO3a+rixHJMlvenHRBHWgUIqXnY8NjikRAyyPIXb3SVJeFIok02Cd6 Pte+BB+VIPTeHtbcBCMp5735wjO93N7J+w6oTo3X1iCqWYNoULwfKv35G6f6Sf3SEMCh 1DEg== X-Gm-Message-State: AOAM531O9Bt+uywGvEyEmGSIfvL5E/lPVh/vIq2ku97WXP63mTGE1XMG +m4R87TOQiatJFsebPhdIqrzJw== X-Google-Smtp-Source: ABdhPJyUgrHUjLLnFOIySfUgESv7dyd1k+yaRlN/VwRB9wuo8Cck12b7HEP1au6kddo+CA5hzDepGQ== X-Received: by 2002:a5d:4746:: with SMTP id o6mr3110118wrs.410.1597925388105; Thu, 20 Aug 2020 05:09:48 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id g70sm4314446wmg.24.2020.08.20.05.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 05:09:47 -0700 (PDT) Date: Thu, 20 Aug 2020 13:09:45 +0100 From: "Leif Lindholm" To: Tanmay Jagdale Cc: graeme@nuviainc.com, shashi.mallela@linaro.org, devel@edk2.groups.io, paul.isaacs@linaro.org, tanmay@marvell.com Subject: Re: [PATCH edk2-platforms 5/7] SbsaQemu: AcpiDxe: Create SSDT table at runtime Message-ID: <20200820120945.GF1191@vanye> References: <20200819143005.13999-1-tanmay.jagdale@linaro.org> <20200819143005.13999-6-tanmay.jagdale@linaro.org> MIME-Version: 1.0 In-Reply-To: <20200819143005.13999-6-tanmay.jagdale@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Aug 19, 2020 at 20:00:03 +0530, Tanmay Jagdale wrote: > - Add support to create SSDT table at runtime. Since SSDT > table is a data table, added a few helper macros to create > the AML entries. > - Also added a function to calculate the length of Packages. > > Signed-off-by: Tanmay Jagdale > --- > .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 144 ++++++++++++++++++ > .../Include/IndustryStandard/SbsaQemuAcpi.h | 29 ++++ > 2 files changed, 173 insertions(+) > > diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > index 569cda8b6474..d90ce0c2a718 100644 > --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -202,6 +203,144 @@ AddMadtTable ( > return Status; > } > > +/* > + * Function to calculate the PkgLength field in ACPI tables > + */ > +STATIC > +UINT32 > +SetPkgLength ( > + IN UINT8 *TablePtr, > + IN UINT32 Length > +) > +{ > + UINT8 ByteCount; > + UINT8 *PkgLeadByte = TablePtr; > + > + if (Length < 64) { > + *TablePtr = Length; > + return 1; > + } > + > + // Set the LSB of Length in PkgLeadByte and advance Length > + *PkgLeadByte = Length & 0xF; > + Length = Length >> 4; > + > + while (Length) { > + TablePtr++; > + *TablePtr = (Length & 0xFF); > + Length = (Length >> 8); > + } > + > + // Calculate the number of bytes the Length field uses > + // and set the ByteCount field in PkgLeadByte. > + ByteCount = (TablePtr - PkgLeadByte) & 0xF; > + *PkgLeadByte |= (ByteCount << 6); > + > + return ByteCount + 1; > +} > + > +/* > + * A function that adds SSDT ACPI table. > + */ > +EFI_STATUS > +AddSsdtTable ( > + IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable > + ) > +{ > + EFI_STATUS Status; > + UINTN TableHandle; > + UINT32 TableSize; > + EFI_PHYSICAL_ADDRESS PageAddress; > + UINT8 *New; > + UINT32 CpuId; > + UINT32 Offset; > + UINT8 ScopeOpName[] = SBSAQEMU_ACPI_SCOPE_NAME; > + UINT32 NumCores = PcdGet32 (PcdCoreCount); > + > + EFI_ACPI_DESCRIPTION_HEADER Header = > + SBSAQEMU_ACPI_HEADER ( > + EFI_ACPI_6_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, > + EFI_ACPI_DESCRIPTION_HEADER, > + EFI_ACPI_6_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_REVISION); > + > + SBSAQEMU_ACPI_CPU_DEVICE CpuDevice = { > + { AML_EXT_OP, AML_EXT_DEVICE_OP }, /* Device () */ > + SBSAQEMU_ACPI_CPU_DEV_LEN, /* Length */ > + SBSAQEMU_ACPI_CPU_DEV_NAME, /* Device Name "C000" */ > + SBSAQEMU_ACPI_CPU_HID, /* Name (HID, "ACPI0007") */ > + SBSAQEMU_ACPI_CPU_UID, /* Name (UID, 0) */ > + }; > + > + // Calculate the new table size based on the number of cores > + TableSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + > + SBSAQEMU_ACPI_SCOPE_OP_MAX_LENGTH + sizeof (ScopeOpName) + > + (sizeof (CpuDevice) * NumCores); Above line contains a tab. /BaseTools/Scripts/PatchCheck.py will find this (and some other issues) for you. Please run over whole set and fix any reporeted issues before submitting v2. / Leif > + > + Status = gBS->AllocatePages ( > + AllocateAnyPages, > + EfiACPIReclaimMemory, > + EFI_SIZE_TO_PAGES (TableSize), > + &PageAddress > + ); > + if (EFI_ERROR(Status)) { > + DEBUG((EFI_D_ERROR, "Failed to allocate pages for SSDT table\n")); > + return EFI_OUT_OF_RESOURCES; > + } > + > + New = (UINT8 *)(UINTN) PageAddress; > + ZeroMem (New, TableSize); > + > + // Add the ACPI Description table header > + CopyMem (New, &Header, sizeof (EFI_ACPI_DESCRIPTION_HEADER)); > + ((EFI_ACPI_DESCRIPTION_HEADER*) New)->Length = TableSize; > + New += sizeof (EFI_ACPI_DESCRIPTION_HEADER); > + > + // Insert the top level ScopeOp > + *New = AML_SCOPE_OP; > + New++; > + Offset = SetPkgLength (New, > + (TableSize - sizeof (EFI_ACPI_DESCRIPTION_HEADER) - 1)); > + New += Offset; > + CopyMem (New, &ScopeOpName, sizeof (ScopeOpName)); > + New += sizeof (ScopeOpName); > + > + // Add new Device structures for the Cores > + for (CpuId = 0; CpuId < NumCores; CpuId++) { > + SBSAQEMU_ACPI_CPU_DEVICE *CpuDevicePtr; > + UINT8 CpuIdByte1, CpuIdByte2, CpuIdByte3; > + > + CopyMem (New, &CpuDevice, sizeof (SBSAQEMU_ACPI_CPU_DEVICE)); > + CpuDevicePtr = (SBSAQEMU_ACPI_CPU_DEVICE *) New; > + > + CpuIdByte1 = CpuId & 0xF; > + CpuIdByte2 = (CpuId >> 4) & 0xF; > + CpuIdByte3 = (CpuId >> 8) & 0xF; > + > + CpuDevicePtr->dev_name[1] = SBSAQEMU_ACPI_ITOA(CpuIdByte3); > + CpuDevicePtr->dev_name[2] = SBSAQEMU_ACPI_ITOA(CpuIdByte2); > + CpuDevicePtr->dev_name[3] = SBSAQEMU_ACPI_ITOA(CpuIdByte1); > + > + CpuDevicePtr->uid[6] = CpuIdByte1 | CpuIdByte2; > + CpuDevicePtr->uid[7] = CpuIdByte3; > + New += sizeof (SBSAQEMU_ACPI_CPU_DEVICE); > + } > + > + // Perform Checksum > + AcpiPlatformChecksum ((UINT8*) PageAddress, TableSize); > + > + Status = AcpiTable->InstallAcpiTable ( > + AcpiTable, > + (EFI_ACPI_COMMON_HEADER *)PageAddress, > + TableSize, > + &TableHandle > + ); > + if (EFI_ERROR(Status)) { > + DEBUG((EFI_D_ERROR, "Failed to install SSDT table\n")); > + } > + > + return Status; > +} > + > EFI_STATUS > EFIAPI > InitializeSbsaQemuAcpiDxe ( > @@ -231,5 +370,10 @@ InitializeSbsaQemuAcpiDxe ( > DEBUG((EFI_D_ERROR, "Failed to add MADT table\n")); > } > > + Status = AddSsdtTable (AcpiTable); > + if (EFI_ERROR(Status)) { > + DEBUG((EFI_D_ERROR, "Failed to add SSDT table\n")); > + } > + > return EFI_SUCCESS; > } > diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuAcpi.h b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuAcpi.h > index 7a9a0061675f..60acc083ddbb 100644 > --- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuAcpi.h > +++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuAcpi.h > @@ -43,4 +43,33 @@ > #define SBSAQEMU_PCI_SEG0_BUSNUM_MIN 0x00 > #define SBSAQEMU_PCI_SEG0_BUSNUM_MAX 0xFF > > +#define SBSAQEMU_ACPI_SCOPE_OP_MAX_LENGTH 5 > + > +#define SBSAQEMU_ACPI_SCOPE_NAME { '_', 'S', 'B', '_' } > + > +#define SBSAQEMU_ACPI_CPU_DEV_LEN 0x1C > +#define SBSAQEMU_ACPI_CPU_DEV_NAME { 'C', '0', '0', '0' } > + > +// Macro to convert Integer to Character > +#define SBSAQEMU_ACPI_ITOA(Byte) (0x30 + (Byte > 9 ? (Byte + 1) : Byte)) > + > +#define SBSAQEMU_ACPI_CPU_HID { \ > + AML_NAME_OP, AML_NAME_CHAR__, 'H', 'I', 'D', \ > + AML_STRING_PREFIX, 'A', 'C', 'P', 'I', '0', '0', '0', '7', \ > + AML_ZERO_OP \ > + } > + > +#define SBSAQEMU_ACPI_CPU_UID { \ > + AML_NAME_OP, AML_NAME_CHAR__, 'U', 'I', 'D', AML_BYTE_PREFIX, \ > + AML_ZERO_OP, AML_ZERO_OP \ > + } > + > +typedef struct { > + UINT8 device_header[2]; > + UINT8 length; > + UINT8 dev_name[4]; > + UINT8 hid[15]; > + UINT8 uid[8]; > +} SBSAQEMU_ACPI_CPU_DEVICE; > + > #endif > -- > 2.28.0 >