Linux Audio

Check our new training course

Loading...
v6.13.7
  1/*
  2 * Copyright (c) 2016 Intel Corporation
  3 *
  4 * Permission to use, copy, modify, distribute, and sell this software and its
  5 * documentation for any purpose is hereby granted without fee, provided that
  6 * the above copyright notice appear in all copies and that both that copyright
  7 * notice and this permission notice appear in supporting documentation, and
  8 * that the name of the copyright holders not be used in advertising or
  9 * publicity pertaining to distribution of the software without specific,
 10 * written prior permission.  The copyright holders make no representations
 11 * about the suitability of this software for any purpose.  It is provided "as
 12 * is" without express or implied warranty.
 13 *
 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 20 * OF THIS SOFTWARE.
 21 */
 22
 23#include <drm/drm_atomic_helper.h>
 24#include <drm/drm_client_event.h>
 25#include <drm/drm_fourcc.h>
 26#include <drm/drm_framebuffer.h>
 27#include <drm/drm_modeset_helper.h>
 28#include <drm/drm_plane_helper.h>
 29#include <drm/drm_print.h>
 30#include <drm/drm_probe_helper.h>
 31
 32/**
 33 * DOC: aux kms helpers
 34 *
 35 * This helper library contains various one-off functions which don't really fit
 36 * anywhere else in the DRM modeset helper library.
 37 */
 38
 39/**
 40 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
 41 * 						connector list
 42 * @dev: drm device to operate on
 43 *
 44 * Some userspace presumes that the first connected connector is the main
 45 * display, where it's supposed to display e.g. the login screen. For
 46 * laptops, this should be the main panel. Use this function to sort all
 47 * (eDP/LVDS/DSI) panels to the front of the connector list, instead of
 48 * painstakingly trying to initialize them in the right order.
 49 */
 50void drm_helper_move_panel_connectors_to_head(struct drm_device *dev)
 51{
 52	struct drm_connector *connector, *tmp;
 53	struct list_head panel_list;
 54
 55	INIT_LIST_HEAD(&panel_list);
 56
 57	spin_lock_irq(&dev->mode_config.connector_list_lock);
 58	list_for_each_entry_safe(connector, tmp,
 59				 &dev->mode_config.connector_list, head) {
 60		if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
 61		    connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
 62		    connector->connector_type == DRM_MODE_CONNECTOR_DSI)
 63			list_move_tail(&connector->head, &panel_list);
 64	}
 65
 66	list_splice(&panel_list, &dev->mode_config.connector_list);
 67	spin_unlock_irq(&dev->mode_config.connector_list_lock);
 68}
 69EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
 70
 71/**
 72 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
 73 * @dev: DRM device
 74 * @fb: drm_framebuffer object to fill out
 75 * @mode_cmd: metadata from the userspace fb creation request
 76 *
 77 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
 78 * metadata fields.
 79 */
 80void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
 81				    struct drm_framebuffer *fb,
 82				    const struct drm_mode_fb_cmd2 *mode_cmd)
 83{
 
 84	int i;
 85
 86	fb->dev = dev;
 87	fb->format = drm_get_format_info(dev, mode_cmd);
 
 
 
 
 
 
 
 
 
 
 
 
 
 88	fb->width = mode_cmd->width;
 89	fb->height = mode_cmd->height;
 90	for (i = 0; i < 4; i++) {
 91		fb->pitches[i] = mode_cmd->pitches[i];
 92		fb->offsets[i] = mode_cmd->offsets[i];
 93	}
 94	fb->modifier = mode_cmd->modifier[0];
 
 95	fb->flags = mode_cmd->flags;
 96}
 97EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
 98
 99/*
100 * This is the minimal list of formats that seem to be safe for modeset use
101 * with all current DRM drivers.  Most hardware can actually support more
102 * formats than this and drivers may specify a more accurate list when
103 * creating the primary plane.
 
104 */
105static const uint32_t safe_modeset_formats[] = {
106	DRM_FORMAT_XRGB8888,
107	DRM_FORMAT_ARGB8888,
108};
109
110static const struct drm_plane_funcs primary_plane_funcs = {
111	DRM_PLANE_NON_ATOMIC_FUNCS,
112};
113
114/**
115 * drm_crtc_init - Legacy CRTC initialization function
116 * @dev: DRM device
117 * @crtc: CRTC object to init
118 * @funcs: callbacks for the new CRTC
119 *
120 * Initialize a CRTC object with a default helper-provided primary plane and no
121 * cursor plane.
122 *
123 * Note that we make some assumptions about hardware limitations that may not be
124 * true for all hardware:
125 *
126 * 1. Primary plane cannot be repositioned.
127 * 2. Primary plane cannot be scaled.
128 * 3. Primary plane must cover the entire CRTC.
129 * 4. Subpixel positioning is not supported.
130 * 5. The primary plane must always be on if the CRTC is enabled.
131 *
132 * This is purely a backwards compatibility helper for old drivers. Drivers
133 * should instead implement their own primary plane. Atomic drivers must do so.
134 * Drivers with the above hardware restriction can look into using &struct
135 * drm_simple_display_pipe, which encapsulates the above limitations into a nice
136 * interface.
137 *
138 * Returns:
139 * Zero on success, error code on failure.
140 */
141int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
142		  const struct drm_crtc_funcs *funcs)
143{
144	struct drm_plane *primary;
145	int ret;
146
147	/* possible_crtc's will be filled in later by crtc_init */
148	primary = __drm_universal_plane_alloc(dev, sizeof(*primary), 0, 0,
149					      &primary_plane_funcs,
150					      safe_modeset_formats,
151					      ARRAY_SIZE(safe_modeset_formats),
152					      NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
153	if (IS_ERR(primary))
154		return PTR_ERR(primary);
155
156	/*
157	 * Remove the format_default field from drm_plane when dropping
158	 * this helper.
159	 */
160	primary->format_default = true;
161
162	ret = drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs, NULL);
163	if (ret)
164		goto err_drm_plane_cleanup;
165
166	return 0;
167
168err_drm_plane_cleanup:
169	drm_plane_cleanup(primary);
170	kfree(primary);
171	return ret;
172}
173EXPORT_SYMBOL(drm_crtc_init);
174
175/**
176 * drm_mode_config_helper_suspend - Modeset suspend helper
177 * @dev: DRM device
178 *
179 * This helper function takes care of suspending the modeset side. It disables
180 * output polling if initialized, suspends fbdev if used and finally calls
181 * drm_atomic_helper_suspend().
182 * If suspending fails, fbdev and polling is re-enabled.
183 *
184 * Returns:
185 * Zero on success, negative error code on error.
186 *
187 * See also:
188 * drm_kms_helper_poll_disable() and drm_client_dev_suspend().
189 */
190int drm_mode_config_helper_suspend(struct drm_device *dev)
191{
192	struct drm_atomic_state *state;
193
194	if (!dev)
195		return 0;
196	/*
197	 * Don't disable polling if it was never initialized
198	 */
199	if (dev->mode_config.poll_enabled)
200		drm_kms_helper_poll_disable(dev);
201
202	drm_client_dev_suspend(dev, false);
203	state = drm_atomic_helper_suspend(dev);
204	if (IS_ERR(state)) {
205		drm_client_dev_resume(dev, false);
206
207		/*
208		 * Don't enable polling if it was never initialized
209		 */
210		if (dev->mode_config.poll_enabled)
211			drm_kms_helper_poll_enable(dev);
212
213		return PTR_ERR(state);
214	}
215
216	dev->mode_config.suspend_state = state;
217
218	return 0;
219}
220EXPORT_SYMBOL(drm_mode_config_helper_suspend);
221
222/**
223 * drm_mode_config_helper_resume - Modeset resume helper
224 * @dev: DRM device
 
 
225 *
226 * This helper function takes care of resuming the modeset side. It calls
227 * drm_atomic_helper_resume(), resumes fbdev if used and enables output polling
228 * if initiaized.
229 *
230 * Returns:
231 * Zero on success, negative error code on error.
232 *
233 * See also:
234 * drm_client_dev_resume() and drm_kms_helper_poll_enable().
235 */
236int drm_mode_config_helper_resume(struct drm_device *dev)
 
237{
238	int ret;
239
240	if (!dev)
241		return 0;
242
243	if (WARN_ON(!dev->mode_config.suspend_state))
244		return -EINVAL;
245
246	ret = drm_atomic_helper_resume(dev, dev->mode_config.suspend_state);
247	if (ret)
248		DRM_ERROR("Failed to resume (%d)\n", ret);
249	dev->mode_config.suspend_state = NULL;
250
251	drm_client_dev_resume(dev, false);
252
253	/*
254	 * Don't enable polling if it is not initialized
255	 */
256	if (dev->mode_config.poll_enabled)
257		drm_kms_helper_poll_enable(dev);
258
259	return ret;
 
 
260}
261EXPORT_SYMBOL(drm_mode_config_helper_resume);
v4.10.11
  1/*
  2 * Copyright (c) 2016 Intel Corporation
  3 *
  4 * Permission to use, copy, modify, distribute, and sell this software and its
  5 * documentation for any purpose is hereby granted without fee, provided that
  6 * the above copyright notice appear in all copies and that both that copyright
  7 * notice and this permission notice appear in supporting documentation, and
  8 * that the name of the copyright holders not be used in advertising or
  9 * publicity pertaining to distribution of the software without specific,
 10 * written prior permission.  The copyright holders make no representations
 11 * about the suitability of this software for any purpose.  It is provided "as
 12 * is" without express or implied warranty.
 13 *
 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 20 * OF THIS SOFTWARE.
 21 */
 22
 
 
 
 
 23#include <drm/drm_modeset_helper.h>
 24#include <drm/drm_plane_helper.h>
 
 
 25
 26/**
 27 * DOC: aux kms helpers
 28 *
 29 * This helper library contains various one-off functions which don't really fit
 30 * anywhere else in the DRM modeset helper library.
 31 */
 32
 33/**
 34 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
 35 * 						connector list
 36 * @dev: drm device to operate on
 37 *
 38 * Some userspace presumes that the first connected connector is the main
 39 * display, where it's supposed to display e.g. the login screen. For
 40 * laptops, this should be the main panel. Use this function to sort all
 41 * (eDP/LVDS/DSI) panels to the front of the connector list, instead of
 42 * painstakingly trying to initialize them in the right order.
 43 */
 44void drm_helper_move_panel_connectors_to_head(struct drm_device *dev)
 45{
 46	struct drm_connector *connector, *tmp;
 47	struct list_head panel_list;
 48
 49	INIT_LIST_HEAD(&panel_list);
 50
 
 51	list_for_each_entry_safe(connector, tmp,
 52				 &dev->mode_config.connector_list, head) {
 53		if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
 54		    connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
 55		    connector->connector_type == DRM_MODE_CONNECTOR_DSI)
 56			list_move_tail(&connector->head, &panel_list);
 57	}
 58
 59	list_splice(&panel_list, &dev->mode_config.connector_list);
 
 60}
 61EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
 62
 63/**
 64 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
 
 65 * @fb: drm_framebuffer object to fill out
 66 * @mode_cmd: metadata from the userspace fb creation request
 67 *
 68 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
 69 * metadata fields.
 70 */
 71void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 
 72				    const struct drm_mode_fb_cmd2 *mode_cmd)
 73{
 74	const struct drm_format_info *info;
 75	int i;
 76
 77	info = drm_format_info(mode_cmd->pixel_format);
 78	if (!info || !info->depth) {
 79		struct drm_format_name_buf format_name;
 80
 81		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
 82		              drm_get_format_name(mode_cmd->pixel_format,
 83		                                  &format_name));
 84
 85		fb->depth = 0;
 86		fb->bits_per_pixel = 0;
 87	} else {
 88		fb->depth = info->depth;
 89		fb->bits_per_pixel = info->cpp[0] * 8;
 90	}
 91
 92	fb->width = mode_cmd->width;
 93	fb->height = mode_cmd->height;
 94	for (i = 0; i < 4; i++) {
 95		fb->pitches[i] = mode_cmd->pitches[i];
 96		fb->offsets[i] = mode_cmd->offsets[i];
 97	}
 98	fb->modifier = mode_cmd->modifier[0];
 99	fb->pixel_format = mode_cmd->pixel_format;
100	fb->flags = mode_cmd->flags;
101}
102EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
103
104/*
105 * This is the minimal list of formats that seem to be safe for modeset use
106 * with all current DRM drivers.  Most hardware can actually support more
107 * formats than this and drivers may specify a more accurate list when
108 * creating the primary plane.  However drivers that still call
109 * drm_plane_init() will use this minimal format list as the default.
110 */
111static const uint32_t safe_modeset_formats[] = {
112	DRM_FORMAT_XRGB8888,
113	DRM_FORMAT_ARGB8888,
114};
115
116static struct drm_plane *create_primary_plane(struct drm_device *dev)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117{
118	struct drm_plane *primary;
119	int ret;
120
121	primary = kzalloc(sizeof(*primary), GFP_KERNEL);
122	if (primary == NULL) {
123		DRM_DEBUG_KMS("Failed to allocate primary plane\n");
124		return NULL;
125	}
 
 
 
126
127	/*
128	 * Remove the format_default field from drm_plane when dropping
129	 * this helper.
130	 */
131	primary->format_default = true;
132
133	/* possible_crtc's will be filled in later by crtc_init */
134	ret = drm_universal_plane_init(dev, primary, 0,
135				       &drm_primary_helper_funcs,
136				       safe_modeset_formats,
137				       ARRAY_SIZE(safe_modeset_formats),
138				       DRM_PLANE_TYPE_PRIMARY, NULL);
139	if (ret) {
140		kfree(primary);
141		primary = NULL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142	}
143
144	return primary;
 
 
145}
 
146
147/**
148 * drm_crtc_init - Legacy CRTC initialization function
149 * @dev: DRM device
150 * @crtc: CRTC object to init
151 * @funcs: callbacks for the new CRTC
152 *
153 * Initialize a CRTC object with a default helper-provided primary plane and no
154 * cursor plane.
 
155 *
156 * Returns:
157 * Zero on success, error code on failure.
 
 
 
158 */
159int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
160		  const struct drm_crtc_funcs *funcs)
161{
162	struct drm_plane *primary;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
164	primary = create_primary_plane(dev);
165	return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs,
166					 NULL);
167}
168EXPORT_SYMBOL(drm_crtc_init);