1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <drm/drmP.h>
26#include <drm/drm_crtc_helper.h>
27
28#include "nouveau_drv.h"
29#include "nouveau_reg.h"
30#include "hw.h"
31#include "nouveau_encoder.h"
32#include "nouveau_connector.h"
33#include "nouveau_bo.h"
34
35#include <nvif/if0004.h>
36
37static void
38nv04_display_fini(struct drm_device *dev, bool suspend)
39{
40 struct nv04_display *disp = nv04_display(dev);
41 struct drm_crtc *crtc;
42
43
44 nvif_notify_put(&disp->flip);
45
46
47 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
48 if (nv_two_heads(dev))
49 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
50
51 if (!suspend)
52 return;
53
54
55 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
56 struct nouveau_framebuffer *nouveau_fb;
57
58 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
59 if (!nouveau_fb || !nouveau_fb->nvbo)
60 continue;
61
62 nouveau_bo_unpin(nouveau_fb->nvbo);
63 }
64
65 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
66 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
67 if (nv_crtc->cursor.nvbo) {
68 if (nv_crtc->cursor.set_offset)
69 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
70 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
71 }
72 }
73}
74
75static int
76nv04_display_init(struct drm_device *dev, bool resume, bool runtime)
77{
78 struct nv04_display *disp = nv04_display(dev);
79 struct nouveau_drm *drm = nouveau_drm(dev);
80 struct nouveau_encoder *encoder;
81 struct drm_crtc *crtc;
82 int ret;
83
84
85
86
87
88
89
90
91
92 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
93 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
94 nv_crtc->save(&nv_crtc->base);
95 }
96
97 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
98 encoder->enc_save(&encoder->base.base);
99
100
101 nvif_notify_get(&disp->flip);
102
103 if (!resume)
104 return 0;
105
106
107 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
108 struct nouveau_framebuffer *nouveau_fb;
109
110 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
111 if (!nouveau_fb || !nouveau_fb->nvbo)
112 continue;
113
114 ret = nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM, true);
115 if (ret)
116 NV_ERROR(drm, "Could not pin framebuffer\n");
117 }
118
119 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
120 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
121 if (!nv_crtc->cursor.nvbo)
122 continue;
123
124 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM, true);
125 if (!ret && nv_crtc->cursor.set_offset)
126 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
127 if (ret)
128 NV_ERROR(drm, "Could not pin/map cursor.\n");
129 }
130
131
132 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
133 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
134
135 nv_crtc->lut.depth = 0;
136 }
137
138
139
140
141
142 if (runtime)
143 return 0;
144
145
146 drm_helper_resume_force_mode(dev);
147
148 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
149 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
150
151 if (!nv_crtc->cursor.nvbo)
152 continue;
153
154 if (nv_crtc->cursor.set_offset)
155 nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset);
156 nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
157 nv_crtc->cursor_saved_y);
158 }
159
160 return 0;
161}
162
163static void
164nv04_display_destroy(struct drm_device *dev)
165{
166 struct nv04_display *disp = nv04_display(dev);
167 struct nouveau_drm *drm = nouveau_drm(dev);
168 struct nouveau_encoder *encoder;
169 struct nouveau_crtc *nv_crtc;
170
171
172 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
173 encoder->enc_restore(&encoder->base.base);
174
175 list_for_each_entry(nv_crtc, &dev->mode_config.crtc_list, base.head)
176 nv_crtc->restore(&nv_crtc->base);
177
178 nouveau_hw_save_vga_fonts(dev, 0);
179
180 nvif_notify_fini(&disp->flip);
181
182 nouveau_display(dev)->priv = NULL;
183 kfree(disp);
184
185 nvif_object_unmap(&drm->client.device.object);
186}
187
188int
189nv04_display_create(struct drm_device *dev)
190{
191 struct nouveau_drm *drm = nouveau_drm(dev);
192 struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
193 struct dcb_table *dcb = &drm->vbios.dcb;
194 struct drm_connector *connector, *ct;
195 struct drm_encoder *encoder;
196 struct nouveau_encoder *nv_encoder;
197 struct nouveau_crtc *crtc;
198 struct nv04_display *disp;
199 int i, ret;
200
201 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
202 if (!disp)
203 return -ENOMEM;
204
205 nvif_object_map(&drm->client.device.object, NULL, 0);
206
207 nouveau_display(dev)->priv = disp;
208 nouveau_display(dev)->dtor = nv04_display_destroy;
209 nouveau_display(dev)->init = nv04_display_init;
210 nouveau_display(dev)->fini = nv04_display_fini;
211
212
213 dev->driver->driver_features &= ~DRIVER_ATOMIC;
214
215
216 if (drm->nvsw.client) {
217 nvif_notify_init(&drm->nvsw, nv04_flip_complete,
218 false, NV04_NVSW_NTFY_UEVENT,
219 NULL, 0, 0, &disp->flip);
220 }
221
222 nouveau_hw_save_vga_fonts(dev, 1);
223
224 nv04_crtc_create(dev, 0);
225 if (nv_two_heads(dev))
226 nv04_crtc_create(dev, 1);
227
228 for (i = 0; i < dcb->entries; i++) {
229 struct dcb_output *dcbent = &dcb->entry[i];
230
231 connector = nouveau_connector_create(dev, dcbent);
232 if (IS_ERR(connector))
233 continue;
234
235 switch (dcbent->type) {
236 case DCB_OUTPUT_ANALOG:
237 ret = nv04_dac_create(connector, dcbent);
238 break;
239 case DCB_OUTPUT_LVDS:
240 case DCB_OUTPUT_TMDS:
241 ret = nv04_dfp_create(connector, dcbent);
242 break;
243 case DCB_OUTPUT_TV:
244 if (dcbent->location == DCB_LOC_ON_CHIP)
245 ret = nv17_tv_create(connector, dcbent);
246 else
247 ret = nv04_tv_create(connector, dcbent);
248 break;
249 default:
250 NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
251 continue;
252 }
253
254 if (ret)
255 continue;
256 }
257
258 list_for_each_entry_safe(connector, ct,
259 &dev->mode_config.connector_list, head) {
260 if (!connector->encoder_ids[0]) {
261 NV_WARN(drm, "%s has no encoders, removing\n",
262 connector->name);
263 connector->funcs->destroy(connector);
264 }
265 }
266
267 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
268 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
269 struct nvkm_i2c_bus *bus =
270 nvkm_i2c_bus_find(i2c, nv_encoder->dcb->i2c_index);
271 nv_encoder->i2c = bus ? &bus->i2c : NULL;
272 }
273
274
275 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
276 crtc->save(&crtc->base);
277
278 list_for_each_entry(nv_encoder, &dev->mode_config.encoder_list, base.base.head)
279 nv_encoder->enc_save(&nv_encoder->base.base);
280
281 nouveau_overlay_init(dev);
282
283 return 0;
284}
285