aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/pseries
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms/pseries')
-rw-r--r--arch/powerpc/platforms/pseries/Kconfig9
-rw-r--r--arch/powerpc/platforms/pseries/Makefile1
-rw-r--r--arch/powerpc/platforms/pseries/hvCall_inst.c4
-rw-r--r--arch/powerpc/platforms/pseries/iommu.c61
-rw-r--r--arch/powerpc/platforms/pseries/lpar.c2
-rw-r--r--arch/powerpc/platforms/pseries/nvram.c7
-rw-r--r--arch/powerpc/platforms/pseries/processor_idle.c329
-rw-r--r--arch/powerpc/platforms/pseries/pseries.h3
-rw-r--r--arch/powerpc/platforms/pseries/setup.c109
-rw-r--r--arch/powerpc/platforms/pseries/smp.c1
10 files changed, 429 insertions, 97 deletions
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index c81f6bb9c10f..ae7b6d41fed3 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -120,3 +120,12 @@ config DTL
120 which are accessible through a debugfs file. 120 which are accessible through a debugfs file.
121 121
122 Say N if you are unsure. 122 Say N if you are unsure.
123
124config PSERIES_IDLE
125 tristate "Cpuidle driver for pSeries platforms"
126 depends on CPU_IDLE
127 depends on PPC_PSERIES
128 default y
129 help
130 Select this option to enable processor idle state management
131 through cpuidle subsystem.
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index 3556e402cbf5..236db46b4078 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_PHYP_DUMP) += phyp_dump.o
22obj-$(CONFIG_CMM) += cmm.o 22obj-$(CONFIG_CMM) += cmm.o
23obj-$(CONFIG_DTL) += dtl.o 23obj-$(CONFIG_DTL) += dtl.o
24obj-$(CONFIG_IO_EVENT_IRQ) += io_event_irq.o 24obj-$(CONFIG_IO_EVENT_IRQ) += io_event_irq.o
25obj-$(CONFIG_PSERIES_IDLE) += processor_idle.o
25 26
26ifeq ($(CONFIG_PPC_PSERIES),y) 27ifeq ($(CONFIG_PPC_PSERIES),y)
27obj-$(CONFIG_SUSPEND) += suspend.o 28obj-$(CONFIG_SUSPEND) += suspend.o
diff --git a/arch/powerpc/platforms/pseries/hvCall_inst.c b/arch/powerpc/platforms/pseries/hvCall_inst.c
index f106662f4381..c9311cfdfcac 100644
--- a/arch/powerpc/platforms/pseries/hvCall_inst.c
+++ b/arch/powerpc/platforms/pseries/hvCall_inst.c
@@ -109,7 +109,7 @@ static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long
109 if (opcode > MAX_HCALL_OPCODE) 109 if (opcode > MAX_HCALL_OPCODE)
110 return; 110 return;
111 111
112 h = &get_cpu_var(hcall_stats)[opcode / 4]; 112 h = &__get_cpu_var(hcall_stats)[opcode / 4];
113 h->tb_start = mftb(); 113 h->tb_start = mftb();
114 h->purr_start = mfspr(SPRN_PURR); 114 h->purr_start = mfspr(SPRN_PURR);
115} 115}
@@ -126,8 +126,6 @@ static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long
126 h->num_calls++; 126 h->num_calls++;
127 h->tb_total += mftb() - h->tb_start; 127 h->tb_total += mftb() - h->tb_start;
128 h->purr_total += mfspr(SPRN_PURR) - h->purr_start; 128 h->purr_total += mfspr(SPRN_PURR) - h->purr_start;
129
130 put_cpu_var(hcall_stats);
131} 129}
132 130
133static int __init hcall_inst_init(void) 131static int __init hcall_inst_init(void)
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index b719d9709730..c442f2b1980f 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -52,13 +52,42 @@
52#include "plpar_wrappers.h" 52#include "plpar_wrappers.h"
53 53
54 54
55static void tce_invalidate_pSeries_sw(struct iommu_table *tbl,
56 u64 *startp, u64 *endp)
57{
58 u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index;
59 unsigned long start, end, inc;
60
61 start = __pa(startp);
62 end = __pa(endp);
63 inc = L1_CACHE_BYTES; /* invalidate a cacheline of TCEs at a time */
64
65 /* If this is non-zero, change the format. We shift the
66 * address and or in the magic from the device tree. */
67 if (tbl->it_busno) {
68 start <<= 12;
69 end <<= 12;
70 inc <<= 12;
71 start |= tbl->it_busno;
72 end |= tbl->it_busno;
73 }
74
75 end |= inc - 1; /* round up end to be different than start */
76
77 mb(); /* Make sure TCEs in memory are written */
78 while (start <= end) {
79 out_be64(invalidate, start);
80 start += inc;
81 }
82}
83
55static int tce_build_pSeries(struct iommu_table *tbl, long index, 84static int tce_build_pSeries(struct iommu_table *tbl, long index,
56 long npages, unsigned long uaddr, 85 long npages, unsigned long uaddr,
57 enum dma_data_direction direction, 86 enum dma_data_direction direction,
58 struct dma_attrs *attrs) 87 struct dma_attrs *attrs)
59{ 88{
60 u64 proto_tce; 89 u64 proto_tce;
61 u64 *tcep; 90 u64 *tcep, *tces;
62 u64 rpn; 91 u64 rpn;
63 92
64 proto_tce = TCE_PCI_READ; // Read allowed 93 proto_tce = TCE_PCI_READ; // Read allowed
@@ -66,7 +95,7 @@ static int tce_build_pSeries(struct iommu_table *tbl, long index,
66 if (direction != DMA_TO_DEVICE) 95 if (direction != DMA_TO_DEVICE)
67 proto_tce |= TCE_PCI_WRITE; 96 proto_tce |= TCE_PCI_WRITE;
68 97
69 tcep = ((u64 *)tbl->it_base) + index; 98 tces = tcep = ((u64 *)tbl->it_base) + index;
70 99
71 while (npages--) { 100 while (npages--) {
72 /* can't move this out since we might cross MEMBLOCK boundary */ 101 /* can't move this out since we might cross MEMBLOCK boundary */
@@ -76,18 +105,24 @@ static int tce_build_pSeries(struct iommu_table *tbl, long index,
76 uaddr += TCE_PAGE_SIZE; 105 uaddr += TCE_PAGE_SIZE;
77 tcep++; 106 tcep++;
78 } 107 }
108
109 if (tbl->it_type == TCE_PCI_SWINV_CREATE)
110 tce_invalidate_pSeries_sw(tbl, tces, tcep - 1);
79 return 0; 111 return 0;
80} 112}
81 113
82 114
83static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages) 115static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages)
84{ 116{
85 u64 *tcep; 117 u64 *tcep, *tces;
86 118
87 tcep = ((u64 *)tbl->it_base) + index; 119 tces = tcep = ((u64 *)tbl->it_base) + index;
88 120
89 while (npages--) 121 while (npages--)
90 *(tcep++) = 0; 122 *(tcep++) = 0;
123
124 if (tbl->it_type == TCE_PCI_SWINV_FREE)
125 tce_invalidate_pSeries_sw(tbl, tces, tcep - 1);
91} 126}
92 127
93static unsigned long tce_get_pseries(struct iommu_table *tbl, long index) 128static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
@@ -425,7 +460,7 @@ static void iommu_table_setparms(struct pci_controller *phb,
425 struct iommu_table *tbl) 460 struct iommu_table *tbl)
426{ 461{
427 struct device_node *node; 462 struct device_node *node;
428 const unsigned long *basep; 463 const unsigned long *basep, *sw_inval;
429 const u32 *sizep; 464 const u32 *sizep;
430 465
431 node = phb->dn; 466 node = phb->dn;
@@ -462,6 +497,22 @@ static void iommu_table_setparms(struct pci_controller *phb,
462 tbl->it_index = 0; 497 tbl->it_index = 0;
463 tbl->it_blocksize = 16; 498 tbl->it_blocksize = 16;
464 tbl->it_type = TCE_PCI; 499 tbl->it_type = TCE_PCI;
500
501 sw_inval = of_get_property(node, "linux,tce-sw-invalidate-info", NULL);
502 if (sw_inval) {
503 /*
504 * This property contains information on how to
505 * invalidate the TCE entry. The first property is
506 * the base MMIO address used to invalidate entries.
507 * The second property tells us the format of the TCE
508 * invalidate (whether it needs to be shifted) and
509 * some magic routing info to add to our invalidate
510 * command.
511 */
512 tbl->it_index = (unsigned long) ioremap(sw_inval[0], 8);
513 tbl->it_busno = sw_inval[1]; /* overload this with magic */
514 tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE;
515 }
465} 516}
466 517
467/* 518/*
diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index 52d429be6c76..948e0e3b3547 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -554,6 +554,7 @@ void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
554 goto out; 554 goto out;
555 555
556 (*depth)++; 556 (*depth)++;
557 preempt_disable();
557 trace_hcall_entry(opcode, args); 558 trace_hcall_entry(opcode, args);
558 if (opcode == H_CEDE) 559 if (opcode == H_CEDE)
559 rcu_idle_enter(); 560 rcu_idle_enter();
@@ -580,6 +581,7 @@ void __trace_hcall_exit(long opcode, unsigned long retval,
580 if (opcode == H_CEDE) 581 if (opcode == H_CEDE)
581 rcu_idle_exit(); 582 rcu_idle_exit();
582 trace_hcall_exit(opcode, retval, retbuf); 583 trace_hcall_exit(opcode, retval, retbuf);
584 preempt_enable();
583 (*depth)--; 585 (*depth)--;
584 586
585out: 587out:
diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c
index a76b22844d18..330a57b7c17c 100644
--- a/arch/powerpc/platforms/pseries/nvram.c
+++ b/arch/powerpc/platforms/pseries/nvram.c
@@ -625,6 +625,8 @@ static void oops_to_nvram(struct kmsg_dumper *dumper,
625{ 625{
626 static unsigned int oops_count = 0; 626 static unsigned int oops_count = 0;
627 static bool panicking = false; 627 static bool panicking = false;
628 static DEFINE_SPINLOCK(lock);
629 unsigned long flags;
628 size_t text_len; 630 size_t text_len;
629 unsigned int err_type = ERR_TYPE_KERNEL_PANIC_GZ; 631 unsigned int err_type = ERR_TYPE_KERNEL_PANIC_GZ;
630 int rc = -1; 632 int rc = -1;
@@ -655,6 +657,9 @@ static void oops_to_nvram(struct kmsg_dumper *dumper,
655 if (clobbering_unread_rtas_event()) 657 if (clobbering_unread_rtas_event())
656 return; 658 return;
657 659
660 if (!spin_trylock_irqsave(&lock, flags))
661 return;
662
658 if (big_oops_buf) { 663 if (big_oops_buf) {
659 text_len = capture_last_msgs(old_msgs, old_len, 664 text_len = capture_last_msgs(old_msgs, old_len,
660 new_msgs, new_len, big_oops_buf, big_oops_buf_sz); 665 new_msgs, new_len, big_oops_buf, big_oops_buf_sz);
@@ -670,4 +675,6 @@ static void oops_to_nvram(struct kmsg_dumper *dumper,
670 675
671 (void) nvram_write_os_partition(&oops_log_partition, oops_buf, 676 (void) nvram_write_os_partition(&oops_log_partition, oops_buf,
672 (int) (sizeof(*oops_len) + *oops_len), err_type, ++oops_count); 677 (int) (sizeof(*oops_len) + *oops_len), err_type, ++oops_count);
678
679 spin_unlock_irqrestore(&lock, flags);
673} 680}
diff --git a/arch/powerpc/platforms/pseries/processor_idle.c b/arch/powerpc/platforms/pseries/processor_idle.c
new file mode 100644
index 000000000000..085fd3f45ad2
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/processor_idle.c
@@ -0,0 +1,329 @@
1/*
2 * processor_idle - idle state cpuidle driver.
3 * Adapted from drivers/idle/intel_idle.c and
4 * drivers/acpi/processor_idle.c
5 *
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/moduleparam.h>
12#include <linux/cpuidle.h>
13#include <linux/cpu.h>
14
15#include <asm/paca.h>
16#include <asm/reg.h>
17#include <asm/system.h>
18#include <asm/machdep.h>
19#include <asm/firmware.h>
20
21#include "plpar_wrappers.h"
22#include "pseries.h"
23
24struct cpuidle_driver pseries_idle_driver = {
25 .name = "pseries_idle",
26 .owner = THIS_MODULE,
27};
28
29#define MAX_IDLE_STATE_COUNT 2
30
31static int max_idle_state = MAX_IDLE_STATE_COUNT - 1;
32static struct cpuidle_device __percpu *pseries_cpuidle_devices;
33static struct cpuidle_state *cpuidle_state_table;
34
35void update_smt_snooze_delay(int snooze)
36{
37 struct cpuidle_driver *drv = cpuidle_get_driver();
38 if (drv)
39 drv->states[0].target_residency = snooze;
40}
41
42static inline void idle_loop_prolog(unsigned long *in_purr, ktime_t *kt_before)
43{
44
45 *kt_before = ktime_get_real();
46 *in_purr = mfspr(SPRN_PURR);
47 /*
48 * Indicate to the HV that we are idle. Now would be
49 * a good time to find other work to dispatch.
50 */
51 get_lppaca()->idle = 1;
52}
53
54static inline s64 idle_loop_epilog(unsigned long in_purr, ktime_t kt_before)
55{
56 get_lppaca()->wait_state_cycles += mfspr(SPRN_PURR) - in_purr;
57 get_lppaca()->idle = 0;
58
59 return ktime_to_us(ktime_sub(ktime_get_real(), kt_before));
60}
61
62static int snooze_loop(struct cpuidle_device *dev,
63 struct cpuidle_driver *drv,
64 int index)
65{
66 unsigned long in_purr;
67 ktime_t kt_before;
68 unsigned long start_snooze;
69 long snooze = drv->states[0].target_residency;
70
71 idle_loop_prolog(&in_purr, &kt_before);
72
73 if (snooze) {
74 start_snooze = get_tb() + snooze * tb_ticks_per_usec;
75 local_irq_enable();
76 set_thread_flag(TIF_POLLING_NRFLAG);
77
78 while ((snooze < 0) || (get_tb() < start_snooze)) {
79 if (need_resched() || cpu_is_offline(dev->cpu))
80 goto out;
81 ppc64_runlatch_off();
82 HMT_low();
83 HMT_very_low();
84 }
85
86 HMT_medium();
87 clear_thread_flag(TIF_POLLING_NRFLAG);
88 smp_mb();
89 local_irq_disable();
90 }
91
92out:
93 HMT_medium();
94 dev->last_residency =
95 (int)idle_loop_epilog(in_purr, kt_before);
96 return index;
97}
98
99static int dedicated_cede_loop(struct cpuidle_device *dev,
100 struct cpuidle_driver *drv,
101 int index)
102{
103 unsigned long in_purr;
104 ktime_t kt_before;
105
106 idle_loop_prolog(&in_purr, &kt_before);
107 get_lppaca()->donate_dedicated_cpu = 1;
108
109 ppc64_runlatch_off();
110 HMT_medium();
111 cede_processor();
112
113 get_lppaca()->donate_dedicated_cpu = 0;
114 dev->last_residency =
115 (int)idle_loop_epilog(in_purr, kt_before);
116 return index;
117}
118
119static int shared_cede_loop(struct cpuidle_device *dev,
120 struct cpuidle_driver *drv,
121 int index)
122{
123 unsigned long in_purr;
124 ktime_t kt_before;
125
126 idle_loop_prolog(&in_purr, &kt_before);
127
128 /*
129 * Yield the processor to the hypervisor. We return if
130 * an external interrupt occurs (which are driven prior
131 * to returning here) or if a prod occurs from another
132 * processor. When returning here, external interrupts
133 * are enabled.
134 */
135 cede_processor();
136
137 dev->last_residency =
138 (int)idle_loop_epilog(in_purr, kt_before);
139 return index;
140}
141
142/*
143 * States for dedicated partition case.
144 */
145static struct cpuidle_state dedicated_states[MAX_IDLE_STATE_COUNT] = {
146 { /* Snooze */
147 .name = "snooze",
148 .desc = "snooze",
149 .flags = CPUIDLE_FLAG_TIME_VALID,
150 .exit_latency = 0,
151 .target_residency = 0,
152 .enter = &snooze_loop },
153 { /* CEDE */
154 .name = "CEDE",
155 .desc = "CEDE",
156 .flags = CPUIDLE_FLAG_TIME_VALID,
157 .exit_latency = 1,
158 .target_residency = 10,
159 .enter = &dedicated_cede_loop },
160};
161
162/*
163 * States for shared partition case.
164 */
165static struct cpuidle_state shared_states[MAX_IDLE_STATE_COUNT] = {
166 { /* Shared Cede */
167 .name = "Shared Cede",
168 .desc = "Shared Cede",
169 .flags = CPUIDLE_FLAG_TIME_VALID,
170 .exit_latency = 0,
171 .target_residency = 0,
172 .enter = &shared_cede_loop },
173};
174
175int pseries_notify_cpuidle_add_cpu(int cpu)
176{
177 struct cpuidle_device *dev =
178 per_cpu_ptr(pseries_cpuidle_devices, cpu);
179 if (dev && cpuidle_get_driver()) {
180 cpuidle_disable_device(dev);
181 cpuidle_enable_device(dev);
182 }
183 return 0;
184}
185
186/*
187 * pseries_cpuidle_driver_init()
188 */
189static int pseries_cpuidle_driver_init(void)
190{
191 int idle_state;
192 struct cpuidle_driver *drv = &pseries_idle_driver;
193
194 drv->state_count = 0;
195
196 for (idle_state = 0; idle_state < MAX_IDLE_STATE_COUNT; ++idle_state) {
197
198 if (idle_state > max_idle_state)
199 break;
200
201 /* is the state not enabled? */
202 if (cpuidle_state_table[idle_state].enter == NULL)
203 continue;
204
205 drv->states[drv->state_count] = /* structure copy */
206 cpuidle_state_table[idle_state];
207
208 if (cpuidle_state_table == dedicated_states)
209 drv->states[drv->state_count].target_residency =
210 __get_cpu_var(smt_snooze_delay);
211
212 drv->state_count += 1;
213 }
214
215 return 0;
216}
217
218/* pseries_idle_devices_uninit(void)
219 * unregister cpuidle devices and de-allocate memory
220 */
221static void pseries_idle_devices_uninit(void)
222{
223 int i;
224 struct cpuidle_device *dev;
225
226 for_each_possible_cpu(i) {
227 dev = per_cpu_ptr(pseries_cpuidle_devices, i);
228 cpuidle_unregister_device(dev);
229 }
230
231 free_percpu(pseries_cpuidle_devices);
232 return;
233}
234
235/* pseries_idle_devices_init()
236 * allocate, initialize and register cpuidle device
237 */
238static int pseries_idle_devices_init(void)
239{
240 int i;
241 struct cpuidle_driver *drv = &pseries_idle_driver;
242 struct cpuidle_device *dev;
243
244 pseries_cpuidle_devices = alloc_percpu(struct cpuidle_device);
245 if (pseries_cpuidle_devices == NULL)
246 return -ENOMEM;
247
248 for_each_possible_cpu(i) {
249 dev = per_cpu_ptr(pseries_cpuidle_devices, i);
250 dev->state_count = drv->state_count;
251 dev->cpu = i;
252 if (cpuidle_register_device(dev)) {
253 printk(KERN_DEBUG \
254 "cpuidle_register_device %d failed!\n", i);
255 return -EIO;
256 }
257 }
258
259 return 0;
260}
261
262/*
263 * pseries_idle_probe()
264 * Choose state table for shared versus dedicated partition
265 */
266static int pseries_idle_probe(void)
267{
268
269 if (!firmware_has_feature(FW_FEATURE_SPLPAR))
270 return -ENODEV;
271
272 if (cpuidle_disable != IDLE_NO_OVERRIDE)
273 return -ENODEV;
274
275 if (max_idle_state == 0) {
276 printk(KERN_DEBUG "pseries processor idle disabled.\n");
277 return -EPERM;
278 }
279
280 if (get_lppaca()->shared_proc)
281 cpuidle_state_table = shared_states;
282 else
283 cpuidle_state_table = dedicated_states;
284
285 return 0;
286}
287
288static int __init pseries_processor_idle_init(void)
289{
290 int retval;
291
292 retval = pseries_idle_probe();
293 if (retval)
294 return retval;
295
296 pseries_cpuidle_driver_init();
297 retval = cpuidle_register_driver(&pseries_idle_driver);
298 if (retval) {
299 printk(KERN_DEBUG "Registration of pseries driver failed.\n");
300 return retval;
301 }
302
303 retval = pseries_idle_devices_init();
304 if (retval) {
305 pseries_idle_devices_uninit();
306 cpuidle_unregister_driver(&pseries_idle_driver);
307 return retval;
308 }
309
310 printk(KERN_DEBUG "pseries_idle_driver registered\n");
311
312 return 0;
313}
314
315static void __exit pseries_processor_idle_exit(void)
316{
317
318 pseries_idle_devices_uninit();
319 cpuidle_unregister_driver(&pseries_idle_driver);
320
321 return;
322}
323
324module_init(pseries_processor_idle_init);
325module_exit(pseries_processor_idle_exit);
326
327MODULE_AUTHOR("Deepthi Dharwar <deepthi@linux.vnet.ibm.com>");
328MODULE_DESCRIPTION("Cpuidle driver for POWER");
329MODULE_LICENSE("GPL");
diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h
index 24c7162f11d9..9a3dda07566f 100644
--- a/arch/powerpc/platforms/pseries/pseries.h
+++ b/arch/powerpc/platforms/pseries/pseries.h
@@ -57,4 +57,7 @@ extern struct device_node *dlpar_configure_connector(u32);
57extern int dlpar_attach_node(struct device_node *); 57extern int dlpar_attach_node(struct device_node *);
58extern int dlpar_detach_node(struct device_node *); 58extern int dlpar_detach_node(struct device_node *);
59 59
60/* Snooze Delay, pseries_idle */
61DECLARE_PER_CPU(long, smt_snooze_delay);
62
60#endif /* _PSERIES_PSERIES_H */ 63#endif /* _PSERIES_PSERIES_H */
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index c3408ca8855e..f79f1278dfca 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -39,6 +39,7 @@
39#include <linux/irq.h> 39#include <linux/irq.h>
40#include <linux/seq_file.h> 40#include <linux/seq_file.h>
41#include <linux/root_dev.h> 41#include <linux/root_dev.h>
42#include <linux/cpuidle.h>
42 43
43#include <asm/mmu.h> 44#include <asm/mmu.h>
44#include <asm/processor.h> 45#include <asm/processor.h>
@@ -74,9 +75,6 @@ EXPORT_SYMBOL(CMO_PageSize);
74 75
75int fwnmi_active; /* TRUE if an FWNMI handler is present */ 76int fwnmi_active; /* TRUE if an FWNMI handler is present */
76 77
77static void pseries_shared_idle_sleep(void);
78static void pseries_dedicated_idle_sleep(void);
79
80static struct device_node *pSeries_mpic_node; 78static struct device_node *pSeries_mpic_node;
81 79
82static void pSeries_show_cpuinfo(struct seq_file *m) 80static void pSeries_show_cpuinfo(struct seq_file *m)
@@ -192,8 +190,7 @@ static void __init pseries_mpic_init_IRQ(void)
192 BUG_ON(openpic_addr == 0); 190 BUG_ON(openpic_addr == 0);
193 191
194 /* Setup the openpic driver */ 192 /* Setup the openpic driver */
195 mpic = mpic_alloc(pSeries_mpic_node, openpic_addr, 193 mpic = mpic_alloc(pSeries_mpic_node, openpic_addr, 0,
196 MPIC_PRIMARY,
197 16, 250, /* isu size, irq count */ 194 16, 250, /* isu size, irq count */
198 " MPIC "); 195 " MPIC ");
199 BUG_ON(mpic == NULL); 196 BUG_ON(mpic == NULL);
@@ -352,8 +349,25 @@ static int alloc_dispatch_log_kmem_cache(void)
352} 349}
353early_initcall(alloc_dispatch_log_kmem_cache); 350early_initcall(alloc_dispatch_log_kmem_cache);
354 351
352static void pSeries_idle(void)
353{
354 /* This would call on the cpuidle framework, and the back-end pseries
355 * driver to go to idle states
356 */
357 if (cpuidle_idle_call()) {
358 /* On error, execute default handler
359 * to go into low thread priority and possibly
360 * low power mode.
361 */
362 HMT_low();
363 HMT_very_low();
364 }
365}
366
355static void __init pSeries_setup_arch(void) 367static void __init pSeries_setup_arch(void)
356{ 368{
369 panic_timeout = 10;
370
357 /* Discover PIC type and setup ppc_md accordingly */ 371 /* Discover PIC type and setup ppc_md accordingly */
358 pseries_discover_pic(); 372 pseries_discover_pic();
359 373
@@ -374,18 +388,9 @@ static void __init pSeries_setup_arch(void)
374 388
375 pSeries_nvram_init(); 389 pSeries_nvram_init();
376 390
377 /* Choose an idle loop */
378 if (firmware_has_feature(FW_FEATURE_SPLPAR)) { 391 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
379 vpa_init(boot_cpuid); 392 vpa_init(boot_cpuid);
380 if (get_lppaca()->shared_proc) { 393 ppc_md.power_save = pSeries_idle;
381 printk(KERN_DEBUG "Using shared processor idle loop\n");
382 ppc_md.power_save = pseries_shared_idle_sleep;
383 } else {
384 printk(KERN_DEBUG "Using dedicated idle loop\n");
385 ppc_md.power_save = pseries_dedicated_idle_sleep;
386 }
387 } else {
388 printk(KERN_DEBUG "Using default idle loop\n");
389 } 394 }
390 395
391 if (firmware_has_feature(FW_FEATURE_LPAR)) 396 if (firmware_has_feature(FW_FEATURE_LPAR))
@@ -586,80 +591,6 @@ static int __init pSeries_probe(void)
586 return 1; 591 return 1;
587} 592}
588 593
589
590DECLARE_PER_CPU(long, smt_snooze_delay);
591
592static void pseries_dedicated_idle_sleep(void)
593{
594 unsigned int cpu = smp_processor_id();
595 unsigned long start_snooze;
596 unsigned long in_purr, out_purr;
597 long snooze = __get_cpu_var(smt_snooze_delay);
598
599 /*
600 * Indicate to the HV that we are idle. Now would be
601 * a good time to find other work to dispatch.
602 */
603 get_lppaca()->idle = 1;
604 get_lppaca()->donate_dedicated_cpu = 1;
605 in_purr = mfspr(SPRN_PURR);
606
607 /*
608 * We come in with interrupts disabled, and need_resched()
609 * has been checked recently. If we should poll for a little
610 * while, do so.
611 */
612 if (snooze) {
613 start_snooze = get_tb() + snooze * tb_ticks_per_usec;
614 local_irq_enable();
615 set_thread_flag(TIF_POLLING_NRFLAG);
616
617 while ((snooze < 0) || (get_tb() < start_snooze)) {
618 if (need_resched() || cpu_is_offline(cpu))
619 goto out;
620 ppc64_runlatch_off();
621 HMT_low();
622 HMT_very_low();
623 }
624
625 HMT_medium();
626 clear_thread_flag(TIF_POLLING_NRFLAG);
627 smp_mb();
628 local_irq_disable();
629 if (need_resched() || cpu_is_offline(cpu))
630 goto out;
631 }
632
633 cede_processor();
634
635out:
636 HMT_medium();
637 out_purr = mfspr(SPRN_PURR);
638 get_lppaca()->wait_state_cycles += out_purr - in_purr;
639 get_lppaca()->donate_dedicated_cpu = 0;
640 get_lppaca()->idle = 0;
641}
642
643static void pseries_shared_idle_sleep(void)
644{
645 /*
646 * Indicate to the HV that we are idle. Now would be
647 * a good time to find other work to dispatch.
648 */
649 get_lppaca()->idle = 1;
650
651 /*
652 * Yield the processor to the hypervisor. We return if
653 * an external interrupt occurs (which are driven prior
654 * to returning here) or if a prod occurs from another
655 * processor. When returning here, external interrupts
656 * are enabled.
657 */
658 cede_processor();
659
660 get_lppaca()->idle = 0;
661}
662
663static int pSeries_pci_probe_mode(struct pci_bus *bus) 594static int pSeries_pci_probe_mode(struct pci_bus *bus)
664{ 595{
665 if (firmware_has_feature(FW_FEATURE_LPAR)) 596 if (firmware_has_feature(FW_FEATURE_LPAR))
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index 26e93fd4c62b..bbc3c42f6730 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -148,6 +148,7 @@ static void __devinit smp_xics_setup_cpu(int cpu)
148 set_cpu_current_state(cpu, CPU_STATE_ONLINE); 148 set_cpu_current_state(cpu, CPU_STATE_ONLINE);
149 set_default_offline_state(cpu); 149 set_default_offline_state(cpu);
150#endif 150#endif
151 pseries_notify_cpuidle_add_cpu(cpu);
151} 152}
152 153
153static int __devinit smp_pSeries_kick_cpu(int nr) 154static int __devinit smp_pSeries_kick_cpu(int nr)