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
7 changes: 7 additions & 0 deletions drivers/media/platform/apple/ave/abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ normal drain barrier; Flush is reserved for cancellation before Stop and Close.
KUnit checks the 1080p and 4K fields directly from the clean ledgers and embeds
no Apple command image.

H.264 P pictures are kept as references on 6070.11.1: the Process timescale
word is written as zero for H.264 (with it nonzero every P slice had
nal_ref_idc 0 and frame_num stayed at 1, which POC type 2 does not allow), and
the Start motion lambdas at 0xff98 (full-pel search), 0xffa4 (inter mode
decision) and 0xffa8 (intra mode decision) are 64, 256 and 64. HEVC keeps its
timescale.

Lifecycle-only validation
-------------------------

Expand Down
79 changes: 79 additions & 0 deletions drivers/media/platform/apple/ave/ave-abi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,84 @@ static void ave_t6041_text_boot_word(struct kunit *test)
KUNIT_EXPECT_EQ(test, ave_fw_text_boot_crc(text, size, size - 2, &a), -EINVAL);
}

/* The process timescale the qualified 6070 image writes. */
#define AVE_TEST_PROC_TIMESCALE 14400000ULL

/* Build the Start image and the first Process image of @sess. */
static void ave_test_6070_build(struct kunit *test, struct ave_ctx *ctx,
u8 *start, u8 *process, u32 bitrate)
{
const struct ave_fw_layout *fw = ctx->ave->layout;
enum ave_codec codec = ctx->sess->p.codec;
size_t start_len = fw->bytes[codec - 1][AVE_IMAGE_START];
size_t process_len = fw->bytes[codec - 1][AVE_IMAGE_PROCESS];

memset(start, 0, start_len);
memset(process, 0, process_len);
KUNIT_ASSERT_EQ(test, ave_build_start(ctx, start, start_len), 0);
KUNIT_ASSERT_EQ(test,
ave_build_process(ctx, process, process_len, 0,
0x8f0000000ULL, bitrate, false, false),
0);
}

/* h264_inter: P pictures stay references, inter decisions are weighted. */
static void ave_6070_h264_inter(struct kunit *test)
{
struct ave_dev *ave = kunit_kzalloc(test, sizeof(*ave), GFP_KERNEL);
struct ave_ctx *ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
struct ave_session *sess = kunit_kzalloc(test, sizeof(*sess), GFP_KERNEL);
u8 *start = kunit_kzalloc(test, 0x32dc8, GFP_KERNEL);
u8 *process = kunit_kzalloc(test, 0x6838, GFP_KERNEL);

KUNIT_ASSERT_NOT_NULL(test, ave);
KUNIT_ASSERT_NOT_NULL(test, ctx);
KUNIT_ASSERT_NOT_NULL(test, sess);
KUNIT_ASSERT_NOT_NULL(test, start);
KUNIT_ASSERT_NOT_NULL(test, process);
KUNIT_EXPECT_TRUE(test, ave_layout_6070_11_1.h264_inter);

for (unsigned int codec = AVE_CODEC_H264; codec <= AVE_CODEC_HEVC;
codec++) {
const struct ave_start_layout *sl;
const struct ave_proc_layout *pl;
bool h264 = codec == AVE_CODEC_H264;

ave_test_6070_session(test, ave, ctx, sess, codec, 1280, 720);
sl = &ave->layout->start[codec - 1];
pl = &ave->layout->process[codec - 1];
for (unsigned int on = 0; on < 2; on++) {
sess->p.h264_inter = on;
ave_test_6070_build(test, ctx, start, process, 4000000);
KUNIT_EXPECT_EQ(test,
get_unaligned_le64(process + pl->timescale),
on && h264 ? 0 : AVE_TEST_PROC_TIMESCALE);
if (!h264)
continue;
KUNIT_EXPECT_EQ(test,
get_unaligned_le32(start +
sl->h264_me_fullpel_lambda),
on ? 64U : 0U);
KUNIT_EXPECT_EQ(test,
get_unaligned_le32(start +
sl->h264_md_inter_lambda),
on ? 256U : 0U);
KUNIT_EXPECT_EQ(test,
get_unaligned_le32(start +
sl->h264_md_intra_lambda),
on ? 64U : 0U);
/* The other H.264 inter words are not touched. */
KUNIT_EXPECT_EQ(test,
get_unaligned_le16(start + sl->h264_skip_mode),
(u16)AVE_AVC_RECON_SKIP_MODE);
KUNIT_EXPECT_EQ(test,
get_unaligned_le32(process +
pl->static_area_mask),
(u32)AVE_AVC_STATIC_AREA_MASK_ALL);
}
}
}

/*
* The M3 generation binds probe-only: no build is pinned, the coprocessor
* is never started, and nothing is encoded, whatever layout a TEXT CRC
Expand Down Expand Up @@ -1737,6 +1815,7 @@ static struct kunit_case ave_abi_cases[] = {
KUNIT_CASE(ave_6070_replies), KUNIT_CASE(ave_6070_frame_result),
KUNIT_CASE(ave_6070_split_surfaces),
KUNIT_CASE(ave_6070_start_process_fields),
KUNIT_CASE(ave_6070_h264_inter),
KUNIT_CASE(ave_6070_reordered_pictures),
KUNIT_CASE(ave_6070_hevc_contract),
KUNIT_CASE(ave_6070_entropy_interleave),
Expand Down
4 changes: 4 additions & 0 deletions drivers/media/platform/apple/ave/ave-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ const struct ave_fw_layout ave_layout_6070_11_1 = {
.max_slots = 5,
.max_sessions = 1,
.codec_state_bytes = { 0x984, 0x5884 },
.h264_inter = true,
.start = {
[0] = {
.header = AVE_SURFACE(0x40, 0x10),
Expand Down Expand Up @@ -677,6 +678,9 @@ const struct ave_fw_layout ave_layout_6070_11_1 = {
.h264_pixel_packing = 0xfce8,
.h264_transform_mode = 0xfcec,
.h264_skip_mode = 0xfcf0,
.h264_me_fullpel_lambda = 0xff98,
.h264_md_inter_lambda = 0xffa4,
.h264_md_intra_lambda = 0xffa8,
.h264_input_bit_depth = 0xfd20,
.h264_parameter_set_count = 0xfda4,
.h264_slice_map_count = 0xfdac,
Expand Down
10 changes: 10 additions & 0 deletions drivers/media/platform/apple/ave/ave-layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ struct ave_start_layout {
u32 h264_pixel_packing;
u32 h264_transform_mode;
u32 h264_skip_mode;
/* H.264 motion lambdas. Zero leaves inter mode decision unweighted. */
u32 h264_me_fullpel_lambda;
u32 h264_md_inter_lambda;
u32 h264_md_intra_lambda;
u32 h264_input_bit_depth;
u32 h264_parameter_set_count;
u32 h264_slice_map_count;
Expand Down Expand Up @@ -382,6 +386,12 @@ struct ave_fw_layout {
u8 process_subtype, max_slots, mcc_dsid;
u8 max_sessions;
u32 codec_state_bytes[2];
/*
* Encode settings of this firmware, checked on one SoC; abi.rst says
* which and against what.
*/
/* H.264 P pictures are references; inter decisions are weighted. */
bool h264_inter;
bool counted;
/*
* A counted layout normally runs only 30 fps sessions with B-frames
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/platform/apple/ave/ave-sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ u32 ave_cq_initial_qp(u32 quality)

static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p)
{
const struct ave_fw_layout *layout = ctx->ave->layout;
bool baseline = false;
int level;

Expand All @@ -140,6 +141,7 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p)
p->fps_num = ctx->timeperframe.denominator;
p->fps_den = ctx->timeperframe.numerator;
p->fps_int = max(DIV_ROUND_CLOSEST(p->fps_num, p->fps_den), 1U);
p->h264_inter = layout->h264_inter;

if (p->codec == AVE_CODEC_H264) {
switch (ctx->h264_profile) {
Expand Down
20 changes: 19 additions & 1 deletion drivers/media/platform/apple/ave/ave-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,16 @@ static void ave_start_config(const struct ave_params *p, u8 *cmd,
ave_start_put32(cmd, l->h264_transform_mode, p->high ? 2 : 0);
if (l->h264_skip_mode)
ave_put16(cmd, l->h264_skip_mode, AVE_AVC_RECON_SKIP_MODE);
/*
* With these left zero, most of each P picture is coded as
* 8x8 partitions. They weight the full-pel search and the
* inter and intra decisions.
*/
if (p->h264_inter) {
ave_start_put32(cmd, l->h264_me_fullpel_lambda, 64);
ave_start_put32(cmd, l->h264_md_inter_lambda, 256);
ave_start_put32(cmd, l->h264_md_intra_lambda, 64);
}
ave_start_put32(cmd, l->h264_input_bit_depth, depth);
ave_start_put32(cmd, l->h264_parameter_set_count, 1);
ave_start_put32(cmd, l->h264_slice_map_count, 1);
Expand Down Expand Up @@ -1261,7 +1271,15 @@ int ave_build_process(struct ave_ctx *ctx, u8 *cmd, size_t len,
else
ave_put32(cmd, l->const5, 5);
ave_put64(cmd, l->fps, ave_f64(p->fps_num, p->fps_den));
ave_put64(cmd, l->timescale, AVE_PROC_TIMESCALE);
/*
* With a nonzero timescale every H.264 P picture is coded with
* nal_ref_idc 0. Zero keeps them references; the PTS below still
* counts in AVE_PROC_TIMESCALE.
*/
if (p->h264_inter && p->codec == AVE_CODEC_H264)
ave_put64(cmd, l->timescale, 0);
else
ave_put64(cmd, l->timescale, AVE_PROC_TIMESCALE);
if (l->crop)
ave_put32(cmd, l->crop,
p->cw != p->width || p->ch != p->height);
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/platform/apple/ave/ave.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ struct ave_params {
u32 mbs; /* 16x16 macroblocks */
u32 fps_num, fps_den; /* frames per second = num / den */
u32 fps_int; /* the same, rounded */
/* The layout's encode settings, see struct ave_fw_layout. */
bool h264_inter;
u32 slots;
u32 refs; /* max_num_ref_frames + 1 */
bool bframes;
Expand Down
Loading