@@ -293,6 +293,13 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax,
293293 (ebx -> split .ways_of_associativity + 1 ) - 1 ;
294294}
295295
296+ struct _cache_attr {
297+ struct attribute attr ;
298+ ssize_t (* show )(struct _cpuid4_info * , char * );
299+ ssize_t (* store )(struct _cpuid4_info * , const char * , size_t count );
300+ };
301+
302+ #ifdef CONFIG_CPU_SUP_AMD
296303static unsigned int __cpuinit amd_calc_l3_indices (void )
297304{
298305 /*
@@ -303,7 +310,7 @@ static unsigned int __cpuinit amd_calc_l3_indices(void)
303310 int node = cpu_to_node (cpu );
304311 struct pci_dev * dev = node_to_k8_nb_misc (node );
305312 unsigned int sc0 , sc1 , sc2 , sc3 ;
306- u32 val ;
313+ u32 val = 0 ;
307314
308315 pci_read_config_dword (dev , 0x1C4 , & val );
309316
@@ -335,6 +342,94 @@ amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf)
335342 this_leaf -> l3_indices = amd_calc_l3_indices ();
336343}
337344
345+ static ssize_t show_cache_disable (struct _cpuid4_info * this_leaf , char * buf ,
346+ unsigned int index )
347+ {
348+ int cpu = cpumask_first (to_cpumask (this_leaf -> shared_cpu_map ));
349+ int node = amd_get_nb_id (cpu );
350+ struct pci_dev * dev = node_to_k8_nb_misc (node );
351+ unsigned int reg = 0 ;
352+
353+ if (!this_leaf -> can_disable )
354+ return - EINVAL ;
355+
356+ if (!dev )
357+ return - EINVAL ;
358+
359+ pci_read_config_dword (dev , 0x1BC + index * 4 , & reg );
360+ return sprintf (buf , "0x%08x\n" , reg );
361+ }
362+
363+ #define SHOW_CACHE_DISABLE (index ) \
364+ static ssize_t \
365+ show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \
366+ { \
367+ return show_cache_disable(this_leaf, buf, index); \
368+ }
369+ SHOW_CACHE_DISABLE (0 )
370+ SHOW_CACHE_DISABLE (1 )
371+
372+ static ssize_t store_cache_disable (struct _cpuid4_info * this_leaf ,
373+ const char * buf , size_t count , unsigned int index )
374+ {
375+ int cpu = cpumask_first (to_cpumask (this_leaf -> shared_cpu_map ));
376+ int node = amd_get_nb_id (cpu );
377+ struct pci_dev * dev = node_to_k8_nb_misc (node );
378+ unsigned long val = 0 ;
379+
380+ #define SUBCACHE_MASK (3UL << 20)
381+ #define SUBCACHE_INDEX 0xfff
382+
383+ if (!this_leaf -> can_disable )
384+ return - EINVAL ;
385+
386+ if (!capable (CAP_SYS_ADMIN ))
387+ return - EPERM ;
388+
389+ if (!dev )
390+ return - EINVAL ;
391+
392+ if (strict_strtoul (buf , 10 , & val ) < 0 )
393+ return - EINVAL ;
394+
395+ /* do not allow writes outside of allowed bits */
396+ if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX )) ||
397+ ((val & SUBCACHE_INDEX ) > this_leaf -> l3_indices ))
398+ return - EINVAL ;
399+
400+ val |= BIT (30 );
401+ pci_write_config_dword (dev , 0x1BC + index * 4 , val );
402+ /*
403+ * We need to WBINVD on a core on the node containing the L3 cache which
404+ * indices we disable therefore a simple wbinvd() is not sufficient.
405+ */
406+ wbinvd_on_cpu (cpu );
407+ pci_write_config_dword (dev , 0x1BC + index * 4 , val | BIT (31 ));
408+ return count ;
409+ }
410+
411+ #define STORE_CACHE_DISABLE (index ) \
412+ static ssize_t \
413+ store_cache_disable_##index(struct _cpuid4_info *this_leaf, \
414+ const char *buf, size_t count) \
415+ { \
416+ return store_cache_disable(this_leaf, buf, count, index); \
417+ }
418+ STORE_CACHE_DISABLE (0 )
419+ STORE_CACHE_DISABLE (1 )
420+
421+ static struct _cache_attr cache_disable_0 = __ATTR (cache_disable_0 , 0644 ,
422+ show_cache_disable_0 , store_cache_disable_0 );
423+ static struct _cache_attr cache_disable_1 = __ATTR (cache_disable_1 , 0644 ,
424+ show_cache_disable_1 , store_cache_disable_1 );
425+
426+ #else /* CONFIG_CPU_SUP_AMD */
427+ static void __cpuinit
428+ amd_check_l3_disable (int index , struct _cpuid4_info_regs * this_leaf )
429+ {
430+ };
431+ #endif /* CONFIG_CPU_SUP_AMD */
432+
338433static int
339434__cpuinit cpuid4_cache_lookup_regs (int index ,
340435 struct _cpuid4_info_regs * this_leaf )
@@ -740,88 +835,6 @@ static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf)
740835#define to_object (k ) container_of(k, struct _index_kobject, kobj)
741836#define to_attr (a ) container_of(a, struct _cache_attr, attr)
742837
743- static ssize_t show_cache_disable (struct _cpuid4_info * this_leaf , char * buf ,
744- unsigned int index )
745- {
746- int cpu = cpumask_first (to_cpumask (this_leaf -> shared_cpu_map ));
747- int node = amd_get_nb_id (cpu );
748- struct pci_dev * dev = node_to_k8_nb_misc (node );
749- unsigned int reg = 0 ;
750-
751- if (!this_leaf -> can_disable )
752- return - EINVAL ;
753-
754- if (!dev )
755- return - EINVAL ;
756-
757- pci_read_config_dword (dev , 0x1BC + index * 4 , & reg );
758- return sprintf (buf , "0x%08x\n" , reg );
759- }
760-
761- #define SHOW_CACHE_DISABLE (index ) \
762- static ssize_t \
763- show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \
764- { \
765- return show_cache_disable(this_leaf, buf, index); \
766- }
767- SHOW_CACHE_DISABLE (0 )
768- SHOW_CACHE_DISABLE (1 )
769-
770- static ssize_t store_cache_disable (struct _cpuid4_info * this_leaf ,
771- const char * buf , size_t count , unsigned int index )
772- {
773- int cpu = cpumask_first (to_cpumask (this_leaf -> shared_cpu_map ));
774- int node = amd_get_nb_id (cpu );
775- struct pci_dev * dev = node_to_k8_nb_misc (node );
776- unsigned long val = 0 ;
777-
778- #define SUBCACHE_MASK (3UL << 20)
779- #define SUBCACHE_INDEX 0xfff
780-
781- if (!this_leaf -> can_disable )
782- return - EINVAL ;
783-
784- if (!capable (CAP_SYS_ADMIN ))
785- return - EPERM ;
786-
787- if (!dev )
788- return - EINVAL ;
789-
790- if (strict_strtoul (buf , 10 , & val ) < 0 )
791- return - EINVAL ;
792-
793- /* do not allow writes outside of allowed bits */
794- if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX )) ||
795- ((val & SUBCACHE_INDEX ) > this_leaf -> l3_indices ))
796- return - EINVAL ;
797-
798- val |= BIT (30 );
799- pci_write_config_dword (dev , 0x1BC + index * 4 , val );
800- /*
801- * We need to WBINVD on a core on the node containing the L3 cache which
802- * indices we disable therefore a simple wbinvd() is not sufficient.
803- */
804- wbinvd_on_cpu (cpu );
805- pci_write_config_dword (dev , 0x1BC + index * 4 , val | BIT (31 ));
806- return count ;
807- }
808-
809- #define STORE_CACHE_DISABLE (index ) \
810- static ssize_t \
811- store_cache_disable_##index(struct _cpuid4_info *this_leaf, \
812- const char *buf, size_t count) \
813- { \
814- return store_cache_disable(this_leaf, buf, count, index); \
815- }
816- STORE_CACHE_DISABLE (0 )
817- STORE_CACHE_DISABLE (1 )
818-
819- struct _cache_attr {
820- struct attribute attr ;
821- ssize_t (* show )(struct _cpuid4_info * , char * );
822- ssize_t (* store )(struct _cpuid4_info * , const char * , size_t count );
823- };
824-
825838#define define_one_ro (_name ) \
826839static struct _cache_attr _name = \
827840 __ATTR(_name, 0444, show_##_name, NULL)
@@ -836,11 +849,6 @@ define_one_ro(size);
836849define_one_ro (shared_cpu_map );
837850define_one_ro (shared_cpu_list );
838851
839- static struct _cache_attr cache_disable_0 = __ATTR (cache_disable_0 , 0644 ,
840- show_cache_disable_0 , store_cache_disable_0 );
841- static struct _cache_attr cache_disable_1 = __ATTR (cache_disable_1 , 0644 ,
842- show_cache_disable_1 , store_cache_disable_1 );
843-
844852#define DEFAULT_SYSFS_CACHE_ATTRS \
845853 &type.attr, \
846854 &level.attr, \
@@ -859,8 +867,10 @@ static struct attribute *default_attrs[] = {
859867
860868static struct attribute * default_l3_attrs [] = {
861869 DEFAULT_SYSFS_CACHE_ATTRS ,
870+ #ifdef CONFIG_CPU_SUP_AMD
862871 & cache_disable_0 .attr ,
863872 & cache_disable_1 .attr ,
873+ #endif
864874 NULL
865875};
866876
0 commit comments