1 | /* $NetBSD: nouveau_subdev_ltcg_gm107.c,v 1.1.1.1 2014/08/06 12:36:31 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2014 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_ltcg_gm107.c,v 1.1.1.1 2014/08/06 12:36:31 riastradh Exp $" ); |
29 | |
30 | #include <subdev/fb.h> |
31 | #include <subdev/timer.h> |
32 | |
33 | #include "gf100.h" |
34 | |
35 | static void |
36 | gm107_ltcg_lts_isr(struct gf100_ltcg_priv *priv, int ltc, int lts) |
37 | { |
38 | u32 base = 0x140000 + (ltc * 0x2000) + (lts * 0x400); |
39 | u32 stat = nv_rd32(priv, base + 0x00c); |
40 | |
41 | if (stat) { |
42 | nv_info(priv, "LTC%d_LTS%d: 0x%08x\n" , ltc, lts, stat); |
43 | nv_wr32(priv, base + 0x00c, stat); |
44 | } |
45 | } |
46 | |
47 | static void |
48 | gm107_ltcg_intr(struct nouveau_subdev *subdev) |
49 | { |
50 | struct gf100_ltcg_priv *priv = (void *)subdev; |
51 | u32 mask; |
52 | |
53 | mask = nv_rd32(priv, 0x00017c); |
54 | while (mask) { |
55 | u32 lts, ltc = __ffs(mask); |
56 | for (lts = 0; lts < priv->lts_nr; lts++) |
57 | gm107_ltcg_lts_isr(priv, ltc, lts); |
58 | mask &= ~(1 << ltc); |
59 | } |
60 | |
61 | /* we do something horribly wrong and upset PMFB a lot, so mask off |
62 | * interrupts from it after the first one until it's fixed |
63 | */ |
64 | nv_mask(priv, 0x000640, 0x02000000, 0x00000000); |
65 | } |
66 | |
67 | static void |
68 | gm107_ltcg_tags_clear(struct nouveau_ltcg *ltcg, u32 first, u32 count) |
69 | { |
70 | struct gf100_ltcg_priv *priv = (struct gf100_ltcg_priv *)ltcg; |
71 | u32 last = first + count - 1; |
72 | int p, i; |
73 | |
74 | BUG_ON((first > last) || (last >= priv->num_tags)); |
75 | |
76 | nv_wr32(priv, 0x17e270, first); |
77 | nv_wr32(priv, 0x17e274, last); |
78 | nv_wr32(priv, 0x17e26c, 0x4); /* trigger clear */ |
79 | |
80 | /* wait until it's finished with clearing */ |
81 | for (p = 0; p < priv->ltc_nr; ++p) { |
82 | for (i = 0; i < priv->lts_nr; ++i) |
83 | nv_wait(priv, 0x14046c + p * 0x2000 + i * 0x200, ~0, 0); |
84 | } |
85 | } |
86 | |
87 | static int |
88 | gm107_ltcg_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
89 | struct nouveau_oclass *oclass, void *data, u32 size, |
90 | struct nouveau_object **pobject) |
91 | { |
92 | struct gf100_ltcg_priv *priv; |
93 | struct nouveau_fb *pfb = nouveau_fb(parent); |
94 | u32 parts, mask; |
95 | int ret, i; |
96 | |
97 | ret = nouveau_ltcg_create(parent, engine, oclass, &priv); |
98 | *pobject = nv_object(priv); |
99 | if (ret) |
100 | return ret; |
101 | |
102 | parts = nv_rd32(priv, 0x022438); |
103 | mask = nv_rd32(priv, 0x021c14); |
104 | for (i = 0; i < parts; i++) { |
105 | if (!(mask & (1 << i))) |
106 | priv->ltc_nr++; |
107 | } |
108 | priv->lts_nr = nv_rd32(priv, 0x17e280) >> 28; |
109 | |
110 | ret = gf100_ltcg_init_tag_ram(pfb, priv); |
111 | if (ret) |
112 | return ret; |
113 | |
114 | priv->base.tags_alloc = gf100_ltcg_tags_alloc; |
115 | priv->base.tags_free = gf100_ltcg_tags_free; |
116 | priv->base.tags_clear = gm107_ltcg_tags_clear; |
117 | |
118 | nv_subdev(priv)->intr = gm107_ltcg_intr; |
119 | return 0; |
120 | } |
121 | |
122 | static int |
123 | gm107_ltcg_init(struct nouveau_object *object) |
124 | { |
125 | struct nouveau_ltcg *ltcg = (struct nouveau_ltcg *)object; |
126 | struct gf100_ltcg_priv *priv = (struct gf100_ltcg_priv *)ltcg; |
127 | int ret; |
128 | |
129 | ret = nouveau_ltcg_init(ltcg); |
130 | if (ret) |
131 | return ret; |
132 | |
133 | nv_wr32(priv, 0x17e27c, priv->ltc_nr); |
134 | nv_wr32(priv, 0x17e278, priv->tag_base); |
135 | return 0; |
136 | } |
137 | |
138 | struct nouveau_oclass * |
139 | gm107_ltcg_oclass = &(struct nouveau_oclass) { |
140 | .handle = NV_SUBDEV(LTCG, 0xff), |
141 | .ofuncs = &(struct nouveau_ofuncs) { |
142 | .ctor = gm107_ltcg_ctor, |
143 | .dtor = gf100_ltcg_dtor, |
144 | .init = gm107_ltcg_init, |
145 | .fini = _nouveau_ltcg_fini, |
146 | }, |
147 | }; |
148 | |