Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions drivers/gpu/drm/tiny/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ obj-$(CONFIG_DRM_GM12U320) += gm12u320.o
obj-$(CONFIG_DRM_OFDRM) += ofdrm.o
obj-$(CONFIG_DRM_PANEL_MIPI_DBI) += panel-mipi-dbi.o
obj-$(CONFIG_DRM_SIMPLEDRM) += simpledrm.o
# built in only (no exports from a file that cannot include kernel headers)
ifeq ($(CONFIG_DRM_SIMPLEDRM)$(CONFIG_ARM)$(CONFIG_KERNEL_MODE_NEON),yyy)
obj-y += simpledrm_neon.o
CFLAGS_simpledrm_neon.o += $(CC_FLAGS_FPU)
CFLAGS_REMOVE_simpledrm_neon.o += -mgeneral-regs-only
endif
obj-$(CONFIG_TINYDRM_HX8357D) += hx8357d.o
obj-$(CONFIG_TINYDRM_ILI9163) += ili9163.o
obj-$(CONFIG_TINYDRM_ILI9225) += ili9225.o
Expand Down
116 changes: 110 additions & 6 deletions drivers/gpu/drm/tiny/simpledrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,16 @@ struct simpledrm_device {
*/
unsigned int rotation;
unsigned int scan_width, scan_height;
/*
* A turned scanout is also offered in its own shape (mode_other, the
* mode's width and height swapped), copied unturned, so that the
* picture can be put on its side without the compositor turning it.
*/
struct drm_display_mode mode_other;
unsigned int zoom;
u32 *row;
/* one turned tile, SIMPLEDRM_TILE squared, for the NEON copy */
u32 *tile;

/* memory management */
struct iosys_map screen_base;
Expand Down Expand Up @@ -631,6 +639,16 @@ static int simpledrm_primary_plane_helper_atomic_check(struct drm_plane *plane,

#define SIMPLEDRM_TILE 32

#if IS_BUILTIN(CONFIG_DRM_SIMPLEDRM) && IS_ENABLED(CONFIG_ARM) && \
IS_ENABLED(CONFIG_KERNEL_MODE_NEON)
#include <asm/neon.h>
#include <asm/simd.h>
#include "simpledrm_neon.h"
#define SIMPLEDRM_NEON 1
#else
#define SIMPLEDRM_NEON 0
#endif

/*
* A turned scanout can also be presented at a fraction of its size, each
* pixel then copied as a ZOOM x ZOOM block: compositors and clients without a
Expand All @@ -640,6 +658,35 @@ static unsigned int simpledrm_zoom = 1;
module_param_named(zoom, simpledrm_zoom, uint, 0444);
MODULE_PARM_DESC(zoom, "Present a turned scanout at 1/zoom size, pixels enlarged in the copy (1 or 2)");

/*
* Copy CLIP of the XRGB8888 framebuffer SRC to the scanout in its own shape,
* unturned. At zoom z each pixel is a z x z block, as in
* simpledrm_blit_rotated.
*/
static void simpledrm_blit_straight(struct simpledrm_device *sdev,
const u8 *src, unsigned int src_pitch,
const struct drm_rect *clip)
{
unsigned int z = sdev->zoom, w = clip->x2 - clip->x1, y, i, k;

for (y = clip->y1; y < clip->y2; y++) {
const u32 *px = (const u32 *)(src + y * src_pitch) + clip->x1;

if (z == 1) {
iosys_map_memcpy_to(&sdev->screen_base, y * sdev->pitch + clip->x1 * 4,
px, w * 4);
continue;
}
for (i = 0; i < w; i++)
for (k = 0; k < z; k++)
sdev->row[i * z + k] = px[i];
for (k = 0; k < z; k++)
iosys_map_memcpy_to(&sdev->screen_base,
(y * z + k) * sdev->pitch + clip->x1 * z * 4,
sdev->row, w * z * 4);
}
}

/*
* Copy CLIP of the upright XRGB8888 framebuffer SRC (pitch SRC_PITCH) to the
* scanout, turned. For rotation 90 the upright pixel (x, y) is at scanout
Expand All @@ -662,6 +709,28 @@ static void simpledrm_blit_rotated(struct simpledrm_device *sdev, const u8 *src,
for (tx = clip->x1; tx < clip->x2; tx += SIMPLEDRM_TILE) {
unsigned int x2 = min_t(unsigned int, tx + SIMPLEDRM_TILE, clip->x2);

#if SIMPLEDRM_NEON
/* the common case, unzoomed and turned 90, in 4x4 blocks */
if (z == 1 && sdev->rotation == 90 && sdev->tile && !((x2 - tx) & 3) &&
!(count & 3) && may_use_simd()) {
unsigned int r;

kernel_neon_begin();
simpledrm_neon_turn90_tile(sdev->tile, SIMPLEDRM_TILE,
src + ty * src_pitch + tx * 4, src_pitch,
x2 - tx, count);
kernel_neon_end();
for (r = 0; r < x2 - tx; r++) {
size_t off = (tx + r) * sdev->pitch +
(sdev->scan_width - y2) * 4;

iosys_map_memcpy_to(&sdev->screen_base, off,
sdev->tile + r * SIMPLEDRM_TILE,
count * 4);
}
continue;
}
#endif
for (x = tx; x < x2; x++) {
const u8 *px = src + x * 4;
long step = src_pitch;
Expand Down Expand Up @@ -700,6 +769,7 @@ static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane
struct simpledrm_device *sdev = simpledrm_device_of_dev(dev);
struct drm_atomic_helper_damage_iter iter;
struct drm_rect damage;
bool other = false;
int ret, idx;

ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
Expand All @@ -709,6 +779,10 @@ static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane
if (!drm_dev_enter(dev, &idx))
goto out_drm_gem_fb_end_cpu_access;

if (sdev->rotation)
other = drm_rect_width(&plane_state->dst) == sdev->mode_other.hdisplay &&
drm_rect_height(&plane_state->dst) == sdev->mode_other.vdisplay;

drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
drm_atomic_for_each_plane_damage(&iter, &damage) {
struct drm_rect dst_clip = plane_state->dst;
Expand All @@ -718,11 +792,15 @@ static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane
continue;

if (sdev->rotation) {
const u8 *src = shadow_plane_state->data[0].vaddr;

/* only the native format is offered when rotated */
if (fb->format != sdev->format || shadow_plane_state->data[0].is_iomem)
continue;
simpledrm_blit_rotated(sdev, shadow_plane_state->data[0].vaddr,
fb->pitches[0], &damage);
if (other)
simpledrm_blit_straight(sdev, src, fb->pitches[0], &damage);
else
simpledrm_blit_rotated(sdev, src, fb->pitches[0], &damage);
continue;
}

Expand Down Expand Up @@ -788,7 +866,11 @@ static enum drm_mode_status simpledrm_crtc_helper_mode_valid(struct drm_crtc *cr
{
struct simpledrm_device *sdev = simpledrm_device_of_dev(crtc->dev);

return drm_crtc_helper_mode_valid_fixed(crtc, mode, &sdev->mode);
enum drm_mode_status status = drm_crtc_helper_mode_valid_fixed(crtc, mode, &sdev->mode);

if (status != MODE_OK && sdev->rotation)
status = drm_crtc_helper_mode_valid_fixed(crtc, mode, &sdev->mode_other);
return status;
}

/*
Expand Down Expand Up @@ -818,7 +900,20 @@ static int simpledrm_connector_helper_get_modes(struct drm_connector *connector)
{
struct simpledrm_device *sdev = simpledrm_device_of_dev(connector->dev);

return drm_connector_helper_get_modes_fixed(connector, &sdev->mode);
struct drm_display_mode *mode;
int count;

count = drm_connector_helper_get_modes_fixed(connector, &sdev->mode);
if (!sdev->rotation)
return count;
/* the scanout's own shape, after the upright (preferred) one */
mode = drm_mode_duplicate(connector->dev, &sdev->mode_other);
if (!mode)
return count;
mode->type |= DRM_MODE_TYPE_DRIVER;
drm_mode_set_name(mode);
drm_mode_probed_add(connector, mode);
return count + 1;
}

static const struct drm_connector_helper_funcs simpledrm_connector_helper_funcs = {
Expand Down Expand Up @@ -962,6 +1057,8 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
sdev->rotation = 0;
}
if (sdev->rotation) {
sdev->tile = devm_kmalloc_array(&pdev->dev, SIMPLEDRM_TILE * SIMPLEDRM_TILE,
sizeof(u32), GFP_KERNEL);
sdev->row = devm_kmalloc_array(&pdev->dev, max(width, height), sizeof(u32),
GFP_KERNEL);
if (!sdev->row)
Expand All @@ -984,6 +1081,8 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
drm_warn(dev, "zoom needs a turned scanout; ignored\n");
}
sdev->mode = simpledrm_mode(width, height, width_mm, height_mm);
if (sdev->rotation)
sdev->mode_other = simpledrm_mode(height, width, height_mm, width_mm);
sdev->format = format;
sdev->pitch = stride;

Expand Down Expand Up @@ -1056,9 +1155,14 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
max_width = max_t(unsigned long, width, DRM_SHADOW_PLANE_MAX_WIDTH);
max_height = max_t(unsigned long, height, DRM_SHADOW_PLANE_MAX_HEIGHT);

dev->mode_config.min_width = width;
if (sdev->rotation) {
/* both shapes: the upright mode and the scanout's own */
max_width = max_t(unsigned long, max(width, height), DRM_SHADOW_PLANE_MAX_WIDTH);
max_height = max_t(unsigned long, max(width, height), DRM_SHADOW_PLANE_MAX_HEIGHT);
}
dev->mode_config.min_width = sdev->rotation ? min(width, height) : width;
dev->mode_config.max_width = max_width;
dev->mode_config.min_height = height;
dev->mode_config.min_height = sdev->rotation ? min(width, height) : height;
dev->mode_config.max_height = max_height;
dev->mode_config.preferred_depth = format->depth;
dev->mode_config.funcs = &simpledrm_mode_config_funcs;
Expand Down
47 changes: 47 additions & 0 deletions drivers/gpu/drm/tiny/simpledrm_neon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* simpledrm's turned copy, the gathering half, with NEON: four upright rows
* of four pixels loaded, transposed in registers, and stored as four runs of
* a scanout row. The scalar loop spent about 23 cycles a pixel on an A5X
* (Cortex-A9) at 1536x2048; this does a 4x4 block in a handful of
* instructions. Built with the kernel's CC_FLAGS_FPU, called between
* kernel_neon_begin() and kernel_neon_end().
*/

/*
* Only the compiler's arm_neon.h here: its stdint.h and the kernel's types do
* not mix, as in crypto/aegis128-neon-inner.c. uint32_t is u32 on ARM.
*/
#include <arm_neon.h>

void simpledrm_neon_turn90_tile(uint32_t *dst, unsigned int dst_stride, const uint8_t *src,
unsigned int src_pitch, unsigned int w, unsigned int h);

void simpledrm_neon_turn90_tile(uint32_t *dst, unsigned int dst_stride, const uint8_t *src,
unsigned int src_pitch, unsigned int w, unsigned int h)
{
unsigned int bx, by, i;

for (by = 0; by < h; by += 4) {
/* the block's rows bottom up: lane order is then the scanout's */
const uint8_t *r3 = src + (by + 3) * src_pitch, *r2 = src + (by + 2) * src_pitch;
const uint8_t *r1 = src + (by + 1) * src_pitch, *r0 = src + by * src_pitch;
uint32_t *out = dst + (h - 4 - by);

for (bx = 0; bx < w; bx += 4) {
uint32x4_t a = vld1q_u32((const uint32_t *)(r3 + bx * 4));
uint32x4_t b = vld1q_u32((const uint32_t *)(r2 + bx * 4));
uint32x4_t c = vld1q_u32((const uint32_t *)(r1 + bx * 4));
uint32x4_t d = vld1q_u32((const uint32_t *)(r0 + bx * 4));
uint32x4x2_t ab = vtrnq_u32(a, b), cd = vtrnq_u32(c, d);
uint32x4_t col[4];

col[0] = vcombine_u32(vget_low_u32(ab.val[0]), vget_low_u32(cd.val[0]));
col[1] = vcombine_u32(vget_low_u32(ab.val[1]), vget_low_u32(cd.val[1]));
col[2] = vcombine_u32(vget_high_u32(ab.val[0]), vget_high_u32(cd.val[0]));
col[3] = vcombine_u32(vget_high_u32(ab.val[1]), vget_high_u32(cd.val[1]));
for (i = 0; i < 4; i++)
vst1q_u32(out + (bx + i) * dst_stride, col[i]);
}
}
}
16 changes: 16 additions & 0 deletions drivers/gpu/drm/tiny/simpledrm_neon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef SIMPLEDRM_NEON_H
#define SIMPLEDRM_NEON_H

#include <linux/types.h>

/*
* One tile of a scanout turned 90 degrees, through NEON 4x4 transposes:
* dst[r * dst_stride + j] = upright pixel (r, h - 1 - j) of the w x h tile at
* src (XRGB8888, src_pitch bytes a line), w and h multiples of 4. Between
* kernel_neon_begin() and kernel_neon_end().
*/
void simpledrm_neon_turn90_tile(u32 *dst, unsigned int dst_stride, const u8 *src,
unsigned int src_pitch, unsigned int w, unsigned int h);

#endif
Loading