diff options
Diffstat (limited to 'drivers/gpu/drm/radeon/radeon_fb.c')
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_fb.c | 358 |
1 files changed, 201 insertions, 157 deletions
diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c index 9ac57a09784b..e192acfbf0cd 100644 --- a/drivers/gpu/drm/radeon/radeon_fb.c +++ b/drivers/gpu/drm/radeon/radeon_fb.c | |||
@@ -23,10 +23,6 @@ | |||
23 | * Authors: | 23 | * Authors: |
24 | * David Airlie | 24 | * David Airlie |
25 | */ | 25 | */ |
26 | /* | ||
27 | * Modularization | ||
28 | */ | ||
29 | |||
30 | #include <linux/module.h> | 26 | #include <linux/module.h> |
31 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
32 | #include <linux/fb.h> | 28 | #include <linux/fb.h> |
@@ -42,17 +38,21 @@ | |||
42 | 38 | ||
43 | #include <linux/vga_switcheroo.h> | 39 | #include <linux/vga_switcheroo.h> |
44 | 40 | ||
45 | struct radeon_fb_device { | 41 | /* object hierarchy - |
42 | this contains a helper + a radeon fb | ||
43 | the helper contains a pointer to radeon framebuffer baseclass. | ||
44 | */ | ||
45 | struct radeon_fbdev { | ||
46 | struct drm_fb_helper helper; | 46 | struct drm_fb_helper helper; |
47 | struct radeon_framebuffer *rfb; | 47 | struct radeon_framebuffer rfb; |
48 | struct radeon_device *rdev; | 48 | struct list_head fbdev_list; |
49 | struct radeon_device *rdev; | ||
49 | }; | 50 | }; |
50 | 51 | ||
51 | static struct fb_ops radeonfb_ops = { | 52 | static struct fb_ops radeonfb_ops = { |
52 | .owner = THIS_MODULE, | 53 | .owner = THIS_MODULE, |
53 | .fb_check_var = drm_fb_helper_check_var, | 54 | .fb_check_var = drm_fb_helper_check_var, |
54 | .fb_set_par = drm_fb_helper_set_par, | 55 | .fb_set_par = drm_fb_helper_set_par, |
55 | .fb_setcolreg = drm_fb_helper_setcolreg, | ||
56 | .fb_fillrect = cfb_fillrect, | 56 | .fb_fillrect = cfb_fillrect, |
57 | .fb_copyarea = cfb_copyarea, | 57 | .fb_copyarea = cfb_copyarea, |
58 | .fb_imageblit = cfb_imageblit, | 58 | .fb_imageblit = cfb_imageblit, |
@@ -61,45 +61,6 @@ static struct fb_ops radeonfb_ops = { | |||
61 | .fb_setcmap = drm_fb_helper_setcmap, | 61 | .fb_setcmap = drm_fb_helper_setcmap, |
62 | }; | 62 | }; |
63 | 63 | ||
64 | /** | ||
65 | * Currently it is assumed that the old framebuffer is reused. | ||
66 | * | ||
67 | * LOCKING | ||
68 | * caller should hold the mode config lock. | ||
69 | * | ||
70 | */ | ||
71 | int radeonfb_resize(struct drm_device *dev, struct drm_crtc *crtc) | ||
72 | { | ||
73 | struct fb_info *info; | ||
74 | struct drm_framebuffer *fb; | ||
75 | struct drm_display_mode *mode = crtc->desired_mode; | ||
76 | |||
77 | fb = crtc->fb; | ||
78 | if (fb == NULL) { | ||
79 | return 1; | ||
80 | } | ||
81 | info = fb->fbdev; | ||
82 | if (info == NULL) { | ||
83 | return 1; | ||
84 | } | ||
85 | if (mode == NULL) { | ||
86 | return 1; | ||
87 | } | ||
88 | info->var.xres = mode->hdisplay; | ||
89 | info->var.right_margin = mode->hsync_start - mode->hdisplay; | ||
90 | info->var.hsync_len = mode->hsync_end - mode->hsync_start; | ||
91 | info->var.left_margin = mode->htotal - mode->hsync_end; | ||
92 | info->var.yres = mode->vdisplay; | ||
93 | info->var.lower_margin = mode->vsync_start - mode->vdisplay; | ||
94 | info->var.vsync_len = mode->vsync_end - mode->vsync_start; | ||
95 | info->var.upper_margin = mode->vtotal - mode->vsync_end; | ||
96 | info->var.pixclock = 10000000 / mode->htotal * 1000 / mode->vtotal * 100; | ||
97 | /* avoid overflow */ | ||
98 | info->var.pixclock = info->var.pixclock * 1000 / mode->vrefresh; | ||
99 | |||
100 | return 0; | ||
101 | } | ||
102 | EXPORT_SYMBOL(radeonfb_resize); | ||
103 | 64 | ||
104 | static int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bool tiled) | 65 | static int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bool tiled) |
105 | { | 66 | { |
@@ -125,57 +86,44 @@ static int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bo | |||
125 | return aligned; | 86 | return aligned; |
126 | } | 87 | } |
127 | 88 | ||
128 | static struct drm_fb_helper_funcs radeon_fb_helper_funcs = { | 89 | static void radeonfb_destroy_pinned_object(struct drm_gem_object *gobj) |
129 | .gamma_set = radeon_crtc_fb_gamma_set, | 90 | { |
130 | .gamma_get = radeon_crtc_fb_gamma_get, | 91 | struct radeon_bo *rbo = gobj->driver_private; |
131 | }; | 92 | int ret; |
93 | |||
94 | ret = radeon_bo_reserve(rbo, false); | ||
95 | if (likely(ret == 0)) { | ||
96 | radeon_bo_kunmap(rbo); | ||
97 | radeon_bo_unreserve(rbo); | ||
98 | } | ||
99 | drm_gem_object_unreference_unlocked(gobj); | ||
100 | } | ||
132 | 101 | ||
133 | int radeonfb_create(struct drm_device *dev, | 102 | static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev, |
134 | uint32_t fb_width, uint32_t fb_height, | 103 | struct drm_mode_fb_cmd *mode_cmd, |
135 | uint32_t surface_width, uint32_t surface_height, | 104 | struct drm_gem_object **gobj_p) |
136 | uint32_t surface_depth, uint32_t surface_bpp, | ||
137 | struct drm_framebuffer **fb_p) | ||
138 | { | 105 | { |
139 | struct radeon_device *rdev = dev->dev_private; | 106 | struct radeon_device *rdev = rfbdev->rdev; |
140 | struct fb_info *info; | ||
141 | struct radeon_fb_device *rfbdev; | ||
142 | struct drm_framebuffer *fb = NULL; | ||
143 | struct radeon_framebuffer *rfb; | ||
144 | struct drm_mode_fb_cmd mode_cmd; | ||
145 | struct drm_gem_object *gobj = NULL; | 107 | struct drm_gem_object *gobj = NULL; |
146 | struct radeon_bo *rbo = NULL; | 108 | struct radeon_bo *rbo = NULL; |
147 | struct device *device = &rdev->pdev->dev; | ||
148 | int size, aligned_size, ret; | ||
149 | u64 fb_gpuaddr; | ||
150 | void *fbptr = NULL; | ||
151 | unsigned long tmp; | ||
152 | bool fb_tiled = false; /* useful for testing */ | 109 | bool fb_tiled = false; /* useful for testing */ |
153 | u32 tiling_flags = 0; | 110 | u32 tiling_flags = 0; |
111 | int ret; | ||
112 | int aligned_size, size; | ||
154 | 113 | ||
155 | mode_cmd.width = surface_width; | ||
156 | mode_cmd.height = surface_height; | ||
157 | |||
158 | /* avivo can't scanout real 24bpp */ | ||
159 | if ((surface_bpp == 24) && ASIC_IS_AVIVO(rdev)) | ||
160 | surface_bpp = 32; | ||
161 | |||
162 | mode_cmd.bpp = surface_bpp; | ||
163 | /* need to align pitch with crtc limits */ | 114 | /* need to align pitch with crtc limits */ |
164 | mode_cmd.pitch = radeon_align_pitch(rdev, mode_cmd.width, mode_cmd.bpp, fb_tiled) * ((mode_cmd.bpp + 1) / 8); | 115 | mode_cmd->pitch = radeon_align_pitch(rdev, mode_cmd->width, mode_cmd->bpp, fb_tiled) * ((mode_cmd->bpp + 1) / 8); |
165 | mode_cmd.depth = surface_depth; | ||
166 | 116 | ||
167 | size = mode_cmd.pitch * mode_cmd.height; | 117 | size = mode_cmd->pitch * mode_cmd->height; |
168 | aligned_size = ALIGN(size, PAGE_SIZE); | 118 | aligned_size = ALIGN(size, PAGE_SIZE); |
169 | |||
170 | ret = radeon_gem_object_create(rdev, aligned_size, 0, | 119 | ret = radeon_gem_object_create(rdev, aligned_size, 0, |
171 | RADEON_GEM_DOMAIN_VRAM, | 120 | RADEON_GEM_DOMAIN_VRAM, |
172 | false, ttm_bo_type_kernel, | 121 | false, ttm_bo_type_kernel, |
173 | &gobj); | 122 | &gobj); |
174 | if (ret) { | 123 | if (ret) { |
175 | printk(KERN_ERR "failed to allocate framebuffer (%d %d)\n", | 124 | printk(KERN_ERR "failed to allocate framebuffer (%d)\n", |
176 | surface_width, surface_height); | 125 | aligned_size); |
177 | ret = -ENOMEM; | 126 | return -ENOMEM; |
178 | goto out; | ||
179 | } | 127 | } |
180 | rbo = gobj->driver_private; | 128 | rbo = gobj->driver_private; |
181 | 129 | ||
@@ -183,7 +131,7 @@ int radeonfb_create(struct drm_device *dev, | |||
183 | tiling_flags = RADEON_TILING_MACRO; | 131 | tiling_flags = RADEON_TILING_MACRO; |
184 | 132 | ||
185 | #ifdef __BIG_ENDIAN | 133 | #ifdef __BIG_ENDIAN |
186 | switch (mode_cmd.bpp) { | 134 | switch (mode_cmd->bpp) { |
187 | case 32: | 135 | case 32: |
188 | tiling_flags |= RADEON_TILING_SWAP_32BIT; | 136 | tiling_flags |= RADEON_TILING_SWAP_32BIT; |
189 | break; | 137 | break; |
@@ -196,57 +144,81 @@ int radeonfb_create(struct drm_device *dev, | |||
196 | 144 | ||
197 | if (tiling_flags) { | 145 | if (tiling_flags) { |
198 | ret = radeon_bo_set_tiling_flags(rbo, | 146 | ret = radeon_bo_set_tiling_flags(rbo, |
199 | tiling_flags | RADEON_TILING_SURFACE, | 147 | tiling_flags | RADEON_TILING_SURFACE, |
200 | mode_cmd.pitch); | 148 | mode_cmd->pitch); |
201 | if (ret) | 149 | if (ret) |
202 | dev_err(rdev->dev, "FB failed to set tiling flags\n"); | 150 | dev_err(rdev->dev, "FB failed to set tiling flags\n"); |
203 | } | 151 | } |
204 | mutex_lock(&rdev->ddev->struct_mutex); | 152 | |
205 | fb = radeon_framebuffer_create(rdev->ddev, &mode_cmd, gobj); | 153 | |
206 | if (fb == NULL) { | ||
207 | DRM_ERROR("failed to allocate fb.\n"); | ||
208 | ret = -ENOMEM; | ||
209 | goto out_unref; | ||
210 | } | ||
211 | ret = radeon_bo_reserve(rbo, false); | 154 | ret = radeon_bo_reserve(rbo, false); |
212 | if (unlikely(ret != 0)) | 155 | if (unlikely(ret != 0)) |
213 | goto out_unref; | 156 | goto out_unref; |
214 | ret = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_gpuaddr); | 157 | ret = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, NULL); |
215 | if (ret) { | 158 | if (ret) { |
216 | radeon_bo_unreserve(rbo); | 159 | radeon_bo_unreserve(rbo); |
217 | goto out_unref; | 160 | goto out_unref; |
218 | } | 161 | } |
219 | if (fb_tiled) | 162 | if (fb_tiled) |
220 | radeon_bo_check_tiling(rbo, 0, 0); | 163 | radeon_bo_check_tiling(rbo, 0, 0); |
221 | ret = radeon_bo_kmap(rbo, &fbptr); | 164 | ret = radeon_bo_kmap(rbo, NULL); |
222 | radeon_bo_unreserve(rbo); | 165 | radeon_bo_unreserve(rbo); |
223 | if (ret) { | 166 | if (ret) { |
224 | goto out_unref; | 167 | goto out_unref; |
225 | } | 168 | } |
226 | 169 | ||
227 | list_add(&fb->filp_head, &rdev->ddev->mode_config.fb_kernel_list); | 170 | *gobj_p = gobj; |
171 | return 0; | ||
172 | out_unref: | ||
173 | radeonfb_destroy_pinned_object(gobj); | ||
174 | *gobj_p = NULL; | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | static int radeonfb_create(struct radeon_fbdev *rfbdev, | ||
179 | struct drm_fb_helper_surface_size *sizes) | ||
180 | { | ||
181 | struct radeon_device *rdev = rfbdev->rdev; | ||
182 | struct fb_info *info; | ||
183 | struct drm_framebuffer *fb = NULL; | ||
184 | struct drm_mode_fb_cmd mode_cmd; | ||
185 | struct drm_gem_object *gobj = NULL; | ||
186 | struct radeon_bo *rbo = NULL; | ||
187 | struct device *device = &rdev->pdev->dev; | ||
188 | int ret; | ||
189 | unsigned long tmp; | ||
190 | |||
191 | mode_cmd.width = sizes->surface_width; | ||
192 | mode_cmd.height = sizes->surface_height; | ||
193 | |||
194 | /* avivo can't scanout real 24bpp */ | ||
195 | if ((sizes->surface_bpp == 24) && ASIC_IS_AVIVO(rdev)) | ||
196 | sizes->surface_bpp = 32; | ||
197 | |||
198 | mode_cmd.bpp = sizes->surface_bpp; | ||
199 | mode_cmd.depth = sizes->surface_depth; | ||
228 | 200 | ||
229 | *fb_p = fb; | 201 | ret = radeonfb_create_pinned_object(rfbdev, &mode_cmd, &gobj); |
230 | rfb = to_radeon_framebuffer(fb); | 202 | rbo = gobj->driver_private; |
231 | rdev->fbdev_rfb = rfb; | ||
232 | rdev->fbdev_rbo = rbo; | ||
233 | 203 | ||
234 | info = framebuffer_alloc(sizeof(struct radeon_fb_device), device); | 204 | /* okay we have an object now allocate the framebuffer */ |
205 | info = framebuffer_alloc(0, device); | ||
235 | if (info == NULL) { | 206 | if (info == NULL) { |
236 | ret = -ENOMEM; | 207 | ret = -ENOMEM; |
237 | goto out_unref; | 208 | goto out_unref; |
238 | } | 209 | } |
239 | 210 | ||
240 | rdev->fbdev_info = info; | 211 | info->par = rfbdev; |
241 | rfbdev = info->par; | 212 | |
242 | rfbdev->helper.funcs = &radeon_fb_helper_funcs; | 213 | radeon_framebuffer_init(rdev->ddev, &rfbdev->rfb, &mode_cmd, gobj); |
243 | rfbdev->helper.dev = dev; | ||
244 | ret = drm_fb_helper_init_crtc_count(&rfbdev->helper, rdev->num_crtc, | ||
245 | RADEONFB_CONN_LIMIT); | ||
246 | if (ret) | ||
247 | goto out_unref; | ||
248 | 214 | ||
249 | memset_io(fbptr, 0x0, aligned_size); | 215 | fb = &rfbdev->rfb.base; |
216 | |||
217 | /* setup helper */ | ||
218 | rfbdev->helper.fb = fb; | ||
219 | rfbdev->helper.fbdev = info; | ||
220 | |||
221 | memset_io(rbo->kptr, 0x0, radeon_bo_size(rbo)); | ||
250 | 222 | ||
251 | strcpy(info->fix.id, "radeondrmfb"); | 223 | strcpy(info->fix.id, "radeondrmfb"); |
252 | 224 | ||
@@ -255,17 +227,22 @@ int radeonfb_create(struct drm_device *dev, | |||
255 | info->flags = FBINFO_DEFAULT; | 227 | info->flags = FBINFO_DEFAULT; |
256 | info->fbops = &radeonfb_ops; | 228 | info->fbops = &radeonfb_ops; |
257 | 229 | ||
258 | tmp = fb_gpuaddr - rdev->mc.vram_start; | 230 | tmp = radeon_bo_gpu_offset(rbo) - rdev->mc.vram_start; |
259 | info->fix.smem_start = rdev->mc.aper_base + tmp; | 231 | info->fix.smem_start = rdev->mc.aper_base + tmp; |
260 | info->fix.smem_len = size; | 232 | info->fix.smem_len = radeon_bo_size(rbo); |
261 | info->screen_base = fbptr; | 233 | info->screen_base = rbo->kptr; |
262 | info->screen_size = size; | 234 | info->screen_size = radeon_bo_size(rbo); |
263 | 235 | ||
264 | drm_fb_helper_fill_var(info, fb, fb_width, fb_height); | 236 | drm_fb_helper_fill_var(info, &rfbdev->helper, sizes->fb_width, sizes->fb_height); |
265 | 237 | ||
266 | /* setup aperture base/size for vesafb takeover */ | 238 | /* setup aperture base/size for vesafb takeover */ |
267 | info->aperture_base = rdev->ddev->mode_config.fb_base; | 239 | info->apertures = alloc_apertures(1); |
268 | info->aperture_size = rdev->mc.real_vram_size; | 240 | if (!info->apertures) { |
241 | ret = -ENOMEM; | ||
242 | goto out_unref; | ||
243 | } | ||
244 | info->apertures->ranges[0].base = rdev->ddev->mode_config.fb_base; | ||
245 | info->apertures->ranges[0].size = rdev->mc.real_vram_size; | ||
269 | 246 | ||
270 | info->fix.mmio_start = 0; | 247 | info->fix.mmio_start = 0; |
271 | info->fix.mmio_len = 0; | 248 | info->fix.mmio_len = 0; |
@@ -274,44 +251,55 @@ int radeonfb_create(struct drm_device *dev, | |||
274 | info->pixmap.access_align = 32; | 251 | info->pixmap.access_align = 32; |
275 | info->pixmap.flags = FB_PIXMAP_SYSTEM; | 252 | info->pixmap.flags = FB_PIXMAP_SYSTEM; |
276 | info->pixmap.scan_align = 1; | 253 | info->pixmap.scan_align = 1; |
254 | |||
277 | if (info->screen_base == NULL) { | 255 | if (info->screen_base == NULL) { |
278 | ret = -ENOSPC; | 256 | ret = -ENOSPC; |
279 | goto out_unref; | 257 | goto out_unref; |
280 | } | 258 | } |
259 | |||
260 | ret = fb_alloc_cmap(&info->cmap, 256, 0); | ||
261 | if (ret) { | ||
262 | ret = -ENOMEM; | ||
263 | goto out_unref; | ||
264 | } | ||
265 | |||
281 | DRM_INFO("fb mappable at 0x%lX\n", info->fix.smem_start); | 266 | DRM_INFO("fb mappable at 0x%lX\n", info->fix.smem_start); |
282 | DRM_INFO("vram apper at 0x%lX\n", (unsigned long)rdev->mc.aper_base); | 267 | DRM_INFO("vram apper at 0x%lX\n", (unsigned long)rdev->mc.aper_base); |
283 | DRM_INFO("size %lu\n", (unsigned long)size); | 268 | DRM_INFO("size %lu\n", (unsigned long)radeon_bo_size(rbo)); |
284 | DRM_INFO("fb depth is %d\n", fb->depth); | 269 | DRM_INFO("fb depth is %d\n", fb->depth); |
285 | DRM_INFO(" pitch is %d\n", fb->pitch); | 270 | DRM_INFO(" pitch is %d\n", fb->pitch); |
286 | 271 | ||
287 | fb->fbdev = info; | ||
288 | rfbdev->rfb = rfb; | ||
289 | rfbdev->rdev = rdev; | ||
290 | |||
291 | mutex_unlock(&rdev->ddev->struct_mutex); | ||
292 | vga_switcheroo_client_fb_set(rdev->ddev->pdev, info); | 272 | vga_switcheroo_client_fb_set(rdev->ddev->pdev, info); |
293 | return 0; | 273 | return 0; |
294 | 274 | ||
295 | out_unref: | 275 | out_unref: |
296 | if (rbo) { | 276 | if (rbo) { |
297 | ret = radeon_bo_reserve(rbo, false); | 277 | |
298 | if (likely(ret == 0)) { | ||
299 | radeon_bo_kunmap(rbo); | ||
300 | radeon_bo_unreserve(rbo); | ||
301 | } | ||
302 | } | 278 | } |
303 | if (fb && ret) { | 279 | if (fb && ret) { |
304 | list_del(&fb->filp_head); | ||
305 | drm_gem_object_unreference(gobj); | 280 | drm_gem_object_unreference(gobj); |
306 | drm_framebuffer_cleanup(fb); | 281 | drm_framebuffer_cleanup(fb); |
307 | kfree(fb); | 282 | kfree(fb); |
308 | } | 283 | } |
309 | drm_gem_object_unreference(gobj); | ||
310 | mutex_unlock(&rdev->ddev->struct_mutex); | ||
311 | out: | ||
312 | return ret; | 284 | return ret; |
313 | } | 285 | } |
314 | 286 | ||
287 | static int radeon_fb_find_or_create_single(struct drm_fb_helper *helper, | ||
288 | struct drm_fb_helper_surface_size *sizes) | ||
289 | { | ||
290 | struct radeon_fbdev *rfbdev = (struct radeon_fbdev *)helper; | ||
291 | int new_fb = 0; | ||
292 | int ret; | ||
293 | |||
294 | if (!helper->fb) { | ||
295 | ret = radeonfb_create(rfbdev, sizes); | ||
296 | if (ret) | ||
297 | return ret; | ||
298 | new_fb = 1; | ||
299 | } | ||
300 | return new_fb; | ||
301 | } | ||
302 | |||
315 | static char *mode_option; | 303 | static char *mode_option; |
316 | int radeon_parse_options(char *options) | 304 | int radeon_parse_options(char *options) |
317 | { | 305 | { |
@@ -328,46 +316,102 @@ int radeon_parse_options(char *options) | |||
328 | return 0; | 316 | return 0; |
329 | } | 317 | } |
330 | 318 | ||
331 | int radeonfb_probe(struct drm_device *dev) | 319 | void radeon_fb_output_poll_changed(struct radeon_device *rdev) |
332 | { | 320 | { |
333 | struct radeon_device *rdev = dev->dev_private; | 321 | drm_fb_helper_hotplug_event(&rdev->mode_info.rfbdev->helper); |
334 | int bpp_sel = 32; | ||
335 | |||
336 | /* select 8 bpp console on RN50 or 16MB cards */ | ||
337 | if (ASIC_IS_RN50(rdev) || rdev->mc.real_vram_size <= (32*1024*1024)) | ||
338 | bpp_sel = 8; | ||
339 | |||
340 | return drm_fb_helper_single_fb_probe(dev, bpp_sel, &radeonfb_create); | ||
341 | } | 322 | } |
342 | 323 | ||
343 | int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb) | 324 | static int radeon_fbdev_destroy(struct drm_device *dev, struct radeon_fbdev *rfbdev) |
344 | { | 325 | { |
345 | struct fb_info *info; | 326 | struct fb_info *info; |
346 | struct radeon_framebuffer *rfb = to_radeon_framebuffer(fb); | 327 | struct radeon_framebuffer *rfb = &rfbdev->rfb; |
347 | struct radeon_bo *rbo; | 328 | struct radeon_bo *rbo; |
348 | int r; | 329 | int r; |
349 | 330 | ||
350 | if (!fb) { | 331 | if (rfbdev->helper.fbdev) { |
351 | return -EINVAL; | 332 | info = rfbdev->helper.fbdev; |
333 | |||
334 | unregister_framebuffer(info); | ||
335 | if (info->cmap.len) | ||
336 | fb_dealloc_cmap(&info->cmap); | ||
337 | framebuffer_release(info); | ||
352 | } | 338 | } |
353 | info = fb->fbdev; | 339 | |
354 | if (info) { | 340 | if (rfb->obj) { |
355 | struct radeon_fb_device *rfbdev = info->par; | ||
356 | rbo = rfb->obj->driver_private; | 341 | rbo = rfb->obj->driver_private; |
357 | unregister_framebuffer(info); | ||
358 | r = radeon_bo_reserve(rbo, false); | 342 | r = radeon_bo_reserve(rbo, false); |
359 | if (likely(r == 0)) { | 343 | if (likely(r == 0)) { |
360 | radeon_bo_kunmap(rbo); | 344 | radeon_bo_kunmap(rbo); |
361 | radeon_bo_unpin(rbo); | 345 | radeon_bo_unpin(rbo); |
362 | radeon_bo_unreserve(rbo); | 346 | radeon_bo_unreserve(rbo); |
363 | } | 347 | } |
364 | drm_fb_helper_free(&rfbdev->helper); | 348 | drm_gem_object_unreference_unlocked(rfb->obj); |
365 | framebuffer_release(info); | ||
366 | } | 349 | } |
350 | drm_fb_helper_fini(&rfbdev->helper); | ||
351 | drm_framebuffer_cleanup(&rfb->base); | ||
367 | 352 | ||
368 | printk(KERN_INFO "unregistered panic notifier\n"); | 353 | return 0; |
354 | } | ||
355 | |||
356 | static struct drm_fb_helper_funcs radeon_fb_helper_funcs = { | ||
357 | .gamma_set = radeon_crtc_fb_gamma_set, | ||
358 | .gamma_get = radeon_crtc_fb_gamma_get, | ||
359 | .fb_probe = radeon_fb_find_or_create_single, | ||
360 | }; | ||
361 | |||
362 | int radeon_fbdev_init(struct radeon_device *rdev) | ||
363 | { | ||
364 | struct radeon_fbdev *rfbdev; | ||
365 | int bpp_sel = 32; | ||
366 | |||
367 | /* select 8 bpp console on RN50 or 16MB cards */ | ||
368 | if (ASIC_IS_RN50(rdev) || rdev->mc.real_vram_size <= (32*1024*1024)) | ||
369 | bpp_sel = 8; | ||
370 | |||
371 | rfbdev = kzalloc(sizeof(struct radeon_fbdev), GFP_KERNEL); | ||
372 | if (!rfbdev) | ||
373 | return -ENOMEM; | ||
374 | |||
375 | rfbdev->rdev = rdev; | ||
376 | rdev->mode_info.rfbdev = rfbdev; | ||
377 | rfbdev->helper.funcs = &radeon_fb_helper_funcs; | ||
369 | 378 | ||
379 | drm_fb_helper_init(rdev->ddev, &rfbdev->helper, | ||
380 | rdev->num_crtc, | ||
381 | RADEONFB_CONN_LIMIT); | ||
382 | drm_fb_helper_single_add_all_connectors(&rfbdev->helper); | ||
383 | drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel); | ||
370 | return 0; | 384 | return 0; |
371 | } | 385 | } |
372 | EXPORT_SYMBOL(radeonfb_remove); | 386 | |
373 | MODULE_LICENSE("GPL"); | 387 | void radeon_fbdev_fini(struct radeon_device *rdev) |
388 | { | ||
389 | if (!rdev->mode_info.rfbdev) | ||
390 | return; | ||
391 | |||
392 | radeon_fbdev_destroy(rdev->ddev, rdev->mode_info.rfbdev); | ||
393 | kfree(rdev->mode_info.rfbdev); | ||
394 | rdev->mode_info.rfbdev = NULL; | ||
395 | } | ||
396 | |||
397 | void radeon_fbdev_set_suspend(struct radeon_device *rdev, int state) | ||
398 | { | ||
399 | fb_set_suspend(rdev->mode_info.rfbdev->helper.fbdev, state); | ||
400 | } | ||
401 | |||
402 | int radeon_fbdev_total_size(struct radeon_device *rdev) | ||
403 | { | ||
404 | struct radeon_bo *robj; | ||
405 | int size = 0; | ||
406 | |||
407 | robj = rdev->mode_info.rfbdev->rfb.obj->driver_private; | ||
408 | size += radeon_bo_size(robj); | ||
409 | return size; | ||
410 | } | ||
411 | |||
412 | bool radeon_fbdev_robj_is_fb(struct radeon_device *rdev, struct radeon_bo *robj) | ||
413 | { | ||
414 | if (robj == rdev->mode_info.rfbdev->rfb.obj->driver_private) | ||
415 | return true; | ||
416 | return false; | ||
417 | } | ||