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