• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24 
25 #include <core/os.h>
26 #include <core/engctx.h>
27 #include <core/event.h>
28 
29 #include <subdev/bar.h>
30 
31 #include <engine/software.h>
32 #include <engine/disp.h>
33 
34 #include "nv50.h"
35 
36 /*******************************************************************************
37  * software object classes
38  ******************************************************************************/
39 
40 static int
nvc0_software_mthd_vblsem_offset(struct nouveau_object * object,u32 mthd,void * args,u32 size)41 nvc0_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd,
42 				 void *args, u32 size)
43 {
44 	struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
45 	u64 data = *(u32 *)args;
46 	if (mthd == 0x0400) {
47 		chan->vblank.offset &= 0x00ffffffffULL;
48 		chan->vblank.offset |= data << 32;
49 	} else {
50 		chan->vblank.offset &= 0xff00000000ULL;
51 		chan->vblank.offset |= data;
52 	}
53 	return 0;
54 }
55 
56 static int
nvc0_software_mthd_mp_control(struct nouveau_object * object,u32 mthd,void * args,u32 size)57 nvc0_software_mthd_mp_control(struct nouveau_object *object, u32 mthd,
58                               void *args, u32 size)
59 {
60 	struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
61 	struct nv50_software_priv *priv = (void *)nv_object(chan)->engine;
62 	u32 data = *(u32 *)args;
63 
64 	switch (mthd) {
65 	case 0x600:
66 		nv_wr32(priv, 0x419e00, data); /* MP.PM_UNK000 */
67 		break;
68 	case 0x644:
69 		if (data & ~0x1ffffe)
70 			return -EINVAL;
71 		nv_wr32(priv, 0x419e44, data); /* MP.TRAP_WARP_ERROR_EN */
72 		break;
73 	case 0x6ac:
74 		nv_wr32(priv, 0x419eac, data); /* MP.PM_UNK0AC */
75 		break;
76 	default:
77 		return -EINVAL;
78 	}
79 	return 0;
80 }
81 
82 static struct nouveau_omthds
83 nvc0_software_omthds[] = {
84 	{ 0x0400, 0x0400, nvc0_software_mthd_vblsem_offset },
85 	{ 0x0404, 0x0404, nvc0_software_mthd_vblsem_offset },
86 	{ 0x0408, 0x0408, nv50_software_mthd_vblsem_value },
87 	{ 0x040c, 0x040c, nv50_software_mthd_vblsem_release },
88 	{ 0x0500, 0x0500, nv50_software_mthd_flip },
89 	{ 0x0600, 0x0600, nvc0_software_mthd_mp_control },
90 	{ 0x0644, 0x0644, nvc0_software_mthd_mp_control },
91 	{ 0x06ac, 0x06ac, nvc0_software_mthd_mp_control },
92 	{}
93 };
94 
95 static struct nouveau_oclass
96 nvc0_software_sclass[] = {
97 	{ 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds },
98 	{}
99 };
100 
101 /*******************************************************************************
102  * software context
103  ******************************************************************************/
104 
105 static int
nvc0_software_vblsem_release(struct nvkm_notify * notify)106 nvc0_software_vblsem_release(struct nvkm_notify *notify)
107 {
108 	struct nv50_software_chan *chan =
109 		container_of(notify, typeof(*chan), vblank.notify[notify->index]);
110 	struct nv50_software_priv *priv = (void *)nv_object(chan)->engine;
111 	struct nouveau_bar *bar = nouveau_bar(priv);
112 
113 	nv_wr32(priv, 0x001718, 0x80000000 | chan->vblank.channel);
114 	bar->flush(bar);
115 	nv_wr32(priv, 0x06000c, upper_32_bits(chan->vblank.offset));
116 	nv_wr32(priv, 0x060010, lower_32_bits(chan->vblank.offset));
117 	nv_wr32(priv, 0x060014, chan->vblank.value);
118 
119 	return NVKM_NOTIFY_DROP;
120 }
121 
122 static struct nv50_software_cclass
123 nvc0_software_cclass = {
124 	.base.handle = NV_ENGCTX(SW, 0xc0),
125 	.base.ofuncs = &(struct nouveau_ofuncs) {
126 		.ctor = nv50_software_context_ctor,
127 		.dtor = nv50_software_context_dtor,
128 		.init = _nouveau_software_context_init,
129 		.fini = _nouveau_software_context_fini,
130 	},
131 	.vblank = nvc0_software_vblsem_release,
132 };
133 
134 /*******************************************************************************
135  * software engine/subdev functions
136  ******************************************************************************/
137 
138 struct nouveau_oclass *
139 nvc0_software_oclass = &(struct nv50_software_oclass) {
140 	.base.handle = NV_ENGINE(SW, 0xc0),
141 	.base.ofuncs = &(struct nouveau_ofuncs) {
142 		.ctor = nv50_software_ctor,
143 		.dtor = _nouveau_software_dtor,
144 		.init = _nouveau_software_init,
145 		.fini = _nouveau_software_fini,
146 	},
147 	.cclass = &nvc0_software_cclass.base,
148 	.sclass =  nvc0_software_sclass,
149 }.base;
150