@@ -78,10 +78,14 @@ int spinning_secondaries;
78
78
u64 ppc64_pft_size ;
79
79
80
80
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
+ },
85
89
};
86
90
EXPORT_SYMBOL_GPL (ppc64_caches );
87
91
@@ -397,105 +401,98 @@ void smp_release_cpus(void)
397
401
* cache informations about the CPU that will be used by cache flush
398
402
* routines and/or provided to userland
399
403
*/
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
+
400
473
void __init initialize_cache_info (void )
401
474
{
402
475
struct device_node * np ;
403
- unsigned long num_cpus = 0 ;
404
476
405
477
DBG (" -> initialize_cache_info()\n" );
406
478
407
- for_each_node_by_type (np , "cpu" ) {
408
- num_cpus += 1 ;
479
+ np = of_find_node_by_type (NULL , "cpu" );
409
480
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" );
494
491
}
495
492
496
493
/* 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 ;
499
496
500
497
DBG (" <- initialize_cache_info()\n" );
501
498
}
0 commit comments