Skip to content

Commit ad635e7

Browse files
vlsunilpalmer-dabbelt
authored andcommitted
riscv: cpu: Add 64bit hartid support on RV64
The hartid can be a 64bit value on RV64 platforms. Add support for 64bit hartid in riscv_of_processor_hartid() and update its callers. Signed-off-by: Sunil V L <[email protected]> Reviewed-by: Atish Patra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 62750ea commit ad635e7

File tree

7 files changed

+42
-32
lines changed

7 files changed

+42
-32
lines changed

arch/riscv/include/asm/processor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ static inline void wait_for_interrupt(void)
7979
}
8080

8181
struct device_node;
82-
int riscv_of_processor_hartid(struct device_node *node);
83-
int riscv_of_parent_hartid(struct device_node *node);
82+
int riscv_of_processor_hartid(struct device_node *node, unsigned long *hartid);
83+
int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid);
8484

8585
extern void riscv_fill_hwcap(void);
8686
extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);

arch/riscv/kernel/cpu.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,36 @@
1414
* Returns the hart ID of the given device tree node, or -ENODEV if the node
1515
* isn't an enabled and valid RISC-V hart node.
1616
*/
17-
int riscv_of_processor_hartid(struct device_node *node)
17+
int riscv_of_processor_hartid(struct device_node *node, unsigned long *hart)
1818
{
1919
const char *isa;
20-
u32 hart;
2120

2221
if (!of_device_is_compatible(node, "riscv")) {
2322
pr_warn("Found incompatible CPU\n");
2423
return -ENODEV;
2524
}
2625

27-
hart = of_get_cpu_hwid(node, 0);
28-
if (hart == ~0U) {
26+
*hart = (unsigned long) of_get_cpu_hwid(node, 0);
27+
if (*hart == ~0UL) {
2928
pr_warn("Found CPU without hart ID\n");
3029
return -ENODEV;
3130
}
3231

3332
if (!of_device_is_available(node)) {
34-
pr_info("CPU with hartid=%d is not available\n", hart);
33+
pr_info("CPU with hartid=%lu is not available\n", *hart);
3534
return -ENODEV;
3635
}
3736

3837
if (of_property_read_string(node, "riscv,isa", &isa)) {
39-
pr_warn("CPU with hartid=%d has no \"riscv,isa\" property\n", hart);
38+
pr_warn("CPU with hartid=%lu has no \"riscv,isa\" property\n", *hart);
4039
return -ENODEV;
4140
}
4241
if (isa[0] != 'r' || isa[1] != 'v') {
43-
pr_warn("CPU with hartid=%d has an invalid ISA of \"%s\"\n", hart, isa);
42+
pr_warn("CPU with hartid=%lu has an invalid ISA of \"%s\"\n", *hart, isa);
4443
return -ENODEV;
4544
}
4645

47-
return hart;
46+
return 0;
4847
}
4948

5049
/*
@@ -53,11 +52,16 @@ int riscv_of_processor_hartid(struct device_node *node)
5352
* To achieve this, we walk up the DT tree until we find an active
5453
* RISC-V core (HART) node and extract the cpuid from it.
5554
*/
56-
int riscv_of_parent_hartid(struct device_node *node)
55+
int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid)
5756
{
57+
int rc;
58+
5859
for (; node; node = node->parent) {
59-
if (of_device_is_compatible(node, "riscv"))
60-
return riscv_of_processor_hartid(node);
60+
if (of_device_is_compatible(node, "riscv")) {
61+
rc = riscv_of_processor_hartid(node, hartid);
62+
if (!rc)
63+
return 0;
64+
}
6165
}
6266

6367
return -1;

arch/riscv/kernel/cpufeature.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ void __init riscv_fill_hwcap(void)
7373
struct device_node *node;
7474
const char *isa;
7575
char print_str[NUM_ALPHA_EXTS + 1];
76-
int i, j;
76+
int i, j, rc;
7777
static unsigned long isa2hwcap[256] = {0};
78+
unsigned long hartid;
7879

7980
isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
8081
isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
@@ -92,7 +93,8 @@ void __init riscv_fill_hwcap(void)
9293
DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX);
9394
const char *temp;
9495

95-
if (riscv_of_processor_hartid(node) < 0)
96+
rc = riscv_of_processor_hartid(node, &hartid);
97+
if (rc < 0)
9698
continue;
9799

98100
if (of_property_read_string(node, "riscv,isa", &isa)) {

arch/riscv/kernel/smpboot.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
7272
void __init setup_smp(void)
7373
{
7474
struct device_node *dn;
75-
int hart;
75+
unsigned long hart;
7676
bool found_boot_cpu = false;
7777
int cpuid = 1;
78+
int rc;
7879

7980
cpu_set_ops(0);
8081

8182
for_each_of_cpu_node(dn) {
82-
hart = riscv_of_processor_hartid(dn);
83-
if (hart < 0)
83+
rc = riscv_of_processor_hartid(dn, &hart);
84+
if (rc < 0)
8485
continue;
8586

8687
if (hart == cpuid_to_hartid_map(0)) {
@@ -90,7 +91,7 @@ void __init setup_smp(void)
9091
continue;
9192
}
9293
if (cpuid >= NR_CPUS) {
93-
pr_warn("Invalid cpuid [%d] for hartid [%d]\n",
94+
pr_warn("Invalid cpuid [%d] for hartid [%lu]\n",
9495
cpuid, hart);
9596
continue;
9697
}

drivers/clocksource/timer-riscv.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,21 @@ static irqreturn_t riscv_timer_interrupt(int irq, void *dev_id)
101101

102102
static int __init riscv_timer_init_dt(struct device_node *n)
103103
{
104-
int cpuid, hartid, error;
104+
int cpuid, error;
105+
unsigned long hartid;
105106
struct device_node *child;
106107
struct irq_domain *domain;
107108

108-
hartid = riscv_of_processor_hartid(n);
109-
if (hartid < 0) {
110-
pr_warn("Not valid hartid for node [%pOF] error = [%d]\n",
109+
error = riscv_of_processor_hartid(n, &hartid);
110+
if (error < 0) {
111+
pr_warn("Not valid hartid for node [%pOF] error = [%lu]\n",
111112
n, hartid);
112-
return hartid;
113+
return error;
113114
}
114115

115116
cpuid = riscv_hartid_to_cpuid(hartid);
116117
if (cpuid < 0) {
117-
pr_warn("Invalid cpuid for hartid [%d]\n", hartid);
118+
pr_warn("Invalid cpuid for hartid [%lu]\n", hartid);
118119
return cpuid;
119120
}
120121

@@ -140,7 +141,7 @@ static int __init riscv_timer_init_dt(struct device_node *n)
140141
return -ENODEV;
141142
}
142143

143-
pr_info("%s: Registering clocksource cpuid [%d] hartid [%d]\n",
144+
pr_info("%s: Registering clocksource cpuid [%d] hartid [%lu]\n",
144145
__func__, cpuid, hartid);
145146
error = clocksource_register_hz(&riscv_clocksource, riscv_timebase);
146147
if (error) {

drivers/irqchip/irq-riscv-intc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ static const struct irq_domain_ops riscv_intc_domain_ops = {
9595
static int __init riscv_intc_init(struct device_node *node,
9696
struct device_node *parent)
9797
{
98-
int rc, hartid;
98+
int rc;
99+
unsigned long hartid;
99100

100-
hartid = riscv_of_parent_hartid(node);
101-
if (hartid < 0) {
101+
rc = riscv_of_parent_hartid(node, &hartid);
102+
if (rc < 0) {
102103
pr_warn("unable to find hart id for %pOF\n", node);
103104
return 0;
104105
}

drivers/irqchip/irq-sifive-plic.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ static int __init plic_init(struct device_node *node,
317317
for (i = 0; i < nr_contexts; i++) {
318318
struct of_phandle_args parent;
319319
irq_hw_number_t hwirq;
320-
int cpu, hartid;
320+
int cpu;
321+
unsigned long hartid;
321322

322323
if (of_irq_parse_one(node, i, &parent)) {
323324
pr_err("failed to parse parent for context %d.\n", i);
@@ -341,8 +342,8 @@ static int __init plic_init(struct device_node *node,
341342
continue;
342343
}
343344

344-
hartid = riscv_of_parent_hartid(parent.np);
345-
if (hartid < 0) {
345+
error = riscv_of_parent_hartid(parent.np, &hartid);
346+
if (error < 0) {
346347
pr_warn("failed to parse hart ID for context %d.\n", i);
347348
continue;
348349
}

0 commit comments

Comments
 (0)