]> Git Repo - linux.git/blob - drivers/gpu/drm/bochs/bochs_kms.c
Merge tag 'kernel.sys.v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner...
[linux.git] / drivers / gpu / drm / bochs / bochs_kms.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  */
4
5 #include <linux/moduleparam.h>
6
7 #include <drm/drm_atomic_helper.h>
8 #include <drm/drm_gem_framebuffer_helper.h>
9 #include <drm/drm_probe_helper.h>
10
11 #include "bochs.h"
12
13 static int defx = 1024;
14 static int defy = 768;
15
16 module_param(defx, int, 0444);
17 module_param(defy, int, 0444);
18 MODULE_PARM_DESC(defx, "default x resolution");
19 MODULE_PARM_DESC(defy, "default y resolution");
20
21 /* ---------------------------------------------------------------------- */
22
23 static const uint32_t bochs_formats[] = {
24         DRM_FORMAT_XRGB8888,
25         DRM_FORMAT_BGRX8888,
26 };
27
28 static void bochs_plane_update(struct bochs_device *bochs,
29                                struct drm_plane_state *state)
30 {
31         struct drm_gem_vram_object *gbo;
32         s64 gpu_addr;
33
34         if (!state->fb || !bochs->stride)
35                 return;
36
37         gbo = drm_gem_vram_of_gem(state->fb->obj[0]);
38         gpu_addr = drm_gem_vram_offset(gbo);
39         if (WARN_ON_ONCE(gpu_addr < 0))
40                 return; /* Bug: we didn't pin the BO to VRAM in prepare_fb. */
41
42         bochs_hw_setbase(bochs,
43                          state->crtc_x,
44                          state->crtc_y,
45                          state->fb->pitches[0],
46                          state->fb->offsets[0] + gpu_addr);
47         bochs_hw_setformat(bochs, state->fb->format);
48 }
49
50 static void bochs_pipe_enable(struct drm_simple_display_pipe *pipe,
51                               struct drm_crtc_state *crtc_state,
52                               struct drm_plane_state *plane_state)
53 {
54         struct bochs_device *bochs = pipe->crtc.dev->dev_private;
55
56         bochs_hw_setmode(bochs, &crtc_state->mode);
57         bochs_plane_update(bochs, plane_state);
58 }
59
60 static void bochs_pipe_disable(struct drm_simple_display_pipe *pipe)
61 {
62         struct bochs_device *bochs = pipe->crtc.dev->dev_private;
63
64         bochs_hw_blank(bochs, true);
65 }
66
67 static void bochs_pipe_update(struct drm_simple_display_pipe *pipe,
68                               struct drm_plane_state *old_state)
69 {
70         struct bochs_device *bochs = pipe->crtc.dev->dev_private;
71
72         bochs_plane_update(bochs, pipe->plane.state);
73 }
74
75 static const struct drm_simple_display_pipe_funcs bochs_pipe_funcs = {
76         .enable     = bochs_pipe_enable,
77         .disable    = bochs_pipe_disable,
78         .update     = bochs_pipe_update,
79         .prepare_fb = drm_gem_vram_simple_display_pipe_prepare_fb,
80         .cleanup_fb = drm_gem_vram_simple_display_pipe_cleanup_fb,
81 };
82
83 static int bochs_connector_get_modes(struct drm_connector *connector)
84 {
85         struct bochs_device *bochs =
86                 container_of(connector, struct bochs_device, connector);
87         int count = 0;
88
89         if (bochs->edid)
90                 count = drm_add_edid_modes(connector, bochs->edid);
91
92         if (!count) {
93                 count = drm_add_modes_noedid(connector, 8192, 8192);
94                 drm_set_preferred_mode(connector, defx, defy);
95         }
96         return count;
97 }
98
99 static const struct drm_connector_helper_funcs bochs_connector_connector_helper_funcs = {
100         .get_modes = bochs_connector_get_modes,
101 };
102
103 static const struct drm_connector_funcs bochs_connector_connector_funcs = {
104         .fill_modes = drm_helper_probe_single_connector_modes,
105         .destroy = drm_connector_cleanup,
106         .reset = drm_atomic_helper_connector_reset,
107         .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
108         .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
109 };
110
111 static void bochs_connector_init(struct drm_device *dev)
112 {
113         struct bochs_device *bochs = dev->dev_private;
114         struct drm_connector *connector = &bochs->connector;
115
116         drm_connector_init(dev, connector, &bochs_connector_connector_funcs,
117                            DRM_MODE_CONNECTOR_VIRTUAL);
118         drm_connector_helper_add(connector,
119                                  &bochs_connector_connector_helper_funcs);
120
121         bochs_hw_load_edid(bochs);
122         if (bochs->edid) {
123                 DRM_INFO("Found EDID data blob.\n");
124                 drm_connector_attach_edid_property(connector);
125                 drm_connector_update_edid_property(connector, bochs->edid);
126         }
127 }
128
129 static struct drm_framebuffer *
130 bochs_gem_fb_create(struct drm_device *dev, struct drm_file *file,
131                     const struct drm_mode_fb_cmd2 *mode_cmd)
132 {
133         if (mode_cmd->pixel_format != DRM_FORMAT_XRGB8888 &&
134             mode_cmd->pixel_format != DRM_FORMAT_BGRX8888)
135                 return ERR_PTR(-EINVAL);
136
137         return drm_gem_fb_create(dev, file, mode_cmd);
138 }
139
140 const struct drm_mode_config_funcs bochs_mode_funcs = {
141         .fb_create = bochs_gem_fb_create,
142         .mode_valid = drm_vram_helper_mode_valid,
143         .atomic_check = drm_atomic_helper_check,
144         .atomic_commit = drm_atomic_helper_commit,
145 };
146
147 int bochs_kms_init(struct bochs_device *bochs)
148 {
149         int ret;
150
151         ret = drmm_mode_config_init(bochs->dev);
152         if (ret)
153                 return ret;
154
155         bochs->dev->mode_config.max_width = 8192;
156         bochs->dev->mode_config.max_height = 8192;
157
158         bochs->dev->mode_config.fb_base = bochs->fb_base;
159         bochs->dev->mode_config.preferred_depth = 24;
160         bochs->dev->mode_config.prefer_shadow = 0;
161         bochs->dev->mode_config.prefer_shadow_fbdev = 1;
162         bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true;
163
164         bochs->dev->mode_config.funcs = &bochs_mode_funcs;
165
166         bochs_connector_init(bochs->dev);
167         drm_simple_display_pipe_init(bochs->dev,
168                                      &bochs->pipe,
169                                      &bochs_pipe_funcs,
170                                      bochs_formats,
171                                      ARRAY_SIZE(bochs_formats),
172                                      NULL,
173                                      &bochs->connector);
174
175         drm_mode_config_reset(bochs->dev);
176
177         return 0;
178 }
This page took 0.044322 seconds and 4 git commands to generate.