Rev 4280 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4280 | Rev 4389 | ||
---|---|---|---|
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 | 38 | ||
39 | #include |
39 | #include |
40 | #include |
40 | #include |
41 | #include |
41 | #include |
42 | #include "intel_drv.h" |
42 | #include "intel_drv.h" |
43 | #include |
43 | #include |
44 | #include "i915_drv.h" |
44 | #include "i915_drv.h" |
45 | 45 | ||
46 | struct drm_i915_gem_object *fb_obj; |
46 | struct drm_i915_gem_object *fb_obj; |
47 | 47 | ||
48 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
48 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
49 | { |
49 | { |
50 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
50 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
51 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
51 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
52 | int fb_info_size = sizeof(struct fb_info); |
52 | int fb_info_size = sizeof(struct fb_info); |
53 | struct fb_info *info; |
53 | struct fb_info *info; |
54 | char *p; |
54 | char *p; |
55 | 55 | ||
56 | if (size) |
56 | if (size) |
57 | fb_info_size += PADDING; |
57 | fb_info_size += PADDING; |
58 | 58 | ||
59 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
59 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
60 | 60 | ||
61 | if (!p) |
61 | if (!p) |
62 | return NULL; |
62 | return NULL; |
63 | 63 | ||
64 | info = (struct fb_info *) p; |
64 | info = (struct fb_info *) p; |
65 | 65 | ||
66 | if (size) |
66 | if (size) |
67 | info->par = p + fb_info_size; |
67 | info->par = p + fb_info_size; |
68 | 68 | ||
69 | return info; |
69 | return info; |
70 | #undef PADDING |
70 | #undef PADDING |
71 | #undef BYTES_PER_LONG |
71 | #undef BYTES_PER_LONG |
72 | } |
72 | } |
73 | 73 | ||
74 | 74 | ||
75 | static struct fb_ops intelfb_ops = { |
75 | static struct fb_ops intelfb_ops = { |
76 | .owner = THIS_MODULE, |
76 | .owner = THIS_MODULE, |
77 | .fb_check_var = drm_fb_helper_check_var, |
77 | .fb_check_var = drm_fb_helper_check_var, |
78 | .fb_set_par = drm_fb_helper_set_par, |
78 | .fb_set_par = drm_fb_helper_set_par, |
79 | // .fb_fillrect = cfb_fillrect, |
79 | // .fb_fillrect = cfb_fillrect, |
80 | // .fb_copyarea = cfb_copyarea, |
80 | // .fb_copyarea = cfb_copyarea, |
81 | // .fb_imageblit = cfb_imageblit, |
81 | // .fb_imageblit = cfb_imageblit, |
82 | // .fb_pan_display = drm_fb_helper_pan_display, |
82 | // .fb_pan_display = drm_fb_helper_pan_display, |
83 | .fb_blank = drm_fb_helper_blank, |
83 | .fb_blank = drm_fb_helper_blank, |
84 | // .fb_setcmap = drm_fb_helper_setcmap, |
84 | // .fb_setcmap = drm_fb_helper_setcmap, |
85 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
85 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
86 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
86 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
87 | }; |
87 | }; |
88 | 88 | ||
89 | static int intelfb_create(struct drm_fb_helper *helper, |
89 | static int intelfb_create(struct drm_fb_helper *helper, |
90 | struct drm_fb_helper_surface_size *sizes) |
90 | struct drm_fb_helper_surface_size *sizes) |
91 | { |
91 | { |
92 | struct intel_fbdev *ifbdev = |
92 | struct intel_fbdev *ifbdev = |
93 | container_of(helper, struct intel_fbdev, helper); |
93 | container_of(helper, struct intel_fbdev, helper); |
94 | struct drm_device *dev = helper->dev; |
94 | struct drm_device *dev = helper->dev; |
95 | struct drm_i915_private *dev_priv = dev->dev_private; |
95 | struct drm_i915_private *dev_priv = dev->dev_private; |
96 | struct fb_info *info; |
96 | struct fb_info *info; |
97 | struct drm_framebuffer *fb; |
97 | struct drm_framebuffer *fb; |
98 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
98 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
99 | struct drm_i915_gem_object *obj; |
99 | struct drm_i915_gem_object *obj; |
100 | struct device *device = &dev->pdev->dev; |
100 | struct device *device = &dev->pdev->dev; |
101 | int size, ret; |
101 | int size, ret; |
102 | - | ||
103 | ENTER(); |
- | |
104 | 102 | ||
105 | /* we don't do packed 24bpp */ |
103 | /* we don't do packed 24bpp */ |
106 | if (sizes->surface_bpp == 24) |
104 | if (sizes->surface_bpp == 24) |
107 | sizes->surface_bpp = 32; |
105 | sizes->surface_bpp = 32; |
108 | 106 | ||
109 | mode_cmd.width = sizes->surface_width; |
107 | mode_cmd.width = sizes->surface_width; |
110 | mode_cmd.height = sizes->surface_height; |
108 | mode_cmd.height = sizes->surface_height; |
111 | 109 | ||
112 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) / |
110 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) / |
113 | 8), 512); |
111 | 8), 512); |
114 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
112 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
115 | sizes->surface_depth); |
113 | sizes->surface_depth); |
116 | 114 | ||
117 | size = mode_cmd.pitches[0] * mode_cmd.height; |
115 | size = mode_cmd.pitches[0] * mode_cmd.height; |
118 | size = ALIGN(size, PAGE_SIZE); |
116 | size = ALIGN(size, PAGE_SIZE); |
119 | obj = fb_obj; |
117 | obj = fb_obj; |
120 | if (!obj) { |
118 | if (!obj) { |
121 | DRM_ERROR("failed to allocate framebuffer\n"); |
119 | DRM_ERROR("failed to allocate framebuffer\n"); |
122 | ret = -ENOMEM; |
120 | ret = -ENOMEM; |
123 | goto out; |
121 | goto out; |
124 | } |
122 | } |
125 | 123 | ||
126 | obj->stride = mode_cmd.pitches[0]; |
124 | obj->stride = mode_cmd.pitches[0]; |
127 | 125 | ||
128 | mutex_lock(&dev->struct_mutex); |
126 | mutex_lock(&dev->struct_mutex); |
129 | 127 | ||
130 | /* Flush everything out, we'll be doing GTT only from now on */ |
128 | /* Flush everything out, we'll be doing GTT only from now on */ |
131 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
129 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
132 | if (ret) { |
130 | if (ret) { |
133 | DRM_ERROR("failed to pin fb: %d\n", ret); |
131 | DRM_ERROR("failed to pin fb: %d\n", ret); |
134 | goto out_unref; |
132 | goto out_unref; |
135 | } |
133 | } |
136 | 134 | ||
137 | info = framebuffer_alloc(0, device); |
135 | info = framebuffer_alloc(0, device); |
138 | if (!info) { |
136 | if (!info) { |
139 | ret = -ENOMEM; |
137 | ret = -ENOMEM; |
140 | goto out_unpin; |
138 | goto out_unpin; |
141 | } |
139 | } |
142 | 140 | ||
143 | info->par = helper; |
141 | info->par = helper; |
144 | 142 | ||
145 | ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj); |
143 | ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj); |
146 | if (ret) |
144 | if (ret) |
147 | goto out_unpin; |
145 | goto out_unpin; |
148 | 146 | ||
149 | fb = &ifbdev->ifb.base; |
147 | fb = &ifbdev->ifb.base; |
150 | 148 | ||
151 | ifbdev->helper.fb = fb; |
149 | ifbdev->helper.fb = fb; |
152 | ifbdev->helper.fbdev = info; |
150 | ifbdev->helper.fbdev = info; |
153 | 151 | ||
154 | strcpy(info->fix.id, "inteldrmfb"); |
152 | strcpy(info->fix.id, "inteldrmfb"); |
155 | 153 | ||
156 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
154 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
157 | info->fbops = &intelfb_ops; |
155 | info->fbops = &intelfb_ops; |
158 | 156 | ||
159 | /* setup aperture base/size for vesafb takeover */ |
157 | /* setup aperture base/size for vesafb takeover */ |
160 | info->apertures = alloc_apertures(1); |
158 | info->apertures = alloc_apertures(1); |
161 | if (!info->apertures) { |
159 | if (!info->apertures) { |
162 | ret = -ENOMEM; |
160 | ret = -ENOMEM; |
163 | goto out_unpin; |
161 | goto out_unpin; |
164 | } |
162 | } |
165 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
163 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
166 | info->apertures->ranges[0].size = dev_priv->gtt.mappable_end; |
164 | info->apertures->ranges[0].size = dev_priv->gtt.mappable_end; |
167 | 165 | ||
168 | info->fix.smem_start = dev->mode_config.fb_base + i915_gem_obj_ggtt_offset(obj); |
166 | info->fix.smem_start = dev->mode_config.fb_base + i915_gem_obj_ggtt_offset(obj); |
169 | info->fix.smem_len = size; |
167 | info->fix.smem_len = size; |
170 | 168 | ||
171 | info->screen_base = (void*) 0xFE000000; |
169 | info->screen_base = (void*) 0xFE000000; |
172 | info->screen_size = size; |
170 | info->screen_size = size; |
173 | 171 | ||
174 | /* This driver doesn't need a VT switch to restore the mode on resume */ |
172 | /* This driver doesn't need a VT switch to restore the mode on resume */ |
175 | info->skip_vt_switch = true; |
173 | info->skip_vt_switch = true; |
176 | 174 | ||
177 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
175 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
178 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
176 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
179 | 177 | ||
180 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
178 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
181 | 179 | ||
182 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n", |
180 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n", |
183 | fb->width, fb->height, |
181 | fb->width, fb->height, |
184 | i915_gem_obj_ggtt_offset(obj), obj); |
182 | i915_gem_obj_ggtt_offset(obj), obj); |
185 | 183 | ||
186 | 184 | ||
187 | mutex_unlock(&dev->struct_mutex); |
185 | mutex_unlock(&dev->struct_mutex); |
188 | return 0; |
186 | return 0; |
189 | 187 | ||
190 | out_unpin: |
188 | out_unpin: |
191 | i915_gem_object_unpin(obj); |
189 | i915_gem_object_unpin(obj); |
192 | out_unref: |
190 | out_unref: |
193 | drm_gem_object_unreference(&obj->base); |
191 | drm_gem_object_unreference(&obj->base); |
194 | mutex_unlock(&dev->struct_mutex); |
192 | mutex_unlock(&dev->struct_mutex); |
195 | out: |
193 | out: |
196 | return ret; |
194 | return ret; |
197 | } |
195 | } |
198 | 196 | ||
199 | static struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
197 | static struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
200 | .gamma_set = intel_crtc_fb_gamma_set, |
198 | .gamma_set = intel_crtc_fb_gamma_set, |
201 | .gamma_get = intel_crtc_fb_gamma_get, |
199 | .gamma_get = intel_crtc_fb_gamma_get, |
202 | .fb_probe = intelfb_create, |
200 | .fb_probe = intelfb_create, |
203 | }; |
201 | }; |
204 | 202 | ||
205 | 203 | ||
206 | int intel_fbdev_init(struct drm_device *dev) |
204 | int intel_fbdev_init(struct drm_device *dev) |
207 | { |
205 | { |
208 | struct intel_fbdev *ifbdev; |
206 | struct intel_fbdev *ifbdev; |
209 | struct drm_i915_private *dev_priv = dev->dev_private; |
207 | struct drm_i915_private *dev_priv = dev->dev_private; |
210 | int ret; |
208 | int ret; |
211 | 209 | ||
212 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
210 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
213 | if (!ifbdev) |
211 | if (!ifbdev) |
214 | return -ENOMEM; |
212 | return -ENOMEM; |
215 | 213 | ||
216 | dev_priv->fbdev = ifbdev; |
214 | dev_priv->fbdev = ifbdev; |
217 | ifbdev->helper.funcs = &intel_fb_helper_funcs; |
215 | ifbdev->helper.funcs = &intel_fb_helper_funcs; |
218 | 216 | ||
219 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
217 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
220 | INTEL_INFO(dev)->num_pipes, |
218 | INTEL_INFO(dev)->num_pipes, |
221 | INTELFB_CONN_LIMIT); |
219 | INTELFB_CONN_LIMIT); |
222 | if (ret) { |
220 | if (ret) { |
223 | kfree(ifbdev); |
221 | kfree(ifbdev); |
224 | return ret; |
222 | return ret; |
225 | } |
223 | } |
226 | 224 | ||
227 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
225 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
228 | 226 | ||
229 | return 0; |
227 | return 0; |
230 | } |
228 | } |
231 | 229 | ||
232 | void intel_fbdev_initial_config(struct drm_device *dev) |
230 | void intel_fbdev_initial_config(struct drm_device *dev) |
233 | { |
231 | { |
234 | struct drm_i915_private *dev_priv = dev->dev_private; |
232 | struct drm_i915_private *dev_priv = dev->dev_private; |
235 | 233 | ||
236 | /* Due to peculiar init order wrt to hpd handling this is separate. */ |
234 | /* Due to peculiar init order wrt to hpd handling this is separate. */ |
237 | drm_fb_helper_initial_config(&dev_priv->fbdev->helper, 32); |
235 | drm_fb_helper_initial_config(&dev_priv->fbdev->helper, 32); |
238 | } |
236 | } |
239 | 237 | ||
240 | void intel_fb_output_poll_changed(struct drm_device *dev) |
238 | void intel_fb_output_poll_changed(struct drm_device *dev) |
241 | { |
239 | { |
242 | struct drm_i915_private *dev_priv = dev->dev_private; |
240 | struct drm_i915_private *dev_priv = dev->dev_private; |
243 | drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper); |
241 | drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper); |
244 | } |
242 | } |