aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc64
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2005-11-09 23:26:20 -0500
committerPaul Mackerras <paulus@samba.org>2005-11-09 23:32:37 -0500
commitd3d2176a0bc696b5365ce0e8f82a29a521d85fd0 (patch)
tree251e7e096f5d96450954df130483f0616452180d /arch/ppc64
parent0f34f490290e05ee6c02e20b3811fce6f09318f4 (diff)
[PATCH] powerpc: Move more ppc64 files with no ppc32 equivalent to powerpc
This patch moves a bunch more files from arch/ppc64 and include/asm-ppc64 which have no equivalents in ppc32 code into arch/powerpc and include/asm-powerpc. The file affected are: hvcall.h proc_ppc64.c sysfs.c lparcfg.c rtas_pci.c The only changes apart from the move and corresponding Makefile changes are: - #ifndef/#define in includes updated to _ASM_POWERPC_ form - trailing whitespace removed - comments giving full paths removed Built and booted on POWER5 LPAR (ARCH=powerpc and ARCH=ppc64), built for 32-bit powermac (ARCH=powerpc). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/ppc64')
-rw-r--r--arch/ppc64/kernel/Makefile5
-rw-r--r--arch/ppc64/kernel/lparcfg.c612
-rw-r--r--arch/ppc64/kernel/proc_ppc64.c128
-rw-r--r--arch/ppc64/kernel/rtas_pci.c513
-rw-r--r--arch/ppc64/kernel/sysfs.c384
5 files changed, 1 insertions, 1641 deletions
diff --git a/arch/ppc64/kernel/Makefile b/arch/ppc64/kernel/Makefile
index 048ba910f028..58b19f107656 100644
--- a/arch/ppc64/kernel/Makefile
+++ b/arch/ppc64/kernel/Makefile
@@ -15,7 +15,7 @@ obj-y += idle.o dma.o \
15 align.o \ 15 align.o \
16 udbg.o \ 16 udbg.o \
17 rtc.o \ 17 rtc.o \
18 iommu.o sysfs.o vdso.o 18 iommu.o vdso.o
19obj-y += vdso32/ vdso64/ 19obj-y += vdso32/ vdso64/
20 20
21pci-obj-$(CONFIG_PPC_MULTIPLATFORM) += pci_dn.o pci_direct_iommu.o 21pci-obj-$(CONFIG_PPC_MULTIPLATFORM) += pci_dn.o pci_direct_iommu.o
@@ -30,13 +30,10 @@ endif
30obj-$(CONFIG_PPC_PSERIES) += udbg_16550.o 30obj-$(CONFIG_PPC_PSERIES) += udbg_16550.o
31 31
32obj-$(CONFIG_KEXEC) += machine_kexec.o 32obj-$(CONFIG_KEXEC) += machine_kexec.o
33obj-$(CONFIG_PROC_FS) += proc_ppc64.o
34obj-$(CONFIG_MODULES) += module.o 33obj-$(CONFIG_MODULES) += module.o
35ifneq ($(CONFIG_PPC_MERGE),y) 34ifneq ($(CONFIG_PPC_MERGE),y)
36obj-$(CONFIG_MODULES) += ppc_ksyms.o 35obj-$(CONFIG_MODULES) += ppc_ksyms.o
37endif 36endif
38obj-$(CONFIG_PPC_RTAS) += rtas_pci.o
39obj-$(CONFIG_LPARCFG) += lparcfg.o
40obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o 37obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o
41ifneq ($(CONFIG_PPC_MERGE),y) 38ifneq ($(CONFIG_PPC_MERGE),y)
42obj-$(CONFIG_BOOTX_TEXT) += btext.o 39obj-$(CONFIG_BOOTX_TEXT) += btext.o
diff --git a/arch/ppc64/kernel/lparcfg.c b/arch/ppc64/kernel/lparcfg.c
deleted file mode 100644
index a80ed307515c..000000000000
--- a/arch/ppc64/kernel/lparcfg.c
+++ /dev/null
@@ -1,612 +0,0 @@
1/*
2 * PowerPC64 LPAR Configuration Information Driver
3 *
4 * Dave Engebretsen engebret@us.ibm.com
5 * Copyright (c) 2003 Dave Engebretsen
6 * Will Schmidt willschm@us.ibm.com
7 * SPLPAR updates, Copyright (c) 2003 Will Schmidt IBM Corporation.
8 * seq_file updates, Copyright (c) 2004 Will Schmidt IBM Corporation.
9 * Nathan Lynch nathanl@austin.ibm.com
10 * Added lparcfg_write, Copyright (C) 2004 Nathan Lynch IBM Corporation.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 *
17 * This driver creates a proc file at /proc/ppc64/lparcfg which contains
18 * keyword - value pairs that specify the configuration of the partition.
19 */
20
21#include <linux/config.h>
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/errno.h>
25#include <linux/proc_fs.h>
26#include <linux/init.h>
27#include <linux/seq_file.h>
28#include <asm/uaccess.h>
29#include <asm/iseries/hv_lp_config.h>
30#include <asm/lppaca.h>
31#include <asm/hvcall.h>
32#include <asm/firmware.h>
33#include <asm/rtas.h>
34#include <asm/system.h>
35#include <asm/time.h>
36#include <asm/iseries/it_exp_vpd_panel.h>
37#include <asm/prom.h>
38#include <asm/systemcfg.h>
39
40#define MODULE_VERS "1.6"
41#define MODULE_NAME "lparcfg"
42
43/* #define LPARCFG_DEBUG */
44
45/* find a better place for this function... */
46void log_plpar_hcall_return(unsigned long rc, char *tag)
47{
48 if (rc == 0) /* success, return */
49 return;
50/* check for null tag ? */
51 if (rc == H_Hardware)
52 printk(KERN_INFO
53 "plpar-hcall (%s) failed with hardware fault\n", tag);
54 else if (rc == H_Function)
55 printk(KERN_INFO
56 "plpar-hcall (%s) failed; function not allowed\n", tag);
57 else if (rc == H_Authority)
58 printk(KERN_INFO
59 "plpar-hcall (%s) failed; not authorized to this function\n",
60 tag);
61 else if (rc == H_Parameter)
62 printk(KERN_INFO "plpar-hcall (%s) failed; Bad parameter(s)\n",
63 tag);
64 else
65 printk(KERN_INFO
66 "plpar-hcall (%s) failed with unexpected rc(0x%lx)\n",
67 tag, rc);
68
69}
70
71static struct proc_dir_entry *proc_ppc64_lparcfg;
72#define LPARCFG_BUFF_SIZE 4096
73
74#ifdef CONFIG_PPC_ISERIES
75
76/*
77 * For iSeries legacy systems, the PPA purr function is available from the
78 * emulated_time_base field in the paca.
79 */
80static unsigned long get_purr(void)
81{
82 unsigned long sum_purr = 0;
83 int cpu;
84 struct paca_struct *lpaca;
85
86 for_each_cpu(cpu) {
87 lpaca = paca + cpu;
88 sum_purr += lpaca->lppaca.emulated_time_base;
89
90#ifdef PURR_DEBUG
91 printk(KERN_INFO "get_purr for cpu (%d) has value (%ld) \n",
92 cpu, lpaca->lppaca.emulated_time_base);
93#endif
94 }
95 return sum_purr;
96}
97
98#define lparcfg_write NULL
99
100/*
101 * Methods used to fetch LPAR data when running on an iSeries platform.
102 */
103static int lparcfg_data(struct seq_file *m, void *v)
104{
105 unsigned long pool_id, lp_index;
106 int shared, entitled_capacity, max_entitled_capacity;
107 int processors, max_processors;
108 struct paca_struct *lpaca = get_paca();
109 unsigned long purr = get_purr();
110
111 seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
112
113 shared = (int)(lpaca->lppaca_ptr->shared_proc);
114 seq_printf(m, "serial_number=%c%c%c%c%c%c%c\n",
115 e2a(xItExtVpdPanel.mfgID[2]),
116 e2a(xItExtVpdPanel.mfgID[3]),
117 e2a(xItExtVpdPanel.systemSerial[1]),
118 e2a(xItExtVpdPanel.systemSerial[2]),
119 e2a(xItExtVpdPanel.systemSerial[3]),
120 e2a(xItExtVpdPanel.systemSerial[4]),
121 e2a(xItExtVpdPanel.systemSerial[5]));
122
123 seq_printf(m, "system_type=%c%c%c%c\n",
124 e2a(xItExtVpdPanel.machineType[0]),
125 e2a(xItExtVpdPanel.machineType[1]),
126 e2a(xItExtVpdPanel.machineType[2]),
127 e2a(xItExtVpdPanel.machineType[3]));
128
129 lp_index = HvLpConfig_getLpIndex();
130 seq_printf(m, "partition_id=%d\n", (int)lp_index);
131
132 seq_printf(m, "system_active_processors=%d\n",
133 (int)HvLpConfig_getSystemPhysicalProcessors());
134
135 seq_printf(m, "system_potential_processors=%d\n",
136 (int)HvLpConfig_getSystemPhysicalProcessors());
137
138 processors = (int)HvLpConfig_getPhysicalProcessors();
139 seq_printf(m, "partition_active_processors=%d\n", processors);
140
141 max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
142 seq_printf(m, "partition_potential_processors=%d\n", max_processors);
143
144 if (shared) {
145 entitled_capacity = HvLpConfig_getSharedProcUnits();
146 max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
147 } else {
148 entitled_capacity = processors * 100;
149 max_entitled_capacity = max_processors * 100;
150 }
151 seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity);
152
153 seq_printf(m, "partition_max_entitled_capacity=%d\n",
154 max_entitled_capacity);
155
156 if (shared) {
157 pool_id = HvLpConfig_getSharedPoolIndex();
158 seq_printf(m, "pool=%d\n", (int)pool_id);
159 seq_printf(m, "pool_capacity=%d\n",
160 (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) *
161 100));
162 seq_printf(m, "purr=%ld\n", purr);
163 }
164
165 seq_printf(m, "shared_processor_mode=%d\n", shared);
166
167 return 0;
168}
169#endif /* CONFIG_PPC_ISERIES */
170
171#ifdef CONFIG_PPC_PSERIES
172/*
173 * Methods used to fetch LPAR data when running on a pSeries platform.
174 */
175
176/*
177 * H_GET_PPP hcall returns info in 4 parms.
178 * entitled_capacity,unallocated_capacity,
179 * aggregation, resource_capability).
180 *
181 * R4 = Entitled Processor Capacity Percentage.
182 * R5 = Unallocated Processor Capacity Percentage.
183 * R6 (AABBCCDDEEFFGGHH).
184 * XXXX - reserved (0)
185 * XXXX - reserved (0)
186 * XXXX - Group Number
187 * XXXX - Pool Number.
188 * R7 (IIJJKKLLMMNNOOPP).
189 * XX - reserved. (0)
190 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
191 * XX - variable processor Capacity Weight
192 * XX - Unallocated Variable Processor Capacity Weight.
193 * XXXX - Active processors in Physical Processor Pool.
194 * XXXX - Processors active on platform.
195 */
196static unsigned int h_get_ppp(unsigned long *entitled,
197 unsigned long *unallocated,
198 unsigned long *aggregation,
199 unsigned long *resource)
200{
201 unsigned long rc;
202 rc = plpar_hcall_4out(H_GET_PPP, 0, 0, 0, 0, entitled, unallocated,
203 aggregation, resource);
204
205 log_plpar_hcall_return(rc, "H_GET_PPP");
206
207 return rc;
208}
209
210static void h_pic(unsigned long *pool_idle_time, unsigned long *num_procs)
211{
212 unsigned long rc;
213 unsigned long dummy;
214 rc = plpar_hcall(H_PIC, 0, 0, 0, 0, pool_idle_time, num_procs, &dummy);
215
216 log_plpar_hcall_return(rc, "H_PIC");
217}
218
219static unsigned long get_purr(void);
220
221/* Track sum of all purrs across all processors. This is used to further */
222/* calculate usage values by different applications */
223
224static unsigned long get_purr(void)
225{
226 unsigned long sum_purr = 0;
227 int cpu;
228 struct cpu_usage *cu;
229
230 for_each_cpu(cpu) {
231 cu = &per_cpu(cpu_usage_array, cpu);
232 sum_purr += cu->current_tb;
233 }
234 return sum_purr;
235}
236
237#define SPLPAR_CHARACTERISTICS_TOKEN 20
238#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
239
240/*
241 * parse_system_parameter_string()
242 * Retrieve the potential_processors, max_entitled_capacity and friends
243 * through the get-system-parameter rtas call. Replace keyword strings as
244 * necessary.
245 */
246static void parse_system_parameter_string(struct seq_file *m)
247{
248 int call_status;
249
250 char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
251 if (!local_buffer) {
252 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
253 __FILE__, __FUNCTION__, __LINE__);
254 return;
255 }
256
257 spin_lock(&rtas_data_buf_lock);
258 memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
259 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
260 NULL,
261 SPLPAR_CHARACTERISTICS_TOKEN,
262 __pa(rtas_data_buf));
263 memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
264 spin_unlock(&rtas_data_buf_lock);
265
266 if (call_status != 0) {
267 printk(KERN_INFO
268 "%s %s Error calling get-system-parameter (0x%x)\n",
269 __FILE__, __FUNCTION__, call_status);
270 } else {
271 int splpar_strlen;
272 int idx, w_idx;
273 char *workbuffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
274 if (!workbuffer) {
275 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
276 __FILE__, __FUNCTION__, __LINE__);
277 kfree(local_buffer);
278 return;
279 }
280#ifdef LPARCFG_DEBUG
281 printk(KERN_INFO "success calling get-system-parameter \n");
282#endif
283 splpar_strlen = local_buffer[0] * 16 + local_buffer[1];
284 local_buffer += 2; /* step over strlen value */
285
286 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
287 w_idx = 0;
288 idx = 0;
289 while ((*local_buffer) && (idx < splpar_strlen)) {
290 workbuffer[w_idx++] = local_buffer[idx++];
291 if ((local_buffer[idx] == ',')
292 || (local_buffer[idx] == '\0')) {
293 workbuffer[w_idx] = '\0';
294 if (w_idx) {
295 /* avoid the empty string */
296 seq_printf(m, "%s\n", workbuffer);
297 }
298 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
299 idx++; /* skip the comma */
300 w_idx = 0;
301 } else if (local_buffer[idx] == '=') {
302 /* code here to replace workbuffer contents
303 with different keyword strings */
304 if (0 == strcmp(workbuffer, "MaxEntCap")) {
305 strcpy(workbuffer,
306 "partition_max_entitled_capacity");
307 w_idx = strlen(workbuffer);
308 }
309 if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
310 strcpy(workbuffer,
311 "system_potential_processors");
312 w_idx = strlen(workbuffer);
313 }
314 }
315 }
316 kfree(workbuffer);
317 local_buffer -= 2; /* back up over strlen value */
318 }
319 kfree(local_buffer);
320}
321
322static int lparcfg_count_active_processors(void);
323
324/* Return the number of processors in the system.
325 * This function reads through the device tree and counts
326 * the virtual processors, this does not include threads.
327 */
328static int lparcfg_count_active_processors(void)
329{
330 struct device_node *cpus_dn = NULL;
331 int count = 0;
332
333 while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
334#ifdef LPARCFG_DEBUG
335 printk(KERN_ERR "cpus_dn %p \n", cpus_dn);
336#endif
337 count++;
338 }
339 return count;
340}
341
342static int lparcfg_data(struct seq_file *m, void *v)
343{
344 int partition_potential_processors;
345 int partition_active_processors;
346 struct device_node *rootdn;
347 const char *model = "";
348 const char *system_id = "";
349 unsigned int *lp_index_ptr, lp_index = 0;
350 struct device_node *rtas_node;
351 int *lrdrp;
352
353 rootdn = find_path_device("/");
354 if (rootdn) {
355 model = get_property(rootdn, "model", NULL);
356 system_id = get_property(rootdn, "system-id", NULL);
357 lp_index_ptr = (unsigned int *)
358 get_property(rootdn, "ibm,partition-no", NULL);
359 if (lp_index_ptr)
360 lp_index = *lp_index_ptr;
361 }
362
363 seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
364
365 seq_printf(m, "serial_number=%s\n", system_id);
366
367 seq_printf(m, "system_type=%s\n", model);
368
369 seq_printf(m, "partition_id=%d\n", (int)lp_index);
370
371 rtas_node = find_path_device("/rtas");
372 lrdrp = (int *)get_property(rtas_node, "ibm,lrdr-capacity", NULL);
373
374 if (lrdrp == NULL) {
375 partition_potential_processors = _systemcfg->processorCount;
376 } else {
377 partition_potential_processors = *(lrdrp + 4);
378 }
379
380 partition_active_processors = lparcfg_count_active_processors();
381
382 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
383 unsigned long h_entitled, h_unallocated;
384 unsigned long h_aggregation, h_resource;
385 unsigned long pool_idle_time, pool_procs;
386 unsigned long purr;
387
388 h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation,
389 &h_resource);
390
391 seq_printf(m, "R4=0x%lx\n", h_entitled);
392 seq_printf(m, "R5=0x%lx\n", h_unallocated);
393 seq_printf(m, "R6=0x%lx\n", h_aggregation);
394 seq_printf(m, "R7=0x%lx\n", h_resource);
395
396 purr = get_purr();
397
398 /* this call handles the ibm,get-system-parameter contents */
399 parse_system_parameter_string(m);
400
401 seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled);
402
403 seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff);
404
405 seq_printf(m, "system_active_processors=%ld\n",
406 (h_resource >> 0 * 8) & 0xffff);
407
408 /* pool related entries are apropriate for shared configs */
409 if (paca[0].lppaca.shared_proc) {
410
411 h_pic(&pool_idle_time, &pool_procs);
412
413 seq_printf(m, "pool=%ld\n",
414 (h_aggregation >> 0 * 8) & 0xffff);
415
416 /* report pool_capacity in percentage */
417 seq_printf(m, "pool_capacity=%ld\n",
418 ((h_resource >> 2 * 8) & 0xffff) * 100);
419
420 seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
421
422 seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
423 }
424
425 seq_printf(m, "unallocated_capacity_weight=%ld\n",
426 (h_resource >> 4 * 8) & 0xFF);
427
428 seq_printf(m, "capacity_weight=%ld\n",
429 (h_resource >> 5 * 8) & 0xFF);
430
431 seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01);
432
433 seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated);
434
435 seq_printf(m, "purr=%ld\n", purr);
436
437 } else { /* non SPLPAR case */
438
439 seq_printf(m, "system_active_processors=%d\n",
440 partition_potential_processors);
441
442 seq_printf(m, "system_potential_processors=%d\n",
443 partition_potential_processors);
444
445 seq_printf(m, "partition_max_entitled_capacity=%d\n",
446 partition_potential_processors * 100);
447
448 seq_printf(m, "partition_entitled_capacity=%d\n",
449 partition_active_processors * 100);
450 }
451
452 seq_printf(m, "partition_active_processors=%d\n",
453 partition_active_processors);
454
455 seq_printf(m, "partition_potential_processors=%d\n",
456 partition_potential_processors);
457
458 seq_printf(m, "shared_processor_mode=%d\n", paca[0].lppaca.shared_proc);
459
460 return 0;
461}
462
463/*
464 * Interface for changing system parameters (variable capacity weight
465 * and entitled capacity). Format of input is "param_name=value";
466 * anything after value is ignored. Valid parameters at this time are
467 * "partition_entitled_capacity" and "capacity_weight". We use
468 * H_SET_PPP to alter parameters.
469 *
470 * This function should be invoked only on systems with
471 * FW_FEATURE_SPLPAR.
472 */
473static ssize_t lparcfg_write(struct file *file, const char __user * buf,
474 size_t count, loff_t * off)
475{
476 char *kbuf;
477 char *tmp;
478 u64 new_entitled, *new_entitled_ptr = &new_entitled;
479 u8 new_weight, *new_weight_ptr = &new_weight;
480
481 unsigned long current_entitled; /* parameters for h_get_ppp */
482 unsigned long dummy;
483 unsigned long resource;
484 u8 current_weight;
485
486 ssize_t retval = -ENOMEM;
487
488 kbuf = kmalloc(count, GFP_KERNEL);
489 if (!kbuf)
490 goto out;
491
492 retval = -EFAULT;
493 if (copy_from_user(kbuf, buf, count))
494 goto out;
495
496 retval = -EINVAL;
497 kbuf[count - 1] = '\0';
498 tmp = strchr(kbuf, '=');
499 if (!tmp)
500 goto out;
501
502 *tmp++ = '\0';
503
504 if (!strcmp(kbuf, "partition_entitled_capacity")) {
505 char *endp;
506 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
507 if (endp == tmp)
508 goto out;
509 new_weight_ptr = &current_weight;
510 } else if (!strcmp(kbuf, "capacity_weight")) {
511 char *endp;
512 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
513 if (endp == tmp)
514 goto out;
515 new_entitled_ptr = &current_entitled;
516 } else
517 goto out;
518
519 /* Get our current parameters */
520 retval = h_get_ppp(&current_entitled, &dummy, &dummy, &resource);
521 if (retval) {
522 retval = -EIO;
523 goto out;
524 }
525
526 current_weight = (resource >> 5 * 8) & 0xFF;
527
528 pr_debug("%s: current_entitled = %lu, current_weight = %lu\n",
529 __FUNCTION__, current_entitled, current_weight);
530
531 pr_debug("%s: new_entitled = %lu, new_weight = %lu\n",
532 __FUNCTION__, *new_entitled_ptr, *new_weight_ptr);
533
534 retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr,
535 *new_weight_ptr);
536
537 if (retval == H_Success || retval == H_Constrained) {
538 retval = count;
539 } else if (retval == H_Busy) {
540 retval = -EBUSY;
541 } else if (retval == H_Hardware) {
542 retval = -EIO;
543 } else if (retval == H_Parameter) {
544 retval = -EINVAL;
545 } else {
546 printk(KERN_WARNING "%s: received unknown hv return code %ld",
547 __FUNCTION__, retval);
548 retval = -EIO;
549 }
550
551 out:
552 kfree(kbuf);
553 return retval;
554}
555
556#endif /* CONFIG_PPC_PSERIES */
557
558static int lparcfg_open(struct inode *inode, struct file *file)
559{
560 return single_open(file, lparcfg_data, NULL);
561}
562
563struct file_operations lparcfg_fops = {
564 .owner = THIS_MODULE,
565 .read = seq_read,
566 .open = lparcfg_open,
567 .release = single_release,
568};
569
570int __init lparcfg_init(void)
571{
572 struct proc_dir_entry *ent;
573 mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
574
575 /* Allow writing if we have FW_FEATURE_SPLPAR */
576 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
577 lparcfg_fops.write = lparcfg_write;
578 mode |= S_IWUSR;
579 }
580
581 ent = create_proc_entry("ppc64/lparcfg", mode, NULL);
582 if (ent) {
583 ent->proc_fops = &lparcfg_fops;
584 ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL);
585 if (!ent->data) {
586 printk(KERN_ERR
587 "Failed to allocate buffer for lparcfg\n");
588 remove_proc_entry("lparcfg", ent->parent);
589 return -ENOMEM;
590 }
591 } else {
592 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
593 return -EIO;
594 }
595
596 proc_ppc64_lparcfg = ent;
597 return 0;
598}
599
600void __exit lparcfg_cleanup(void)
601{
602 if (proc_ppc64_lparcfg) {
603 kfree(proc_ppc64_lparcfg->data);
604 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
605 }
606}
607
608module_init(lparcfg_init);
609module_exit(lparcfg_cleanup);
610MODULE_DESCRIPTION("Interface for LPAR configuration data");
611MODULE_AUTHOR("Dave Engebretsen");
612MODULE_LICENSE("GPL");
diff --git a/arch/ppc64/kernel/proc_ppc64.c b/arch/ppc64/kernel/proc_ppc64.c
deleted file mode 100644
index c893a11ee198..000000000000
--- a/arch/ppc64/kernel/proc_ppc64.c
+++ /dev/null
@@ -1,128 +0,0 @@
1/*
2 * arch/ppc64/kernel/proc_ppc64.c
3 *
4 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/config.h>
22#include <linux/init.h>
23#include <linux/mm.h>
24#include <linux/proc_fs.h>
25#include <linux/slab.h>
26#include <linux/kernel.h>
27
28#include <asm/systemcfg.h>
29#include <asm/rtas.h>
30#include <asm/uaccess.h>
31#include <asm/prom.h>
32
33static loff_t page_map_seek( struct file *file, loff_t off, int whence);
34static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
35 loff_t *ppos);
36static int page_map_mmap( struct file *file, struct vm_area_struct *vma );
37
38static struct file_operations page_map_fops = {
39 .llseek = page_map_seek,
40 .read = page_map_read,
41 .mmap = page_map_mmap
42};
43
44/*
45 * Create the ppc64 and ppc64/rtas directories early. This allows us to
46 * assume that they have been previously created in drivers.
47 */
48static int __init proc_ppc64_create(void)
49{
50 struct proc_dir_entry *root;
51
52 root = proc_mkdir("ppc64", NULL);
53 if (!root)
54 return 1;
55
56 if (!(platform_is_pseries() || _machine == PLATFORM_CELL))
57 return 0;
58
59 if (!proc_mkdir("rtas", root))
60 return 1;
61
62 if (!proc_symlink("rtas", NULL, "ppc64/rtas"))
63 return 1;
64
65 return 0;
66}
67core_initcall(proc_ppc64_create);
68
69static int __init proc_ppc64_init(void)
70{
71 struct proc_dir_entry *pde;
72
73 pde = create_proc_entry("ppc64/systemcfg", S_IFREG|S_IRUGO, NULL);
74 if (!pde)
75 return 1;
76 pde->nlink = 1;
77 pde->data = _systemcfg;
78 pde->size = PAGE_SIZE;
79 pde->proc_fops = &page_map_fops;
80
81 return 0;
82}
83__initcall(proc_ppc64_init);
84
85static loff_t page_map_seek( struct file *file, loff_t off, int whence)
86{
87 loff_t new;
88 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
89
90 switch(whence) {
91 case 0:
92 new = off;
93 break;
94 case 1:
95 new = file->f_pos + off;
96 break;
97 case 2:
98 new = dp->size + off;
99 break;
100 default:
101 return -EINVAL;
102 }
103 if ( new < 0 || new > dp->size )
104 return -EINVAL;
105 return (file->f_pos = new);
106}
107
108static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
109 loff_t *ppos)
110{
111 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
112 return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size);
113}
114
115static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
116{
117 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
118
119 vma->vm_flags |= VM_SHM | VM_LOCKED;
120
121 if ((vma->vm_end - vma->vm_start) > dp->size)
122 return -EINVAL;
123
124 remap_pfn_range(vma, vma->vm_start, __pa(dp->data) >> PAGE_SHIFT,
125 dp->size, vma->vm_page_prot);
126 return 0;
127}
128
diff --git a/arch/ppc64/kernel/rtas_pci.c b/arch/ppc64/kernel/rtas_pci.c
deleted file mode 100644
index 0e5a8e116653..000000000000
--- a/arch/ppc64/kernel/rtas_pci.c
+++ /dev/null
@@ -1,513 +0,0 @@
1/*
2 * arch/ppc64/kernel/rtas_pci.c
3 *
4 * Copyright (C) 2001 Dave Engebretsen, IBM Corporation
5 * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
6 *
7 * RTAS specific routines for PCI.
8 *
9 * Based on code from pci.c, chrp_pci.c and pSeries_pci.c
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#include <linux/kernel.h>
27#include <linux/threads.h>
28#include <linux/pci.h>
29#include <linux/string.h>
30#include <linux/init.h>
31#include <linux/bootmem.h>
32
33#include <asm/io.h>
34#include <asm/pgtable.h>
35#include <asm/irq.h>
36#include <asm/prom.h>
37#include <asm/machdep.h>
38#include <asm/pci-bridge.h>
39#include <asm/iommu.h>
40#include <asm/rtas.h>
41#include <asm/mpic.h>
42#include <asm/ppc-pci.h>
43
44/* RTAS tokens */
45static int read_pci_config;
46static int write_pci_config;
47static int ibm_read_pci_config;
48static int ibm_write_pci_config;
49
50static inline int config_access_valid(struct pci_dn *dn, int where)
51{
52 if (where < 256)
53 return 1;
54 if (where < 4096 && dn->pci_ext_config_space)
55 return 1;
56
57 return 0;
58}
59
60static int of_device_available(struct device_node * dn)
61{
62 char * status;
63
64 status = get_property(dn, "status", NULL);
65
66 if (!status)
67 return 1;
68
69 if (!strcmp(status, "okay"))
70 return 1;
71
72 return 0;
73}
74
75static int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
76{
77 int returnval = -1;
78 unsigned long buid, addr;
79 int ret;
80
81 if (!pdn)
82 return PCIBIOS_DEVICE_NOT_FOUND;
83 if (!config_access_valid(pdn, where))
84 return PCIBIOS_BAD_REGISTER_NUMBER;
85
86 addr = ((where & 0xf00) << 20) | (pdn->busno << 16) |
87 (pdn->devfn << 8) | (where & 0xff);
88 buid = pdn->phb->buid;
89 if (buid) {
90 ret = rtas_call(ibm_read_pci_config, 4, 2, &returnval,
91 addr, BUID_HI(buid), BUID_LO(buid), size);
92 } else {
93 ret = rtas_call(read_pci_config, 2, 2, &returnval, addr, size);
94 }
95 *val = returnval;
96
97 if (ret)
98 return PCIBIOS_DEVICE_NOT_FOUND;
99
100 if (returnval == EEH_IO_ERROR_VALUE(size) &&
101 eeh_dn_check_failure (pdn->node, NULL))
102 return PCIBIOS_DEVICE_NOT_FOUND;
103
104 return PCIBIOS_SUCCESSFUL;
105}
106
107static int rtas_pci_read_config(struct pci_bus *bus,
108 unsigned int devfn,
109 int where, int size, u32 *val)
110{
111 struct device_node *busdn, *dn;
112
113 if (bus->self)
114 busdn = pci_device_to_OF_node(bus->self);
115 else
116 busdn = bus->sysdata; /* must be a phb */
117
118 /* Search only direct children of the bus */
119 for (dn = busdn->child; dn; dn = dn->sibling) {
120 struct pci_dn *pdn = PCI_DN(dn);
121 if (pdn && pdn->devfn == devfn
122 && of_device_available(dn))
123 return rtas_read_config(pdn, where, size, val);
124 }
125
126 return PCIBIOS_DEVICE_NOT_FOUND;
127}
128
129int rtas_write_config(struct pci_dn *pdn, int where, int size, u32 val)
130{
131 unsigned long buid, addr;
132 int ret;
133
134 if (!pdn)
135 return PCIBIOS_DEVICE_NOT_FOUND;
136 if (!config_access_valid(pdn, where))
137 return PCIBIOS_BAD_REGISTER_NUMBER;
138
139 addr = ((where & 0xf00) << 20) | (pdn->busno << 16) |
140 (pdn->devfn << 8) | (where & 0xff);
141 buid = pdn->phb->buid;
142 if (buid) {
143 ret = rtas_call(ibm_write_pci_config, 5, 1, NULL, addr,
144 BUID_HI(buid), BUID_LO(buid), size, (ulong) val);
145 } else {
146 ret = rtas_call(write_pci_config, 3, 1, NULL, addr, size, (ulong)val);
147 }
148
149 if (ret)
150 return PCIBIOS_DEVICE_NOT_FOUND;
151
152 return PCIBIOS_SUCCESSFUL;
153}
154
155static int rtas_pci_write_config(struct pci_bus *bus,
156 unsigned int devfn,
157 int where, int size, u32 val)
158{
159 struct device_node *busdn, *dn;
160
161 if (bus->self)
162 busdn = pci_device_to_OF_node(bus->self);
163 else
164 busdn = bus->sysdata; /* must be a phb */
165
166 /* Search only direct children of the bus */
167 for (dn = busdn->child; dn; dn = dn->sibling) {
168 struct pci_dn *pdn = PCI_DN(dn);
169 if (pdn && pdn->devfn == devfn
170 && of_device_available(dn))
171 return rtas_write_config(pdn, where, size, val);
172 }
173 return PCIBIOS_DEVICE_NOT_FOUND;
174}
175
176struct pci_ops rtas_pci_ops = {
177 rtas_pci_read_config,
178 rtas_pci_write_config
179};
180
181int is_python(struct device_node *dev)
182{
183 char *model = (char *)get_property(dev, "model", NULL);
184
185 if (model && strstr(model, "Python"))
186 return 1;
187
188 return 0;
189}
190
191static int get_phb_reg_prop(struct device_node *dev,
192 unsigned int addr_size_words,
193 struct reg_property64 *reg)
194{
195 unsigned int *ui_ptr = NULL, len;
196
197 /* Found a PHB, now figure out where his registers are mapped. */
198 ui_ptr = (unsigned int *)get_property(dev, "reg", &len);
199 if (ui_ptr == NULL)
200 return 1;
201
202 if (addr_size_words == 1) {
203 reg->address = ((struct reg_property32 *)ui_ptr)->address;
204 reg->size = ((struct reg_property32 *)ui_ptr)->size;
205 } else {
206 *reg = *((struct reg_property64 *)ui_ptr);
207 }
208
209 return 0;
210}
211
212static void python_countermeasures(struct device_node *dev,
213 unsigned int addr_size_words)
214{
215 struct reg_property64 reg_struct;
216 void __iomem *chip_regs;
217 volatile u32 val;
218
219 if (get_phb_reg_prop(dev, addr_size_words, &reg_struct))
220 return;
221
222 /* Python's register file is 1 MB in size. */
223 chip_regs = ioremap(reg_struct.address & ~(0xfffffUL), 0x100000);
224
225 /*
226 * Firmware doesn't always clear this bit which is critical
227 * for good performance - Anton
228 */
229
230#define PRG_CL_RESET_VALID 0x00010000
231
232 val = in_be32(chip_regs + 0xf6030);
233 if (val & PRG_CL_RESET_VALID) {
234 printk(KERN_INFO "Python workaround: ");
235 val &= ~PRG_CL_RESET_VALID;
236 out_be32(chip_regs + 0xf6030, val);
237 /*
238 * We must read it back for changes to
239 * take effect
240 */
241 val = in_be32(chip_regs + 0xf6030);
242 printk("reg0: %x\n", val);
243 }
244
245 iounmap(chip_regs);
246}
247
248void __init init_pci_config_tokens (void)
249{
250 read_pci_config = rtas_token("read-pci-config");
251 write_pci_config = rtas_token("write-pci-config");
252 ibm_read_pci_config = rtas_token("ibm,read-pci-config");
253 ibm_write_pci_config = rtas_token("ibm,write-pci-config");
254}
255
256unsigned long __devinit get_phb_buid (struct device_node *phb)
257{
258 int addr_cells;
259 unsigned int *buid_vals;
260 unsigned int len;
261 unsigned long buid;
262
263 if (ibm_read_pci_config == -1) return 0;
264
265 /* PHB's will always be children of the root node,
266 * or so it is promised by the current firmware. */
267 if (phb->parent == NULL)
268 return 0;
269 if (phb->parent->parent)
270 return 0;
271
272 buid_vals = (unsigned int *) get_property(phb, "reg", &len);
273 if (buid_vals == NULL)
274 return 0;
275
276 addr_cells = prom_n_addr_cells(phb);
277 if (addr_cells == 1) {
278 buid = (unsigned long) buid_vals[0];
279 } else {
280 buid = (((unsigned long)buid_vals[0]) << 32UL) |
281 (((unsigned long)buid_vals[1]) & 0xffffffff);
282 }
283 return buid;
284}
285
286static int phb_set_bus_ranges(struct device_node *dev,
287 struct pci_controller *phb)
288{
289 int *bus_range;
290 unsigned int len;
291
292 bus_range = (int *) get_property(dev, "bus-range", &len);
293 if (bus_range == NULL || len < 2 * sizeof(int)) {
294 return 1;
295 }
296
297 phb->first_busno = bus_range[0];
298 phb->last_busno = bus_range[1];
299
300 return 0;
301}
302
303static int __devinit setup_phb(struct device_node *dev,
304 struct pci_controller *phb,
305 unsigned int addr_size_words)
306{
307 pci_setup_pci_controller(phb);
308
309 if (is_python(dev))
310 python_countermeasures(dev, addr_size_words);
311
312 if (phb_set_bus_ranges(dev, phb))
313 return 1;
314
315 phb->arch_data = dev;
316 phb->ops = &rtas_pci_ops;
317 phb->buid = get_phb_buid(dev);
318
319 return 0;
320}
321
322static void __devinit add_linux_pci_domain(struct device_node *dev,
323 struct pci_controller *phb,
324 struct property *of_prop)
325{
326 memset(of_prop, 0, sizeof(struct property));
327 of_prop->name = "linux,pci-domain";
328 of_prop->length = sizeof(phb->global_number);
329 of_prop->value = (unsigned char *)&of_prop[1];
330 memcpy(of_prop->value, &phb->global_number, sizeof(phb->global_number));
331 prom_add_property(dev, of_prop);
332}
333
334static struct pci_controller * __init alloc_phb(struct device_node *dev,
335 unsigned int addr_size_words)
336{
337 struct pci_controller *phb;
338 struct property *of_prop;
339
340 phb = alloc_bootmem(sizeof(struct pci_controller));
341 if (phb == NULL)
342 return NULL;
343
344 of_prop = alloc_bootmem(sizeof(struct property) +
345 sizeof(phb->global_number));
346 if (!of_prop)
347 return NULL;
348
349 if (setup_phb(dev, phb, addr_size_words))
350 return NULL;
351
352 add_linux_pci_domain(dev, phb, of_prop);
353
354 return phb;
355}
356
357static struct pci_controller * __devinit alloc_phb_dynamic(struct device_node *dev, unsigned int addr_size_words)
358{
359 struct pci_controller *phb;
360
361 phb = (struct pci_controller *)kmalloc(sizeof(struct pci_controller),
362 GFP_KERNEL);
363 if (phb == NULL)
364 return NULL;
365
366 if (setup_phb(dev, phb, addr_size_words))
367 return NULL;
368
369 phb->is_dynamic = 1;
370
371 /* TODO: linux,pci-domain? */
372
373 return phb;
374}
375
376unsigned long __init find_and_init_phbs(void)
377{
378 struct device_node *node;
379 struct pci_controller *phb;
380 unsigned int root_size_cells = 0;
381 unsigned int index;
382 unsigned int *opprop = NULL;
383 struct device_node *root = of_find_node_by_path("/");
384
385 if (ppc64_interrupt_controller == IC_OPEN_PIC) {
386 opprop = (unsigned int *)get_property(root,
387 "platform-open-pic", NULL);
388 }
389
390 root_size_cells = prom_n_size_cells(root);
391
392 index = 0;
393
394 for (node = of_get_next_child(root, NULL);
395 node != NULL;
396 node = of_get_next_child(root, node)) {
397 if (node->type == NULL || strcmp(node->type, "pci") != 0)
398 continue;
399
400 phb = alloc_phb(node, root_size_cells);
401 if (!phb)
402 continue;
403
404 pci_process_bridge_OF_ranges(phb, node, 0);
405 pci_setup_phb_io(phb, index == 0);
406#ifdef CONFIG_PPC_PSERIES
407 if (ppc64_interrupt_controller == IC_OPEN_PIC && pSeries_mpic) {
408 int addr = root_size_cells * (index + 2) - 1;
409 mpic_assign_isu(pSeries_mpic, index, opprop[addr]);
410 }
411#endif
412 index++;
413 }
414
415 of_node_put(root);
416 pci_devs_phb_init();
417
418 /*
419 * pci_probe_only and pci_assign_all_buses can be set via properties
420 * in chosen.
421 */
422 if (of_chosen) {
423 int *prop;
424
425 prop = (int *)get_property(of_chosen, "linux,pci-probe-only",
426 NULL);
427 if (prop)
428 pci_probe_only = *prop;
429
430 prop = (int *)get_property(of_chosen,
431 "linux,pci-assign-all-buses", NULL);
432 if (prop)
433 pci_assign_all_buses = *prop;
434 }
435
436 return 0;
437}
438
439struct pci_controller * __devinit init_phb_dynamic(struct device_node *dn)
440{
441 struct device_node *root = of_find_node_by_path("/");
442 unsigned int root_size_cells = 0;
443 struct pci_controller *phb;
444 int primary;
445
446 root_size_cells = prom_n_size_cells(root);
447
448 primary = list_empty(&hose_list);
449 phb = alloc_phb_dynamic(dn, root_size_cells);
450 if (!phb)
451 return NULL;
452
453 pci_process_bridge_OF_ranges(phb, dn, primary);
454
455 pci_setup_phb_io_dynamic(phb, primary);
456 of_node_put(root);
457
458 pci_devs_phb_init_dynamic(phb);
459 scan_phb(phb);
460
461 return phb;
462}
463EXPORT_SYMBOL(init_phb_dynamic);
464
465/* RPA-specific bits for removing PHBs */
466int pcibios_remove_root_bus(struct pci_controller *phb)
467{
468 struct pci_bus *b = phb->bus;
469 struct resource *res;
470 int rc, i;
471
472 res = b->resource[0];
473 if (!res->flags) {
474 printk(KERN_ERR "%s: no IO resource for PHB %s\n", __FUNCTION__,
475 b->name);
476 return 1;
477 }
478
479 rc = unmap_bus_range(b);
480 if (rc) {
481 printk(KERN_ERR "%s: failed to unmap IO on bus %s\n",
482 __FUNCTION__, b->name);
483 return 1;
484 }
485
486 if (release_resource(res)) {
487 printk(KERN_ERR "%s: failed to release IO on bus %s\n",
488 __FUNCTION__, b->name);
489 return 1;
490 }
491
492 for (i = 1; i < 3; ++i) {
493 res = b->resource[i];
494 if (!res->flags && i == 0) {
495 printk(KERN_ERR "%s: no MEM resource for PHB %s\n",
496 __FUNCTION__, b->name);
497 return 1;
498 }
499 if (res->flags && release_resource(res)) {
500 printk(KERN_ERR
501 "%s: failed to release IO %d on bus %s\n",
502 __FUNCTION__, i, b->name);
503 return 1;
504 }
505 }
506
507 list_del(&phb->list_node);
508 if (phb->is_dynamic)
509 kfree(phb);
510
511 return 0;
512}
513EXPORT_SYMBOL(pcibios_remove_root_bus);
diff --git a/arch/ppc64/kernel/sysfs.c b/arch/ppc64/kernel/sysfs.c
deleted file mode 100644
index e99ec62c2c52..000000000000
--- a/arch/ppc64/kernel/sysfs.c
+++ /dev/null
@@ -1,384 +0,0 @@
1#include <linux/config.h>
2#include <linux/sysdev.h>
3#include <linux/cpu.h>
4#include <linux/smp.h>
5#include <linux/percpu.h>
6#include <linux/init.h>
7#include <linux/sched.h>
8#include <linux/module.h>
9#include <linux/nodemask.h>
10#include <linux/cpumask.h>
11#include <linux/notifier.h>
12
13#include <asm/current.h>
14#include <asm/processor.h>
15#include <asm/cputable.h>
16#include <asm/firmware.h>
17#include <asm/hvcall.h>
18#include <asm/prom.h>
19#include <asm/systemcfg.h>
20#include <asm/paca.h>
21#include <asm/lppaca.h>
22#include <asm/machdep.h>
23#include <asm/smp.h>
24
25static DEFINE_PER_CPU(struct cpu, cpu_devices);
26
27/* SMT stuff */
28
29#ifdef CONFIG_PPC_MULTIPLATFORM
30/* default to snooze disabled */
31DEFINE_PER_CPU(unsigned long, smt_snooze_delay);
32
33static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf,
34 size_t count)
35{
36 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
37 ssize_t ret;
38 unsigned long snooze;
39
40 ret = sscanf(buf, "%lu", &snooze);
41 if (ret != 1)
42 return -EINVAL;
43
44 per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze;
45
46 return count;
47}
48
49static ssize_t show_smt_snooze_delay(struct sys_device *dev, char *buf)
50{
51 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
52
53 return sprintf(buf, "%lu\n", per_cpu(smt_snooze_delay, cpu->sysdev.id));
54}
55
56static SYSDEV_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
57 store_smt_snooze_delay);
58
59/* Only parse OF options if the matching cmdline option was not specified */
60static int smt_snooze_cmdline;
61
62static int __init smt_setup(void)
63{
64 struct device_node *options;
65 unsigned int *val;
66 unsigned int cpu;
67
68 if (!cpu_has_feature(CPU_FTR_SMT))
69 return 1;
70
71 options = find_path_device("/options");
72 if (!options)
73 return 1;
74
75 val = (unsigned int *)get_property(options, "ibm,smt-snooze-delay",
76 NULL);
77 if (!smt_snooze_cmdline && val) {
78 for_each_cpu(cpu)
79 per_cpu(smt_snooze_delay, cpu) = *val;
80 }
81
82 return 1;
83}
84__initcall(smt_setup);
85
86static int __init setup_smt_snooze_delay(char *str)
87{
88 unsigned int cpu;
89 int snooze;
90
91 if (!cpu_has_feature(CPU_FTR_SMT))
92 return 1;
93
94 smt_snooze_cmdline = 1;
95
96 if (get_option(&str, &snooze)) {
97 for_each_cpu(cpu)
98 per_cpu(smt_snooze_delay, cpu) = snooze;
99 }
100
101 return 1;
102}
103__setup("smt-snooze-delay=", setup_smt_snooze_delay);
104
105#endif /* CONFIG_PPC_MULTIPLATFORM */
106
107/*
108 * Enabling PMCs will slow partition context switch times so we only do
109 * it the first time we write to the PMCs.
110 */
111
112static DEFINE_PER_CPU(char, pmcs_enabled);
113
114void ppc64_enable_pmcs(void)
115{
116 /* Only need to enable them once */
117 if (__get_cpu_var(pmcs_enabled))
118 return;
119
120 __get_cpu_var(pmcs_enabled) = 1;
121
122 if (ppc_md.enable_pmcs)
123 ppc_md.enable_pmcs();
124}
125EXPORT_SYMBOL(ppc64_enable_pmcs);
126
127/* XXX convert to rusty's on_one_cpu */
128static unsigned long run_on_cpu(unsigned long cpu,
129 unsigned long (*func)(unsigned long),
130 unsigned long arg)
131{
132 cpumask_t old_affinity = current->cpus_allowed;
133 unsigned long ret;
134
135 /* should return -EINVAL to userspace */
136 if (set_cpus_allowed(current, cpumask_of_cpu(cpu)))
137 return 0;
138
139 ret = func(arg);
140
141 set_cpus_allowed(current, old_affinity);
142
143 return ret;
144}
145
146#define SYSFS_PMCSETUP(NAME, ADDRESS) \
147static unsigned long read_##NAME(unsigned long junk) \
148{ \
149 return mfspr(ADDRESS); \
150} \
151static unsigned long write_##NAME(unsigned long val) \
152{ \
153 ppc64_enable_pmcs(); \
154 mtspr(ADDRESS, val); \
155 return 0; \
156} \
157static ssize_t show_##NAME(struct sys_device *dev, char *buf) \
158{ \
159 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
160 unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
161 return sprintf(buf, "%lx\n", val); \
162} \
163static ssize_t __attribute_used__ \
164 store_##NAME(struct sys_device *dev, const char *buf, size_t count) \
165{ \
166 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
167 unsigned long val; \
168 int ret = sscanf(buf, "%lx", &val); \
169 if (ret != 1) \
170 return -EINVAL; \
171 run_on_cpu(cpu->sysdev.id, write_##NAME, val); \
172 return count; \
173}
174
175SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0);
176SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1);
177SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
178SYSFS_PMCSETUP(pmc1, SPRN_PMC1);
179SYSFS_PMCSETUP(pmc2, SPRN_PMC2);
180SYSFS_PMCSETUP(pmc3, SPRN_PMC3);
181SYSFS_PMCSETUP(pmc4, SPRN_PMC4);
182SYSFS_PMCSETUP(pmc5, SPRN_PMC5);
183SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
184SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
185SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
186SYSFS_PMCSETUP(purr, SPRN_PURR);
187
188static SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0);
189static SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1);
190static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
191static SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1);
192static SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2);
193static SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3);
194static SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4);
195static SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5);
196static SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6);
197static SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7);
198static SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8);
199static SYSDEV_ATTR(purr, 0600, show_purr, NULL);
200
201static void register_cpu_online(unsigned int cpu)
202{
203 struct cpu *c = &per_cpu(cpu_devices, cpu);
204 struct sys_device *s = &c->sysdev;
205
206#ifndef CONFIG_PPC_ISERIES
207 if (cpu_has_feature(CPU_FTR_SMT))
208 sysdev_create_file(s, &attr_smt_snooze_delay);
209#endif
210
211 /* PMC stuff */
212
213 sysdev_create_file(s, &attr_mmcr0);
214 sysdev_create_file(s, &attr_mmcr1);
215
216 if (cpu_has_feature(CPU_FTR_MMCRA))
217 sysdev_create_file(s, &attr_mmcra);
218
219 if (cur_cpu_spec->num_pmcs >= 1)
220 sysdev_create_file(s, &attr_pmc1);
221 if (cur_cpu_spec->num_pmcs >= 2)
222 sysdev_create_file(s, &attr_pmc2);
223 if (cur_cpu_spec->num_pmcs >= 3)
224 sysdev_create_file(s, &attr_pmc3);
225 if (cur_cpu_spec->num_pmcs >= 4)
226 sysdev_create_file(s, &attr_pmc4);
227 if (cur_cpu_spec->num_pmcs >= 5)
228 sysdev_create_file(s, &attr_pmc5);
229 if (cur_cpu_spec->num_pmcs >= 6)
230 sysdev_create_file(s, &attr_pmc6);
231 if (cur_cpu_spec->num_pmcs >= 7)
232 sysdev_create_file(s, &attr_pmc7);
233 if (cur_cpu_spec->num_pmcs >= 8)
234 sysdev_create_file(s, &attr_pmc8);
235
236 if (cpu_has_feature(CPU_FTR_SMT))
237 sysdev_create_file(s, &attr_purr);
238}
239
240#ifdef CONFIG_HOTPLUG_CPU
241static void unregister_cpu_online(unsigned int cpu)
242{
243 struct cpu *c = &per_cpu(cpu_devices, cpu);
244 struct sys_device *s = &c->sysdev;
245
246 BUG_ON(c->no_control);
247
248#ifndef CONFIG_PPC_ISERIES
249 if (cpu_has_feature(CPU_FTR_SMT))
250 sysdev_remove_file(s, &attr_smt_snooze_delay);
251#endif
252
253 /* PMC stuff */
254
255 sysdev_remove_file(s, &attr_mmcr0);
256 sysdev_remove_file(s, &attr_mmcr1);
257
258 if (cpu_has_feature(CPU_FTR_MMCRA))
259 sysdev_remove_file(s, &attr_mmcra);
260
261 if (cur_cpu_spec->num_pmcs >= 1)
262 sysdev_remove_file(s, &attr_pmc1);
263 if (cur_cpu_spec->num_pmcs >= 2)
264 sysdev_remove_file(s, &attr_pmc2);
265 if (cur_cpu_spec->num_pmcs >= 3)
266 sysdev_remove_file(s, &attr_pmc3);
267 if (cur_cpu_spec->num_pmcs >= 4)
268 sysdev_remove_file(s, &attr_pmc4);
269 if (cur_cpu_spec->num_pmcs >= 5)
270 sysdev_remove_file(s, &attr_pmc5);
271 if (cur_cpu_spec->num_pmcs >= 6)
272 sysdev_remove_file(s, &attr_pmc6);
273 if (cur_cpu_spec->num_pmcs >= 7)
274 sysdev_remove_file(s, &attr_pmc7);
275 if (cur_cpu_spec->num_pmcs >= 8)
276 sysdev_remove_file(s, &attr_pmc8);
277
278 if (cpu_has_feature(CPU_FTR_SMT))
279 sysdev_remove_file(s, &attr_purr);
280}
281#endif /* CONFIG_HOTPLUG_CPU */
282
283static int __devinit sysfs_cpu_notify(struct notifier_block *self,
284 unsigned long action, void *hcpu)
285{
286 unsigned int cpu = (unsigned int)(long)hcpu;
287
288 switch (action) {
289 case CPU_ONLINE:
290 register_cpu_online(cpu);
291 break;
292#ifdef CONFIG_HOTPLUG_CPU
293 case CPU_DEAD:
294 unregister_cpu_online(cpu);
295 break;
296#endif
297 }
298 return NOTIFY_OK;
299}
300
301static struct notifier_block __devinitdata sysfs_cpu_nb = {
302 .notifier_call = sysfs_cpu_notify,
303};
304
305/* NUMA stuff */
306
307#ifdef CONFIG_NUMA
308static struct node node_devices[MAX_NUMNODES];
309
310static void register_nodes(void)
311{
312 int i;
313
314 for (i = 0; i < MAX_NUMNODES; i++) {
315 if (node_online(i)) {
316 int p_node = parent_node(i);
317 struct node *parent = NULL;
318
319 if (p_node != i)
320 parent = &node_devices[p_node];
321
322 register_node(&node_devices[i], i, parent);
323 }
324 }
325}
326#else
327static void register_nodes(void)
328{
329 return;
330}
331#endif
332
333/* Only valid if CPU is present. */
334static ssize_t show_physical_id(struct sys_device *dev, char *buf)
335{
336 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
337
338 return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->sysdev.id));
339}
340static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL);
341
342static int __init topology_init(void)
343{
344 int cpu;
345 struct node *parent = NULL;
346
347 register_nodes();
348
349 register_cpu_notifier(&sysfs_cpu_nb);
350
351 for_each_cpu(cpu) {
352 struct cpu *c = &per_cpu(cpu_devices, cpu);
353
354#ifdef CONFIG_NUMA
355 /* The node to which a cpu belongs can't be known
356 * until the cpu is made present.
357 */
358 parent = NULL;
359 if (cpu_present(cpu))
360 parent = &node_devices[cpu_to_node(cpu)];
361#endif
362 /*
363 * For now, we just see if the system supports making
364 * the RTAS calls for CPU hotplug. But, there may be a
365 * more comprehensive way to do this for an individual
366 * CPU. For instance, the boot cpu might never be valid
367 * for hotplugging.
368 */
369 if (!ppc_md.cpu_die)
370 c->no_control = 1;
371
372 if (cpu_online(cpu) || (c->no_control == 0)) {
373 register_cpu(c, cpu, parent);
374
375 sysdev_create_file(&c->sysdev, &attr_physical_id);
376 }
377
378 if (cpu_online(cpu))
379 register_cpu_online(cpu);
380 }
381
382 return 0;
383}
384__initcall(topology_init);