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.
10 static int defx
= 1024;
11 static int defy
= 768;
13 module_param(defx
, int, 0444);
14 module_param(defy
, int, 0444);
15 MODULE_PARM_DESC(defx
, "default x resolution");
16 MODULE_PARM_DESC(defy
, "default y resolution");
18 /* ---------------------------------------------------------------------- */
20 static void bochs_crtc_load_lut(struct drm_crtc
*crtc
)
24 static void bochs_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
27 case DRM_MODE_DPMS_ON
:
28 case DRM_MODE_DPMS_STANDBY
:
29 case DRM_MODE_DPMS_SUSPEND
:
30 case DRM_MODE_DPMS_OFF
:
36 static bool bochs_crtc_mode_fixup(struct drm_crtc
*crtc
,
37 const struct drm_display_mode
*mode
,
38 struct drm_display_mode
*adjusted_mode
)
43 static int bochs_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
44 struct drm_framebuffer
*old_fb
)
46 struct bochs_device
*bochs
=
47 container_of(crtc
, struct bochs_device
, crtc
);
48 struct bochs_framebuffer
*bochs_fb
;
54 bochs_fb
= to_bochs_framebuffer(old_fb
);
55 bo
= gem_to_bochs_bo(bochs_fb
->obj
);
56 ret
= ttm_bo_reserve(&bo
->bo
, true, false, false, 0);
58 DRM_ERROR("failed to reserve old_fb bo\n");
61 ttm_bo_unreserve(&bo
->bo
);
65 if (WARN_ON(crtc
->fb
== NULL
))
68 bochs_fb
= to_bochs_framebuffer(crtc
->fb
);
69 bo
= gem_to_bochs_bo(bochs_fb
->obj
);
70 ret
= ttm_bo_reserve(&bo
->bo
, true, false, false, 0);
74 ret
= bochs_bo_pin(bo
, TTM_PL_FLAG_VRAM
, &gpu_addr
);
76 ttm_bo_unreserve(&bo
->bo
);
80 ttm_bo_unreserve(&bo
->bo
);
81 bochs_hw_setbase(bochs
, x
, y
, gpu_addr
);
85 static int bochs_crtc_mode_set(struct drm_crtc
*crtc
,
86 struct drm_display_mode
*mode
,
87 struct drm_display_mode
*adjusted_mode
,
88 int x
, int y
, struct drm_framebuffer
*old_fb
)
90 struct bochs_device
*bochs
=
91 container_of(crtc
, struct bochs_device
, crtc
);
93 bochs_hw_setmode(bochs
, mode
);
94 bochs_crtc_mode_set_base(crtc
, x
, y
, old_fb
);
98 static void bochs_crtc_prepare(struct drm_crtc
*crtc
)
102 static void bochs_crtc_commit(struct drm_crtc
*crtc
)
106 static void bochs_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
107 u16
*blue
, uint32_t start
, uint32_t size
)
111 /* These provide the minimum set of functions required to handle a CRTC */
112 static const struct drm_crtc_funcs bochs_crtc_funcs
= {
113 .gamma_set
= bochs_crtc_gamma_set
,
114 .set_config
= drm_crtc_helper_set_config
,
115 .destroy
= drm_crtc_cleanup
,
118 static const struct drm_crtc_helper_funcs bochs_helper_funcs
= {
119 .dpms
= bochs_crtc_dpms
,
120 .mode_fixup
= bochs_crtc_mode_fixup
,
121 .mode_set
= bochs_crtc_mode_set
,
122 .mode_set_base
= bochs_crtc_mode_set_base
,
123 .prepare
= bochs_crtc_prepare
,
124 .commit
= bochs_crtc_commit
,
125 .load_lut
= bochs_crtc_load_lut
,
128 static void bochs_crtc_init(struct drm_device
*dev
)
130 struct bochs_device
*bochs
= dev
->dev_private
;
131 struct drm_crtc
*crtc
= &bochs
->crtc
;
133 drm_crtc_init(dev
, crtc
, &bochs_crtc_funcs
);
134 drm_mode_crtc_set_gamma_size(crtc
, 256);
135 drm_crtc_helper_add(crtc
, &bochs_helper_funcs
);
138 static bool bochs_encoder_mode_fixup(struct drm_encoder
*encoder
,
139 const struct drm_display_mode
*mode
,
140 struct drm_display_mode
*adjusted_mode
)
145 static void bochs_encoder_mode_set(struct drm_encoder
*encoder
,
146 struct drm_display_mode
*mode
,
147 struct drm_display_mode
*adjusted_mode
)
151 static void bochs_encoder_dpms(struct drm_encoder
*encoder
, int state
)
155 static void bochs_encoder_prepare(struct drm_encoder
*encoder
)
159 static void bochs_encoder_commit(struct drm_encoder
*encoder
)
163 static const struct drm_encoder_helper_funcs bochs_encoder_helper_funcs
= {
164 .dpms
= bochs_encoder_dpms
,
165 .mode_fixup
= bochs_encoder_mode_fixup
,
166 .mode_set
= bochs_encoder_mode_set
,
167 .prepare
= bochs_encoder_prepare
,
168 .commit
= bochs_encoder_commit
,
171 static const struct drm_encoder_funcs bochs_encoder_encoder_funcs
= {
172 .destroy
= drm_encoder_cleanup
,
175 static void bochs_encoder_init(struct drm_device
*dev
)
177 struct bochs_device
*bochs
= dev
->dev_private
;
178 struct drm_encoder
*encoder
= &bochs
->encoder
;
180 encoder
->possible_crtcs
= 0x1;
181 drm_encoder_init(dev
, encoder
, &bochs_encoder_encoder_funcs
,
182 DRM_MODE_ENCODER_DAC
);
183 drm_encoder_helper_add(encoder
, &bochs_encoder_helper_funcs
);
187 int bochs_connector_get_modes(struct drm_connector
*connector
)
191 count
= drm_add_modes_noedid(connector
, 8192, 8192);
192 drm_set_preferred_mode(connector
, defx
, defy
);
196 static int bochs_connector_mode_valid(struct drm_connector
*connector
,
197 struct drm_display_mode
*mode
)
199 struct bochs_device
*bochs
=
200 container_of(connector
, struct bochs_device
, connector
);
201 unsigned long size
= mode
->hdisplay
* mode
->vdisplay
* 4;
204 * Make sure we can fit two framebuffers into video memory.
205 * This allows up to 1600x1200 with 16 MB (default size).
206 * If you want more try this:
207 * 'qemu -vga std -global VGA.vgamem_mb=32 $otherargs'
209 if (size
* 2 > bochs
->fb_size
)
215 static struct drm_encoder
*
216 bochs_connector_best_encoder(struct drm_connector
*connector
)
218 int enc_id
= connector
->encoder_ids
[0];
219 struct drm_mode_object
*obj
;
220 struct drm_encoder
*encoder
;
222 /* pick the encoder ids */
224 obj
= drm_mode_object_find(connector
->dev
, enc_id
,
225 DRM_MODE_OBJECT_ENCODER
);
228 encoder
= obj_to_encoder(obj
);
234 static enum drm_connector_status
bochs_connector_detect(struct drm_connector
235 *connector
, bool force
)
237 return connector_status_connected
;
240 struct drm_connector_helper_funcs bochs_connector_connector_helper_funcs
= {
241 .get_modes
= bochs_connector_get_modes
,
242 .mode_valid
= bochs_connector_mode_valid
,
243 .best_encoder
= bochs_connector_best_encoder
,
246 struct drm_connector_funcs bochs_connector_connector_funcs
= {
247 .dpms
= drm_helper_connector_dpms
,
248 .detect
= bochs_connector_detect
,
249 .fill_modes
= drm_helper_probe_single_connector_modes
,
250 .destroy
= drm_connector_cleanup
,
253 static void bochs_connector_init(struct drm_device
*dev
)
255 struct bochs_device
*bochs
= dev
->dev_private
;
256 struct drm_connector
*connector
= &bochs
->connector
;
258 drm_connector_init(dev
, connector
, &bochs_connector_connector_funcs
,
259 DRM_MODE_CONNECTOR_VIRTUAL
);
260 drm_connector_helper_add(connector
,
261 &bochs_connector_connector_helper_funcs
);
265 int bochs_kms_init(struct bochs_device
*bochs
)
267 drm_mode_config_init(bochs
->dev
);
268 bochs
->mode_config_initialized
= true;
270 bochs
->dev
->mode_config
.max_width
= 8192;
271 bochs
->dev
->mode_config
.max_height
= 8192;
273 bochs
->dev
->mode_config
.fb_base
= bochs
->fb_base
;
274 bochs
->dev
->mode_config
.preferred_depth
= 24;
275 bochs
->dev
->mode_config
.prefer_shadow
= 0;
277 bochs
->dev
->mode_config
.funcs
= (void *)&bochs_mode_funcs
;
279 bochs_crtc_init(bochs
->dev
);
280 bochs_encoder_init(bochs
->dev
);
281 bochs_connector_init(bochs
->dev
);
282 drm_mode_connector_attach_encoder(&bochs
->connector
,
288 void bochs_kms_fini(struct bochs_device
*bochs
)
290 if (bochs
->mode_config_initialized
) {
291 drm_mode_config_cleanup(bochs
->dev
);
292 bochs
->mode_config_initialized
= false;