Rev 2336 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2332 | Serge | 1 | /* |
2 | * Copyright © 2007 David Airlie |
||
3 | * |
||
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
5 | * copy of this software and associated documentation files (the "Software"), |
||
6 | * to deal in the Software without restriction, including without limitation |
||
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 |
||
9 | * Software is furnished to do so, subject to the following conditions: |
||
10 | * |
||
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 |
||
13 | * Software. |
||
14 | * |
||
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, |
||
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 |
||
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 |
||
21 | * DEALINGS IN THE SOFTWARE. |
||
22 | * |
||
23 | * Authors: |
||
24 | * David Airlie |
||
25 | */ |
||
26 | |||
27 | #include |
||
28 | #include |
||
29 | #include |
||
30 | #include |
||
31 | //#include |
||
32 | //#include |
||
33 | #include |
||
34 | //#include |
||
35 | #include |
||
36 | //#include |
||
37 | //#include |
||
38 | |||
39 | #include "drmP.h" |
||
40 | #include "drm.h" |
||
41 | #include "drm_crtc.h" |
||
42 | #include "drm_fb_helper.h" |
||
43 | #include "intel_drv.h" |
||
44 | #include "i915_drm.h" |
||
45 | #include "i915_drv.h" |
||
46 | |||
47 | |||
2335 | Serge | 48 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
49 | { |
||
50 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
||
51 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
||
52 | int fb_info_size = sizeof(struct fb_info); |
||
53 | struct fb_info *info; |
||
54 | char *p; |
||
55 | |||
56 | if (size) |
||
57 | fb_info_size += PADDING; |
||
58 | |||
59 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
||
60 | |||
61 | if (!p) |
||
62 | return NULL; |
||
63 | |||
64 | info = (struct fb_info *) p; |
||
65 | |||
66 | if (size) |
||
67 | info->par = p + fb_info_size; |
||
68 | |||
69 | return info; |
||
70 | #undef PADDING |
||
71 | #undef BYTES_PER_LONG |
||
72 | } |
||
73 | |||
74 | |||
75 | static struct fb_ops intelfb_ops = { |
||
76 | // .owner = THIS_MODULE, |
||
77 | .fb_check_var = drm_fb_helper_check_var, |
||
78 | .fb_set_par = drm_fb_helper_set_par, |
||
79 | // .fb_fillrect = cfb_fillrect, |
||
80 | // .fb_copyarea = cfb_copyarea, |
||
81 | // .fb_imageblit = cfb_imageblit, |
||
82 | // .fb_pan_display = drm_fb_helper_pan_display, |
||
83 | .fb_blank = drm_fb_helper_blank, |
||
84 | // .fb_setcmap = drm_fb_helper_setcmap, |
||
85 | // .fb_debug_enter = drm_fb_helper_debug_enter, |
||
86 | // .fb_debug_leave = drm_fb_helper_debug_leave, |
||
87 | }; |
||
88 | |||
89 | static int intelfb_create(struct intel_fbdev *ifbdev, |
||
90 | struct drm_fb_helper_surface_size *sizes) |
||
91 | { |
||
92 | struct drm_device *dev = ifbdev->helper.dev; |
||
93 | struct drm_i915_private *dev_priv = dev->dev_private; |
||
94 | struct fb_info *info; |
||
95 | struct drm_framebuffer *fb; |
||
2342 | Serge | 96 | struct drm_mode_fb_cmd2 mode_cmd; |
2335 | Serge | 97 | struct drm_i915_gem_object *obj; |
98 | struct device *device = &dev->pdev->dev; |
||
99 | int size, ret; |
||
100 | |||
101 | /* we don't do packed 24bpp */ |
||
102 | if (sizes->surface_bpp == 24) |
||
103 | sizes->surface_bpp = 32; |
||
104 | |||
105 | mode_cmd.width = sizes->surface_width; |
||
106 | mode_cmd.height = sizes->surface_height; |
||
107 | |||
2342 | Serge | 108 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) / |
109 | 8), 64); |
||
110 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
||
111 | sizes->surface_depth); |
||
2335 | Serge | 112 | |
2342 | Serge | 113 | size = mode_cmd.pitches[0] * mode_cmd.height; |
2335 | Serge | 114 | size = ALIGN(size, PAGE_SIZE); |
115 | obj = i915_gem_alloc_object(dev, size); |
||
116 | if (!obj) { |
||
117 | DRM_ERROR("failed to allocate framebuffer\n"); |
||
118 | ret = -ENOMEM; |
||
119 | goto out; |
||
120 | } |
||
121 | |||
122 | mutex_lock(&dev->struct_mutex); |
||
123 | |||
2336 | Serge | 124 | #if 0 |
125 | // skip this part and use existing framebiffer |
||
126 | |||
2335 | Serge | 127 | /* Flush everything out, we'll be doing GTT only from now on */ |
128 | ret = intel_pin_and_fence_fb_obj(dev, obj, false); |
||
129 | if (ret) { |
||
130 | DRM_ERROR("failed to pin fb: %d\n", ret); |
||
131 | goto out_unref; |
||
132 | } |
||
2336 | Serge | 133 | #endif |
2335 | Serge | 134 | |
2336 | Serge | 135 | /***********************************************************************/ |
136 | { |
||
137 | #define LFB_SIZE 0xC00000 |
||
138 | |||
139 | static struct drm_mm_node lfb_vm_node; |
||
140 | |||
141 | lfb_vm_node.size = LFB_SIZE; |
||
142 | lfb_vm_node.start = 0; |
||
143 | lfb_vm_node.mm = NULL; |
||
144 | |||
145 | obj->gtt_space = &lfb_vm_node; |
||
146 | obj->gtt_offset = 0; |
||
147 | obj->pin_count = 1; |
||
148 | } |
||
149 | /***********************************************************************/ |
||
150 | |||
2335 | Serge | 151 | info = framebuffer_alloc(0, device); |
152 | if (!info) { |
||
153 | ret = -ENOMEM; |
||
154 | goto out_unpin; |
||
155 | } |
||
156 | |||
157 | info->par = ifbdev; |
||
158 | |||
159 | ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj); |
||
160 | if (ret) |
||
161 | goto out_unpin; |
||
162 | |||
163 | fb = &ifbdev->ifb.base; |
||
164 | |||
165 | ifbdev->helper.fb = fb; |
||
166 | ifbdev->helper.fbdev = info; |
||
167 | |||
168 | strcpy(info->fix.id, "inteldrmfb"); |
||
169 | |||
170 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
||
171 | info->fbops = &intelfb_ops; |
||
172 | |||
173 | /* setup aperture base/size for vesafb takeover */ |
||
174 | info->apertures = alloc_apertures(1); |
||
175 | if (!info->apertures) { |
||
176 | ret = -ENOMEM; |
||
177 | goto out_unpin; |
||
178 | } |
||
179 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
||
180 | info->apertures->ranges[0].size = |
||
181 | dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; |
||
182 | |||
183 | info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset; |
||
184 | info->fix.smem_len = size; |
||
185 | |||
186 | info->screen_size = size; |
||
187 | |||
188 | // memset(info->screen_base, 0, size); |
||
189 | |||
2342 | Serge | 190 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
2335 | Serge | 191 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
192 | |||
193 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x, bo %p\n", |
||
194 | fb->width, fb->height, |
||
195 | obj->gtt_offset, obj); |
||
196 | |||
197 | |||
198 | mutex_unlock(&dev->struct_mutex); |
||
199 | // vga_switcheroo_client_fb_set(dev->pdev, info); |
||
200 | return 0; |
||
201 | |||
202 | out_unpin: |
||
203 | // i915_gem_object_unpin(obj); |
||
204 | out_unref: |
||
205 | // drm_gem_object_unreference(&obj->base); |
||
206 | mutex_unlock(&dev->struct_mutex); |
||
207 | out: |
||
208 | return ret; |
||
209 | } |
||
2342 | Serge | 210 | |
2335 | Serge | 211 | static int intel_fb_find_or_create_single(struct drm_fb_helper *helper, |
212 | struct drm_fb_helper_surface_size *sizes) |
||
213 | { |
||
214 | struct intel_fbdev *ifbdev = (struct intel_fbdev *)helper; |
||
215 | int new_fb = 0; |
||
216 | int ret; |
||
217 | |||
218 | if (!helper->fb) { |
||
219 | ret = intelfb_create(ifbdev, sizes); |
||
220 | if (ret) |
||
221 | return ret; |
||
222 | new_fb = 1; |
||
223 | } |
||
224 | return new_fb; |
||
225 | } |
||
226 | |||
2332 | Serge | 227 | static struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
228 | .gamma_set = intel_crtc_fb_gamma_set, |
||
229 | .gamma_get = intel_crtc_fb_gamma_get, |
||
2335 | Serge | 230 | .fb_probe = intel_fb_find_or_create_single, |
2332 | Serge | 231 | }; |
232 | |||
233 | |||
234 | int intel_fbdev_init(struct drm_device *dev) |
||
235 | { |
||
236 | struct intel_fbdev *ifbdev; |
||
237 | drm_i915_private_t *dev_priv = dev->dev_private; |
||
238 | int ret; |
||
239 | |||
240 | ENTER(); |
||
241 | |||
242 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
||
243 | if (!ifbdev) |
||
244 | return -ENOMEM; |
||
245 | |||
246 | dev_priv->fbdev = ifbdev; |
||
247 | ifbdev->helper.funcs = &intel_fb_helper_funcs; |
||
248 | |||
249 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
||
250 | dev_priv->num_pipe, |
||
251 | INTELFB_CONN_LIMIT); |
||
252 | if (ret) { |
||
253 | kfree(ifbdev); |
||
254 | return ret; |
||
255 | } |
||
256 | |||
257 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
||
258 | drm_fb_helper_initial_config(&ifbdev->helper, 32); |
||
259 | |||
260 | LEAVE(); |
||
261 | return 0; |
||
262 | }><> |
||
263 |