EDAC: i7core, sb_edac: Don't return NOTIFY_BAD from mce_decoder callback
[linux/fpc-iii.git] / drivers / gpu / drm / bochs / bochs_kms.c
blob96926f09e0c9cdcdcaed085edcd7ccf8ebb971ca
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 */
8 #include "bochs.h"
9 #include <drm/drm_plane_helper.h>
11 static int defx = 1024;
12 static int defy = 768;
14 module_param(defx, int, 0444);
15 module_param(defy, int, 0444);
16 MODULE_PARM_DESC(defx, "default x resolution");
17 MODULE_PARM_DESC(defy, "default y resolution");
19 /* ---------------------------------------------------------------------- */
21 static void bochs_crtc_dpms(struct drm_crtc *crtc, int mode)
23 switch (mode) {
24 case DRM_MODE_DPMS_ON:
25 case DRM_MODE_DPMS_STANDBY:
26 case DRM_MODE_DPMS_SUSPEND:
27 case DRM_MODE_DPMS_OFF:
28 default:
29 return;
33 static int bochs_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
34 struct drm_framebuffer *old_fb)
36 struct bochs_device *bochs =
37 container_of(crtc, struct bochs_device, crtc);
38 struct bochs_framebuffer *bochs_fb;
39 struct bochs_bo *bo;
40 u64 gpu_addr = 0;
41 int ret;
43 if (old_fb) {
44 bochs_fb = to_bochs_framebuffer(old_fb);
45 bo = gem_to_bochs_bo(bochs_fb->obj);
46 ret = ttm_bo_reserve(&bo->bo, true, false, false, NULL);
47 if (ret) {
48 DRM_ERROR("failed to reserve old_fb bo\n");
49 } else {
50 bochs_bo_unpin(bo);
51 ttm_bo_unreserve(&bo->bo);
55 if (WARN_ON(crtc->primary->fb == NULL))
56 return -EINVAL;
58 bochs_fb = to_bochs_framebuffer(crtc->primary->fb);
59 bo = gem_to_bochs_bo(bochs_fb->obj);
60 ret = ttm_bo_reserve(&bo->bo, true, false, false, NULL);
61 if (ret)
62 return ret;
64 ret = bochs_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
65 if (ret) {
66 ttm_bo_unreserve(&bo->bo);
67 return ret;
70 ttm_bo_unreserve(&bo->bo);
71 bochs_hw_setbase(bochs, x, y, gpu_addr);
72 return 0;
75 static int bochs_crtc_mode_set(struct drm_crtc *crtc,
76 struct drm_display_mode *mode,
77 struct drm_display_mode *adjusted_mode,
78 int x, int y, struct drm_framebuffer *old_fb)
80 struct bochs_device *bochs =
81 container_of(crtc, struct bochs_device, crtc);
83 bochs_hw_setmode(bochs, mode);
84 bochs_crtc_mode_set_base(crtc, x, y, old_fb);
85 return 0;
88 static void bochs_crtc_prepare(struct drm_crtc *crtc)
92 static void bochs_crtc_commit(struct drm_crtc *crtc)
96 static void bochs_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
97 u16 *blue, uint32_t start, uint32_t size)
101 static int bochs_crtc_page_flip(struct drm_crtc *crtc,
102 struct drm_framebuffer *fb,
103 struct drm_pending_vblank_event *event,
104 uint32_t page_flip_flags)
106 struct bochs_device *bochs =
107 container_of(crtc, struct bochs_device, crtc);
108 struct drm_framebuffer *old_fb = crtc->primary->fb;
109 unsigned long irqflags;
111 crtc->primary->fb = fb;
112 bochs_crtc_mode_set_base(crtc, 0, 0, old_fb);
113 if (event) {
114 spin_lock_irqsave(&bochs->dev->event_lock, irqflags);
115 drm_crtc_send_vblank_event(crtc, event);
116 spin_unlock_irqrestore(&bochs->dev->event_lock, irqflags);
118 return 0;
121 /* These provide the minimum set of functions required to handle a CRTC */
122 static const struct drm_crtc_funcs bochs_crtc_funcs = {
123 .gamma_set = bochs_crtc_gamma_set,
124 .set_config = drm_crtc_helper_set_config,
125 .destroy = drm_crtc_cleanup,
126 .page_flip = bochs_crtc_page_flip,
129 static const struct drm_crtc_helper_funcs bochs_helper_funcs = {
130 .dpms = bochs_crtc_dpms,
131 .mode_set = bochs_crtc_mode_set,
132 .mode_set_base = bochs_crtc_mode_set_base,
133 .prepare = bochs_crtc_prepare,
134 .commit = bochs_crtc_commit,
137 static void bochs_crtc_init(struct drm_device *dev)
139 struct bochs_device *bochs = dev->dev_private;
140 struct drm_crtc *crtc = &bochs->crtc;
142 drm_crtc_init(dev, crtc, &bochs_crtc_funcs);
143 drm_mode_crtc_set_gamma_size(crtc, 256);
144 drm_crtc_helper_add(crtc, &bochs_helper_funcs);
147 static void bochs_encoder_mode_set(struct drm_encoder *encoder,
148 struct drm_display_mode *mode,
149 struct drm_display_mode *adjusted_mode)
153 static void bochs_encoder_dpms(struct drm_encoder *encoder, int state)
157 static void bochs_encoder_prepare(struct drm_encoder *encoder)
161 static void bochs_encoder_commit(struct drm_encoder *encoder)
165 static const struct drm_encoder_helper_funcs bochs_encoder_helper_funcs = {
166 .dpms = bochs_encoder_dpms,
167 .mode_set = bochs_encoder_mode_set,
168 .prepare = bochs_encoder_prepare,
169 .commit = bochs_encoder_commit,
172 static const struct drm_encoder_funcs bochs_encoder_encoder_funcs = {
173 .destroy = drm_encoder_cleanup,
176 static void bochs_encoder_init(struct drm_device *dev)
178 struct bochs_device *bochs = dev->dev_private;
179 struct drm_encoder *encoder = &bochs->encoder;
181 encoder->possible_crtcs = 0x1;
182 drm_encoder_init(dev, encoder, &bochs_encoder_encoder_funcs,
183 DRM_MODE_ENCODER_DAC, NULL);
184 drm_encoder_helper_add(encoder, &bochs_encoder_helper_funcs);
188 int bochs_connector_get_modes(struct drm_connector *connector)
190 int count;
192 count = drm_add_modes_noedid(connector, 8192, 8192);
193 drm_set_preferred_mode(connector, defx, defy);
194 return count;
197 static int bochs_connector_mode_valid(struct drm_connector *connector,
198 struct drm_display_mode *mode)
200 struct bochs_device *bochs =
201 container_of(connector, struct bochs_device, connector);
202 unsigned long size = mode->hdisplay * mode->vdisplay * 4;
205 * Make sure we can fit two framebuffers into video memory.
206 * This allows up to 1600x1200 with 16 MB (default size).
207 * If you want more try this:
208 * 'qemu -vga std -global VGA.vgamem_mb=32 $otherargs'
210 if (size * 2 > bochs->fb_size)
211 return MODE_BAD;
213 return MODE_OK;
216 static struct drm_encoder *
217 bochs_connector_best_encoder(struct drm_connector *connector)
219 int enc_id = connector->encoder_ids[0];
220 /* pick the encoder ids */
221 if (enc_id)
222 return drm_encoder_find(connector->dev, enc_id);
223 return NULL;
226 static enum drm_connector_status bochs_connector_detect(struct drm_connector
227 *connector, bool force)
229 return connector_status_connected;
232 static const struct drm_connector_helper_funcs bochs_connector_connector_helper_funcs = {
233 .get_modes = bochs_connector_get_modes,
234 .mode_valid = bochs_connector_mode_valid,
235 .best_encoder = bochs_connector_best_encoder,
238 static const struct drm_connector_funcs bochs_connector_connector_funcs = {
239 .dpms = drm_helper_connector_dpms,
240 .detect = bochs_connector_detect,
241 .fill_modes = drm_helper_probe_single_connector_modes,
242 .destroy = drm_connector_cleanup,
245 static void bochs_connector_init(struct drm_device *dev)
247 struct bochs_device *bochs = dev->dev_private;
248 struct drm_connector *connector = &bochs->connector;
250 drm_connector_init(dev, connector, &bochs_connector_connector_funcs,
251 DRM_MODE_CONNECTOR_VIRTUAL);
252 drm_connector_helper_add(connector,
253 &bochs_connector_connector_helper_funcs);
254 drm_connector_register(connector);
258 int bochs_kms_init(struct bochs_device *bochs)
260 drm_mode_config_init(bochs->dev);
261 bochs->mode_config_initialized = true;
263 bochs->dev->mode_config.max_width = 8192;
264 bochs->dev->mode_config.max_height = 8192;
266 bochs->dev->mode_config.fb_base = bochs->fb_base;
267 bochs->dev->mode_config.preferred_depth = 24;
268 bochs->dev->mode_config.prefer_shadow = 0;
270 bochs->dev->mode_config.funcs = &bochs_mode_funcs;
272 bochs_crtc_init(bochs->dev);
273 bochs_encoder_init(bochs->dev);
274 bochs_connector_init(bochs->dev);
275 drm_mode_connector_attach_encoder(&bochs->connector,
276 &bochs->encoder);
278 return 0;
281 void bochs_kms_fini(struct bochs_device *bochs)
283 if (bochs->mode_config_initialized) {
284 drm_mode_config_cleanup(bochs->dev);
285 bochs->mode_config_initialized = false;