15718399fSFrançois Tigeot /* 25718399fSFrançois Tigeot * Copyright (c) 2006-2009 Red Hat Inc. 35718399fSFrançois Tigeot * Copyright (c) 2006-2008 Intel Corporation 45718399fSFrançois Tigeot * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 55718399fSFrançois Tigeot * 65718399fSFrançois Tigeot * DRM framebuffer helper functions 75718399fSFrançois Tigeot * 85718399fSFrançois Tigeot * Permission to use, copy, modify, distribute, and sell this software and its 95718399fSFrançois Tigeot * documentation for any purpose is hereby granted without fee, provided that 105718399fSFrançois Tigeot * the above copyright notice appear in all copies and that both that copyright 115718399fSFrançois Tigeot * notice and this permission notice appear in supporting documentation, and 125718399fSFrançois Tigeot * that the name of the copyright holders not be used in advertising or 135718399fSFrançois Tigeot * publicity pertaining to distribution of the software without specific, 145718399fSFrançois Tigeot * written prior permission. The copyright holders make no representations 155718399fSFrançois Tigeot * about the suitability of this software for any purpose. It is provided "as 165718399fSFrançois Tigeot * is" without express or implied warranty. 175718399fSFrançois Tigeot * 185718399fSFrançois Tigeot * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 195718399fSFrançois Tigeot * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 205718399fSFrançois Tigeot * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 215718399fSFrançois Tigeot * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 225718399fSFrançois Tigeot * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 235718399fSFrançois Tigeot * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 245718399fSFrançois Tigeot * OF THIS SOFTWARE. 255718399fSFrançois Tigeot * 265718399fSFrançois Tigeot * Authors: 275718399fSFrançois Tigeot * Dave Airlie <airlied@linux.ie> 285718399fSFrançois Tigeot * Jesse Barnes <jesse.barnes@intel.com> 295718399fSFrançois Tigeot * 305718399fSFrançois Tigeot * $FreeBSD: src/sys/dev/drm2/drm_fb_helper.c,v 1.1 2012/05/22 11:07:44 kib Exp $ 315718399fSFrançois Tigeot */ 325718399fSFrançois Tigeot 33*4a968d2aSFrançois Tigeot #include <linux/export.h> 3418e26a6dSFrançois Tigeot #include <drm/drmP.h> 3518e26a6dSFrançois Tigeot #include <drm/drm_crtc.h> 3618e26a6dSFrançois Tigeot #include <drm/drm_fb_helper.h> 3718e26a6dSFrançois Tigeot #include <drm/drm_crtc_helper.h> 385718399fSFrançois Tigeot 3928828b89SFrançois Tigeot static LINUX_LIST_HEAD(kernel_fb_helper_list); 405718399fSFrançois Tigeot 415718399fSFrançois Tigeot /* simple single crtc case helper function */ 425718399fSFrançois Tigeot int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) 435718399fSFrançois Tigeot { 445718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 455718399fSFrançois Tigeot struct drm_connector *connector; 465718399fSFrançois Tigeot 475718399fSFrançois Tigeot list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 485718399fSFrançois Tigeot struct drm_fb_helper_connector *fb_helper_connector; 495718399fSFrançois Tigeot 505718399fSFrançois Tigeot fb_helper_connector = kmalloc( 515718399fSFrançois Tigeot sizeof(struct drm_fb_helper_connector), DRM_MEM_KMS, 525718399fSFrançois Tigeot M_WAITOK | M_ZERO); 535718399fSFrançois Tigeot 545718399fSFrançois Tigeot fb_helper_connector->connector = connector; 555718399fSFrançois Tigeot fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector; 565718399fSFrançois Tigeot } 575718399fSFrançois Tigeot return 0; 585718399fSFrançois Tigeot } 595718399fSFrançois Tigeot 605718399fSFrançois Tigeot const char *fb_mode_option; 615718399fSFrançois Tigeot 625718399fSFrançois Tigeot static int 635718399fSFrançois Tigeot fb_get_options(const char *connector_name, char **option) 645718399fSFrançois Tigeot { 655718399fSFrançois Tigeot 665718399fSFrançois Tigeot return (1); 675718399fSFrançois Tigeot } 685718399fSFrançois Tigeot 695718399fSFrançois Tigeot static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper) 705718399fSFrançois Tigeot { 715718399fSFrançois Tigeot struct drm_fb_helper_connector *fb_helper_conn; 725718399fSFrançois Tigeot int i; 735718399fSFrançois Tigeot 745718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 75*4a968d2aSFrançois Tigeot struct drm_cmdline_mode *mode; 76*4a968d2aSFrançois Tigeot struct drm_connector *connector; 775718399fSFrançois Tigeot char *option = NULL; 785718399fSFrançois Tigeot 795718399fSFrançois Tigeot fb_helper_conn = fb_helper->connector_info[i]; 80*4a968d2aSFrançois Tigeot connector = fb_helper_conn->connector; 81*4a968d2aSFrançois Tigeot mode = &fb_helper_conn->cmdline_mode; 825718399fSFrançois Tigeot 835718399fSFrançois Tigeot /* do something on return - turn off connector maybe */ 84*4a968d2aSFrançois Tigeot if (fb_get_options(drm_get_connector_name(connector), &option)) 855718399fSFrançois Tigeot continue; 865718399fSFrançois Tigeot 87*4a968d2aSFrançois Tigeot if (drm_mode_parse_command_line_for_connector(option, 88*4a968d2aSFrançois Tigeot connector, 89*4a968d2aSFrançois Tigeot mode)) { 90*4a968d2aSFrançois Tigeot if (mode->force) { 91*4a968d2aSFrançois Tigeot const char *s; 92*4a968d2aSFrançois Tigeot switch (mode->force) { 93*4a968d2aSFrançois Tigeot case DRM_FORCE_OFF: 94*4a968d2aSFrançois Tigeot s = "OFF"; 95*4a968d2aSFrançois Tigeot break; 96*4a968d2aSFrançois Tigeot case DRM_FORCE_ON_DIGITAL: 97*4a968d2aSFrançois Tigeot s = "ON - dig"; 98*4a968d2aSFrançois Tigeot break; 99*4a968d2aSFrançois Tigeot default: 100*4a968d2aSFrançois Tigeot case DRM_FORCE_ON: 101*4a968d2aSFrançois Tigeot s = "ON"; 102*4a968d2aSFrançois Tigeot break; 103*4a968d2aSFrançois Tigeot } 104*4a968d2aSFrançois Tigeot 105*4a968d2aSFrançois Tigeot DRM_INFO("forcing %s connector %s\n", 106*4a968d2aSFrançois Tigeot drm_get_connector_name(connector), s); 107*4a968d2aSFrançois Tigeot connector->force = mode->force; 108*4a968d2aSFrançois Tigeot } 109*4a968d2aSFrançois Tigeot 110*4a968d2aSFrançois Tigeot DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", 111*4a968d2aSFrançois Tigeot drm_get_connector_name(connector), 112*4a968d2aSFrançois Tigeot mode->xres, mode->yres, 113*4a968d2aSFrançois Tigeot mode->refresh_specified ? mode->refresh : 60, 114*4a968d2aSFrançois Tigeot mode->rb ? " reduced blanking" : "", 115*4a968d2aSFrançois Tigeot mode->margins ? " with margins" : "", 116*4a968d2aSFrançois Tigeot mode->interlace ? " interlaced" : ""); 117*4a968d2aSFrançois Tigeot } 118*4a968d2aSFrançois Tigeot 1195718399fSFrançois Tigeot } 1205718399fSFrançois Tigeot return 0; 1215718399fSFrançois Tigeot } 1225718399fSFrançois Tigeot 1235718399fSFrançois Tigeot #if 0 1245718399fSFrançois Tigeot static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper) 1255718399fSFrançois Tigeot { 1265718399fSFrançois Tigeot uint16_t *r_base, *g_base, *b_base; 1275718399fSFrançois Tigeot int i; 1285718399fSFrançois Tigeot 1295718399fSFrançois Tigeot r_base = crtc->gamma_store; 1305718399fSFrançois Tigeot g_base = r_base + crtc->gamma_size; 1315718399fSFrançois Tigeot b_base = g_base + crtc->gamma_size; 1325718399fSFrançois Tigeot 1335718399fSFrançois Tigeot for (i = 0; i < crtc->gamma_size; i++) 1345718399fSFrançois Tigeot helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i); 1355718399fSFrançois Tigeot } 1365718399fSFrançois Tigeot 1375718399fSFrançois Tigeot static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc) 1385718399fSFrançois Tigeot { 1395718399fSFrançois Tigeot uint16_t *r_base, *g_base, *b_base; 1405718399fSFrançois Tigeot 1415718399fSFrançois Tigeot r_base = crtc->gamma_store; 1425718399fSFrançois Tigeot g_base = r_base + crtc->gamma_size; 1435718399fSFrançois Tigeot b_base = g_base + crtc->gamma_size; 1445718399fSFrançois Tigeot 1455718399fSFrançois Tigeot crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); 1465718399fSFrançois Tigeot } 1475718399fSFrançois Tigeot #endif 1485718399fSFrançois Tigeot 1495718399fSFrançois Tigeot #if 0 1505718399fSFrançois Tigeot int drm_fb_helper_debug_enter(struct fb_info *info) 1515718399fSFrançois Tigeot { 1525718399fSFrançois Tigeot struct drm_fb_helper *helper = info->par; 1535718399fSFrançois Tigeot struct drm_crtc_helper_funcs *funcs; 1545718399fSFrançois Tigeot int i; 1555718399fSFrançois Tigeot 1565718399fSFrançois Tigeot if (list_empty(&kernel_fb_helper_list)) 1575718399fSFrançois Tigeot return false; 1585718399fSFrançois Tigeot 1595718399fSFrançois Tigeot list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { 1605718399fSFrançois Tigeot for (i = 0; i < helper->crtc_count; i++) { 1615718399fSFrançois Tigeot struct drm_mode_set *mode_set = 1625718399fSFrançois Tigeot &helper->crtc_info[i].mode_set; 1635718399fSFrançois Tigeot 1645718399fSFrançois Tigeot if (!mode_set->crtc->enabled) 1655718399fSFrançois Tigeot continue; 1665718399fSFrançois Tigeot 1675718399fSFrançois Tigeot funcs = mode_set->crtc->helper_private; 1685718399fSFrançois Tigeot drm_fb_helper_save_lut_atomic(mode_set->crtc, helper); 1695718399fSFrançois Tigeot funcs->mode_set_base_atomic(mode_set->crtc, 1705718399fSFrançois Tigeot mode_set->fb, 1715718399fSFrançois Tigeot mode_set->x, 1725718399fSFrançois Tigeot mode_set->y, 1735718399fSFrançois Tigeot ENTER_ATOMIC_MODE_SET); 1745718399fSFrançois Tigeot } 1755718399fSFrançois Tigeot } 1765718399fSFrançois Tigeot 1775718399fSFrançois Tigeot return 0; 1785718399fSFrançois Tigeot } 1795718399fSFrançois Tigeot #endif 1805718399fSFrançois Tigeot 1815718399fSFrançois Tigeot #if 0 1825718399fSFrançois Tigeot /* Find the real fb for a given fb helper CRTC */ 1835718399fSFrançois Tigeot static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc) 1845718399fSFrançois Tigeot { 1855718399fSFrançois Tigeot struct drm_device *dev = crtc->dev; 1865718399fSFrançois Tigeot struct drm_crtc *c; 1875718399fSFrançois Tigeot 1885718399fSFrançois Tigeot list_for_each_entry(c, &dev->mode_config.crtc_list, head) { 1895718399fSFrançois Tigeot if (crtc->base.id == c->base.id) 1905718399fSFrançois Tigeot return c->fb; 1915718399fSFrançois Tigeot } 1925718399fSFrançois Tigeot 1935718399fSFrançois Tigeot return NULL; 1945718399fSFrançois Tigeot } 1955718399fSFrançois Tigeot #endif 1965718399fSFrançois Tigeot 1975718399fSFrançois Tigeot #if 0 1985718399fSFrançois Tigeot int drm_fb_helper_debug_leave(struct fb_info *info) 1995718399fSFrançois Tigeot { 2005718399fSFrançois Tigeot struct drm_fb_helper *helper = info->par; 2015718399fSFrançois Tigeot struct drm_crtc *crtc; 2025718399fSFrançois Tigeot struct drm_crtc_helper_funcs *funcs; 2035718399fSFrançois Tigeot struct drm_framebuffer *fb; 2045718399fSFrançois Tigeot int i; 2055718399fSFrançois Tigeot 2065718399fSFrançois Tigeot for (i = 0; i < helper->crtc_count; i++) { 2075718399fSFrançois Tigeot struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set; 2085718399fSFrançois Tigeot crtc = mode_set->crtc; 2095718399fSFrançois Tigeot funcs = crtc->helper_private; 2105718399fSFrançois Tigeot fb = drm_mode_config_fb(crtc); 2115718399fSFrançois Tigeot 2125718399fSFrançois Tigeot if (!crtc->enabled) 2135718399fSFrançois Tigeot continue; 2145718399fSFrançois Tigeot 2155718399fSFrançois Tigeot if (!fb) { 2165718399fSFrançois Tigeot DRM_ERROR("no fb to restore??\n"); 2175718399fSFrançois Tigeot continue; 2185718399fSFrançois Tigeot } 2195718399fSFrançois Tigeot 2205718399fSFrançois Tigeot drm_fb_helper_restore_lut_atomic(mode_set->crtc); 2215718399fSFrançois Tigeot funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x, 2225718399fSFrançois Tigeot crtc->y, LEAVE_ATOMIC_MODE_SET); 2235718399fSFrançois Tigeot } 2245718399fSFrançois Tigeot 2255718399fSFrançois Tigeot return 0; 2265718399fSFrançois Tigeot } 2275718399fSFrançois Tigeot #endif 2285718399fSFrançois Tigeot 2295718399fSFrançois Tigeot bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper) 2305718399fSFrançois Tigeot { 2315718399fSFrançois Tigeot bool error = false; 2325718399fSFrançois Tigeot int i, ret; 2335718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 2345718399fSFrançois Tigeot struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set; 2355718399fSFrançois Tigeot ret = drm_crtc_helper_set_config(mode_set); 2365718399fSFrançois Tigeot if (ret) 2375718399fSFrançois Tigeot error = true; 2385718399fSFrançois Tigeot } 2395718399fSFrançois Tigeot return error; 2405718399fSFrançois Tigeot } 2415718399fSFrançois Tigeot 2425718399fSFrançois Tigeot #if 0 2435718399fSFrançois Tigeot bool drm_fb_helper_force_kernel_mode(void) 2445718399fSFrançois Tigeot { 2455718399fSFrançois Tigeot bool ret, error = false; 2465718399fSFrançois Tigeot struct drm_fb_helper *helper; 2475718399fSFrançois Tigeot 2485718399fSFrançois Tigeot if (list_empty(&kernel_fb_helper_list)) 2495718399fSFrançois Tigeot return false; 2505718399fSFrançois Tigeot 2515718399fSFrançois Tigeot list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { 2525718399fSFrançois Tigeot if (helper->dev->switch_power_state == DRM_SWITCH_POWER_OFF) 2535718399fSFrançois Tigeot continue; 2545718399fSFrançois Tigeot 2555718399fSFrançois Tigeot ret = drm_fb_helper_restore_fbdev_mode(helper); 2565718399fSFrançois Tigeot if (ret) 2575718399fSFrançois Tigeot error = true; 2585718399fSFrançois Tigeot } 2595718399fSFrançois Tigeot return error; 2605718399fSFrançois Tigeot } 2615718399fSFrançois Tigeot #endif 2625718399fSFrançois Tigeot 2635718399fSFrançois Tigeot #if 0 2645718399fSFrançois Tigeot int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed, 2655718399fSFrançois Tigeot void *panic_str) 2665718399fSFrançois Tigeot { 2675718399fSFrançois Tigeot printf("panic occurred, switching back to text console\n"); 2685718399fSFrançois Tigeot return drm_fb_helper_force_kernel_mode(); 2695718399fSFrançois Tigeot return 0; 2705718399fSFrançois Tigeot } 2715718399fSFrançois Tigeot 2725718399fSFrançois Tigeot static struct notifier_block paniced = { 2735718399fSFrançois Tigeot .notifier_call = drm_fb_helper_panic, 2745718399fSFrançois Tigeot }; 2755718399fSFrançois Tigeot 2765718399fSFrançois Tigeot /** 2775718399fSFrançois Tigeot * drm_fb_helper_restore - restore the framebuffer console (kernel) config 2785718399fSFrançois Tigeot * 2795718399fSFrançois Tigeot * Restore's the kernel's fbcon mode, used for lastclose & panic paths. 2805718399fSFrançois Tigeot */ 2815718399fSFrançois Tigeot void drm_fb_helper_restore(void) 2825718399fSFrançois Tigeot { 2835718399fSFrançois Tigeot bool ret; 2845718399fSFrançois Tigeot ret = drm_fb_helper_force_kernel_mode(); 2855718399fSFrançois Tigeot if (ret == true) 2865718399fSFrançois Tigeot DRM_ERROR("Failed to restore crtc configuration\n"); 2875718399fSFrançois Tigeot } 2885718399fSFrançois Tigeot 2895718399fSFrançois Tigeot #ifdef CONFIG_MAGIC_SYSRQ 2905718399fSFrançois Tigeot static void drm_fb_helper_restore_work_fn(struct work_struct *ignored) 2915718399fSFrançois Tigeot { 2925718399fSFrançois Tigeot drm_fb_helper_restore(); 2935718399fSFrançois Tigeot } 2945718399fSFrançois Tigeot static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn); 2955718399fSFrançois Tigeot 2965718399fSFrançois Tigeot static void drm_fb_helper_sysrq(int dummy1) 2975718399fSFrançois Tigeot { 2985718399fSFrançois Tigeot schedule_work(&drm_fb_helper_restore_work); 2995718399fSFrançois Tigeot } 3005718399fSFrançois Tigeot 3015718399fSFrançois Tigeot static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { 3025718399fSFrançois Tigeot .handler = drm_fb_helper_sysrq, 3035718399fSFrançois Tigeot .help_msg = "force-fb(V)", 3045718399fSFrançois Tigeot .action_msg = "Restore framebuffer console", 3055718399fSFrançois Tigeot }; 3065718399fSFrançois Tigeot #else 3075718399fSFrançois Tigeot static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; 3085718399fSFrançois Tigeot #endif 3095718399fSFrançois Tigeot #endif 3105718399fSFrançois Tigeot 3115718399fSFrançois Tigeot #if 0 3125718399fSFrançois Tigeot static void drm_fb_helper_on(struct fb_info *info) 3135718399fSFrançois Tigeot { 3145718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 3155718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 3165718399fSFrançois Tigeot struct drm_crtc *crtc; 3175718399fSFrançois Tigeot struct drm_crtc_helper_funcs *crtc_funcs; 3185718399fSFrançois Tigeot struct drm_connector *connector; 3195718399fSFrançois Tigeot struct drm_encoder *encoder; 3205718399fSFrançois Tigeot int i, j; 3215718399fSFrançois Tigeot 3225718399fSFrançois Tigeot /* 3235718399fSFrançois Tigeot * For each CRTC in this fb, turn the crtc on then, 3245718399fSFrançois Tigeot * find all associated encoders and turn them on. 3255718399fSFrançois Tigeot */ 3265718399fSFrançois Tigeot sx_xlock(&dev->mode_config.mutex); 3275718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 3285718399fSFrançois Tigeot crtc = fb_helper->crtc_info[i].mode_set.crtc; 3295718399fSFrançois Tigeot crtc_funcs = crtc->helper_private; 3305718399fSFrançois Tigeot 3315718399fSFrançois Tigeot if (!crtc->enabled) 3325718399fSFrançois Tigeot continue; 3335718399fSFrançois Tigeot 3345718399fSFrançois Tigeot crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); 3355718399fSFrançois Tigeot 3365718399fSFrançois Tigeot /* Walk the connectors & encoders on this fb turning them on */ 3375718399fSFrançois Tigeot for (j = 0; j < fb_helper->connector_count; j++) { 3385718399fSFrançois Tigeot connector = fb_helper->connector_info[j]->connector; 3395718399fSFrançois Tigeot connector->dpms = DRM_MODE_DPMS_ON; 3405718399fSFrançois Tigeot drm_connector_property_set_value(connector, 3415718399fSFrançois Tigeot dev->mode_config.dpms_property, 3425718399fSFrançois Tigeot DRM_MODE_DPMS_ON); 3435718399fSFrançois Tigeot } 3445718399fSFrançois Tigeot /* Found a CRTC on this fb, now find encoders */ 3455718399fSFrançois Tigeot list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 3465718399fSFrançois Tigeot if (encoder->crtc == crtc) { 3475718399fSFrançois Tigeot struct drm_encoder_helper_funcs *encoder_funcs; 3485718399fSFrançois Tigeot 3495718399fSFrançois Tigeot encoder_funcs = encoder->helper_private; 3505718399fSFrançois Tigeot encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); 3515718399fSFrançois Tigeot } 3525718399fSFrançois Tigeot } 3535718399fSFrançois Tigeot } 3545718399fSFrançois Tigeot sx_xunlock(&dev->mode_config.mutex); 3555718399fSFrançois Tigeot } 3565718399fSFrançois Tigeot #endif 3575718399fSFrançois Tigeot 3585718399fSFrançois Tigeot #if 0 3595718399fSFrançois Tigeot static void drm_fb_helper_off(struct fb_info *info, int dpms_mode) 3605718399fSFrançois Tigeot { 3615718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 3625718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 3635718399fSFrançois Tigeot struct drm_crtc *crtc; 3645718399fSFrançois Tigeot struct drm_crtc_helper_funcs *crtc_funcs; 3655718399fSFrançois Tigeot struct drm_connector *connector; 3665718399fSFrançois Tigeot struct drm_encoder *encoder; 3675718399fSFrançois Tigeot int i, j; 3685718399fSFrançois Tigeot 3695718399fSFrançois Tigeot /* 3705718399fSFrançois Tigeot * For each CRTC in this fb, find all associated encoders 3715718399fSFrançois Tigeot * and turn them off, then turn off the CRTC. 3725718399fSFrançois Tigeot */ 3735718399fSFrançois Tigeot sx_xlock(&dev->mode_config.mutex); 3745718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 3755718399fSFrançois Tigeot crtc = fb_helper->crtc_info[i].mode_set.crtc; 3765718399fSFrançois Tigeot crtc_funcs = crtc->helper_private; 3775718399fSFrançois Tigeot 3785718399fSFrançois Tigeot if (!crtc->enabled) 3795718399fSFrançois Tigeot continue; 3805718399fSFrançois Tigeot 3815718399fSFrançois Tigeot /* Walk the connectors on this fb and mark them off */ 3825718399fSFrançois Tigeot for (j = 0; j < fb_helper->connector_count; j++) { 3835718399fSFrançois Tigeot connector = fb_helper->connector_info[j]->connector; 3845718399fSFrançois Tigeot connector->dpms = dpms_mode; 3855718399fSFrançois Tigeot drm_connector_property_set_value(connector, 3865718399fSFrançois Tigeot dev->mode_config.dpms_property, 3875718399fSFrançois Tigeot dpms_mode); 3885718399fSFrançois Tigeot } 3895718399fSFrançois Tigeot /* Found a CRTC on this fb, now find encoders */ 3905718399fSFrançois Tigeot list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 3915718399fSFrançois Tigeot if (encoder->crtc == crtc) { 3925718399fSFrançois Tigeot struct drm_encoder_helper_funcs *encoder_funcs; 3935718399fSFrançois Tigeot 3945718399fSFrançois Tigeot encoder_funcs = encoder->helper_private; 3955718399fSFrançois Tigeot encoder_funcs->dpms(encoder, dpms_mode); 3965718399fSFrançois Tigeot } 3975718399fSFrançois Tigeot } 3985718399fSFrançois Tigeot crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); 3995718399fSFrançois Tigeot } 4005718399fSFrançois Tigeot sx_xunlock(&dev->mode_config.mutex); 4015718399fSFrançois Tigeot } 4025718399fSFrançois Tigeot #endif 4035718399fSFrançois Tigeot 4045718399fSFrançois Tigeot #if 0 4055718399fSFrançois Tigeot int drm_fb_helper_blank(int blank, struct fb_info *info) 4065718399fSFrançois Tigeot { 4075718399fSFrançois Tigeot switch (blank) { 4085718399fSFrançois Tigeot /* Display: On; HSync: On, VSync: On */ 4095718399fSFrançois Tigeot case FB_BLANK_UNBLANK: 4105718399fSFrançois Tigeot drm_fb_helper_on(info); 4115718399fSFrançois Tigeot break; 4125718399fSFrançois Tigeot /* Display: Off; HSync: On, VSync: On */ 4135718399fSFrançois Tigeot case FB_BLANK_NORMAL: 4145718399fSFrançois Tigeot drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY); 4155718399fSFrançois Tigeot break; 4165718399fSFrançois Tigeot /* Display: Off; HSync: Off, VSync: On */ 4175718399fSFrançois Tigeot case FB_BLANK_HSYNC_SUSPEND: 4185718399fSFrançois Tigeot drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY); 4195718399fSFrançois Tigeot break; 4205718399fSFrançois Tigeot /* Display: Off; HSync: On, VSync: Off */ 4215718399fSFrançois Tigeot case FB_BLANK_VSYNC_SUSPEND: 4225718399fSFrançois Tigeot drm_fb_helper_off(info, DRM_MODE_DPMS_SUSPEND); 4235718399fSFrançois Tigeot break; 4245718399fSFrançois Tigeot /* Display: Off; HSync: Off, VSync: Off */ 4255718399fSFrançois Tigeot case FB_BLANK_POWERDOWN: 4265718399fSFrançois Tigeot drm_fb_helper_off(info, DRM_MODE_DPMS_OFF); 4275718399fSFrançois Tigeot break; 4285718399fSFrançois Tigeot } 4295718399fSFrançois Tigeot return 0; 4305718399fSFrançois Tigeot } 4315718399fSFrançois Tigeot #endif 4325718399fSFrançois Tigeot 4335718399fSFrançois Tigeot static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) 4345718399fSFrançois Tigeot { 4355718399fSFrançois Tigeot int i; 4365718399fSFrançois Tigeot 4375718399fSFrançois Tigeot for (i = 0; i < helper->connector_count; i++) 4385718399fSFrançois Tigeot drm_free(helper->connector_info[i], DRM_MEM_KMS); 4395718399fSFrançois Tigeot drm_free(helper->connector_info, DRM_MEM_KMS); 4406f486c69SFrançois Tigeot for (i = 0; i < helper->crtc_count; i++) { 4415718399fSFrançois Tigeot drm_free(helper->crtc_info[i].mode_set.connectors, DRM_MEM_KMS); 4426f486c69SFrançois Tigeot if (helper->crtc_info[i].mode_set.mode) 4436f486c69SFrançois Tigeot drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode); 4446f486c69SFrançois Tigeot } 4455718399fSFrançois Tigeot drm_free(helper->crtc_info, DRM_MEM_KMS); 4465718399fSFrançois Tigeot } 4475718399fSFrançois Tigeot 4485718399fSFrançois Tigeot int drm_fb_helper_init(struct drm_device *dev, 4495718399fSFrançois Tigeot struct drm_fb_helper *fb_helper, 4505718399fSFrançois Tigeot int crtc_count, int max_conn_count) 4515718399fSFrançois Tigeot { 4525718399fSFrançois Tigeot struct drm_crtc *crtc; 4535718399fSFrançois Tigeot int i; 4545718399fSFrançois Tigeot 4555718399fSFrançois Tigeot fb_helper->dev = dev; 4565718399fSFrançois Tigeot 4575718399fSFrançois Tigeot INIT_LIST_HEAD(&fb_helper->kernel_fb_list); 4585718399fSFrançois Tigeot 4595718399fSFrançois Tigeot fb_helper->crtc_info = kmalloc(crtc_count * 4605718399fSFrançois Tigeot sizeof(struct drm_fb_helper_crtc), DRM_MEM_KMS, M_WAITOK | M_ZERO); 461*4a968d2aSFrançois Tigeot if (!fb_helper->crtc_info) 462*4a968d2aSFrançois Tigeot return -ENOMEM; 4635718399fSFrançois Tigeot 4645718399fSFrançois Tigeot fb_helper->crtc_count = crtc_count; 4655718399fSFrançois Tigeot fb_helper->connector_info = kmalloc(dev->mode_config.num_connector * 4665718399fSFrançois Tigeot sizeof(struct drm_fb_helper_connector *), DRM_MEM_KMS, 4675718399fSFrançois Tigeot M_WAITOK | M_ZERO); 468*4a968d2aSFrançois Tigeot if (!fb_helper->connector_info) { 469*4a968d2aSFrançois Tigeot kfree(fb_helper->crtc_info, DRM_MEM_KMS); 470*4a968d2aSFrançois Tigeot return -ENOMEM; 471*4a968d2aSFrançois Tigeot } 4725718399fSFrançois Tigeot fb_helper->connector_count = 0; 4735718399fSFrançois Tigeot 4745718399fSFrançois Tigeot for (i = 0; i < crtc_count; i++) { 4755718399fSFrançois Tigeot fb_helper->crtc_info[i].mode_set.connectors = 4765718399fSFrançois Tigeot kmalloc(max_conn_count * sizeof(struct drm_connector *), 4775718399fSFrançois Tigeot DRM_MEM_KMS, M_WAITOK | M_ZERO); 4785718399fSFrançois Tigeot 479*4a968d2aSFrançois Tigeot if (!fb_helper->crtc_info[i].mode_set.connectors) 480*4a968d2aSFrançois Tigeot goto out_free; 4815718399fSFrançois Tigeot fb_helper->crtc_info[i].mode_set.num_connectors = 0; 4825718399fSFrançois Tigeot } 4835718399fSFrançois Tigeot 4845718399fSFrançois Tigeot i = 0; 4855718399fSFrançois Tigeot list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 4865718399fSFrançois Tigeot fb_helper->crtc_info[i].mode_set.crtc = crtc; 4875718399fSFrançois Tigeot i++; 4885718399fSFrançois Tigeot } 489*4a968d2aSFrançois Tigeot 4905718399fSFrançois Tigeot return 0; 491*4a968d2aSFrançois Tigeot out_free: 492*4a968d2aSFrançois Tigeot drm_fb_helper_crtc_free(fb_helper); 493*4a968d2aSFrançois Tigeot return -ENOMEM; 4945718399fSFrançois Tigeot } 495*4a968d2aSFrançois Tigeot EXPORT_SYMBOL(drm_fb_helper_init); 4965718399fSFrançois Tigeot 4975718399fSFrançois Tigeot void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) 4985718399fSFrançois Tigeot { 4995718399fSFrançois Tigeot if (!list_empty(&fb_helper->kernel_fb_list)) { 5005718399fSFrançois Tigeot list_del(&fb_helper->kernel_fb_list); 5015718399fSFrançois Tigeot if (list_empty(&kernel_fb_helper_list)) { 5025718399fSFrançois Tigeot #if 0 5035718399fSFrançois Tigeot printk(KERN_INFO "drm: unregistered panic notifier\n"); 5045718399fSFrançois Tigeot atomic_notifier_chain_unregister(&panic_notifier_list, 5055718399fSFrançois Tigeot &paniced); 5065718399fSFrançois Tigeot unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); 5075718399fSFrançois Tigeot #endif 5085718399fSFrançois Tigeot } 5095718399fSFrançois Tigeot } 5105718399fSFrançois Tigeot 5115718399fSFrançois Tigeot drm_fb_helper_crtc_free(fb_helper); 5125718399fSFrançois Tigeot 5135718399fSFrançois Tigeot } 5145718399fSFrançois Tigeot 5155718399fSFrançois Tigeot #if 0 5165718399fSFrançois Tigeot static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green, 5175718399fSFrançois Tigeot u16 blue, u16 regno, struct fb_info *info) 5185718399fSFrançois Tigeot { 5195718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 5205718399fSFrançois Tigeot struct drm_framebuffer *fb = fb_helper->fb; 5215718399fSFrançois Tigeot int pindex; 5225718399fSFrançois Tigeot 5235718399fSFrançois Tigeot if (info->fix.visual == FB_VISUAL_trueCOLOR) { 5245718399fSFrançois Tigeot u32 *palette; 5255718399fSFrançois Tigeot u32 value; 5265718399fSFrançois Tigeot /* place color in psuedopalette */ 5275718399fSFrançois Tigeot if (regno > 16) 5285718399fSFrançois Tigeot return -EINVAL; 5295718399fSFrançois Tigeot palette = (u32 *)info->pseudo_palette; 5305718399fSFrançois Tigeot red >>= (16 - info->var.red.length); 5315718399fSFrançois Tigeot green >>= (16 - info->var.green.length); 5325718399fSFrançois Tigeot blue >>= (16 - info->var.blue.length); 5335718399fSFrançois Tigeot value = (red << info->var.red.offset) | 5345718399fSFrançois Tigeot (green << info->var.green.offset) | 5355718399fSFrançois Tigeot (blue << info->var.blue.offset); 5365718399fSFrançois Tigeot if (info->var.transp.length > 0) { 5375718399fSFrançois Tigeot u32 mask = (1 << info->var.transp.length) - 1; 5385718399fSFrançois Tigeot mask <<= info->var.transp.offset; 5395718399fSFrançois Tigeot value |= mask; 5405718399fSFrançois Tigeot } 5415718399fSFrançois Tigeot palette[regno] = value; 5425718399fSFrançois Tigeot return 0; 5435718399fSFrançois Tigeot } 5445718399fSFrançois Tigeot 5455718399fSFrançois Tigeot pindex = regno; 5465718399fSFrançois Tigeot 5475718399fSFrançois Tigeot if (fb->bits_per_pixel == 16) { 5485718399fSFrançois Tigeot pindex = regno << 3; 5495718399fSFrançois Tigeot 5505718399fSFrançois Tigeot if (fb->depth == 16 && regno > 63) 5515718399fSFrançois Tigeot return -EINVAL; 5525718399fSFrançois Tigeot if (fb->depth == 15 && regno > 31) 5535718399fSFrançois Tigeot return -EINVAL; 5545718399fSFrançois Tigeot 5555718399fSFrançois Tigeot if (fb->depth == 16) { 5565718399fSFrançois Tigeot u16 r, g, b; 5575718399fSFrançois Tigeot int i; 5585718399fSFrançois Tigeot if (regno < 32) { 5595718399fSFrançois Tigeot for (i = 0; i < 8; i++) 5605718399fSFrançois Tigeot fb_helper->funcs->gamma_set(crtc, red, 5615718399fSFrançois Tigeot green, blue, pindex + i); 5625718399fSFrançois Tigeot } 5635718399fSFrançois Tigeot 5645718399fSFrançois Tigeot fb_helper->funcs->gamma_get(crtc, &r, 5655718399fSFrançois Tigeot &g, &b, 5665718399fSFrançois Tigeot pindex >> 1); 5675718399fSFrançois Tigeot 5685718399fSFrançois Tigeot for (i = 0; i < 4; i++) 5695718399fSFrançois Tigeot fb_helper->funcs->gamma_set(crtc, r, 5705718399fSFrançois Tigeot green, b, 5715718399fSFrançois Tigeot (pindex >> 1) + i); 5725718399fSFrançois Tigeot } 5735718399fSFrançois Tigeot } 5745718399fSFrançois Tigeot 5755718399fSFrançois Tigeot if (fb->depth != 16) 5765718399fSFrançois Tigeot fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex); 5775718399fSFrançois Tigeot return 0; 5785718399fSFrançois Tigeot } 5795718399fSFrançois Tigeot #endif 5805718399fSFrançois Tigeot 5815718399fSFrançois Tigeot #if 0 5825718399fSFrançois Tigeot int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) 5835718399fSFrançois Tigeot { 5845718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 5855718399fSFrançois Tigeot struct drm_crtc_helper_funcs *crtc_funcs; 5865718399fSFrançois Tigeot u16 *red, *green, *blue, *transp; 5875718399fSFrançois Tigeot struct drm_crtc *crtc; 5885718399fSFrançois Tigeot int i, j, rc = 0; 5895718399fSFrançois Tigeot int start; 5905718399fSFrançois Tigeot 5915718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 5925718399fSFrançois Tigeot crtc = fb_helper->crtc_info[i].mode_set.crtc; 5935718399fSFrançois Tigeot crtc_funcs = crtc->helper_private; 5945718399fSFrançois Tigeot 5955718399fSFrançois Tigeot red = cmap->red; 5965718399fSFrançois Tigeot green = cmap->green; 5975718399fSFrançois Tigeot blue = cmap->blue; 5985718399fSFrançois Tigeot transp = cmap->transp; 5995718399fSFrançois Tigeot start = cmap->start; 6005718399fSFrançois Tigeot 6015718399fSFrançois Tigeot for (j = 0; j < cmap->len; j++) { 6025718399fSFrançois Tigeot u16 hred, hgreen, hblue, htransp = 0xffff; 6035718399fSFrançois Tigeot 6045718399fSFrançois Tigeot hred = *red++; 6055718399fSFrançois Tigeot hgreen = *green++; 6065718399fSFrançois Tigeot hblue = *blue++; 6075718399fSFrançois Tigeot 6085718399fSFrançois Tigeot if (transp) 6095718399fSFrançois Tigeot htransp = *transp++; 6105718399fSFrançois Tigeot 6115718399fSFrançois Tigeot rc = setcolreg(crtc, hred, hgreen, hblue, start++, info); 6125718399fSFrançois Tigeot if (rc) 6135718399fSFrançois Tigeot return rc; 6145718399fSFrançois Tigeot } 6155718399fSFrançois Tigeot crtc_funcs->load_lut(crtc); 6165718399fSFrançois Tigeot } 6175718399fSFrançois Tigeot return rc; 6185718399fSFrançois Tigeot } 6195718399fSFrançois Tigeot #endif 6205718399fSFrançois Tigeot 6215718399fSFrançois Tigeot #if 0 6225718399fSFrançois Tigeot int drm_fb_helper_check_var(struct fb_var_screeninfo *var, 6235718399fSFrançois Tigeot struct fb_info *info) 6245718399fSFrançois Tigeot { 6255718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 6265718399fSFrançois Tigeot struct drm_framebuffer *fb = fb_helper->fb; 6275718399fSFrançois Tigeot int depth; 6285718399fSFrançois Tigeot 6295718399fSFrançois Tigeot if (var->pixclock != 0 || in_dbg_master()) 6305718399fSFrançois Tigeot return -EINVAL; 6315718399fSFrançois Tigeot 6325718399fSFrançois Tigeot /* Need to resize the fb object !!! */ 6335718399fSFrançois Tigeot if (var->bits_per_pixel > fb->bits_per_pixel || 6345718399fSFrançois Tigeot var->xres > fb->width || var->yres > fb->height || 6355718399fSFrançois Tigeot var->xres_virtual > fb->width || var->yres_virtual > fb->height) { 6365718399fSFrançois Tigeot DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb " 6375718399fSFrançois Tigeot "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n", 6385718399fSFrançois Tigeot var->xres, var->yres, var->bits_per_pixel, 6395718399fSFrançois Tigeot var->xres_virtual, var->yres_virtual, 6405718399fSFrançois Tigeot fb->width, fb->height, fb->bits_per_pixel); 6415718399fSFrançois Tigeot return -EINVAL; 6425718399fSFrançois Tigeot } 6435718399fSFrançois Tigeot 6445718399fSFrançois Tigeot switch (var->bits_per_pixel) { 6455718399fSFrançois Tigeot case 16: 6465718399fSFrançois Tigeot depth = (var->green.length == 6) ? 16 : 15; 6475718399fSFrançois Tigeot break; 6485718399fSFrançois Tigeot case 32: 6495718399fSFrançois Tigeot depth = (var->transp.length > 0) ? 32 : 24; 6505718399fSFrançois Tigeot break; 6515718399fSFrançois Tigeot default: 6525718399fSFrançois Tigeot depth = var->bits_per_pixel; 6535718399fSFrançois Tigeot break; 6545718399fSFrançois Tigeot } 6555718399fSFrançois Tigeot 6565718399fSFrançois Tigeot switch (depth) { 6575718399fSFrançois Tigeot case 8: 6585718399fSFrançois Tigeot var->red.offset = 0; 6595718399fSFrançois Tigeot var->green.offset = 0; 6605718399fSFrançois Tigeot var->blue.offset = 0; 6615718399fSFrançois Tigeot var->red.length = 8; 6625718399fSFrançois Tigeot var->green.length = 8; 6635718399fSFrançois Tigeot var->blue.length = 8; 6645718399fSFrançois Tigeot var->transp.length = 0; 6655718399fSFrançois Tigeot var->transp.offset = 0; 6665718399fSFrançois Tigeot break; 6675718399fSFrançois Tigeot case 15: 6685718399fSFrançois Tigeot var->red.offset = 10; 6695718399fSFrançois Tigeot var->green.offset = 5; 6705718399fSFrançois Tigeot var->blue.offset = 0; 6715718399fSFrançois Tigeot var->red.length = 5; 6725718399fSFrançois Tigeot var->green.length = 5; 6735718399fSFrançois Tigeot var->blue.length = 5; 6745718399fSFrançois Tigeot var->transp.length = 1; 6755718399fSFrançois Tigeot var->transp.offset = 15; 6765718399fSFrançois Tigeot break; 6775718399fSFrançois Tigeot case 16: 6785718399fSFrançois Tigeot var->red.offset = 11; 6795718399fSFrançois Tigeot var->green.offset = 5; 6805718399fSFrançois Tigeot var->blue.offset = 0; 6815718399fSFrançois Tigeot var->red.length = 5; 6825718399fSFrançois Tigeot var->green.length = 6; 6835718399fSFrançois Tigeot var->blue.length = 5; 6845718399fSFrançois Tigeot var->transp.length = 0; 6855718399fSFrançois Tigeot var->transp.offset = 0; 6865718399fSFrançois Tigeot break; 6875718399fSFrançois Tigeot case 24: 6885718399fSFrançois Tigeot var->red.offset = 16; 6895718399fSFrançois Tigeot var->green.offset = 8; 6905718399fSFrançois Tigeot var->blue.offset = 0; 6915718399fSFrançois Tigeot var->red.length = 8; 6925718399fSFrançois Tigeot var->green.length = 8; 6935718399fSFrançois Tigeot var->blue.length = 8; 6945718399fSFrançois Tigeot var->transp.length = 0; 6955718399fSFrançois Tigeot var->transp.offset = 0; 6965718399fSFrançois Tigeot break; 6975718399fSFrançois Tigeot case 32: 6985718399fSFrançois Tigeot var->red.offset = 16; 6995718399fSFrançois Tigeot var->green.offset = 8; 7005718399fSFrançois Tigeot var->blue.offset = 0; 7015718399fSFrançois Tigeot var->red.length = 8; 7025718399fSFrançois Tigeot var->green.length = 8; 7035718399fSFrançois Tigeot var->blue.length = 8; 7045718399fSFrançois Tigeot var->transp.length = 8; 7055718399fSFrançois Tigeot var->transp.offset = 24; 7065718399fSFrançois Tigeot break; 7075718399fSFrançois Tigeot default: 7085718399fSFrançois Tigeot return -EINVAL; 7095718399fSFrançois Tigeot } 7105718399fSFrançois Tigeot return 0; 7115718399fSFrançois Tigeot } 7125718399fSFrançois Tigeot #endif 7135718399fSFrançois Tigeot 7145718399fSFrançois Tigeot #if 0 7155718399fSFrançois Tigeot /* this will let fbcon do the mode init */ 7165718399fSFrançois Tigeot int drm_fb_helper_set_par(struct fb_info *info) 7175718399fSFrançois Tigeot { 7185718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 7195718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 7205718399fSFrançois Tigeot struct fb_var_screeninfo *var = &info->var; 7215718399fSFrançois Tigeot struct drm_crtc *crtc; 7225718399fSFrançois Tigeot int ret; 7235718399fSFrançois Tigeot int i; 7245718399fSFrançois Tigeot 7255718399fSFrançois Tigeot if (var->pixclock != 0) { 7265718399fSFrançois Tigeot DRM_ERROR("PIXEL CLOCK SET\n"); 7275718399fSFrançois Tigeot return -EINVAL; 7285718399fSFrançois Tigeot } 7295718399fSFrançois Tigeot 7305718399fSFrançois Tigeot mutex_lock(&dev->mode_config.mutex); 7315718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 7325718399fSFrançois Tigeot crtc = fb_helper->crtc_info[i].mode_set.crtc; 7335718399fSFrançois Tigeot ret = crtc->funcs->set_config(&fb_helper->crtc_info[i].mode_set); 7345718399fSFrançois Tigeot if (ret) { 7355718399fSFrançois Tigeot mutex_unlock(&dev->mode_config.mutex); 7365718399fSFrançois Tigeot return ret; 7375718399fSFrançois Tigeot } 7385718399fSFrançois Tigeot } 7395718399fSFrançois Tigeot mutex_unlock(&dev->mode_config.mutex); 7405718399fSFrançois Tigeot 7415718399fSFrançois Tigeot if (fb_helper->delayed_hotplug) { 7425718399fSFrançois Tigeot fb_helper->delayed_hotplug = false; 7435718399fSFrançois Tigeot drm_fb_helper_hotplug_event(fb_helper); 7445718399fSFrançois Tigeot } 7455718399fSFrançois Tigeot return 0; 7465718399fSFrançois Tigeot } 7475718399fSFrançois Tigeot #endif 7485718399fSFrançois Tigeot 7495718399fSFrançois Tigeot #if 0 7505718399fSFrançois Tigeot int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, 7515718399fSFrançois Tigeot struct fb_info *info) 7525718399fSFrançois Tigeot { 7535718399fSFrançois Tigeot struct drm_fb_helper *fb_helper = info->par; 7545718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 7555718399fSFrançois Tigeot struct drm_mode_set *modeset; 7565718399fSFrançois Tigeot struct drm_crtc *crtc; 7575718399fSFrançois Tigeot int ret = 0; 7585718399fSFrançois Tigeot int i; 7595718399fSFrançois Tigeot 7605718399fSFrançois Tigeot mutex_lock(&dev->mode_config.mutex); 7615718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 7625718399fSFrançois Tigeot crtc = fb_helper->crtc_info[i].mode_set.crtc; 7635718399fSFrançois Tigeot 7645718399fSFrançois Tigeot modeset = &fb_helper->crtc_info[i].mode_set; 7655718399fSFrançois Tigeot 7665718399fSFrançois Tigeot modeset->x = var->xoffset; 7675718399fSFrançois Tigeot modeset->y = var->yoffset; 7685718399fSFrançois Tigeot 7695718399fSFrançois Tigeot if (modeset->num_connectors) { 7705718399fSFrançois Tigeot ret = crtc->funcs->set_config(modeset); 7715718399fSFrançois Tigeot if (!ret) { 7725718399fSFrançois Tigeot info->var.xoffset = var->xoffset; 7735718399fSFrançois Tigeot info->var.yoffset = var->yoffset; 7745718399fSFrançois Tigeot } 7755718399fSFrançois Tigeot } 7765718399fSFrançois Tigeot } 7775718399fSFrançois Tigeot mutex_unlock(&dev->mode_config.mutex); 7785718399fSFrançois Tigeot return ret; 7795718399fSFrançois Tigeot } 7805718399fSFrançois Tigeot #endif 7815718399fSFrançois Tigeot 7825718399fSFrançois Tigeot int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, 7835718399fSFrançois Tigeot int preferred_bpp) 7845718399fSFrançois Tigeot { 7855718399fSFrançois Tigeot int new_fb = 0; 7865718399fSFrançois Tigeot int crtc_count = 0; 7875718399fSFrançois Tigeot int i; 7885718399fSFrançois Tigeot #if 0 7895718399fSFrançois Tigeot struct fb_info *info; 7905718399fSFrançois Tigeot #endif 7915718399fSFrançois Tigeot struct drm_fb_helper_surface_size sizes; 7925718399fSFrançois Tigeot int gamma_size = 0; 7935718399fSFrançois Tigeot 7945718399fSFrançois Tigeot memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); 7955718399fSFrançois Tigeot sizes.surface_depth = 24; 7965718399fSFrançois Tigeot sizes.surface_bpp = 32; 7975718399fSFrançois Tigeot sizes.fb_width = (unsigned)-1; 7985718399fSFrançois Tigeot sizes.fb_height = (unsigned)-1; 7995718399fSFrançois Tigeot 8005718399fSFrançois Tigeot /* if driver picks 8 or 16 by default use that 8015718399fSFrançois Tigeot for both depth/bpp */ 802*4a968d2aSFrançois Tigeot if (preferred_bpp != sizes.surface_bpp) 8035718399fSFrançois Tigeot sizes.surface_depth = sizes.surface_bpp = preferred_bpp; 804*4a968d2aSFrançois Tigeot 8055718399fSFrançois Tigeot /* first up get a count of crtcs now in use and new min/maxes width/heights */ 8065718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 8075718399fSFrançois Tigeot struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i]; 808*4a968d2aSFrançois Tigeot struct drm_cmdline_mode *cmdline_mode; 8095718399fSFrançois Tigeot 8105718399fSFrançois Tigeot cmdline_mode = &fb_helper_conn->cmdline_mode; 8115718399fSFrançois Tigeot 8125718399fSFrançois Tigeot if (cmdline_mode->bpp_specified) { 8135718399fSFrançois Tigeot switch (cmdline_mode->bpp) { 8145718399fSFrançois Tigeot case 8: 8155718399fSFrançois Tigeot sizes.surface_depth = sizes.surface_bpp = 8; 8165718399fSFrançois Tigeot break; 8175718399fSFrançois Tigeot case 15: 8185718399fSFrançois Tigeot sizes.surface_depth = 15; 8195718399fSFrançois Tigeot sizes.surface_bpp = 16; 8205718399fSFrançois Tigeot break; 8215718399fSFrançois Tigeot case 16: 8225718399fSFrançois Tigeot sizes.surface_depth = sizes.surface_bpp = 16; 8235718399fSFrançois Tigeot break; 8245718399fSFrançois Tigeot case 24: 8255718399fSFrançois Tigeot sizes.surface_depth = sizes.surface_bpp = 24; 8265718399fSFrançois Tigeot break; 8275718399fSFrançois Tigeot case 32: 8285718399fSFrançois Tigeot sizes.surface_depth = 24; 8295718399fSFrançois Tigeot sizes.surface_bpp = 32; 8305718399fSFrançois Tigeot break; 8315718399fSFrançois Tigeot } 8325718399fSFrançois Tigeot break; 8335718399fSFrançois Tigeot } 8345718399fSFrançois Tigeot } 8355718399fSFrançois Tigeot 8365718399fSFrançois Tigeot crtc_count = 0; 8375718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 8385718399fSFrançois Tigeot struct drm_display_mode *desired_mode; 8395718399fSFrançois Tigeot desired_mode = fb_helper->crtc_info[i].desired_mode; 8405718399fSFrançois Tigeot 8415718399fSFrançois Tigeot if (desired_mode) { 8425718399fSFrançois Tigeot if (gamma_size == 0) 8435718399fSFrançois Tigeot gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size; 8445718399fSFrançois Tigeot if (desired_mode->hdisplay < sizes.fb_width) 8455718399fSFrançois Tigeot sizes.fb_width = desired_mode->hdisplay; 8465718399fSFrançois Tigeot if (desired_mode->vdisplay < sizes.fb_height) 8475718399fSFrançois Tigeot sizes.fb_height = desired_mode->vdisplay; 8485718399fSFrançois Tigeot if (desired_mode->hdisplay > sizes.surface_width) 8495718399fSFrançois Tigeot sizes.surface_width = desired_mode->hdisplay; 8505718399fSFrançois Tigeot if (desired_mode->vdisplay > sizes.surface_height) 8515718399fSFrançois Tigeot sizes.surface_height = desired_mode->vdisplay; 8525718399fSFrançois Tigeot crtc_count++; 8535718399fSFrançois Tigeot } 8545718399fSFrançois Tigeot } 8555718399fSFrançois Tigeot 8565718399fSFrançois Tigeot if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) { 8575718399fSFrançois Tigeot /* hmm everyone went away - assume VGA cable just fell out 8585718399fSFrançois Tigeot and will come back later. */ 8595718399fSFrançois Tigeot DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n"); 8605718399fSFrançois Tigeot sizes.fb_width = sizes.surface_width = 1024; 8615718399fSFrançois Tigeot sizes.fb_height = sizes.surface_height = 768; 8625718399fSFrançois Tigeot } 8635718399fSFrançois Tigeot 8645718399fSFrançois Tigeot /* push down into drivers */ 8655718399fSFrançois Tigeot new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes); 8665718399fSFrançois Tigeot if (new_fb < 0) 8675718399fSFrançois Tigeot return new_fb; 8685718399fSFrançois Tigeot 8695718399fSFrançois Tigeot #if 0 8705718399fSFrançois Tigeot info = fb_helper->fbdev; 8715718399fSFrançois Tigeot #endif 8725718399fSFrançois Tigeot 8735718399fSFrançois Tigeot /* set the fb pointer */ 874*4a968d2aSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) 8755718399fSFrançois Tigeot fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb; 8765718399fSFrançois Tigeot 8775718399fSFrançois Tigeot #if 0 8785718399fSFrançois Tigeot if (new_fb) { 8795718399fSFrançois Tigeot info->var.pixclock = 0; 880*4a968d2aSFrançois Tigeot if (register_framebuffer(info) < 0) 8815718399fSFrançois Tigeot return -EINVAL; 8825718399fSFrançois Tigeot 883*4a968d2aSFrançois Tigeot dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n", 884*4a968d2aSFrançois Tigeot info->node, info->fix.id); 8855718399fSFrançois Tigeot 8865718399fSFrançois Tigeot } else { 8875718399fSFrançois Tigeot drm_fb_helper_set_par(info); 8885718399fSFrançois Tigeot } 8895718399fSFrançois Tigeot 8905718399fSFrançois Tigeot /* Switch back to kernel console on panic */ 8915718399fSFrançois Tigeot /* multi card linked list maybe */ 8925718399fSFrançois Tigeot if (list_empty(&kernel_fb_helper_list)) { 893*4a968d2aSFrançois Tigeot dev_info(fb_helper->dev->dev, "registered panic notifier\n"); 8945718399fSFrançois Tigeot atomic_notifier_chain_register(&panic_notifier_list, 8955718399fSFrançois Tigeot &paniced); 896*4a968d2aSFrançois Tigeot register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); 8975718399fSFrançois Tigeot } 8985718399fSFrançois Tigeot if (new_fb) 8995718399fSFrançois Tigeot list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); 9005718399fSFrançois Tigeot #endif 9015718399fSFrançois Tigeot 9025718399fSFrançois Tigeot return 0; 9035718399fSFrançois Tigeot } 904*4a968d2aSFrançois Tigeot EXPORT_SYMBOL(drm_fb_helper_single_fb_probe); 9055718399fSFrançois Tigeot 9065718399fSFrançois Tigeot #if 0 9075718399fSFrançois Tigeot void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, 9085718399fSFrançois Tigeot uint32_t depth) 9095718399fSFrançois Tigeot { 9105718399fSFrançois Tigeot info->fix.type = FB_TYPE_PACKED_PIXELS; 9115718399fSFrançois Tigeot info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR : 9125718399fSFrançois Tigeot FB_VISUAL_trueCOLOR; 9135718399fSFrançois Tigeot info->fix.mmio_start = 0; 9145718399fSFrançois Tigeot info->fix.mmio_len = 0; 9155718399fSFrançois Tigeot info->fix.type_aux = 0; 9165718399fSFrançois Tigeot info->fix.xpanstep = 1; /* doing it in hw */ 9175718399fSFrançois Tigeot info->fix.ypanstep = 1; /* doing it in hw */ 9185718399fSFrançois Tigeot info->fix.ywrapstep = 0; 9195718399fSFrançois Tigeot info->fix.accel = FB_ACCEL_NONE; 9205718399fSFrançois Tigeot info->fix.type_aux = 0; 9215718399fSFrançois Tigeot 9225718399fSFrançois Tigeot info->fix.line_length = pitch; 9235718399fSFrançois Tigeot return; 9245718399fSFrançois Tigeot } 9255718399fSFrançois Tigeot 9265718399fSFrançois Tigeot void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper, 9275718399fSFrançois Tigeot uint32_t fb_width, uint32_t fb_height) 9285718399fSFrançois Tigeot { 9295718399fSFrançois Tigeot struct drm_framebuffer *fb = fb_helper->fb; 9305718399fSFrançois Tigeot info->pseudo_palette = fb_helper->pseudo_palette; 9315718399fSFrançois Tigeot info->var.xres_virtual = fb->width; 9325718399fSFrançois Tigeot info->var.yres_virtual = fb->height; 9335718399fSFrançois Tigeot info->var.bits_per_pixel = fb->bits_per_pixel; 9345718399fSFrançois Tigeot info->var.accel_flags = FB_ACCELF_TEXT; 9355718399fSFrançois Tigeot info->var.xoffset = 0; 9365718399fSFrançois Tigeot info->var.yoffset = 0; 9375718399fSFrançois Tigeot info->var.activate = FB_ACTIVATE_NOW; 9385718399fSFrançois Tigeot info->var.height = -1; 9395718399fSFrançois Tigeot info->var.width = -1; 9405718399fSFrançois Tigeot 9415718399fSFrançois Tigeot switch (fb->depth) { 9425718399fSFrançois Tigeot case 8: 9435718399fSFrançois Tigeot info->var.red.offset = 0; 9445718399fSFrançois Tigeot info->var.green.offset = 0; 9455718399fSFrançois Tigeot info->var.blue.offset = 0; 9465718399fSFrançois Tigeot info->var.red.length = 8; /* 8bit DAC */ 9475718399fSFrançois Tigeot info->var.green.length = 8; 9485718399fSFrançois Tigeot info->var.blue.length = 8; 9495718399fSFrançois Tigeot info->var.transp.offset = 0; 9505718399fSFrançois Tigeot info->var.transp.length = 0; 9515718399fSFrançois Tigeot break; 9525718399fSFrançois Tigeot case 15: 9535718399fSFrançois Tigeot info->var.red.offset = 10; 9545718399fSFrançois Tigeot info->var.green.offset = 5; 9555718399fSFrançois Tigeot info->var.blue.offset = 0; 9565718399fSFrançois Tigeot info->var.red.length = 5; 9575718399fSFrançois Tigeot info->var.green.length = 5; 9585718399fSFrançois Tigeot info->var.blue.length = 5; 9595718399fSFrançois Tigeot info->var.transp.offset = 15; 9605718399fSFrançois Tigeot info->var.transp.length = 1; 9615718399fSFrançois Tigeot break; 9625718399fSFrançois Tigeot case 16: 9635718399fSFrançois Tigeot info->var.red.offset = 11; 9645718399fSFrançois Tigeot info->var.green.offset = 5; 9655718399fSFrançois Tigeot info->var.blue.offset = 0; 9665718399fSFrançois Tigeot info->var.red.length = 5; 9675718399fSFrançois Tigeot info->var.green.length = 6; 9685718399fSFrançois Tigeot info->var.blue.length = 5; 9695718399fSFrançois Tigeot info->var.transp.offset = 0; 9705718399fSFrançois Tigeot break; 9715718399fSFrançois Tigeot case 24: 9725718399fSFrançois Tigeot info->var.red.offset = 16; 9735718399fSFrançois Tigeot info->var.green.offset = 8; 9745718399fSFrançois Tigeot info->var.blue.offset = 0; 9755718399fSFrançois Tigeot info->var.red.length = 8; 9765718399fSFrançois Tigeot info->var.green.length = 8; 9775718399fSFrançois Tigeot info->var.blue.length = 8; 9785718399fSFrançois Tigeot info->var.transp.offset = 0; 9795718399fSFrançois Tigeot info->var.transp.length = 0; 9805718399fSFrançois Tigeot break; 9815718399fSFrançois Tigeot case 32: 9825718399fSFrançois Tigeot info->var.red.offset = 16; 9835718399fSFrançois Tigeot info->var.green.offset = 8; 9845718399fSFrançois Tigeot info->var.blue.offset = 0; 9855718399fSFrançois Tigeot info->var.red.length = 8; 9865718399fSFrançois Tigeot info->var.green.length = 8; 9875718399fSFrançois Tigeot info->var.blue.length = 8; 9885718399fSFrançois Tigeot info->var.transp.offset = 24; 9895718399fSFrançois Tigeot info->var.transp.length = 8; 9905718399fSFrançois Tigeot break; 9915718399fSFrançois Tigeot default: 9925718399fSFrançois Tigeot break; 9935718399fSFrançois Tigeot } 9945718399fSFrançois Tigeot 9955718399fSFrançois Tigeot info->var.xres = fb_width; 9965718399fSFrançois Tigeot info->var.yres = fb_height; 9975718399fSFrançois Tigeot } 9985718399fSFrançois Tigeot #endif 9995718399fSFrançois Tigeot 10005718399fSFrançois Tigeot static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper, 10015718399fSFrançois Tigeot uint32_t maxX, 10025718399fSFrançois Tigeot uint32_t maxY) 10035718399fSFrançois Tigeot { 10045718399fSFrançois Tigeot struct drm_connector *connector; 10055718399fSFrançois Tigeot int count = 0; 10065718399fSFrançois Tigeot int i; 10075718399fSFrançois Tigeot 10085718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 10095718399fSFrançois Tigeot connector = fb_helper->connector_info[i]->connector; 10105718399fSFrançois Tigeot count += connector->funcs->fill_modes(connector, maxX, maxY); 10115718399fSFrançois Tigeot } 10125718399fSFrançois Tigeot 10135718399fSFrançois Tigeot return count; 10145718399fSFrançois Tigeot } 10155718399fSFrançois Tigeot 10165718399fSFrançois Tigeot static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height) 10175718399fSFrançois Tigeot { 10185718399fSFrançois Tigeot struct drm_display_mode *mode; 10195718399fSFrançois Tigeot 10205718399fSFrançois Tigeot list_for_each_entry(mode, &fb_connector->connector->modes, head) { 10215718399fSFrançois Tigeot if (drm_mode_width(mode) > width || 10225718399fSFrançois Tigeot drm_mode_height(mode) > height) 10235718399fSFrançois Tigeot continue; 10245718399fSFrançois Tigeot if (mode->type & DRM_MODE_TYPE_PREFERRED) 10255718399fSFrançois Tigeot return mode; 10265718399fSFrançois Tigeot } 10275718399fSFrançois Tigeot return NULL; 10285718399fSFrançois Tigeot } 10295718399fSFrançois Tigeot 10305718399fSFrançois Tigeot static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector) 10315718399fSFrançois Tigeot { 1032*4a968d2aSFrançois Tigeot struct drm_cmdline_mode *cmdline_mode; 10335718399fSFrançois Tigeot cmdline_mode = &fb_connector->cmdline_mode; 10345718399fSFrançois Tigeot return cmdline_mode->specified; 10355718399fSFrançois Tigeot } 10365718399fSFrançois Tigeot 10375718399fSFrançois Tigeot static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn, 10385718399fSFrançois Tigeot int width, int height) 10395718399fSFrançois Tigeot { 10405718399fSFrançois Tigeot struct drm_cmdline_mode *cmdline_mode; 10415718399fSFrançois Tigeot struct drm_display_mode *mode = NULL; 10425718399fSFrançois Tigeot 1043*4a968d2aSFrançois Tigeot cmdline_mode = &fb_helper_conn->cmdline_mode; 10445718399fSFrançois Tigeot if (cmdline_mode->specified == false && 10455718399fSFrançois Tigeot !drm_fetch_cmdline_mode_from_kenv(fb_helper_conn->connector, 10465718399fSFrançois Tigeot cmdline_mode)) 10475718399fSFrançois Tigeot return (NULL); 10485718399fSFrançois Tigeot 10495718399fSFrançois Tigeot /* attempt to find a matching mode in the list of modes 10505718399fSFrançois Tigeot * we have gotten so far, if not add a CVT mode that conforms 10515718399fSFrançois Tigeot */ 10525718399fSFrançois Tigeot if (cmdline_mode->rb || cmdline_mode->margins) 10535718399fSFrançois Tigeot goto create_mode; 10545718399fSFrançois Tigeot 10555718399fSFrançois Tigeot list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { 10565718399fSFrançois Tigeot /* check width/height */ 10575718399fSFrançois Tigeot if (mode->hdisplay != cmdline_mode->xres || 10585718399fSFrançois Tigeot mode->vdisplay != cmdline_mode->yres) 10595718399fSFrançois Tigeot continue; 10605718399fSFrançois Tigeot 10615718399fSFrançois Tigeot if (cmdline_mode->refresh_specified) { 10625718399fSFrançois Tigeot if (mode->vrefresh != cmdline_mode->refresh) 10635718399fSFrançois Tigeot continue; 10645718399fSFrançois Tigeot } 10655718399fSFrançois Tigeot 10665718399fSFrançois Tigeot if (cmdline_mode->interlace) { 10675718399fSFrançois Tigeot if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) 10685718399fSFrançois Tigeot continue; 10695718399fSFrançois Tigeot } 10705718399fSFrançois Tigeot return mode; 10715718399fSFrançois Tigeot } 10725718399fSFrançois Tigeot 10735718399fSFrançois Tigeot create_mode: 10745718399fSFrançois Tigeot if (cmdline_mode->cvt) 10755718399fSFrançois Tigeot mode = drm_cvt_mode(fb_helper_conn->connector->dev, 10765718399fSFrançois Tigeot cmdline_mode->xres, cmdline_mode->yres, 10775718399fSFrançois Tigeot cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60, 10785718399fSFrançois Tigeot cmdline_mode->rb, cmdline_mode->interlace, 10795718399fSFrançois Tigeot cmdline_mode->margins); 10805718399fSFrançois Tigeot else 10815718399fSFrançois Tigeot mode = drm_gtf_mode(fb_helper_conn->connector->dev, 10825718399fSFrançois Tigeot cmdline_mode->xres, cmdline_mode->yres, 10835718399fSFrançois Tigeot cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60, 10845718399fSFrançois Tigeot cmdline_mode->interlace, 10855718399fSFrançois Tigeot cmdline_mode->margins); 10865718399fSFrançois Tigeot drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); 10875718399fSFrançois Tigeot list_add(&mode->head, &fb_helper_conn->connector->modes); 10885718399fSFrançois Tigeot return mode; 10895718399fSFrançois Tigeot } 10905718399fSFrançois Tigeot 10915718399fSFrançois Tigeot static bool drm_connector_enabled(struct drm_connector *connector, bool strict) 10925718399fSFrançois Tigeot { 10935718399fSFrançois Tigeot bool enable; 10945718399fSFrançois Tigeot 10955718399fSFrançois Tigeot if (strict) { 10965718399fSFrançois Tigeot enable = connector->status == connector_status_connected; 10975718399fSFrançois Tigeot } else { 10985718399fSFrançois Tigeot enable = connector->status != connector_status_disconnected; 10995718399fSFrançois Tigeot } 11005718399fSFrançois Tigeot return enable; 11015718399fSFrançois Tigeot } 11025718399fSFrançois Tigeot 11035718399fSFrançois Tigeot static void drm_enable_connectors(struct drm_fb_helper *fb_helper, 11045718399fSFrançois Tigeot bool *enabled) 11055718399fSFrançois Tigeot { 11065718399fSFrançois Tigeot bool any_enabled = false; 11075718399fSFrançois Tigeot struct drm_connector *connector; 11085718399fSFrançois Tigeot int i = 0; 11095718399fSFrançois Tigeot 11105718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 11115718399fSFrançois Tigeot connector = fb_helper->connector_info[i]->connector; 11125718399fSFrançois Tigeot enabled[i] = drm_connector_enabled(connector, true); 11135718399fSFrançois Tigeot DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id, 11145718399fSFrançois Tigeot enabled[i] ? "yes" : "no"); 11155718399fSFrançois Tigeot any_enabled |= enabled[i]; 11165718399fSFrançois Tigeot } 11175718399fSFrançois Tigeot 11185718399fSFrançois Tigeot if (any_enabled) 11195718399fSFrançois Tigeot return; 11205718399fSFrançois Tigeot 11215718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 11225718399fSFrançois Tigeot connector = fb_helper->connector_info[i]->connector; 11235718399fSFrançois Tigeot enabled[i] = drm_connector_enabled(connector, false); 11245718399fSFrançois Tigeot } 11255718399fSFrançois Tigeot } 11265718399fSFrançois Tigeot 11275718399fSFrançois Tigeot static bool drm_target_cloned(struct drm_fb_helper *fb_helper, 11285718399fSFrançois Tigeot struct drm_display_mode **modes, 11295718399fSFrançois Tigeot bool *enabled, int width, int height) 11305718399fSFrançois Tigeot { 11315718399fSFrançois Tigeot int count, i, j; 11325718399fSFrançois Tigeot bool can_clone = false; 11335718399fSFrançois Tigeot struct drm_fb_helper_connector *fb_helper_conn; 11345718399fSFrançois Tigeot struct drm_display_mode *dmt_mode, *mode; 11355718399fSFrançois Tigeot 11365718399fSFrançois Tigeot /* only contemplate cloning in the single crtc case */ 11375718399fSFrançois Tigeot if (fb_helper->crtc_count > 1) 11385718399fSFrançois Tigeot return false; 11395718399fSFrançois Tigeot 11405718399fSFrançois Tigeot count = 0; 11415718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 11425718399fSFrançois Tigeot if (enabled[i]) 11435718399fSFrançois Tigeot count++; 11445718399fSFrançois Tigeot } 11455718399fSFrançois Tigeot 11465718399fSFrançois Tigeot /* only contemplate cloning if more than one connector is enabled */ 11475718399fSFrançois Tigeot if (count <= 1) 11485718399fSFrançois Tigeot return false; 11495718399fSFrançois Tigeot 11505718399fSFrançois Tigeot /* check the command line or if nothing common pick 1024x768 */ 11515718399fSFrançois Tigeot can_clone = true; 11525718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 11535718399fSFrançois Tigeot if (!enabled[i]) 11545718399fSFrançois Tigeot continue; 11555718399fSFrançois Tigeot fb_helper_conn = fb_helper->connector_info[i]; 11565718399fSFrançois Tigeot modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); 11575718399fSFrançois Tigeot if (!modes[i]) { 11585718399fSFrançois Tigeot can_clone = false; 11595718399fSFrançois Tigeot break; 11605718399fSFrançois Tigeot } 11615718399fSFrançois Tigeot for (j = 0; j < i; j++) { 11625718399fSFrançois Tigeot if (!enabled[j]) 11635718399fSFrançois Tigeot continue; 11645718399fSFrançois Tigeot if (!drm_mode_equal(modes[j], modes[i])) 11655718399fSFrançois Tigeot can_clone = false; 11665718399fSFrançois Tigeot } 11675718399fSFrançois Tigeot } 11685718399fSFrançois Tigeot 11695718399fSFrançois Tigeot if (can_clone) { 11705718399fSFrançois Tigeot DRM_DEBUG_KMS("can clone using command line\n"); 11715718399fSFrançois Tigeot return true; 11725718399fSFrançois Tigeot } 11735718399fSFrançois Tigeot 11745718399fSFrançois Tigeot /* try and find a 1024x768 mode on each connector */ 11755718399fSFrançois Tigeot can_clone = true; 1176ce3d36d7SFrançois Tigeot dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false); 11775718399fSFrançois Tigeot 11785718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 11795718399fSFrançois Tigeot 11805718399fSFrançois Tigeot if (!enabled[i]) 11815718399fSFrançois Tigeot continue; 11825718399fSFrançois Tigeot 11835718399fSFrançois Tigeot fb_helper_conn = fb_helper->connector_info[i]; 11845718399fSFrançois Tigeot list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { 11855718399fSFrançois Tigeot if (drm_mode_equal(mode, dmt_mode)) 11865718399fSFrançois Tigeot modes[i] = mode; 11875718399fSFrançois Tigeot } 11885718399fSFrançois Tigeot if (!modes[i]) 11895718399fSFrançois Tigeot can_clone = false; 11905718399fSFrançois Tigeot } 11915718399fSFrançois Tigeot 11925718399fSFrançois Tigeot if (can_clone) { 11935718399fSFrançois Tigeot DRM_DEBUG_KMS("can clone using 1024x768\n"); 11945718399fSFrançois Tigeot return true; 11955718399fSFrançois Tigeot } 11965718399fSFrançois Tigeot DRM_INFO("kms: can't enable cloning when we probably wanted to.\n"); 11975718399fSFrançois Tigeot return false; 11985718399fSFrançois Tigeot } 11995718399fSFrançois Tigeot 12005718399fSFrançois Tigeot static bool drm_target_preferred(struct drm_fb_helper *fb_helper, 12015718399fSFrançois Tigeot struct drm_display_mode **modes, 12025718399fSFrançois Tigeot bool *enabled, int width, int height) 12035718399fSFrançois Tigeot { 12045718399fSFrançois Tigeot struct drm_fb_helper_connector *fb_helper_conn; 12055718399fSFrançois Tigeot int i; 12065718399fSFrançois Tigeot 12075718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 12085718399fSFrançois Tigeot fb_helper_conn = fb_helper->connector_info[i]; 12095718399fSFrançois Tigeot 12105718399fSFrançois Tigeot if (enabled[i] == false) 12115718399fSFrançois Tigeot continue; 12125718399fSFrançois Tigeot 12135718399fSFrançois Tigeot DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n", 12145718399fSFrançois Tigeot fb_helper_conn->connector->base.id); 12155718399fSFrançois Tigeot 12165718399fSFrançois Tigeot /* got for command line mode first */ 12175718399fSFrançois Tigeot modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); 12185718399fSFrançois Tigeot if (!modes[i]) { 12195718399fSFrançois Tigeot DRM_DEBUG_KMS("looking for preferred mode on connector %d\n", 12205718399fSFrançois Tigeot fb_helper_conn->connector->base.id); 12215718399fSFrançois Tigeot modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height); 12225718399fSFrançois Tigeot } 12235718399fSFrançois Tigeot /* No preferred modes, pick one off the list */ 12245718399fSFrançois Tigeot if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) { 12255718399fSFrançois Tigeot list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head) 12265718399fSFrançois Tigeot break; 12275718399fSFrançois Tigeot } 12285718399fSFrançois Tigeot DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : 12295718399fSFrançois Tigeot "none"); 12305718399fSFrançois Tigeot } 12315718399fSFrançois Tigeot return true; 12325718399fSFrançois Tigeot } 12335718399fSFrançois Tigeot 12345718399fSFrançois Tigeot static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, 12355718399fSFrançois Tigeot struct drm_fb_helper_crtc **best_crtcs, 12365718399fSFrançois Tigeot struct drm_display_mode **modes, 12375718399fSFrançois Tigeot int n, int width, int height) 12385718399fSFrançois Tigeot { 12395718399fSFrançois Tigeot int c, o; 12405718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 12415718399fSFrançois Tigeot struct drm_connector *connector; 12425718399fSFrançois Tigeot struct drm_connector_helper_funcs *connector_funcs; 12435718399fSFrançois Tigeot struct drm_encoder *encoder; 12445718399fSFrançois Tigeot struct drm_fb_helper_crtc *best_crtc; 12455718399fSFrançois Tigeot int my_score, best_score, score; 12465718399fSFrançois Tigeot struct drm_fb_helper_crtc **crtcs, *crtc; 12475718399fSFrançois Tigeot struct drm_fb_helper_connector *fb_helper_conn; 12485718399fSFrançois Tigeot 12495718399fSFrançois Tigeot if (n == fb_helper->connector_count) 12505718399fSFrançois Tigeot return 0; 12515718399fSFrançois Tigeot 12525718399fSFrançois Tigeot fb_helper_conn = fb_helper->connector_info[n]; 12535718399fSFrançois Tigeot connector = fb_helper_conn->connector; 12545718399fSFrançois Tigeot 12555718399fSFrançois Tigeot best_crtcs[n] = NULL; 12565718399fSFrançois Tigeot best_crtc = NULL; 12575718399fSFrançois Tigeot best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height); 12585718399fSFrançois Tigeot if (modes[n] == NULL) 12595718399fSFrançois Tigeot return best_score; 12605718399fSFrançois Tigeot 12615718399fSFrançois Tigeot crtcs = kmalloc(dev->mode_config.num_connector * 12625718399fSFrançois Tigeot sizeof(struct drm_fb_helper_crtc *), DRM_MEM_KMS, 12635718399fSFrançois Tigeot M_WAITOK | M_ZERO); 12645718399fSFrançois Tigeot 12655718399fSFrançois Tigeot my_score = 1; 12665718399fSFrançois Tigeot if (connector->status == connector_status_connected) 12675718399fSFrançois Tigeot my_score++; 12685718399fSFrançois Tigeot if (drm_has_cmdline_mode(fb_helper_conn)) 12695718399fSFrançois Tigeot my_score++; 12705718399fSFrançois Tigeot if (drm_has_preferred_mode(fb_helper_conn, width, height)) 12715718399fSFrançois Tigeot my_score++; 12725718399fSFrançois Tigeot 12735718399fSFrançois Tigeot connector_funcs = connector->helper_private; 12745718399fSFrançois Tigeot encoder = connector_funcs->best_encoder(connector); 12755718399fSFrançois Tigeot if (!encoder) 12765718399fSFrançois Tigeot goto out; 12775718399fSFrançois Tigeot 12785718399fSFrançois Tigeot /* select a crtc for this connector and then attempt to configure 12795718399fSFrançois Tigeot remaining connectors */ 12805718399fSFrançois Tigeot for (c = 0; c < fb_helper->crtc_count; c++) { 12815718399fSFrançois Tigeot crtc = &fb_helper->crtc_info[c]; 12825718399fSFrançois Tigeot 12835718399fSFrançois Tigeot if ((encoder->possible_crtcs & (1 << c)) == 0) { 12845718399fSFrançois Tigeot continue; 12855718399fSFrançois Tigeot } 12865718399fSFrançois Tigeot 12875718399fSFrançois Tigeot for (o = 0; o < n; o++) 12885718399fSFrançois Tigeot if (best_crtcs[o] == crtc) 12895718399fSFrançois Tigeot break; 12905718399fSFrançois Tigeot 12915718399fSFrançois Tigeot if (o < n) { 12925718399fSFrançois Tigeot /* ignore cloning unless only a single crtc */ 12935718399fSFrançois Tigeot if (fb_helper->crtc_count > 1) 12945718399fSFrançois Tigeot continue; 12955718399fSFrançois Tigeot 12965718399fSFrançois Tigeot if (!drm_mode_equal(modes[o], modes[n])) 12975718399fSFrançois Tigeot continue; 12985718399fSFrançois Tigeot } 12995718399fSFrançois Tigeot 13005718399fSFrançois Tigeot crtcs[n] = crtc; 13015718399fSFrançois Tigeot memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *)); 13025718399fSFrançois Tigeot score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1, 13035718399fSFrançois Tigeot width, height); 13045718399fSFrançois Tigeot if (score > best_score) { 13055718399fSFrançois Tigeot best_crtc = crtc; 13065718399fSFrançois Tigeot best_score = score; 13075718399fSFrançois Tigeot memcpy(best_crtcs, crtcs, 13085718399fSFrançois Tigeot dev->mode_config.num_connector * 13095718399fSFrançois Tigeot sizeof(struct drm_fb_helper_crtc *)); 13105718399fSFrançois Tigeot } 13115718399fSFrançois Tigeot } 13125718399fSFrançois Tigeot out: 13135718399fSFrançois Tigeot drm_free(crtcs, DRM_MEM_KMS); 13145718399fSFrançois Tigeot return best_score; 13155718399fSFrançois Tigeot } 13165718399fSFrançois Tigeot 13175718399fSFrançois Tigeot static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) 13185718399fSFrançois Tigeot { 13195718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 13205718399fSFrançois Tigeot struct drm_fb_helper_crtc **crtcs; 13215718399fSFrançois Tigeot struct drm_display_mode **modes; 13225718399fSFrançois Tigeot struct drm_encoder *encoder; 13235718399fSFrançois Tigeot struct drm_mode_set *modeset; 13245718399fSFrançois Tigeot bool *enabled; 13255718399fSFrançois Tigeot int width, height; 13265718399fSFrançois Tigeot int i, ret; 13275718399fSFrançois Tigeot 13285718399fSFrançois Tigeot DRM_DEBUG_KMS("\n"); 13295718399fSFrançois Tigeot 13305718399fSFrançois Tigeot width = dev->mode_config.max_width; 13315718399fSFrançois Tigeot height = dev->mode_config.max_height; 13325718399fSFrançois Tigeot 13335718399fSFrançois Tigeot /* clean out all the encoder/crtc combos */ 13345718399fSFrançois Tigeot list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 13355718399fSFrançois Tigeot encoder->crtc = NULL; 13365718399fSFrançois Tigeot } 13375718399fSFrançois Tigeot 13385718399fSFrançois Tigeot crtcs = kmalloc(dev->mode_config.num_connector * 13395718399fSFrançois Tigeot sizeof(struct drm_fb_helper_crtc *), DRM_MEM_KMS, 13405718399fSFrançois Tigeot M_WAITOK | M_ZERO); 13415718399fSFrançois Tigeot modes = kmalloc(dev->mode_config.num_connector * 13425718399fSFrançois Tigeot sizeof(struct drm_display_mode *), DRM_MEM_KMS, 13435718399fSFrançois Tigeot M_WAITOK | M_ZERO); 13445718399fSFrançois Tigeot enabled = kmalloc(dev->mode_config.num_connector * 13455718399fSFrançois Tigeot sizeof(bool), DRM_MEM_KMS, M_WAITOK | M_ZERO); 13465718399fSFrançois Tigeot 13475718399fSFrançois Tigeot drm_enable_connectors(fb_helper, enabled); 13485718399fSFrançois Tigeot 13495718399fSFrançois Tigeot ret = drm_target_cloned(fb_helper, modes, enabled, width, height); 13505718399fSFrançois Tigeot if (!ret) { 13515718399fSFrançois Tigeot ret = drm_target_preferred(fb_helper, modes, enabled, width, height); 13525718399fSFrançois Tigeot if (!ret) 13535718399fSFrançois Tigeot DRM_ERROR("Unable to find initial modes\n"); 13545718399fSFrançois Tigeot } 13555718399fSFrançois Tigeot 13565718399fSFrançois Tigeot DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height); 13575718399fSFrançois Tigeot 13585718399fSFrançois Tigeot drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height); 13595718399fSFrançois Tigeot 13605718399fSFrançois Tigeot /* need to set the modesets up here for use later */ 13615718399fSFrançois Tigeot /* fill out the connector<->crtc mappings into the modesets */ 13625718399fSFrançois Tigeot for (i = 0; i < fb_helper->crtc_count; i++) { 13635718399fSFrançois Tigeot modeset = &fb_helper->crtc_info[i].mode_set; 13645718399fSFrançois Tigeot modeset->num_connectors = 0; 13655718399fSFrançois Tigeot } 13665718399fSFrançois Tigeot 13675718399fSFrançois Tigeot for (i = 0; i < fb_helper->connector_count; i++) { 13685718399fSFrançois Tigeot struct drm_display_mode *mode = modes[i]; 13695718399fSFrançois Tigeot struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; 13705718399fSFrançois Tigeot modeset = &fb_crtc->mode_set; 13715718399fSFrançois Tigeot 13725718399fSFrançois Tigeot if (mode && fb_crtc) { 13735718399fSFrançois Tigeot DRM_DEBUG_KMS("desired mode %s set on crtc %d\n", 13745718399fSFrançois Tigeot mode->name, fb_crtc->mode_set.crtc->base.id); 13755718399fSFrançois Tigeot fb_crtc->desired_mode = mode; 13765718399fSFrançois Tigeot if (modeset->mode) 13775718399fSFrançois Tigeot drm_mode_destroy(dev, modeset->mode); 13785718399fSFrançois Tigeot modeset->mode = drm_mode_duplicate(dev, 13795718399fSFrançois Tigeot fb_crtc->desired_mode); 13805718399fSFrançois Tigeot modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector; 13815718399fSFrançois Tigeot } 13825718399fSFrançois Tigeot } 13835718399fSFrançois Tigeot 13845718399fSFrançois Tigeot drm_free(crtcs, DRM_MEM_KMS); 13855718399fSFrançois Tigeot drm_free(modes, DRM_MEM_KMS); 13865718399fSFrançois Tigeot drm_free(enabled, DRM_MEM_KMS); 13875718399fSFrançois Tigeot } 13885718399fSFrançois Tigeot 13895718399fSFrançois Tigeot /** 13905718399fSFrançois Tigeot * drm_helper_initial_config - setup a sane initial connector configuration 13915718399fSFrançois Tigeot * @dev: DRM device 13925718399fSFrançois Tigeot * 13935718399fSFrançois Tigeot * LOCKING: 13945718399fSFrançois Tigeot * Called at init time, must take mode config lock. 13955718399fSFrançois Tigeot * 13965718399fSFrançois Tigeot * Scan the CRTCs and connectors and try to put together an initial setup. 13975718399fSFrançois Tigeot * At the moment, this is a cloned configuration across all heads with 13985718399fSFrançois Tigeot * a new framebuffer object as the backing store. 13995718399fSFrançois Tigeot * 14005718399fSFrançois Tigeot * RETURNS: 14015718399fSFrançois Tigeot * Zero if everything went ok, nonzero otherwise. 14025718399fSFrançois Tigeot */ 14035718399fSFrançois Tigeot bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel) 14045718399fSFrançois Tigeot { 14055718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 14065718399fSFrançois Tigeot int count = 0; 14075718399fSFrançois Tigeot 14085718399fSFrançois Tigeot /* disable all the possible outputs/crtcs before entering KMS mode */ 14095718399fSFrançois Tigeot drm_helper_disable_unused_functions(fb_helper->dev); 14105718399fSFrançois Tigeot 14115718399fSFrançois Tigeot drm_fb_helper_parse_command_line(fb_helper); 14125718399fSFrançois Tigeot 14135718399fSFrançois Tigeot count = drm_fb_helper_probe_connector_modes(fb_helper, 14145718399fSFrançois Tigeot dev->mode_config.max_width, 14155718399fSFrançois Tigeot dev->mode_config.max_height); 14165718399fSFrançois Tigeot /* 14175718399fSFrançois Tigeot * we shouldn't end up with no modes here. 14185718399fSFrançois Tigeot */ 14195718399fSFrançois Tigeot if (count == 0) { 14205718399fSFrançois Tigeot kprintf("No connectors reported connected with modes\n"); 14215718399fSFrançois Tigeot } 14225718399fSFrançois Tigeot drm_setup_crtcs(fb_helper); 14235718399fSFrançois Tigeot 14245718399fSFrançois Tigeot return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); 14255718399fSFrançois Tigeot } 14265718399fSFrançois Tigeot 14275718399fSFrançois Tigeot int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) 14285718399fSFrançois Tigeot { 14295718399fSFrançois Tigeot struct drm_device *dev = fb_helper->dev; 14305718399fSFrançois Tigeot int count = 0; 14315718399fSFrançois Tigeot u32 max_width, max_height, bpp_sel; 14325718399fSFrançois Tigeot bool bound = false, crtcs_bound = false; 14335718399fSFrançois Tigeot struct drm_crtc *crtc; 14345718399fSFrançois Tigeot 14355718399fSFrançois Tigeot if (!fb_helper->fb) 14365718399fSFrançois Tigeot return 0; 14375718399fSFrançois Tigeot 1438af4b81b9SFrançois Tigeot lockmgr(&dev->mode_config.mutex, LK_EXCLUSIVE); 14395718399fSFrançois Tigeot list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 14405718399fSFrançois Tigeot if (crtc->fb) 14415718399fSFrançois Tigeot crtcs_bound = true; 14425718399fSFrançois Tigeot if (crtc->fb == fb_helper->fb) 14435718399fSFrançois Tigeot bound = true; 14445718399fSFrançois Tigeot } 14455718399fSFrançois Tigeot 14465718399fSFrançois Tigeot if (!bound && crtcs_bound) { 14475718399fSFrançois Tigeot fb_helper->delayed_hotplug = true; 1448af4b81b9SFrançois Tigeot lockmgr(&dev->mode_config.mutex, LK_RELEASE); 14495718399fSFrançois Tigeot return 0; 14505718399fSFrançois Tigeot } 14515718399fSFrançois Tigeot DRM_DEBUG_KMS("\n"); 14525718399fSFrançois Tigeot 14535718399fSFrançois Tigeot max_width = fb_helper->fb->width; 14545718399fSFrançois Tigeot max_height = fb_helper->fb->height; 14555718399fSFrançois Tigeot bpp_sel = fb_helper->fb->bits_per_pixel; 14565718399fSFrançois Tigeot 14575718399fSFrançois Tigeot count = drm_fb_helper_probe_connector_modes(fb_helper, max_width, 14585718399fSFrançois Tigeot max_height); 14595718399fSFrançois Tigeot drm_setup_crtcs(fb_helper); 1460af4b81b9SFrançois Tigeot lockmgr(&dev->mode_config.mutex, LK_RELEASE); 14615718399fSFrançois Tigeot 14625718399fSFrançois Tigeot return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); 14635718399fSFrançois Tigeot } 14645718399fSFrançois Tigeot 1465