2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <core/falcon.h>
26 #include <core/class.h>
27 #include <core/enum.h>
29 #include <subdev/fb.h>
30 #include <subdev/vm.h>
32 #include <engine/fifo.h>
33 #include <engine/copy.h>
35 #include "fuc/nva3.fuc.h"
37 struct nva3_copy_priv {
38 struct nouveau_falcon base;
41 /*******************************************************************************
43 ******************************************************************************/
45 static struct nouveau_oclass
46 nva3_copy_sclass[] = {
47 { 0x85b5, &nouveau_object_ofuncs },
51 /*******************************************************************************
53 ******************************************************************************/
55 static struct nouveau_oclass
57 .handle = NV_ENGCTX(COPY0, 0xa3),
58 .ofuncs = &(struct nouveau_ofuncs) {
59 .ctor = _nouveau_falcon_context_ctor,
60 .dtor = _nouveau_falcon_context_dtor,
61 .init = _nouveau_falcon_context_init,
62 .fini = _nouveau_falcon_context_fini,
63 .rd32 = _nouveau_falcon_context_rd32,
64 .wr32 = _nouveau_falcon_context_wr32,
69 /*******************************************************************************
70 * PCOPY engine/subdev functions
71 ******************************************************************************/
73 static const struct nouveau_enum nva3_copy_isr_error_name[] = {
74 { 0x0001, "ILLEGAL_MTHD" },
75 { 0x0002, "INVALID_ENUM" },
76 { 0x0003, "INVALID_BITFIELD" },
81 nva3_copy_intr(struct nouveau_subdev *subdev)
83 struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
84 struct nouveau_engine *engine = nv_engine(subdev);
85 struct nouveau_falcon *falcon = (void *)subdev;
86 struct nouveau_object *engctx;
87 u32 dispatch = nv_ro32(falcon, 0x01c);
88 u32 stat = nv_ro32(falcon, 0x008) & dispatch & ~(dispatch >> 16);
89 u64 inst = nv_ro32(falcon, 0x050) & 0x3fffffff;
90 u32 ssta = nv_ro32(falcon, 0x040) & 0x0000ffff;
91 u32 addr = nv_ro32(falcon, 0x040) >> 16;
92 u32 mthd = (addr & 0x07ff) << 2;
93 u32 subc = (addr & 0x3800) >> 11;
94 u32 data = nv_ro32(falcon, 0x044);
97 engctx = nouveau_engctx_get(engine, inst);
98 chid = pfifo->chid(pfifo, engctx);
100 if (stat & 0x00000040) {
101 nv_error(falcon, "DISPATCH_ERROR [");
102 nouveau_enum_print(nva3_copy_isr_error_name, ssta);
103 printk("] ch %d [0x%010llx] subc %d mthd 0x%04x data 0x%08x\n",
104 chid, inst << 12, subc, mthd, data);
105 nv_wo32(falcon, 0x004, 0x00000040);
110 nv_error(falcon, "unhandled intr 0x%08x\n", stat);
111 nv_wo32(falcon, 0x004, stat);
114 nouveau_engctx_put(engctx);
118 nva3_copy_tlb_flush(struct nouveau_engine *engine)
120 nv50_vm_flush_engine(&engine->base, 0x0d);
125 nva3_copy_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
126 struct nouveau_oclass *oclass, void *data, u32 size,
127 struct nouveau_object **pobject)
129 bool enable = (nv_device(parent)->chipset != 0xaf);
130 struct nva3_copy_priv *priv;
133 ret = nouveau_falcon_create(parent, engine, oclass, 0x104000, enable,
134 "PCE0", "copy0", &priv);
135 *pobject = nv_object(priv);
139 nv_subdev(priv)->unit = 0x00802000;
140 nv_subdev(priv)->intr = nva3_copy_intr;
141 nv_engine(priv)->cclass = &nva3_copy_cclass;
142 nv_engine(priv)->sclass = nva3_copy_sclass;
143 nv_engine(priv)->tlb_flush = nva3_copy_tlb_flush;
144 nv_falcon(priv)->code.data = nva3_pcopy_code;
145 nv_falcon(priv)->code.size = sizeof(nva3_pcopy_code);
146 nv_falcon(priv)->data.data = nva3_pcopy_data;
147 nv_falcon(priv)->data.size = sizeof(nva3_pcopy_data);
151 struct nouveau_oclass
153 .handle = NV_ENGINE(COPY0, 0xa3),
154 .ofuncs = &(struct nouveau_ofuncs) {
155 .ctor = nva3_copy_ctor,
156 .dtor = _nouveau_falcon_dtor,
157 .init = _nouveau_falcon_init,
158 .fini = _nouveau_falcon_fini,
159 .rd32 = _nouveau_falcon_rd32,
160 .wr32 = _nouveau_falcon_wr32,