Rev 1963 | Rev 2997 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1963 | Rev 1986 | ||
---|---|---|---|
Line 22... | Line 22... | ||
22 | * |
22 | * |
23 | * Authors: |
23 | * Authors: |
24 | * David Airlie |
24 | * David Airlie |
25 | */ |
25 | */ |
26 | #include |
26 | #include |
- | 27 | #include |
|
27 | #include |
28 | #include |
Line 28... | Line 29... | ||
28 | 29 | ||
29 | #include "drmP.h" |
30 | #include "drmP.h" |
30 | #include "drm.h" |
31 | #include "drm.h" |
Line 36... | Line 37... | ||
36 | #include "drm_fb_helper.h" |
37 | #include "drm_fb_helper.h" |
Line 37... | Line 38... | ||
37 | 38 | ||
38 | #include |
39 | #include |
Line -... | Line 40... | ||
- | 40 | #include "radeon_object.h" |
|
- | 41 | ||
- | 42 | int radeonfb_create_object(struct radeon_fbdev *rfbdev, |
|
- | 43 | struct drm_mode_fb_cmd *mode_cmd, |
|
39 | #include "radeon_object.h" |
44 | struct drm_gem_object **gobj_p); |
40 | 45 | ||
41 | /* object hierarchy - |
46 | /* object hierarchy - |
42 | this contains a helper + a radeon fb |
47 | this contains a helper + a radeon fb |
43 | the helper contains a pointer to radeon framebuffer baseclass. |
48 | the helper contains a pointer to radeon framebuffer baseclass. |
Line 84... | Line 89... | ||
84 | aligned += pitch_mask; |
89 | aligned += pitch_mask; |
85 | aligned &= ~pitch_mask; |
90 | aligned &= ~pitch_mask; |
86 | return aligned; |
91 | return aligned; |
87 | } |
92 | } |
Line 88... | Line -... | ||
88 | - | ||
89 | static void radeonfb_destroy_pinned_object(struct drm_gem_object *gobj) |
- | |
90 | { |
- | |
91 | struct radeon_bo *rbo = gobj->driver_private; |
- | |
92 | int ret; |
- | |
93 | - | ||
94 | ret = radeon_bo_reserve(rbo, false); |
- | |
95 | if (likely(ret == 0)) { |
- | |
96 | radeon_bo_kunmap(rbo); |
- | |
97 | radeon_bo_unpin(rbo); |
- | |
98 | radeon_bo_unreserve(rbo); |
- | |
99 | } |
- | |
100 | // drm_gem_object_unreference_unlocked(gobj); |
- | |
101 | } |
- | |
102 | - | ||
103 | static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev, |
- | |
104 | struct drm_mode_fb_cmd *mode_cmd, |
- | |
105 | struct drm_gem_object **gobj_p) |
- | |
106 | { |
- | |
107 | struct radeon_device *rdev = rfbdev->rdev; |
- | |
108 | struct drm_gem_object *gobj = NULL; |
- | |
109 | struct radeon_bo *rbo = NULL; |
- | |
110 | bool fb_tiled = false; /* useful for testing */ |
- | |
111 | u32 tiling_flags = 0; |
- | |
112 | int ret; |
- | |
113 | int aligned_size, size; |
- | |
114 | - | ||
115 | /* need to align pitch with crtc limits */ |
- | |
116 | mode_cmd->pitch = radeon_align_pitch(rdev, mode_cmd->width, mode_cmd->bpp, fb_tiled) * ((mode_cmd->bpp + 1) / 8); |
- | |
117 | - | ||
118 | size = mode_cmd->pitch * mode_cmd->height; |
- | |
119 | aligned_size = ALIGN(size, PAGE_SIZE); |
- | |
120 | // ret = radeon_gem_object_create(rdev, aligned_size, 0, |
- | |
121 | // RADEON_GEM_DOMAIN_VRAM, |
- | |
122 | // false, true, |
- | |
123 | // &gobj); |
- | |
124 | if (ret) { |
- | |
125 | printk(KERN_ERR "failed to allocate framebuffer (%d)\n", |
- | |
126 | aligned_size); |
- | |
127 | return -ENOMEM; |
- | |
128 | } |
- | |
129 | rbo = gobj->driver_private; |
- | |
130 | - | ||
131 | if (fb_tiled) |
- | |
132 | tiling_flags = RADEON_TILING_MACRO; |
- | |
133 | - | ||
134 | #ifdef __BIG_ENDIAN |
- | |
135 | switch (mode_cmd->bpp) { |
- | |
136 | case 32: |
- | |
137 | tiling_flags |= RADEON_TILING_SWAP_32BIT; |
- | |
138 | break; |
- | |
139 | case 16: |
- | |
140 | tiling_flags |= RADEON_TILING_SWAP_16BIT; |
- | |
141 | default: |
- | |
142 | break; |
- | |
143 | } |
- | |
144 | #endif |
- | |
145 | - | ||
146 | if (tiling_flags) { |
- | |
147 | ret = radeon_bo_set_tiling_flags(rbo, |
- | |
148 | tiling_flags | RADEON_TILING_SURFACE, |
- | |
149 | mode_cmd->pitch); |
- | |
150 | if (ret) |
- | |
151 | dev_err(rdev->dev, "FB failed to set tiling flags\n"); |
- | |
152 | } |
- | |
153 | - | ||
154 | - | ||
155 | ret = radeon_bo_reserve(rbo, false); |
- | |
156 | if (unlikely(ret != 0)) |
- | |
157 | goto out_unref; |
- | |
158 | ret = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, NULL); |
- | |
159 | if (ret) { |
- | |
160 | radeon_bo_unreserve(rbo); |
- | |
161 | goto out_unref; |
- | |
162 | } |
- | |
163 | if (fb_tiled) |
- | |
164 | radeon_bo_check_tiling(rbo, 0, 0); |
- | |
165 | ret = radeon_bo_kmap(rbo, NULL); |
- | |
166 | radeon_bo_unreserve(rbo); |
- | |
167 | if (ret) { |
- | |
168 | goto out_unref; |
- | |
169 | } |
- | |
170 | - | ||
171 | *gobj_p = gobj; |
- | |
172 | return 0; |
- | |
173 | out_unref: |
- | |
174 | radeonfb_destroy_pinned_object(gobj); |
- | |
175 | *gobj_p = NULL; |
- | |
176 | return ret; |
- | |
Line 177... | Line 93... | ||
177 | } |
93 | |
178 | 94 | ||
179 | static int radeonfb_create(struct radeon_fbdev *rfbdev, |
95 | static int radeonfb_create(struct radeon_fbdev *rfbdev, |
180 | struct drm_fb_helper_surface_size *sizes) |
96 | struct drm_fb_helper_surface_size *sizes) |
Line 199... | Line 115... | ||
199 | sizes->surface_bpp = 32; |
115 | sizes->surface_bpp = 32; |
Line 200... | Line 116... | ||
200 | 116 | ||
201 | mode_cmd.bpp = sizes->surface_bpp; |
117 | mode_cmd.bpp = sizes->surface_bpp; |
Line 202... | Line 118... | ||
202 | mode_cmd.depth = sizes->surface_depth; |
118 | mode_cmd.depth = sizes->surface_depth; |
203 | 119 | ||
Line 204... | Line 120... | ||
204 | // ret = radeonfb_create_pinned_object(rfbdev, &mode_cmd, &gobj); |
120 | ret = radeonfb_create_object(rfbdev, &mode_cmd, &gobj); |
205 | // rbo = gobj->driver_private; |
121 | rbo = gem_to_radeon_bo(gobj); |
206 | 122 | ||
207 | /* okay we have an object now allocate the framebuffer */ |
123 | /* okay we have an object now allocate the framebuffer */ |
208 | info = framebuffer_alloc(0, device); |
124 | info = framebuffer_alloc(0, device); |
209 | if (info == NULL) { |
125 | if (info == NULL) { |
Line 210... | Line 126... | ||
210 | ret = -ENOMEM; |
126 | ret = -ENOMEM; |
Line 211... | Line -... | ||
211 | goto out_unref; |
- | |
212 | } |
127 | goto out_unref; |
Line 213... | Line 128... | ||
213 | 128 | } |
|
Line 214... | Line 129... | ||
214 | info->par = rfbdev; |
129 | |
Line 261... | Line 176... | ||
261 | DRM_INFO("fb mappable at 0x%lX\n", info->fix.smem_start); |
176 | DRM_INFO("fb mappable at 0x%lX\n", info->fix.smem_start); |
262 | DRM_INFO("vram apper at 0x%lX\n", (unsigned long)rdev->mc.aper_base); |
177 | DRM_INFO("vram apper at 0x%lX\n", (unsigned long)rdev->mc.aper_base); |
263 | DRM_INFO("size %lu\n", (unsigned long)radeon_bo_size(rbo)); |
178 | DRM_INFO("size %lu\n", (unsigned long)radeon_bo_size(rbo)); |
264 | DRM_INFO("fb depth is %d\n", fb->depth); |
179 | DRM_INFO("fb depth is %d\n", fb->depth); |
265 | DRM_INFO(" pitch is %d\n", fb->pitch); |
180 | DRM_INFO(" pitch is %d\n", fb->pitch); |
266 | #endif |
181 | |
Line 267... | Line 182... | ||
267 | 182 | ||
Line 268... | Line 183... | ||
268 | LEAVE(); |
183 | LEAVE(); |
Line 305... | Line 220... | ||
305 | // unregister_framebuffer(info); |
220 | // unregister_framebuffer(info); |
306 | // framebuffer_release(info); |
221 | // framebuffer_release(info); |
307 | } |
222 | } |
Line 308... | Line 223... | ||
308 | 223 | ||
309 | if (rfb->obj) { |
- | |
310 | radeonfb_destroy_pinned_object(rfb->obj); |
224 | if (rfb->obj) { |
311 | rfb->obj = NULL; |
225 | rfb->obj = NULL; |
312 | } |
226 | } |
313 | // drm_fb_helper_fini(&rfbdev->helper); |
227 | // drm_fb_helper_fini(&rfbdev->helper); |
Line 320... | Line 234... | ||
320 | .gamma_set = radeon_crtc_fb_gamma_set, |
234 | .gamma_set = radeon_crtc_fb_gamma_set, |
321 | .gamma_get = radeon_crtc_fb_gamma_get, |
235 | .gamma_get = radeon_crtc_fb_gamma_get, |
322 | .fb_probe = radeon_fb_find_or_create_single, |
236 | .fb_probe = radeon_fb_find_or_create_single, |
323 | }; |
237 | }; |
Line -... | Line 238... | ||
- | 238 | ||
- | 239 | extern struct radeon_fbdev *kos_rfbdev; |
|
324 | 240 | ||
325 | int radeon_fbdev_init(struct radeon_device *rdev) |
241 | int radeon_fbdev_init(struct radeon_device *rdev) |
326 | { |
242 | { |
327 | struct radeon_fbdev *rfbdev; |
243 | struct radeon_fbdev *rfbdev; |
328 | int bpp_sel = 32; |
244 | int bpp_sel = 32; |
Line 351... | Line 267... | ||
351 | } |
267 | } |
Line 352... | Line 268... | ||
352 | 268 | ||
353 | drm_fb_helper_single_add_all_connectors(&rfbdev->helper); |
269 | drm_fb_helper_single_add_all_connectors(&rfbdev->helper); |
Line -... | Line 270... | ||
- | 270 | drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel); |
|
- | 271 | ||
354 | drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel); |
272 | kos_rfbdev = rfbdev; |
Line 355... | Line 273... | ||
355 | 273 | ||
356 | LEAVE(); |
274 | LEAVE(); |
Line 372... | Line 290... | ||
372 | int radeon_fbdev_total_size(struct radeon_device *rdev) |
290 | int radeon_fbdev_total_size(struct radeon_device *rdev) |
373 | { |
291 | { |
374 | struct radeon_bo *robj; |
292 | struct radeon_bo *robj; |
375 | int size = 0; |
293 | int size = 0; |
Line 376... | Line 294... | ||
376 | 294 | ||
377 | robj = rdev->mode_info.rfbdev->rfb.obj->driver_private; |
295 | robj = gem_to_radeon_bo(rdev->mode_info.rfbdev->rfb.obj); |
378 | size += radeon_bo_size(robj); |
296 | size += radeon_bo_size(robj); |
379 | return size; |
297 | return size; |
Line 380... | Line 298... | ||
380 | } |
298 | } |
381 | 299 | ||
382 | bool radeon_fbdev_robj_is_fb(struct radeon_device *rdev, struct radeon_bo *robj) |
300 | bool radeon_fbdev_robj_is_fb(struct radeon_device *rdev, struct radeon_bo *robj) |
383 | { |
301 | { |
384 | if (robj == rdev->mode_info.rfbdev->rfb.obj->driver_private) |
302 | if (robj == gem_to_radeon_bo(rdev->mode_info.rfbdev->rfb.obj)) |
385 | return true; |
303 | return true; |