~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to arch/x86/kernel/cpu/intel_cacheinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
304
304
 
305
305
struct _cache_attr {
306
306
        struct attribute attr;
307
 
        ssize_t (*show)(struct _cpuid4_info *, char *);
308
 
        ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count);
 
307
        ssize_t (*show)(struct _cpuid4_info *, char *, unsigned int);
 
308
        ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count,
 
309
                         unsigned int);
309
310
};
310
311
 
311
312
#ifdef CONFIG_AMD_NB
326
327
        l3->subcaches[2] = sc2 = !(val & BIT(8))  + !(val & BIT(9));
327
328
        l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13));
328
329
 
329
 
        l3->indices = (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1;
330
330
        l3->indices = (max(max3(sc0, sc1, sc2), sc3) << 10) - 1;
331
331
}
332
332
 
400
400
 
401
401
#define SHOW_CACHE_DISABLE(slot)                                        \
402
402
static ssize_t                                                          \
403
 
show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf)    \
 
403
show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf,    \
 
404
                          unsigned int cpu)                             \
404
405
{                                                                       \
405
406
        return show_cache_disable(this_leaf, buf, slot);                \
406
407
}
452
453
{
453
454
        int ret = 0;
454
455
 
455
 
#define SUBCACHE_MASK   (3UL << 20)
456
 
#define SUBCACHE_INDEX  0xfff
457
 
 
458
 
        /*
459
 
         * check whether this slot is already used or
460
 
         * the index is already disabled
461
 
         */
 
456
        /*  check if @slot is already used or the index is already disabled */
462
457
        ret = amd_get_l3_disable_slot(l3, slot);
463
458
        if (ret >= 0)
464
459
                return -EINVAL;
465
460
 
466
 
        /*
467
 
         * check whether the other slot has disabled the
468
 
         * same index already
469
 
         */
 
461
        if (index > l3->indices)
 
462
                return -EINVAL;
 
463
 
 
464
        /* check whether the other slot has disabled the same index already */
470
465
        if (index == amd_get_l3_disable_slot(l3, !slot))
471
466
                return -EINVAL;
472
467
 
473
 
        /* do not allow writes outside of allowed bits */
474
 
        if ((index & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) ||
475
 
            ((index & SUBCACHE_INDEX) > l3->indices))
476
 
                return -EINVAL;
477
 
 
478
468
        amd_l3_disable_index(l3, cpu, slot, index);
479
469
 
480
470
        return 0;
512
502
#define STORE_CACHE_DISABLE(slot)                                       \
513
503
static ssize_t                                                          \
514
504
store_cache_disable_##slot(struct _cpuid4_info *this_leaf,              \
515
 
                           const char *buf, size_t count)               \
 
505
                           const char *buf, size_t count,               \
 
506
                           unsigned int cpu)                            \
516
507
{                                                                       \
517
508
        return store_cache_disable(this_leaf, buf, count, slot);        \
518
509
}
524
515
static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644,
525
516
                show_cache_disable_1, store_cache_disable_1);
526
517
 
 
518
static ssize_t
 
519
show_subcaches(struct _cpuid4_info *this_leaf, char *buf, unsigned int cpu)
 
520
{
 
521
        if (!this_leaf->l3 || !amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
 
522
                return -EINVAL;
 
523
 
 
524
        return sprintf(buf, "%x\n", amd_get_subcaches(cpu));
 
525
}
 
526
 
 
527
static ssize_t
 
528
store_subcaches(struct _cpuid4_info *this_leaf, const char *buf, size_t count,
 
529
                unsigned int cpu)
 
530
{
 
531
        unsigned long val;
 
532
 
 
533
        if (!capable(CAP_SYS_ADMIN))
 
534
                return -EPERM;
 
535
 
 
536
        if (!this_leaf->l3 || !amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
 
537
                return -EINVAL;
 
538
 
 
539
        if (strict_strtoul(buf, 16, &val) < 0)
 
540
                return -EINVAL;
 
541
 
 
542
        if (amd_set_subcaches(cpu, val))
 
543
                return -EINVAL;
 
544
 
 
545
        return count;
 
546
}
 
547
 
 
548
static struct _cache_attr subcaches =
 
549
        __ATTR(subcaches, 0644, show_subcaches, store_subcaches);
 
550
 
527
551
#else   /* CONFIG_AMD_NB */
528
552
#define amd_init_l3_cache(x, y)
529
553
#endif /* CONFIG_AMD_NB */
532
556
__cpuinit cpuid4_cache_lookup_regs(int index,
533
557
                                   struct _cpuid4_info_regs *this_leaf)
534
558
{
535
 
        union _cpuid4_leaf_eax  eax;
536
 
        union _cpuid4_leaf_ebx  ebx;
537
 
        union _cpuid4_leaf_ecx  ecx;
 
559
        union _cpuid4_leaf_eax  eax;
 
560
        union _cpuid4_leaf_ebx  ebx;
 
561
        union _cpuid4_leaf_ecx  ecx;
538
562
        unsigned                edx;
539
563
 
540
564
        if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
732
756
        struct cpuinfo_x86 *c = &cpu_data(cpu);
733
757
 
734
758
        if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) {
735
 
                for_each_cpu(i, c->llc_shared_map) {
 
759
                for_each_cpu(i, cpu_llc_shared_mask(cpu)) {
736
760
                        if (!per_cpu(ici_cpuid4_info, i))
737
761
                                continue;
738
762
                        this_leaf = CPUID4_INFO_IDX(i, index);
739
 
                        for_each_cpu(sibling, c->llc_shared_map) {
 
763
                        for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) {
740
764
                                if (!cpu_online(sibling))
741
765
                                        continue;
742
766
                                set_bit(sibling, this_leaf->shared_cpu_map);
870
894
#define INDEX_KOBJECT_PTR(x, y)         (&((per_cpu(ici_index_kobject, x))[y]))
871
895
 
872
896
#define show_one_plus(file_name, object, val)                           \
873
 
static ssize_t show_##file_name                                         \
874
 
                        (struct _cpuid4_info *this_leaf, char *buf)     \
 
897
static ssize_t show_##file_name(struct _cpuid4_info *this_leaf, char *buf, \
 
898
                                unsigned int cpu)                       \
875
899
{                                                                       \
876
900
        return sprintf(buf, "%lu\n", (unsigned long)this_leaf->object + val); \
877
901
}
882
906
show_one_plus(ways_of_associativity, ebx.split.ways_of_associativity, 1);
883
907
show_one_plus(number_of_sets, ecx.split.number_of_sets, 1);
884
908
 
885
 
static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf)
 
909
static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf,
 
910
                         unsigned int cpu)
886
911
{
887
912
        return sprintf(buf, "%luK\n", this_leaf->size / 1024);
888
913
}
906
931
        return n;
907
932
}
908
933
 
909
 
static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf)
 
934
static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf,
 
935
                                          unsigned int cpu)
910
936
{
911
937
        return show_shared_cpu_map_func(leaf, 0, buf);
912
938
}
913
939
 
914
 
static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf)
 
940
static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf,
 
941
                                           unsigned int cpu)
915
942
{
916
943
        return show_shared_cpu_map_func(leaf, 1, buf);
917
944
}
918
945
 
919
 
static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf)
 
946
static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf,
 
947
                         unsigned int cpu)
920
948
{
921
949
        switch (this_leaf->eax.split.type) {
922
950
        case CACHE_TYPE_DATA:
974
1002
        if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
975
1003
                n += 2;
976
1004
 
 
1005
        if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
 
1006
                n += 1;
 
1007
 
977
1008
        attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
978
1009
        if (attrs == NULL)
979
1010
                return attrs = default_attrs;
986
1017
                attrs[n++] = &cache_disable_1.attr;
987
1018
        }
988
1019
 
 
1020
        if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
 
1021
                attrs[n++] = &subcaches.attr;
 
1022
 
989
1023
        return attrs;
990
1024
}
991
1025
#endif
998
1032
 
999
1033
        ret = fattr->show ?
1000
1034
                fattr->show(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
1001
 
                        buf) :
 
1035
                        buf, this_leaf->cpu) :
1002
1036
                0;
1003
1037
        return ret;
1004
1038
}
1012
1046
 
1013
1047
        ret = fattr->store ?
1014
1048
                fattr->store(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
1015
 
                        buf, count) :
 
1049
                        buf, count, this_leaf->cpu) :
1016
1050
                0;
1017
1051
        return ret;
1018
1052
}