]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/BdsLinuxFdt.c: Fix creation of 'cpu' and 'psci' device tree nodes.
authoroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 12 May 2013 23:56:35 +0000 (23:56 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 12 May 2013 23:56:35 +0000 (23:56 +0000)
* Fix name of 'device_type' and 'migrate' properties.
* Fix 'reg' property. It is supposed to contain the CPU MPIDR of the
  CPU being described.
* Fix byte ordering of data in 'psci' node.
* Fix some problems regarding the size of data. In a number of places
  it was assumed data would be 32-bits wide.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14351 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Include/Library/ArmLib.h
ArmPkg/Library/BdsLib/BdsLinuxFdt.c

index 75f775536280b44248ba37acf263adf1f05ff842..5663844b1f1890a6fdb91231f4cec7bb0cd2c732 100644 (file)
@@ -116,6 +116,7 @@ typedef enum {
 #define ARM_CLUSTER_MASK      (0xFF << 8)\r
 #define GET_CORE_ID(MpId)     ((MpId) & ARM_CORE_MASK)\r
 #define GET_CLUSTER_ID(MpId)  (((MpId) & ARM_CLUSTER_MASK) >> 8)\r
+#define GET_MPID(ClusterId, CoreId)   (((ClusterId) << 8) | (CoreId))\r
 // Get the position of the core for the Stack Offset (4 Core per Cluster)\r
 //   Position = (ClusterId * 4) + CoreId\r
 #define GET_CORE_POS(MpId)    ((((MpId) & ARM_CLUSTER_MASK) >> 6) + ((MpId) & ARM_CORE_MASK))\r
index b07b3e465d2c0aaf92d144651e38d6a0bcd526c0..4ff0afeb7d93c1718ed84e6cc1302d90196da8e0 100644 (file)
@@ -361,6 +361,8 @@ PrepareFdt (
   BOOLEAN               PsciSmcSupported;\r
   UINTN                 OriginalFdtSize;\r
   BOOLEAN               CpusNodeExist;\r
+  UINTN                 CoreMpId;\r
+  UINTN                 Smc;\r
 \r
   NewFdtBlobAllocation = 0;\r
 \r
@@ -503,7 +505,11 @@ PrepareFdt (
   }\r
 \r
   //\r
-  // Setup Arm Mpcore Info if it is a multi-core or multi-cluster platforms\r
+  // Setup Arm Mpcore Info if it is a multi-core or multi-cluster platforms.\r
+  //\r
+  // For 'cpus' and 'cpu' device tree nodes bindings, refer to this file\r
+  // in the kernel documentation:\r
+  // Documentation/devicetree/bindings/arm/cpus.txt\r
   //\r
   for (Index=0; Index < gST->NumberOfTableEntries; Index++) {\r
     // Check for correct GUID type\r
@@ -517,7 +523,7 @@ PrepareFdt (
         // Create the /cpus node\r
         node = fdt_add_subnode(fdt, 0, "cpus");\r
         fdt_setprop_string(fdt, node, "name", "cpus");\r
-        fdt_setprop_cell(fdt, node, "#address-cells", 1);\r
+        fdt_setprop_cell (fdt, node, "#address-cells", sizeof (UINTN) / 4);\r
         fdt_setprop_cell(fdt, node, "#size-cells", 0);\r
         CpusNodeExist = FALSE;\r
       } else {\r
@@ -531,12 +537,25 @@ PrepareFdt (
       for (Index = 0; Index < ArmProcessorTable->NumberOfEntries; Index++) {\r
         AsciiSPrint (Name, 10, "cpu@%d", Index);\r
 \r
-        // If the 'cpus' node did not exist then creates the 'cpu' nodes. In case 'cpus' node\r
-        // is provided in the original FDT then we do not add any 'cpu' node.\r
+        // If the 'cpus' node did not exist then create all the 'cpu' nodes.\r
+        // In case 'cpus' node is provided in the original FDT then we do not add\r
+        // any 'cpu' node.\r
         if (!CpusNodeExist) {\r
-          cpu_node = fdt_add_subnode(fdt, node, Name);\r
-          fdt_setprop_string(fdt, cpu_node, "device-type", "cpu");\r
-          fdt_setprop(fdt, cpu_node, "reg", &Index, sizeof(Index));\r
+          cpu_node = fdt_add_subnode (fdt, node, Name);\r
+          if (cpu_node < 0) {\r
+            DEBUG ((EFI_D_ERROR, "Error on creating '%s' node\n", Name));\r
+            Status = EFI_INVALID_PARAMETER;\r
+            goto FAIL_COMPLETE_FDT;\r
+          }\r
+\r
+          fdt_setprop_string (fdt, cpu_node, "device_type", "cpu");\r
+          CoreMpId = (UINTN) GET_MPID (ArmCoreInfoTable[Index].ClusterId,\r
+                               ArmCoreInfoTable[Index].CoreId);\r
+          CoreMpId = cpu_to_fdtn (CoreMpId);\r
+          fdt_setprop (fdt, cpu_node, "reg", &CoreMpId, sizeof (CoreMpId));\r
+          if (PsciSmcSupported) {\r
+            fdt_setprop_string (fdt, cpu_node, "enable-method", "psci");\r
+          }\r
         } else {\r
           cpu_node = fdt_subnode_offset(fdt, node, Name);\r
         }\r
@@ -578,12 +597,20 @@ PrepareFdt (
         Status = EFI_INVALID_PARAMETER;\r
         goto FAIL_COMPLETE_FDT;\r
       } else {\r
-        fdt_setprop_string(fdt, node, "compatible", "arm,psci");\r
-        fdt_setprop_string(fdt, node, "method", "smc");\r
-        fdt_setprop_cell(fdt, node, "cpu_suspend", ARM_SMC_ARM_CPU_SUSPEND);\r
-        fdt_setprop_cell(fdt, node, "cpu_off", ARM_SMC_ARM_CPU_OFF);\r
-        fdt_setprop_cell(fdt, node, "cpu_on", ARM_SMC_ARM_CPU_ON);\r
-        fdt_setprop_cell(fdt, node, "cpu_migrate", ARM_SMC_ARM_MIGRATE);\r
+        fdt_setprop_string (fdt, node, "compatible", "arm,psci");\r
+        fdt_setprop_string (fdt, node, "method", "smc");\r
+\r
+        Smc = cpu_to_fdtn (ARM_SMC_ARM_CPU_SUSPEND);\r
+        fdt_setprop (fdt, node, "cpu_suspend", &Smc, sizeof (Smc));\r
+\r
+        Smc = cpu_to_fdtn (ARM_SMC_ARM_CPU_OFF);\r
+        fdt_setprop (fdt, node, "cpu_off", &Smc, sizeof (Smc));\r
+\r
+        Smc = cpu_to_fdtn (ARM_SMC_ARM_CPU_ON);\r
+        fdt_setprop (fdt, node, "cpu_on", &Smc, sizeof (Smc));\r
+\r
+        Smc = cpu_to_fdtn (ARM_SMC_ARM_MIGRATE);\r
+        fdt_setprop (fdt, node, "migrate", &Smc, sizeof (Smc));\r
       }\r
     }\r
   }\r