Skip to content

Commit efabefb

Browse files
valdaarhunstffrdhrn
authored andcommitted
openrisc: Refactor struct cpuinfo_or1k to reduce duplication
The "cpuinfo_or1k" structure currently has identical data members for different cache components. Remove these fields out of struct cpuinfo_or1k and into its own struct. This reduces duplication while keeping cpuinfo_or1k extensible so more cache descriptors can be added in the future. Also add a new field "sets" to the new structure. Signed-off-by: Sahil Siddiq <sahilcdq0@gmail.com> Signed-off-by: Stafford Horne <shorne@gmail.com>
1 parent 38fec10 commit efabefb

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

arch/openrisc/include/asm/cpuinfo.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
#ifndef __ASM_OPENRISC_CPUINFO_H
1616
#define __ASM_OPENRISC_CPUINFO_H
1717

18+
struct cache_desc {
19+
u32 size;
20+
u32 sets;
21+
u32 block_size;
22+
u32 ways;
23+
};
24+
1825
struct cpuinfo_or1k {
1926
u32 clock_frequency;
2027

21-
u32 icache_size;
22-
u32 icache_block_size;
23-
u32 icache_ways;
24-
25-
u32 dcache_size;
26-
u32 dcache_block_size;
27-
u32 dcache_ways;
28+
struct cache_desc icache;
29+
struct cache_desc dcache;
2830

2931
u16 coreid;
3032
};

arch/openrisc/kernel/setup.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ static void print_cpuinfo(void)
115115

116116
if (upr & SPR_UPR_DCP)
117117
printk(KERN_INFO
118-
"-- dcache: %4d bytes total, %2d bytes/line, %d way(s)\n",
119-
cpuinfo->dcache_size, cpuinfo->dcache_block_size,
120-
cpuinfo->dcache_ways);
118+
"-- dcache: %4d bytes total, %2d bytes/line, %d set(s), %d way(s)\n",
119+
cpuinfo->dcache.size, cpuinfo->dcache.block_size,
120+
cpuinfo->dcache.sets, cpuinfo->dcache.ways);
121121
else
122122
printk(KERN_INFO "-- dcache disabled\n");
123123
if (upr & SPR_UPR_ICP)
124124
printk(KERN_INFO
125-
"-- icache: %4d bytes total, %2d bytes/line, %d way(s)\n",
126-
cpuinfo->icache_size, cpuinfo->icache_block_size,
127-
cpuinfo->icache_ways);
125+
"-- icache: %4d bytes total, %2d bytes/line, %d set(s), %d way(s)\n",
126+
cpuinfo->icache.size, cpuinfo->icache.block_size,
127+
cpuinfo->icache.sets, cpuinfo->icache.ways);
128128
else
129129
printk(KERN_INFO "-- icache disabled\n");
130130

@@ -156,7 +156,6 @@ void __init setup_cpuinfo(void)
156156
{
157157
struct device_node *cpu;
158158
unsigned long iccfgr, dccfgr;
159-
unsigned long cache_set_size;
160159
int cpu_id = smp_processor_id();
161160
struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[cpu_id];
162161

@@ -165,18 +164,18 @@ void __init setup_cpuinfo(void)
165164
panic("Couldn't find CPU%d in device tree...\n", cpu_id);
166165

167166
iccfgr = mfspr(SPR_ICCFGR);
168-
cpuinfo->icache_ways = 1 << (iccfgr & SPR_ICCFGR_NCW);
169-
cache_set_size = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
170-
cpuinfo->icache_block_size = 16 << ((iccfgr & SPR_ICCFGR_CBS) >> 7);
171-
cpuinfo->icache_size =
172-
cache_set_size * cpuinfo->icache_ways * cpuinfo->icache_block_size;
167+
cpuinfo->icache.ways = 1 << (iccfgr & SPR_ICCFGR_NCW);
168+
cpuinfo->icache.sets = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
169+
cpuinfo->icache.block_size = 16 << ((iccfgr & SPR_ICCFGR_CBS) >> 7);
170+
cpuinfo->icache.size =
171+
cpuinfo->icache.sets * cpuinfo->icache.ways * cpuinfo->icache.block_size;
173172

174173
dccfgr = mfspr(SPR_DCCFGR);
175-
cpuinfo->dcache_ways = 1 << (dccfgr & SPR_DCCFGR_NCW);
176-
cache_set_size = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3);
177-
cpuinfo->dcache_block_size = 16 << ((dccfgr & SPR_DCCFGR_CBS) >> 7);
178-
cpuinfo->dcache_size =
179-
cache_set_size * cpuinfo->dcache_ways * cpuinfo->dcache_block_size;
174+
cpuinfo->dcache.ways = 1 << (dccfgr & SPR_DCCFGR_NCW);
175+
cpuinfo->dcache.sets = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3);
176+
cpuinfo->dcache.block_size = 16 << ((dccfgr & SPR_DCCFGR_CBS) >> 7);
177+
cpuinfo->dcache.size =
178+
cpuinfo->dcache.sets * cpuinfo->dcache.ways * cpuinfo->dcache.block_size;
180179

181180
if (of_property_read_u32(cpu, "clock-frequency",
182181
&cpuinfo->clock_frequency)) {
@@ -320,14 +319,14 @@ static int show_cpuinfo(struct seq_file *m, void *v)
320319
seq_printf(m, "revision\t\t: %d\n", vr & SPR_VR_REV);
321320
}
322321
seq_printf(m, "frequency\t\t: %ld\n", loops_per_jiffy * HZ);
323-
seq_printf(m, "dcache size\t\t: %d bytes\n", cpuinfo->dcache_size);
322+
seq_printf(m, "dcache size\t\t: %d bytes\n", cpuinfo->dcache.size);
324323
seq_printf(m, "dcache block size\t: %d bytes\n",
325-
cpuinfo->dcache_block_size);
326-
seq_printf(m, "dcache ways\t\t: %d\n", cpuinfo->dcache_ways);
327-
seq_printf(m, "icache size\t\t: %d bytes\n", cpuinfo->icache_size);
324+
cpuinfo->dcache.block_size);
325+
seq_printf(m, "dcache ways\t\t: %d\n", cpuinfo->dcache.ways);
326+
seq_printf(m, "icache size\t\t: %d bytes\n", cpuinfo->icache.size);
328327
seq_printf(m, "icache block size\t: %d bytes\n",
329-
cpuinfo->icache_block_size);
330-
seq_printf(m, "icache ways\t\t: %d\n", cpuinfo->icache_ways);
328+
cpuinfo->icache.block_size);
329+
seq_printf(m, "icache ways\t\t: %d\n", cpuinfo->icache.ways);
331330
seq_printf(m, "immu\t\t\t: %d entries, %lu ways\n",
332331
1 << ((mfspr(SPR_DMMUCFGR) & SPR_DMMUCFGR_NTS) >> 2),
333332
1 + (mfspr(SPR_DMMUCFGR) & SPR_DMMUCFGR_NTW));

0 commit comments

Comments
 (0)