Skip to content

Commit e2827fe

Browse files
ozbenhmpe
authored andcommitted
powerpc/64: Clean up ppc64_caches using a struct per cache
We have two set of identical struct members for the I and D sides and mostly identical bunches of code to parse the device-tree to populate them. Instead make a ppc_cache_info structure with one copy for I and one for D Signed-off-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 5d451a8 commit e2827fe

File tree

6 files changed

+119
-122
lines changed

6 files changed

+119
-122
lines changed

arch/powerpc/include/asm/cache.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030
#define IFETCH_ALIGN_BYTES (1 << IFETCH_ALIGN_SHIFT)
3131

3232
#if defined(__powerpc64__) && !defined(__ASSEMBLY__)
33+
34+
struct ppc_cache_info {
35+
u32 size;
36+
u32 line_size;
37+
u32 block_size; /* L1 only */
38+
u32 log_block_size;
39+
u32 blocks_per_page;
40+
u32 sets;
41+
};
42+
3343
struct ppc64_caches {
34-
u32 dsize; /* L1 d-cache size */
35-
u32 dline_size; /* L1 d-cache line size */
36-
u32 dblock_size; /* L1 d-cache block size */
37-
u32 log_dblock_size;
38-
u32 dblocks_per_page;
39-
u32 dsets;
40-
u32 isize; /* L1 i-cache size */
41-
u32 iline_size; /* L1 d-cache line size */
42-
u32 iblock_size; /* L1 i-cache block size */
43-
u32 log_iblock_size;
44-
u32 iblocks_per_page;
45-
u32 isets;
44+
struct ppc_cache_info l1d;
45+
struct ppc_cache_info l1i;
4646
};
4747

4848
extern struct ppc64_caches ppc64_caches;

arch/powerpc/include/asm/page_64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ static inline void clear_page(void *addr)
4747
unsigned long iterations;
4848
unsigned long onex, twox, fourx, eightx;
4949

50-
iterations = ppc64_caches.dblocks_per_page / 8;
50+
iterations = ppc64_caches.l1d.blocks_per_page / 8;
5151

5252
/*
5353
* Some verisions of gcc use multiply instructions to
5454
* calculate the offsets so lets give it a hand to
5555
* do better.
5656
*/
57-
onex = ppc64_caches.dblock_size;
57+
onex = ppc64_caches.l1d.block_size;
5858
twox = onex << 1;
5959
fourx = onex << 2;
6060
eightx = onex << 3;

arch/powerpc/kernel/align.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int emulate_dcbz(struct pt_regs *regs, unsigned char __user *addr)
204204
int i, size;
205205

206206
#ifdef __powerpc64__
207-
size = ppc64_caches.dblock_size;
207+
size = ppc64_caches.l1d.block_size;
208208
#else
209209
size = L1_CACHE_BYTES;
210210
#endif

arch/powerpc/kernel/asm-offsets.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ int main(void)
163163
DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
164164

165165
#ifdef CONFIG_PPC64
166-
DEFINE(DCACHEL1BLOCKSIZE, offsetof(struct ppc64_caches, dblock_size));
167-
DEFINE(DCACHEL1LOGBLOCKSIZE, offsetof(struct ppc64_caches, log_dblock_size));
168-
DEFINE(DCACHEL1BLOCKSPERPAGE, offsetof(struct ppc64_caches, dblocks_per_page));
169-
DEFINE(ICACHEL1BLOCKSIZE, offsetof(struct ppc64_caches, iblock_size));
170-
DEFINE(ICACHEL1LOGBLOCKSIZE, offsetof(struct ppc64_caches, log_iblock_size));
171-
DEFINE(ICACHEL1BLOCKSPERPAGE, offsetof(struct ppc64_caches, iblocks_per_page));
166+
DEFINE(DCACHEL1BLOCKSIZE, offsetof(struct ppc64_caches, l1d.block_size));
167+
DEFINE(DCACHEL1LOGBLOCKSIZE, offsetof(struct ppc64_caches, l1d.log_block_size));
168+
DEFINE(DCACHEL1BLOCKSPERPAGE, offsetof(struct ppc64_caches, l1d.blocks_per_page));
169+
DEFINE(ICACHEL1BLOCKSIZE, offsetof(struct ppc64_caches, l1i.block_size));
170+
DEFINE(ICACHEL1LOGBLOCKSIZE, offsetof(struct ppc64_caches, l1i.log_block_size));
171+
DEFINE(ICACHEL1BLOCKSPERPAGE, offsetof(struct ppc64_caches, l1i.blocks_per_page));
172172
/* paca */
173173
DEFINE(PACA_SIZE, sizeof(struct paca_struct));
174174
DEFINE(PACAPACAINDEX, offsetof(struct paca_struct, paca_index));

arch/powerpc/kernel/setup_64.c

Lines changed: 90 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ int spinning_secondaries;
7878
u64 ppc64_pft_size;
7979

8080
struct ppc64_caches ppc64_caches = {
81-
.dblock_size = 0x40,
82-
.log_dblock_size = 6,
83-
.iblock_size = 0x40,
84-
.log_iblock_size = 6
81+
.l1d = {
82+
.block_size = 0x40,
83+
.log_block_size = 6,
84+
},
85+
.l1i = {
86+
.block_size = 0x40,
87+
.log_block_size = 6
88+
},
8589
};
8690
EXPORT_SYMBOL_GPL(ppc64_caches);
8791

@@ -397,105 +401,98 @@ void smp_release_cpus(void)
397401
* cache informations about the CPU that will be used by cache flush
398402
* routines and/or provided to userland
399403
*/
404+
405+
static void init_cache_info(struct ppc_cache_info *info, u32 size, u32 lsize,
406+
u32 bsize, u32 sets)
407+
{
408+
info->size = size;
409+
info->sets = sets;
410+
info->line_size = lsize;
411+
info->block_size = bsize;
412+
info->log_block_size = __ilog2(bsize);
413+
info->blocks_per_page = PAGE_SIZE / bsize;
414+
}
415+
416+
static bool __init parse_cache_info(struct device_node *np,
417+
bool icache,
418+
struct ppc_cache_info *info)
419+
{
420+
static const char *ipropnames[] __initdata = {
421+
"i-cache-size",
422+
"i-cache-sets",
423+
"i-cache-block-size",
424+
"i-cache-line-size",
425+
};
426+
static const char *dpropnames[] __initdata = {
427+
"d-cache-size",
428+
"d-cache-sets",
429+
"d-cache-block-size",
430+
"d-cache-line-size",
431+
};
432+
const char **propnames = icache ? ipropnames : dpropnames;
433+
const __be32 *sizep, *lsizep, *bsizep, *setsp;
434+
u32 size, lsize, bsize, sets;
435+
bool success = true;
436+
437+
size = 0;
438+
sets = -1u;
439+
lsize = bsize = cur_cpu_spec->dcache_bsize;
440+
sizep = of_get_property(np, propnames[0], NULL);
441+
if (sizep != NULL)
442+
size = be32_to_cpu(*sizep);
443+
setsp = of_get_property(np, propnames[1], NULL);
444+
if (setsp != NULL)
445+
sets = be32_to_cpu(*setsp);
446+
bsizep = of_get_property(np, propnames[2], NULL);
447+
lsizep = of_get_property(np, propnames[3], NULL);
448+
if (bsizep == NULL)
449+
bsizep = lsizep;
450+
if (lsizep != NULL)
451+
lsize = be32_to_cpu(*lsizep);
452+
if (bsizep != NULL)
453+
bsize = be32_to_cpu(*bsizep);
454+
if (sizep == NULL || bsizep == NULL || lsizep == NULL)
455+
success = false;
456+
457+
/*
458+
* OF is weird .. it represents fully associative caches
459+
* as "1 way" which doesn't make much sense and doesn't
460+
* leave room for direct mapped. We'll assume that 0
461+
* in OF means direct mapped for that reason.
462+
*/
463+
if (sets == 1)
464+
sets = 0;
465+
else if (sets == 0)
466+
sets = 1;
467+
468+
init_cache_info(info, size, lsize, bsize, sets);
469+
470+
return success;
471+
}
472+
400473
void __init initialize_cache_info(void)
401474
{
402475
struct device_node *np;
403-
unsigned long num_cpus = 0;
404476

405477
DBG(" -> initialize_cache_info()\n");
406478

407-
for_each_node_by_type(np, "cpu") {
408-
num_cpus += 1;
479+
np = of_find_node_by_type(NULL, "cpu");
409480

410-
/*
411-
* We're assuming *all* of the CPUs have the same
412-
* d-cache and i-cache sizes... -Peter
413-
*/
414-
if (num_cpus == 1) {
415-
const __be32 *sizep, *lsizep, *bsizep, *setsp;
416-
u32 size, lsize, bsize, sets;
417-
418-
size = 0;
419-
sets = -1u;
420-
lsize = bsize = cur_cpu_spec->dcache_bsize;
421-
sizep = of_get_property(np, "d-cache-size", NULL);
422-
if (sizep != NULL)
423-
size = be32_to_cpu(*sizep);
424-
setsp = of_get_property(np, "d-cache-sets", NULL);
425-
if (setsp != NULL)
426-
sets = be32_to_cpu(*setsp);
427-
bsizep = of_get_property(np, "d-cache-block-size",
428-
NULL);
429-
lsizep = of_get_property(np, "d-cache-line-size",
430-
NULL);
431-
if (bsizep == NULL)
432-
bsizep = lsizep;
433-
if (lsizep != NULL)
434-
lsize = be32_to_cpu(*lsizep);
435-
if (bsizep != NULL)
436-
bsize = be32_to_cpu(*bsizep);
437-
if (sizep == NULL || bsizep == NULL || lsizep == NULL)
438-
DBG("Argh, can't find dcache properties ! "
439-
"sizep: %p, bsizep: %p, lsizep: %p\n",
440-
sizep, bsizep, lsizep);
441-
442-
/*
443-
* OF is weird .. it represents fully associative caches
444-
* as "1 way" which doesn't make much sense and doesn't
445-
* leave room for direct mapped. We'll assume that 0
446-
* in OF means direct mapped for that reason.
447-
*/
448-
if (sets == 1)
449-
sets = 0;
450-
else if (sets == 0)
451-
sets = 1;
452-
ppc64_caches.dsize = size;
453-
ppc64_caches.dsets = sets;
454-
ppc64_caches.dline_size = lsize;
455-
ppc64_caches.dblock_size = bsize;
456-
ppc64_caches.log_dblock_size = __ilog2(bsize);
457-
ppc64_caches.dblocks_per_page = PAGE_SIZE / bsize;
458-
459-
size = 0;
460-
sets = -1u;
461-
lsize = bsize = cur_cpu_spec->icache_bsize;
462-
sizep = of_get_property(np, "i-cache-size", NULL);
463-
if (sizep != NULL)
464-
size = be32_to_cpu(*sizep);
465-
setsp = of_get_property(np, "i-cache-sets", NULL);
466-
if (setsp != NULL)
467-
sets = be32_to_cpu(*setsp);
468-
bsizep = of_get_property(np, "i-cache-block-size",
469-
NULL);
470-
lsizep = of_get_property(np, "i-cache-line-size",
471-
NULL);
472-
if (bsizep == NULL)
473-
bsizep = lsizep;
474-
if (lsizep != NULL)
475-
lsize = be32_to_cpu(*lsizep);
476-
if (bsizep != NULL)
477-
bsize = be32_to_cpu(*bsizep);
478-
if (sizep == NULL || bsizep == NULL || lsizep == NULL)
479-
DBG("Argh, can't find icache properties ! "
480-
"sizep: %p, bsizep: %p, lsizep: %p\n",
481-
sizep, bsizep, lsizep);
482-
483-
if (sets == 1)
484-
sets = 0;
485-
else if (sets == 0)
486-
sets = 1;
487-
ppc64_caches.isize = size;
488-
ppc64_caches.isets = sets;
489-
ppc64_caches.iline_size = lsize;
490-
ppc64_caches.iblock_size = bsize;
491-
ppc64_caches.log_iblock_size = __ilog2(bsize);
492-
ppc64_caches.iblocks_per_page = PAGE_SIZE / bsize;
493-
}
481+
/*
482+
* We're assuming *all* of the CPUs have the same
483+
* d-cache and i-cache sizes... -Peter
484+
*/
485+
if (np) {
486+
if (!parse_cache_info(np, false, &ppc64_caches.l1d))
487+
DBG("Argh, can't find dcache properties !\n");
488+
489+
if (!parse_cache_info(np, true, &ppc64_caches.l1i))
490+
DBG("Argh, can't find icache properties !\n");
494491
}
495492

496493
/* For use by binfmt_elf */
497-
dcache_bsize = ppc64_caches.dblock_size;
498-
icache_bsize = ppc64_caches.iblock_size;
494+
dcache_bsize = ppc64_caches.l1d.block_size;
495+
icache_bsize = ppc64_caches.l1i.block_size;
499496

500497
DBG(" <- initialize_cache_info()\n");
501498
}

arch/powerpc/kernel/vdso.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,14 @@ static int __init vdso_init(void)
736736
if (firmware_has_feature(FW_FEATURE_LPAR))
737737
vdso_data->platform |= 1;
738738
vdso_data->physicalMemorySize = memblock_phys_mem_size();
739-
vdso_data->dcache_size = ppc64_caches.dsize;
740-
vdso_data->dcache_line_size = ppc64_caches.dline_size;
741-
vdso_data->icache_size = ppc64_caches.isize;
742-
vdso_data->icache_line_size = ppc64_caches.iline_size;
743-
vdso_data->dcache_block_size = ppc64_caches.dblock_size;
744-
vdso_data->icache_block_size = ppc64_caches.iblock_size;
745-
vdso_data->dcache_log_block_size = ppc64_caches.log_dblock_size;
746-
vdso_data->icache_log_block_size = ppc64_caches.log_iblock_size;
739+
vdso_data->dcache_size = ppc64_caches.l1d.size;
740+
vdso_data->dcache_line_size = ppc64_caches.l1d.line_size;
741+
vdso_data->icache_size = ppc64_caches.l1i.size;
742+
vdso_data->icache_line_size = ppc64_caches.l1i.line_size;
743+
vdso_data->dcache_block_size = ppc64_caches.l1d.block_size;
744+
vdso_data->icache_block_size = ppc64_caches.l1i.block_size;
745+
vdso_data->dcache_log_block_size = ppc64_caches.l1d.log_block_size;
746+
vdso_data->icache_log_block_size = ppc64_caches.l1i.log_block_size;
747747

748748
/*
749749
* Calculate the size of the 64 bits vDSO

0 commit comments

Comments
 (0)