blob: f9430c1bf3e511a343373f2c20bac059dd2f7b82 [file] [log] [blame]
Ben Skeggsebb945a2012-07-20 08:17:34 +10001/*
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/class.h>
27#include <core/engctx.h>
Ben Skeggs1d7c71a2013-01-31 09:23:34 +100028#include <core/event.h>
29
30#include <subdev/bar.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100031
32#include <engine/software.h>
33#include <engine/disp.h>
34
Ben Skeggs3bfcec32013-10-03 07:17:02 +100035#include "nv50.h"
Ben Skeggsebb945a2012-07-20 08:17:34 +100036
37/*******************************************************************************
38 * software object classes
39 ******************************************************************************/
40
41static int
42nvc0_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd,
43 void *args, u32 size)
44{
Ben Skeggs3bfcec32013-10-03 07:17:02 +100045 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
Ben Skeggsebb945a2012-07-20 08:17:34 +100046 u64 data = *(u32 *)args;
47 if (mthd == 0x0400) {
Ben Skeggsef8d4782013-10-03 07:21:34 +100048 chan->vblank.offset &= 0x00ffffffffULL;
49 chan->vblank.offset |= data << 32;
Ben Skeggsebb945a2012-07-20 08:17:34 +100050 } else {
Ben Skeggsef8d4782013-10-03 07:21:34 +100051 chan->vblank.offset &= 0xff00000000ULL;
52 chan->vblank.offset |= data;
Ben Skeggsebb945a2012-07-20 08:17:34 +100053 }
54 return 0;
55}
56
57static int
Christoph Bumiller96854822013-03-27 22:16:55 +010058nvc0_software_mthd_mp_control(struct nouveau_object *object, u32 mthd,
59 void *args, u32 size)
60{
Ben Skeggs3bfcec32013-10-03 07:17:02 +100061 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
62 struct nv50_software_priv *priv = (void *)nv_object(chan)->engine;
Christoph Bumiller96854822013-03-27 22:16:55 +010063 u32 data = *(u32 *)args;
64
65 switch (mthd) {
66 case 0x600:
67 nv_wr32(priv, 0x419e00, data); /* MP.PM_UNK000 */
68 break;
69 case 0x644:
70 if (data & ~0x1ffffe)
71 return -EINVAL;
72 nv_wr32(priv, 0x419e44, data); /* MP.TRAP_WARP_ERROR_EN */
73 break;
74 case 0x6ac:
75 nv_wr32(priv, 0x419eac, data); /* MP.PM_UNK0AC */
76 break;
77 default:
78 return -EINVAL;
79 }
80 return 0;
81}
82
Ben Skeggsebb945a2012-07-20 08:17:34 +100083static struct nouveau_omthds
84nvc0_software_omthds[] = {
Ben Skeggsfb445b3c22012-11-07 16:28:35 +100085 { 0x0400, 0x0400, nvc0_software_mthd_vblsem_offset },
86 { 0x0404, 0x0404, nvc0_software_mthd_vblsem_offset },
Ben Skeggs51cb4b32013-10-03 07:02:29 +100087 { 0x0408, 0x0408, nv50_software_mthd_vblsem_value },
88 { 0x040c, 0x040c, nv50_software_mthd_vblsem_release },
89 { 0x0500, 0x0500, nv50_software_mthd_flip },
Christoph Bumiller96854822013-03-27 22:16:55 +010090 { 0x0600, 0x0600, nvc0_software_mthd_mp_control },
91 { 0x0644, 0x0644, nvc0_software_mthd_mp_control },
92 { 0x06ac, 0x06ac, nvc0_software_mthd_mp_control },
Ben Skeggsebb945a2012-07-20 08:17:34 +100093 {}
94};
95
96static struct nouveau_oclass
97nvc0_software_sclass[] = {
98 { 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds },
99 {}
100};
101
102/*******************************************************************************
103 * software context
104 ******************************************************************************/
105
106static int
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000107nvc0_software_vblsem_release(void *data, int head)
Ben Skeggs1d7c71a2013-01-31 09:23:34 +1000108{
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000109 struct nv50_software_chan *chan = data;
Ben Skeggs3bfcec32013-10-03 07:17:02 +1000110 struct nv50_software_priv *priv = (void *)nv_object(chan)->engine;
Ben Skeggs1d7c71a2013-01-31 09:23:34 +1000111 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_EVENT_DROP;
120}
121
Ben Skeggs75895632013-10-03 07:42:41 +1000122static struct nv50_software_cclass
Ben Skeggsebb945a2012-07-20 08:17:34 +1000123nvc0_software_cclass = {
Ben Skeggs75895632013-10-03 07:42:41 +1000124 .base.handle = NV_ENGCTX(SW, 0xc0),
125 .base.ofuncs = &(struct nouveau_ofuncs) {
126 .ctor = nv50_software_context_ctor,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000127 .dtor = _nouveau_software_context_dtor,
128 .init = _nouveau_software_context_init,
129 .fini = _nouveau_software_context_fini,
130 },
Ben Skeggs75895632013-10-03 07:42:41 +1000131 .vblank = nvc0_software_vblsem_release,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000132};
133
134/*******************************************************************************
135 * software engine/subdev functions
136 ******************************************************************************/
137
Ben Skeggsc46c3dd2013-10-03 07:30:11 +1000138struct nouveau_oclass *
139nvc0_software_oclass = &(struct nv50_software_oclass) {
140 .base.handle = NV_ENGINE(SW, 0xc0),
141 .base.ofuncs = &(struct nouveau_ofuncs) {
Ben Skeggs75895632013-10-03 07:42:41 +1000142 .ctor = nv50_software_ctor,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000143 .dtor = _nouveau_software_dtor,
144 .init = _nouveau_software_init,
145 .fini = _nouveau_software_fini,
146 },
Ben Skeggs75895632013-10-03 07:42:41 +1000147 .cclass = &nvc0_software_cclass.base,
148 .sclass = nvc0_software_sclass,
Ben Skeggsc46c3dd2013-10-03 07:30:11 +1000149}.base;