treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / bochs / bochs_kms.c
blob3f0006c2470d1a28d61fb03853eac3b3f6470c1f
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 */
5 #include <linux/moduleparam.h>
7 #include <drm/drm_atomic_helper.h>
8 #include <drm/drm_gem_framebuffer_helper.h>
9 #include <drm/drm_probe_helper.h>
10 #include <drm/drm_vblank.h>
12 #include "bochs.h"
14 static int defx = 1024;
15 static int defy = 768;
17 module_param(defx, int, 0444);
18 module_param(defy, int, 0444);
19 MODULE_PARM_DESC(defx, "default x resolution");
20 MODULE_PARM_DESC(defy, "default y resolution");
22 /* ---------------------------------------------------------------------- */
24 static const uint32_t bochs_formats[] = {
25 DRM_FORMAT_XRGB8888,
26 DRM_FORMAT_BGRX8888,
29 static void bochs_plane_update(struct bochs_device *bochs,
30 struct drm_plane_state *state)
32 struct drm_gem_vram_object *gbo;
34 if (!state->fb || !bochs->stride)
35 return;
37 gbo = drm_gem_vram_of_gem(state->fb->obj[0]);
38 bochs_hw_setbase(bochs,
39 state->crtc_x,
40 state->crtc_y,
41 state->fb->pitches[0],
42 state->fb->offsets[0] + gbo->bo.offset);
43 bochs_hw_setformat(bochs, state->fb->format);
46 static void bochs_pipe_enable(struct drm_simple_display_pipe *pipe,
47 struct drm_crtc_state *crtc_state,
48 struct drm_plane_state *plane_state)
50 struct bochs_device *bochs = pipe->crtc.dev->dev_private;
52 bochs_hw_setmode(bochs, &crtc_state->mode);
53 bochs_plane_update(bochs, plane_state);
56 static void bochs_pipe_update(struct drm_simple_display_pipe *pipe,
57 struct drm_plane_state *old_state)
59 struct bochs_device *bochs = pipe->crtc.dev->dev_private;
60 struct drm_crtc *crtc = &pipe->crtc;
62 bochs_plane_update(bochs, pipe->plane.state);
64 if (crtc->state->event) {
65 spin_lock_irq(&crtc->dev->event_lock);
66 drm_crtc_send_vblank_event(crtc, crtc->state->event);
67 crtc->state->event = NULL;
68 spin_unlock_irq(&crtc->dev->event_lock);
72 static const struct drm_simple_display_pipe_funcs bochs_pipe_funcs = {
73 .enable = bochs_pipe_enable,
74 .update = bochs_pipe_update,
75 .prepare_fb = drm_gem_vram_simple_display_pipe_prepare_fb,
76 .cleanup_fb = drm_gem_vram_simple_display_pipe_cleanup_fb,
79 static int bochs_connector_get_modes(struct drm_connector *connector)
81 struct bochs_device *bochs =
82 container_of(connector, struct bochs_device, connector);
83 int count = 0;
85 if (bochs->edid)
86 count = drm_add_edid_modes(connector, bochs->edid);
88 if (!count) {
89 count = drm_add_modes_noedid(connector, 8192, 8192);
90 drm_set_preferred_mode(connector, defx, defy);
92 return count;
95 static enum drm_mode_status bochs_connector_mode_valid(struct drm_connector *connector,
96 struct drm_display_mode *mode)
98 struct bochs_device *bochs =
99 container_of(connector, struct bochs_device, connector);
100 unsigned long size = mode->hdisplay * mode->vdisplay * 4;
103 * Make sure we can fit two framebuffers into video memory.
104 * This allows up to 1600x1200 with 16 MB (default size).
105 * If you want more try this:
106 * 'qemu -vga std -global VGA.vgamem_mb=32 $otherargs'
108 if (size * 2 > bochs->fb_size)
109 return MODE_BAD;
111 return MODE_OK;
114 static const struct drm_connector_helper_funcs bochs_connector_connector_helper_funcs = {
115 .get_modes = bochs_connector_get_modes,
116 .mode_valid = bochs_connector_mode_valid,
119 static const struct drm_connector_funcs bochs_connector_connector_funcs = {
120 .dpms = drm_helper_connector_dpms,
121 .fill_modes = drm_helper_probe_single_connector_modes,
122 .destroy = drm_connector_cleanup,
123 .reset = drm_atomic_helper_connector_reset,
124 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
125 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
128 static void bochs_connector_init(struct drm_device *dev)
130 struct bochs_device *bochs = dev->dev_private;
131 struct drm_connector *connector = &bochs->connector;
133 drm_connector_init(dev, connector, &bochs_connector_connector_funcs,
134 DRM_MODE_CONNECTOR_VIRTUAL);
135 drm_connector_helper_add(connector,
136 &bochs_connector_connector_helper_funcs);
137 drm_connector_register(connector);
139 bochs_hw_load_edid(bochs);
140 if (bochs->edid) {
141 DRM_INFO("Found EDID data blob.\n");
142 drm_connector_attach_edid_property(connector);
143 drm_connector_update_edid_property(connector, bochs->edid);
147 static struct drm_framebuffer *
148 bochs_gem_fb_create(struct drm_device *dev, struct drm_file *file,
149 const struct drm_mode_fb_cmd2 *mode_cmd)
151 if (mode_cmd->pixel_format != DRM_FORMAT_XRGB8888 &&
152 mode_cmd->pixel_format != DRM_FORMAT_BGRX8888)
153 return ERR_PTR(-EINVAL);
155 return drm_gem_fb_create(dev, file, mode_cmd);
158 const struct drm_mode_config_funcs bochs_mode_funcs = {
159 .fb_create = bochs_gem_fb_create,
160 .atomic_check = drm_atomic_helper_check,
161 .atomic_commit = drm_atomic_helper_commit,
164 int bochs_kms_init(struct bochs_device *bochs)
166 drm_mode_config_init(bochs->dev);
168 bochs->dev->mode_config.max_width = 8192;
169 bochs->dev->mode_config.max_height = 8192;
171 bochs->dev->mode_config.fb_base = bochs->fb_base;
172 bochs->dev->mode_config.preferred_depth = 24;
173 bochs->dev->mode_config.prefer_shadow = 0;
174 bochs->dev->mode_config.prefer_shadow_fbdev = 1;
175 bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true;
177 bochs->dev->mode_config.funcs = &bochs_mode_funcs;
179 bochs_connector_init(bochs->dev);
180 drm_simple_display_pipe_init(bochs->dev,
181 &bochs->pipe,
182 &bochs_pipe_funcs,
183 bochs_formats,
184 ARRAY_SIZE(bochs_formats),
185 NULL,
186 &bochs->connector);
188 drm_mode_config_reset(bochs->dev);
190 return 0;
193 void bochs_kms_fini(struct bochs_device *bochs)
195 drm_atomic_helper_shutdown(bochs->dev);
196 drm_mode_config_cleanup(bochs->dev);