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
7 changes: 7 additions & 0 deletions Documentation/devicetree/bindings/media/apple,isp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ properties:
description:
Firmware temporal-filter strength selected for the attached sensor.

apple,ane:
$ref: /schemas/types.yaml#/definitions/phandle
description:
The Neural Engine the ISP firmware runs its ML noise reduction (MLVNR)
on. The two coprocessors exchange messages on rings in shared memory
and ring each other's doorbells.

apple,camera-indicator:
$ref: /schemas/types.yaml#/definitions/phandle
description:
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/boot/dts/apple/t604x.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,8 @@
<&ps_isp_clr>, <&ps_ispsens0>;
/* the shared memory window above the firmware's 32 MiB */
apple,dart-vm-size = /bits/ 64 <0xde600000>;
/* ADT isp0 function-ane_ep_control/data_param_set/get */
apple,ane = <&ane>;
status = "disabled";
};

Expand Down
5 changes: 5 additions & 0 deletions drivers/accel/ane/ane_fw_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ const struct ane_fw_platform ane_h16_platform = {
.mailbox = 0x1608000,
.scratch = 0x1880020,
.doorbell = 0x1884000,
/* macOS gives the ISP 0x485660000 and 1 on the J616s. */
.peer_doorbell = 0x1660000,
.peer_doorbell_value = 0x1,
/* The DSID macOS grants the J616s camera's spill (0x300000 bytes). */
.peer_spill_dsid = 0xe,
.irq_status = 0x188c000,
.irq_ack = 0x1890000,
.power_words = ane_h16_power_words,
Expand Down
9 changes: 9 additions & 0 deletions drivers/accel/ane/ane_fw_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ struct ane_fw_platform {
u32 mailbox;
u32 scratch;
u32 doorbell;
/*
* The doorbell a peer coprocessor's firmware rings (the ISP, see
* <linux/soc/apple/ane.h>), in the engine window, and the value it
* writes there. Zero without a peer endpoint.
*/
u32 peer_doorbell;
u32 peer_doorbell_value;
/* The mcache DSID for the peer networks' intermediate spill; 0 for none. */
u32 peer_spill_dsid;
u32 irq_status;
u32 irq_ack;
const u32 *power_words;
Expand Down
6 changes: 6 additions & 0 deletions drivers/accel/ane/ane_fw_protocol_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ static void ane_h16_id_table_test(struct kunit *test)
{ 0x20c, 0xca8, 0xcd8, 0x18, 7, false },
{ 0x2d, 0xc, 0xc, 1, 7, false },
{ 0x300, 0x60, 0x60, 1, 6, true },
{ 0x26, 0xc, 0xc, 1, 1, false },
{ 0x2a, 0x30, 0x30, 1, 1, false },
{ 0x2b, 0x30, 0x30, 1, 1, false },
{ 0x2e, 0x20, 0x20, 1, 1, false },
{ 0x205, 0x38, 0x38, 1, 1, false },
{ 0x206, 0x38, 0x38, 1, 1, false },
};
u8 *command = kunit_kzalloc(test, 0xcd8, GFP_KERNEL);
unsigned int i;
Expand Down
40 changes: 40 additions & 0 deletions drivers/accel/ane/ane_fw_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ struct ane_fw_transport_ops {
void (*refused)(void *ctx, u64 word0, u64 word1, u64 word2, int error);
/* Optional: a shared allocation was freed ("FREE") or served again ("reuse"). */
void (*shared_note)(void *ctx, const char *event, u64 dva, u64 size, u32 tag);
/*
* Optional: a peer coprocessor's surface, which the firmware names by
* the ID the peer's firmware got for it (SHAREDMALLOC with zero DVA
* and size). peer_map maps it and returns its DVA and size;
* peer_unmap gives back a DVA peer_map returned, and -ENOENT means it
* is not a peer surface (an ordinary FREE then).
*/
int (*peer_map)(void *ctx, u32 id, u64 *dva, u64 *size);
int (*peer_unmap)(void *ctx, u64 dva);
/*
* Optional: true once the firmware's CPU no longer runs, so no reply can
* come. A wait then ends at once with -ESHUTDOWN instead of at its
Expand Down Expand Up @@ -832,6 +841,20 @@ static inline int ane_fw_transport_shared_reserve(struct ane_fw_transport *t, si

static inline int ane_fw_transport_irq(struct ane_fw_transport *t, u32 *pending);

/* Answer a peer surface map (DVA|1, size, ID) or unmap (1, 0, 0) in place. */
static inline int ane_fw_transport_peer_reply(struct ane_fw_transport *t, void *slot,
u64 word0, u64 word1, u64 word2)
{
t->ops->store64(t->ctx, (u8 *)slot + 8, word1);
t->ops->store64(t->ctx, (u8 *)slot + 16, word2);
t->ops->write_barrier(t->ctx);
t->ops->store64(t->ctx, slot, word0);
t->ops->write_barrier(t->ctx);
ane_fw_transport_doorbell(t, ANE_FW_SHAREDMALLOC);
ane_fw_transport_advance(t, ANE_FW_SHAREDMALLOC);
return 0;
}

static inline int ane_fw_transport_shared(struct ane_fw_transport *t)
{
u64 word0, word1, word2;
Expand Down Expand Up @@ -870,11 +893,28 @@ static inline int ane_fw_transport_shared(struct ane_fw_transport *t)
if (!word0 && !word1 && !word2)
return -EAGAIN;
if (word0) {
if (t->ops->peer_unmap && !word1 && !word2) {
ret = t->ops->peer_unmap(t->ctx, word0);
if (!ret)
return ane_fw_transport_peer_reply(t, p, 1, 0, 0);
if (ret != -ENOENT)
goto refused;
}
ret = ane_fw_transport_free(t, p, word0, word1, word2);
if (ret)
goto refused;
return 0;
}
if (!word1 && t->ops->peer_map) {
u64 dva, bytes;

ret = word2 > U32_MAX ? -E2BIG : t->ops->peer_map(t->ctx, word2, &dva, &bytes);
if (!ret && (!dva || (dva & 1) || !bytes))
ret = -EPROTO;
if (ret)
goto refused;
return ane_fw_transport_peer_reply(t, p, dva | 1, bytes, word2);
}
ret = ane_fw_shared_size(word0, word1, word2, &size);
if (ret)
goto refused;
Expand Down
98 changes: 98 additions & 0 deletions drivers/accel/ane/ane_fw_transport_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,44 @@ static const struct ane_fw_transport_ops ane_test_ops = {
.refused = ane_test_refused,
};

/* The ISP peer: surface id 0x3c maps at TEST_PEER_DVA; one unmap is known. */
#define TEST_PEER_DVA 0x7000000000ULL

static int ane_test_peer_map(void *ctx, u32 id, u64 *dva, u64 *size)
{
struct ane_transport_test *f = ctx;

f->allocs++;
if (id != 0x3c)
return -ENOENT;
*dva = TEST_PEER_DVA;
*size = SZ_64K;
return 0;
}

static int ane_test_peer_unmap(void *ctx, u64 dva)
{
struct ane_transport_test *f = ctx;

f->refused[2] = dva;
return dva == TEST_PEER_DVA ? 0 : -ENOENT;
}

static const struct ane_fw_transport_ops ane_test_peer_ops = {
.load64 = ane_test_load,
.store64 = ane_test_store,
.read_barrier = ane_test_rmb,
.write_barrier = ane_test_wmb,
.read32 = ane_test_read32,
.write32 = ane_test_write32,
.now_ns = ane_test_now,
.relax = ane_test_relax,
.alloc = ane_test_alloc,
.refused = ane_test_refused,
.peer_map = ane_test_peer_map,
.peer_unmap = ane_test_peer_unmap,
};

static void ane_test_table(struct ane_transport_test *f)
{
static const char * const names[] = {
Expand Down Expand Up @@ -755,6 +793,64 @@ static void ane_transport_shared_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, f->t.shared_count, 2U);
}

/*
* The ISP peer's surfaces: a map request (zero DVA and size, the surface ID
* in word 2) is answered DVA|1, size, ID; an unmap of that DVA with 1, 0, 0;
* an unmap of another DVA is an ordinary FREE.
*/
static void ane_transport_peer_test(struct kunit *test)
{
struct ane_transport_test *f = test->priv;
u8 *slot;

f->t.ops = &ane_test_peer_ops;
KUNIT_ASSERT_EQ(test, ane_fw_transport_arm(&f->t), 0);
ane_test_shared_request(f, 0, 0, 0x3c);
slot = ane_test_slot(f, ANE_FW_SHAREDMALLOC);
KUNIT_ASSERT_EQ(test, ane_fw_transport_shared(&f->t), 0);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot), TEST_PEER_DVA | 1);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot + 8), (u64)SZ_64K);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot + 16), 0x3cULL);
KUNIT_EXPECT_EQ(test, f->last_value, (u32)BIT(5));
/* A peer surface is not shared memory: nothing counted against the quota. */
KUNIT_EXPECT_EQ(test, f->t.shared_count, 0U);

ane_test_shared_request(f, TEST_PEER_DVA, 0, 0);
slot = ane_test_slot(f, ANE_FW_SHAREDMALLOC);
KUNIT_ASSERT_EQ(test, ane_fw_transport_shared(&f->t), 0);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot), 1ULL);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot + 8), 0ULL);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot + 16), 0ULL);
KUNIT_EXPECT_EQ(test, f->refusals, 0U);

/* An unknown surface ID cannot be answered: the transport fails. */
ane_test_shared_request(f, 0, 0, 0x3d);
KUNIT_EXPECT_EQ(test, ane_fw_transport_shared(&f->t), -ENOENT);
KUNIT_EXPECT_EQ(test, f->refusals, 1U);
KUNIT_EXPECT_EQ(test, f->refused[2], 0x3dULL);
}

/* An unmap the peer does not know is an ordinary FREE. */
static void ane_transport_peer_free_test(struct kunit *test)
{
struct ane_transport_test *f = test->priv;
u8 *slot;
u64 dva;

f->t.ops = &ane_test_peer_ops;
KUNIT_ASSERT_EQ(test, ane_fw_transport_arm(&f->t), 0);
ane_test_shared_request(f, 0, SZ_2M, ANE_FW_SHARED_EXPP);
KUNIT_ASSERT_EQ(test, ane_fw_transport_shared(&f->t), 0);
dva = f->t.shared[0].dva;
f->t.allow_free = true;
ane_test_shared_request(f, dva, 0, 0);
slot = ane_test_slot(f, ANE_FW_SHAREDMALLOC);
KUNIT_ASSERT_EQ(test, ane_fw_transport_shared(&f->t), 0);
KUNIT_EXPECT_EQ(test, f->refused[2], dva);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(slot), dva | 1);
KUNIT_EXPECT_TRUE(test, f->t.shared_retired[0]);
}

/* The body of a fresh zero-header request is not its publication boundary. */
static void ane_transport_shared_notification_test(struct kunit *test)
{
Expand Down Expand Up @@ -1721,6 +1817,8 @@ static void ane_transport_terminal_wrap_test(struct kunit *test)
}

static struct kunit_case ane_transport_cases[] = {
KUNIT_CASE(ane_transport_peer_test),
KUNIT_CASE(ane_transport_peer_free_test),
KUNIT_CASE(ane_transport_terminal_ack_test),
KUNIT_CASE(ane_transport_terminal_bounds_test),
KUNIT_CASE(ane_transport_terminal_wrap_test),
Expand Down
Loading
Loading