Skip to content

Commit 5d451a8

Browse files
ozbenhmpe
authored andcommitted
powerpc/64: Retrieve number of L1 cache sets from device-tree
It will be used to calculate the associativity Signed-off-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent bd067f8 commit 5d451a8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

arch/powerpc/include/asm/cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ struct ppc64_caches {
3636
u32 dblock_size; /* L1 d-cache block size */
3737
u32 log_dblock_size;
3838
u32 dblocks_per_page;
39+
u32 dsets;
3940
u32 isize; /* L1 i-cache size */
4041
u32 iline_size; /* L1 d-cache line size */
4142
u32 iblock_size; /* L1 i-cache block size */
4243
u32 log_iblock_size;
4344
u32 iblocks_per_page;
45+
u32 isets;
4446
};
4547

4648
extern struct ppc64_caches ppc64_caches;

arch/powerpc/kernel/setup_64.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,18 @@ void __init initialize_cache_info(void)
412412
* d-cache and i-cache sizes... -Peter
413413
*/
414414
if (num_cpus == 1) {
415-
const __be32 *sizep, *lsizep, *bsizep;
416-
u32 size, lsize, bsize;
415+
const __be32 *sizep, *lsizep, *bsizep, *setsp;
416+
u32 size, lsize, bsize, sets;
417417

418418
size = 0;
419+
sets = -1u;
419420
lsize = bsize = cur_cpu_spec->dcache_bsize;
420421
sizep = of_get_property(np, "d-cache-size", NULL);
421422
if (sizep != NULL)
422423
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);
423427
bsizep = of_get_property(np, "d-cache-block-size",
424428
NULL);
425429
lsizep = of_get_property(np, "d-cache-line-size",
@@ -435,17 +439,32 @@ void __init initialize_cache_info(void)
435439
"sizep: %p, bsizep: %p, lsizep: %p\n",
436440
sizep, bsizep, lsizep);
437441

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;
438452
ppc64_caches.dsize = size;
453+
ppc64_caches.dsets = sets;
439454
ppc64_caches.dline_size = lsize;
440455
ppc64_caches.dblock_size = bsize;
441456
ppc64_caches.log_dblock_size = __ilog2(bsize);
442457
ppc64_caches.dblocks_per_page = PAGE_SIZE / bsize;
443458

444459
size = 0;
460+
sets = -1u;
445461
lsize = bsize = cur_cpu_spec->icache_bsize;
446462
sizep = of_get_property(np, "i-cache-size", NULL);
447463
if (sizep != NULL)
448464
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);
449468
bsizep = of_get_property(np, "i-cache-block-size",
450469
NULL);
451470
lsizep = of_get_property(np, "i-cache-line-size",
@@ -461,7 +480,12 @@ void __init initialize_cache_info(void)
461480
"sizep: %p, bsizep: %p, lsizep: %p\n",
462481
sizep, bsizep, lsizep);
463482

483+
if (sets == 1)
484+
sets = 0;
485+
else if (sets == 0)
486+
sets = 1;
464487
ppc64_caches.isize = size;
488+
ppc64_caches.isets = sets;
465489
ppc64_caches.iline_size = lsize;
466490
ppc64_caches.iblock_size = bsize;
467491
ppc64_caches.log_iblock_size = __ilog2(bsize);

0 commit comments

Comments
 (0)