xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/pmu/fuc/macros.fuc (revision 8c57a5e7b2820f349c95b8c8393fec1e0f4070d2)
1ebb58dc2SBen Skeggs/*
2ebb58dc2SBen Skeggs * Copyright 2013 Red Hat Inc.
3ebb58dc2SBen Skeggs *
4ebb58dc2SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5ebb58dc2SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6ebb58dc2SBen Skeggs * to deal in the Software without restriction, including without limitation
7ebb58dc2SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ebb58dc2SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9ebb58dc2SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10ebb58dc2SBen Skeggs *
11ebb58dc2SBen Skeggs * The above copyright notice and this permission notice shall be included in
12ebb58dc2SBen Skeggs * all copies or substantial portions of the Software.
13ebb58dc2SBen Skeggs *
14ebb58dc2SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ebb58dc2SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ebb58dc2SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17ebb58dc2SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18ebb58dc2SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ebb58dc2SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20ebb58dc2SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21ebb58dc2SBen Skeggs *
22ebb58dc2SBen Skeggs * Authors: Ben Skeggs
23ebb58dc2SBen Skeggs */
24ebb58dc2SBen Skeggs
25ebb58dc2SBen Skeggs#define GT215 0xa3
26ebb58dc2SBen Skeggs#define GF100 0xc0
27ebb58dc2SBen Skeggs#define GF119 0xd9
28ebb58dc2SBen Skeggs#define GK208 0x108
29ebb58dc2SBen Skeggs
30ebb58dc2SBen Skeggs#include "os.h"
31ebb58dc2SBen Skeggs
32ebb58dc2SBen Skeggs// IO addresses
33ebb58dc2SBen Skeggs#define NV_PPWR_INTR_TRIGGER                                             0x0000
34ebb58dc2SBen Skeggs#define NV_PPWR_INTR_TRIGGER_USER1                                   0x00000080
35ebb58dc2SBen Skeggs#define NV_PPWR_INTR_TRIGGER_USER0                                   0x00000040
36ebb58dc2SBen Skeggs#define NV_PPWR_INTR_ACK                                                 0x0004
37ebb58dc2SBen Skeggs#define NV_PPWR_INTR_ACK_SUBINTR                                     0x00000800
38ebb58dc2SBen Skeggs#define NV_PPWR_INTR_ACK_WATCHDOG                                    0x00000002
39ebb58dc2SBen Skeggs#define NV_PPWR_INTR                                                     0x0008
40ebb58dc2SBen Skeggs#define NV_PPWR_INTR_SUBINTR                                         0x00000800
41ebb58dc2SBen Skeggs#define NV_PPWR_INTR_USER1                                           0x00000080
42ebb58dc2SBen Skeggs#define NV_PPWR_INTR_USER0                                           0x00000040
43ebb58dc2SBen Skeggs#define NV_PPWR_INTR_PAUSE                                           0x00000020
44ebb58dc2SBen Skeggs#define NV_PPWR_INTR_WATCHDOG                                        0x00000002
45ebb58dc2SBen Skeggs#define NV_PPWR_INTR_EN_SET                                              0x0010
46ebb58dc2SBen Skeggs#define NV_PPWR_INTR_EN_SET_SUBINTR                                  0x00000800
47ebb58dc2SBen Skeggs#define NV_PPWR_INTR_EN_SET_WATCHDOG                                 0x00000002
48ebb58dc2SBen Skeggs#define NV_PPWR_INTR_EN_CLR                                              0x0014
49ebb58dc2SBen Skeggs#define NV_PPWR_INTR_EN_CLR_MASK                    /* fuck i hate envyas */ -1
50ebb58dc2SBen Skeggs#define NV_PPWR_INTR_ROUTE                                               0x001c
51ebb58dc2SBen Skeggs#define NV_PPWR_TIMER_LOW                                                0x002c
52ebb58dc2SBen Skeggs#define NV_PPWR_WATCHDOG_TIME                                            0x0034
53ebb58dc2SBen Skeggs#define NV_PPWR_WATCHDOG_ENABLE                                          0x0038
54ebb58dc2SBen Skeggs#define NV_PPWR_CAPS                                                     0x0108
55ebb58dc2SBen Skeggs#define NV_PPWR_UAS_CONFIG                                               0x0164
56ebb58dc2SBen Skeggs#define NV_PPWR_UAS_CONFIG_ENABLE                                    0x00010000
57ebb58dc2SBen Skeggs#if NVKM_PPWR_CHIPSET >= GK208
58ebb58dc2SBen Skeggs#define NV_PPWR_DSCRATCH(i)                                   (4 * (i) + 0x0450)
59ebb58dc2SBen Skeggs#endif
60ebb58dc2SBen Skeggs#define NV_PPWR_FIFO_PUT(i)                                   (4 * (i) + 0x04a0)
61ebb58dc2SBen Skeggs#define NV_PPWR_FIFO_GET(i)                                   (4 * (i) + 0x04b0)
62ebb58dc2SBen Skeggs#define NV_PPWR_FIFO_INTR                                                0x04c0
63ebb58dc2SBen Skeggs#define NV_PPWR_FIFO_INTR_EN                                             0x04c4
64ebb58dc2SBen Skeggs#define NV_PPWR_RFIFO_PUT                                                0x04c8
65ebb58dc2SBen Skeggs#define NV_PPWR_RFIFO_GET                                                0x04cc
66ebb58dc2SBen Skeggs#define NV_PPWR_H2D                                                      0x04d0
67ebb58dc2SBen Skeggs#define NV_PPWR_D2H                                                      0x04dc
68ebb58dc2SBen Skeggs#if NVKM_PPWR_CHIPSET < GK208
69ebb58dc2SBen Skeggs#define NV_PPWR_DSCRATCH(i)                                   (4 * (i) + 0x05d0)
70ebb58dc2SBen Skeggs#endif
71ebb58dc2SBen Skeggs#define NV_PPWR_SUBINTR                                                  0x0688
72ebb58dc2SBen Skeggs#define NV_PPWR_SUBINTR_FIFO                                         0x00000002
73ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_ADDR                                                0x07a0
74ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_DATA                                                0x07a4
75ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL                                                0x07ac
76ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_TRIGGER                                    0x00010000
77ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_STATUS                                     0x00007000
78ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_STATUS_IDLE                                0x00000000
79ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_MASK                                       0x000000f0
80ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_MASK_B32_0                                 0x000000f0
81ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_OP                                         0x00000003
82ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_OP_RD                                      0x00000001
83ebb58dc2SBen Skeggs#define NV_PPWR_MMIO_CTRL_OP_WR                                      0x00000002
84ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT                                                   0x07c0
85ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_FB_PAUSE                                      0x00000004
86ebb58dc2SBen Skeggs#if NVKM_PPWR_CHIPSET < GF119
87ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_3_SCL                                     0x00000100
88ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_3_SDA                                     0x00000200
89ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_0_SCL                                     0x00001000
90ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_0_SDA                                     0x00002000
91ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_1_SCL                                     0x00004000
92ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_1_SDA                                     0x00008000
93ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_2_SCL                                     0x00010000
94ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_2_SDA                                     0x00020000
95ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_4_SCL                                     0x00040000
96ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_4_SDA                                     0x00080000
97ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_5_SCL                                     0x00100000
98ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_5_SDA                                     0x00200000
99ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_6_SCL                                     0x00400000
100ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_6_SDA                                     0x00800000
101ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_7_SCL                                     0x01000000
102ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_7_SDA                                     0x02000000
103ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_8_SCL                                     0x04000000
104ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_8_SDA                                     0x08000000
105ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_9_SCL                                     0x10000000
106ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_9_SDA                                     0x20000000
107ebb58dc2SBen Skeggs#else
108ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_0_SCL                                     0x00000400
109ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_1_SCL                                     0x00000800
110ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_2_SCL                                     0x00001000
111ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_3_SCL                                     0x00002000
112ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_4_SCL                                     0x00004000
113ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_5_SCL                                     0x00008000
114ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_6_SCL                                     0x00010000
115ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_7_SCL                                     0x00020000
116ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_8_SCL                                     0x00040000
117ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_9_SCL                                     0x00080000
118ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_0_SDA                                     0x00100000
119ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_1_SDA                                     0x00200000
120ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_2_SDA                                     0x00400000
121ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_3_SDA                                     0x00800000
122ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_4_SDA                                     0x01000000
123ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_5_SDA                                     0x02000000
124ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_6_SDA                                     0x04000000
125ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_7_SDA                                     0x08000000
126ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_8_SDA                                     0x10000000
127ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_I2C_9_SDA                                     0x20000000
128ebb58dc2SBen Skeggs#endif
129ebb58dc2SBen Skeggs#define NV_PPWR_INPUT                                                    0x07c4
130ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_SET                                               0x07e0
131ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_SET_FB_PAUSE                                  0x00000004
132ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_CLR                                               0x07e4
133ebb58dc2SBen Skeggs#define NV_PPWR_OUTPUT_CLR_FB_PAUSE                                  0x00000004
134ebb58dc2SBen Skeggs
135ebb58dc2SBen Skeggs// Inter-process message format
136ebb58dc2SBen Skeggs.equ #msg_process 0x00 /* send() target, recv() sender */
137ebb58dc2SBen Skeggs.equ #msg_message 0x04
138ebb58dc2SBen Skeggs.equ #msg_data0   0x08
139ebb58dc2SBen Skeggs.equ #msg_data1   0x0c
140ebb58dc2SBen Skeggs
141ebb58dc2SBen Skeggs// Kernel message IDs
142ebb58dc2SBen Skeggs#define KMSG_FIFO  0x00000000
143ebb58dc2SBen Skeggs#define KMSG_ALARM 0x00000001
144ebb58dc2SBen Skeggs
145ebb58dc2SBen Skeggs// Process message queue description
146ebb58dc2SBen Skeggs.equ #proc_qlen 4 // log2(size of queue entry in bytes)
147ebb58dc2SBen Skeggs.equ #proc_qnum 2 // log2(max number of entries in queue)
148ebb58dc2SBen Skeggs.equ #proc_qmaskb (1 << #proc_qnum) // max number of entries in queue
149ebb58dc2SBen Skeggs.equ #proc_qmaskp (#proc_qmaskb - 1)
150ebb58dc2SBen Skeggs.equ #proc_qmaskf ((#proc_qmaskb << 1) - 1)
151ebb58dc2SBen Skeggs.equ #proc_qsize  (1 << (#proc_qlen + #proc_qnum))
152ebb58dc2SBen Skeggs
153ebb58dc2SBen Skeggs// Process table entry
154ebb58dc2SBen Skeggs.equ #proc_id    0x00
155ebb58dc2SBen Skeggs.equ #proc_init  0x04
156ebb58dc2SBen Skeggs.equ #proc_recv  0x08
157ebb58dc2SBen Skeggs.equ #proc_time  0x0c
158ebb58dc2SBen Skeggs.equ #proc_qput  0x10
159ebb58dc2SBen Skeggs.equ #proc_qget  0x14
160ebb58dc2SBen Skeggs.equ #proc_queue 0x18
161ebb58dc2SBen Skeggs.equ #proc_size (0x18 + #proc_qsize)
162ebb58dc2SBen Skeggs
163ebb58dc2SBen Skeggs#define process(id,init,recv) /*
164ebb58dc2SBen Skeggs*/	.b32 id /*
165ebb58dc2SBen Skeggs*/	.b32 init /*
166ebb58dc2SBen Skeggs*/	.b32 recv /*
167ebb58dc2SBen Skeggs*/	.b32 0 /*
168ebb58dc2SBen Skeggs*/	.b32 0 /*
169ebb58dc2SBen Skeggs*/	.b32 0 /*
170ebb58dc2SBen Skeggs*/	.skip 64
171ebb58dc2SBen Skeggs
1724382e909SKarol Herbst#if NVKM_PPWR_CHIPSET < GK208
173ebb58dc2SBen Skeggs#define imm32(reg,val) /*
174ebb58dc2SBen Skeggs*/	movw reg  ((val) & 0x0000ffff) /*
175ebb58dc2SBen Skeggs*/	sethi reg ((val) & 0xffff0000)
176ebb58dc2SBen Skeggs#else
177ebb58dc2SBen Skeggs#define imm32(reg,val) /*
178ebb58dc2SBen Skeggs*/	mov reg (val)
179ebb58dc2SBen Skeggs#endif
180ebb58dc2SBen Skeggs
181ebb58dc2SBen Skeggs#ifndef NVKM_FALCON_UNSHIFTED_IO
182ebb58dc2SBen Skeggs#define nv_iord(reg,ior) /*
183ebb58dc2SBen Skeggs*/	mov reg ior /*
184ebb58dc2SBen Skeggs*/ 	shl b32 reg 6 /*
185ebb58dc2SBen Skeggs*/ 	iord reg I[reg + 0x000]
186ebb58dc2SBen Skeggs#else
187ebb58dc2SBen Skeggs#define nv_iord(reg,ior) /*
188ebb58dc2SBen Skeggs*/	mov reg ior /*
189ebb58dc2SBen Skeggs*/ 	iord reg I[reg + 0x000]
190ebb58dc2SBen Skeggs#endif
191ebb58dc2SBen Skeggs
192ebb58dc2SBen Skeggs#ifndef NVKM_FALCON_UNSHIFTED_IO
193ebb58dc2SBen Skeggs#define nv_iowr(ior,reg) /*
194ebb58dc2SBen Skeggs*/	mov $r0 ior /*
195ebb58dc2SBen Skeggs*/ 	shl b32 $r0 6 /*
196ebb58dc2SBen Skeggs*/ 	iowr I[$r0 + 0x000] reg /*
197ebb58dc2SBen Skeggs*/	clear b32 $r0
198ebb58dc2SBen Skeggs#else
199ebb58dc2SBen Skeggs#define nv_iowr(ior,reg) /*
200ebb58dc2SBen Skeggs*/	mov $r0 ior /*
201ebb58dc2SBen Skeggs*/ 	iowr I[$r0 + 0x000] reg /*
202ebb58dc2SBen Skeggs*/	clear b32 $r0
203ebb58dc2SBen Skeggs#endif
204ebb58dc2SBen Skeggs
205ebb58dc2SBen Skeggs#ifndef NVKM_FALCON_UNSHIFTED_IO
206ebb58dc2SBen Skeggs#define nv_iowrs(ior,reg) /*
207ebb58dc2SBen Skeggs*/	mov $r0 ior /*
208ebb58dc2SBen Skeggs*/ 	shl b32 $r0 6 /*
209ebb58dc2SBen Skeggs*/ 	iowrs I[$r0 + 0x000] reg /*
210ebb58dc2SBen Skeggs*/	clear b32 $r0
211ebb58dc2SBen Skeggs#else
212ebb58dc2SBen Skeggs#define nv_iowrs(ior,reg) /*
213ebb58dc2SBen Skeggs*/	mov $r0 ior /*
214ebb58dc2SBen Skeggs*/ 	iowrs I[$r0 + 0x000] reg /*
215ebb58dc2SBen Skeggs*/	clear b32 $r0
216ebb58dc2SBen Skeggs#endif
217ebb58dc2SBen Skeggs
218ebb58dc2SBen Skeggs#define hash #
219ebb58dc2SBen Skeggs#define fn(a) a
220ebb58dc2SBen Skeggs#ifndef NVKM_FALCON_PC24
221ebb58dc2SBen Skeggs#define call(a) call fn(hash)a
222ebb58dc2SBen Skeggs#else
223ebb58dc2SBen Skeggs#define call(a) lcall fn(hash)a
224ebb58dc2SBen Skeggs#endif
225ebb58dc2SBen Skeggs
226ebb58dc2SBen Skeggs#ifndef NVKM_FALCON_MMIO_UAS
227ebb58dc2SBen Skeggs#define nv_rd32(reg,addr) /*
228ebb58dc2SBen Skeggs*/	mov b32 $r14 addr /*
229ebb58dc2SBen Skeggs*/	call(rd32) /*
230ebb58dc2SBen Skeggs*/	mov b32 reg $r13
231ebb58dc2SBen Skeggs#else
232ebb58dc2SBen Skeggs#define nv_rd32(reg,addr) /*
233ebb58dc2SBen Skeggs*/ 	sethi $r0 0x14000000 /*
234ebb58dc2SBen Skeggs*/	or $r0 addr /*
235ebb58dc2SBen Skeggs*/	ld b32 reg D[$r0] /*
236ebb58dc2SBen Skeggs*/	clear b32 $r0
237ebb58dc2SBen Skeggs#endif
238ebb58dc2SBen Skeggs
239ebb58dc2SBen Skeggs#if !defined(NVKM_FALCON_MMIO_UAS) || defined(NVKM_FALCON_MMIO_TRAP)
240ebb58dc2SBen Skeggs#define nv_wr32(addr,reg) /*
241ebb58dc2SBen Skeggs*/	push addr /*
242ebb58dc2SBen Skeggs*/	push reg /*
243ebb58dc2SBen Skeggs*/	pop $r13 /*
244ebb58dc2SBen Skeggs*/	pop $r14 /*
245ebb58dc2SBen Skeggs*/	call(wr32)
246ebb58dc2SBen Skeggs#else
247ebb58dc2SBen Skeggs#define nv_wr32(addr,reg) /*
248ebb58dc2SBen Skeggs*/ 	sethi $r0 0x14000000 /*
249ebb58dc2SBen Skeggs*/	or $r0 addr /*
250ebb58dc2SBen Skeggs*/	st b32 D[$r0] reg /*
251ebb58dc2SBen Skeggs*/	clear b32 $r0
252ebb58dc2SBen Skeggs#endif
253ebb58dc2SBen Skeggs
254ebb58dc2SBen Skeggs#define st(size, addr, reg) /*
255*b815a2e3SKarol Herbst*/	imm32($r0, addr) /*
256ebb58dc2SBen Skeggs*/	st size D[$r0] reg /*
257ebb58dc2SBen Skeggs*/	clear b32 $r0
258ebb58dc2SBen Skeggs
259ebb58dc2SBen Skeggs#define ld(size, reg, addr) /*
260*b815a2e3SKarol Herbst*/	imm32($r0, addr)  /*
261ebb58dc2SBen Skeggs*/	ld size reg D[$r0] /*
262ebb58dc2SBen Skeggs*/	clear b32 $r0
263ebb58dc2SBen Skeggs
264ebb58dc2SBen Skeggs// does a 64+64 -> 64 unsigned addition (C = A + B)
265ebb58dc2SBen Skeggs#define addu64(reg_a_c_hi, reg_a_c_lo, b_hi, b_lo) /*
266ebb58dc2SBen Skeggs*/    add b32 reg_a_c_lo b_lo /*
267ebb58dc2SBen Skeggs*/    adc b32 reg_a_c_hi b_hi
268ebb58dc2SBen Skeggs
269ebb58dc2SBen Skeggs// does a 64+64 -> 64 substraction (C = A - B)
270ebb58dc2SBen Skeggs#define subu64(reg_a_c_hi, reg_a_c_lo, b_hi, b_lo) /*
271ebb58dc2SBen Skeggs*/    sub b32 reg_a_c_lo b_lo /*
272ebb58dc2SBen Skeggs*/    sbb b32 reg_a_c_hi b_hi
273