Skip to content
Draft
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
120 changes: 119 additions & 1 deletion drivers/media/platform/apple/ave/ave-abi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2279,10 +2279,128 @@ static void ave_m3_probe_only(struct kunit *test)
KUNIT_EXPECT_EQ(test, ave_fw_check_boot(ave), -EOPNOTSUPP);
}

static void ave_6070_hevc_main10(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);
struct ave_6070_avc_recon_layout recon;
const struct ave_start_layout *sl = &ave_layout_6070_11_1.start[1];
const struct ave_proc_layout *pl = &ave_layout_6070_11_1.process[1];
size_t slen = ave_layout_6070_11_1.bytes[1][AVE_IMAGE_START];
size_t plen = ave_layout_6070_11_1.bytes[1][AVE_IMAGE_PROCESS];
u8 *start = kunit_kzalloc(test, slen, GFP_KERNEL);
u8 *proc = kunit_kzalloc(test, plen, 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, proc);

ave_test_6070_session(test, ave, ctx, sess, AVE_CODEC_HEVC, 1920, 1080);
sess->p.profile = 2;
sess->p.bit_depth = 10;
sess->p.sample_bytes = 2;
sess->p.stride = ALIGN(1920 * 2, 64);
sess->p.min_qp = -AVE_QP_BD_OFFSET_10;
sess->p.rc_mode = 3;
sess->p.initial_qp = 26;

KUNIT_ASSERT_EQ(test, ave_build_start(ctx, start, slen), 0);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(start + sl->hevc_profile_a), 2U);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(start + sl->hevc_profile_b), 2U);
KUNIT_EXPECT_EQ(test, start[sl->hevc_compat_a + 1], 0U);
KUNIT_EXPECT_EQ(test, start[sl->hevc_compat_a + 2], 1U);
KUNIT_EXPECT_EQ(test, start[sl->hevc_compat_b + 1], 0U);
KUNIT_EXPECT_EQ(test, start[sl->hevc_compat_b + 2], 1U);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(start + sl->hevc_depth_luma), 2U);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(start + sl->hevc_depth_chroma), 2U);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(start + sl->hevc_input_depth), 10U);
KUNIT_EXPECT_EQ(test, (s32)get_unaligned_le32(start + sl->min_qp), -12);

recon = ave_6070_recon_layout(1920, 1080, 10);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(start + sl->recon.address),
sess->ref_a[0].dma + recon.luma_data_offset);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(start + sl->recon.address + 8),
sess->ref_a[0].dma + recon.luma_metadata_offset);

KUNIT_ASSERT_EQ(test, ave_build_process(ctx, proc, plen, 0,
0x10000000ULL, 0, false, false), 0);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(proc + pl->current_recon.luma_data),
sess->ref_a[0].dma + recon.luma_data_offset);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(proc + pl->current_recon.chroma_data),
sess->ref_a[0].dma + recon.chroma_data_offset);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(proc + pl->current_recon.luma_metadata),
sess->ref_a[0].dma + recon.luma_metadata_offset);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(proc + pl->current_recon.chroma_metadata),
sess->ref_a[0].dma + recon.chroma_metadata_offset);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(proc + pl->y + 8), sess->p.stride);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(proc + pl->uv),
0x10000000ULL + (u64)sess->p.stride * 1080);
}

static void ave_hevc_vui_colorimetry(struct kunit *test)
{
static const struct ave_fw_layout * const layouts[] = {
&ave_layout_9003_78_0,
&ave_layout_26a428,
&ave_layout_26b123,
&ave_layout_6070_11_1,
};
static const u32 vui_off[] = { 0x74a0, 0x80a4, 0x80a4, 0x262bc };

for (unsigned int i = 0; i < ARRAY_SIZE(layouts); i++) {
const struct ave_fw_layout *fw = layouts[i];
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);
size_t len = fw->bytes[1][AVE_IMAGE_START];
u8 *cmd = kunit_kzalloc(test, len, 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, cmd);

if (fw->kind == AVE_LAYOUT_6070) {
ave_test_6070_session(test, ave, ctx, sess, AVE_CODEC_HEVC, 1920, 1080);
} else {
ave->layout = fw;
ctx->ave = ave;
ctx->sess = sess;
ave_test_session(sess, AVE_CODEC_HEVC, 1920, 1080, true);
}
sess->p.profile = 2;
sess->p.bit_depth = 10;
sess->p.vui_color = true;
sess->p.vui_primaries = 9;
sess->p.vui_transfer = 16;
sess->p.vui_matrix = 9;
sess->p.vui_full_range = 1;

KUNIT_ASSERT_EQ(test, ave_build_start(ctx, cmd, len), 0);
KUNIT_EXPECT_EQ_MSG(test, cmd[vui_off[i]], 1U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, cmd[vui_off[i] + 0x11], 1U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(cmd + vui_off[i] + 0x14),
5U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(cmd + vui_off[i] + 0x18),
1U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, cmd[vui_off[i] + 0x1c], 1U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(cmd + vui_off[i] + 0x20),
9U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(cmd + vui_off[i] + 0x24),
16U, "layout %u", i);
KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(cmd + vui_off[i] + 0x28),
9U, "layout %u", i);
}
}

static struct kunit_case ave_abi_cases[] = {
KUNIT_CASE(ave_t6041_text_boot_word),
KUNIT_CASE(ave_9003_byte_equality), KUNIT_CASE(ave_9003_hevc_main10),
KUNIT_CASE(ave_26a428_hevc_main10),
KUNIT_CASE(ave_26a428_hevc_main10), KUNIT_CASE(ave_6070_hevc_main10),
KUNIT_CASE(ave_hevc_vui_colorimetry),
KUNIT_CASE(ave_9003_speed), KUNIT_CASE(ave_cq_table),
KUNIT_CASE(ave_6070_images),
KUNIT_CASE(ave_6070_replies), KUNIT_CASE(ave_6070_frame_result),
Expand Down
3 changes: 3 additions & 0 deletions drivers/media/platform/apple/ave/ave-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const struct ave_fw_layout ave_layout_9003_78_0 = {
.hevc_dpb_minus1 = 0x5b00,
.hevc_reorder = 0x5b04,
.hevc_reorder_on = 0x95fc,
.hevc_vui = 0x74a0,
},
},
.process = {
Expand Down Expand Up @@ -486,6 +487,7 @@ const struct ave_fw_layout ave_layout_9003_78_0 = {
.hevc_cq_copy = 0xbefc, \
.hevc_cq_codec = 0x37c8, \
.hevc_cq_picture = 0x9e38, \
.hevc_vui = 0x80a4, \
}, \
}, \
.process = { \
Expand Down Expand Up @@ -837,6 +839,7 @@ const struct ave_fw_layout ave_layout_6070_11_1 = {
.hevc_sps_scaling_enabled = 0x24970,
.hevc_sps_sao = 0x2621d,
.hevc_sps_tmvp = 0x262b8,
.hevc_vui = 0x262bc,
.hevc_sps_fw_header = 0x26375,
.hevc_sps_header_len = 0x26378,
.hevc_pps_extra_slice_bits = 0x2848c,
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/apple/ave/ave-layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ struct ave_start_layout {
u32 hevc_sps_scaling_enabled;
u32 hevc_sps_sao;
u32 hevc_sps_tmvp;
u32 hevc_vui;
u32 hevc_sps_fw_header;
u32 hevc_sps_header_len;
u32 hevc_pps_extra_slice_bits;
Expand Down
108 changes: 98 additions & 10 deletions drivers/media/platform/apple/ave/ave-sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#define AVE_H264_HIGH 6
#define AVE_HEVC_MAIN 1
#define AVE_HEVC_MAIN_10 2
/* QpBdOffset: 10-bit HEVC lets the QP go 12 below the 8-bit range. */
#define AVE_QP_BD_OFFSET_10 12

#define AVE_META_PARAMS 0xb2a4
#define AVE_META_SCAN_FROM 0x200
Expand Down Expand Up @@ -124,6 +122,86 @@ u32 ave_cq_initial_qp(u32 quality)
return ave_cq_qp[min(quality, 100U)];
}

/* Map V4L2 colorimetry to ITU-T H.273 / H.265 Table E.3..E.5 VUI codes. */
static u8 ave_vui_primaries(enum v4l2_colorspace colorspace)
{
switch (colorspace) {
case V4L2_COLORSPACE_REC709:
case V4L2_COLORSPACE_SRGB:
case V4L2_COLORSPACE_JPEG:
return 1;
case V4L2_COLORSPACE_470_SYSTEM_M:
return 4;
case V4L2_COLORSPACE_470_SYSTEM_BG:
return 5;
case V4L2_COLORSPACE_SMPTE170M:
return 6;
case V4L2_COLORSPACE_SMPTE240M:
return 7;
case V4L2_COLORSPACE_BT2020:
return 9;
case V4L2_COLORSPACE_DCI_P3:
return 11;
default:
return 2;
}
}

static u8 ave_vui_transfer(enum v4l2_colorspace colorspace,
enum v4l2_xfer_func xfer_func, u32 bit_depth)
{
if (xfer_func == V4L2_XFER_FUNC_DEFAULT)
xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(colorspace);
switch (xfer_func) {
case V4L2_XFER_FUNC_709:
return colorspace == V4L2_COLORSPACE_BT2020 &&
bit_depth == 10 ? 14 : 1;
case V4L2_XFER_FUNC_SMPTE240M:
return 7;
case V4L2_XFER_FUNC_NONE:
return 8;
case V4L2_XFER_FUNC_SRGB:
return 13;
case V4L2_XFER_FUNC_SMPTE2084:
return 16;
default:
return 2;
}
}

static u8 ave_vui_matrix(enum v4l2_colorspace colorspace,
enum v4l2_ycbcr_encoding ycbcr_enc)
{
if (ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(colorspace);
switch (ycbcr_enc) {
case V4L2_YCBCR_ENC_709:
case V4L2_YCBCR_ENC_XV709:
return 1;
case V4L2_YCBCR_ENC_601:
case V4L2_YCBCR_ENC_XV601:
return colorspace == V4L2_COLORSPACE_470_SYSTEM_BG ? 5 : 6;
case V4L2_YCBCR_ENC_SMPTE240M:
return 7;
case V4L2_YCBCR_ENC_BT2020:
return 9;
case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
return 10;
default:
return 2;
}
}

static u8 ave_vui_full_range(enum v4l2_colorspace colorspace,
enum v4l2_ycbcr_encoding ycbcr_enc,
enum v4l2_quantization quantization)
{
if (quantization == V4L2_QUANTIZATION_DEFAULT)
quantization = V4L2_MAP_QUANTIZATION_DEFAULT(false, colorspace,
ycbcr_enc);
return quantization == V4L2_QUANTIZATION_FULL_RANGE ? 1 : 0;
}

static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p)
{
const struct ave_fw_layout *layout = ctx->ave->layout;
Expand Down Expand Up @@ -185,12 +263,10 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p)
p->sample_bytes == 2 ? "10-bit P010" : "8-bit NV12");
return -EINVAL;
}
if (ctx->ave->layout->kind == AVE_LAYOUT_6070 && p->sample_bytes != 1)
return -EOPNOTSUPP;
/*
* The 6070 path supports 8-bit H.264 and HEVC Main, including one B per
* P, with frame widths in whole macroblocks. Wider-than-coded widths are
* not yet supported.
* The 6070 path supports 8-bit H.264 and HEVC Main/Main 10, including
* one B per P, with frame widths in whole macroblocks. Wider-than-coded
* widths are not yet supported.
*/
if (ctx->ave->layout->kind == AVE_LAYOUT_6070 && p->width % 16)
return -EOPNOTSUPP;
Expand All @@ -200,6 +276,20 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p)
p->bit_depth = 10;
p->min_qp -= AVE_QP_BD_OFFSET_10;
}
if (p->codec == AVE_CODEC_HEVC &&
ctx->src_fmt.colorspace != V4L2_COLORSPACE_DEFAULT) {
p->vui_primaries = ave_vui_primaries(ctx->src_fmt.colorspace);
p->vui_transfer = ave_vui_transfer(ctx->src_fmt.colorspace,
ctx->src_fmt.xfer_func,
p->bit_depth);
p->vui_matrix = ave_vui_matrix(ctx->src_fmt.colorspace,
ctx->src_fmt.ycbcr_enc);
p->vui_full_range = ave_vui_full_range(ctx->src_fmt.colorspace,
ctx->src_fmt.ycbcr_enc,
ctx->src_fmt.quantization);
p->vui_color = p->vui_primaries != 2 || p->vui_transfer != 2 ||
p->vui_matrix != 2 || p->vui_full_range;
}

/*
* Reference structures as macOS sets them up: a B-frame pyramid,
Expand Down Expand Up @@ -431,9 +521,7 @@ static int ave_sess_alloc(struct ave_dev *ave, struct ave_session *sess)
for (unsigned int i = 0; i < entropy_tiles; i++) {
ave_req(r, &n, &sess->tile[set][i], tile, 0, nomap);
ave_req(r, &n, &sess->tile_aux[set][i],
fw6070 ? ave_6070_entropy_aux_size(w, h, hevc) :
ALIGN(h, 128), 0,
nomap);
fw6070 ? tile : ALIGN(h, 128), 0, nomap);
}
if (hevc)
for (unsigned int i = 0; i < 2; i++)
Expand Down
8 changes: 4 additions & 4 deletions drivers/media/platform/apple/ave/ave-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ static bool ave_fmt_listed(const u32 *list, unsigned int n, u32 fourcc)
}

/*
* HEVC Main 10 (P010 input): the 9003 and the counted (26A428) layouts,
* whose Starts map every field that changes with bit depth. The 6070
* layout has none.
* HEVC Main 10 (P010 input): supported on 9003, counted (26A428/26B123),
* and 6070 layouts, whose Starts map every field that changes with bit depth.
*/
static bool ave_main10_supported(const struct ave_dev *ave)
{
return ave->layout && (ave->layout->counted ||
ave->layout->kind == AVE_LAYOUT_9003);
ave->layout->kind == AVE_LAYOUT_9003 ||
ave->layout->kind == AVE_LAYOUT_6070);
}

/*
Expand Down
36 changes: 31 additions & 5 deletions drivers/media/platform/apple/ave/ave-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,17 @@ static void ave_start_put8(u8 *cmd, u32 off, u8 val)
/* IPPP selects 0..3; IbP selects 0..6 and has a possible index-7 arm. */
#define AVE_6070_HEVC_RPS_SETS_LOW_DELAY 4
#define AVE_6070_HEVC_RPS_SETS_REORDER 8
/* HEVC SPS VUI fields relative to l->hevc_vui (ITU-T H.265 Annex E). */
#define AVE_HEVC_VUI_PRESENT 0x00 /* u8 */
#define AVE_HEVC_VUI_VIDEO_SIGNAL_PRESENT 0x11 /* u8 */
#define AVE_HEVC_VUI_VIDEO_FORMAT 0x14 /* u32 */
#define AVE_HEVC_VUI_FULL_RANGE 0x18 /* u32 */
#define AVE_HEVC_VUI_COLOUR_DESC_PRESENT 0x1c /* u8 */
#define AVE_HEVC_VUI_COLOUR_PRIMARIES 0x20 /* u32 */
#define AVE_HEVC_VUI_TRANSFER_CHAR 0x24 /* u32 */
#define AVE_HEVC_VUI_MATRIX_COEFFS 0x28 /* u32 */
#define AVE_HEVC_VUI_VIDEO_FORMAT_UNSPECIFIED 5

/* HEVC Start constants (H.265 A.3 and 7.4.3.2). */
#define AVE_6070_HEVC_INPUT_CHROMA_FROM_SPS 16 /* bits [4:2] = 4: use SPS format */
#define AVE_6070_HEVC_CHROMA_420 1 /* H.265 chroma_format_idc */
Expand Down Expand Up @@ -811,7 +822,7 @@ static void ave_start_config(const struct ave_params *p, u8 *cmd,
ave_start_put64(cmd, l->f64_2c0, AVE_F64_NEG | ave_f64(1, 1));
ave_start_put64(cmd, l->f64_2c8, AVE_F64_NEG | ave_f64(1, 1));
if (cq && fw->kind == AVE_LAYOUT_6070) {
min_qp = 0;
min_qp = depth == 10 ? -AVE_QP_BD_OFFSET_10 : 0;
max_qp = 51;
}
ave_start_put32(cmd, l->min_qp, min_qp);
Expand Down Expand Up @@ -983,9 +994,9 @@ static void ave_start_config(const struct ave_params *p, u8 *cmd,
ave_start_put32(cmd, l->hevc_profile_a, p->profile);
ave_start_put32(cmd, l->hevc_profile_b, p->profile);
if (fw->kind == AVE_LAYOUT_6070) {
cmd[l->hevc_compat_a + 1] = 1;
cmd[l->hevc_compat_a + 1] = depth == 8;
cmd[l->hevc_compat_a + 2] = 1;
cmd[l->hevc_compat_b + 1] = 1;
cmd[l->hevc_compat_b + 1] = depth == 8;
cmd[l->hevc_compat_b + 2] = 1;
cmd[l->hevc_8bit_a] = 1;
cmd[l->hevc_8bit_a + 2] = 1;
Expand Down Expand Up @@ -1071,6 +1082,21 @@ static void ave_start_config(const struct ave_params *p, u8 *cmd,
ave_start_put8(cmd, l->hevc_sps_scaling_enabled, 0);
ave_start_put8(cmd, l->hevc_sps_sao, 1);
ave_start_put8(cmd, l->hevc_sps_tmvp, 0);
if (l->hevc_vui && p->vui_color) {
cmd[l->hevc_vui + AVE_HEVC_VUI_PRESENT] = 1;
cmd[l->hevc_vui + AVE_HEVC_VUI_VIDEO_SIGNAL_PRESENT] = 1;
ave_put32(cmd, l->hevc_vui + AVE_HEVC_VUI_VIDEO_FORMAT,
AVE_HEVC_VUI_VIDEO_FORMAT_UNSPECIFIED);
ave_put32(cmd, l->hevc_vui + AVE_HEVC_VUI_FULL_RANGE,
p->vui_full_range);
cmd[l->hevc_vui + AVE_HEVC_VUI_COLOUR_DESC_PRESENT] = 1;
ave_put32(cmd, l->hevc_vui + AVE_HEVC_VUI_COLOUR_PRIMARIES,
p->vui_primaries);
ave_put32(cmd, l->hevc_vui + AVE_HEVC_VUI_TRANSFER_CHAR,
p->vui_transfer);
ave_put32(cmd, l->hevc_vui + AVE_HEVC_VUI_MATRIX_COEFFS,
p->vui_matrix);
}
ave_start_put8(cmd, l->hevc_sps_fw_header, 1);
ave_start_put32(cmd, l->hevc_sps_header_len, 0);
ave_start_put32(cmd, l->hevc_pps_extra_slice_bits, 0);
Expand Down Expand Up @@ -1190,9 +1216,9 @@ int ave_build_process(struct ave_ctx *ctx, u8 *cmd, size_t len,
}
}
ave_put32(cmd, l->pic_size, 0xf68);
if (p->bit_depth == 8) {
if (!p->bit_depth || p->bit_depth == 8 || p->bit_depth == 10) {
recon = ave_6070_recon_layout(p->width, p->height,
p->bit_depth);
p->bit_depth ?: 8);
ave_write_recon_selection(cmd, &l->current_recon,
&sess->ref_a[pic.current_ref], &recon);
ave_put64(cmd, l->current_colocated,
Expand Down
Loading
Loading