1 /*	$NetBSD: nouveau_subdev_ibus_nvc0.c,v 1.1.1.1 2014/08/06 12:36:30 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_subdev_ibus_nvc0.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $");
29 
30 #include <subdev/ibus.h>
31 
32 struct nvc0_ibus_priv {
33 	struct nouveau_ibus base;
34 };
35 
36 static void
nvc0_ibus_intr_hub(struct nvc0_ibus_priv * priv,int i)37 nvc0_ibus_intr_hub(struct nvc0_ibus_priv *priv, int i)
38 {
39 	u32 addr = nv_rd32(priv, 0x122120 + (i * 0x0400));
40 	u32 data = nv_rd32(priv, 0x122124 + (i * 0x0400));
41 	u32 stat = nv_rd32(priv, 0x122128 + (i * 0x0400));
42 	nv_error(priv, "HUB%d: 0x%06x 0x%08x (0x%08x)\n", i, addr, data, stat);
43 	nv_mask(priv, 0x122128 + (i * 0x0400), 0x00000200, 0x00000000);
44 }
45 
46 static void
nvc0_ibus_intr_rop(struct nvc0_ibus_priv * priv,int i)47 nvc0_ibus_intr_rop(struct nvc0_ibus_priv *priv, int i)
48 {
49 	u32 addr = nv_rd32(priv, 0x124120 + (i * 0x0400));
50 	u32 data = nv_rd32(priv, 0x124124 + (i * 0x0400));
51 	u32 stat = nv_rd32(priv, 0x124128 + (i * 0x0400));
52 	nv_error(priv, "ROP%d: 0x%06x 0x%08x (0x%08x)\n", i, addr, data, stat);
53 	nv_mask(priv, 0x124128 + (i * 0x0400), 0x00000200, 0x00000000);
54 }
55 
56 static void
nvc0_ibus_intr_gpc(struct nvc0_ibus_priv * priv,int i)57 nvc0_ibus_intr_gpc(struct nvc0_ibus_priv *priv, int i)
58 {
59 	u32 addr = nv_rd32(priv, 0x128120 + (i * 0x0400));
60 	u32 data = nv_rd32(priv, 0x128124 + (i * 0x0400));
61 	u32 stat = nv_rd32(priv, 0x128128 + (i * 0x0400));
62 	nv_error(priv, "GPC%d: 0x%06x 0x%08x (0x%08x)\n", i, addr, data, stat);
63 	nv_mask(priv, 0x128128 + (i * 0x0400), 0x00000200, 0x00000000);
64 }
65 
66 static void
nvc0_ibus_intr(struct nouveau_subdev * subdev)67 nvc0_ibus_intr(struct nouveau_subdev *subdev)
68 {
69 	struct nvc0_ibus_priv *priv = (void *)subdev;
70 	u32 intr0 = nv_rd32(priv, 0x121c58);
71 	u32 intr1 = nv_rd32(priv, 0x121c5c);
72 	u32 hubnr = nv_rd32(priv, 0x121c70);
73 	u32 ropnr = nv_rd32(priv, 0x121c74);
74 	u32 gpcnr = nv_rd32(priv, 0x121c78);
75 	u32 i;
76 
77 	for (i = 0; (intr0 & 0x0000ff00) && i < hubnr; i++) {
78 		u32 stat = 0x00000100 << i;
79 		if (intr0 & stat) {
80 			nvc0_ibus_intr_hub(priv, i);
81 			intr0 &= ~stat;
82 		}
83 	}
84 
85 	for (i = 0; (intr0 & 0xffff0000) && i < ropnr; i++) {
86 		u32 stat = 0x00010000 << i;
87 		if (intr0 & stat) {
88 			nvc0_ibus_intr_rop(priv, i);
89 			intr0 &= ~stat;
90 		}
91 	}
92 
93 	for (i = 0; intr1 && i < gpcnr; i++) {
94 		u32 stat = 0x00000001 << i;
95 		if (intr1 & stat) {
96 			nvc0_ibus_intr_gpc(priv, i);
97 			intr1 &= ~stat;
98 		}
99 	}
100 }
101 
102 static int
nvc0_ibus_ctor(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,void * data,u32 size,struct nouveau_object ** pobject)103 nvc0_ibus_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
104 	       struct nouveau_oclass *oclass, void *data, u32 size,
105 	       struct nouveau_object **pobject)
106 {
107 	struct nvc0_ibus_priv *priv;
108 	int ret;
109 
110 	ret = nouveau_ibus_create(parent, engine, oclass, &priv);
111 	*pobject = nv_object(priv);
112 	if (ret)
113 		return ret;
114 
115 	nv_subdev(priv)->intr = nvc0_ibus_intr;
116 	return 0;
117 }
118 
119 struct nouveau_oclass
120 nvc0_ibus_oclass = {
121 	.handle = NV_SUBDEV(IBUS, 0xc0),
122 	.ofuncs = &(struct nouveau_ofuncs) {
123 		.ctor = nvc0_ibus_ctor,
124 		.dtor = _nouveau_ibus_dtor,
125 		.init = _nouveau_ibus_init,
126 		.fini = _nouveau_ibus_fini,
127 	},
128 };
129