1/* $NetBSD: nouveau_engine_software_nv04.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $ */
2
3/*
4 * Copyright 2012 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Ben Skeggs
25 */
26
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_software_nv04.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $");
29
30#include <core/os.h>
31#include <core/class.h>
32#include <core/engctx.h>
33
34#include <engine/software.h>
35#include <engine/fifo.h>
36
37struct nv04_software_priv {
38 struct nouveau_software base;
39};
40
41struct nv04_software_chan {
42 struct nouveau_software_chan base;
43};
44
45/*******************************************************************************
46 * software object classes
47 ******************************************************************************/
48
49static int
50nv04_software_set_ref(struct nouveau_object *object, u32 mthd,
51 void *data, u32 size)
52{
53 struct nouveau_object *channel = (void *)nv_engctx(object->parent);
54 struct nouveau_fifo_chan *fifo = (void *)channel->parent;
55 atomic_set(&fifo->refcnt, *(u32*)data);
56 return 0;
57}
58
59static int
60nv04_software_flip(struct nouveau_object *object, u32 mthd,
61 void *args, u32 size)
62{
63 struct nv04_software_chan *chan = (void *)nv_engctx(object->parent);
64 if (chan->base.flip)
65 return chan->base.flip(chan->base.flip_data);
66 return -EINVAL;
67}
68
69static struct nouveau_omthds
70nv04_software_omthds[] = {
71 { 0x0150, 0x0150, nv04_software_set_ref },
72 { 0x0500, 0x0500, nv04_software_flip },
73 {}
74};
75
76static struct nouveau_oclass
77nv04_software_sclass[] = {
78 { 0x006e, &nouveau_object_ofuncs, nv04_software_omthds },
79 {}
80};
81
82/*******************************************************************************
83 * software context
84 ******************************************************************************/
85
86static int
87nv04_software_context_ctor(struct nouveau_object *parent,
88 struct nouveau_object *engine,
89 struct nouveau_oclass *oclass, void *data, u32 size,
90 struct nouveau_object **pobject)
91{
92 struct nv04_software_chan *chan;
93 int ret;
94
95 ret = nouveau_software_context_create(parent, engine, oclass, &chan);
96 *pobject = nv_object(chan);
97 if (ret)
98 return ret;
99
100 return 0;
101}
102
103static struct nouveau_oclass
104nv04_software_cclass = {
105 .handle = NV_ENGCTX(SW, 0x04),
106 .ofuncs = &(struct nouveau_ofuncs) {
107 .ctor = nv04_software_context_ctor,
108 .dtor = _nouveau_software_context_dtor,
109 .init = _nouveau_software_context_init,
110 .fini = _nouveau_software_context_fini,
111 },
112};
113
114/*******************************************************************************
115 * software engine/subdev functions
116 ******************************************************************************/
117
118void
119nv04_software_intr(struct nouveau_subdev *subdev)
120{
121 nv_mask(subdev, 0x000100, 0x80000000, 0x00000000);
122}
123
124static int
125nv04_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
126 struct nouveau_oclass *oclass, void *data, u32 size,
127 struct nouveau_object **pobject)
128{
129 struct nv04_software_priv *priv;
130 int ret;
131
132 ret = nouveau_software_create(parent, engine, oclass, &priv);
133 *pobject = nv_object(priv);
134 if (ret)
135 return ret;
136
137 nv_engine(priv)->cclass = &nv04_software_cclass;
138 nv_engine(priv)->sclass = nv04_software_sclass;
139 nv_subdev(priv)->intr = nv04_software_intr;
140 return 0;
141}
142
143struct nouveau_oclass *
144nv04_software_oclass = &(struct nouveau_oclass) {
145 .handle = NV_ENGINE(SW, 0x04),
146 .ofuncs = &(struct nouveau_ofuncs) {
147 .ctor = nv04_software_ctor,
148 .dtor = _nouveau_software_dtor,
149 .init = _nouveau_software_init,
150 .fini = _nouveau_software_fini,
151 },
152};
153