1 | /* |
---|
2 | * ppc_idle.c |
---|
3 | * |
---|
4 | * Authorship |
---|
5 | * ---------- |
---|
6 | * This software was created by |
---|
7 | * Till Straumann <strauman@slac.stanford.edu>, 2010, |
---|
8 | * Stanford Linear Accelerator Center, Stanford University. |
---|
9 | * |
---|
10 | * Acknowledgement of sponsorship |
---|
11 | * ------------------------------ |
---|
12 | * This software was produced by |
---|
13 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
14 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
15 | * |
---|
16 | * Government disclaimer of liability |
---|
17 | * ---------------------------------- |
---|
18 | * Neither the United States nor the United States Department of Energy, |
---|
19 | * nor any of their employees, makes any warranty, express or implied, or |
---|
20 | * assumes any legal liability or responsibility for the accuracy, |
---|
21 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
22 | * disclosed, or represents that its use would not infringe privately owned |
---|
23 | * rights. |
---|
24 | * |
---|
25 | * Stanford disclaimer of liability |
---|
26 | * -------------------------------- |
---|
27 | * Stanford University makes no representations or warranties, express or |
---|
28 | * implied, nor assumes any liability for the use of this software. |
---|
29 | * |
---|
30 | * Stanford disclaimer of copyright |
---|
31 | * -------------------------------- |
---|
32 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
33 | * copyright and all other rights in this software. Hence, anyone may |
---|
34 | * freely use it for any purpose without restriction. |
---|
35 | * |
---|
36 | * Maintenance of notices |
---|
37 | * ---------------------- |
---|
38 | * In the interest of clarity regarding the origin and status of this |
---|
39 | * SLAC software, this and all the preceding Stanford University notices |
---|
40 | * are to remain affixed to any copy or derivative of this software made |
---|
41 | * or distributed by the recipient and are to be affixed to any copy of |
---|
42 | * software made or distributed by the recipient that contains a copy or |
---|
43 | * derivative of this software. |
---|
44 | * |
---|
45 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
46 | */ |
---|
47 | #include <bsp.h> |
---|
48 | #include <stdint.h> |
---|
49 | |
---|
50 | #ifdef BSP_IDLE_TASK_BODY |
---|
51 | |
---|
52 | /* Provide an idle-task body which switches the |
---|
53 | * CPU into power-save mode when idle. Any exception |
---|
54 | * (including an interrupt/external-exception) |
---|
55 | * wakes it up. |
---|
56 | * |
---|
57 | * IIRC - this cannot be used on real hardware due |
---|
58 | * to errata on many chips which is a real |
---|
59 | * pity. However, when used under qemu it |
---|
60 | * saves host-CPU cycles. |
---|
61 | * While qemu-0.12.4 needed to be patched |
---|
62 | * (would otherwise hang because an exception |
---|
63 | * didn't clear MSR_POW) qemu-0.14.1 seems |
---|
64 | * to work fine. |
---|
65 | */ |
---|
66 | |
---|
67 | #include <rtems/powerpc/registers.h> |
---|
68 | #include <libcpu/cpuIdent.h> |
---|
69 | #include <libcpu/spr.h> |
---|
70 | |
---|
71 | SPR_RW(HID0) |
---|
72 | |
---|
73 | void * |
---|
74 | bsp_ppc_idle_task_body(uintptr_t ignored) |
---|
75 | { |
---|
76 | uint32_t msr; |
---|
77 | |
---|
78 | switch ( current_ppc_cpu ) { |
---|
79 | |
---|
80 | case PPC_7400: |
---|
81 | case PPC_7455: |
---|
82 | case PPC_7457: |
---|
83 | /* Must enable NAP mode in HID0 for MSR_POW to work */ |
---|
84 | _write_HID0( _read_HID0() | HID0_NAP ); |
---|
85 | break; |
---|
86 | |
---|
87 | default: |
---|
88 | break; |
---|
89 | } |
---|
90 | |
---|
91 | for ( ;; ) { |
---|
92 | _CPU_MSR_GET(msr); |
---|
93 | msr |= MSR_POW; |
---|
94 | asm volatile( |
---|
95 | "1: sync \n" |
---|
96 | " mtmsr %0 \n" |
---|
97 | " isync \n" |
---|
98 | " b 1b \n" |
---|
99 | ::"r"(msr) |
---|
100 | ); |
---|
101 | } |
---|
102 | |
---|
103 | return 0; |
---|
104 | } |
---|
105 | |
---|
106 | #endif |
---|