Subversion Repositories Kolibri OS

Rev

Rev 1986 | Rev 5271 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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