Rev 5367 | Rev 6088 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5367 | Rev 6084 | ||
---|---|---|---|
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 | 26 | ||
27 | #include |
27 | #include |
28 | #include |
28 | #include |
29 | #include |
29 | #include |
30 | #include |
30 | #include |
31 | #include |
31 | #include |
32 | //#include |
32 | #include |
33 | //#include |
33 | //#include |
34 | #include |
34 | #include |
35 | #include |
35 | #include |
36 | #include |
36 | #include |
37 | //#include |
37 | //#include |
38 | //#include |
38 | //#include |
39 | 39 | ||
40 | #include |
40 | #include |
41 | #include |
41 | #include |
42 | #include |
42 | #include |
43 | #include "intel_drv.h" |
43 | #include "intel_drv.h" |
44 | #include |
44 | #include |
45 | #include "i915_drv.h" |
45 | #include "i915_drv.h" |
46 | - | ||
47 | 46 | ||
48 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
47 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
49 | { |
48 | { |
50 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
49 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
51 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
50 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
52 | int fb_info_size = sizeof(struct fb_info); |
51 | int fb_info_size = sizeof(struct fb_info); |
53 | struct fb_info *info; |
52 | struct fb_info *info; |
54 | char *p; |
53 | char *p; |
55 | 54 | ||
56 | if (size) |
55 | if (size) |
57 | fb_info_size += PADDING; |
56 | fb_info_size += PADDING; |
58 | 57 | ||
59 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
58 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
60 | 59 | ||
61 | if (!p) |
60 | if (!p) |
62 | return NULL; |
61 | return NULL; |
63 | 62 | ||
64 | info = (struct fb_info *) p; |
63 | info = (struct fb_info *) p; |
65 | 64 | ||
66 | if (size) |
65 | if (size) |
67 | info->par = p + fb_info_size; |
66 | info->par = p + fb_info_size; |
68 | 67 | ||
69 | return info; |
68 | return info; |
70 | #undef PADDING |
69 | #undef PADDING |
71 | #undef BYTES_PER_LONG |
70 | #undef BYTES_PER_LONG |
72 | } |
71 | } |
73 | 72 | ||
74 | static int intel_fbdev_set_par(struct fb_info *info) |
73 | static int intel_fbdev_set_par(struct fb_info *info) |
75 | { |
74 | { |
76 | struct drm_fb_helper *fb_helper = info->par; |
75 | struct drm_fb_helper *fb_helper = info->par; |
77 | struct intel_fbdev *ifbdev = |
76 | struct intel_fbdev *ifbdev = |
78 | container_of(fb_helper, struct intel_fbdev, helper); |
77 | container_of(fb_helper, struct intel_fbdev, helper); |
79 | int ret; |
78 | int ret; |
80 | 79 | ||
81 | ret = drm_fb_helper_set_par(info); |
80 | ret = drm_fb_helper_set_par(info); |
82 | 81 | ||
83 | if (ret == 0) { |
82 | if (ret == 0) { |
84 | /* |
- | |
85 | * FIXME: fbdev presumes that all callbacks also work from |
- | |
86 | * atomic contexts and relies on that for emergency oops |
- | |
87 | * printing. KMS totally doesn't do that and the locking here is |
- | |
88 | * by far not the only place this goes wrong. Ignore this for |
- | |
89 | * now until we solve this for real. |
- | |
90 | */ |
- | |
91 | mutex_lock(&fb_helper->dev->struct_mutex); |
83 | mutex_lock(&fb_helper->dev->struct_mutex); |
92 | ret = i915_gem_object_set_to_gtt_domain(ifbdev->fb->obj, |
84 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
- | 85 | mutex_unlock(&fb_helper->dev->struct_mutex); |
|
- | 86 | } |
|
- | 87 | ||
- | 88 | return ret; |
|
- | 89 | } |
|
- | 90 | ||
- | 91 | static int intel_fbdev_blank(int blank, struct fb_info *info) |
|
- | 92 | { |
|
- | 93 | struct drm_fb_helper *fb_helper = info->par; |
|
- | 94 | struct intel_fbdev *ifbdev = |
|
- | 95 | container_of(fb_helper, struct intel_fbdev, helper); |
|
- | 96 | int ret; |
|
- | 97 | ||
- | 98 | ret = drm_fb_helper_blank(blank, info); |
|
- | 99 | ||
- | 100 | if (ret == 0) { |
|
- | 101 | mutex_lock(&fb_helper->dev->struct_mutex); |
|
- | 102 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
|
- | 103 | mutex_unlock(&fb_helper->dev->struct_mutex); |
|
- | 104 | } |
|
- | 105 | ||
93 | true); |
106 | return ret; |
- | 107 | } |
|
- | 108 | ||
- | 109 | static int intel_fbdev_pan_display(struct fb_var_screeninfo *var, |
|
- | 110 | struct fb_info *info) |
|
- | 111 | { |
|
- | 112 | struct drm_fb_helper *fb_helper = info->par; |
|
- | 113 | struct intel_fbdev *ifbdev = |
|
- | 114 | container_of(fb_helper, struct intel_fbdev, helper); |
|
- | 115 | ||
- | 116 | int ret; |
|
- | 117 | ret = drm_fb_helper_pan_display(var, info); |
|
- | 118 | ||
- | 119 | if (ret == 0) { |
|
- | 120 | mutex_lock(&fb_helper->dev->struct_mutex); |
|
- | 121 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
|
94 | mutex_unlock(&fb_helper->dev->struct_mutex); |
122 | mutex_unlock(&fb_helper->dev->struct_mutex); |
95 | } |
123 | } |
96 | 124 | ||
97 | return ret; |
125 | return ret; |
98 | } |
126 | } |
99 | 127 | ||
100 | static struct fb_ops intelfb_ops = { |
128 | static struct fb_ops intelfb_ops = { |
101 | .owner = THIS_MODULE, |
129 | .owner = THIS_MODULE, |
102 | .fb_check_var = drm_fb_helper_check_var, |
130 | .fb_check_var = drm_fb_helper_check_var, |
103 | .fb_set_par = intel_fbdev_set_par, |
131 | .fb_set_par = intel_fbdev_set_par, |
104 | // .fb_fillrect = cfb_fillrect, |
132 | // .fb_fillrect = cfb_fillrect, |
105 | // .fb_copyarea = cfb_copyarea, |
133 | // .fb_copyarea = cfb_copyarea, |
106 | // .fb_imageblit = cfb_imageblit, |
134 | // .fb_imageblit = cfb_imageblit, |
107 | // .fb_pan_display = drm_fb_helper_pan_display, |
135 | .fb_pan_display = intel_fbdev_pan_display, |
108 | .fb_blank = drm_fb_helper_blank, |
136 | .fb_blank = intel_fbdev_blank, |
109 | // .fb_setcmap = drm_fb_helper_setcmap, |
137 | // .fb_setcmap = drm_fb_helper_setcmap, |
110 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
138 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
111 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
139 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
112 | }; |
140 | }; |
113 | 141 | ||
114 | static int intelfb_alloc(struct drm_fb_helper *helper, |
142 | static int intelfb_alloc(struct drm_fb_helper *helper, |
115 | struct drm_fb_helper_surface_size *sizes) |
143 | struct drm_fb_helper_surface_size *sizes) |
116 | { |
144 | { |
117 | struct intel_fbdev *ifbdev = |
145 | struct intel_fbdev *ifbdev = |
118 | container_of(helper, struct intel_fbdev, helper); |
146 | container_of(helper, struct intel_fbdev, helper); |
119 | struct drm_framebuffer *fb; |
147 | struct drm_framebuffer *fb; |
120 | struct drm_device *dev = helper->dev; |
148 | struct drm_device *dev = helper->dev; |
- | 149 | struct drm_i915_private *dev_priv = to_i915(dev); |
|
121 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
150 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
122 | struct drm_i915_gem_object *obj; |
151 | struct drm_i915_gem_object *obj = NULL; |
123 | int size, ret; |
152 | int size, ret; |
124 | 153 | ||
125 | /* we don't do packed 24bpp */ |
154 | /* we don't do packed 24bpp */ |
126 | if (sizes->surface_bpp == 24) |
155 | if (sizes->surface_bpp == 24) |
127 | sizes->surface_bpp = 32; |
156 | sizes->surface_bpp = 32; |
128 | 157 | ||
129 | mode_cmd.width = sizes->surface_width; |
158 | mode_cmd.width = sizes->surface_width; |
130 | mode_cmd.height = sizes->surface_height; |
159 | mode_cmd.height = sizes->surface_height; |
131 | 160 | ||
132 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * |
161 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * |
133 | DIV_ROUND_UP(sizes->surface_bpp, 8), 64); |
162 | DIV_ROUND_UP(sizes->surface_bpp, 8), 64); |
134 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
163 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
135 | sizes->surface_depth); |
164 | sizes->surface_depth); |
136 | 165 | ||
137 | size = mode_cmd.pitches[0] * mode_cmd.height; |
166 | size = mode_cmd.pitches[0] * mode_cmd.height; |
138 | size = ALIGN(size, PAGE_SIZE); |
167 | size = PAGE_ALIGN(size); |
139 | obj = main_fb_obj; |
168 | obj = main_fb_obj; |
140 | obj->stride = mode_cmd.pitches[0]; |
169 | obj->map_and_fenceable=true; |
141 | if (!obj) { |
170 | if (!obj) { |
142 | DRM_ERROR("failed to allocate framebuffer\n"); |
171 | DRM_ERROR("failed to allocate framebuffer\n"); |
143 | ret = -ENOMEM; |
172 | ret = -ENOMEM; |
144 | goto out; |
173 | goto out; |
145 | } |
174 | } |
146 | 175 | ||
147 | fb = __intel_framebuffer_create(dev, &mode_cmd, obj); |
176 | fb = __intel_framebuffer_create(dev, &mode_cmd, obj); |
148 | if (IS_ERR(fb)) { |
177 | if (IS_ERR(fb)) { |
149 | ret = PTR_ERR(fb); |
178 | ret = PTR_ERR(fb); |
150 | goto out_unref; |
179 | goto out_unref; |
151 | } |
180 | } |
152 | 181 | ||
153 | /* Flush everything out, we'll be doing GTT only from now on */ |
182 | /* Flush everything out, we'll be doing GTT only from now on */ |
154 | ret = intel_pin_and_fence_fb_obj(NULL, fb, NULL); |
183 | ret = intel_pin_and_fence_fb_obj(NULL, fb, NULL, NULL, NULL); |
155 | if (ret) { |
184 | if (ret) { |
156 | DRM_ERROR("failed to pin obj: %d\n", ret); |
185 | DRM_ERROR("failed to pin obj: %d\n", ret); |
157 | goto out_fb; |
186 | goto out_fb; |
158 | } |
187 | } |
159 | 188 | ||
160 | ifbdev->fb = to_intel_framebuffer(fb); |
189 | ifbdev->fb = to_intel_framebuffer(fb); |
161 | 190 | ||
162 | return 0; |
191 | return 0; |
163 | 192 | ||
164 | out_fb: |
193 | out_fb: |
165 | drm_framebuffer_remove(fb); |
194 | drm_framebuffer_remove(fb); |
166 | out_unref: |
195 | out_unref: |
167 | drm_gem_object_unreference(&obj->base); |
196 | drm_gem_object_unreference(&obj->base); |
168 | out: |
197 | out: |
169 | return ret; |
198 | return ret; |
170 | } |
199 | } |
171 | 200 | ||
172 | static int intelfb_create(struct drm_fb_helper *helper, |
201 | static int intelfb_create(struct drm_fb_helper *helper, |
173 | struct drm_fb_helper_surface_size *sizes) |
202 | struct drm_fb_helper_surface_size *sizes) |
174 | { |
203 | { |
175 | struct intel_fbdev *ifbdev = |
204 | struct intel_fbdev *ifbdev = |
176 | container_of(helper, struct intel_fbdev, helper); |
205 | container_of(helper, struct intel_fbdev, helper); |
177 | struct intel_framebuffer *intel_fb = ifbdev->fb; |
206 | struct intel_framebuffer *intel_fb = ifbdev->fb; |
178 | struct drm_device *dev = helper->dev; |
207 | struct drm_device *dev = helper->dev; |
179 | struct drm_i915_private *dev_priv = dev->dev_private; |
208 | struct drm_i915_private *dev_priv = dev->dev_private; |
180 | struct fb_info *info; |
209 | struct fb_info *info; |
181 | struct drm_framebuffer *fb; |
210 | struct drm_framebuffer *fb; |
182 | struct drm_i915_gem_object *obj; |
211 | struct drm_i915_gem_object *obj; |
183 | int size, ret; |
212 | int size, ret; |
184 | bool prealloc = false; |
213 | bool prealloc = false; |
185 | 214 | ||
186 | mutex_lock(&dev->struct_mutex); |
215 | mutex_lock(&dev->struct_mutex); |
187 | 216 | ||
188 | #if 0 |
217 | #if 0 |
189 | if (intel_fb && |
218 | if (intel_fb && |
190 | (sizes->fb_width > intel_fb->base.width || |
219 | (sizes->fb_width > intel_fb->base.width || |
191 | sizes->fb_height > intel_fb->base.height)) { |
220 | sizes->fb_height > intel_fb->base.height)) { |
192 | DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d)," |
221 | DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d)," |
193 | " releasing it\n", |
222 | " releasing it\n", |
194 | intel_fb->base.width, intel_fb->base.height, |
223 | intel_fb->base.width, intel_fb->base.height, |
195 | sizes->fb_width, sizes->fb_height); |
224 | sizes->fb_width, sizes->fb_height); |
196 | drm_framebuffer_unreference(&intel_fb->base); |
225 | drm_framebuffer_unreference(&intel_fb->base); |
197 | intel_fb = ifbdev->fb = NULL; |
226 | intel_fb = ifbdev->fb = NULL; |
198 | } |
227 | } |
199 | #endif |
228 | #endif |
200 | 229 | ||
201 | if (!intel_fb || WARN_ON(!intel_fb->obj)) { |
230 | if (!intel_fb || WARN_ON(!intel_fb->obj)) { |
202 | DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n"); |
231 | DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n"); |
203 | ret = intelfb_alloc(helper, sizes); |
232 | ret = intelfb_alloc(helper, sizes); |
204 | if (ret) |
233 | if (ret) |
205 | goto out_unlock; |
234 | goto out_unlock; |
206 | intel_fb = ifbdev->fb; |
235 | intel_fb = ifbdev->fb; |
207 | } else { |
236 | } else { |
208 | DRM_DEBUG_KMS("re-using BIOS fb\n"); |
237 | DRM_DEBUG_KMS("re-using BIOS fb\n"); |
209 | prealloc = true; |
238 | prealloc = true; |
210 | sizes->fb_width = intel_fb->base.width; |
239 | sizes->fb_width = intel_fb->base.width; |
211 | sizes->fb_height = intel_fb->base.height; |
240 | sizes->fb_height = intel_fb->base.height; |
212 | } |
241 | } |
213 | 242 | ||
214 | obj = intel_fb->obj; |
243 | obj = intel_fb->obj; |
215 | size = obj->base.size; |
244 | size = obj->base.size; |
216 | 245 | ||
217 | info = framebuffer_alloc(0, &dev->pdev->dev); |
246 | info = drm_fb_helper_alloc_fbi(helper); |
218 | if (!info) { |
247 | if (IS_ERR(info)) { |
219 | ret = -ENOMEM; |
248 | ret = PTR_ERR(info); |
220 | goto out_unpin; |
249 | goto out_unpin; |
221 | } |
250 | } |
222 | 251 | ||
223 | info->par = helper; |
252 | info->par = helper; |
224 | 253 | ||
225 | fb = &ifbdev->fb->base; |
254 | fb = &ifbdev->fb->base; |
- | 255 | ||
- | 256 | if(main_framebuffer == NULL) |
|
- | 257 | main_framebuffer = fb; |
|
226 | 258 | ||
227 | ifbdev->helper.fb = fb; |
- | |
228 | ifbdev->helper.fbdev = info; |
259 | ifbdev->helper.fb = fb; |
229 | 260 | ||
230 | strcpy(info->fix.id, "inteldrmfb"); |
261 | strcpy(info->fix.id, "inteldrmfb"); |
231 | 262 | ||
232 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
263 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
233 | info->fbops = &intelfb_ops; |
264 | info->fbops = &intelfb_ops; |
234 | 265 | ||
235 | /* setup aperture base/size for vesafb takeover */ |
266 | /* setup aperture base/size for vesafb takeover */ |
236 | info->apertures = alloc_apertures(1); |
- | |
237 | if (!info->apertures) { |
- | |
238 | ret = -ENOMEM; |
- | |
239 | goto out_unpin; |
- | |
240 | } |
- | |
241 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
267 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
242 | info->apertures->ranges[0].size = dev_priv->gtt.mappable_end; |
268 | info->apertures->ranges[0].size = dev_priv->gtt.mappable_end; |
243 | 269 | ||
244 | 270 | ||
245 | info->screen_base = (void*) 0xFE000000; |
271 | info->screen_base = (void*) 0xFE000000; |
246 | info->screen_size = size; |
272 | info->screen_size = size; |
247 | 273 | ||
248 | /* This driver doesn't need a VT switch to restore the mode on resume */ |
274 | /* This driver doesn't need a VT switch to restore the mode on resume */ |
249 | info->skip_vt_switch = true; |
275 | info->skip_vt_switch = true; |
250 | 276 | ||
251 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
277 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
252 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
278 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
253 | 279 | ||
254 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
280 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
255 | 281 | ||
256 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n", |
282 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08llx, bo %p\n", |
257 | fb->width, fb->height, |
283 | fb->width, fb->height, |
258 | i915_gem_obj_ggtt_offset(obj), obj); |
284 | i915_gem_obj_ggtt_offset(obj), obj); |
259 | 285 | ||
260 | mutex_unlock(&dev->struct_mutex); |
286 | mutex_unlock(&dev->struct_mutex); |
261 | return 0; |
287 | return 0; |
- | 288 | ||
- | 289 | out_destroy_fbi: |
|
262 | 290 | drm_fb_helper_release_fbi(helper); |
|
263 | out_unpin: |
291 | out_unpin: |
264 | i915_gem_object_ggtt_unpin(obj); |
292 | i915_gem_object_ggtt_unpin(obj); |
265 | drm_gem_object_unreference(&obj->base); |
293 | drm_gem_object_unreference(&obj->base); |
266 | out_unlock: |
294 | out_unlock: |
267 | mutex_unlock(&dev->struct_mutex); |
295 | mutex_unlock(&dev->struct_mutex); |
268 | return ret; |
296 | return ret; |
269 | } |
297 | } |
270 | 298 | ||
271 | /** Sets the color ramps on behalf of RandR */ |
299 | /** Sets the color ramps on behalf of RandR */ |
272 | static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
300 | static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
273 | u16 blue, int regno) |
301 | u16 blue, int regno) |
274 | { |
302 | { |
275 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
303 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
276 | 304 | ||
277 | intel_crtc->lut_r[regno] = red >> 8; |
305 | intel_crtc->lut_r[regno] = red >> 8; |
278 | intel_crtc->lut_g[regno] = green >> 8; |
306 | intel_crtc->lut_g[regno] = green >> 8; |
279 | intel_crtc->lut_b[regno] = blue >> 8; |
307 | intel_crtc->lut_b[regno] = blue >> 8; |
280 | } |
308 | } |
281 | 309 | ||
282 | static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
310 | static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
283 | u16 *blue, int regno) |
311 | u16 *blue, int regno) |
284 | { |
312 | { |
285 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
313 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
286 | 314 | ||
287 | *red = intel_crtc->lut_r[regno] << 8; |
315 | *red = intel_crtc->lut_r[regno] << 8; |
288 | *green = intel_crtc->lut_g[regno] << 8; |
316 | *green = intel_crtc->lut_g[regno] << 8; |
289 | *blue = intel_crtc->lut_b[regno] << 8; |
317 | *blue = intel_crtc->lut_b[regno] << 8; |
290 | } |
318 | } |
291 | 319 | ||
292 | static struct drm_fb_helper_crtc * |
320 | static struct drm_fb_helper_crtc * |
293 | intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc) |
321 | intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc) |
294 | { |
322 | { |
295 | int i; |
323 | int i; |
296 | 324 | ||
297 | for (i = 0; i < fb_helper->crtc_count; i++) |
325 | for (i = 0; i < fb_helper->crtc_count; i++) |
298 | if (fb_helper->crtc_info[i].mode_set.crtc == crtc) |
326 | if (fb_helper->crtc_info[i].mode_set.crtc == crtc) |
299 | return &fb_helper->crtc_info[i]; |
327 | return &fb_helper->crtc_info[i]; |
300 | 328 | ||
301 | return NULL; |
329 | return NULL; |
302 | } |
330 | } |
303 | 331 | ||
304 | /* |
332 | /* |
305 | * Try to read the BIOS display configuration and use it for the initial |
333 | * Try to read the BIOS display configuration and use it for the initial |
306 | * fb configuration. |
334 | * fb configuration. |
307 | * |
335 | * |
308 | * The BIOS or boot loader will generally create an initial display |
336 | * The BIOS or boot loader will generally create an initial display |
309 | * configuration for us that includes some set of active pipes and displays. |
337 | * configuration for us that includes some set of active pipes and displays. |
310 | * This routine tries to figure out which pipes and connectors are active |
338 | * This routine tries to figure out which pipes and connectors are active |
311 | * and stuffs them into the crtcs and modes array given to us by the |
339 | * and stuffs them into the crtcs and modes array given to us by the |
312 | * drm_fb_helper code. |
340 | * drm_fb_helper code. |
313 | * |
341 | * |
314 | * The overall sequence is: |
342 | * The overall sequence is: |
315 | * intel_fbdev_init - from driver load |
343 | * intel_fbdev_init - from driver load |
316 | * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data |
344 | * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data |
317 | * drm_fb_helper_init - build fb helper structs |
345 | * drm_fb_helper_init - build fb helper structs |
318 | * drm_fb_helper_single_add_all_connectors - more fb helper structs |
346 | * drm_fb_helper_single_add_all_connectors - more fb helper structs |
319 | * intel_fbdev_initial_config - apply the config |
347 | * intel_fbdev_initial_config - apply the config |
320 | * drm_fb_helper_initial_config - call ->probe then register_framebuffer() |
348 | * drm_fb_helper_initial_config - call ->probe then register_framebuffer() |
321 | * drm_setup_crtcs - build crtc config for fbdev |
349 | * drm_setup_crtcs - build crtc config for fbdev |
322 | * intel_fb_initial_config - find active connectors etc |
350 | * intel_fb_initial_config - find active connectors etc |
323 | * drm_fb_helper_single_fb_probe - set up fbdev |
351 | * drm_fb_helper_single_fb_probe - set up fbdev |
324 | * intelfb_create - re-use or alloc fb, build out fbdev structs |
352 | * intelfb_create - re-use or alloc fb, build out fbdev structs |
325 | * |
353 | * |
326 | * Note that we don't make special consideration whether we could actually |
354 | * Note that we don't make special consideration whether we could actually |
327 | * switch to the selected modes without a full modeset. E.g. when the display |
355 | * switch to the selected modes without a full modeset. E.g. when the display |
328 | * is in VGA mode we need to recalculate watermarks and set a new high-res |
356 | * is in VGA mode we need to recalculate watermarks and set a new high-res |
329 | * framebuffer anyway. |
357 | * framebuffer anyway. |
330 | */ |
358 | */ |
331 | static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper, |
359 | static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper, |
332 | struct drm_fb_helper_crtc **crtcs, |
360 | struct drm_fb_helper_crtc **crtcs, |
333 | struct drm_display_mode **modes, |
361 | struct drm_display_mode **modes, |
334 | struct drm_fb_offset *offsets, |
362 | struct drm_fb_offset *offsets, |
335 | bool *enabled, int width, int height) |
363 | bool *enabled, int width, int height) |
336 | { |
364 | { |
337 | struct drm_device *dev = fb_helper->dev; |
365 | struct drm_device *dev = fb_helper->dev; |
338 | int i, j; |
366 | int i, j; |
339 | bool *save_enabled; |
367 | bool *save_enabled; |
340 | bool fallback = true; |
368 | bool fallback = true; |
341 | int num_connectors_enabled = 0; |
369 | int num_connectors_enabled = 0; |
342 | int num_connectors_detected = 0; |
370 | int num_connectors_detected = 0; |
343 | uint64_t conn_configured = 0, mask; |
371 | uint64_t conn_configured = 0, mask; |
344 | int pass = 0; |
372 | int pass = 0; |
345 | 373 | ||
346 | save_enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool), |
374 | save_enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool), |
347 | GFP_KERNEL); |
375 | GFP_KERNEL); |
348 | if (!save_enabled) |
376 | if (!save_enabled) |
349 | return false; |
377 | return false; |
350 | 378 | ||
351 | memcpy(save_enabled, enabled, dev->mode_config.num_connector); |
379 | memcpy(save_enabled, enabled, dev->mode_config.num_connector); |
352 | mask = (1 << fb_helper->connector_count) - 1; |
380 | mask = (1 << fb_helper->connector_count) - 1; |
353 | retry: |
381 | retry: |
354 | for (i = 0; i < fb_helper->connector_count; i++) { |
382 | for (i = 0; i < fb_helper->connector_count; i++) { |
355 | struct drm_fb_helper_connector *fb_conn; |
383 | struct drm_fb_helper_connector *fb_conn; |
356 | struct drm_connector *connector; |
384 | struct drm_connector *connector; |
357 | struct drm_encoder *encoder; |
385 | struct drm_encoder *encoder; |
358 | struct drm_fb_helper_crtc *new_crtc; |
386 | struct drm_fb_helper_crtc *new_crtc; |
359 | 387 | ||
360 | fb_conn = fb_helper->connector_info[i]; |
388 | fb_conn = fb_helper->connector_info[i]; |
361 | connector = fb_conn->connector; |
389 | connector = fb_conn->connector; |
362 | 390 | ||
363 | if (conn_configured & (1 << i)) |
391 | if (conn_configured & (1 << i)) |
364 | continue; |
392 | continue; |
365 | 393 | ||
366 | if (pass == 0 && !connector->has_tile) |
394 | if (pass == 0 && !connector->has_tile) |
367 | continue; |
395 | continue; |
368 | 396 | ||
369 | if (connector->status == connector_status_connected) |
397 | if (connector->status == connector_status_connected) |
370 | num_connectors_detected++; |
398 | num_connectors_detected++; |
371 | 399 | ||
372 | if (!enabled[i]) { |
400 | if (!enabled[i]) { |
373 | DRM_DEBUG_KMS("connector %s not enabled, skipping\n", |
401 | DRM_DEBUG_KMS("connector %s not enabled, skipping\n", |
374 | connector->name); |
402 | connector->name); |
375 | conn_configured |= (1 << i); |
403 | conn_configured |= (1 << i); |
376 | continue; |
404 | continue; |
377 | } |
405 | } |
378 | 406 | ||
379 | if (connector->force == DRM_FORCE_OFF) { |
407 | if (connector->force == DRM_FORCE_OFF) { |
380 | DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n", |
408 | DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n", |
381 | connector->name); |
409 | connector->name); |
382 | enabled[i] = false; |
410 | enabled[i] = false; |
383 | continue; |
411 | continue; |
384 | } |
412 | } |
385 | 413 | ||
386 | encoder = connector->encoder; |
414 | encoder = connector->encoder; |
387 | if (!encoder || WARN_ON(!encoder->crtc)) { |
415 | if (!encoder || WARN_ON(!encoder->crtc)) { |
388 | if (connector->force > DRM_FORCE_OFF) |
416 | if (connector->force > DRM_FORCE_OFF) |
389 | goto bail; |
417 | goto bail; |
390 | 418 | ||
391 | DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n", |
419 | DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n", |
392 | connector->name); |
420 | connector->name); |
393 | enabled[i] = false; |
421 | enabled[i] = false; |
394 | conn_configured |= (1 << i); |
422 | conn_configured |= (1 << i); |
395 | continue; |
423 | continue; |
396 | } |
424 | } |
397 | 425 | ||
398 | num_connectors_enabled++; |
426 | num_connectors_enabled++; |
399 | 427 | ||
400 | new_crtc = intel_fb_helper_crtc(fb_helper, encoder->crtc); |
428 | new_crtc = intel_fb_helper_crtc(fb_helper, encoder->crtc); |
401 | 429 | ||
402 | /* |
430 | /* |
403 | * Make sure we're not trying to drive multiple connectors |
431 | * Make sure we're not trying to drive multiple connectors |
404 | * with a single CRTC, since our cloning support may not |
432 | * with a single CRTC, since our cloning support may not |
405 | * match the BIOS. |
433 | * match the BIOS. |
406 | */ |
434 | */ |
407 | for (j = 0; j < fb_helper->connector_count; j++) { |
435 | for (j = 0; j < fb_helper->connector_count; j++) { |
408 | if (crtcs[j] == new_crtc) { |
436 | if (crtcs[j] == new_crtc) { |
409 | DRM_DEBUG_KMS("fallback: cloned configuration\n"); |
437 | DRM_DEBUG_KMS("fallback: cloned configuration\n"); |
410 | goto bail; |
438 | goto bail; |
411 | } |
439 | } |
412 | } |
440 | } |
413 | 441 | ||
414 | DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n", |
442 | DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n", |
415 | connector->name); |
443 | connector->name); |
416 | 444 | ||
417 | /* go for command line mode first */ |
445 | /* go for command line mode first */ |
418 | modes[i] = drm_pick_cmdline_mode(fb_conn, width, height); |
446 | modes[i] = drm_pick_cmdline_mode(fb_conn, width, height); |
419 | 447 | ||
420 | /* try for preferred next */ |
448 | /* try for preferred next */ |
421 | if (!modes[i]) { |
449 | if (!modes[i]) { |
422 | DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n", |
450 | DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n", |
423 | connector->name, connector->has_tile); |
451 | connector->name, connector->has_tile); |
424 | modes[i] = drm_has_preferred_mode(fb_conn, width, |
452 | modes[i] = drm_has_preferred_mode(fb_conn, width, |
425 | height); |
453 | height); |
426 | } |
454 | } |
427 | 455 | ||
428 | /* No preferred mode marked by the EDID? Are there any modes? */ |
456 | /* No preferred mode marked by the EDID? Are there any modes? */ |
429 | if (!modes[i] && !list_empty(&connector->modes)) { |
457 | if (!modes[i] && !list_empty(&connector->modes)) { |
430 | DRM_DEBUG_KMS("using first mode listed on connector %s\n", |
458 | DRM_DEBUG_KMS("using first mode listed on connector %s\n", |
431 | connector->name); |
459 | connector->name); |
432 | modes[i] = list_first_entry(&connector->modes, |
460 | modes[i] = list_first_entry(&connector->modes, |
433 | struct drm_display_mode, |
461 | struct drm_display_mode, |
434 | head); |
462 | head); |
435 | } |
463 | } |
436 | 464 | ||
437 | /* last resort: use current mode */ |
465 | /* last resort: use current mode */ |
438 | if (!modes[i]) { |
466 | if (!modes[i]) { |
439 | /* |
467 | /* |
440 | * IMPORTANT: We want to use the adjusted mode (i.e. |
468 | * IMPORTANT: We want to use the adjusted mode (i.e. |
441 | * after the panel fitter upscaling) as the initial |
469 | * after the panel fitter upscaling) as the initial |
442 | * config, not the input mode, which is what crtc->mode |
470 | * config, not the input mode, which is what crtc->mode |
443 | * usually contains. But since our current fastboot |
471 | * usually contains. But since our current |
444 | * code puts a mode derived from the post-pfit timings |
472 | * code puts a mode derived from the post-pfit timings |
445 | * into crtc->mode this works out correctly. We don't |
473 | * into crtc->mode this works out correctly. |
446 | * use hwmode anywhere right now, so use it for this |
- | |
447 | * since the fb helper layer wants a pointer to |
- | |
448 | * something we own. |
- | |
449 | */ |
474 | */ |
450 | DRM_DEBUG_KMS("looking for current mode on connector %s\n", |
475 | DRM_DEBUG_KMS("looking for current mode on connector %s\n", |
451 | connector->name); |
476 | connector->name); |
452 | intel_mode_from_pipe_config(&encoder->crtc->hwmode, |
- | |
453 | &to_intel_crtc(encoder->crtc)->config); |
- | |
454 | modes[i] = &encoder->crtc->hwmode; |
477 | modes[i] = &encoder->crtc->mode; |
455 | } |
478 | } |
456 | crtcs[i] = new_crtc; |
479 | crtcs[i] = new_crtc; |
457 | 480 | ||
458 | DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n", |
481 | DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n", |
459 | connector->name, |
482 | connector->name, |
460 | pipe_name(to_intel_crtc(encoder->crtc)->pipe), |
483 | pipe_name(to_intel_crtc(encoder->crtc)->pipe), |
461 | encoder->crtc->base.id, |
484 | encoder->crtc->base.id, |
462 | modes[i]->hdisplay, modes[i]->vdisplay, |
485 | modes[i]->hdisplay, modes[i]->vdisplay, |
463 | modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :""); |
486 | modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :""); |
464 | 487 | ||
465 | fallback = false; |
488 | fallback = false; |
466 | conn_configured |= (1 << i); |
489 | conn_configured |= (1 << i); |
467 | } |
490 | } |
468 | 491 | ||
469 | if ((conn_configured & mask) != mask) { |
492 | if ((conn_configured & mask) != mask) { |
470 | pass++; |
493 | pass++; |
471 | goto retry; |
494 | goto retry; |
472 | } |
495 | } |
473 | 496 | ||
474 | /* |
497 | /* |
475 | * If the BIOS didn't enable everything it could, fall back to have the |
498 | * If the BIOS didn't enable everything it could, fall back to have the |
476 | * same user experiencing of lighting up as much as possible like the |
499 | * same user experiencing of lighting up as much as possible like the |
477 | * fbdev helper library. |
500 | * fbdev helper library. |
478 | */ |
501 | */ |
479 | if (num_connectors_enabled != num_connectors_detected && |
502 | if (num_connectors_enabled != num_connectors_detected && |
480 | num_connectors_enabled < INTEL_INFO(dev)->num_pipes) { |
503 | num_connectors_enabled < INTEL_INFO(dev)->num_pipes) { |
481 | DRM_DEBUG_KMS("fallback: Not all outputs enabled\n"); |
504 | DRM_DEBUG_KMS("fallback: Not all outputs enabled\n"); |
482 | DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled, |
505 | DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled, |
483 | num_connectors_detected); |
506 | num_connectors_detected); |
484 | fallback = true; |
507 | fallback = true; |
485 | } |
508 | } |
486 | 509 | ||
487 | if (fallback) { |
510 | if (fallback) { |
488 | bail: |
511 | bail: |
489 | DRM_DEBUG_KMS("Not using firmware configuration\n"); |
512 | DRM_DEBUG_KMS("Not using firmware configuration\n"); |
490 | memcpy(enabled, save_enabled, dev->mode_config.num_connector); |
513 | memcpy(enabled, save_enabled, dev->mode_config.num_connector); |
491 | kfree(save_enabled); |
514 | kfree(save_enabled); |
492 | return false; |
515 | return false; |
493 | } |
516 | } |
494 | 517 | ||
495 | kfree(save_enabled); |
518 | kfree(save_enabled); |
496 | return true; |
519 | return true; |
497 | } |
520 | } |
498 | 521 | ||
499 | static const struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
522 | static const struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
500 | .initial_config = intel_fb_initial_config, |
523 | .initial_config = intel_fb_initial_config, |
501 | .gamma_set = intel_crtc_fb_gamma_set, |
524 | .gamma_set = intel_crtc_fb_gamma_set, |
502 | .gamma_get = intel_crtc_fb_gamma_get, |
525 | .gamma_get = intel_crtc_fb_gamma_get, |
503 | .fb_probe = intelfb_create, |
526 | .fb_probe = intelfb_create, |
504 | }; |
527 | }; |
505 | 528 | ||
506 | /* |
529 | /* |
507 | * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible. |
530 | * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible. |
508 | * The core display code will have read out the current plane configuration, |
531 | * The core display code will have read out the current plane configuration, |
509 | * so we use that to figure out if there's an object for us to use as the |
532 | * so we use that to figure out if there's an object for us to use as the |
510 | * fb, and if so, we re-use it for the fbdev configuration. |
533 | * fb, and if so, we re-use it for the fbdev configuration. |
511 | * |
534 | * |
512 | * Note we only support a single fb shared across pipes for boot (mostly for |
535 | * Note we only support a single fb shared across pipes for boot (mostly for |
513 | * fbcon), so we just find the biggest and use that. |
536 | * fbcon), so we just find the biggest and use that. |
514 | */ |
537 | */ |
515 | static bool intel_fbdev_init_bios(struct drm_device *dev, |
538 | static bool intel_fbdev_init_bios(struct drm_device *dev, |
516 | struct intel_fbdev *ifbdev) |
539 | struct intel_fbdev *ifbdev) |
517 | { |
540 | { |
518 | struct intel_framebuffer *fb = NULL; |
541 | struct intel_framebuffer *fb = NULL; |
519 | struct drm_crtc *crtc; |
542 | struct drm_crtc *crtc; |
520 | struct intel_crtc *intel_crtc; |
543 | struct intel_crtc *intel_crtc; |
521 | struct intel_plane_config *plane_config = NULL; |
- | |
522 | unsigned int max_size = 0; |
544 | unsigned int max_size = 0; |
523 | - | ||
524 | if (!i915.fastboot) |
- | |
525 | return false; |
- | |
526 | 545 | ||
527 | /* Find the largest fb */ |
546 | /* Find the largest fb */ |
- | 547 | for_each_crtc(dev, crtc) { |
|
- | 548 | struct drm_i915_gem_object *obj = |
|
528 | for_each_crtc(dev, crtc) { |
549 | intel_fb_obj(crtc->primary->state->fb); |
529 | intel_crtc = to_intel_crtc(crtc); |
550 | intel_crtc = to_intel_crtc(crtc); |
530 | 551 | ||
531 | if (!intel_crtc->active || !crtc->primary->fb) { |
552 | if (!crtc->state->active || !obj) { |
532 | DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n", |
553 | DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n", |
533 | pipe_name(intel_crtc->pipe)); |
554 | pipe_name(intel_crtc->pipe)); |
534 | continue; |
555 | continue; |
535 | } |
556 | } |
536 | 557 | ||
537 | if (intel_crtc->plane_config.size > max_size) { |
558 | if (obj->base.size > max_size) { |
538 | DRM_DEBUG_KMS("found possible fb from plane %c\n", |
559 | DRM_DEBUG_KMS("found possible fb from plane %c\n", |
539 | pipe_name(intel_crtc->pipe)); |
- | |
540 | plane_config = &intel_crtc->plane_config; |
560 | pipe_name(intel_crtc->pipe)); |
541 | fb = to_intel_framebuffer(crtc->primary->fb); |
561 | fb = to_intel_framebuffer(crtc->primary->state->fb); |
542 | max_size = plane_config->size; |
562 | max_size = obj->base.size; |
543 | } |
563 | } |
544 | } |
564 | } |
545 | 565 | ||
546 | if (!fb) { |
566 | if (!fb) { |
547 | DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n"); |
567 | DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n"); |
548 | goto out; |
568 | goto out; |
549 | } |
569 | } |
550 | 570 | ||
551 | /* Now make sure all the pipes will fit into it */ |
571 | /* Now make sure all the pipes will fit into it */ |
552 | for_each_crtc(dev, crtc) { |
572 | for_each_crtc(dev, crtc) { |
553 | unsigned int cur_size; |
573 | unsigned int cur_size; |
554 | 574 | ||
555 | intel_crtc = to_intel_crtc(crtc); |
575 | intel_crtc = to_intel_crtc(crtc); |
556 | 576 | ||
557 | if (!intel_crtc->active) { |
577 | if (!crtc->state->active) { |
558 | DRM_DEBUG_KMS("pipe %c not active, skipping\n", |
578 | DRM_DEBUG_KMS("pipe %c not active, skipping\n", |
559 | pipe_name(intel_crtc->pipe)); |
579 | pipe_name(intel_crtc->pipe)); |
560 | continue; |
580 | continue; |
561 | } |
581 | } |
562 | 582 | ||
563 | DRM_DEBUG_KMS("checking plane %c for BIOS fb\n", |
583 | DRM_DEBUG_KMS("checking plane %c for BIOS fb\n", |
564 | pipe_name(intel_crtc->pipe)); |
584 | pipe_name(intel_crtc->pipe)); |
565 | 585 | ||
566 | /* |
586 | /* |
567 | * See if the plane fb we found above will fit on this |
587 | * See if the plane fb we found above will fit on this |
568 | * pipe. Note we need to use the selected fb's pitch and bpp |
588 | * pipe. Note we need to use the selected fb's pitch and bpp |
569 | * rather than the current pipe's, since they differ. |
589 | * rather than the current pipe's, since they differ. |
570 | */ |
590 | */ |
571 | cur_size = intel_crtc->config.adjusted_mode.crtc_hdisplay; |
591 | cur_size = intel_crtc->config->base.adjusted_mode.crtc_hdisplay; |
572 | cur_size = cur_size * fb->base.bits_per_pixel / 8; |
592 | cur_size = cur_size * fb->base.bits_per_pixel / 8; |
573 | if (fb->base.pitches[0] < cur_size) { |
593 | if (fb->base.pitches[0] < cur_size) { |
574 | DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n", |
594 | DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n", |
575 | pipe_name(intel_crtc->pipe), |
595 | pipe_name(intel_crtc->pipe), |
576 | cur_size, fb->base.pitches[0]); |
596 | cur_size, fb->base.pitches[0]); |
577 | plane_config = NULL; |
- | |
578 | fb = NULL; |
597 | fb = NULL; |
579 | break; |
598 | break; |
580 | } |
599 | } |
581 | 600 | ||
582 | cur_size = intel_crtc->config.adjusted_mode.crtc_vdisplay; |
601 | cur_size = intel_crtc->config->base.adjusted_mode.crtc_vdisplay; |
- | 602 | cur_size = intel_fb_align_height(dev, cur_size, |
|
- | 603 | fb->base.pixel_format, |
|
583 | cur_size = ALIGN(cur_size, plane_config->tiled ? (IS_GEN2(dev) ? 16 : 8) : 1); |
604 | fb->base.modifier[0]); |
584 | cur_size *= fb->base.pitches[0]; |
605 | cur_size *= fb->base.pitches[0]; |
585 | DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n", |
606 | DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n", |
586 | pipe_name(intel_crtc->pipe), |
607 | pipe_name(intel_crtc->pipe), |
587 | intel_crtc->config.adjusted_mode.crtc_hdisplay, |
608 | intel_crtc->config->base.adjusted_mode.crtc_hdisplay, |
588 | intel_crtc->config.adjusted_mode.crtc_vdisplay, |
609 | intel_crtc->config->base.adjusted_mode.crtc_vdisplay, |
589 | fb->base.bits_per_pixel, |
610 | fb->base.bits_per_pixel, |
590 | cur_size); |
611 | cur_size); |
591 | 612 | ||
592 | if (cur_size > max_size) { |
613 | if (cur_size > max_size) { |
593 | DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n", |
614 | DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n", |
594 | pipe_name(intel_crtc->pipe), |
615 | pipe_name(intel_crtc->pipe), |
595 | cur_size, max_size); |
616 | cur_size, max_size); |
596 | plane_config = NULL; |
- | |
597 | fb = NULL; |
617 | fb = NULL; |
598 | break; |
618 | break; |
599 | } |
619 | } |
600 | 620 | ||
601 | DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n", |
621 | DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n", |
602 | pipe_name(intel_crtc->pipe), |
622 | pipe_name(intel_crtc->pipe), |
603 | max_size, cur_size); |
623 | max_size, cur_size); |
604 | } |
624 | } |
605 | 625 | ||
606 | if (!fb) { |
626 | if (!fb) { |
607 | DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n"); |
627 | DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n"); |
608 | goto out; |
628 | goto out; |
609 | } |
629 | } |
610 | 630 | ||
611 | ifbdev->preferred_bpp = fb->base.bits_per_pixel; |
631 | ifbdev->preferred_bpp = fb->base.bits_per_pixel; |
612 | ifbdev->fb = fb; |
632 | ifbdev->fb = fb; |
613 | 633 | ||
614 | drm_framebuffer_reference(&ifbdev->fb->base); |
634 | drm_framebuffer_reference(&ifbdev->fb->base); |
615 | 635 | ||
616 | /* Final pass to check if any active pipes don't have fbs */ |
636 | /* Final pass to check if any active pipes don't have fbs */ |
617 | for_each_crtc(dev, crtc) { |
637 | for_each_crtc(dev, crtc) { |
618 | intel_crtc = to_intel_crtc(crtc); |
638 | intel_crtc = to_intel_crtc(crtc); |
619 | 639 | ||
620 | if (!intel_crtc->active) |
640 | if (!crtc->state->active) |
621 | continue; |
641 | continue; |
622 | 642 | ||
623 | WARN(!crtc->primary->fb, |
643 | WARN(!crtc->primary->fb, |
624 | "re-used BIOS config but lost an fb on crtc %d\n", |
644 | "re-used BIOS config but lost an fb on crtc %d\n", |
625 | crtc->base.id); |
645 | crtc->base.id); |
626 | } |
646 | } |
627 | 647 | ||
628 | 648 | ||
629 | DRM_DEBUG_KMS("using BIOS fb for initial console\n"); |
649 | DRM_DEBUG_KMS("using BIOS fb for initial console\n"); |
630 | return true; |
650 | return true; |
631 | 651 | ||
632 | out: |
652 | out: |
633 | 653 | ||
634 | return false; |
654 | return false; |
635 | } |
655 | } |
636 | 656 | ||
637 | int intel_fbdev_init(struct drm_device *dev) |
657 | int intel_fbdev_init(struct drm_device *dev) |
638 | { |
658 | { |
639 | struct intel_fbdev *ifbdev; |
659 | struct intel_fbdev *ifbdev; |
640 | struct drm_i915_private *dev_priv = dev->dev_private; |
660 | struct drm_i915_private *dev_priv = dev->dev_private; |
641 | int ret; |
661 | int ret; |
642 | 662 | ||
643 | if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0)) |
663 | if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0)) |
644 | return -ENODEV; |
664 | return -ENODEV; |
645 | 665 | ||
646 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
666 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
647 | if (ifbdev == NULL) |
667 | if (ifbdev == NULL) |
648 | return -ENOMEM; |
668 | return -ENOMEM; |
649 | 669 | ||
650 | drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs); |
670 | drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs); |
651 | 671 | ||
652 | if (!intel_fbdev_init_bios(dev, ifbdev)) |
672 | if (!intel_fbdev_init_bios(dev, ifbdev)) |
653 | ifbdev->preferred_bpp = 32; |
673 | ifbdev->preferred_bpp = 32; |
654 | 674 | ||
655 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
675 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
656 | INTEL_INFO(dev)->num_pipes, 4); |
676 | INTEL_INFO(dev)->num_pipes, 4); |
657 | if (ret) { |
677 | if (ret) { |
658 | kfree(ifbdev); |
678 | kfree(ifbdev); |
659 | return ret; |
679 | return ret; |
660 | } |
680 | } |
- | 681 | ||
- | 682 | ifbdev->helper.atomic = true; |
|
661 | 683 | ||
662 | dev_priv->fbdev = ifbdev; |
684 | dev_priv->fbdev = ifbdev; |
663 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
685 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
664 | 686 | ||
665 | return 0; |
687 | return 0; |
666 | } |
688 | } |
667 | 689 | ||
668 | void intel_fbdev_initial_config(void *data, async_cookie_t cookie) |
690 | void intel_fbdev_initial_config(void *data, async_cookie_t cookie) |
669 | { |
691 | { |
670 | struct drm_i915_private *dev_priv = data; |
692 | struct drm_i915_private *dev_priv = data; |
671 | struct intel_fbdev *ifbdev = dev_priv->fbdev; |
693 | struct intel_fbdev *ifbdev = dev_priv->fbdev; |
672 | 694 | ||
673 | /* Due to peculiar init order wrt to hpd handling this is separate. */ |
695 | /* Due to peculiar init order wrt to hpd handling this is separate. */ |
674 | drm_fb_helper_initial_config(&ifbdev->helper, ifbdev->preferred_bpp); |
696 | drm_fb_helper_initial_config(&ifbdev->helper, ifbdev->preferred_bpp); |
675 | } |
697 | } |
676 | 698 | ||
677 | 699 | ||
678 | void intel_fbdev_output_poll_changed(struct drm_device *dev) |
700 | void intel_fbdev_output_poll_changed(struct drm_device *dev) |
679 | { |
701 | { |
680 | struct drm_i915_private *dev_priv = dev->dev_private; |
702 | struct drm_i915_private *dev_priv = dev->dev_private; |
681 | if (dev_priv->fbdev) |
703 | if (dev_priv->fbdev) |
682 | drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper); |
704 | drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper); |
683 | }>>><>>><>><>><>>><>>><>><>><> |
705 | }>>><>>><>><>><>>><>>><>><>><> |