Skip to content

Commit 0b58936

Browse files
committed
[ppc64][riscv64] Device Tree fetching based on kernel version
1 parent e532c1c commit 0b58936

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

ppc64le/corefreqk.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,21 @@ static void Query_Features(void *pArg)
542542
VendorFromMainID(midr, iArg->Features->Info.Vendor.ID,
543543
&iArg->Features->Info.Vendor.CRC, &iArg->HypervisorID);
544544
*/
545-
if (iArg->Features->TSC) {
546-
iArg->Features->Factory.Freq = 512;
547-
} else {
548-
iArg->Features->Factory.Freq = 1000;
549-
}
545+
#ifdef CONFIG_OF
546+
{
547+
struct device_node *cpu_node = of_cpu_device_node_get(iArg->localProcessor);
548+
if (cpu_node != NULL) {
549+
of_property_read_u32( cpu_node, "clock-frequency",
550+
&iArg->Features->Factory.Freq ); /* Hz->Mhz */
551+
of_node_put(cpu_node);
552+
iArg->Features->Factory.Freq = iArg->Features->Factory.Freq / 1000000U;
553+
}
554+
else
555+
iArg->Features->Factory.Freq = 512;
556+
}
557+
#else
558+
iArg->Features->Factory.Freq = 512;
559+
#endif /* CONFIG_OF */
550560
#if defined(CONFIG_ACPI)
551561
iArg->Features->ACPI = acpi_disabled == 0;
552562
#else
@@ -773,6 +783,14 @@ static void Map_Generic_Topology(void *arg)
773783
Core->T.CoreID = mpid.Aff0;
774784
}
775785
*/
786+
#ifdef CONFIG_OF
787+
struct device_node *cpu_node = of_cpu_device_node_get(Core->Bind);
788+
if (cpu_node != NULL) {
789+
of_property_read_u32(cpu_node, "reg", &Core->T.CoreID);
790+
of_node_put(cpu_node);
791+
}
792+
#endif /* CONFIG_OF */
793+
776794
Cache_Topology(Core);
777795
}
778796
}
@@ -981,6 +999,16 @@ static void Query_DeviceTree(unsigned int cpu)
981999
#endif
9821000
}
9831001
#endif /* CONFIG_CPU_FREQ */
1002+
#ifdef CONFIG_OF
1003+
if (max_freq == 0) {
1004+
struct device_node *cpu_node = of_cpu_device_node_get(Core->Bind);
1005+
if (cpu_node != NULL) {
1006+
of_property_read_u32(cpu_node, "clock-frequency", &max_freq); /* Hz */
1007+
of_node_put(cpu_node);
1008+
max_freq = max_freq / 1000U; /* KHz */
1009+
}
1010+
}
1011+
#endif /* CONFIG_OF */
9841012
if (max_freq > 0) {
9851013
FREQ2COF(max_freq, COF);
9861014
} else {

ppc64le/corefreqk.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
* Licenses: GPL2
55
*/
66

7+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
8+
#define of_cpu_device_node_get(cpu) \
9+
({ \
10+
struct device_node *cpu_node; \
11+
struct device *cpu_dev; \
12+
cpu_dev = get_cpu_device(cpu); \
13+
if (!cpu_dev) { \
14+
cpu_node = of_get_cpu_node(cpu, NULL); \
15+
} else { \
16+
cpu_node = of_node_get(cpu_dev->of_node); \
17+
} \
18+
cpu_node; \
19+
})
20+
#endif
21+
722
#define Atomic_Read_VPMC(_lock, _dest, _src) \
823
{ \
924
/* __asm__ volatile \

riscv64/corefreqk.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
* Licenses: GPL2
55
*/
66

7+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
8+
#define of_cpu_device_node_get(cpu) \
9+
({ \
10+
struct device_node *cpu_node; \
11+
struct device *cpu_dev; \
12+
cpu_dev = get_cpu_device(cpu); \
13+
if (!cpu_dev) { \
14+
cpu_node = of_get_cpu_node(cpu, NULL); \
15+
} else { \
16+
cpu_node = of_node_get(cpu_dev->of_node); \
17+
} \
18+
cpu_node; \
19+
})
20+
#endif
21+
722
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
823
#define sys_reg(op0, op1, crn, crm, op2) ({ \
924
UNUSED(op0); \

0 commit comments

Comments
 (0)