1/*
2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
4 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
5 *
6 * DRM framebuffer helper functions
7 *
8 * Permission to use, copy, modify, distribute, and sell this software and its
--- 15 unchanged lines hidden (view full) ---
24 * OF THIS SOFTWARE.
25 *
26 * Authors:
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/drm2/drm_fb_helper.c 259016 2013-12-05 22:38:53Z ray $");
33
34#include <dev/drm2/drmP.h>
35#include <dev/drm2/drm_crtc.h>
36#include <dev/drm2/drm_fb_helper.h>
37#include <dev/drm2/drm_crtc_helper.h>
38
39#if defined(__FreeBSD__)
40struct vt_kms_softc {
41 struct drm_fb_helper *fb_helper;
42 struct task fb_mode_task;
43};
44
45static fb_enter_t vt_kms_postswitch;
46static void vt_restore_fbdev_mode(void *, int);
47
48/* Call restore out of vt(9) locks. */
49static void
50vt_restore_fbdev_mode(void *arg, int pending)
51{
52 struct drm_fb_helper *fb_helper;
53 struct vt_kms_softc *sc;
54
55 sc = (struct vt_kms_softc *)arg;
56 fb_helper = sc->fb_helper;
57 sx_xlock(&fb_helper->dev->mode_config.mutex);
58 drm_fb_helper_restore_fbdev_mode(fb_helper);
59 sx_xunlock(&fb_helper->dev->mode_config.mutex);
60}
61
62static int
63vt_kms_postswitch(void *arg)
64{
65 struct vt_kms_softc *sc;
66
67 sc = (struct vt_kms_softc *)arg;
68 taskqueue_enqueue_fast(taskqueue_thread, &sc->fb_mode_task);
69
70 return (0);
71}
72#endif
73
74static DRM_LIST_HEAD(kernel_fb_helper_list);
75
76/* simple single crtc case helper function */
77int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
78{
79 struct drm_device *dev = fb_helper->dev;
80 struct drm_connector *connector;
81
--- 164 unchanged lines hidden (view full) ---
246
247 return true;
248}
249
250static int
251fb_get_options(const char *connector_name, char **option)
252{
253
254 /*
255 * TODO: store mode options pointer in ${option} for connector with
256 * name ${connector_name}
257 */
258 return (1);
259}
260
261static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
262{
263 struct drm_fb_helper_connector *fb_helper_conn;
264 int i;
265
--- 660 unchanged lines hidden (view full) ---
926#endif
927
928int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
929 int preferred_bpp)
930{
931 int new_fb = 0;
932 int crtc_count = 0;
933 int i;
934 struct fb_info *info;
935 struct drm_fb_helper_surface_size sizes;
936 int gamma_size = 0;
937#if defined(__FreeBSD__)
938 struct vt_kms_softc *sc;
939 device_t kdev;
940#endif
941
942 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
943 sizes.surface_depth = 24;
944 sizes.surface_bpp = 32;
945 sizes.fb_width = (unsigned)-1;
946 sizes.fb_height = (unsigned)-1;
947
948 /* if driver picks 8 or 16 by default use that
--- 60 unchanged lines hidden (view full) ---
1009 sizes.fb_height = sizes.surface_height = 768;
1010 }
1011
1012 /* push down into drivers */
1013 new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1014 if (new_fb < 0)
1015 return new_fb;
1016
1017#if defined(__FreeBSD__)
1018 sc = malloc(sizeof(struct vt_kms_softc), DRM_MEM_KMS,
1019 M_WAITOK | M_ZERO);
1020 sc->fb_helper = fb_helper;
1021 TASK_INIT(&sc->fb_mode_task, 0, vt_restore_fbdev_mode, sc);
1022
1023 info = fb_helper->fbdev;
1024
1025 info->fb_name = device_get_nameunit(fb_helper->dev->device);
1026 info->fb_depth = fb_helper->fb->bits_per_pixel;
1027 info->fb_height = fb_helper->fb->height;
1028 info->fb_width = fb_helper->fb->width;
1029 info->fb_stride = fb_helper->fb->pitches[0];
1030 info->fb_priv = sc;
1031 info->enter = &vt_kms_postswitch;
1032#endif
1033
1034 /* set the fb pointer */
1035 for (i = 0; i < fb_helper->crtc_count; i++) {
1036 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1037 }
1038
1039#if defined(__FreeBSD__)
1040 if (new_fb) {
1041 device_t fbd;
1042 int ret;
1043
1044 kdev = fb_helper->dev->device;
1045 fbd = device_add_child(kdev, "fbd", device_get_unit(kdev));
1046 ret = device_probe_and_attach(fbd);
1047 if (ret != 0)
1048 DRM_ERROR("Failed to attach fbd device: %d\n", ret);
1049 }
1050#else
1051 if (new_fb) {
1052 info->var.pixclock = 0;
1053 if (register_framebuffer(info) < 0) {
1054 return -EINVAL;
1055 }
1056
1057 printf("fb%d: %s frame buffer device\n", info->node,
1058 info->fix.id);
1059
--- 6 unchanged lines hidden (view full) ---
1066 if (list_empty(&kernel_fb_helper_list)) {
1067 printf("drm: registered panic notifier\n");
1068 atomic_notifier_chain_register(&panic_notifier_list,
1069 &paniced);
1070 }
1071 if (new_fb)
1072 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
1073#endif
1074 return 0;
1075}
1076
1077#if 0
1078void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1079 uint32_t depth)
1080{
1081 info->fix.type = FB_TYPE_PACKED_PIXELS;
--- 554 unchanged lines hidden ---
2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
4 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
5 *
6 * DRM framebuffer helper functions
7 *
8 * Permission to use, copy, modify, distribute, and sell this software and its
--- 15 unchanged lines hidden (view full) ---
24 * OF THIS SOFTWARE.
25 *
26 * Authors:
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/drm2/drm_fb_helper.c 259016 2013-12-05 22:38:53Z ray $");
33
34#include <dev/drm2/drmP.h>
35#include <dev/drm2/drm_crtc.h>
36#include <dev/drm2/drm_fb_helper.h>
37#include <dev/drm2/drm_crtc_helper.h>
38
39#if defined(__FreeBSD__)
40struct vt_kms_softc {
41 struct drm_fb_helper *fb_helper;
42 struct task fb_mode_task;
43};
44
45static fb_enter_t vt_kms_postswitch;
46static void vt_restore_fbdev_mode(void *, int);
47
48/* Call restore out of vt(9) locks. */
49static void
50vt_restore_fbdev_mode(void *arg, int pending)
51{
52 struct drm_fb_helper *fb_helper;
53 struct vt_kms_softc *sc;
54
55 sc = (struct vt_kms_softc *)arg;
56 fb_helper = sc->fb_helper;
57 sx_xlock(&fb_helper->dev->mode_config.mutex);
58 drm_fb_helper_restore_fbdev_mode(fb_helper);
59 sx_xunlock(&fb_helper->dev->mode_config.mutex);
60}
61
62static int
63vt_kms_postswitch(void *arg)
64{
65 struct vt_kms_softc *sc;
66
67 sc = (struct vt_kms_softc *)arg;
68 taskqueue_enqueue_fast(taskqueue_thread, &sc->fb_mode_task);
69
70 return (0);
71}
72#endif
73
74static DRM_LIST_HEAD(kernel_fb_helper_list);
75
76/* simple single crtc case helper function */
77int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
78{
79 struct drm_device *dev = fb_helper->dev;
80 struct drm_connector *connector;
81
--- 164 unchanged lines hidden (view full) ---
246
247 return true;
248}
249
250static int
251fb_get_options(const char *connector_name, char **option)
252{
253
254 /*
255 * TODO: store mode options pointer in ${option} for connector with
256 * name ${connector_name}
257 */
258 return (1);
259}
260
261static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
262{
263 struct drm_fb_helper_connector *fb_helper_conn;
264 int i;
265
--- 660 unchanged lines hidden (view full) ---
926#endif
927
928int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
929 int preferred_bpp)
930{
931 int new_fb = 0;
932 int crtc_count = 0;
933 int i;
934 struct fb_info *info;
935 struct drm_fb_helper_surface_size sizes;
936 int gamma_size = 0;
937#if defined(__FreeBSD__)
938 struct vt_kms_softc *sc;
939 device_t kdev;
940#endif
941
942 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
943 sizes.surface_depth = 24;
944 sizes.surface_bpp = 32;
945 sizes.fb_width = (unsigned)-1;
946 sizes.fb_height = (unsigned)-1;
947
948 /* if driver picks 8 or 16 by default use that
--- 60 unchanged lines hidden (view full) ---
1009 sizes.fb_height = sizes.surface_height = 768;
1010 }
1011
1012 /* push down into drivers */
1013 new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1014 if (new_fb < 0)
1015 return new_fb;
1016
1017#if defined(__FreeBSD__)
1018 sc = malloc(sizeof(struct vt_kms_softc), DRM_MEM_KMS,
1019 M_WAITOK | M_ZERO);
1020 sc->fb_helper = fb_helper;
1021 TASK_INIT(&sc->fb_mode_task, 0, vt_restore_fbdev_mode, sc);
1022
1023 info = fb_helper->fbdev;
1024
1025 info->fb_name = device_get_nameunit(fb_helper->dev->device);
1026 info->fb_depth = fb_helper->fb->bits_per_pixel;
1027 info->fb_height = fb_helper->fb->height;
1028 info->fb_width = fb_helper->fb->width;
1029 info->fb_stride = fb_helper->fb->pitches[0];
1030 info->fb_priv = sc;
1031 info->enter = &vt_kms_postswitch;
1032#endif
1033
1034 /* set the fb pointer */
1035 for (i = 0; i < fb_helper->crtc_count; i++) {
1036 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1037 }
1038
1039#if defined(__FreeBSD__)
1040 if (new_fb) {
1041 device_t fbd;
1042 int ret;
1043
1044 kdev = fb_helper->dev->device;
1045 fbd = device_add_child(kdev, "fbd", device_get_unit(kdev));
1046 ret = device_probe_and_attach(fbd);
1047 if (ret != 0)
1048 DRM_ERROR("Failed to attach fbd device: %d\n", ret);
1049 }
1050#else
1051 if (new_fb) {
1052 info->var.pixclock = 0;
1053 if (register_framebuffer(info) < 0) {
1054 return -EINVAL;
1055 }
1056
1057 printf("fb%d: %s frame buffer device\n", info->node,
1058 info->fix.id);
1059
--- 6 unchanged lines hidden (view full) ---
1066 if (list_empty(&kernel_fb_helper_list)) {
1067 printf("drm: registered panic notifier\n");
1068 atomic_notifier_chain_register(&panic_notifier_list,
1069 &paniced);
1070 }
1071 if (new_fb)
1072 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
1073#endif
1074 return 0;
1075}
1076
1077#if 0
1078void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1079 uint32_t depth)
1080{
1081 info->fix.type = FB_TYPE_PACKED_PIXELS;
--- 554 unchanged lines hidden ---