Subversion Repositories Kolibri OS

Rev

Rev 5060 | Rev 5367 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4560 Serge 1
/*
2
 * Copyright © 2007 David Airlie
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 * and/or sell copies of the Software, and to permit persons to whom the
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice (including the next
12
 * paragraph) shall be included in all copies or substantial portions of the
13
 * Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 * Authors:
24
 *     David Airlie
25
 */
26
 
5354 serge 27
#include 
4560 Serge 28
#include 
29
#include 
30
#include 
31
#include 
32
//#include 
33
//#include 
34
#include 
5354 serge 35
#include 
4560 Serge 36
#include 
37
//#include 
38
//#include 
39
 
40
#include 
41
#include 
42
#include 
43
#include "intel_drv.h"
44
#include 
45
#include "i915_drv.h"
46
 
47
 
48
struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
49
{
50
#define BYTES_PER_LONG (BITS_PER_LONG/8)
51
#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
52
    int fb_info_size = sizeof(struct fb_info);
53
    struct fb_info *info;
54
    char *p;
55
 
56
    if (size)
57
        fb_info_size += PADDING;
58
 
59
    p = kzalloc(fb_info_size + size, GFP_KERNEL);
60
 
61
    if (!p)
62
        return NULL;
63
 
64
    info = (struct fb_info *) p;
65
 
66
    if (size)
67
        info->par = p + fb_info_size;
68
 
69
    return info;
70
#undef PADDING
71
#undef BYTES_PER_LONG
72
}
73
 
5354 serge 74
static int intel_fbdev_set_par(struct fb_info *info)
75
{
76
	struct drm_fb_helper *fb_helper = info->par;
77
	struct intel_fbdev *ifbdev =
78
		container_of(fb_helper, struct intel_fbdev, helper);
79
	int ret;
4560 Serge 80
 
5354 serge 81
	ret = drm_fb_helper_set_par(info);
82
 
83
	if (ret == 0) {
84
		/*
85
		 * FIXME: fbdev presumes that all callbacks also work from
86
		 * atomic contexts and relies on that for emergency oops
87
		 * printing. KMS totally doesn't do that and the locking here is
88
		 * by far not the only place this goes wrong.  Ignore this for
89
		 * now until we solve this for real.
90
		 */
91
		mutex_lock(&fb_helper->dev->struct_mutex);
92
		ret = i915_gem_object_set_to_gtt_domain(ifbdev->fb->obj,
93
							true);
94
		mutex_unlock(&fb_helper->dev->struct_mutex);
95
	}
96
 
97
	return ret;
98
}
99
 
4560 Serge 100
static struct fb_ops intelfb_ops = {
101
	.owner = THIS_MODULE,
102
	.fb_check_var = drm_fb_helper_check_var,
5354 serge 103
	.fb_set_par = intel_fbdev_set_par,
4560 Serge 104
//   .fb_fillrect = cfb_fillrect,
105
//   .fb_copyarea = cfb_copyarea,
106
//   .fb_imageblit = cfb_imageblit,
107
//   .fb_pan_display = drm_fb_helper_pan_display,
108
	.fb_blank = drm_fb_helper_blank,
109
//   .fb_setcmap = drm_fb_helper_setcmap,
110
//   .fb_debug_enter = drm_fb_helper_debug_enter,
111
//   .fb_debug_leave = drm_fb_helper_debug_leave,
112
};
113
 
114
static int intelfb_alloc(struct drm_fb_helper *helper,
115
			  struct drm_fb_helper_surface_size *sizes)
116
{
117
	struct intel_fbdev *ifbdev =
118
		container_of(helper, struct intel_fbdev, helper);
5060 serge 119
	struct drm_framebuffer *fb;
4560 Serge 120
	struct drm_device *dev = helper->dev;
121
	struct drm_mode_fb_cmd2 mode_cmd = {};
122
	struct drm_i915_gem_object *obj;
123
	int size, ret;
124
 
125
	/* we don't do packed 24bpp */
126
	if (sizes->surface_bpp == 24)
127
		sizes->surface_bpp = 32;
128
 
129
	mode_cmd.width = sizes->surface_width;
130
	mode_cmd.height = sizes->surface_height;
131
 
5354 serge 132
	mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
133
				    DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
4560 Serge 134
	mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
135
							  sizes->surface_depth);
136
 
137
	size = mode_cmd.pitches[0] * mode_cmd.height;
138
	size = ALIGN(size, PAGE_SIZE);
139
	obj = main_fb_obj;
5354 serge 140
    obj->stride = mode_cmd.pitches[0];
4560 Serge 141
	if (!obj) {
142
		DRM_ERROR("failed to allocate framebuffer\n");
143
		ret = -ENOMEM;
144
		goto out;
145
	}
146
 
5354 serge 147
	fb = __intel_framebuffer_create(dev, &mode_cmd, obj);
148
	if (IS_ERR(fb)) {
149
		ret = PTR_ERR(fb);
150
		goto out_unref;
151
	}
152
 
4560 Serge 153
	/* Flush everything out, we'll be doing GTT only from now on */
5354 serge 154
	ret = intel_pin_and_fence_fb_obj(NULL, fb, NULL);
4560 Serge 155
	if (ret) {
5060 serge 156
		DRM_ERROR("failed to pin obj: %d\n", ret);
5354 serge 157
		goto out_fb;
4560 Serge 158
	}
159
 
5060 serge 160
	ifbdev->fb = to_intel_framebuffer(fb);
161
 
4560 Serge 162
	return 0;
163
 
5354 serge 164
out_fb:
165
	drm_framebuffer_remove(fb);
4560 Serge 166
out_unref:
167
	drm_gem_object_unreference(&obj->base);
168
out:
169
	return ret;
170
}
171
 
172
static int intelfb_create(struct drm_fb_helper *helper,
173
			  struct drm_fb_helper_surface_size *sizes)
174
{
175
	struct intel_fbdev *ifbdev =
176
		container_of(helper, struct intel_fbdev, helper);
5060 serge 177
	struct intel_framebuffer *intel_fb = ifbdev->fb;
4560 Serge 178
	struct drm_device *dev = helper->dev;
179
	struct drm_i915_private *dev_priv = dev->dev_private;
180
	struct fb_info *info;
181
	struct drm_framebuffer *fb;
182
	struct drm_i915_gem_object *obj;
183
	int size, ret;
5060 serge 184
	bool prealloc = false;
4560 Serge 185
 
186
	mutex_lock(&dev->struct_mutex);
187
 
5060 serge 188
	if (intel_fb &&
189
	    (sizes->fb_width > intel_fb->base.width ||
190
	     sizes->fb_height > intel_fb->base.height)) {
191
		DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d),"
192
			      " releasing it\n",
193
			      intel_fb->base.width, intel_fb->base.height,
194
			      sizes->fb_width, sizes->fb_height);
195
		drm_framebuffer_unreference(&intel_fb->base);
196
		intel_fb = ifbdev->fb = NULL;
197
	}
198
	if (!intel_fb || WARN_ON(!intel_fb->obj)) {
4560 Serge 199
		DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n");
200
		ret = intelfb_alloc(helper, sizes);
201
		if (ret)
202
			goto out_unlock;
5060 serge 203
		intel_fb = ifbdev->fb;
4560 Serge 204
	} else {
205
		DRM_DEBUG_KMS("re-using BIOS fb\n");
5060 serge 206
		prealloc = true;
4560 Serge 207
		sizes->fb_width = intel_fb->base.width;
208
		sizes->fb_height = intel_fb->base.height;
209
	}
210
 
211
	obj = intel_fb->obj;
212
	size = obj->base.size;
213
 
214
	info = framebuffer_alloc(0, &dev->pdev->dev);
215
	if (!info) {
216
		ret = -ENOMEM;
217
		goto out_unpin;
218
	}
219
 
220
	info->par = helper;
221
 
5060 serge 222
	fb = &ifbdev->fb->base;
4560 Serge 223
 
224
	ifbdev->helper.fb = fb;
225
	ifbdev->helper.fbdev = info;
226
 
227
    strcpy(info->fix.id, "inteldrmfb");
228
 
229
    info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
230
    info->fbops = &intelfb_ops;
231
 
232
    /* setup aperture base/size for vesafb takeover */
233
	info->apertures = alloc_apertures(1);
234
	if (!info->apertures) {
235
		ret = -ENOMEM;
236
		goto out_unpin;
237
	}
238
	info->apertures->ranges[0].base = dev->mode_config.fb_base;
239
	info->apertures->ranges[0].size = dev_priv->gtt.mappable_end;
240
 
241
 
242
	info->screen_base = (void*) 0xFE000000;
243
	info->screen_size = size;
244
 
245
	/* This driver doesn't need a VT switch to restore the mode on resume */
246
	info->skip_vt_switch = true;
247
 
248
	drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
249
	drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height);
250
 
251
	/* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
252
 
253
	DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n",
254
		      fb->width, fb->height,
255
		      i915_gem_obj_ggtt_offset(obj), obj);
256
 
257
	mutex_unlock(&dev->struct_mutex);
258
	return 0;
259
 
260
out_unpin:
5060 serge 261
	i915_gem_object_ggtt_unpin(obj);
4560 Serge 262
	drm_gem_object_unreference(&obj->base);
263
out_unlock:
264
	mutex_unlock(&dev->struct_mutex);
265
	return ret;
266
}
267
 
268
/** Sets the color ramps on behalf of RandR */
269
static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
270
				    u16 blue, int regno)
271
{
272
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
273
 
274
	intel_crtc->lut_r[regno] = red >> 8;
275
	intel_crtc->lut_g[regno] = green >> 8;
276
	intel_crtc->lut_b[regno] = blue >> 8;
277
}
278
 
279
static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
280
				    u16 *blue, int regno)
281
{
282
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
283
 
284
	*red = intel_crtc->lut_r[regno] << 8;
285
	*green = intel_crtc->lut_g[regno] << 8;
286
	*blue = intel_crtc->lut_b[regno] << 8;
287
}
288
 
5060 serge 289
static struct drm_fb_helper_crtc *
290
intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
291
{
292
	int i;
293
 
294
	for (i = 0; i < fb_helper->crtc_count; i++)
295
		if (fb_helper->crtc_info[i].mode_set.crtc == crtc)
296
			return &fb_helper->crtc_info[i];
297
 
298
	return NULL;
299
}
300
 
301
/*
302
 * Try to read the BIOS display configuration and use it for the initial
303
 * fb configuration.
304
 *
305
 * The BIOS or boot loader will generally create an initial display
306
 * configuration for us that includes some set of active pipes and displays.
307
 * This routine tries to figure out which pipes and connectors are active
308
 * and stuffs them into the crtcs and modes array given to us by the
309
 * drm_fb_helper code.
310
 *
311
 * The overall sequence is:
312
 *   intel_fbdev_init - from driver load
313
 *     intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data
314
 *     drm_fb_helper_init - build fb helper structs
315
 *     drm_fb_helper_single_add_all_connectors - more fb helper structs
316
 *   intel_fbdev_initial_config - apply the config
317
 *     drm_fb_helper_initial_config - call ->probe then register_framebuffer()
318
 *         drm_setup_crtcs - build crtc config for fbdev
319
 *           intel_fb_initial_config - find active connectors etc
320
 *         drm_fb_helper_single_fb_probe - set up fbdev
321
 *           intelfb_create - re-use or alloc fb, build out fbdev structs
322
 *
323
 * Note that we don't make special consideration whether we could actually
324
 * switch to the selected modes without a full modeset. E.g. when the display
325
 * is in VGA mode we need to recalculate watermarks and set a new high-res
326
 * framebuffer anyway.
327
 */
328
static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
329
				    struct drm_fb_helper_crtc **crtcs,
330
				    struct drm_display_mode **modes,
5354 serge 331
				    struct drm_fb_offset *offsets,
5060 serge 332
				    bool *enabled, int width, int height)
333
{
334
	struct drm_device *dev = fb_helper->dev;
335
	int i, j;
336
	bool *save_enabled;
337
	bool fallback = true;
338
	int num_connectors_enabled = 0;
339
	int num_connectors_detected = 0;
5354 serge 340
	uint64_t conn_configured = 0, mask;
341
	int pass = 0;
5060 serge 342
 
343
	save_enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool),
344
			       GFP_KERNEL);
345
	if (!save_enabled)
346
		return false;
347
 
348
	memcpy(save_enabled, enabled, dev->mode_config.num_connector);
5354 serge 349
	mask = (1 << fb_helper->connector_count) - 1;
350
retry:
5060 serge 351
	for (i = 0; i < fb_helper->connector_count; i++) {
352
		struct drm_fb_helper_connector *fb_conn;
353
		struct drm_connector *connector;
354
		struct drm_encoder *encoder;
355
		struct drm_fb_helper_crtc *new_crtc;
356
 
357
		fb_conn = fb_helper->connector_info[i];
358
		connector = fb_conn->connector;
359
 
5354 serge 360
		if (conn_configured & (1 << i))
361
			continue;
362
 
363
		if (pass == 0 && !connector->has_tile)
364
			continue;
365
 
5060 serge 366
		if (connector->status == connector_status_connected)
367
			num_connectors_detected++;
368
 
369
		if (!enabled[i]) {
370
			DRM_DEBUG_KMS("connector %s not enabled, skipping\n",
371
				      connector->name);
5354 serge 372
			conn_configured |= (1 << i);
5060 serge 373
			continue;
374
		}
375
 
5354 serge 376
		if (connector->force == DRM_FORCE_OFF) {
377
			DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n",
378
				      connector->name);
379
			enabled[i] = false;
380
			continue;
381
		}
382
 
5060 serge 383
		encoder = connector->encoder;
384
		if (!encoder || WARN_ON(!encoder->crtc)) {
5354 serge 385
			if (connector->force > DRM_FORCE_OFF)
386
				goto bail;
387
 
5060 serge 388
			DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n",
389
				      connector->name);
390
			enabled[i] = false;
5354 serge 391
			conn_configured |= (1 << i);
5060 serge 392
			continue;
393
		}
394
 
395
		num_connectors_enabled++;
396
 
397
		new_crtc = intel_fb_helper_crtc(fb_helper, encoder->crtc);
398
 
399
		/*
400
		 * Make sure we're not trying to drive multiple connectors
401
		 * with a single CRTC, since our cloning support may not
402
		 * match the BIOS.
403
		 */
404
		for (j = 0; j < fb_helper->connector_count; j++) {
405
			if (crtcs[j] == new_crtc) {
406
				DRM_DEBUG_KMS("fallback: cloned configuration\n");
5354 serge 407
				goto bail;
5060 serge 408
			}
409
		}
410
 
411
		DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n",
412
			      connector->name);
413
 
414
		/* go for command line mode first */
415
		modes[i] = drm_pick_cmdline_mode(fb_conn, width, height);
416
 
417
		/* try for preferred next */
418
		if (!modes[i]) {
5354 serge 419
			DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n",
420
				      connector->name, connector->has_tile);
5060 serge 421
			modes[i] = drm_has_preferred_mode(fb_conn, width,
422
							  height);
423
		}
424
 
425
		/* No preferred mode marked by the EDID? Are there any modes? */
426
		if (!modes[i] && !list_empty(&connector->modes)) {
427
			DRM_DEBUG_KMS("using first mode listed on connector %s\n",
428
				      connector->name);
429
			modes[i] = list_first_entry(&connector->modes,
430
						    struct drm_display_mode,
431
						    head);
432
		}
433
 
434
		/* last resort: use current mode */
435
		if (!modes[i]) {
436
			/*
437
			 * IMPORTANT: We want to use the adjusted mode (i.e.
438
			 * after the panel fitter upscaling) as the initial
439
			 * config, not the input mode, which is what crtc->mode
440
			 * usually contains. But since our current fastboot
441
			 * code puts a mode derived from the post-pfit timings
442
			 * into crtc->mode this works out correctly. We don't
443
			 * use hwmode anywhere right now, so use it for this
444
			 * since the fb helper layer wants a pointer to
445
			 * something we own.
446
			 */
447
			DRM_DEBUG_KMS("looking for current mode on connector %s\n",
448
				      connector->name);
449
			intel_mode_from_pipe_config(&encoder->crtc->hwmode,
450
						    &to_intel_crtc(encoder->crtc)->config);
451
			modes[i] = &encoder->crtc->hwmode;
452
		}
453
		crtcs[i] = new_crtc;
454
 
455
		DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n",
456
			      connector->name,
457
			      pipe_name(to_intel_crtc(encoder->crtc)->pipe),
458
			      encoder->crtc->base.id,
459
			      modes[i]->hdisplay, modes[i]->vdisplay,
460
			      modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :"");
461
 
462
		fallback = false;
5354 serge 463
		conn_configured |= (1 << i);
5060 serge 464
	}
465
 
5354 serge 466
	if ((conn_configured & mask) != mask) {
467
		pass++;
468
		goto retry;
469
	}
470
 
5060 serge 471
	/*
472
	 * If the BIOS didn't enable everything it could, fall back to have the
473
	 * same user experiencing of lighting up as much as possible like the
474
	 * fbdev helper library.
475
	 */
476
	if (num_connectors_enabled != num_connectors_detected &&
477
	    num_connectors_enabled < INTEL_INFO(dev)->num_pipes) {
478
		DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
479
		DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled,
480
			      num_connectors_detected);
481
		fallback = true;
482
	}
483
 
484
	if (fallback) {
5354 serge 485
bail:
5060 serge 486
		DRM_DEBUG_KMS("Not using firmware configuration\n");
487
		memcpy(enabled, save_enabled, dev->mode_config.num_connector);
488
		kfree(save_enabled);
489
		return false;
490
	}
491
 
492
	kfree(save_enabled);
493
	return true;
494
}
495
 
496
static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
497
	.initial_config = intel_fb_initial_config,
4560 Serge 498
	.gamma_set = intel_crtc_fb_gamma_set,
499
	.gamma_get = intel_crtc_fb_gamma_get,
500
	.fb_probe = intelfb_create,
501
};
502
 
5060 serge 503
/*
504
 * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
505
 * The core display code will have read out the current plane configuration,
506
 * so we use that to figure out if there's an object for us to use as the
507
 * fb, and if so, we re-use it for the fbdev configuration.
508
 *
509
 * Note we only support a single fb shared across pipes for boot (mostly for
510
 * fbcon), so we just find the biggest and use that.
511
 */
512
static bool intel_fbdev_init_bios(struct drm_device *dev,
513
				 struct intel_fbdev *ifbdev)
514
{
515
	struct intel_framebuffer *fb = NULL;
516
	struct drm_crtc *crtc;
517
	struct intel_crtc *intel_crtc;
518
	struct intel_plane_config *plane_config = NULL;
519
	unsigned int max_size = 0;
4560 Serge 520
 
5060 serge 521
	if (!i915.fastboot)
522
		return false;
523
 
524
	/* Find the largest fb */
525
	for_each_crtc(dev, crtc) {
526
		intel_crtc = to_intel_crtc(crtc);
527
 
528
		if (!intel_crtc->active || !crtc->primary->fb) {
529
			DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n",
530
				      pipe_name(intel_crtc->pipe));
531
			continue;
532
		}
533
 
534
		if (intel_crtc->plane_config.size > max_size) {
535
			DRM_DEBUG_KMS("found possible fb from plane %c\n",
536
				      pipe_name(intel_crtc->pipe));
537
			plane_config = &intel_crtc->plane_config;
538
			fb = to_intel_framebuffer(crtc->primary->fb);
539
			max_size = plane_config->size;
540
		}
541
	}
542
 
543
	if (!fb) {
544
		DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n");
545
		goto out;
546
	}
547
 
548
	/* Now make sure all the pipes will fit into it */
549
	for_each_crtc(dev, crtc) {
550
		unsigned int cur_size;
551
 
552
		intel_crtc = to_intel_crtc(crtc);
553
 
554
		if (!intel_crtc->active) {
555
			DRM_DEBUG_KMS("pipe %c not active, skipping\n",
556
				      pipe_name(intel_crtc->pipe));
557
			continue;
558
		}
559
 
560
		DRM_DEBUG_KMS("checking plane %c for BIOS fb\n",
561
			      pipe_name(intel_crtc->pipe));
562
 
563
		/*
564
		 * See if the plane fb we found above will fit on this
565
		 * pipe.  Note we need to use the selected fb's pitch and bpp
566
		 * rather than the current pipe's, since they differ.
567
		 */
568
		cur_size = intel_crtc->config.adjusted_mode.crtc_hdisplay;
569
		cur_size = cur_size * fb->base.bits_per_pixel / 8;
570
		if (fb->base.pitches[0] < cur_size) {
571
			DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n",
572
				      pipe_name(intel_crtc->pipe),
573
				      cur_size, fb->base.pitches[0]);
574
			plane_config = NULL;
575
			fb = NULL;
576
			break;
577
		}
578
 
579
		cur_size = intel_crtc->config.adjusted_mode.crtc_vdisplay;
580
		cur_size = ALIGN(cur_size, plane_config->tiled ? (IS_GEN2(dev) ? 16 : 8) : 1);
581
		cur_size *= fb->base.pitches[0];
582
		DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n",
583
			      pipe_name(intel_crtc->pipe),
584
			      intel_crtc->config.adjusted_mode.crtc_hdisplay,
585
			      intel_crtc->config.adjusted_mode.crtc_vdisplay,
586
			      fb->base.bits_per_pixel,
587
			      cur_size);
588
 
589
		if (cur_size > max_size) {
590
			DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n",
591
				      pipe_name(intel_crtc->pipe),
592
				      cur_size, max_size);
593
			plane_config = NULL;
594
			fb = NULL;
595
			break;
596
		}
597
 
598
		DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n",
599
			      pipe_name(intel_crtc->pipe),
600
			      max_size, cur_size);
601
	}
602
 
603
	if (!fb) {
604
		DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n");
605
		goto out;
606
	}
607
 
608
	ifbdev->preferred_bpp = fb->base.bits_per_pixel;
609
	ifbdev->fb = fb;
610
 
611
	drm_framebuffer_reference(&ifbdev->fb->base);
612
 
613
	/* Final pass to check if any active pipes don't have fbs */
614
	for_each_crtc(dev, crtc) {
615
		intel_crtc = to_intel_crtc(crtc);
616
 
617
		if (!intel_crtc->active)
618
			continue;
619
 
620
		WARN(!crtc->primary->fb,
621
		     "re-used BIOS config but lost an fb on crtc %d\n",
622
		     crtc->base.id);
623
	}
624
 
625
 
626
	DRM_DEBUG_KMS("using BIOS fb for initial console\n");
627
	return true;
628
 
629
out:
630
 
631
	return false;
632
}
633
 
4560 Serge 634
int intel_fbdev_init(struct drm_device *dev)
635
{
636
	struct intel_fbdev *ifbdev;
637
	struct drm_i915_private *dev_priv = dev->dev_private;
638
	int ret;
639
 
5060 serge 640
	if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0))
641
		return -ENODEV;
642
 
643
	ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
644
	if (ifbdev == NULL)
4560 Serge 645
		return -ENOMEM;
646
 
5060 serge 647
	drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs);
4560 Serge 648
 
5060 serge 649
	if (!intel_fbdev_init_bios(dev, ifbdev))
650
		ifbdev->preferred_bpp = 32;
651
 
4560 Serge 652
	ret = drm_fb_helper_init(dev, &ifbdev->helper,
5060 serge 653
				 INTEL_INFO(dev)->num_pipes, 4);
4560 Serge 654
	if (ret) {
655
		kfree(ifbdev);
656
		return ret;
657
	}
658
 
5060 serge 659
	dev_priv->fbdev = ifbdev;
4560 Serge 660
	drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
661
 
662
    return 0;
663
}
664
 
5354 serge 665
void intel_fbdev_initial_config(void *data, async_cookie_t cookie)
4560 Serge 666
{
5354 serge 667
	struct drm_i915_private *dev_priv = data;
5060 serge 668
	struct intel_fbdev *ifbdev = dev_priv->fbdev;
4560 Serge 669
 
670
	/* Due to peculiar init order wrt to hpd handling this is separate. */
5060 serge 671
	drm_fb_helper_initial_config(&ifbdev->helper, ifbdev->preferred_bpp);
4560 Serge 672
}
673
 
674
 
675
void intel_fbdev_output_poll_changed(struct drm_device *dev)
676
{
677
	struct drm_i915_private *dev_priv = dev->dev_private;
5060 serge 678
	if (dev_priv->fbdev)
679
		drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper);
4560 Serge 680
}