Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/cpu.h> |
| 3 | #include <linux/smp.h> |
| 4 | #include <linux/percpu.h> |
| 5 | #include <linux/init.h> |
| 6 | #include <linux/sched.h> |
Paul Gortmaker | 4b16f8e | 2011-07-22 18:24:23 -0400 | [diff] [blame] | 7 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/nodemask.h> |
| 9 | #include <linux/cpumask.h> |
| 10 | #include <linux/notifier.h> |
| 11 | |
| 12 | #include <asm/current.h> |
| 13 | #include <asm/processor.h> |
| 14 | #include <asm/cputable.h> |
| 15 | #include <asm/hvcall.h> |
| 16 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/machdep.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame] | 18 | #include <asm/smp.h> |
Paul Mackerras | a6dbf93 | 2009-09-09 01:26:03 +0000 | [diff] [blame] | 19 | #include <asm/pmc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Nathan Lynch | 93197a3 | 2008-12-23 18:55:54 +0000 | [diff] [blame] | 21 | #include "cacheinfo.h" |
| 22 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 23 | #ifdef CONFIG_PPC64 |
| 24 | #include <asm/paca.h> |
| 25 | #include <asm/lppaca.h> |
| 26 | #endif |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static DEFINE_PER_CPU(struct cpu, cpu_devices); |
| 29 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 30 | /* |
| 31 | * SMT snooze delay stuff, 64-bit only for now |
| 32 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 34 | #ifdef CONFIG_PPC64 |
| 35 | |
Anton Blanchard | 0ddd3e7 | 2006-09-22 20:30:14 +1000 | [diff] [blame] | 36 | /* Time in microseconds we delay before sleeping in the idle loop */ |
Anton Blanchard | b878dc0 | 2010-05-16 20:02:39 +0000 | [diff] [blame] | 37 | DEFINE_PER_CPU(long, smt_snooze_delay) = { 100 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 39 | static ssize_t store_smt_snooze_delay(struct device *dev, |
| 40 | struct device_attribute *attr, |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 41 | const char *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | size_t count) |
| 43 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 44 | struct cpu *cpu = container_of(dev, struct cpu, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | ssize_t ret; |
Anton Blanchard | b878dc0 | 2010-05-16 20:02:39 +0000 | [diff] [blame] | 46 | long snooze; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Anton Blanchard | b878dc0 | 2010-05-16 20:02:39 +0000 | [diff] [blame] | 48 | ret = sscanf(buf, "%ld", &snooze); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | if (ret != 1) |
| 50 | return -EINVAL; |
| 51 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 52 | per_cpu(smt_snooze_delay, cpu->dev.id) = snooze; |
Deepthi Dharwar | 707827f | 2011-11-30 02:46:42 +0000 | [diff] [blame] | 53 | update_smt_snooze_delay(snooze); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | return count; |
| 56 | } |
| 57 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 58 | static ssize_t show_smt_snooze_delay(struct device *dev, |
| 59 | struct device_attribute *attr, |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 60 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 62 | struct cpu *cpu = container_of(dev, struct cpu, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 64 | return sprintf(buf, "%ld\n", per_cpu(smt_snooze_delay, cpu->dev.id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 67 | static DEVICE_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | store_smt_snooze_delay); |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static int __init setup_smt_snooze_delay(char *str) |
| 71 | { |
| 72 | unsigned int cpu; |
Anton Blanchard | b878dc0 | 2010-05-16 20:02:39 +0000 | [diff] [blame] | 73 | long snooze; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | if (!cpu_has_feature(CPU_FTR_SMT)) |
| 76 | return 1; |
| 77 | |
Anton Blanchard | b878dc0 | 2010-05-16 20:02:39 +0000 | [diff] [blame] | 78 | snooze = simple_strtol(str, NULL, 10); |
| 79 | for_each_possible_cpu(cpu) |
| 80 | per_cpu(smt_snooze_delay, cpu) = snooze; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | return 1; |
| 83 | } |
| 84 | __setup("smt-snooze-delay=", setup_smt_snooze_delay); |
| 85 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 86 | #endif /* CONFIG_PPC64 */ |
Michael Ellerman | 180a336 | 2005-08-09 11:13:36 +1000 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* |
| 89 | * Enabling PMCs will slow partition context switch times so we only do |
| 90 | * it the first time we write to the PMCs. |
| 91 | */ |
| 92 | |
| 93 | static DEFINE_PER_CPU(char, pmcs_enabled); |
| 94 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 95 | void ppc_enable_pmcs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Paul Mackerras | a6dbf93 | 2009-09-09 01:26:03 +0000 | [diff] [blame] | 97 | ppc_set_pmu_inuse(1); |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* Only need to enable them once */ |
| 100 | if (__get_cpu_var(pmcs_enabled)) |
| 101 | return; |
| 102 | |
| 103 | __get_cpu_var(pmcs_enabled) = 1; |
| 104 | |
Michael Ellerman | 180a336 | 2005-08-09 11:13:36 +1000 | [diff] [blame] | 105 | if (ppc_md.enable_pmcs) |
| 106 | ppc_md.enable_pmcs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 108 | EXPORT_SYMBOL(ppc_enable_pmcs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #define SYSFS_PMCSETUP(NAME, ADDRESS) \ |
Rusty Russell | 9a37193 | 2009-03-11 12:20:05 +0000 | [diff] [blame] | 111 | static void read_##NAME(void *val) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { \ |
Benjamin Herrenschmidt | ec78c8a | 2009-03-26 19:29:06 +0000 | [diff] [blame] | 113 | *(unsigned long *)val = mfspr(ADDRESS); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } \ |
Benjamin Herrenschmidt | ec78c8a | 2009-03-26 19:29:06 +0000 | [diff] [blame] | 115 | static void write_##NAME(void *val) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { \ |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 117 | ppc_enable_pmcs(); \ |
Rusty Russell | 9a37193 | 2009-03-11 12:20:05 +0000 | [diff] [blame] | 118 | mtspr(ADDRESS, *(unsigned long *)val); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 120 | static ssize_t show_##NAME(struct device *dev, \ |
| 121 | struct device_attribute *attr, \ |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 122 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 124 | struct cpu *cpu = container_of(dev, struct cpu, dev); \ |
Rusty Russell | 9a37193 | 2009-03-11 12:20:05 +0000 | [diff] [blame] | 125 | unsigned long val; \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 126 | smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return sprintf(buf, "%lx\n", val); \ |
| 128 | } \ |
Adrian Bunk | 3ff6eec | 2008-01-24 22:16:20 +0100 | [diff] [blame] | 129 | static ssize_t __used \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 130 | store_##NAME(struct device *dev, struct device_attribute *attr, \ |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 131 | const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 133 | struct cpu *cpu = container_of(dev, struct cpu, dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | unsigned long val; \ |
| 135 | int ret = sscanf(buf, "%lx", &val); \ |
| 136 | if (ret != 1) \ |
| 137 | return -EINVAL; \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 138 | smp_call_function_single(cpu->dev.id, write_##NAME, &val, 1); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | return count; \ |
| 140 | } |
| 141 | |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 142 | |
| 143 | /* Let's define all possible registers, we'll only hook up the ones |
| 144 | * that are implemented on the current processor |
| 145 | */ |
| 146 | |
Kumar Gala | 33a7f12 | 2008-09-18 17:50:42 -0500 | [diff] [blame] | 147 | #if defined(CONFIG_PPC64) |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 148 | #define HAS_PPC_PMC_CLASSIC 1 |
| 149 | #define HAS_PPC_PMC_IBM 1 |
| 150 | #define HAS_PPC_PMC_PA6T 1 |
Kumar Gala | 33a7f12 | 2008-09-18 17:50:42 -0500 | [diff] [blame] | 151 | #elif defined(CONFIG_6xx) |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 152 | #define HAS_PPC_PMC_CLASSIC 1 |
| 153 | #define HAS_PPC_PMC_IBM 1 |
| 154 | #define HAS_PPC_PMC_G4 1 |
| 155 | #endif |
| 156 | |
| 157 | |
| 158 | #ifdef HAS_PPC_PMC_CLASSIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); |
| 160 | SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | SYSFS_PMCSETUP(pmc1, SPRN_PMC1); |
| 162 | SYSFS_PMCSETUP(pmc2, SPRN_PMC2); |
| 163 | SYSFS_PMCSETUP(pmc3, SPRN_PMC3); |
| 164 | SYSFS_PMCSETUP(pmc4, SPRN_PMC4); |
| 165 | SYSFS_PMCSETUP(pmc5, SPRN_PMC5); |
| 166 | SYSFS_PMCSETUP(pmc6, SPRN_PMC6); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 167 | |
| 168 | #ifdef HAS_PPC_PMC_G4 |
| 169 | SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2); |
| 170 | #endif |
| 171 | |
| 172 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | SYSFS_PMCSETUP(pmc7, SPRN_PMC7); |
| 174 | SYSFS_PMCSETUP(pmc8, SPRN_PMC8); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 175 | |
| 176 | SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | SYSFS_PMCSETUP(purr, SPRN_PURR); |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 178 | SYSFS_PMCSETUP(spurr, SPRN_SPURR); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 179 | SYSFS_PMCSETUP(dscr, SPRN_DSCR); |
Ananth N Mavinakayanahalli | 595fe91 | 2011-11-10 19:58:53 +0000 | [diff] [blame] | 180 | SYSFS_PMCSETUP(pir, SPRN_PIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 182 | static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra); |
| 183 | static DEVICE_ATTR(spurr, 0600, show_spurr, NULL); |
| 184 | static DEVICE_ATTR(dscr, 0600, show_dscr, store_dscr); |
| 185 | static DEVICE_ATTR(purr, 0600, show_purr, store_purr); |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 186 | static DEVICE_ATTR(pir, 0400, show_pir, NULL); |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 187 | |
| 188 | unsigned long dscr_default = 0; |
| 189 | EXPORT_SYMBOL(dscr_default); |
| 190 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 191 | static ssize_t show_dscr_default(struct device *dev, |
| 192 | struct device_attribute *attr, char *buf) |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 193 | { |
| 194 | return sprintf(buf, "%lx\n", dscr_default); |
| 195 | } |
| 196 | |
Anton Blanchard | 1b6ca2a | 2012-09-03 16:47:56 +0000 | [diff] [blame^] | 197 | static void update_dscr(void *dummy) |
| 198 | { |
| 199 | if (!current->thread.dscr_inherit) |
| 200 | mtspr(SPRN_DSCR, dscr_default); |
| 201 | } |
| 202 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 203 | static ssize_t __used store_dscr_default(struct device *dev, |
| 204 | struct device_attribute *attr, const char *buf, |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 205 | size_t count) |
| 206 | { |
| 207 | unsigned long val; |
| 208 | int ret = 0; |
| 209 | |
| 210 | ret = sscanf(buf, "%lx", &val); |
| 211 | if (ret != 1) |
| 212 | return -EINVAL; |
| 213 | dscr_default = val; |
| 214 | |
Anton Blanchard | 1b6ca2a | 2012-09-03 16:47:56 +0000 | [diff] [blame^] | 215 | on_each_cpu(update_dscr, NULL, 1); |
| 216 | |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 217 | return count; |
| 218 | } |
| 219 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 220 | static DEVICE_ATTR(dscr_default, 0600, |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 221 | show_dscr_default, store_dscr_default); |
| 222 | |
| 223 | static void sysfs_create_dscr_default(void) |
| 224 | { |
| 225 | int err = 0; |
| 226 | if (cpu_has_feature(CPU_FTR_DSCR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 227 | err = device_create_file(cpu_subsys.dev_root, &dev_attr_dscr_default); |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 228 | } |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 229 | #endif /* CONFIG_PPC64 */ |
| 230 | |
| 231 | #ifdef HAS_PPC_PMC_PA6T |
Olof Johansson | 25fc530 | 2007-04-18 16:38:21 +1000 | [diff] [blame] | 232 | SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0); |
| 233 | SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1); |
| 234 | SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2); |
| 235 | SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3); |
| 236 | SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4); |
| 237 | SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5); |
Olof Johansson | 2e1957f | 2007-09-05 12:09:06 +1000 | [diff] [blame] | 238 | #ifdef CONFIG_DEBUG_KERNEL |
| 239 | SYSFS_PMCSETUP(hid0, SPRN_HID0); |
| 240 | SYSFS_PMCSETUP(hid1, SPRN_HID1); |
| 241 | SYSFS_PMCSETUP(hid4, SPRN_HID4); |
| 242 | SYSFS_PMCSETUP(hid5, SPRN_HID5); |
| 243 | SYSFS_PMCSETUP(ima0, SPRN_PA6T_IMA0); |
| 244 | SYSFS_PMCSETUP(ima1, SPRN_PA6T_IMA1); |
| 245 | SYSFS_PMCSETUP(ima2, SPRN_PA6T_IMA2); |
| 246 | SYSFS_PMCSETUP(ima3, SPRN_PA6T_IMA3); |
| 247 | SYSFS_PMCSETUP(ima4, SPRN_PA6T_IMA4); |
| 248 | SYSFS_PMCSETUP(ima5, SPRN_PA6T_IMA5); |
| 249 | SYSFS_PMCSETUP(ima6, SPRN_PA6T_IMA6); |
| 250 | SYSFS_PMCSETUP(ima7, SPRN_PA6T_IMA7); |
| 251 | SYSFS_PMCSETUP(ima8, SPRN_PA6T_IMA8); |
| 252 | SYSFS_PMCSETUP(ima9, SPRN_PA6T_IMA9); |
| 253 | SYSFS_PMCSETUP(imaat, SPRN_PA6T_IMAAT); |
| 254 | SYSFS_PMCSETUP(btcr, SPRN_PA6T_BTCR); |
| 255 | SYSFS_PMCSETUP(pccr, SPRN_PA6T_PCCR); |
| 256 | SYSFS_PMCSETUP(rpccr, SPRN_PA6T_RPCCR); |
| 257 | SYSFS_PMCSETUP(der, SPRN_PA6T_DER); |
| 258 | SYSFS_PMCSETUP(mer, SPRN_PA6T_MER); |
| 259 | SYSFS_PMCSETUP(ber, SPRN_PA6T_BER); |
| 260 | SYSFS_PMCSETUP(ier, SPRN_PA6T_IER); |
| 261 | SYSFS_PMCSETUP(sier, SPRN_PA6T_SIER); |
| 262 | SYSFS_PMCSETUP(siar, SPRN_PA6T_SIAR); |
| 263 | SYSFS_PMCSETUP(tsr0, SPRN_PA6T_TSR0); |
| 264 | SYSFS_PMCSETUP(tsr1, SPRN_PA6T_TSR1); |
| 265 | SYSFS_PMCSETUP(tsr2, SPRN_PA6T_TSR2); |
| 266 | SYSFS_PMCSETUP(tsr3, SPRN_PA6T_TSR3); |
| 267 | #endif /* CONFIG_DEBUG_KERNEL */ |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 268 | #endif /* HAS_PPC_PMC_PA6T */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 269 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 270 | #ifdef HAS_PPC_PMC_IBM |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 271 | static struct device_attribute ibm_common_attrs[] = { |
| 272 | __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), |
| 273 | __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 274 | }; |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 275 | #endif /* HAS_PPC_PMC_G4 */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 276 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 277 | #ifdef HAS_PPC_PMC_G4 |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 278 | static struct device_attribute g4_common_attrs[] = { |
| 279 | __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), |
| 280 | __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), |
| 281 | __ATTR(mmcr2, 0600, show_mmcr2, store_mmcr2), |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 282 | }; |
| 283 | #endif /* HAS_PPC_PMC_G4 */ |
| 284 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 285 | static struct device_attribute classic_pmc_attrs[] = { |
| 286 | __ATTR(pmc1, 0600, show_pmc1, store_pmc1), |
| 287 | __ATTR(pmc2, 0600, show_pmc2, store_pmc2), |
| 288 | __ATTR(pmc3, 0600, show_pmc3, store_pmc3), |
| 289 | __ATTR(pmc4, 0600, show_pmc4, store_pmc4), |
| 290 | __ATTR(pmc5, 0600, show_pmc5, store_pmc5), |
| 291 | __ATTR(pmc6, 0600, show_pmc6, store_pmc6), |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 292 | #ifdef CONFIG_PPC64 |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 293 | __ATTR(pmc7, 0600, show_pmc7, store_pmc7), |
| 294 | __ATTR(pmc8, 0600, show_pmc8, store_pmc8), |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 295 | #endif |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 296 | }; |
| 297 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 298 | #ifdef HAS_PPC_PMC_PA6T |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 299 | static struct device_attribute pa6t_attrs[] = { |
| 300 | __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), |
| 301 | __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), |
| 302 | __ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0), |
| 303 | __ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1), |
| 304 | __ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2), |
| 305 | __ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3), |
| 306 | __ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4), |
| 307 | __ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5), |
Olof Johansson | 2e1957f | 2007-09-05 12:09:06 +1000 | [diff] [blame] | 308 | #ifdef CONFIG_DEBUG_KERNEL |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 309 | __ATTR(hid0, 0600, show_hid0, store_hid0), |
| 310 | __ATTR(hid1, 0600, show_hid1, store_hid1), |
| 311 | __ATTR(hid4, 0600, show_hid4, store_hid4), |
| 312 | __ATTR(hid5, 0600, show_hid5, store_hid5), |
| 313 | __ATTR(ima0, 0600, show_ima0, store_ima0), |
| 314 | __ATTR(ima1, 0600, show_ima1, store_ima1), |
| 315 | __ATTR(ima2, 0600, show_ima2, store_ima2), |
| 316 | __ATTR(ima3, 0600, show_ima3, store_ima3), |
| 317 | __ATTR(ima4, 0600, show_ima4, store_ima4), |
| 318 | __ATTR(ima5, 0600, show_ima5, store_ima5), |
| 319 | __ATTR(ima6, 0600, show_ima6, store_ima6), |
| 320 | __ATTR(ima7, 0600, show_ima7, store_ima7), |
| 321 | __ATTR(ima8, 0600, show_ima8, store_ima8), |
| 322 | __ATTR(ima9, 0600, show_ima9, store_ima9), |
| 323 | __ATTR(imaat, 0600, show_imaat, store_imaat), |
| 324 | __ATTR(btcr, 0600, show_btcr, store_btcr), |
| 325 | __ATTR(pccr, 0600, show_pccr, store_pccr), |
| 326 | __ATTR(rpccr, 0600, show_rpccr, store_rpccr), |
| 327 | __ATTR(der, 0600, show_der, store_der), |
| 328 | __ATTR(mer, 0600, show_mer, store_mer), |
| 329 | __ATTR(ber, 0600, show_ber, store_ber), |
| 330 | __ATTR(ier, 0600, show_ier, store_ier), |
| 331 | __ATTR(sier, 0600, show_sier, store_sier), |
| 332 | __ATTR(siar, 0600, show_siar, store_siar), |
| 333 | __ATTR(tsr0, 0600, show_tsr0, store_tsr0), |
| 334 | __ATTR(tsr1, 0600, show_tsr1, store_tsr1), |
| 335 | __ATTR(tsr2, 0600, show_tsr2, store_tsr2), |
| 336 | __ATTR(tsr3, 0600, show_tsr3, store_tsr3), |
Olof Johansson | 2e1957f | 2007-09-05 12:09:06 +1000 | [diff] [blame] | 337 | #endif /* CONFIG_DEBUG_KERNEL */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 338 | }; |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 339 | #endif /* HAS_PPC_PMC_PA6T */ |
| 340 | #endif /* HAS_PPC_PMC_CLASSIC */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 341 | |
Nathan Lynch | 9ba1984 | 2008-07-27 15:24:51 +1000 | [diff] [blame] | 342 | static void __cpuinit register_cpu_online(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
| 344 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 345 | struct device *s = &c->dev; |
| 346 | struct device_attribute *attrs, *pmc_attrs; |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 347 | int i, nattrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 349 | #ifdef CONFIG_PPC64 |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 350 | if (cpu_has_feature(CPU_FTR_SMT)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 351 | device_create_file(s, &dev_attr_smt_snooze_delay); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 352 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | /* PMC stuff */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 355 | switch (cur_cpu_spec->pmc_type) { |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 356 | #ifdef HAS_PPC_PMC_IBM |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 357 | case PPC_PMC_IBM: |
| 358 | attrs = ibm_common_attrs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 359 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 360 | pmc_attrs = classic_pmc_attrs; |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 361 | break; |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 362 | #endif /* HAS_PPC_PMC_IBM */ |
| 363 | #ifdef HAS_PPC_PMC_G4 |
| 364 | case PPC_PMC_G4: |
| 365 | attrs = g4_common_attrs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 366 | nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 367 | pmc_attrs = classic_pmc_attrs; |
| 368 | break; |
| 369 | #endif /* HAS_PPC_PMC_G4 */ |
| 370 | #ifdef HAS_PPC_PMC_PA6T |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 371 | case PPC_PMC_PA6T: |
| 372 | /* PA Semi starts counting at PMC0 */ |
| 373 | attrs = pa6t_attrs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 374 | nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute); |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 375 | pmc_attrs = NULL; |
| 376 | break; |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 377 | #endif /* HAS_PPC_PMC_PA6T */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 378 | default: |
| 379 | attrs = NULL; |
| 380 | nattrs = 0; |
| 381 | pmc_attrs = NULL; |
| 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 384 | for (i = 0; i < nattrs; i++) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 385 | device_create_file(s, &attrs[i]); |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 386 | |
| 387 | if (pmc_attrs) |
| 388 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 389 | device_create_file(s, &pmc_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 391 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 393 | device_create_file(s, &dev_attr_mmcra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Michael Neuling | afd0542 | 2006-07-28 13:58:37 +1000 | [diff] [blame] | 395 | if (cpu_has_feature(CPU_FTR_PURR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 396 | device_create_file(s, &dev_attr_purr); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 397 | |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 398 | if (cpu_has_feature(CPU_FTR_SPURR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 399 | device_create_file(s, &dev_attr_spurr); |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 400 | |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 401 | if (cpu_has_feature(CPU_FTR_DSCR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 402 | device_create_file(s, &dev_attr_dscr); |
Ananth N Mavinakayanahalli | 595fe91 | 2011-11-10 19:58:53 +0000 | [diff] [blame] | 403 | |
| 404 | if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2)) |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 405 | device_create_file(s, &dev_attr_pir); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 406 | #endif /* CONFIG_PPC64 */ |
Nathan Lynch | 124c27d | 2008-07-27 15:24:55 +1000 | [diff] [blame] | 407 | |
Nathan Lynch | 93197a3 | 2008-12-23 18:55:54 +0000 | [diff] [blame] | 408 | cacheinfo_cpu_online(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | #ifdef CONFIG_HOTPLUG_CPU |
| 412 | static void unregister_cpu_online(unsigned int cpu) |
| 413 | { |
| 414 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 415 | struct device *s = &c->dev; |
| 416 | struct device_attribute *attrs, *pmc_attrs; |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 417 | int i, nattrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 419 | BUG_ON(!c->hotpluggable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
Milton Miller | a1e0eb1 | 2008-11-16 11:44:42 +0000 | [diff] [blame] | 421 | #ifdef CONFIG_PPC64 |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 422 | if (cpu_has_feature(CPU_FTR_SMT)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 423 | device_remove_file(s, &dev_attr_smt_snooze_delay); |
Milton Miller | a1e0eb1 | 2008-11-16 11:44:42 +0000 | [diff] [blame] | 424 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | /* PMC stuff */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 427 | switch (cur_cpu_spec->pmc_type) { |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 428 | #ifdef HAS_PPC_PMC_IBM |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 429 | case PPC_PMC_IBM: |
| 430 | attrs = ibm_common_attrs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 431 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 432 | pmc_attrs = classic_pmc_attrs; |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 433 | break; |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 434 | #endif /* HAS_PPC_PMC_IBM */ |
| 435 | #ifdef HAS_PPC_PMC_G4 |
| 436 | case PPC_PMC_G4: |
| 437 | attrs = g4_common_attrs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 438 | nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 439 | pmc_attrs = classic_pmc_attrs; |
| 440 | break; |
| 441 | #endif /* HAS_PPC_PMC_G4 */ |
| 442 | #ifdef HAS_PPC_PMC_PA6T |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 443 | case PPC_PMC_PA6T: |
| 444 | /* PA Semi starts counting at PMC0 */ |
| 445 | attrs = pa6t_attrs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 446 | nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute); |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 447 | pmc_attrs = NULL; |
| 448 | break; |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 449 | #endif /* HAS_PPC_PMC_PA6T */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 450 | default: |
| 451 | attrs = NULL; |
| 452 | nattrs = 0; |
| 453 | pmc_attrs = NULL; |
| 454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 456 | for (i = 0; i < nattrs; i++) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 457 | device_remove_file(s, &attrs[i]); |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 458 | |
| 459 | if (pmc_attrs) |
| 460 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 461 | device_remove_file(s, &pmc_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 463 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 465 | device_remove_file(s, &dev_attr_mmcra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Michael Neuling | afd0542 | 2006-07-28 13:58:37 +1000 | [diff] [blame] | 467 | if (cpu_has_feature(CPU_FTR_PURR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 468 | device_remove_file(s, &dev_attr_purr); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 469 | |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 470 | if (cpu_has_feature(CPU_FTR_SPURR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 471 | device_remove_file(s, &dev_attr_spurr); |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 472 | |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 473 | if (cpu_has_feature(CPU_FTR_DSCR)) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 474 | device_remove_file(s, &dev_attr_dscr); |
Ananth N Mavinakayanahalli | 595fe91 | 2011-11-10 19:58:53 +0000 | [diff] [blame] | 475 | |
| 476 | if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2)) |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 477 | device_remove_file(s, &dev_attr_pir); |
Benjamin Herrenschmidt | b950bdd | 2008-08-18 14:23:51 +1000 | [diff] [blame] | 478 | #endif /* CONFIG_PPC64 */ |
Nathan Lynch | 124c27d | 2008-07-27 15:24:55 +1000 | [diff] [blame] | 479 | |
Nathan Lynch | 93197a3 | 2008-12-23 18:55:54 +0000 | [diff] [blame] | 480 | cacheinfo_cpu_offline(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
Nathan Fontenot | 12633e8 | 2009-11-25 17:23:25 +0000 | [diff] [blame] | 482 | |
| 483 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE |
| 484 | ssize_t arch_cpu_probe(const char *buf, size_t count) |
| 485 | { |
| 486 | if (ppc_md.cpu_probe) |
| 487 | return ppc_md.cpu_probe(buf, count); |
| 488 | |
| 489 | return -EINVAL; |
| 490 | } |
| 491 | |
| 492 | ssize_t arch_cpu_release(const char *buf, size_t count) |
| 493 | { |
| 494 | if (ppc_md.cpu_release) |
| 495 | return ppc_md.cpu_release(buf, count); |
| 496 | |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 502 | |
Chandra Seetharaman | 8c78f30 | 2006-07-30 03:03:35 -0700 | [diff] [blame] | 503 | static int __cpuinit sysfs_cpu_notify(struct notifier_block *self, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | unsigned long action, void *hcpu) |
| 505 | { |
| 506 | unsigned int cpu = (unsigned int)(long)hcpu; |
| 507 | |
| 508 | switch (action) { |
| 509 | case CPU_ONLINE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 510 | case CPU_ONLINE_FROZEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | register_cpu_online(cpu); |
| 512 | break; |
| 513 | #ifdef CONFIG_HOTPLUG_CPU |
| 514 | case CPU_DEAD: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 515 | case CPU_DEAD_FROZEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | unregister_cpu_online(cpu); |
| 517 | break; |
| 518 | #endif |
| 519 | } |
| 520 | return NOTIFY_OK; |
| 521 | } |
| 522 | |
Chandra Seetharaman | 8c78f30 | 2006-07-30 03:03:35 -0700 | [diff] [blame] | 523 | static struct notifier_block __cpuinitdata sysfs_cpu_nb = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | .notifier_call = sysfs_cpu_notify, |
| 525 | }; |
| 526 | |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 527 | static DEFINE_MUTEX(cpu_mutex); |
| 528 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 529 | int cpu_add_dev_attr(struct device_attribute *attr) |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 530 | { |
| 531 | int cpu; |
| 532 | |
| 533 | mutex_lock(&cpu_mutex); |
| 534 | |
| 535 | for_each_possible_cpu(cpu) { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 536 | device_create_file(get_cpu_device(cpu), attr); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | mutex_unlock(&cpu_mutex); |
| 540 | return 0; |
| 541 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 542 | EXPORT_SYMBOL_GPL(cpu_add_dev_attr); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 543 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 544 | int cpu_add_dev_attr_group(struct attribute_group *attrs) |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 545 | { |
| 546 | int cpu; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 547 | struct device *dev; |
Olof Johansson | 6bcc4c0 | 2007-09-05 12:43:17 +1000 | [diff] [blame] | 548 | int ret; |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 549 | |
| 550 | mutex_lock(&cpu_mutex); |
| 551 | |
| 552 | for_each_possible_cpu(cpu) { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 553 | dev = get_cpu_device(cpu); |
| 554 | ret = sysfs_create_group(&dev->kobj, attrs); |
Olof Johansson | 6bcc4c0 | 2007-09-05 12:43:17 +1000 | [diff] [blame] | 555 | WARN_ON(ret != 0); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | mutex_unlock(&cpu_mutex); |
| 559 | return 0; |
| 560 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 561 | EXPORT_SYMBOL_GPL(cpu_add_dev_attr_group); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 562 | |
| 563 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 564 | void cpu_remove_dev_attr(struct device_attribute *attr) |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 565 | { |
| 566 | int cpu; |
| 567 | |
| 568 | mutex_lock(&cpu_mutex); |
| 569 | |
| 570 | for_each_possible_cpu(cpu) { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 571 | device_remove_file(get_cpu_device(cpu), attr); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | mutex_unlock(&cpu_mutex); |
| 575 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 576 | EXPORT_SYMBOL_GPL(cpu_remove_dev_attr); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 577 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 578 | void cpu_remove_dev_attr_group(struct attribute_group *attrs) |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 579 | { |
| 580 | int cpu; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 581 | struct device *dev; |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 582 | |
| 583 | mutex_lock(&cpu_mutex); |
| 584 | |
| 585 | for_each_possible_cpu(cpu) { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 586 | dev = get_cpu_device(cpu); |
| 587 | sysfs_remove_group(&dev->kobj, attrs); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | mutex_unlock(&cpu_mutex); |
| 591 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 592 | EXPORT_SYMBOL_GPL(cpu_remove_dev_attr_group); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 593 | |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | /* NUMA stuff */ |
| 596 | |
| 597 | #ifdef CONFIG_NUMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | static void register_nodes(void) |
| 599 | { |
| 600 | int i; |
| 601 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 602 | for (i = 0; i < MAX_NUMNODES; i++) |
| 603 | register_one_node(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 605 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 606 | int sysfs_add_device_to_node(struct device *dev, int nid) |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 607 | { |
| 608 | struct node *node = &node_devices[nid]; |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 609 | return sysfs_create_link(&node->dev.kobj, &dev->kobj, |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 610 | kobject_name(&dev->kobj)); |
| 611 | } |
Johannes Berg | 12654f7 | 2007-07-05 19:35:33 +1000 | [diff] [blame] | 612 | EXPORT_SYMBOL_GPL(sysfs_add_device_to_node); |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 613 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 614 | void sysfs_remove_device_from_node(struct device *dev, int nid) |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 615 | { |
| 616 | struct node *node = &node_devices[nid]; |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 617 | sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj)); |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 618 | } |
Johannes Berg | 12654f7 | 2007-07-05 19:35:33 +1000 | [diff] [blame] | 619 | EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node); |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | #else |
| 622 | static void register_nodes(void) |
| 623 | { |
| 624 | return; |
| 625 | } |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | #endif |
| 628 | |
| 629 | /* Only valid if CPU is present. */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 630 | static ssize_t show_physical_id(struct device *dev, |
| 631 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 633 | struct cpu *cpu = container_of(dev, struct cpu, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 635 | return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 637 | static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
| 639 | static int __init topology_init(void) |
| 640 | { |
| 641 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | register_nodes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | register_cpu_notifier(&sysfs_cpu_nb); |
| 645 | |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 646 | for_each_possible_cpu(cpu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | /* |
| 650 | * For now, we just see if the system supports making |
| 651 | * the RTAS calls for CPU hotplug. But, there may be a |
| 652 | * more comprehensive way to do this for an individual |
| 653 | * CPU. For instance, the boot cpu might never be valid |
| 654 | * for hotplugging. |
| 655 | */ |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 656 | if (ppc_md.cpu_die) |
| 657 | c->hotpluggable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 659 | if (cpu_online(cpu) || c->hotpluggable) { |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 660 | register_cpu(c, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 662 | device_create_file(&c->dev, &dev_attr_physical_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | if (cpu_online(cpu)) |
| 666 | register_cpu_online(cpu); |
| 667 | } |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 668 | #ifdef CONFIG_PPC64 |
| 669 | sysfs_create_dscr_default(); |
| 670 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | return 0; |
| 673 | } |
Kevin Corry | e9e77ce | 2007-05-03 03:11:49 +1000 | [diff] [blame] | 674 | subsys_initcall(topology_init); |