blob: d37de6e3c3b2e0d44341ff3a8c3096d36966ef8f [file] [log] [blame]
Ben Skeggs20abd162012-04-30 11:33:43 -05001/*
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 "drmP.h"
26#include "nouveau_drv.h"
27#include "nouveau_ramht.h"
28#include "nouveau_software.h"
29#include "nouveau_hw.h"
30
31struct nv04_software_priv {
32 struct nouveau_software_priv base;
33};
34
35struct nv04_software_chan {
36 struct nouveau_software_chan base;
37};
38
39static int
40mthd_fence(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
41{
42 atomic_set(&chan->fence.last_sequence_irq, data);
43 return 0;
44}
45
46static int
47mthd_flip(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
48{
49
50 struct nouveau_page_flip_state state;
51
52 if (!nouveau_finish_page_flip(chan, &state)) {
53 nv_set_crtc_base(chan->dev, state.crtc, state.offset +
54 state.y * state.pitch +
55 state.x * state.bpp / 8);
56 }
57
58 return 0;
59}
60
61static int
62nv04_software_context_new(struct nouveau_channel *chan, int engine)
63{
64 struct nv04_software_chan *pch;
65
66 pch = kzalloc(sizeof(*pch), GFP_KERNEL);
67 if (!pch)
68 return -ENOMEM;
69
70 nouveau_software_context_new(&pch->base);
71 atomic_set(&chan->fence.last_sequence_irq, 0);
72 chan->engctx[engine] = pch;
73 return 0;
74}
75
76static void
77nv04_software_context_del(struct nouveau_channel *chan, int engine)
78{
79 struct nv04_software_chan *pch = chan->engctx[engine];
80 chan->engctx[engine] = NULL;
81 kfree(pch);
82}
83
84static int
85nv04_software_object_new(struct nouveau_channel *chan, int engine,
86 u32 handle, u16 class)
87{
88 struct drm_device *dev = chan->dev;
89 struct nouveau_gpuobj *obj = NULL;
90 int ret;
91
92 ret = nouveau_gpuobj_new(dev, chan, 16, 16, 0, &obj);
93 if (ret)
94 return ret;
95 obj->engine = 0;
96 obj->class = class;
97
98 ret = nouveau_ramht_insert(chan, handle, obj);
99 nouveau_gpuobj_ref(NULL, &obj);
100 return ret;
101}
102
103static int
104nv04_software_init(struct drm_device *dev, int engine)
105{
106 return 0;
107}
108
109static int
110nv04_software_fini(struct drm_device *dev, int engine, bool suspend)
111{
112 return 0;
113}
114
115static void
116nv04_software_destroy(struct drm_device *dev, int engine)
117{
118 struct nv04_software_priv *psw = nv_engine(dev, engine);
119
120 NVOBJ_ENGINE_DEL(dev, SW);
121 kfree(psw);
122}
123
124int
125nv04_software_create(struct drm_device *dev)
126{
127 struct drm_nouveau_private *dev_priv = dev->dev_private;
128 struct nv04_software_priv *psw;
129
130 psw = kzalloc(sizeof(*psw), GFP_KERNEL);
131 if (!psw)
132 return -ENOMEM;
133
134 psw->base.base.destroy = nv04_software_destroy;
135 psw->base.base.init = nv04_software_init;
136 psw->base.base.fini = nv04_software_fini;
137 psw->base.base.context_new = nv04_software_context_new;
138 psw->base.base.context_del = nv04_software_context_del;
139 psw->base.base.object_new = nv04_software_object_new;
140 nouveau_software_create(&psw->base);
141
142 NVOBJ_ENGINE_ADD(dev, SW, &psw->base.base);
143 if (dev_priv->card_type <= NV_04) {
144 NVOBJ_CLASS(dev, 0x006e, SW);
145 NVOBJ_MTHD (dev, 0x006e, 0x0150, mthd_fence);
146 NVOBJ_MTHD (dev, 0x006e, 0x0500, mthd_flip);
147 } else {
148 NVOBJ_CLASS(dev, 0x016e, SW);
149 NVOBJ_MTHD (dev, 0x016e, 0x0500, mthd_flip);
150 }
151
152 return 0;
153}