Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3037 | Rev 3263 | ||
---|---|---|---|
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 | ||
- | 46 | static struct drm_i915_gem_object *fb_obj; |
|
- | 47 | ||
- | 48 | struct drm_i915_gem_object *get_fb_obj() |
|
- | 49 | { |
|
- | 50 | return fb_obj; |
|
45 | 51 | }; |
|
46 | 52 | ||
47 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
53 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
48 | { |
54 | { |
49 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
55 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
50 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
56 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
51 | int fb_info_size = sizeof(struct fb_info); |
57 | int fb_info_size = sizeof(struct fb_info); |
52 | struct fb_info *info; |
58 | struct fb_info *info; |
53 | char *p; |
59 | char *p; |
54 | 60 | ||
55 | if (size) |
61 | if (size) |
56 | fb_info_size += PADDING; |
62 | fb_info_size += PADDING; |
57 | 63 | ||
58 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
64 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
59 | 65 | ||
60 | if (!p) |
66 | if (!p) |
61 | return NULL; |
67 | return NULL; |
62 | 68 | ||
63 | info = (struct fb_info *) p; |
69 | info = (struct fb_info *) p; |
64 | 70 | ||
65 | if (size) |
71 | if (size) |
66 | info->par = p + fb_info_size; |
72 | info->par = p + fb_info_size; |
67 | 73 | ||
68 | return info; |
74 | return info; |
69 | #undef PADDING |
75 | #undef PADDING |
70 | #undef BYTES_PER_LONG |
76 | #undef BYTES_PER_LONG |
71 | } |
77 | } |
72 | 78 | ||
73 | 79 | ||
74 | static struct fb_ops intelfb_ops = { |
80 | static struct fb_ops intelfb_ops = { |
75 | .owner = THIS_MODULE, |
81 | .owner = THIS_MODULE, |
76 | .fb_check_var = drm_fb_helper_check_var, |
82 | .fb_check_var = drm_fb_helper_check_var, |
77 | .fb_set_par = drm_fb_helper_set_par, |
83 | .fb_set_par = drm_fb_helper_set_par, |
78 | // .fb_fillrect = cfb_fillrect, |
84 | // .fb_fillrect = cfb_fillrect, |
79 | // .fb_copyarea = cfb_copyarea, |
85 | // .fb_copyarea = cfb_copyarea, |
80 | // .fb_imageblit = cfb_imageblit, |
86 | // .fb_imageblit = cfb_imageblit, |
81 | // .fb_pan_display = drm_fb_helper_pan_display, |
87 | // .fb_pan_display = drm_fb_helper_pan_display, |
82 | .fb_blank = drm_fb_helper_blank, |
88 | .fb_blank = drm_fb_helper_blank, |
83 | // .fb_setcmap = drm_fb_helper_setcmap, |
89 | // .fb_setcmap = drm_fb_helper_setcmap, |
84 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
90 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
85 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
91 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
86 | }; |
92 | }; |
87 | 93 | ||
88 | static int intelfb_create(struct intel_fbdev *ifbdev, |
94 | static int intelfb_create(struct intel_fbdev *ifbdev, |
89 | struct drm_fb_helper_surface_size *sizes) |
95 | struct drm_fb_helper_surface_size *sizes) |
90 | { |
96 | { |
91 | struct drm_device *dev = ifbdev->helper.dev; |
97 | struct drm_device *dev = ifbdev->helper.dev; |
92 | struct drm_i915_private *dev_priv = dev->dev_private; |
98 | struct drm_i915_private *dev_priv = dev->dev_private; |
93 | struct fb_info *info; |
99 | struct fb_info *info; |
94 | struct drm_framebuffer *fb; |
100 | struct drm_framebuffer *fb; |
95 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
101 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
96 | struct drm_i915_gem_object *obj; |
102 | struct drm_i915_gem_object *obj; |
97 | struct device *device = &dev->pdev->dev; |
103 | struct device *device = &dev->pdev->dev; |
98 | int size, ret; |
104 | int size, ret; |
99 | 105 | ||
100 | /* we don't do packed 24bpp */ |
106 | /* we don't do packed 24bpp */ |
101 | if (sizes->surface_bpp == 24) |
107 | if (sizes->surface_bpp == 24) |
102 | sizes->surface_bpp = 32; |
108 | sizes->surface_bpp = 32; |
103 | 109 | ||
104 | mode_cmd.width = sizes->surface_width; |
110 | mode_cmd.width = sizes->surface_width; |
105 | mode_cmd.height = sizes->surface_height; |
111 | mode_cmd.height = sizes->surface_height; |
106 | 112 | ||
107 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) / |
113 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) / |
108 | 8), 64); |
114 | 8), 64); |
109 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
115 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
110 | sizes->surface_depth); |
116 | sizes->surface_depth); |
111 | 117 | ||
112 | size = mode_cmd.pitches[0] * mode_cmd.height; |
118 | size = mode_cmd.pitches[0] * mode_cmd.height; |
113 | size = ALIGN(size, PAGE_SIZE); |
119 | size = ALIGN(size, PAGE_SIZE); |
114 | obj = i915_gem_alloc_object(dev, size); |
120 | obj = i915_gem_alloc_object(dev, size); |
115 | if (!obj) { |
121 | if (!obj) { |
116 | DRM_ERROR("failed to allocate framebuffer\n"); |
122 | DRM_ERROR("failed to allocate framebuffer\n"); |
117 | ret = -ENOMEM; |
123 | ret = -ENOMEM; |
118 | goto out; |
124 | goto out; |
119 | } |
125 | } |
120 | 126 | ||
121 | mutex_lock(&dev->struct_mutex); |
127 | mutex_lock(&dev->struct_mutex); |
122 | 128 | ||
123 | #if 0 |
129 | #if 0 |
124 | // skip this part and use existing framebiffer |
130 | // skip this part and use existing framebiffer |
125 | 131 | ||
126 | /* Flush everything out, we'll be doing GTT only from now on */ |
132 | /* Flush everything out, we'll be doing GTT only from now on */ |
127 | ret = intel_pin_and_fence_fb_obj(dev, obj, false); |
133 | ret = intel_pin_and_fence_fb_obj(dev, obj, false); |
128 | if (ret) { |
134 | if (ret) { |
129 | DRM_ERROR("failed to pin fb: %d\n", ret); |
135 | DRM_ERROR("failed to pin fb: %d\n", ret); |
130 | goto out_unref; |
136 | goto out_unref; |
131 | } |
137 | } |
132 | #endif |
138 | #endif |
133 | 139 | ||
134 | /***********************************************************************/ |
140 | /***********************************************************************/ |
135 | { |
141 | { |
136 | #define LFB_SIZE 0xC00000 |
142 | #define LFB_SIZE 0xC00000 |
137 | 143 | ||
138 | static struct drm_mm_node lfb_vm_node; |
144 | static struct drm_mm_node lfb_vm_node; |
139 | 145 | ||
140 | lfb_vm_node.size = LFB_SIZE; |
146 | lfb_vm_node.size = LFB_SIZE; |
141 | lfb_vm_node.start = 0; |
147 | lfb_vm_node.start = 0; |
142 | lfb_vm_node.mm = NULL; |
148 | lfb_vm_node.mm = NULL; |
143 | 149 | ||
144 | obj->gtt_space = &lfb_vm_node; |
150 | obj->gtt_space = &lfb_vm_node; |
145 | obj->gtt_offset = 0; |
151 | obj->gtt_offset = 0; |
146 | obj->pin_count = 2; |
152 | obj->pin_count = 2; |
- | 153 | obj->cache_level = I915_CACHE_NONE; |
|
- | 154 | obj->base.write_domain = 0; |
|
- | 155 | obj->base.read_domains = I915_GEM_DOMAIN_GTT; |
|
- | 156 | ||
147 | } |
157 | } |
148 | /***********************************************************************/ |
158 | /***********************************************************************/ |
149 | 159 | ||
150 | info = framebuffer_alloc(0, device); |
160 | info = framebuffer_alloc(0, device); |
151 | if (!info) { |
161 | if (!info) { |
152 | ret = -ENOMEM; |
162 | ret = -ENOMEM; |
153 | goto out_unpin; |
163 | goto out_unpin; |
154 | } |
164 | } |
155 | 165 | ||
156 | info->par = ifbdev; |
166 | info->par = ifbdev; |
157 | 167 | ||
158 | ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj); |
168 | ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj); |
159 | if (ret) |
169 | if (ret) |
160 | goto out_unpin; |
170 | goto out_unpin; |
161 | 171 | ||
162 | fb = &ifbdev->ifb.base; |
172 | fb = &ifbdev->ifb.base; |
163 | 173 | ||
164 | ifbdev->helper.fb = fb; |
174 | ifbdev->helper.fb = fb; |
165 | ifbdev->helper.fbdev = info; |
175 | ifbdev->helper.fbdev = info; |
166 | 176 | ||
167 | strcpy(info->fix.id, "inteldrmfb"); |
177 | strcpy(info->fix.id, "inteldrmfb"); |
168 | 178 | ||
169 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
179 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
170 | info->fbops = &intelfb_ops; |
180 | info->fbops = &intelfb_ops; |
171 | 181 | ||
172 | /* setup aperture base/size for vesafb takeover */ |
182 | /* setup aperture base/size for vesafb takeover */ |
173 | info->apertures = alloc_apertures(1); |
183 | info->apertures = alloc_apertures(1); |
174 | if (!info->apertures) { |
184 | if (!info->apertures) { |
175 | ret = -ENOMEM; |
185 | ret = -ENOMEM; |
176 | goto out_unpin; |
186 | goto out_unpin; |
177 | } |
187 | } |
178 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
188 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
179 | info->apertures->ranges[0].size = |
189 | info->apertures->ranges[0].size = |
180 | dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; |
190 | dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; |
181 | 191 | ||
182 | info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset; |
192 | info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset; |
183 | info->fix.smem_len = size; |
193 | info->fix.smem_len = size; |
184 | 194 | ||
185 | info->screen_base = 0xFE000000; |
195 | info->screen_base = (void*) 0xFE000000; |
186 | info->screen_size = size; |
196 | info->screen_size = size; |
187 | 197 | ||
188 | // memset(info->screen_base, 0, size); |
198 | // memset(info->screen_base, 0, size); |
189 | 199 | ||
190 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
200 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
191 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
201 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
192 | 202 | ||
193 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
203 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
194 | 204 | ||
195 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x, bo %p\n", |
205 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x, bo %p\n", |
196 | fb->width, fb->height, |
206 | fb->width, fb->height, |
197 | obj->gtt_offset, obj); |
207 | obj->gtt_offset, obj); |
198 | 208 | ||
199 | 209 | ||
200 | mutex_unlock(&dev->struct_mutex); |
210 | mutex_unlock(&dev->struct_mutex); |
201 | // vga_switcheroo_client_fb_set(dev->pdev, info); |
211 | // vga_switcheroo_client_fb_set(dev->pdev, info); |
- | 212 | ||
- | 213 | fb_obj = obj; |
|
202 | 214 | ||
203 | return 0; |
215 | return 0; |
204 | 216 | ||
205 | out_unpin: |
217 | out_unpin: |
206 | i915_gem_object_unpin(obj); |
218 | i915_gem_object_unpin(obj); |
207 | out_unref: |
219 | out_unref: |
208 | drm_gem_object_unreference(&obj->base); |
220 | drm_gem_object_unreference(&obj->base); |
209 | mutex_unlock(&dev->struct_mutex); |
221 | mutex_unlock(&dev->struct_mutex); |
210 | out: |
222 | out: |
211 | return ret; |
223 | return ret; |
212 | } |
224 | } |
213 | 225 | ||
214 | static int intel_fb_find_or_create_single(struct drm_fb_helper *helper, |
226 | static int intel_fb_find_or_create_single(struct drm_fb_helper *helper, |
215 | struct drm_fb_helper_surface_size *sizes) |
227 | struct drm_fb_helper_surface_size *sizes) |
216 | { |
228 | { |
217 | struct intel_fbdev *ifbdev = (struct intel_fbdev *)helper; |
229 | struct intel_fbdev *ifbdev = (struct intel_fbdev *)helper; |
218 | int new_fb = 0; |
230 | int new_fb = 0; |
219 | int ret; |
231 | int ret; |
220 | 232 | ||
221 | if (!helper->fb) { |
233 | if (!helper->fb) { |
222 | ret = intelfb_create(ifbdev, sizes); |
234 | ret = intelfb_create(ifbdev, sizes); |
223 | if (ret) |
235 | if (ret) |
224 | return ret; |
236 | return ret; |
225 | new_fb = 1; |
237 | new_fb = 1; |
226 | } |
238 | } |
227 | return new_fb; |
239 | return new_fb; |
228 | } |
240 | } |
229 | 241 | ||
230 | static struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
242 | static struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
231 | .gamma_set = intel_crtc_fb_gamma_set, |
243 | .gamma_set = intel_crtc_fb_gamma_set, |
232 | .gamma_get = intel_crtc_fb_gamma_get, |
244 | .gamma_get = intel_crtc_fb_gamma_get, |
233 | .fb_probe = intel_fb_find_or_create_single, |
245 | .fb_probe = intel_fb_find_or_create_single, |
234 | }; |
246 | }; |
235 | 247 | ||
236 | 248 | ||
237 | int intel_fbdev_init(struct drm_device *dev) |
249 | int intel_fbdev_init(struct drm_device *dev) |
238 | { |
250 | { |
239 | struct intel_fbdev *ifbdev; |
251 | struct intel_fbdev *ifbdev; |
240 | drm_i915_private_t *dev_priv = dev->dev_private; |
252 | drm_i915_private_t *dev_priv = dev->dev_private; |
241 | int ret; |
253 | int ret; |
242 | 254 | ||
243 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
255 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
244 | if (!ifbdev) |
256 | if (!ifbdev) |
245 | return -ENOMEM; |
257 | return -ENOMEM; |
246 | 258 | ||
247 | dev_priv->fbdev = ifbdev; |
259 | dev_priv->fbdev = ifbdev; |
248 | ifbdev->helper.funcs = &intel_fb_helper_funcs; |
260 | ifbdev->helper.funcs = &intel_fb_helper_funcs; |
249 | 261 | ||
250 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
262 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
251 | dev_priv->num_pipe, |
263 | dev_priv->num_pipe, |
252 | INTELFB_CONN_LIMIT); |
264 | INTELFB_CONN_LIMIT); |
253 | if (ret) { |
265 | if (ret) { |
254 | kfree(ifbdev); |
266 | kfree(ifbdev); |
255 | return ret; |
267 | return ret; |
256 | } |
268 | } |
257 | 269 | ||
258 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
270 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
259 | drm_fb_helper_initial_config(&ifbdev->helper, 32); |
271 | drm_fb_helper_initial_config(&ifbdev->helper, 32); |
260 | 272 | ||
261 | return 0; |
273 | return 0; |
262 | }><> |
274 | }><> |