2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include <core/client.h>
28 #include <core/ramht.h>
29 #include <engine/dma.h>
31 #include <nvif/class.h>
32 #include <nvif/event.h>
33 #include <nvif/unpack.h>
36 nv50_disp_mthd_list(struct nv50_disp
*disp
, int debug
, u32 base
, int c
,
37 const struct nv50_disp_mthd_list
*list
, int inst
)
39 struct nvkm_subdev
*subdev
= &disp
->base
.engine
.subdev
;
40 struct nvkm_device
*device
= subdev
->device
;
43 for (i
= 0; list
->data
[i
].mthd
; i
++) {
44 if (list
->data
[i
].addr
) {
45 u32 next
= nvkm_rd32(device
, list
->data
[i
].addr
+ base
+ 0);
46 u32 prev
= nvkm_rd32(device
, list
->data
[i
].addr
+ base
+ c
);
47 u32 mthd
= list
->data
[i
].mthd
+ (list
->mthd
* inst
);
48 const char *name
= list
->data
[i
].name
;
52 snprintf(mods
, sizeof(mods
), "-> %08x", next
);
54 snprintf(mods
, sizeof(mods
), "%13c", ' ');
56 nvkm_printk_(subdev
, debug
, info
,
57 "\t%04x: %08x %s%s%s\n",
58 mthd
, prev
, mods
, name
? " // " : "",
65 nv50_disp_chan_mthd(struct nv50_disp_chan
*chan
, int debug
)
67 struct nv50_disp
*disp
= chan
->root
->disp
;
68 struct nvkm_subdev
*subdev
= &disp
->base
.engine
.subdev
;
69 const struct nv50_disp_chan_mthd
*mthd
= chan
->mthd
;
70 const struct nv50_disp_mthd_list
*list
;
73 if (debug
> subdev
->debug
)
76 for (i
= 0; (list
= mthd
->data
[i
].mthd
) != NULL
; i
++) {
77 u32 base
= chan
->head
* mthd
->addr
;
78 for (j
= 0; j
< mthd
->data
[i
].nr
; j
++, base
+= list
->addr
) {
79 const char *cname
= mthd
->name
;
80 const char *sname
= "";
81 char cname_
[16], sname_
[16];
84 snprintf(cname_
, sizeof(cname_
), "%s %d",
85 mthd
->name
, chan
->chid
);
89 if (mthd
->data
[i
].nr
> 1) {
90 snprintf(sname_
, sizeof(sname_
), " - %s %d",
91 mthd
->data
[i
].name
, j
);
95 nvkm_printk_(subdev
, debug
, info
, "%s%s:\n", cname
, sname
);
96 nv50_disp_mthd_list(disp
, debug
, base
, mthd
->prev
,
103 nv50_disp_chan_uevent_fini(struct nvkm_event
*event
, int type
, int index
)
105 struct nv50_disp
*disp
= container_of(event
, typeof(*disp
), uevent
);
106 struct nvkm_device
*device
= disp
->base
.engine
.subdev
.device
;
107 nvkm_mask(device
, 0x610028, 0x00000001 << index
, 0x00000000 << index
);
108 nvkm_wr32(device
, 0x610020, 0x00000001 << index
);
112 nv50_disp_chan_uevent_init(struct nvkm_event
*event
, int types
, int index
)
114 struct nv50_disp
*disp
= container_of(event
, typeof(*disp
), uevent
);
115 struct nvkm_device
*device
= disp
->base
.engine
.subdev
.device
;
116 nvkm_wr32(device
, 0x610020, 0x00000001 << index
);
117 nvkm_mask(device
, 0x610028, 0x00000001 << index
, 0x00000001 << index
);
121 nv50_disp_chan_uevent_send(struct nv50_disp
*disp
, int chid
)
123 struct nvif_notify_uevent_rep
{
126 nvkm_event_send(&disp
->uevent
, 1, chid
, &rep
, sizeof(rep
));
130 nv50_disp_chan_uevent_ctor(struct nvkm_object
*object
, void *data
, u32 size
,
131 struct nvkm_notify
*notify
)
133 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
135 struct nvif_notify_uevent_req none
;
139 if (nvif_unvers(args
->none
)) {
140 notify
->size
= sizeof(struct nvif_notify_uevent_rep
);
142 notify
->index
= chan
->chid
;
149 const struct nvkm_event_func
150 nv50_disp_chan_uevent
= {
151 .ctor
= nv50_disp_chan_uevent_ctor
,
152 .init
= nv50_disp_chan_uevent_init
,
153 .fini
= nv50_disp_chan_uevent_fini
,
157 nv50_disp_chan_rd32(struct nvkm_object
*object
, u64 addr
, u32
*data
)
159 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
160 struct nv50_disp
*disp
= chan
->root
->disp
;
161 struct nvkm_device
*device
= disp
->base
.engine
.subdev
.device
;
162 *data
= nvkm_rd32(device
, 0x640000 + (chan
->chid
* 0x1000) + addr
);
167 nv50_disp_chan_wr32(struct nvkm_object
*object
, u64 addr
, u32 data
)
169 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
170 struct nv50_disp
*disp
= chan
->root
->disp
;
171 struct nvkm_device
*device
= disp
->base
.engine
.subdev
.device
;
172 nvkm_wr32(device
, 0x640000 + (chan
->chid
* 0x1000) + addr
, data
);
177 nv50_disp_chan_ntfy(struct nvkm_object
*object
, u32 type
,
178 struct nvkm_event
**pevent
)
180 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
181 struct nv50_disp
*disp
= chan
->root
->disp
;
183 case NV50_DISP_CORE_CHANNEL_DMA_V0_NTFY_UEVENT
:
184 *pevent
= &disp
->uevent
;
193 nv50_disp_chan_map(struct nvkm_object
*object
, u64
*addr
, u32
*size
)
195 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
196 struct nv50_disp
*disp
= chan
->root
->disp
;
197 struct nvkm_device
*device
= disp
->base
.engine
.subdev
.device
;
198 *addr
= device
->func
->resource_addr(device
, 0) +
199 0x640000 + (chan
->chid
* 0x1000);
205 nv50_disp_chan_child_new(const struct nvkm_oclass
*oclass
,
206 void *data
, u32 size
, struct nvkm_object
**pobject
)
208 struct nv50_disp_chan
*chan
= nv50_disp_chan(oclass
->parent
);
209 return chan
->func
->child_new(chan
, oclass
, data
, size
, pobject
);
213 nv50_disp_chan_child_get(struct nvkm_object
*object
, int index
,
214 struct nvkm_oclass
*oclass
)
216 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
217 if (chan
->func
->child_get
) {
218 int ret
= chan
->func
->child_get(chan
, index
, oclass
);
220 oclass
->ctor
= nv50_disp_chan_child_new
;
227 nv50_disp_chan_fini(struct nvkm_object
*object
, bool suspend
)
229 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
230 chan
->func
->fini(chan
);
235 nv50_disp_chan_init(struct nvkm_object
*object
)
237 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
238 return chan
->func
->init(chan
);
242 nv50_disp_chan_dtor(struct nvkm_object
*object
)
244 struct nv50_disp_chan
*chan
= nv50_disp_chan(object
);
245 struct nv50_disp
*disp
= chan
->root
->disp
;
247 disp
->chan
[chan
->chid
] = NULL
;
248 return chan
->func
->dtor
? chan
->func
->dtor(chan
) : chan
;
251 static const struct nvkm_object_func
253 .dtor
= nv50_disp_chan_dtor
,
254 .init
= nv50_disp_chan_init
,
255 .fini
= nv50_disp_chan_fini
,
256 .rd32
= nv50_disp_chan_rd32
,
257 .wr32
= nv50_disp_chan_wr32
,
258 .ntfy
= nv50_disp_chan_ntfy
,
259 .map
= nv50_disp_chan_map
,
260 .sclass
= nv50_disp_chan_child_get
,
264 nv50_disp_chan_ctor(const struct nv50_disp_chan_func
*func
,
265 const struct nv50_disp_chan_mthd
*mthd
,
266 struct nv50_disp_root
*root
, int chid
, int head
,
267 const struct nvkm_oclass
*oclass
,
268 struct nv50_disp_chan
*chan
)
270 struct nv50_disp
*disp
= root
->disp
;
272 nvkm_object_ctor(&nv50_disp_chan
, oclass
, &chan
->object
);
279 if (disp
->chan
[chan
->chid
]) {
283 disp
->chan
[chan
->chid
] = chan
;
288 nv50_disp_chan_new_(const struct nv50_disp_chan_func
*func
,
289 const struct nv50_disp_chan_mthd
*mthd
,
290 struct nv50_disp_root
*root
, int chid
, int head
,
291 const struct nvkm_oclass
*oclass
,
292 struct nvkm_object
**pobject
)
294 struct nv50_disp_chan
*chan
;
296 if (!(chan
= kzalloc(sizeof(*chan
), GFP_KERNEL
)))
298 *pobject
= &chan
->object
;
300 return nv50_disp_chan_ctor(func
, mthd
, root
, chid
, head
, oclass
, chan
);