From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171])
 by mx.groups.io with SMTP id smtpd.web11.58162.1622555464249241362
 for <devel@edk2.groups.io>;
 Tue, 01 Jun 2021 06:51:04 -0700
Authentication-Results: mx.groups.io;
 dkim=pass header.i=@puresoftware.com header.s=google header.b=RgWRVCWB;
 spf=pass (domain: puresoftware.com, ip: 209.85.215.171, mailfrom: vikas.singh@puresoftware.com)
Received: by mail-pg1-f171.google.com with SMTP id e22so10730671pgv.10
        for <devel@edk2.groups.io>; Tue, 01 Jun 2021 06:51:04 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=puresoftware.com; s=google;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :mime-version:content-transfer-encoding;
        bh=3r2SijxuGySlaMfCm2Px0U+4O7mdeIM6L4cKiUrHYwQ=;
        b=RgWRVCWBAhRXE3vmkHx9Unb5eu2GEDAO34LaxKAfzUk1ceUaTDJy6qDGu24A0woI41
         lEWCTfMkBXnH95dPvO5+2GJDukRMuIJ86V8XWVCHGeJPLHiGk5/PwnZb7BKalOUZwMAG
         +LThegDWI8QblpezJRvrV/Mwm5YwU6CqdeXjI=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:mime-version:content-transfer-encoding;
        bh=3r2SijxuGySlaMfCm2Px0U+4O7mdeIM6L4cKiUrHYwQ=;
        b=hERClQm8qsfanGc6setrrp2PFEOcboLWFriOjzO3etkOftKM5noGkh6S6X/DJJlVgf
         yhR+LPskoqcWl70CM45PRZkO0i7maK3Gadnad7A1KuPlM02q4m1dTls3pMadaNat+saM
         2NtckG/v8plhyyPaqW64YVI71CAvzhs5kSdtxn/Ntyjdn7arnaUD2PAXAmfiUY0DtZA8
         OL3jKNYqUr0Q3bzqR5BkZY+Mu6AqC2hsPPFMZl0pz0ucAMVh2dger/YBuCL/4+3wLUzY
         0i31ARWdkNpvyckEjN5svKf31RjGvPqJ4jpWlinhCc9FM2a2t4zXnatvEVynEqfFLLLO
         GR0Q==
X-Gm-Message-State: AOAM532/YxU+VMqqnLD8rV9uYHpw43C+xF+huZq6aw1WSyXQ/w0SYWR/
	/x9lpYiMjiITgG/gM4EhoRvllMtOTkBeIO+5lIs=
X-Google-Smtp-Source: ABdhPJzqQMjkxNqNWsjCJIyn/Svwjrugoz5vKM0+FrBK+D11Fsu33qXXDS5FuMiNWiXx8pYSknr3+g==
X-Received: by 2002:aa7:8556:0:b029:2e2:45aa:d01e with SMTP id y22-20020aa785560000b02902e245aad01emr22043168pfn.14.1622555463328;
        Tue, 01 Jun 2021 06:51:03 -0700 (PDT)
Return-Path: <vikas.singh@puresoftware.com>
Received: from embedded-PC.puresoft.int ([125.63.92.170])
        by smtp.gmail.com with ESMTPSA id d22sm14504798pgb.15.2021.06.01.06.50.59
        (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 01 Jun 2021 06:51:03 -0700 (PDT)
From: "Vikas Singh" <vikas.singh@puresoftware.com>
To: devel@edk2.groups.io
Cc: sami.mujawar@arm.com,
	leif@nuviainc.com,
	meenakshi.aggarwal@nxp.com,
	samer.el-haj-mahmoud@arm.com,
	v.sethi@nxp.com,
	arokia.samy@puresoftware.com,
	kuldip.dwivedi@puresoftware.com,
	ard.biesheuvel@arm.com,
	vikas.singh@nxp.com,
	Sunny.Wang@arm.com
Subject: [PATCH V0 4/4] Platform/NXP/LS1046aFrwyPkg: Add OEM specific DSDT generator
Date: Tue,  1 Jun 2021 19:20:34 +0530
Message-Id: <20210601135034.22386-5-vikas.singh@puresoftware.com>
X-Mailer: git-send-email 2.31.1
In-Reply-To: <20210601135034.22386-1-vikas.singh@puresoftware.com>
References: <20210601135034.22386-1-vikas.singh@puresoftware.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable

This patch adds platform specific DSDT generator
and Clk dsdt properties for LS1046AFRWY platform.

Signed-off-by: Vikas Singh <vikas.singh@puresoftware.com>
---
 .../AcpiTablesInclude/Dsdt/Clk.asl            |  60 ++++++++
 .../AcpiTablesInclude/Dsdt/Dsdt.asl           |  15 ++
 .../AcpiTablesInclude/PlatformAcpiDsdtLib.inf |  39 +++++
 .../PlatformAcpiDsdtLib/RawDsdtGenerator.c    | 138 ++++++++++++++++++
 .../AcpiTablesInclude/PlatformAcpiLib.h       |  23 +++
 .../NXP/LS1046aFrwyPkg/Include/Platform.h     |   6 +-
 .../NXP/LS1046aFrwyPkg/LS1046aFrwyPkg.dsc     |   1 +
 7 files changed, 281 insertions(+), 1 deletion(-)
 create mode 100644 Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Clk.=
asl
 create mode 100644 Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Dsdt=
.asl
 create mode 100644 Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformA=
cpiDsdtLib.inf
 create mode 100644 Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformA=
cpiDsdtLib/RawDsdtGenerator.c
 create mode 100644 Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformA=
cpiLib.h

diff --git a/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Clk.asl b/P=
latform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Clk.asl
new file mode 100644
index 0000000000..58541c3019
--- /dev/null
+++ b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Clk.asl
@@ -0,0 +1,60 @@
+/** @file=0D
+*  DSDT : Dynamic Clock ACPI Information=0D
+*=0D
+*  Copyright 2021 NXP=0D
+*  Copyright 2021 Puresoftware Ltd.=0D
+*=0D
+*  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+*=0D
+**/=0D
+=0D
+Scope(_SB)=0D
+{=0D
+  Device(PCLK) {=0D
+    Name(_HID, "NXP0017")=0D
+    Name(CLK, 0)  // Maximum Platform Clock (Hz)=0D
+    Name(CCLK, 0) // Maximum CPU Core Clock (MHz)=0D
+    Name(AVBL, 0)=0D
+    OperationRegion(RCWS, SystemMemory, DCFG_BASE, DCFG_LEN)=0D
+    Method(_REG,2) {=0D
+      if (Arg0 =3D=3D "RCWS") {=0D
+        Store(Arg1, AVBL)=0D
+      }=0D
+    }=0D
+    Field (RCWS, ByteAcc, NoLock, Preserve) {=0D
+      /* The below table provides the func of diff bits in 512 bits RCW da=
ta:=0D
+         SYS_PLL_CFG : 0-1 bits=0D
+         SYS_PLL_RAT : 2-6 bits=0D
+         SYSCLK_FREQ : 472-481 bits etc.=0D
+         Refer LS1046ARM for more info.=0D
+         For LS1046 RCWSRs are read as RCW[0:31] .=0D
+      */=0D
+      offset(0x100),=0D
+      RESV, 1,=0D
+      PRAT, 5,=0D
+      PCFG, 2,=0D
+      offset(0x103),=0D
+      CPRT, 6,  // Cluster Group PLL Multiplier ratio=0D
+      offset(0x13B),=0D
+      HFRQ, 8,  // Higher 8 bits of SYSCLK_FREQ=0D
+      RESX, 6,=0D
+      LFRQ, 2   // Lower bits of SYSCLK_FREQ=0D
+    }=0D
+=0D
+    Method(_INI, 0, NotSerialized) {=0D
+      /* Calculating Platform Clock */=0D
+      Local0 =3D (HFRQ<<2 | LFRQ) // Concatinating LFRQ at end of HFRQ=0D
+      Multiply(Local0, 500000, Local0)=0D
+      Multiply(Local0, PRAT, Local0)=0D
+      Divide(Local0, 3, , Local0)=0D
+      Store(Local0, CLK)=0D
+=0D
+      /* Calculating Maximum Core Clock */=0D
+      Local0 =3D (HFRQ<<2 | LFRQ) // Concatinating LFRQ at end of HFRQ=0D
+      Multiply(Local0, 500000, Local0)=0D
+      Divide(Local0, 3, , Local0)=0D
+      Divide(Local0, 1000000, , Local0) //Just the MHz part of SYSCLK.=0D
+      Multiply(Local0, CPRT, CCLK) // PLL_Ratio * SYSCLK, Max freq of clus=
ter=0D
+    }=0D
+  } // end of device PCLK=0D
+}=0D
diff --git a/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Dsdt.asl b/=
Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Dsdt.asl
new file mode 100644
index 0000000000..19f3f1c0e8
--- /dev/null
+++ b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Dsdt/Dsdt.asl
@@ -0,0 +1,15 @@
+/** @file=0D
+  Differentiated System Description Table Fields (DSDT)=0D
+=0D
+  Copyright 2021 NXP=0D
+  Copyright 2021 Puresoftware Ltd.=0D
+=0D
+  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "Platform.h"=0D
+=0D
+DefinitionBlock("DsdtTable.aml", "DSDT", 2, "NXP  ", "LS1046  ", EFI_ACPI_=
ARM_OEM_REVISION) {=0D
+  include ("Clk.asl")=0D
+}=0D
diff --git a/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiDsdt=
Lib.inf b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiDsdtLib=
.inf
new file mode 100644
index 0000000000..ed5f9dd442
--- /dev/null
+++ b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiDsdtLib.inf
@@ -0,0 +1,39 @@
+## @file=0D
+#  Raw Table Generator=0D
+#=0D
+#  Copyright 2021 NXP=0D
+#  Copyright 2021 Puresoftware Ltd=0D
+#=0D
+#  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+##=0D
+=0D
+[Defines]=0D
+  INF_VERSION    =3D 0x00010019=0D
+  BASE_NAME      =3D PlatformAcpiDsdtLib=0D
+  FILE_GUID      =3D A97F70AC-3BB4-4596-B4D2-9F948EC12D17=0D
+  VERSION_STRING =3D 1.0=0D
+  MODULE_TYPE    =3D DXE_DRIVER=0D
+  LIBRARY_CLASS  =3D NULL|DXE_DRIVER=0D
+  CONSTRUCTOR    =3D AcpiDsdtLibConstructor=0D
+  DESTRUCTOR     =3D AcpiDsdtLibDestructor=0D
+=0D
+[Sources]=0D
+  PlatformAcpiDsdtLib/RawDsdtGenerator.c=0D
+  Dsdt/Dsdt.asl=0D
+=0D
+[Packages]=0D
+  DynamicTablesPkg/DynamicTablesPkg.dec=0D
+  EmbeddedPkg/EmbeddedPkg.dec=0D
+  MdePkg/MdePkg.dec=0D
+  MdeModulePkg/MdeModulePkg.dec=0D
+  Platform/NXP/LS1046aFrwyPkg/LS1046aFrwyPkg.dec=0D
+  Platform/NXP/ConfigurationManagerPkg/ConfigurationManagerPkg.dec=0D
+=0D
+[LibraryClasses]=0D
+  BaseLib=0D
+=0D
+[Pcd]=0D
+=0D
+[Protocols]=0D
+=0D
+[Guids]=0D
diff --git a/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiDsdt=
Lib/RawDsdtGenerator.c b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/Plat=
formAcpiDsdtLib/RawDsdtGenerator.c
new file mode 100644
index 0000000000..7d886396ca
--- /dev/null
+++ b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiDsdtLib/Raw=
DsdtGenerator.c
@@ -0,0 +1,138 @@
+/** @file=0D
+  Raw DSDT Table Generator=0D
+=0D
+  Copyright 2021 NXP=0D
+  Copyright 2021 Puresoftware Ltd.=0D
+=0D
+  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include <Library/AcpiLib.h>=0D
+#include <Library/DebugLib.h>=0D
+#include <Protocol/AcpiTable.h>=0D
+=0D
+// Module specific include files.=0D
+#include <AcpiTableGenerator.h>=0D
+#include <ConfigurationManagerObject.h>=0D
+#include <ConfigurationManagerHelper.h>=0D
+#include <Library/TableHelperLib.h>=0D
+#include <Protocol/ConfigurationManagerProtocol.h>=0D
+=0D
+#include "PlatformAcpiLib.h"=0D
+=0D
+/** Construct the ACPI table using the ACPI table data provided.=0D
+  This function invokes the Configuration Manager protocol interface=0D
+  to get the required hardware information for generating the ACPI=0D
+  table.=0D
+  If this function allocates any resources then they must be freed=0D
+  in the FreeXXXXTableResources function.=0D
+  @param [in]  This           Pointer to the table generator.=0D
+  @param [in]  AcpiTableInfo  Pointer to the ACPI Table Info.=0D
+  @param [in]  CfgMgrProtocol Pointer to the Configuration Manager=0D
+                              Protocol Interface.=0D
+  @param [out] Table          Pointer to the constructed ACPI Table.=0D
+  @retval EFI_SUCCESS           Table generated successfully.=0D
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.=0D
+**/=0D
+STATIC=0D
+EFI_STATUS=0D
+EFIAPI=0D
+BuildRawDsdtTable (=0D
+  IN  CONST ACPI_TABLE_GENERATOR                  * CONST This,=0D
+  IN  CONST CM_STD_OBJ_ACPI_TABLE_INFO            * CONST AcpiTableInfo,=0D
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  * CONST CfgMgrProtocol,=
=0D
+  OUT       EFI_ACPI_DESCRIPTION_HEADER          ** CONST Table=0D
+  )=0D
+{=0D
+  ASSERT (This !=3D NULL);=0D
+  ASSERT (AcpiTableInfo !=3D NULL);=0D
+  ASSERT (CfgMgrProtocol !=3D NULL);=0D
+  ASSERT (Table !=3D NULL);=0D
+  ASSERT (AcpiTableInfo->TableGeneratorId =3D=3D This->GeneratorID);=0D
+=0D
+  if (AcpiTableInfo->AcpiTableData =3D=3D NULL) {=0D
+    // Add the dsdt aml code here.=0D
+    *Table =3D (EFI_ACPI_DESCRIPTION_HEADER *)&dsdt_aml_code;=0D
+  }=0D
+=0D
+  return EFI_SUCCESS;=0D
+}=0D
+=0D
+/** This macro defines the Raw Generator revision.=0D
+*/=0D
+#define DSDT_GENERATOR_REVISION CREATE_REVISION (1, 0)=0D
+=0D
+/** The interface for the Raw Table Generator.=0D
+*/=0D
+STATIC=0D
+CONST=0D
+ACPI_TABLE_GENERATOR RawDsdtGenerator =3D {=0D
+  // Generator ID=0D
+  CREATE_OEM_ACPI_TABLE_GEN_ID (PlatAcpiTableIdDsdt),=0D
+  // Generator Description=0D
+  L"ACPI.OEM.RAW.DSDT.GENERATOR",=0D
+  // ACPI Table Signature - Unused=0D
+  0,=0D
+  // ACPI Table Revision - Unused=0D
+  0,=0D
+  // Minimum ACPI Table Revision - Unused=0D
+  0,=0D
+  // Creator ID=0D
+  TABLE_GENERATOR_CREATOR_ID_ARM,=0D
+  // Creator Revision=0D
+  DSDT_GENERATOR_REVISION,=0D
+  // Build Table function=0D
+  BuildRawDsdtTable,=0D
+  // No additional resources are allocated by the generator.=0D
+  // Hence the Free Resource function is not required.=0D
+  NULL,=0D
+  // Extended build function not needed=0D
+  NULL,=0D
+  // Extended build function not implemented by the generator.=0D
+  // Hence extended free resource function is not required.=0D
+  NULL=0D
+};=0D
+=0D
+/** Register the Generator with the ACPI Table Factory.=0D
+  @param [in]  ImageHandle  The handle to the image.=0D
+  @param [in]  SystemTable  Pointer to the System Table.=0D
+  @retval EFI_SUCCESS           The Generator is registered.=0D
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.=0D
+  @retval EFI_ALREADY_STARTED   The Generator for the Table ID=0D
+                                is already registered.=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+AcpiDsdtLibConstructor (=0D
+  IN CONST EFI_HANDLE                ImageHandle,=0D
+  IN       EFI_SYSTEM_TABLE  * CONST SystemTable=0D
+  )=0D
+{=0D
+  EFI_STATUS  Status;=0D
+  Status =3D RegisterAcpiTableGenerator (&RawDsdtGenerator);=0D
+  DEBUG ((DEBUG_INFO, "OEM: Register DSDT Generator. Status =3D %r\n", Sta=
tus));=0D
+  ASSERT_EFI_ERROR (Status);=0D
+  return Status;=0D
+}=0D
+=0D
+/** Deregister the Generator from the ACPI Table Factory.=0D
+  @param [in]  ImageHandle  The handle to the image.=0D
+  @param [in]  SystemTable  Pointer to the System Table.=0D
+  @retval EFI_SUCCESS           The Generator is deregistered.=0D
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.=0D
+  @retval EFI_NOT_FOUND         The Generator is not registered.=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+AcpiDsdtLibDestructor (=0D
+  IN CONST EFI_HANDLE                ImageHandle,=0D
+  IN       EFI_SYSTEM_TABLE  * CONST SystemTable=0D
+  )=0D
+{=0D
+  EFI_STATUS  Status;=0D
+  Status =3D DeregisterAcpiTableGenerator (&RawDsdtGenerator);=0D
+  DEBUG ((DEBUG_INFO, "OEM: Deregister DSDT Generator. Status =3D %r\n", S=
tatus));=0D
+  ASSERT_EFI_ERROR (Status);=0D
+  return Status;=0D
+}=0D
diff --git a/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiLib.=
h b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiLib.h
new file mode 100644
index 0000000000..e5f907a7d4
--- /dev/null
+++ b/Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiLib.h
@@ -0,0 +1,23 @@
+/** @file=0D
+ *  Acpi lib headers=0D
+ *=0D
+ *  Copyright 2021 NXP=0D
+ *  Copyright 2021 Puresoftware Ltd=0D
+ *=0D
+ *  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+ *=0D
+**/=0D
+=0D
+=0D
+#ifndef LS1046AFRWY_PLATFORM_ACPI_LIB_H=0D
+#define LS1046AFRWY_PLATFORM_ACPI_LIB_H=0D
+=0D
+#include <PlatformAcpiTableGenerator.h>=0D
+=0D
+/** C array containing the compiled AML template.=0D
+    These symbols are defined in the auto generated C file=0D
+    containing the AML bytecode array.=0D
+*/=0D
+extern CHAR8  dsdt_aml_code[];=0D
+=0D
+#endif=0D
diff --git a/Platform/NXP/LS1046aFrwyPkg/Include/Platform.h b/Platform/NXP/=
LS1046aFrwyPkg/Include/Platform.h
index 19e879ec6d..b21e875f20 100644
--- a/Platform/NXP/LS1046aFrwyPkg/Include/Platform.h
+++ b/Platform/NXP/LS1046aFrwyPkg/Include/Platform.h
@@ -20,6 +20,10 @@
 #define SVR_MAJOR(svr)               (((svr) >> 4) & 0xf)=0D
 #define SVR_MINOR(svr)               (((svr) >> 0) & 0xf)=0D
 =0D
+// PCLK : Dynamic Clock=0D
+#define DCFG_BASE                    0x1EE0000  /* Device configuration da=
ta Base Address */=0D
+#define DCFG_LEN                     0xFFF      /* Device configuration da=
ta length */=0D
+=0D
 // Gic=0D
 #define GIC_VERSION                  2=0D
 #define GICD_BASE                    0x1410000=0D
@@ -62,7 +66,7 @@
 #define CFG_MGR_TABLE_ID  SIGNATURE_64 ('L','S','1','0','4','6',' ',' ')=0D
 =0D
 // Specify the OEM defined tables=0D
-#define OEM_ACPI_TABLES             0=0D
+#define OEM_ACPI_TABLES             1 // Added DSDT=0D
 =0D
 #define PLAT_PCI_SEG0               LS1046A_PCI_SEG0=0D
 #define PLAT_PCI_SEG1_CONFIG_BASE   LS1046A_PCI_SEG1_CONFIG_BASE=0D
diff --git a/Platform/NXP/LS1046aFrwyPkg/LS1046aFrwyPkg.dsc b/Platform/NXP/=
LS1046aFrwyPkg/LS1046aFrwyPkg.dsc
index 20111e6037..7041d15da5 100755
--- a/Platform/NXP/LS1046aFrwyPkg/LS1046aFrwyPkg.dsc
+++ b/Platform/NXP/LS1046aFrwyPkg/LS1046aFrwyPkg.dsc
@@ -65,6 +65,7 @@
         NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/AcpiMadtLibA=
rm.inf=0D
         NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/AcpiMcfgLibA=
rm.inf=0D
         NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/AcpiSpcrLibA=
rm.inf=0D
+        NULL|Platform/NXP/LS1046aFrwyPkg/AcpiTablesInclude/PlatformAcpiDsd=
tLib.inf=0D
     }=0D
   !endif=0D
 =0D
--=20
2.25.1