Skip to content

Commit bb1be74

Browse files
committed
firmware: arm_ffa: Add v1.1 get_partition_info support
FF-A v1.1 adds support to discovery the UUIDs of the partitions that was missing in v1.0 and which the driver workarounds by using UUIDs supplied by the ffa_drivers. Add the v1.1 get_partition_info support and disable the workaround if the detected FF-A version is greater than v1.0. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jens Wiklander <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent 7aa7a97 commit bb1be74

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

drivers/firmware/arm_ffa/driver.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,24 @@ static int ffa_rxtx_unmap(u16 vm_id)
264264
return 0;
265265
}
266266

267+
#define PARTITION_INFO_GET_RETURN_COUNT_ONLY BIT(0)
268+
267269
/* buffer must be sizeof(struct ffa_partition_info) * num_partitions */
268270
static int
269271
__ffa_partition_info_get(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3,
270272
struct ffa_partition_info *buffer, int num_partitions)
271273
{
272-
int count;
274+
int idx, count, flags = 0, sz, buf_sz;
273275
ffa_value_t partition_info;
274276

277+
if (!buffer || !num_partitions) /* Just get the count for now */
278+
flags = PARTITION_INFO_GET_RETURN_COUNT_ONLY;
279+
275280
mutex_lock(&drv_info->rx_lock);
276281
invoke_ffa_fn((ffa_value_t){
277282
.a0 = FFA_PARTITION_INFO_GET,
278283
.a1 = uuid0, .a2 = uuid1, .a3 = uuid2, .a4 = uuid3,
284+
.a5 = flags,
279285
}, &partition_info);
280286

281287
if (partition_info.a0 == FFA_ERROR) {
@@ -285,8 +291,19 @@ __ffa_partition_info_get(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3,
285291

286292
count = partition_info.a2;
287293

294+
if (drv_info->version > FFA_VERSION_1_0) {
295+
buf_sz = sz = partition_info.a3;
296+
if (sz > sizeof(*buffer))
297+
buf_sz = sizeof(*buffer);
298+
} else {
299+
/* FFA_VERSION_1_0 lacks size in the response */
300+
buf_sz = sz = 8;
301+
}
302+
288303
if (buffer && count <= num_partitions)
289-
memcpy(buffer, drv_info->rx_buffer, sizeof(*buffer) * count);
304+
for (idx = 0; idx < count; idx++)
305+
memcpy(buffer + idx, drv_info->rx_buffer + idx * sz,
306+
buf_sz);
290307

291308
ffa_rx_release();
292309

@@ -681,6 +698,14 @@ void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
681698
int count, idx;
682699
struct ffa_partition_info *pbuf, *tpbuf;
683700

701+
/*
702+
* FF-A v1.1 provides UUID for each partition as part of the discovery
703+
* API, the discovered UUID must be populated in the device's UUID and
704+
* there is no need to copy the same from the driver table.
705+
*/
706+
if (drv_info->version > FFA_VERSION_1_0)
707+
return;
708+
684709
count = ffa_partition_probe(uuid, &pbuf);
685710
if (count <= 0)
686711
return;
@@ -694,6 +719,7 @@ void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
694719
static void ffa_setup_partitions(void)
695720
{
696721
int count, idx;
722+
uuid_t uuid;
697723
struct ffa_device *ffa_dev;
698724
struct ffa_partition_info *pbuf, *tpbuf;
699725

@@ -704,14 +730,15 @@ static void ffa_setup_partitions(void)
704730
}
705731

706732
for (idx = 0, tpbuf = pbuf; idx < count; idx++, tpbuf++) {
707-
/* Note that the &uuid_null parameter will require
733+
import_uuid(&uuid, (u8 *)tpbuf->uuid);
734+
735+
/* Note that if the UUID will be uuid_null, that will require
708736
* ffa_device_match() to find the UUID of this partition id
709-
* with help of ffa_device_match_uuid(). Once the FF-A spec
710-
* is updated to provide correct UUID here for each partition
711-
* as part of the discovery API, we need to pass the
712-
* discovered UUID here instead.
737+
* with help of ffa_device_match_uuid(). FF-A v1.1 and above
738+
* provides UUID here for each partition as part of the
739+
* discovery API and the same is passed.
713740
*/
714-
ffa_dev = ffa_device_register(&uuid_null, tpbuf->id, &ffa_ops);
741+
ffa_dev = ffa_device_register(&uuid, tpbuf->id, &ffa_ops);
715742
if (!ffa_dev) {
716743
pr_err("%s: failed to register partition ID 0x%x\n",
717744
__func__, tpbuf->id);

include/linux/arm_ffa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct ffa_partition_info {
107107
/* partition can send and receive indirect messages. */
108108
#define FFA_PARTITION_INDIRECT_MSG BIT(2)
109109
u32 properties;
110+
u32 uuid[4];
110111
};
111112

112113
/* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registers */

0 commit comments

Comments
 (0)