Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2332 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
 
27
#include 
28
#include 
29
#include 
30
#include 
31
//#include 
32
//#include 
33
#include 
34
//#include 
35
#include 
36
//#include 
37
//#include 
38
 
3031 serge 39
#include 
40
#include 
41
#include 
2332 Serge 42
#include "intel_drv.h"
3031 serge 43
#include 
2332 Serge 44
#include "i915_drv.h"
45
 
3263 Serge 46
static struct drm_i915_gem_object *fb_obj;
2332 Serge 47
 
3263 Serge 48
struct drm_i915_gem_object *get_fb_obj()
49
{
50
    return fb_obj;
51
};
52
 
2335 Serge 53
struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
54
{
55
#define BYTES_PER_LONG (BITS_PER_LONG/8)
56
#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
57
    int fb_info_size = sizeof(struct fb_info);
58
    struct fb_info *info;
59
    char *p;
60
 
61
    if (size)
62
        fb_info_size += PADDING;
63
 
64
    p = kzalloc(fb_info_size + size, GFP_KERNEL);
65
 
66
    if (!p)
67
        return NULL;
68
 
69
    info = (struct fb_info *) p;
70
 
71
    if (size)
72
        info->par = p + fb_info_size;
73
 
74
    return info;
75
#undef PADDING
76
#undef BYTES_PER_LONG
77
}
78
 
79
 
80
static struct fb_ops intelfb_ops = {
3031 serge 81
	.owner = THIS_MODULE,
2335 Serge 82
	.fb_check_var = drm_fb_helper_check_var,
83
	.fb_set_par = drm_fb_helper_set_par,
84
//   .fb_fillrect = cfb_fillrect,
85
//   .fb_copyarea = cfb_copyarea,
86
//   .fb_imageblit = cfb_imageblit,
87
//   .fb_pan_display = drm_fb_helper_pan_display,
88
	.fb_blank = drm_fb_helper_blank,
89
//   .fb_setcmap = drm_fb_helper_setcmap,
90
//   .fb_debug_enter = drm_fb_helper_debug_enter,
91
//   .fb_debug_leave = drm_fb_helper_debug_leave,
92
};
93
 
94
static int intelfb_create(struct intel_fbdev *ifbdev,
95
			  struct drm_fb_helper_surface_size *sizes)
96
{
97
	struct drm_device *dev = ifbdev->helper.dev;
98
	struct drm_i915_private *dev_priv = dev->dev_private;
99
	struct fb_info *info;
100
	struct drm_framebuffer *fb;
3031 serge 101
	struct drm_mode_fb_cmd2 mode_cmd = {};
2335 Serge 102
	struct drm_i915_gem_object *obj;
103
	struct device *device = &dev->pdev->dev;
104
	int size, ret;
105
 
106
	/* we don't do packed 24bpp */
107
	if (sizes->surface_bpp == 24)
108
		sizes->surface_bpp = 32;
109
 
110
	mode_cmd.width = sizes->surface_width;
111
	mode_cmd.height = sizes->surface_height;
112
 
2342 Serge 113
	mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) /
114
						      8), 64);
115
	mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
116
							  sizes->surface_depth);
2335 Serge 117
 
2342 Serge 118
	size = mode_cmd.pitches[0] * mode_cmd.height;
2335 Serge 119
	size = ALIGN(size, PAGE_SIZE);
120
	obj = i915_gem_alloc_object(dev, size);
121
	if (!obj) {
122
		DRM_ERROR("failed to allocate framebuffer\n");
123
		ret = -ENOMEM;
124
		goto out;
125
	}
126
 
127
	mutex_lock(&dev->struct_mutex);
128
 
2336 Serge 129
#if 0
130
// skip this part and use existing framebiffer
131
 
2335 Serge 132
	/* Flush everything out, we'll be doing GTT only from now on */
133
	ret = intel_pin_and_fence_fb_obj(dev, obj, false);
134
	if (ret) {
135
		DRM_ERROR("failed to pin fb: %d\n", ret);
136
		goto out_unref;
137
	}
2336 Serge 138
#endif
2335 Serge 139
 
2336 Serge 140
/***********************************************************************/
141
    {
142
#define LFB_SIZE 0xC00000
143
 
144
        static struct drm_mm_node lfb_vm_node;
145
 
146
        lfb_vm_node.size = LFB_SIZE;
147
        lfb_vm_node.start = 0;
148
        lfb_vm_node.mm = NULL;
149
 
150
        obj->gtt_space = &lfb_vm_node;
151
        obj->gtt_offset = 0;
2344 Serge 152
        obj->pin_count = 2;
3263 Serge 153
        obj->cache_level = I915_CACHE_NONE;
154
	    obj->base.write_domain = 0;
155
	    obj->base.read_domains = I915_GEM_DOMAIN_GTT;
156
 
2336 Serge 157
    }
158
/***********************************************************************/
159
 
2335 Serge 160
	info = framebuffer_alloc(0, device);
161
	if (!info) {
162
		ret = -ENOMEM;
163
		goto out_unpin;
164
	}
165
 
166
	info->par = ifbdev;
167
 
168
	ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj);
169
	if (ret)
170
		goto out_unpin;
171
 
172
	fb = &ifbdev->ifb.base;
173
 
174
	ifbdev->helper.fb = fb;
175
	ifbdev->helper.fbdev = info;
176
 
177
    strcpy(info->fix.id, "inteldrmfb");
178
 
179
    info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
180
    info->fbops = &intelfb_ops;
181
 
182
    /* setup aperture base/size for vesafb takeover */
183
	info->apertures = alloc_apertures(1);
184
	if (!info->apertures) {
185
		ret = -ENOMEM;
186
		goto out_unpin;
187
	}
188
	info->apertures->ranges[0].base = dev->mode_config.fb_base;
189
	info->apertures->ranges[0].size =
190
		dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT;
191
 
192
	info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset;
193
	info->fix.smem_len = size;
194
 
3263 Serge 195
	info->screen_base = (void*) 0xFE000000;
2335 Serge 196
	info->screen_size = size;
197
 
198
//	memset(info->screen_base, 0, size);
199
 
2342 Serge 200
	drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
2335 Serge 201
	drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height);
202
 
3031 serge 203
	/* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
204
 
2335 Serge 205
	DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x, bo %p\n",
206
		      fb->width, fb->height,
207
		      obj->gtt_offset, obj);
208
 
209
 
210
	mutex_unlock(&dev->struct_mutex);
211
//   vga_switcheroo_client_fb_set(dev->pdev, info);
3031 serge 212
 
3263 Serge 213
    fb_obj = obj;
214
 
2335 Serge 215
	return 0;
216
 
217
out_unpin:
2344 Serge 218
	i915_gem_object_unpin(obj);
2335 Serge 219
out_unref:
2344 Serge 220
	drm_gem_object_unreference(&obj->base);
2335 Serge 221
	mutex_unlock(&dev->struct_mutex);
222
out:
223
	return ret;
224
}
2342 Serge 225
 
2335 Serge 226
static int intel_fb_find_or_create_single(struct drm_fb_helper *helper,
227
					  struct drm_fb_helper_surface_size *sizes)
228
{
229
	struct intel_fbdev *ifbdev = (struct intel_fbdev *)helper;
230
	int new_fb = 0;
231
	int ret;
232
 
233
	if (!helper->fb) {
234
		ret = intelfb_create(ifbdev, sizes);
235
		if (ret)
236
			return ret;
237
		new_fb = 1;
238
	}
239
	return new_fb;
240
}
241
 
2332 Serge 242
static struct drm_fb_helper_funcs intel_fb_helper_funcs = {
243
	.gamma_set = intel_crtc_fb_gamma_set,
244
	.gamma_get = intel_crtc_fb_gamma_get,
2335 Serge 245
    .fb_probe = intel_fb_find_or_create_single,
2332 Serge 246
};
247
 
248
 
249
int intel_fbdev_init(struct drm_device *dev)
250
{
251
	struct intel_fbdev *ifbdev;
252
	drm_i915_private_t *dev_priv = dev->dev_private;
253
	int ret;
254
 
255
	ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
256
	if (!ifbdev)
257
		return -ENOMEM;
258
 
259
	dev_priv->fbdev = ifbdev;
260
	ifbdev->helper.funcs = &intel_fb_helper_funcs;
261
 
262
	ret = drm_fb_helper_init(dev, &ifbdev->helper,
263
				 dev_priv->num_pipe,
264
				 INTELFB_CONN_LIMIT);
265
	if (ret) {
266
		kfree(ifbdev);
267
		return ret;
268
	}
269
 
270
	drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
271
	drm_fb_helper_initial_config(&ifbdev->helper, 32);
272
 
3037 serge 273
    return 0;
2332 Serge 274
}
275