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