Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:58

0001 /*
0002  *  ppc_idle.c
0003  *
0004  * Authorship
0005  * ----------
0006  * This software was created by
0007  *     Till Straumann <strauman@slac.stanford.edu>, 2010,
0008  *     Stanford Linear Accelerator Center, Stanford University.
0009  *
0010  * Acknowledgement of sponsorship
0011  * ------------------------------
0012  * This software was produced by
0013  *     the Stanford Linear Accelerator Center, Stanford University,
0014  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0015  *
0016  * Government disclaimer of liability
0017  * ----------------------------------
0018  * Neither the United States nor the United States Department of Energy,
0019  * nor any of their employees, makes any warranty, express or implied, or
0020  * assumes any legal liability or responsibility for the accuracy,
0021  * completeness, or usefulness of any data, apparatus, product, or process
0022  * disclosed, or represents that its use would not infringe privately owned
0023  * rights.
0024  *
0025  * Stanford disclaimer of liability
0026  * --------------------------------
0027  * Stanford University makes no representations or warranties, express or
0028  * implied, nor assumes any liability for the use of this software.
0029  *
0030  * Stanford disclaimer of copyright
0031  * --------------------------------
0032  * Stanford University, owner of the copyright, hereby disclaims its
0033  * copyright and all other rights in this software.  Hence, anyone may
0034  * freely use it for any purpose without restriction.
0035  *
0036  * Maintenance of notices
0037  * ----------------------
0038  * In the interest of clarity regarding the origin and status of this
0039  * SLAC software, this and all the preceding Stanford University notices
0040  * are to remain affixed to any copy or derivative of this software made
0041  * or distributed by the recipient and are to be affixed to any copy of
0042  * software made or distributed by the recipient that contains a copy or
0043  * derivative of this software.
0044  *
0045  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0046  */
0047 #include <bsp.h>
0048 #include <stdint.h>
0049 
0050 #ifdef BSP_IDLE_TASK_BODY
0051 
0052 /* Provide an idle-task body which switches the
0053  * CPU into power-save mode when idle. Any exception
0054  * (including an interrupt/external-exception)
0055  * wakes it up.
0056  *
0057  * IIRC - this cannot be used on real hardware due
0058  *        to errata on many chips which is a real
0059  *        pity. However, when used under qemu it
0060  *        saves host-CPU cycles.
0061  *        While qemu-0.12.4 needed to be patched
0062  *        (would otherwise hang because an exception
0063  *        didn't clear MSR_POW) qemu-0.14.1 seems
0064  *        to work fine.
0065  */
0066 
0067 #include <rtems/powerpc/registers.h>
0068 #include <libcpu/cpuIdent.h>
0069 #include <libcpu/spr.h>
0070 
0071 SPR_RW(HID0)
0072 
0073 void *
0074 bsp_ppc_idle_task_body(uintptr_t ignored)
0075 {
0076 uint32_t msr;
0077 
0078     switch ( current_ppc_cpu ) {
0079 
0080         case PPC_7400:
0081         case PPC_7455:
0082         case PPC_7457:
0083             /* Must enable NAP mode in HID0 for MSR_POW to work */
0084             _write_HID0( _read_HID0() | HID0_NAP );
0085         break;
0086 
0087         default:
0088         break;
0089     }
0090 
0091     for ( ;; ) {
0092         _CPU_MSR_GET(msr);
0093         msr |= MSR_POW;
0094         asm volatile(
0095                 "1: sync       \n"
0096                 "   mtmsr %0   \n"
0097                 "   isync      \n"
0098                 "   b 1b       \n"
0099                 ::"r"(msr)
0100                 );
0101     }
0102 
0103     return 0;
0104 }
0105 
0106 #endif