2 * drm kms/fb cma (contiguous memory allocator) helper functions
4 * Copyright (C) 2012 Analog Device Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
8 * Copyright (C) 2012 Red Hat
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include <drm/drm_fourcc.h>
21 #include <drm/drm_framebuffer.h>
22 #include <drm/drm_gem_cma_helper.h>
23 #include <drm/drm_gem_framebuffer_helper.h>
24 #include <drm/drm_plane.h>
25 #include <linux/module.h>
28 * DOC: framebuffer cma helper functions
30 * Provides helper functions for creating a cma (contiguous memory allocator)
33 * drm_gem_fb_create() is used in the &drm_mode_config_funcs.fb_create
34 * callback function to create a cma backed framebuffer.
38 * drm_fb_cma_get_gem_obj() - Get CMA GEM object for framebuffer
39 * @fb: The framebuffer
42 * Return the CMA GEM object for given framebuffer.
44 * This function will usually be called from the CRTC callback functions.
46 struct drm_gem_cma_object
*drm_fb_cma_get_gem_obj(struct drm_framebuffer
*fb
,
49 struct drm_gem_object
*gem
;
51 gem
= drm_gem_fb_get_obj(fb
, plane
);
55 return to_drm_gem_cma_obj(gem
);
57 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj
);
60 * drm_fb_cma_get_gem_addr() - Get physical address for framebuffer, for pixel
61 * formats where values are grouped in blocks this will get you the beginning of
63 * @fb: The framebuffer
64 * @state: Which state of drm plane
66 * Return the CMA GEM address for given framebuffer.
68 * This function will usually be called from the PLANE callback functions.
70 dma_addr_t
drm_fb_cma_get_gem_addr(struct drm_framebuffer
*fb
,
71 struct drm_plane_state
*state
,
74 struct drm_gem_cma_object
*obj
;
76 u8 h_div
= 1, v_div
= 1;
77 u32 block_w
= drm_format_info_block_width(fb
->format
, plane
);
78 u32 block_h
= drm_format_info_block_height(fb
->format
, plane
);
79 u32 block_size
= fb
->format
->char_per_block
[plane
];
85 obj
= drm_fb_cma_get_gem_obj(fb
, plane
);
89 paddr
= obj
->paddr
+ fb
->offsets
[plane
];
92 h_div
= fb
->format
->hsub
;
93 v_div
= fb
->format
->vsub
;
96 sample_x
= (state
->src_x
>> 16) / h_div
;
97 sample_y
= (state
->src_y
>> 16) / v_div
;
98 block_start_y
= (sample_y
/ block_h
) * block_h
;
99 num_hblocks
= sample_x
/ block_w
;
101 paddr
+= fb
->pitches
[plane
] * block_start_y
;
102 paddr
+= block_size
* num_hblocks
;
106 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_addr
);