Skip to content

Commit 999b112

Browse files
committed
hw/intc/loongson_ipi: Add more input parameter for cpu_by_arch_id
Add logic cpu index input parameter for function cpu_by_arch_id, CPUState::cpu_index is logic cpu slot index for possible_cpus. At the same time it is logic index with LoongsonIPICommonState::IPICore, here hide access for CPUState::cpu_index directly, it comes from function cpu_by_arch_id(). Signed-off-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
1 parent 1b3aa34 commit 999b112

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

hw/intc/loongarch_ipi.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,28 @@ static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id)
3838
return found_cpu;
3939
}
4040

41-
static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id)
41+
static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics,
42+
int64_t arch_id, int *index, CPUState **pcs)
4243
{
4344
MachineState *machine = MACHINE(qdev_get_machine());
4445
CPUArchId *archid;
46+
CPUState *cs;
4547

4648
archid = find_cpu_by_archid(machine, arch_id);
47-
if (archid) {
48-
return CPU(archid->cpu);
49+
if (archid && archid->cpu) {
50+
cs = archid->cpu;
51+
if (index) {
52+
*index = cs->cpu_index;
53+
}
54+
55+
if (pcs) {
56+
*pcs = cs;
57+
}
58+
59+
return MEMTX_OK;
4960
}
5061

51-
return NULL;
62+
return MEMTX_ERROR;
5263
}
5364

5465
static void loongarch_ipi_realize(DeviceState *dev, Error **errp)

hw/intc/loongson_ipi.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ static AddressSpace *get_iocsr_as(CPUState *cpu)
2020
return NULL;
2121
}
2222

23+
static int loongson_cpu_by_arch_id(LoongsonIPICommonState *lics,
24+
int64_t arch_id, int *index, CPUState **pcs)
25+
{
26+
CPUState *cs;
27+
28+
cs = cpu_by_arch_id(arch_id);
29+
if (cs == NULL) {
30+
return MEMTX_ERROR;
31+
}
32+
33+
if (index) {
34+
*index = cs->cpu_index;
35+
}
36+
37+
if (pcs) {
38+
*pcs = cs;
39+
}
40+
41+
return MEMTX_OK;
42+
}
43+
2344
static const MemoryRegionOps loongson_ipi_core_ops = {
2445
.read_with_attrs = loongson_ipi_core_readl,
2546
.write_with_attrs = loongson_ipi_core_writel,
@@ -92,7 +113,7 @@ static void loongson_ipi_class_init(ObjectClass *klass, void *data)
92113
&lic->parent_unrealize);
93114
device_class_set_props(dc, loongson_ipi_properties);
94115
licc->get_iocsr_as = get_iocsr_as;
95-
licc->cpu_by_arch_id = cpu_by_arch_id;
116+
licc->cpu_by_arch_id = loongson_cpu_by_arch_id;
96117
}
97118

98119
static const TypeInfo loongson_ipi_types[] = {

hw/intc/loongson_ipi_common.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,17 @@ static MemTxResult mail_send(LoongsonIPICommonState *ipi,
103103
uint32_t cpuid;
104104
hwaddr addr;
105105
CPUState *cs;
106+
int cpu, ret;
106107

107108
cpuid = extract32(val, 16, 10);
108-
cs = licc->cpu_by_arch_id(cpuid);
109-
if (cs == NULL) {
109+
ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs);
110+
if (ret != MEMTX_OK) {
110111
return MEMTX_DECODE_ERROR;
111112
}
112113

113114
/* override requester_id */
114115
addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c);
115-
attrs.requester_id = cs->cpu_index;
116+
attrs.requester_id = cpu;
116117
return send_ipi_data(ipi, cs, val, addr, attrs);
117118
}
118119

@@ -123,16 +124,17 @@ static MemTxResult any_send(LoongsonIPICommonState *ipi,
123124
uint32_t cpuid;
124125
hwaddr addr;
125126
CPUState *cs;
127+
int cpu, ret;
126128

127129
cpuid = extract32(val, 16, 10);
128-
cs = licc->cpu_by_arch_id(cpuid);
129-
if (cs == NULL) {
130+
ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs);
131+
if (ret != MEMTX_OK) {
130132
return MEMTX_DECODE_ERROR;
131133
}
132134

133135
/* override requester_id */
134136
addr = val & 0xffff;
135-
attrs.requester_id = cs->cpu_index;
137+
attrs.requester_id = cpu;
136138
return send_ipi_data(ipi, cs, val, addr, attrs);
137139
}
138140

@@ -146,6 +148,7 @@ MemTxResult loongson_ipi_core_writel(void *opaque, hwaddr addr, uint64_t val,
146148
uint32_t cpuid;
147149
uint8_t vector;
148150
CPUState *cs;
151+
int cpu, ret;
149152

150153
addr &= 0xff;
151154
trace_loongson_ipi_write(size, (uint64_t)addr, val);
@@ -176,11 +179,11 @@ MemTxResult loongson_ipi_core_writel(void *opaque, hwaddr addr, uint64_t val,
176179
cpuid = extract32(val, 16, 10);
177180
/* IPI status vector */
178181
vector = extract8(val, 0, 5);
179-
cs = licc->cpu_by_arch_id(cpuid);
180-
if (cs == NULL || cs->cpu_index >= ipi->num_cpu) {
182+
ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs);
183+
if (ret != MEMTX_OK || cpu >= ipi->num_cpu) {
181184
return MEMTX_DECODE_ERROR;
182185
}
183-
loongson_ipi_core_writel(&ipi->cpu[cs->cpu_index], CORE_SET_OFF,
186+
loongson_ipi_core_writel(&ipi->cpu[cpu], CORE_SET_OFF,
184187
BIT(vector), 4, attrs);
185188
break;
186189
default:

include/hw/intc/loongson_ipi_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ struct LoongsonIPICommonClass {
4646
DeviceRealize parent_realize;
4747
DeviceUnrealize parent_unrealize;
4848
AddressSpace *(*get_iocsr_as)(CPUState *cpu);
49-
CPUState *(*cpu_by_arch_id)(int64_t id);
49+
int (*cpu_by_arch_id)(LoongsonIPICommonState *lics, int64_t id,
50+
int *index, CPUState **pcs);
5051
};
5152

5253
MemTxResult loongson_ipi_core_readl(void *opaque, hwaddr addr, uint64_t *data,

0 commit comments

Comments
 (0)