1/* $NetBSD: nouveau_engine_copy_nve0.c,v 1.1.1.1 2014/08/06 12:36:24 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_copy_nve0.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $");
29
30#include <core/os.h>
31#include <core/enum.h>
32#include <core/class.h>
33#include <core/engctx.h>
34
35#include <engine/copy.h>
36
37struct nve0_copy_priv {
38 struct nouveau_engine base;
39};
40
41/*******************************************************************************
42 * Copy object classes
43 ******************************************************************************/
44
45static struct nouveau_oclass
46nve0_copy_sclass[] = {
47 { 0xa0b5, &nouveau_object_ofuncs },
48 {},
49};
50
51/*******************************************************************************
52 * PCOPY context
53 ******************************************************************************/
54
55static struct nouveau_ofuncs
56nve0_copy_context_ofuncs = {
57 .ctor = _nouveau_engctx_ctor,
58 .dtor = _nouveau_engctx_dtor,
59 .init = _nouveau_engctx_init,
60 .fini = _nouveau_engctx_fini,
61 .rd32 = _nouveau_engctx_rd32,
62 .wr32 = _nouveau_engctx_wr32,
63};
64
65static struct nouveau_oclass
66nve0_copy_cclass = {
67 .handle = NV_ENGCTX(COPY0, 0xc0),
68 .ofuncs = &nve0_copy_context_ofuncs,
69};
70
71/*******************************************************************************
72 * PCOPY engine/subdev functions
73 ******************************************************************************/
74
75static void
76nve0_copy_intr(struct nouveau_subdev *subdev)
77{
78 const int ce = nv_subidx(nv_object(subdev)) - NVDEV_ENGINE_COPY0;
79 struct nve0_copy_priv *priv = (void *)subdev;
80 u32 stat = nv_rd32(priv, 0x104908 + (ce * 0x1000));
81
82 if (stat) {
83 nv_warn(priv, "unhandled intr 0x%08x\n", stat);
84 nv_wr32(priv, 0x104908 + (ce * 0x1000), stat);
85 }
86}
87
88static int
89nve0_copy0_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
90 struct nouveau_oclass *oclass, void *data, u32 size,
91 struct nouveau_object **pobject)
92{
93 struct nve0_copy_priv *priv;
94 int ret;
95
96 ret = nouveau_engine_create(parent, engine, oclass, true,
97 "PCE0", "copy0", &priv);
98 *pobject = nv_object(priv);
99 if (ret)
100 return ret;
101
102 nv_subdev(priv)->unit = 0x00000040;
103 nv_subdev(priv)->intr = nve0_copy_intr;
104 nv_engine(priv)->cclass = &nve0_copy_cclass;
105 nv_engine(priv)->sclass = nve0_copy_sclass;
106 return 0;
107}
108
109static int
110nve0_copy1_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
111 struct nouveau_oclass *oclass, void *data, u32 size,
112 struct nouveau_object **pobject)
113{
114 struct nve0_copy_priv *priv;
115 int ret;
116
117 ret = nouveau_engine_create(parent, engine, oclass, true,
118 "PCE1", "copy1", &priv);
119 *pobject = nv_object(priv);
120 if (ret)
121 return ret;
122
123 nv_subdev(priv)->unit = 0x00000080;
124 nv_subdev(priv)->intr = nve0_copy_intr;
125 nv_engine(priv)->cclass = &nve0_copy_cclass;
126 nv_engine(priv)->sclass = nve0_copy_sclass;
127 return 0;
128}
129
130static int
131nve0_copy2_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
132 struct nouveau_oclass *oclass, void *data, u32 size,
133 struct nouveau_object **pobject)
134{
135 struct nve0_copy_priv *priv;
136 int ret;
137
138 ret = nouveau_engine_create(parent, engine, oclass, true,
139 "PCE2", "copy2", &priv);
140 *pobject = nv_object(priv);
141 if (ret)
142 return ret;
143
144 nv_subdev(priv)->unit = 0x00200000;
145 nv_subdev(priv)->intr = nve0_copy_intr;
146 nv_engine(priv)->cclass = &nve0_copy_cclass;
147 nv_engine(priv)->sclass = nve0_copy_sclass;
148 return 0;
149}
150
151struct nouveau_oclass
152nve0_copy0_oclass = {
153 .handle = NV_ENGINE(COPY0, 0xe0),
154 .ofuncs = &(struct nouveau_ofuncs) {
155 .ctor = nve0_copy0_ctor,
156 .dtor = _nouveau_engine_dtor,
157 .init = _nouveau_engine_init,
158 .fini = _nouveau_engine_fini,
159 },
160};
161
162struct nouveau_oclass
163nve0_copy1_oclass = {
164 .handle = NV_ENGINE(COPY1, 0xe0),
165 .ofuncs = &(struct nouveau_ofuncs) {
166 .ctor = nve0_copy1_ctor,
167 .dtor = _nouveau_engine_dtor,
168 .init = _nouveau_engine_init,
169 .fini = _nouveau_engine_fini,
170 },
171};
172
173struct nouveau_oclass
174nve0_copy2_oclass = {
175 .handle = NV_ENGINE(COPY2, 0xe0),
176 .ofuncs = &(struct nouveau_ofuncs) {
177 .ctor = nve0_copy2_ctor,
178 .dtor = _nouveau_engine_dtor,
179 .init = _nouveau_engine_init,
180 .fini = _nouveau_engine_fini,
181 },
182};
183