/*
*/
/*
* Copyright (c) 2006-2009 Red Hat Inc.
* Copyright (c) 2006-2008, 2013, Intel Corporation
* Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
*
* DRM framebuffer helper functions
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
* Authors:
* Dave Airlie <airlied@linux.ie>
* Jesse Barnes <jesse.barnes@intel.com>
*/
#include "drmP.h"
#include "drm_crtc.h"
#include "drm_fb_helper.h"
#include "drm_crtc_helper.h"
/**
* DOC: fbdev helpers
*
* The fb helper functions are useful to provide an fbdev on top of a drm kernel
* mode setting driver. They can be used mostly independantely from the crtc
* helper functions used by many drivers to implement the kernel mode setting
* interfaces.
*
* Initialization is done as a three-step process with drm_fb_helper_init(),
* drm_fb_helper_single_add_all_connectors() and drm_fb_helper_initial_config().
* Drivers with fancier requirements than the default beheviour can override the
* second step with their own code. Teardown is done with drm_fb_helper_fini().
*
* At runtime drivers should restore the fbdev console by calling
* drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
* should also notify the fb helper code from updates to the output
* configuration by calling drm_fb_helper_hotplug_event(). For easier
* integration with the output polling code in drm_crtc_helper.c the modeset
* code proves a ->output_poll_changed callback.
*
* All other functions exported by the fb helper library can be used to
* implement the fbdev driver interface by the driver.
*/
/* simple single crtc case helper function
* drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
* emulation helper
* @fb_helper: fbdev initialized with drm_fb_helper_init
*
* This functions adds all the available connectors for use with the given
* fb_helper. This is a separate step to allow drivers to freely assign
* connectors to the fbdev, e.g. if some are reserved for special purposes or
* not adequate to be used for the fbcon.
*
* Since this is part of the initial setup before the fbdev is published, no
* locking is required.
*/
{
int i;
if (!fb_helper_connector)
goto fail;
}
return 0;
fail:
for (i = 0; i < fb_helper->connector_count; i++) {
}
fb_helper->connector_count = 0;
return -ENOMEM;
}
{
int i;
for (i = 0; i < fb_helper->connector_count; i++) {
cmdline_mode->specified = true;
cmdline_mode->refresh_specified = true;
cmdline_mode->bpp_specified = true;
}
return 0;
}
{
int i;
return;
for (i = 0; i < crtc->gamma_size; i++)
}
{
return;
}
/* Find the real fb for a given fb helper CRTC */
{
struct drm_crtc *c;
return c->fb;
}
return NULL;
}
{
bool error = false;
int i;
return error;
for (i = 0; i < fb_helper->crtc_count; i++) {
int ret;
if (ret)
error = true;
}
if (ret)
error = true;
}
return error;
}
bool drm_fb_helper_force_kernel_mode(void)
{
if (list_empty(&kernel_fb_helper_list))
return false;
continue;
if (ret)
error = true;
}
return error;
}
{
crtcs_bound++;
bound++;
}
if (bound < crtcs_bound)
return false;
return true;
}
/* maximum connectors per crtcs in the mode set */
{
int i;
kfree(helper->connector_info, dev->mode_config.num_connector * sizeof(struct drm_fb_helper_connector *));
for (i = 0; i < helper->crtc_count; i++) {
kfree(helper->crtc_info[i].mode_set.connectors, INTELFB_CONN_LIMIT * sizeof(struct drm_connector *));
}
}
struct drm_fb_helper *fb_helper,
int crtc_count, int max_conn_count)
{
int i;
return -ENOMEM;
fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
if (!fb_helper->connector_info) {
return -ENOMEM;
}
fb_helper->connector_count = 0;
for (i = 0; i < crtc_count; i++) {
sizeof(struct drm_connector *),
goto out_free;
}
i = 0;
i++;
}
return 0;
return -ENOMEM;
}
{
if (list_empty(&kernel_fb_helper_list)) {
DRM_INFO("drm: unregistered panic notifier");
}
}
}
int preferred_bpp)
{
int ret = 0;
int crtc_count = 0;
int i;
int gamma_size = 0;
/* if driver picks 8 or 16 by default use that
for (i = 0; i < fb_helper->connector_count; i++) {
if (cmdline_mode->bpp_specified) {
switch (cmdline_mode->bpp) {
case 8:
break;
case 15:
break;
case 16:
break;
case 24:
break;
case 32:
break;
}
break;
}
}
crtc_count = 0;
for (i = 0; i < fb_helper->crtc_count; i++) {
if (desired_mode) {
if (gamma_size == 0)
crtc_count++;
}
}
/* hmm everyone went away - assume VGA cable just fell out
and will come back later. */
DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
}
/* push down into drivers */
if (ret < 0)
return ret;
/*
* Set the fb pointer - usually drm_setup_crtcs does this for hotplug
* events, but at init time drm_setup_crtcs needs to be called before
* the fb is allocated (since we need to figure out the desired size of
* the fb before we can allocate it ...). Hence we need to fix things up
* here again.
*/
for (i = 0; i < fb_helper->crtc_count; i++)
/* Switch back to kernel console on panic */
/* multi card linked list maybe */
if (list_empty(&kernel_fb_helper_list)) {
DRM_INFO("registered panic notifier");
}
return 0;
}
{
int count = 0;
int i;
for (i = 0; i < fb_helper->connector_count; i++) {
}
return count;
}
static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
{
continue;
return mode;
}
return NULL;
}
{
return cmdline_mode->specified;
}
static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
/* LINTED E_FUNC_ARG_UNUSED */
{
if (cmdline_mode->specified == false)
return mode;
/* attempt to find a matching mode in the list of modes
* we have gotten so far, if not add a CVT mode that conforms
*/
goto create_mode;
continue;
if (cmdline_mode->refresh_specified) {
continue;
}
if (cmdline_mode->interlace) {
continue;
}
return mode;
}
if (mode)
return mode;
}
{
bool enable;
if (strict)
else
return enable;
}
bool *enabled)
{
bool any_enabled = false;
int i = 0;
for (i = 0; i < fb_helper->connector_count; i++) {
any_enabled |= enabled[i];
}
if (any_enabled)
return;
for (i = 0; i < fb_helper->connector_count; i++) {
}
}
struct drm_display_mode **modes,
{
int count, i, j;
bool can_clone = false;
/* only contemplate cloning in the single crtc case */
return false;
count = 0;
for (i = 0; i < fb_helper->connector_count; i++) {
if (enabled[i])
count++;
}
/* only contemplate cloning if more than one connector is enabled */
if (count <= 1)
return false;
/* check the command line or if nothing common pick 1024x768 */
can_clone = true;
for (i = 0; i < fb_helper->connector_count; i++) {
if (!enabled[i])
continue;
if (!modes[i]) {
can_clone = false;
break;
}
for (j = 0; j < i; j++) {
if (!enabled[j])
continue;
can_clone = false;
}
}
if (can_clone) {
DRM_DEBUG_KMS("can clone using command line\n");
return true;
}
/* try and find a 1024x768 mode on each connector */
can_clone = true;
for (i = 0; i < fb_helper->connector_count; i++) {
if (!enabled[i])
continue;
}
if (!modes[i])
can_clone = false;
}
if (can_clone) {
DRM_DEBUG_KMS("can clone using 1024x768\n");
return true;
}
DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
return false;
}
struct drm_display_mode **modes,
{
int i;
for (i = 0; i < fb_helper->connector_count; i++) {
if (enabled[i] == false)
continue;
DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
/* got for command line mode first */
if (!modes[i]) {
DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
}
/* No preferred modes, pick one off the list */
/* LINTED */
{ if (1) break; }
}
"none");
}
return true;
}
struct drm_fb_helper_crtc **best_crtcs,
struct drm_display_mode **modes,
{
int c, o;
if (n == fb_helper->connector_count)
return 0;
ASSERT(n <= num_connector);
best_crtcs[n] = NULL;
return best_score;
if (!crtcs)
return best_score;
my_score = 1;
my_score++;
my_score++;
my_score++;
if (!encoder)
goto out;
/* select a crtc for this connector and then attempt to configure
remaining connectors */
for (c = 0; c < fb_helper->crtc_count; c++) {
continue;
for (o = 0; o < n; o++)
if (best_crtcs[o] == crtc)
break;
if (o < n) {
/* ignore cloning unless only a single crtc */
continue;
continue;
}
if (score > best_score) {
best_score = score;
sizeof(struct drm_fb_helper_crtc *));
}
}
out:
return best_score;
}
{
bool *enabled;
DRM_DEBUG_KMS("\n");
DRM_ERROR("Memory allocation failed for crtcs\n");
return;
}
DRM_ERROR("Memory allocation failed for modes\n");
goto errout1;
}
sizeof(bool), GFP_KERNEL)) == NULL) {
DRM_ERROR("Memory allocation failed for enabled\n");
goto errout2;
}
if (!drm_target_cloned(fb_helper,
DRM_ERROR("Unable to find initial modes\n");
DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
}
/* need to set the modesets up here for use later */
/* fill out the connector<->crtc mappings into the modesets */
for (i = 0; i < fb_helper->crtc_count; i++) {
modeset->num_connectors = 0;
}
for (i = 0; i < fb_helper->connector_count; i++) {
DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
}
}
/* Clear out any old modes if there are no more connected outputs. */
for (i = 0; i < fb_helper->crtc_count; i++) {
if (modeset->num_connectors == 0) {
}
}
}
/**
* drm_helper_initial_config - setup a sane initial connector configuration
* @dev: DRM device
*
*
* Scan the CRTCs and connectors and try to put together an initial setup.
* At the moment, this is a cloned configuration across all heads with
* a new framebuffer object as the backing store.
*
* Note that this also registers the fbdev and so allows userspace to call into
* the driver through the fbdev interfaces.
*
* This function will call down into the ->fb_probe callback to let
* the driver allocate and initialize the fbdev info structure and the drm
* framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
* drm_fb_helper_fill_fix() are provided as helpers to setup simple default
* values for the fbdev info structure.
*
* RETURNS:
* Zero if everything went ok, nonzero otherwise.
*/
{
int count = 0;
/*
* we shouldn't end up with no modes here.
*/
if (count == 0) {
DRM_INFO("No connectors reported connected with modes");
}
}
/**
* drm_fb_helper_hotplug_event - respond to a hotplug notification by
* probing all the outputs attached to the fb.
* @fb_helper: the drm_fb_helper
*
* Scan the connectors attached to the fb_helper and try to put together a
* setup after *notification of a change in output configuration.
*
* modeset configuration. Must be run from process context (which usually means
* either the output polling work or a work item launched from the driver's
* hotplug interrupt).
*
* Scan the connectors attached to the fb_helper and try to put together a
* setup after *notification of a change in output configuration.
*
* RETURNS:
* 0 on success and a non-zero error code otherwise.
*/
{
return 0;
if (!drm_fb_helper_is_bound(fb_helper)) {
fb_helper->delayed_hotplug = true;
return 0;
}
DRM_DEBUG_KMS("\n");
}
{
bool ret = 0;
if (mode == 0) {
if (ret == true)
DRM_ERROR("Failed to restore crtc configuration\n");
}
if (mode == 1)
DRM_DEBUG_KMS("do nothing in entervt");
return ret;
}
NULL, /* blt */
NULL, /* copy */
NULL, /* clear */
drm_gfxp_setmode, /* setmode */
};
{
}
{
return size;
}