mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
drm/msm: fbdev: Calculate buffer geometry with format helpers
Replace the geometry and size calculation in msm's fbdev emulation with DRM format helpers. This consists of a 4CC lookup from the fbdev parameters, format lookup, pitch calculation and size calculation. Then allocate the GEM buffer object for the framebuffer memory from the calculated size. Explicitly align the size of the allocated GEM buffer object to full pages. The contained memory is the framebuffer memory as seen by fbdev. The page alignment is required for mmap. v2: - clarify the page alignment of the buffer size (Dmitry) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Patchwork: https://patchwork.freedesktop.org/patch/733885/ Link: https://lore.kernel.org/r/20260618141249.151338-5-tzimmermann@suse.de Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
This commit is contained in:
parent
e78d1bc9e4
commit
6cf3fb14f3
|
|
@ -505,13 +505,6 @@ void msm_hrtimer_work_init(struct msm_hrtimer_work *work,
|
|||
#define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
|
||||
#define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
|
||||
|
||||
static inline int align_pitch(int width, int bpp)
|
||||
{
|
||||
int bytespp = (bpp + 7) / 8;
|
||||
/* adreno needs pitch aligned to 32 pixels: */
|
||||
return bytespp * ALIGN(width, 32);
|
||||
}
|
||||
|
||||
/* for the generated headers: */
|
||||
#define INVALID_IDX(idx) ({BUG(); 0;})
|
||||
#define fui(x) ({BUG(); 0;})
|
||||
|
|
|
|||
|
|
@ -95,23 +95,25 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
|
|||
struct fb_info *fbi = helper->info;
|
||||
struct drm_mode_fb_cmd2 mode_cmd = { };
|
||||
struct drm_framebuffer *fb = NULL;
|
||||
const struct drm_format_info *format;
|
||||
u32 fourcc, pitch;
|
||||
u64 size;
|
||||
struct drm_gem_object *bo;
|
||||
uint64_t paddr;
|
||||
uint32_t format;
|
||||
int ret, pitch;
|
||||
int size;
|
||||
|
||||
format = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth);
|
||||
int ret;
|
||||
|
||||
DBG("create fbdev: %dx%d@%d (%dx%d)", sizes->surface_width,
|
||||
sizes->surface_height, sizes->surface_bpp,
|
||||
sizes->fb_width, sizes->fb_height);
|
||||
|
||||
pitch = align_pitch(sizes->surface_width, sizes->surface_bpp);
|
||||
fourcc = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth);
|
||||
format = drm_get_format_info(dev, fourcc, DRM_FORMAT_MOD_LINEAR);
|
||||
/* adreno needs pitch aligned to 32 pixels: */
|
||||
pitch = drm_format_info_min_pitch(format, 0, ALIGN(sizes->surface_width, 32));
|
||||
size = ALIGN(pitch * sizes->surface_height, PAGE_SIZE);
|
||||
|
||||
/* allocate backing bo */
|
||||
size = pitch * sizes->surface_height;
|
||||
DBG("allocating %d bytes for fb %d", size, dev->primary->index);
|
||||
DBG("allocating %llu bytes for fb %d", size, dev->primary->index);
|
||||
bo = msm_gem_new(dev, size, MSM_BO_SCANOUT | MSM_BO_WC | MSM_BO_STOLEN, NULL);
|
||||
if (IS_ERR(bo)) {
|
||||
drm_warn(dev, "could not allocate stolen bo\n");
|
||||
|
|
@ -125,16 +127,12 @@ int msm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
|
|||
|
||||
msm_gem_object_set_name(bo, "stolenfb");
|
||||
|
||||
mode_cmd.pixel_format = format;
|
||||
mode_cmd.pixel_format = fourcc;
|
||||
mode_cmd.width = sizes->surface_width;
|
||||
mode_cmd.height = sizes->surface_height;
|
||||
mode_cmd.pitches[0] = pitch;
|
||||
mode_cmd.modifier[0] = DRM_FORMAT_MOD_LINEAR;
|
||||
|
||||
fb = msm_framebuffer_init(dev,
|
||||
drm_get_format_info(dev, mode_cmd.pixel_format,
|
||||
mode_cmd.modifier[0]),
|
||||
&mode_cmd, &bo);
|
||||
fb = msm_framebuffer_init(dev, format, &mode_cmd, &bo);
|
||||
if (IS_ERR(fb)) {
|
||||
drm_err(dev, "failed to allocate fb\n");
|
||||
ret = PTR_ERR(fb);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user