Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1126 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
 */
1179 serge 26
#include 
1986 serge 27
#include 
1179 serge 28
#include 
1126 serge 29
 
30
#include "drmP.h"
31
#include "drm.h"
32
#include "drm_crtc.h"
33
#include "drm_crtc_helper.h"
34
#include "radeon_drm.h"
35
#include "radeon.h"
36
 
1179 serge 37
#include "drm_fb_helper.h"
38
 
1126 serge 39
#include 
40
#include "radeon_object.h"
41
 
1986 serge 42
int radeonfb_create_object(struct radeon_fbdev *rfbdev,
43
                     struct drm_mode_fb_cmd *mode_cmd,
44
                     struct drm_gem_object **gobj_p);
45
 
1963 serge 46
/* object hierarchy -
47
   this contains a helper + a radeon fb
48
   the helper contains a pointer to radeon framebuffer baseclass.
49
*/
50
struct radeon_fbdev {
1179 serge 51
    struct drm_fb_helper        helper;
1963 serge 52
	struct radeon_framebuffer rfb;
53
	struct list_head fbdev_list;
1126 serge 54
	struct radeon_device		*rdev;
55
};
56
 
57
static struct fb_ops radeonfb_ops = {
1179 serge 58
//   .owner = THIS_MODULE,
59
	.fb_check_var = drm_fb_helper_check_var,
60
	.fb_set_par = drm_fb_helper_set_par,
61
//	.fb_fillrect = cfb_fillrect,
62
//	.fb_copyarea = cfb_copyarea,
63
//	.fb_imageblit = cfb_imageblit,
64
//	.fb_pan_display = drm_fb_helper_pan_display,
65
	.fb_blank = drm_fb_helper_blank,
1221 serge 66
	.fb_setcmap = drm_fb_helper_setcmap,
1126 serge 67
};
68
 
69
 
1233 serge 70
int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bool tiled)
1126 serge 71
{
72
	int aligned = width;
1179 serge 73
	int align_large = (ASIC_IS_AVIVO(rdev)) || tiled;
1126 serge 74
	int pitch_mask = 0;
75
 
76
	switch (bpp / 8) {
77
	case 1:
78
		pitch_mask = align_large ? 255 : 127;
79
		break;
80
	case 2:
81
		pitch_mask = align_large ? 127 : 31;
82
		break;
83
	case 3:
84
	case 4:
85
		pitch_mask = align_large ? 63 : 15;
86
		break;
87
	}
88
 
89
	aligned += pitch_mask;
90
	aligned &= ~pitch_mask;
91
	return aligned;
92
}
93
 
1179 serge 94
 
1963 serge 95
static int radeonfb_create(struct radeon_fbdev *rfbdev,
96
			   struct drm_fb_helper_surface_size *sizes)
97
{
98
	struct radeon_device *rdev = rfbdev->rdev;
99
	struct fb_info *info;
100
	struct drm_framebuffer *fb = NULL;
101
	struct drm_mode_fb_cmd mode_cmd;
102
	struct drm_gem_object *gobj = NULL;
103
	struct radeon_bo *rbo = NULL;
104
	struct device *device = &rdev->pdev->dev;
105
	int ret;
106
	unsigned long tmp;
1126 serge 107
 
1963 serge 108
    ENTER();
109
 
110
	mode_cmd.width = sizes->surface_width;
111
	mode_cmd.height = sizes->surface_height;
112
 
113
	/* avivo can't scanout real 24bpp */
114
	if ((sizes->surface_bpp == 24) && ASIC_IS_AVIVO(rdev))
115
		sizes->surface_bpp = 32;
116
 
117
	mode_cmd.bpp = sizes->surface_bpp;
118
	mode_cmd.depth = sizes->surface_depth;
119
 
1986 serge 120
    ret = radeonfb_create_object(rfbdev, &mode_cmd, &gobj);
121
	rbo = gem_to_radeon_bo(gobj);
1963 serge 122
 
123
	/* okay we have an object now allocate the framebuffer */
124
	info = framebuffer_alloc(0, device);
1126 serge 125
	if (info == NULL) {
126
		ret = -ENOMEM;
127
		goto out_unref;
128
	}
1179 serge 129
 
1963 serge 130
	info->par = rfbdev;
1126 serge 131
 
1963 serge 132
	radeon_framebuffer_init(rdev->ddev, &rfbdev->rfb, &mode_cmd, gobj);
133
 
134
	fb = &rfbdev->rfb.base;
135
 
136
	/* setup helper */
137
	rfbdev->helper.fb = fb;
138
	rfbdev->helper.fbdev = info;
139
 
140
//   memset_io(rbo->kptr, 0x0, radeon_bo_size(rbo));
141
 
1179 serge 142
	strcpy(info->fix.id, "radeondrmfb");
1126 serge 143
 
1221 serge 144
	drm_fb_helper_fill_fix(info, fb->pitch, fb->depth);
1179 serge 145
 
1963 serge 146
	info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
1179 serge 147
	info->fbops = &radeonfb_ops;
148
 
1963 serge 149
	tmp = radeon_bo_gpu_offset(rbo) - rdev->mc.vram_start;
1126 serge 150
	info->fix.smem_start = rdev->mc.aper_base + tmp;
1963 serge 151
	info->fix.smem_len = radeon_bo_size(rbo);
152
	info->screen_base = rbo->kptr;
153
	info->screen_size = radeon_bo_size(rbo);
1179 serge 154
 
1963 serge 155
	drm_fb_helper_fill_var(info, &rfbdev->helper, sizes->fb_width, sizes->fb_height);
1179 serge 156
 
157
	/* setup aperture base/size for vesafb takeover */
1963 serge 158
	info->apertures = alloc_apertures(1);
159
	if (!info->apertures) {
160
		ret = -ENOMEM;
161
		goto out_unref;
162
	}
163
	info->apertures->ranges[0].base = rdev->ddev->mode_config.fb_base;
164
	info->apertures->ranges[0].size = rdev->mc.aper_size;
1179 serge 165
 
1126 serge 166
//   info->pixmap.size = 64*1024;
167
//   info->pixmap.buf_align = 8;
168
//   info->pixmap.access_align = 32;
169
//   info->pixmap.flags = FB_PIXMAP_SYSTEM;
170
//   info->pixmap.scan_align = 1;
1963 serge 171
 
1126 serge 172
	if (info->screen_base == NULL) {
173
		ret = -ENOSPC;
174
		goto out_unref;
175
	}
176
	DRM_INFO("fb mappable at 0x%lX\n",  info->fix.smem_start);
177
	DRM_INFO("vram apper at 0x%lX\n",  (unsigned long)rdev->mc.aper_base);
1963 serge 178
	DRM_INFO("size %lu\n", (unsigned long)radeon_bo_size(rbo));
1126 serge 179
	DRM_INFO("fb depth is %d\n", fb->depth);
180
	DRM_INFO("   pitch is %d\n", fb->pitch);
181
 
1986 serge 182
 
1963 serge 183
    LEAVE();
1126 serge 184
 
1963 serge 185
    return 0;
1126 serge 186
 
187
out_unref:
1404 serge 188
	if (rbo) {
1963 serge 189
 
1126 serge 190
	}
191
	if (fb && ret) {
192
		kfree(fb);
193
	}
194
	return ret;
195
}
196
 
1963 serge 197
static int radeon_fb_find_or_create_single(struct drm_fb_helper *helper,
198
					   struct drm_fb_helper_surface_size *sizes)
1126 serge 199
{
1963 serge 200
	struct radeon_fbdev *rfbdev = (struct radeon_fbdev *)helper;
201
	int new_fb = 0;
202
	int ret;
203
 
204
	if (!helper->fb) {
205
		ret = radeonfb_create(rfbdev, sizes);
206
		if (ret)
207
			return ret;
208
		new_fb = 1;
209
	}
210
	return new_fb;
211
}
212
static int radeon_fbdev_destroy(struct drm_device *dev, struct radeon_fbdev *rfbdev)
213
{
214
	struct fb_info *info;
215
	struct radeon_framebuffer *rfb = &rfbdev->rfb;
216
 
217
	if (rfbdev->helper.fbdev) {
218
		info = rfbdev->helper.fbdev;
219
 
220
//       unregister_framebuffer(info);
221
//       framebuffer_release(info);
222
	}
223
 
224
	if (rfb->obj) {
225
		rfb->obj = NULL;
226
	}
227
//   drm_fb_helper_fini(&rfbdev->helper);
228
	drm_framebuffer_cleanup(&rfb->base);
229
 
230
	return 0;
231
}
232
 
233
static struct drm_fb_helper_funcs radeon_fb_helper_funcs = {
234
	.gamma_set = radeon_crtc_fb_gamma_set,
235
	.gamma_get = radeon_crtc_fb_gamma_get,
236
	.fb_probe = radeon_fb_find_or_create_single,
237
};
238
 
1986 serge 239
extern struct radeon_fbdev *kos_rfbdev;
240
 
1963 serge 241
int radeon_fbdev_init(struct radeon_device *rdev)
242
{
243
	struct radeon_fbdev *rfbdev;
1404 serge 244
	int bpp_sel = 32;
1963 serge 245
	int ret;
1404 serge 246
 
1963 serge 247
    ENTER();
248
 
1404 serge 249
	/* select 8 bpp console on RN50 or 16MB cards */
250
	if (ASIC_IS_RN50(rdev) || rdev->mc.real_vram_size <= (32*1024*1024))
251
		bpp_sel = 8;
252
 
1963 serge 253
	rfbdev = kzalloc(sizeof(struct radeon_fbdev), GFP_KERNEL);
254
	if (!rfbdev)
255
		return -ENOMEM;
1126 serge 256
 
1963 serge 257
	rfbdev->rdev = rdev;
258
	rdev->mode_info.rfbdev = rfbdev;
259
	rfbdev->helper.funcs = &radeon_fb_helper_funcs;
1126 serge 260
 
1963 serge 261
	ret = drm_fb_helper_init(rdev->ddev, &rfbdev->helper,
262
				 rdev->num_crtc,
263
				 RADEONFB_CONN_LIMIT);
264
	if (ret) {
265
		kfree(rfbdev);
266
		return ret;
1126 serge 267
	}
268
 
1963 serge 269
	drm_fb_helper_single_add_all_connectors(&rfbdev->helper);
270
	drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel);
1179 serge 271
 
1986 serge 272
    kos_rfbdev = rfbdev;
273
 
1963 serge 274
    LEAVE();
275
 
1126 serge 276
	return 0;
277
}
1963 serge 278
 
279
void radeon_fbdev_fini(struct radeon_device *rdev)
280
{
281
	if (!rdev->mode_info.rfbdev)
282
		return;
283
 
284
	radeon_fbdev_destroy(rdev->ddev, rdev->mode_info.rfbdev);
285
	kfree(rdev->mode_info.rfbdev);
286
	rdev->mode_info.rfbdev = NULL;
287
}
288
 
289
 
290
int radeon_fbdev_total_size(struct radeon_device *rdev)
291
{
292
	struct radeon_bo *robj;
293
	int size = 0;
294
 
1986 serge 295
	robj = gem_to_radeon_bo(rdev->mode_info.rfbdev->rfb.obj);
1963 serge 296
	size += radeon_bo_size(robj);
297
	return size;
298
}
299
 
300
bool radeon_fbdev_robj_is_fb(struct radeon_device *rdev, struct radeon_bo *robj)
301
{
1986 serge 302
	if (robj == gem_to_radeon_bo(rdev->mode_info.rfbdev->rfb.obj))
1963 serge 303
		return true;
304
	return false;
305
}