diff options
author | Alan Cox <alan@linux.intel.com> | 2011-11-03 14:21:20 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2011-11-16 06:24:36 -0500 |
commit | 4d8d096e9ae86621cc38b5417f4353305c5fd3a9 (patch) | |
tree | c158eec1389cfaaf7f4945440453bb63caceddc3 | |
parent | 8c8f1c958ab5e948e954ebd97e328f23d347293b (diff) |
gma500: introduce the framebuffer support code
We support 2D acceleration on some devices but we try and do tricks with
the GTT as a starting point as this is far faster. The GTT logic could be
improved further but for most display sizes it already makes a pretty good
decision.
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r-- | drivers/gpu/drm/gma500/accel_2d.c | 362 | ||||
-rw-r--r-- | drivers/gpu/drm/gma500/framebuffer.c | 784 | ||||
-rw-r--r-- | drivers/gpu/drm/gma500/framebuffer.h | 48 |
3 files changed, 1194 insertions, 0 deletions
diff --git a/drivers/gpu/drm/gma500/accel_2d.c b/drivers/gpu/drm/gma500/accel_2d.c new file mode 100644 index 000000000000..305e6f91a7db --- /dev/null +++ b/drivers/gpu/drm/gma500/accel_2d.c | |||
@@ -0,0 +1,362 @@ | |||
1 | /************************************************************************** | ||
2 | * Copyright (c) 2007-2011, Intel Corporation. | ||
3 | * All Rights Reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to | ||
19 | * develop this driver. | ||
20 | * | ||
21 | **************************************************************************/ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/string.h> | ||
27 | #include <linux/mm.h> | ||
28 | #include <linux/tty.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/fb.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/console.h> | ||
34 | |||
35 | #include <drm/drmP.h> | ||
36 | #include <drm/drm.h> | ||
37 | #include <drm/drm_crtc.h> | ||
38 | |||
39 | #include "psb_drv.h" | ||
40 | #include "psb_reg.h" | ||
41 | #include "framebuffer.h" | ||
42 | |||
43 | /** | ||
44 | * psb_spank - reset the 2D engine | ||
45 | * @dev_priv: our PSB DRM device | ||
46 | * | ||
47 | * Soft reset the graphics engine and then reload the necessary registers. | ||
48 | * We use this at initialisation time but it will become relevant for | ||
49 | * accelerated X later | ||
50 | */ | ||
51 | void psb_spank(struct drm_psb_private *dev_priv) | ||
52 | { | ||
53 | PSB_WSGX32(_PSB_CS_RESET_BIF_RESET | _PSB_CS_RESET_DPM_RESET | | ||
54 | _PSB_CS_RESET_TA_RESET | _PSB_CS_RESET_USE_RESET | | ||
55 | _PSB_CS_RESET_ISP_RESET | _PSB_CS_RESET_TSP_RESET | | ||
56 | _PSB_CS_RESET_TWOD_RESET, PSB_CR_SOFT_RESET); | ||
57 | PSB_RSGX32(PSB_CR_SOFT_RESET); | ||
58 | |||
59 | msleep(1); | ||
60 | |||
61 | PSB_WSGX32(0, PSB_CR_SOFT_RESET); | ||
62 | wmb(); | ||
63 | PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_CB_CTRL_CLEAR_FAULT, | ||
64 | PSB_CR_BIF_CTRL); | ||
65 | wmb(); | ||
66 | (void) PSB_RSGX32(PSB_CR_BIF_CTRL); | ||
67 | |||
68 | msleep(1); | ||
69 | PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_CB_CTRL_CLEAR_FAULT, | ||
70 | PSB_CR_BIF_CTRL); | ||
71 | (void) PSB_RSGX32(PSB_CR_BIF_CTRL); | ||
72 | PSB_WSGX32(dev_priv->gtt.gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * psb2_2d_wait_available - wait for FIFO room | ||
77 | * @dev_priv: our DRM device | ||
78 | * @size: size (in dwords) of the command we want to issue | ||
79 | * | ||
80 | * Wait until there is room to load the FIFO with our data. If the | ||
81 | * device is not responding then reset it | ||
82 | */ | ||
83 | static int psb_2d_wait_available(struct drm_psb_private *dev_priv, | ||
84 | unsigned size) | ||
85 | { | ||
86 | uint32_t avail = PSB_RSGX32(PSB_CR_2D_SOCIF); | ||
87 | unsigned long t = jiffies + HZ; | ||
88 | |||
89 | while (avail < size) { | ||
90 | avail = PSB_RSGX32(PSB_CR_2D_SOCIF); | ||
91 | if (time_after(jiffies, t)) { | ||
92 | psb_spank(dev_priv); | ||
93 | return -EIO; | ||
94 | } | ||
95 | } | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * psb_2d_submit - submit a 2D command | ||
101 | * @dev_priv: our DRM device | ||
102 | * @cmdbuf: command to issue | ||
103 | * @size: length (in dwords) | ||
104 | * | ||
105 | * Issue one or more 2D commands to the accelerator. This needs to be | ||
106 | * serialized later when we add the GEM interfaces for acceleration | ||
107 | */ | ||
108 | static int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf, | ||
109 | unsigned size) | ||
110 | { | ||
111 | int ret = 0; | ||
112 | int i; | ||
113 | unsigned submit_size; | ||
114 | |||
115 | mutex_lock(&dev_priv->mutex_2d); | ||
116 | while (size > 0) { | ||
117 | submit_size = (size < 0x60) ? size : 0x60; | ||
118 | size -= submit_size; | ||
119 | ret = psb_2d_wait_available(dev_priv, submit_size); | ||
120 | if (ret) | ||
121 | break; | ||
122 | |||
123 | submit_size <<= 2; | ||
124 | |||
125 | for (i = 0; i < submit_size; i += 4) | ||
126 | PSB_WSGX32(*cmdbuf++, PSB_SGX_2D_SLAVE_PORT + i); | ||
127 | |||
128 | (void)PSB_RSGX32(PSB_SGX_2D_SLAVE_PORT + i - 4); | ||
129 | } | ||
130 | mutex_unlock(&dev_priv->mutex_2d); | ||
131 | return ret; | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
136 | * psb_accel_2d_copy_direction - compute blit order | ||
137 | * @xdir: X direction of move | ||
138 | * @ydir: Y direction of move | ||
139 | * | ||
140 | * Compute the correct order setings to ensure that an overlapping blit | ||
141 | * correctly copies all the pixels. | ||
142 | */ | ||
143 | static u32 psb_accel_2d_copy_direction(int xdir, int ydir) | ||
144 | { | ||
145 | if (xdir < 0) | ||
146 | return (ydir < 0) ? PSB_2D_COPYORDER_BR2TL : | ||
147 | PSB_2D_COPYORDER_TR2BL; | ||
148 | else | ||
149 | return (ydir < 0) ? PSB_2D_COPYORDER_BL2TR : | ||
150 | PSB_2D_COPYORDER_TL2BR; | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * psb_accel_2d_copy - accelerated 2D copy | ||
155 | * @dev_priv: our DRM device | ||
156 | * @src_offset in bytes | ||
157 | * @src_stride in bytes | ||
158 | * @src_format psb 2D format defines | ||
159 | * @dst_offset in bytes | ||
160 | * @dst_stride in bytes | ||
161 | * @dst_format psb 2D format defines | ||
162 | * @src_x offset in pixels | ||
163 | * @src_y offset in pixels | ||
164 | * @dst_x offset in pixels | ||
165 | * @dst_y offset in pixels | ||
166 | * @size_x of the copied area | ||
167 | * @size_y of the copied area | ||
168 | * | ||
169 | * Format and issue a 2D accelerated copy command. | ||
170 | */ | ||
171 | static int psb_accel_2d_copy(struct drm_psb_private *dev_priv, | ||
172 | uint32_t src_offset, uint32_t src_stride, | ||
173 | uint32_t src_format, uint32_t dst_offset, | ||
174 | uint32_t dst_stride, uint32_t dst_format, | ||
175 | uint16_t src_x, uint16_t src_y, | ||
176 | uint16_t dst_x, uint16_t dst_y, | ||
177 | uint16_t size_x, uint16_t size_y) | ||
178 | { | ||
179 | uint32_t blit_cmd; | ||
180 | uint32_t buffer[10]; | ||
181 | uint32_t *buf; | ||
182 | uint32_t direction; | ||
183 | |||
184 | buf = buffer; | ||
185 | |||
186 | direction = | ||
187 | psb_accel_2d_copy_direction(src_x - dst_x, src_y - dst_y); | ||
188 | |||
189 | if (direction == PSB_2D_COPYORDER_BR2TL || | ||
190 | direction == PSB_2D_COPYORDER_TR2BL) { | ||
191 | src_x += size_x - 1; | ||
192 | dst_x += size_x - 1; | ||
193 | } | ||
194 | if (direction == PSB_2D_COPYORDER_BR2TL || | ||
195 | direction == PSB_2D_COPYORDER_BL2TR) { | ||
196 | src_y += size_y - 1; | ||
197 | dst_y += size_y - 1; | ||
198 | } | ||
199 | |||
200 | blit_cmd = | ||
201 | PSB_2D_BLIT_BH | | ||
202 | PSB_2D_ROT_NONE | | ||
203 | PSB_2D_DSTCK_DISABLE | | ||
204 | PSB_2D_SRCCK_DISABLE | | ||
205 | PSB_2D_USE_PAT | PSB_2D_ROP3_SRCCOPY | direction; | ||
206 | |||
207 | *buf++ = PSB_2D_FENCE_BH; | ||
208 | *buf++ = | ||
209 | PSB_2D_DST_SURF_BH | dst_format | (dst_stride << | ||
210 | PSB_2D_DST_STRIDE_SHIFT); | ||
211 | *buf++ = dst_offset; | ||
212 | *buf++ = | ||
213 | PSB_2D_SRC_SURF_BH | src_format | (src_stride << | ||
214 | PSB_2D_SRC_STRIDE_SHIFT); | ||
215 | *buf++ = src_offset; | ||
216 | *buf++ = | ||
217 | PSB_2D_SRC_OFF_BH | (src_x << PSB_2D_SRCOFF_XSTART_SHIFT) | | ||
218 | (src_y << PSB_2D_SRCOFF_YSTART_SHIFT); | ||
219 | *buf++ = blit_cmd; | ||
220 | *buf++ = | ||
221 | (dst_x << PSB_2D_DST_XSTART_SHIFT) | (dst_y << | ||
222 | PSB_2D_DST_YSTART_SHIFT); | ||
223 | *buf++ = | ||
224 | (size_x << PSB_2D_DST_XSIZE_SHIFT) | (size_y << | ||
225 | PSB_2D_DST_YSIZE_SHIFT); | ||
226 | *buf++ = PSB_2D_FLUSH_BH; | ||
227 | |||
228 | return psbfb_2d_submit(dev_priv, buffer, buf - buffer); | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * psbfb_copyarea_accel - copyarea acceleration for /dev/fb | ||
233 | * @info: our framebuffer | ||
234 | * @a: copyarea parameters from the framebuffer core | ||
235 | * | ||
236 | * Perform a 2D copy via the accelerator | ||
237 | */ | ||
238 | static void psbfb_copyarea_accel(struct fb_info *info, | ||
239 | const struct fb_copyarea *a) | ||
240 | { | ||
241 | struct psb_fbdev *fbdev = info->par; | ||
242 | struct psb_framebuffer *psbfb = &fbdev->pfb; | ||
243 | struct drm_device *dev = psbfb->base.dev; | ||
244 | struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb; | ||
245 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
246 | uint32_t offset; | ||
247 | uint32_t stride; | ||
248 | uint32_t src_format; | ||
249 | uint32_t dst_format; | ||
250 | |||
251 | if (!fb) | ||
252 | return; | ||
253 | |||
254 | offset = psbfb->gtt->offset; | ||
255 | stride = fb->pitch; | ||
256 | |||
257 | switch (fb->depth) { | ||
258 | case 8: | ||
259 | src_format = PSB_2D_SRC_332RGB; | ||
260 | dst_format = PSB_2D_DST_332RGB; | ||
261 | break; | ||
262 | case 15: | ||
263 | src_format = PSB_2D_SRC_555RGB; | ||
264 | dst_format = PSB_2D_DST_555RGB; | ||
265 | break; | ||
266 | case 16: | ||
267 | src_format = PSB_2D_SRC_565RGB; | ||
268 | dst_format = PSB_2D_DST_565RGB; | ||
269 | break; | ||
270 | case 24: | ||
271 | case 32: | ||
272 | /* this is wrong but since we don't do blending its okay */ | ||
273 | src_format = PSB_2D_SRC_8888ARGB; | ||
274 | dst_format = PSB_2D_DST_8888ARGB; | ||
275 | break; | ||
276 | default: | ||
277 | /* software fallback */ | ||
278 | cfb_copyarea(info, a); | ||
279 | return; | ||
280 | } | ||
281 | |||
282 | if (!gma_power_begin(dev, false)) { | ||
283 | cfb_copyarea(info, a); | ||
284 | return; | ||
285 | } | ||
286 | psb_accel_2d_copy(dev_priv, | ||
287 | offset, stride, src_format, | ||
288 | offset, stride, dst_format, | ||
289 | a->sx, a->sy, a->dx, a->dy, a->width, a->height); | ||
290 | gma_power_end(dev); | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * psbfb_copyarea - 2D copy interface | ||
295 | * @info: our framebuffer | ||
296 | * @region: region to copy | ||
297 | * | ||
298 | * Copy an area of the framebuffer console either by the accelerator | ||
299 | * or directly using the cfb helpers according to the request | ||
300 | */ | ||
301 | void psbfb_copyarea(struct fb_info *info, | ||
302 | const struct fb_copyarea *region) | ||
303 | { | ||
304 | if (unlikely(info->state != FBINFO_STATE_RUNNING)) | ||
305 | return; | ||
306 | |||
307 | /* Avoid the 8 pixel erratum */ | ||
308 | if (region->width == 8 || region->height == 8 || | ||
309 | (info->flags & FBINFO_HWACCEL_DISABLED)) | ||
310 | return cfb_copyarea(info, region); | ||
311 | |||
312 | psbfb_copyarea_accel(info, region); | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * psbfb_sync - synchronize 2D | ||
317 | * @info: our framebuffer | ||
318 | * | ||
319 | * Wait for the 2D engine to quiesce so that we can do CPU | ||
320 | * access to the framebuffer again | ||
321 | */ | ||
322 | int psbfb_sync(struct fb_info *info) | ||
323 | { | ||
324 | struct psb_fbdev *fbdev = info->par; | ||
325 | struct psb_framebuffer *psbfb = &fbdev->pfb; | ||
326 | struct drm_device *dev = psbfb->base.dev; | ||
327 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
328 | unsigned long _end = jiffies + DRM_HZ; | ||
329 | int busy = 0; | ||
330 | |||
331 | mutex_lock(&dev_priv->mutex_2d); | ||
332 | /* | ||
333 | * First idle the 2D engine. | ||
334 | */ | ||
335 | |||
336 | if ((PSB_RSGX32(PSB_CR_2D_SOCIF) == _PSB_C2_SOCIF_EMPTY) && | ||
337 | ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) & _PSB_C2B_STATUS_BUSY) == 0)) | ||
338 | goto out; | ||
339 | |||
340 | do { | ||
341 | busy = (PSB_RSGX32(PSB_CR_2D_SOCIF) != _PSB_C2_SOCIF_EMPTY); | ||
342 | cpu_relax(); | ||
343 | } while (busy && !time_after_eq(jiffies, _end)); | ||
344 | |||
345 | if (busy) | ||
346 | busy = (PSB_RSGX32(PSB_CR_2D_SOCIF) != _PSB_C2_SOCIF_EMPTY); | ||
347 | if (busy) | ||
348 | goto out; | ||
349 | |||
350 | do { | ||
351 | busy = ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) & | ||
352 | _PSB_C2B_STATUS_BUSY) != 0); | ||
353 | cpu_relax(); | ||
354 | } while (busy && !time_after_eq(jiffies, _end)); | ||
355 | if (busy) | ||
356 | busy = ((PSB_RSGX32(PSB_CR_2D_BLIT_STATUS) & | ||
357 | _PSB_C2B_STATUS_BUSY) != 0); | ||
358 | |||
359 | out: | ||
360 | mutex_unlock(&dev_priv->mutex_2d); | ||
361 | return (busy) ? -EBUSY : 0; | ||
362 | } | ||
diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c new file mode 100644 index 000000000000..61ed7b26488e --- /dev/null +++ b/drivers/gpu/drm/gma500/framebuffer.c | |||
@@ -0,0 +1,784 @@ | |||
1 | /************************************************************************** | ||
2 | * Copyright (c) 2007-2011, Intel Corporation. | ||
3 | * All Rights Reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | **************************************************************************/ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/mm.h> | ||
25 | #include <linux/tty.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/fb.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/console.h> | ||
31 | |||
32 | #include <drm/drmP.h> | ||
33 | #include <drm/drm.h> | ||
34 | #include <drm/drm_crtc.h> | ||
35 | |||
36 | #include "psb_drv.h" | ||
37 | #include "psb_intel_reg.h" | ||
38 | #include "psb_intel_drv.h" | ||
39 | #include "framebuffer.h" | ||
40 | |||
41 | static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb); | ||
42 | static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb, | ||
43 | struct drm_file *file_priv, | ||
44 | unsigned int *handle); | ||
45 | |||
46 | static const struct drm_framebuffer_funcs psb_fb_funcs = { | ||
47 | .destroy = psb_user_framebuffer_destroy, | ||
48 | .create_handle = psb_user_framebuffer_create_handle, | ||
49 | }; | ||
50 | |||
51 | #define CMAP_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16) | ||
52 | |||
53 | static int psbfb_setcolreg(unsigned regno, unsigned red, unsigned green, | ||
54 | unsigned blue, unsigned transp, | ||
55 | struct fb_info *info) | ||
56 | { | ||
57 | struct psb_fbdev *fbdev = info->par; | ||
58 | struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb; | ||
59 | uint32_t v; | ||
60 | |||
61 | if (!fb) | ||
62 | return -ENOMEM; | ||
63 | |||
64 | if (regno > 255) | ||
65 | return 1; | ||
66 | |||
67 | red = CMAP_TOHW(red, info->var.red.length); | ||
68 | blue = CMAP_TOHW(blue, info->var.blue.length); | ||
69 | green = CMAP_TOHW(green, info->var.green.length); | ||
70 | transp = CMAP_TOHW(transp, info->var.transp.length); | ||
71 | |||
72 | v = (red << info->var.red.offset) | | ||
73 | (green << info->var.green.offset) | | ||
74 | (blue << info->var.blue.offset) | | ||
75 | (transp << info->var.transp.offset); | ||
76 | |||
77 | if (regno < 16) { | ||
78 | switch (fb->bits_per_pixel) { | ||
79 | case 16: | ||
80 | ((uint32_t *) info->pseudo_palette)[regno] = v; | ||
81 | break; | ||
82 | case 24: | ||
83 | case 32: | ||
84 | ((uint32_t *) info->pseudo_palette)[regno] = v; | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | |||
93 | void psbfb_suspend(struct drm_device *dev) | ||
94 | { | ||
95 | struct drm_framebuffer *fb = 0; | ||
96 | struct psb_framebuffer *psbfb = to_psb_fb(fb); | ||
97 | |||
98 | console_lock(); | ||
99 | mutex_lock(&dev->mode_config.mutex); | ||
100 | list_for_each_entry(fb, &dev->mode_config.fb_list, head) { | ||
101 | struct fb_info *info = psbfb->fbdev; | ||
102 | fb_set_suspend(info, 1); | ||
103 | drm_fb_helper_blank(FB_BLANK_POWERDOWN, info); | ||
104 | } | ||
105 | mutex_unlock(&dev->mode_config.mutex); | ||
106 | console_unlock(); | ||
107 | } | ||
108 | |||
109 | void psbfb_resume(struct drm_device *dev) | ||
110 | { | ||
111 | struct drm_framebuffer *fb = 0; | ||
112 | struct psb_framebuffer *psbfb = to_psb_fb(fb); | ||
113 | |||
114 | console_lock(); | ||
115 | mutex_lock(&dev->mode_config.mutex); | ||
116 | list_for_each_entry(fb, &dev->mode_config.fb_list, head) { | ||
117 | struct fb_info *info = psbfb->fbdev; | ||
118 | fb_set_suspend(info, 0); | ||
119 | drm_fb_helper_blank(FB_BLANK_UNBLANK, info); | ||
120 | } | ||
121 | mutex_unlock(&dev->mode_config.mutex); | ||
122 | console_unlock(); | ||
123 | drm_helper_disable_unused_functions(dev); | ||
124 | } | ||
125 | |||
126 | static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | ||
127 | { | ||
128 | struct psb_framebuffer *psbfb = vma->vm_private_data; | ||
129 | struct drm_device *dev = psbfb->base.dev; | ||
130 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
131 | int page_num; | ||
132 | int i; | ||
133 | unsigned long address; | ||
134 | int ret; | ||
135 | unsigned long pfn; | ||
136 | /* FIXME: assumes fb at stolen base which may not be true */ | ||
137 | unsigned long phys_addr = (unsigned long)dev_priv->stolen_base; | ||
138 | |||
139 | page_num = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; | ||
140 | address = (unsigned long)vmf->virtual_address; | ||
141 | |||
142 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | ||
143 | |||
144 | for (i = 0; i < page_num; i++) { | ||
145 | pfn = (phys_addr >> PAGE_SHIFT); | ||
146 | |||
147 | ret = vm_insert_mixed(vma, address, pfn); | ||
148 | if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0))) | ||
149 | break; | ||
150 | else if (unlikely(ret != 0)) { | ||
151 | ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; | ||
152 | return ret; | ||
153 | } | ||
154 | address += PAGE_SIZE; | ||
155 | phys_addr += PAGE_SIZE; | ||
156 | } | ||
157 | return VM_FAULT_NOPAGE; | ||
158 | } | ||
159 | |||
160 | static void psbfb_vm_open(struct vm_area_struct *vma) | ||
161 | { | ||
162 | } | ||
163 | |||
164 | static void psbfb_vm_close(struct vm_area_struct *vma) | ||
165 | { | ||
166 | } | ||
167 | |||
168 | static struct vm_operations_struct psbfb_vm_ops = { | ||
169 | .fault = psbfb_vm_fault, | ||
170 | .open = psbfb_vm_open, | ||
171 | .close = psbfb_vm_close | ||
172 | }; | ||
173 | |||
174 | static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma) | ||
175 | { | ||
176 | struct psb_fbdev *fbdev = info->par; | ||
177 | struct psb_framebuffer *psbfb = &fbdev->pfb; | ||
178 | |||
179 | if (vma->vm_pgoff != 0) | ||
180 | return -EINVAL; | ||
181 | if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) | ||
182 | return -EINVAL; | ||
183 | |||
184 | if (!psbfb->addr_space) | ||
185 | psbfb->addr_space = vma->vm_file->f_mapping; | ||
186 | /* | ||
187 | * If this is a GEM object then info->screen_base is the virtual | ||
188 | * kernel remapping of the object. FIXME: Review if this is | ||
189 | * suitable for our mmap work | ||
190 | */ | ||
191 | vma->vm_ops = &psbfb_vm_ops; | ||
192 | vma->vm_private_data = (void *)psbfb; | ||
193 | vma->vm_flags |= VM_RESERVED | VM_IO | | ||
194 | VM_MIXEDMAP | VM_DONTEXPAND; | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static int psbfb_ioctl(struct fb_info *info, unsigned int cmd, | ||
199 | unsigned long arg) | ||
200 | { | ||
201 | return -ENOTTY; | ||
202 | } | ||
203 | |||
204 | static struct fb_ops psbfb_ops = { | ||
205 | .owner = THIS_MODULE, | ||
206 | .fb_check_var = drm_fb_helper_check_var, | ||
207 | .fb_set_par = drm_fb_helper_set_par, | ||
208 | .fb_blank = drm_fb_helper_blank, | ||
209 | .fb_setcolreg = psbfb_setcolreg, | ||
210 | .fb_fillrect = cfb_fillrect, | ||
211 | .fb_copyarea = psbfb_copyarea, | ||
212 | .fb_imageblit = cfb_imageblit, | ||
213 | .fb_mmap = psbfb_mmap, | ||
214 | .fb_sync = psbfb_sync, | ||
215 | .fb_ioctl = psbfb_ioctl, | ||
216 | }; | ||
217 | |||
218 | static struct fb_ops psbfb_unaccel_ops = { | ||
219 | .owner = THIS_MODULE, | ||
220 | .fb_check_var = drm_fb_helper_check_var, | ||
221 | .fb_set_par = drm_fb_helper_set_par, | ||
222 | .fb_blank = drm_fb_helper_blank, | ||
223 | .fb_setcolreg = psbfb_setcolreg, | ||
224 | .fb_fillrect = cfb_fillrect, | ||
225 | .fb_copyarea = cfb_copyarea, | ||
226 | .fb_imageblit = cfb_imageblit, | ||
227 | .fb_mmap = psbfb_mmap, | ||
228 | .fb_ioctl = psbfb_ioctl, | ||
229 | }; | ||
230 | |||
231 | /** | ||
232 | * psb_framebuffer_init - initialize a framebuffer | ||
233 | * @dev: our DRM device | ||
234 | * @fb: framebuffer to set up | ||
235 | * @mode_cmd: mode description | ||
236 | * @gt: backing object | ||
237 | * | ||
238 | * Configure and fill in the boilerplate for our frame buffer. Return | ||
239 | * 0 on success or an error code if we fail. | ||
240 | */ | ||
241 | static int psb_framebuffer_init(struct drm_device *dev, | ||
242 | struct psb_framebuffer *fb, | ||
243 | struct drm_mode_fb_cmd *mode_cmd, | ||
244 | struct gtt_range *gt) | ||
245 | { | ||
246 | int ret; | ||
247 | |||
248 | if (mode_cmd->pitch & 63) | ||
249 | return -EINVAL; | ||
250 | switch (mode_cmd->bpp) { | ||
251 | case 8: | ||
252 | case 16: | ||
253 | case 24: | ||
254 | case 32: | ||
255 | break; | ||
256 | default: | ||
257 | return -EINVAL; | ||
258 | } | ||
259 | ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs); | ||
260 | if (ret) { | ||
261 | dev_err(dev->dev, "framebuffer init failed: %d\n", ret); | ||
262 | return ret; | ||
263 | } | ||
264 | drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd); | ||
265 | fb->gtt = gt; | ||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | /** | ||
270 | * psb_framebuffer_create - create a framebuffer backed by gt | ||
271 | * @dev: our DRM device | ||
272 | * @mode_cmd: the description of the requested mode | ||
273 | * @gt: the backing object | ||
274 | * | ||
275 | * Create a framebuffer object backed by the gt, and fill in the | ||
276 | * boilerplate required | ||
277 | * | ||
278 | * TODO: review object references | ||
279 | */ | ||
280 | |||
281 | static struct drm_framebuffer *psb_framebuffer_create | ||
282 | (struct drm_device *dev, | ||
283 | struct drm_mode_fb_cmd *mode_cmd, | ||
284 | struct gtt_range *gt) | ||
285 | { | ||
286 | struct psb_framebuffer *fb; | ||
287 | int ret; | ||
288 | |||
289 | fb = kzalloc(sizeof(*fb), GFP_KERNEL); | ||
290 | if (!fb) | ||
291 | return ERR_PTR(-ENOMEM); | ||
292 | |||
293 | ret = psb_framebuffer_init(dev, fb, mode_cmd, gt); | ||
294 | if (ret) { | ||
295 | kfree(fb); | ||
296 | return ERR_PTR(ret); | ||
297 | } | ||
298 | return &fb->base; | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * psbfb_alloc - allocate frame buffer memory | ||
303 | * @dev: the DRM device | ||
304 | * @aligned_size: space needed | ||
305 | * | ||
306 | * Allocate the frame buffer. In the usual case we get a GTT range that | ||
307 | * is stolen memory backed and life is simple. If there isn't sufficient | ||
308 | * stolen memory or the system has no stolen memory we allocate a range | ||
309 | * and back it with a GEM object. | ||
310 | * | ||
311 | * In this case the GEM object has no handle. | ||
312 | * | ||
313 | * FIXME: console speed up - allocate twice the space if room and use | ||
314 | * hardware scrolling for acceleration. | ||
315 | */ | ||
316 | static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size) | ||
317 | { | ||
318 | struct gtt_range *backing; | ||
319 | /* Begin by trying to use stolen memory backing */ | ||
320 | backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1); | ||
321 | if (backing) { | ||
322 | if (drm_gem_private_object_init(dev, | ||
323 | &backing->gem, aligned_size) == 0) | ||
324 | return backing; | ||
325 | psb_gtt_free_range(dev, backing); | ||
326 | } | ||
327 | /* Next try using GEM host memory */ | ||
328 | backing = psb_gtt_alloc_range(dev, aligned_size, "fb(gem)", 0); | ||
329 | if (backing == NULL) | ||
330 | return NULL; | ||
331 | |||
332 | /* Now back it with an object */ | ||
333 | if (drm_gem_object_init(dev, &backing->gem, aligned_size) != 0) { | ||
334 | psb_gtt_free_range(dev, backing); | ||
335 | return NULL; | ||
336 | } | ||
337 | return backing; | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * psbfb_create - create a framebuffer | ||
342 | * @fbdev: the framebuffer device | ||
343 | * @sizes: specification of the layout | ||
344 | * | ||
345 | * Create a framebuffer to the specifications provided | ||
346 | */ | ||
347 | static int psbfb_create(struct psb_fbdev *fbdev, | ||
348 | struct drm_fb_helper_surface_size *sizes) | ||
349 | { | ||
350 | struct drm_device *dev = fbdev->psb_fb_helper.dev; | ||
351 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
352 | struct fb_info *info; | ||
353 | struct drm_framebuffer *fb; | ||
354 | struct psb_framebuffer *psbfb = &fbdev->pfb; | ||
355 | struct drm_mode_fb_cmd mode_cmd; | ||
356 | struct device *device = &dev->pdev->dev; | ||
357 | int size; | ||
358 | int ret; | ||
359 | struct gtt_range *backing; | ||
360 | |||
361 | mode_cmd.width = sizes->surface_width; | ||
362 | mode_cmd.height = sizes->surface_height; | ||
363 | mode_cmd.bpp = sizes->surface_bpp; | ||
364 | |||
365 | /* No 24bit packed */ | ||
366 | if (mode_cmd.bpp == 24) | ||
367 | mode_cmd.bpp = 32; | ||
368 | |||
369 | /* HW requires pitch to be 64 byte aligned */ | ||
370 | mode_cmd.pitch = ALIGN(mode_cmd.width * ((mode_cmd.bpp + 7) / 8), 64); | ||
371 | mode_cmd.depth = sizes->surface_depth; | ||
372 | |||
373 | size = mode_cmd.pitch * mode_cmd.height; | ||
374 | size = ALIGN(size, PAGE_SIZE); | ||
375 | |||
376 | /* Allocate the framebuffer in the GTT with stolen page backing */ | ||
377 | backing = psbfb_alloc(dev, size); | ||
378 | if (backing == NULL) | ||
379 | return -ENOMEM; | ||
380 | |||
381 | mutex_lock(&dev->struct_mutex); | ||
382 | |||
383 | info = framebuffer_alloc(0, device); | ||
384 | if (!info) { | ||
385 | ret = -ENOMEM; | ||
386 | goto out_err1; | ||
387 | } | ||
388 | info->par = fbdev; | ||
389 | |||
390 | ret = psb_framebuffer_init(dev, psbfb, &mode_cmd, backing); | ||
391 | if (ret) | ||
392 | goto out_unref; | ||
393 | |||
394 | fb = &psbfb->base; | ||
395 | psbfb->fbdev = info; | ||
396 | |||
397 | fbdev->psb_fb_helper.fb = fb; | ||
398 | fbdev->psb_fb_helper.fbdev = info; | ||
399 | |||
400 | strcpy(info->fix.id, "psbfb"); | ||
401 | |||
402 | info->flags = FBINFO_DEFAULT; | ||
403 | /* No 2D engine */ | ||
404 | if (!dev_priv->ops->accel_2d) | ||
405 | info->fbops = &psbfb_unaccel_ops; | ||
406 | else | ||
407 | info->fbops = &psbfb_ops; | ||
408 | |||
409 | ret = fb_alloc_cmap(&info->cmap, 256, 0); | ||
410 | if (ret) { | ||
411 | ret = -ENOMEM; | ||
412 | goto out_unref; | ||
413 | } | ||
414 | |||
415 | info->fix.smem_start = dev->mode_config.fb_base; | ||
416 | info->fix.smem_len = size; | ||
417 | |||
418 | if (backing->stolen) { | ||
419 | /* Accessed stolen memory directly */ | ||
420 | info->screen_base = (char *)dev_priv->vram_addr + | ||
421 | backing->offset; | ||
422 | } else { | ||
423 | /* Pin the pages into the GTT and create a mapping to them */ | ||
424 | psb_gtt_pin(backing); | ||
425 | info->screen_base = vm_map_ram(backing->pages, backing->npage, | ||
426 | -1, PAGE_KERNEL); | ||
427 | if (info->screen_base == NULL) { | ||
428 | psb_gtt_unpin(backing); | ||
429 | ret = -ENOMEM; | ||
430 | goto out_unref; | ||
431 | } | ||
432 | psbfb->vm_map = 1; | ||
433 | } | ||
434 | info->screen_size = size; | ||
435 | |||
436 | if (dev_priv->gtt.stolen_size) { | ||
437 | info->apertures = alloc_apertures(1); | ||
438 | if (!info->apertures) { | ||
439 | ret = -ENOMEM; | ||
440 | goto out_unref; | ||
441 | } | ||
442 | info->apertures->ranges[0].base = dev->mode_config.fb_base; | ||
443 | info->apertures->ranges[0].size = dev_priv->gtt.stolen_size; | ||
444 | } | ||
445 | |||
446 | drm_fb_helper_fill_fix(info, fb->pitch, fb->depth); | ||
447 | drm_fb_helper_fill_var(info, &fbdev->psb_fb_helper, | ||
448 | sizes->fb_width, sizes->fb_height); | ||
449 | |||
450 | info->fix.mmio_start = pci_resource_start(dev->pdev, 0); | ||
451 | info->fix.mmio_len = pci_resource_len(dev->pdev, 0); | ||
452 | |||
453 | info->pixmap.size = 64 * 1024; | ||
454 | info->pixmap.buf_align = 8; | ||
455 | info->pixmap.access_align = 32; | ||
456 | info->pixmap.flags = FB_PIXMAP_SYSTEM; | ||
457 | info->pixmap.scan_align = 1; | ||
458 | |||
459 | dev_info(dev->dev, "allocated %dx%d fb\n", | ||
460 | psbfb->base.width, psbfb->base.height); | ||
461 | |||
462 | mutex_unlock(&dev->struct_mutex); | ||
463 | return 0; | ||
464 | out_unref: | ||
465 | if (backing->stolen) | ||
466 | psb_gtt_free_range(dev, backing); | ||
467 | else { | ||
468 | if (psbfb->vm_map) | ||
469 | vm_unmap_ram(info->screen_base, backing->npage); | ||
470 | drm_gem_object_unreference(&backing->gem); | ||
471 | } | ||
472 | out_err1: | ||
473 | mutex_unlock(&dev->struct_mutex); | ||
474 | psb_gtt_free_range(dev, backing); | ||
475 | return ret; | ||
476 | } | ||
477 | |||
478 | /** | ||
479 | * psb_user_framebuffer_create - create framebuffer | ||
480 | * @dev: our DRM device | ||
481 | * @filp: client file | ||
482 | * @cmd: mode request | ||
483 | * | ||
484 | * Create a new framebuffer backed by a userspace GEM object | ||
485 | */ | ||
486 | static struct drm_framebuffer *psb_user_framebuffer_create | ||
487 | (struct drm_device *dev, struct drm_file *filp, | ||
488 | struct drm_mode_fb_cmd *cmd) | ||
489 | { | ||
490 | struct gtt_range *r; | ||
491 | struct drm_gem_object *obj; | ||
492 | |||
493 | /* | ||
494 | * Find the GEM object and thus the gtt range object that is | ||
495 | * to back this space | ||
496 | */ | ||
497 | obj = drm_gem_object_lookup(dev, filp, cmd->handle); | ||
498 | if (obj == NULL) | ||
499 | return ERR_PTR(-ENOENT); | ||
500 | |||
501 | /* Let the core code do all the work */ | ||
502 | r = container_of(obj, struct gtt_range, gem); | ||
503 | return psb_framebuffer_create(dev, cmd, r); | ||
504 | } | ||
505 | |||
506 | static void psbfb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, | ||
507 | u16 blue, int regno) | ||
508 | { | ||
509 | } | ||
510 | |||
511 | static void psbfb_gamma_get(struct drm_crtc *crtc, u16 *red, | ||
512 | u16 *green, u16 *blue, int regno) | ||
513 | { | ||
514 | } | ||
515 | |||
516 | static int psbfb_probe(struct drm_fb_helper *helper, | ||
517 | struct drm_fb_helper_surface_size *sizes) | ||
518 | { | ||
519 | struct psb_fbdev *psb_fbdev = (struct psb_fbdev *)helper; | ||
520 | int new_fb = 0; | ||
521 | int ret; | ||
522 | |||
523 | if (!helper->fb) { | ||
524 | ret = psbfb_create(psb_fbdev, sizes); | ||
525 | if (ret) | ||
526 | return ret; | ||
527 | new_fb = 1; | ||
528 | } | ||
529 | return new_fb; | ||
530 | } | ||
531 | |||
532 | struct drm_fb_helper_funcs psb_fb_helper_funcs = { | ||
533 | .gamma_set = psbfb_gamma_set, | ||
534 | .gamma_get = psbfb_gamma_get, | ||
535 | .fb_probe = psbfb_probe, | ||
536 | }; | ||
537 | |||
538 | int psb_fbdev_destroy(struct drm_device *dev, struct psb_fbdev *fbdev) | ||
539 | { | ||
540 | struct fb_info *info; | ||
541 | struct psb_framebuffer *psbfb = &fbdev->pfb; | ||
542 | |||
543 | if (fbdev->psb_fb_helper.fbdev) { | ||
544 | info = fbdev->psb_fb_helper.fbdev; | ||
545 | |||
546 | /* If this is our base framebuffer then kill any virtual map | ||
547 | for the framebuffer layer and unpin it */ | ||
548 | if (psbfb->vm_map) { | ||
549 | vm_unmap_ram(info->screen_base, psbfb->gtt->npage); | ||
550 | psb_gtt_unpin(psbfb->gtt); | ||
551 | } | ||
552 | unregister_framebuffer(info); | ||
553 | if (info->cmap.len) | ||
554 | fb_dealloc_cmap(&info->cmap); | ||
555 | framebuffer_release(info); | ||
556 | } | ||
557 | drm_fb_helper_fini(&fbdev->psb_fb_helper); | ||
558 | drm_framebuffer_cleanup(&psbfb->base); | ||
559 | |||
560 | if (psbfb->gtt) | ||
561 | drm_gem_object_unreference(&psbfb->gtt->gem); | ||
562 | return 0; | ||
563 | } | ||
564 | |||
565 | int psb_fbdev_init(struct drm_device *dev) | ||
566 | { | ||
567 | struct psb_fbdev *fbdev; | ||
568 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
569 | |||
570 | fbdev = kzalloc(sizeof(struct psb_fbdev), GFP_KERNEL); | ||
571 | if (!fbdev) { | ||
572 | dev_err(dev->dev, "no memory\n"); | ||
573 | return -ENOMEM; | ||
574 | } | ||
575 | |||
576 | dev_priv->fbdev = fbdev; | ||
577 | fbdev->psb_fb_helper.funcs = &psb_fb_helper_funcs; | ||
578 | |||
579 | drm_fb_helper_init(dev, &fbdev->psb_fb_helper, dev_priv->ops->crtcs, | ||
580 | INTELFB_CONN_LIMIT); | ||
581 | |||
582 | drm_fb_helper_single_add_all_connectors(&fbdev->psb_fb_helper); | ||
583 | drm_fb_helper_initial_config(&fbdev->psb_fb_helper, 32); | ||
584 | return 0; | ||
585 | } | ||
586 | |||
587 | void psb_fbdev_fini(struct drm_device *dev) | ||
588 | { | ||
589 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
590 | |||
591 | if (!dev_priv->fbdev) | ||
592 | return; | ||
593 | |||
594 | psb_fbdev_destroy(dev, dev_priv->fbdev); | ||
595 | kfree(dev_priv->fbdev); | ||
596 | dev_priv->fbdev = NULL; | ||
597 | } | ||
598 | |||
599 | static void psbfb_output_poll_changed(struct drm_device *dev) | ||
600 | { | ||
601 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
602 | struct psb_fbdev *fbdev = (struct psb_fbdev *)dev_priv->fbdev; | ||
603 | drm_fb_helper_hotplug_event(&fbdev->psb_fb_helper); | ||
604 | } | ||
605 | |||
606 | /** | ||
607 | * psb_user_framebuffer_create_handle - add hamdle to a framebuffer | ||
608 | * @fb: framebuffer | ||
609 | * @file_priv: our DRM file | ||
610 | * @handle: returned handle | ||
611 | * | ||
612 | * Our framebuffer object is a GTT range which also contains a GEM | ||
613 | * object. We need to turn it into a handle for userspace. GEM will do | ||
614 | * the work for us | ||
615 | */ | ||
616 | static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb, | ||
617 | struct drm_file *file_priv, | ||
618 | unsigned int *handle) | ||
619 | { | ||
620 | struct psb_framebuffer *psbfb = to_psb_fb(fb); | ||
621 | struct gtt_range *r = psbfb->gtt; | ||
622 | return drm_gem_handle_create(file_priv, &r->gem, handle); | ||
623 | } | ||
624 | |||
625 | /** | ||
626 | * psb_user_framebuffer_destroy - destruct user created fb | ||
627 | * @fb: framebuffer | ||
628 | * | ||
629 | * User framebuffers are backed by GEM objects so all we have to do is | ||
630 | * clean up a bit and drop the reference, GEM will handle the fallout | ||
631 | */ | ||
632 | static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb) | ||
633 | { | ||
634 | struct psb_framebuffer *psbfb = to_psb_fb(fb); | ||
635 | struct gtt_range *r = psbfb->gtt; | ||
636 | struct drm_device *dev = fb->dev; | ||
637 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
638 | struct psb_fbdev *fbdev = dev_priv->fbdev; | ||
639 | struct drm_crtc *crtc; | ||
640 | int reset = 0; | ||
641 | |||
642 | /* Should never get stolen memory for a user fb */ | ||
643 | WARN_ON(r->stolen); | ||
644 | |||
645 | /* Check if we are erroneously live */ | ||
646 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | ||
647 | if (crtc->fb == fb) | ||
648 | reset = 1; | ||
649 | |||
650 | if (reset) | ||
651 | /* | ||
652 | * Now force a sane response before we permit the DRM CRTC | ||
653 | * layer to do stupid things like blank the display. Instead | ||
654 | * we reset this framebuffer as if the user had forced a reset. | ||
655 | * We must do this before the cleanup so that the DRM layer | ||
656 | * doesn't get a chance to stick its oar in where it isn't | ||
657 | * wanted. | ||
658 | */ | ||
659 | drm_fb_helper_restore_fbdev_mode(&fbdev->psb_fb_helper); | ||
660 | |||
661 | /* Let DRM do its clean up */ | ||
662 | drm_framebuffer_cleanup(fb); | ||
663 | /* We are no longer using the resource in GEM */ | ||
664 | drm_gem_object_unreference_unlocked(&r->gem); | ||
665 | kfree(fb); | ||
666 | } | ||
667 | |||
668 | static const struct drm_mode_config_funcs psb_mode_funcs = { | ||
669 | .fb_create = psb_user_framebuffer_create, | ||
670 | .output_poll_changed = psbfb_output_poll_changed, | ||
671 | }; | ||
672 | |||
673 | static int psb_create_backlight_property(struct drm_device *dev) | ||
674 | { | ||
675 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
676 | struct drm_property *backlight; | ||
677 | |||
678 | if (dev_priv->backlight_property) | ||
679 | return 0; | ||
680 | |||
681 | backlight = drm_property_create(dev, DRM_MODE_PROP_RANGE, | ||
682 | "backlight", 2); | ||
683 | backlight->values[0] = 0; | ||
684 | backlight->values[1] = 100; | ||
685 | |||
686 | dev_priv->backlight_property = backlight; | ||
687 | |||
688 | return 0; | ||
689 | } | ||
690 | |||
691 | static void psb_setup_outputs(struct drm_device *dev) | ||
692 | { | ||
693 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
694 | struct drm_connector *connector; | ||
695 | |||
696 | drm_mode_create_scaling_mode_property(dev); | ||
697 | psb_create_backlight_property(dev); | ||
698 | |||
699 | dev_priv->ops->output_init(dev); | ||
700 | |||
701 | list_for_each_entry(connector, &dev->mode_config.connector_list, | ||
702 | head) { | ||
703 | struct psb_intel_output *psb_intel_output = | ||
704 | to_psb_intel_output(connector); | ||
705 | struct drm_encoder *encoder = &psb_intel_output->enc; | ||
706 | int crtc_mask = 0, clone_mask = 0; | ||
707 | |||
708 | /* valid crtcs */ | ||
709 | switch (psb_intel_output->type) { | ||
710 | case INTEL_OUTPUT_ANALOG: | ||
711 | crtc_mask = (1 << 0); | ||
712 | clone_mask = (1 << INTEL_OUTPUT_ANALOG); | ||
713 | break; | ||
714 | case INTEL_OUTPUT_SDVO: | ||
715 | crtc_mask = ((1 << 0) | (1 << 1)); | ||
716 | clone_mask = (1 << INTEL_OUTPUT_SDVO); | ||
717 | break; | ||
718 | case INTEL_OUTPUT_LVDS: | ||
719 | if (IS_MRST(dev)) | ||
720 | crtc_mask = (1 << 0); | ||
721 | else | ||
722 | crtc_mask = (1 << 1); | ||
723 | clone_mask = (1 << INTEL_OUTPUT_LVDS); | ||
724 | break; | ||
725 | case INTEL_OUTPUT_MIPI: | ||
726 | crtc_mask = (1 << 0); | ||
727 | clone_mask = (1 << INTEL_OUTPUT_MIPI); | ||
728 | break; | ||
729 | case INTEL_OUTPUT_MIPI2: | ||
730 | crtc_mask = (1 << 2); | ||
731 | clone_mask = (1 << INTEL_OUTPUT_MIPI2); | ||
732 | break; | ||
733 | case INTEL_OUTPUT_HDMI: | ||
734 | if (IS_MFLD(dev)) | ||
735 | crtc_mask = (1 << 1); | ||
736 | else | ||
737 | crtc_mask = (1 << 0); | ||
738 | clone_mask = (1 << INTEL_OUTPUT_HDMI); | ||
739 | break; | ||
740 | } | ||
741 | encoder->possible_crtcs = crtc_mask; | ||
742 | encoder->possible_clones = | ||
743 | psb_intel_connector_clones(dev, clone_mask); | ||
744 | } | ||
745 | } | ||
746 | |||
747 | void psb_modeset_init(struct drm_device *dev) | ||
748 | { | ||
749 | struct drm_psb_private *dev_priv = dev->dev_private; | ||
750 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; | ||
751 | int i; | ||
752 | |||
753 | drm_mode_config_init(dev); | ||
754 | |||
755 | dev->mode_config.min_width = 0; | ||
756 | dev->mode_config.min_height = 0; | ||
757 | |||
758 | dev->mode_config.funcs = (void *) &psb_mode_funcs; | ||
759 | |||
760 | /* set memory base */ | ||
761 | /* MRST and PSB should use BAR 2*/ | ||
762 | pci_read_config_dword(dev->pdev, PSB_BSM, (u32 *) | ||
763 | &(dev->mode_config.fb_base)); | ||
764 | |||
765 | /* num pipes is 2 for PSB but 1 for Mrst */ | ||
766 | for (i = 0; i < dev_priv->num_pipe; i++) | ||
767 | psb_intel_crtc_init(dev, i, mode_dev); | ||
768 | |||
769 | dev->mode_config.max_width = 2048; | ||
770 | dev->mode_config.max_height = 2048; | ||
771 | |||
772 | psb_setup_outputs(dev); | ||
773 | } | ||
774 | |||
775 | void psb_modeset_cleanup(struct drm_device *dev) | ||
776 | { | ||
777 | mutex_lock(&dev->struct_mutex); | ||
778 | |||
779 | drm_kms_helper_poll_fini(dev); | ||
780 | psb_fbdev_fini(dev); | ||
781 | drm_mode_config_cleanup(dev); | ||
782 | |||
783 | mutex_unlock(&dev->struct_mutex); | ||
784 | } | ||
diff --git a/drivers/gpu/drm/gma500/framebuffer.h b/drivers/gpu/drm/gma500/framebuffer.h new file mode 100644 index 000000000000..d1b2289447f0 --- /dev/null +++ b/drivers/gpu/drm/gma500/framebuffer.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008-2011, Intel Corporation | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along with | ||
14 | * this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | * | ||
17 | * Authors: | ||
18 | * Eric Anholt <eric@anholt.net> | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #ifndef _FRAMEBUFFER_H_ | ||
23 | #define _FRAMEBUFFER_H_ | ||
24 | |||
25 | #include <drm/drmP.h> | ||
26 | #include <drm/drm_fb_helper.h> | ||
27 | |||
28 | #include "psb_drv.h" | ||
29 | |||
30 | struct psb_framebuffer { | ||
31 | struct drm_framebuffer base; | ||
32 | struct address_space *addr_space; | ||
33 | struct fb_info *fbdev; | ||
34 | struct gtt_range *gtt; | ||
35 | bool vm_map; /* True if we must undo a vm_map_ram */ | ||
36 | }; | ||
37 | |||
38 | struct psb_fbdev { | ||
39 | struct drm_fb_helper psb_fb_helper; | ||
40 | struct psb_framebuffer pfb; | ||
41 | }; | ||
42 | |||
43 | #define to_psb_fb(x) container_of(x, struct psb_framebuffer, base) | ||
44 | |||
45 | extern int psb_intel_connector_clones(struct drm_device *dev, int type_mask); | ||
46 | |||
47 | #endif | ||
48 | |||