xref: /freebsd/sys/powerpc/powerpc/cpu_subr64.S (revision 0957b409)
1/*-
2 * Copyright (c) 2017-2018 QCM Technologies.
3 * Copyright (c) 2017-2018 Semihalf.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30#include "assym.inc"
31
32#include <machine/asm.h>
33
34	.globl	CNAME(power_save_sequence)
35	.p2align 3
36ENTRY(enter_idle_powerx)
37	mfsprg0	%r3			/* Get the pcpu pointer */
38	ld	%r3,PC_CURTHREAD(%r3)	/* Get current thread */
39	ld	%r3,TD_PCB(%r3)		/* Get PCB of current thread */
40	std	%r12,PCB_CONTEXT(%r3)	/* Save the non-volatile GP regs. */
41	std	%r13,PCB_CONTEXT+1*8(%r3)
42	std	%r14,PCB_CONTEXT+2*8(%r3)
43	std	%r15,PCB_CONTEXT+3*8(%r3)
44	std	%r16,PCB_CONTEXT+4*8(%r3)
45	std	%r17,PCB_CONTEXT+5*8(%r3)
46	std	%r18,PCB_CONTEXT+6*8(%r3)
47	std	%r19,PCB_CONTEXT+7*8(%r3)
48	std	%r20,PCB_CONTEXT+8*8(%r3)
49	std	%r21,PCB_CONTEXT+9*8(%r3)
50	std	%r22,PCB_CONTEXT+10*8(%r3)
51	std	%r23,PCB_CONTEXT+11*8(%r3)
52	std	%r24,PCB_CONTEXT+12*8(%r3)
53	std	%r25,PCB_CONTEXT+13*8(%r3)
54	std	%r26,PCB_CONTEXT+14*8(%r3)
55	std	%r27,PCB_CONTEXT+15*8(%r3)
56	std	%r28,PCB_CONTEXT+16*8(%r3)
57	std	%r29,PCB_CONTEXT+17*8(%r3)
58	std	%r30,PCB_CONTEXT+18*8(%r3)
59	std	%r31,PCB_CONTEXT+19*8(%r3)
60
61	mfcr	%r16			/* Save the condition register */
62	std	%r16,PCB_CR(%r3)
63	mflr	%r16			/* Save the link register */
64	std	%r16,PCB_LR(%r3)
65	std	%r1,PCB_SP(%r3)		/* Save the stack pointer */
66	std	%r2,PCB_TOC(%r3)	/* Save the TOC pointer */
67
68	/* Set where we want to jump */
69	bl	1f
70	.llong power_save_sequence	/* Remember about 8 byte alignment */
711:	mflr	%r3
72	ld	%r3,0(%r3)
73	mtsrr0	%r3
74
75	/* Set MSR */
76	li	%r3,0
77	ori	%r3,%r3,(PSL_ME | PSL_RI)
78	li	%r8,0x9			/* PSL_SF and PSL_HV */
79	insrdi	%r3,%r8,4,0
80	mtsrr1	%r3
81
82	rfid
83
84	.p2align 2
85CNAME(power_save_sequence):
86	bl	1f
87	.llong	0x0			/* Playground for power-save sequence */
881:	mflr	%r3
89
90	/* Start power-save sequence */
91	std	%r2,0(%r3)
92	ptesync
93	ld	%r2,0(%r3)
942:	cmpd	%r2,%r2
95	bne	2b
96	nap
97	b	.
98