16d13fd63SWojciech Macek/*- 26d13fd63SWojciech Macek * Copyright (c) 2017-2018 QCM Technologies. 36d13fd63SWojciech Macek * Copyright (c) 2017-2018 Semihalf. 46d13fd63SWojciech Macek * All rights reserved. 56d13fd63SWojciech Macek * 66d13fd63SWojciech Macek * Redistribution and use in source and binary forms, with or without 76d13fd63SWojciech Macek * modification, are permitted provided that the following conditions 86d13fd63SWojciech Macek * are met: 96d13fd63SWojciech Macek * 1. Redistributions of source code must retain the above copyright 106d13fd63SWojciech Macek * notice, this list of conditions and the following disclaimer. 116d13fd63SWojciech Macek * 2. Redistributions in binary form must reproduce the above copyright 126d13fd63SWojciech Macek * notice, this list of conditions and the following disclaimer in the 136d13fd63SWojciech Macek * documentation and/or other materials provided with the distribution. 146d13fd63SWojciech Macek * 156d13fd63SWojciech Macek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 166d13fd63SWojciech Macek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 176d13fd63SWojciech Macek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 186d13fd63SWojciech Macek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 196d13fd63SWojciech Macek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 206d13fd63SWojciech Macek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 216d13fd63SWojciech Macek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 226d13fd63SWojciech Macek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 236d13fd63SWojciech Macek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 246d13fd63SWojciech Macek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 256d13fd63SWojciech Macek * SUCH DAMAGE. 266d13fd63SWojciech Macek */ 276d13fd63SWojciech Macek 28fc2a8776SEd Maste#include "assym.inc" 296d13fd63SWojciech Macek 306d13fd63SWojciech Macek#include <machine/asm.h> 316d13fd63SWojciech Macek 326d13fd63SWojciech Macek .p2align 3 336d13fd63SWojciech MacekENTRY(enter_idle_powerx) 346d13fd63SWojciech Macek mfsprg0 %r3 /* Get the pcpu pointer */ 356d13fd63SWojciech Macek ld %r3,PC_CURTHREAD(%r3) /* Get current thread */ 366d13fd63SWojciech Macek ld %r3,TD_PCB(%r3) /* Get PCB of current thread */ 376d13fd63SWojciech Macek std %r12,PCB_CONTEXT(%r3) /* Save the non-volatile GP regs. */ 386d13fd63SWojciech Macek std %r13,PCB_CONTEXT+1*8(%r3) 396d13fd63SWojciech Macek std %r14,PCB_CONTEXT+2*8(%r3) 406d13fd63SWojciech Macek std %r15,PCB_CONTEXT+3*8(%r3) 416d13fd63SWojciech Macek std %r16,PCB_CONTEXT+4*8(%r3) 426d13fd63SWojciech Macek std %r17,PCB_CONTEXT+5*8(%r3) 436d13fd63SWojciech Macek std %r18,PCB_CONTEXT+6*8(%r3) 446d13fd63SWojciech Macek std %r19,PCB_CONTEXT+7*8(%r3) 456d13fd63SWojciech Macek std %r20,PCB_CONTEXT+8*8(%r3) 466d13fd63SWojciech Macek std %r21,PCB_CONTEXT+9*8(%r3) 476d13fd63SWojciech Macek std %r22,PCB_CONTEXT+10*8(%r3) 486d13fd63SWojciech Macek std %r23,PCB_CONTEXT+11*8(%r3) 496d13fd63SWojciech Macek std %r24,PCB_CONTEXT+12*8(%r3) 506d13fd63SWojciech Macek std %r25,PCB_CONTEXT+13*8(%r3) 516d13fd63SWojciech Macek std %r26,PCB_CONTEXT+14*8(%r3) 526d13fd63SWojciech Macek std %r27,PCB_CONTEXT+15*8(%r3) 536d13fd63SWojciech Macek std %r28,PCB_CONTEXT+16*8(%r3) 546d13fd63SWojciech Macek std %r29,PCB_CONTEXT+17*8(%r3) 556d13fd63SWojciech Macek std %r30,PCB_CONTEXT+18*8(%r3) 566d13fd63SWojciech Macek std %r31,PCB_CONTEXT+19*8(%r3) 576d13fd63SWojciech Macek 586d13fd63SWojciech Macek mfcr %r16 /* Save the condition register */ 596d13fd63SWojciech Macek std %r16,PCB_CR(%r3) 606d13fd63SWojciech Macek mflr %r16 /* Save the link register */ 616d13fd63SWojciech Macek std %r16,PCB_LR(%r3) 626d13fd63SWojciech Macek std %r1,PCB_SP(%r3) /* Save the stack pointer */ 636d13fd63SWojciech Macek std %r2,PCB_TOC(%r3) /* Save the TOC pointer */ 646d13fd63SWojciech Macek 656d13fd63SWojciech Macek bl 1f 666d13fd63SWojciech Macek1: mflr %r3 670632bb89SLeandro Lupori addi %r3,%r3,power_save_sequence-1b 686d13fd63SWojciech Macek mtsrr0 %r3 696d13fd63SWojciech Macek 706d13fd63SWojciech Macek /* Set MSR */ 716d13fd63SWojciech Macek li %r3,0 7293a53419SBrandon Bergren#ifdef __LITTLE_ENDIAN__ 7393a53419SBrandon Bergren ori %r3,%r3,(PSL_ME | PSL_RI | PSL_LE) 7493a53419SBrandon Bergren#else 756d13fd63SWojciech Macek ori %r3,%r3,(PSL_ME | PSL_RI) 7693a53419SBrandon Bergren#endif 776d13fd63SWojciech Macek li %r8,0x9 /* PSL_SF and PSL_HV */ 786d13fd63SWojciech Macek insrdi %r3,%r8,4,0 796d13fd63SWojciech Macek mtsrr1 %r3 806d13fd63SWojciech Macek 816d13fd63SWojciech Macek rfid 826d13fd63SWojciech Macek 836d13fd63SWojciech Macek .p2align 2 840632bb89SLeandro Luporipower_save_sequence: 856d13fd63SWojciech Macek bl 1f 866d13fd63SWojciech Macek .llong 0x0 /* Playground for power-save sequence */ 876d13fd63SWojciech Macek1: mflr %r3 886d13fd63SWojciech Macek 896d13fd63SWojciech Macek /* Start power-save sequence */ 906d13fd63SWojciech Macek std %r2,0(%r3) 916d13fd63SWojciech Macek ptesync 926d13fd63SWojciech Macek ld %r2,0(%r3) 936d13fd63SWojciech Macek2: cmpd %r2,%r2 946d13fd63SWojciech Macek bne 2b 956d13fd63SWojciech Macek nap 966d13fd63SWojciech Macek b . 9778599c32SConrad MeyerEND(enter_idle_powerx) 98