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