Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4a2b36b authored by Jeff Hugo's avatar Jeff Hugo
Browse files

msm: smem: add smem_get_free_space()



The smem_get_free_space() API is a private helper function to optimize the
SMD client's table scanning usecase.

Change-Id: I00b12bf3b667001f973fd5126278536b47e052f4
Signed-off-by: default avatarJeffrey Hugo <jhugo@codeaurora.org>
parent e76e482e
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -856,6 +856,47 @@ remote_spinlock_t *smem_get_remote_spinlock(void)
}
EXPORT_SYMBOL(smem_get_remote_spinlock);

/**
 * smem_get_free_space() - Get the available allocation free space for a
 *				partition
 *
 * @to_proc: remote SMEM host.  Determines the applicable partition
 * @returns: size in bytes available to allocate
 *
 * Helper function for SMD so that SMD only scans the channel allocation
 * table for a partition when it is reasonably certain that a channel has
 * actually been created, because scanning can be expensive.  Creating a channel
 * will consume some of the free space in a partition, so SMD can compare the
 * last free space size against the current free space size to determine if
 * a channel may have been created.  SMD can't do this directly, because the
 * necessary partition internals are restricted to just SMEM.
 */
unsigned smem_get_free_space(unsigned to_proc)
{
	struct smem_partition_header *hdr;
	struct smem_shared *shared;

	if (to_proc >= NUM_SMEM_SUBSYSTEMS) {
		pr_err("%s: invalid to_proc:%d\n", __func__, to_proc);
		return UINT_MAX;
	}

	if (partitions[to_proc].offset) {
		if (unlikely(OVERFLOW_ADD_UNSIGNED(uintptr_t,
					(uintptr_t)smem_areas[0].virt_addr,
					partitions[to_proc].offset))) {
			pr_err("%s: unexpected overflow detected\n", __func__);
			return UINT_MAX;
		}
		hdr = smem_areas[0].virt_addr + partitions[to_proc].offset;
		return hdr->offset_free_cached - hdr->offset_free_uncached;
	} else {
		shared = (void *)MSM_SHARED_RAM_BASE;
		return shared->heap_info.heap_remaining;
	}
}
EXPORT_SYMBOL(smem_get_free_space);

/**
 * init_smem_remote_spinlock - Reentrant remote spinlock initialization
 *
+17 −0
Original line number Diff line number Diff line
@@ -76,4 +76,21 @@ int smem_module_init_notifier_register(struct notifier_block *nb);
 * @nb: Notifier block to be unregistered
 */
int smem_module_init_notifier_unregister(struct notifier_block *nb);

/**
 * smem_get_free_space() - Get the available allocation free space for a
 *				partition
 *
 * @to_proc: remote SMEM host.  Determines the applicable partition
 * @returns: size in bytes available to allocate
 *
 * Helper function for SMD so that SMD only scans the channel allocation
 * table for a partition when it is reasonably certain that a channel has
 * actually been created, because scanning can be expensive.  Creating a channel
 * will consume some of the free space in a partition, so SMD can compare the
 * last free space size against the current free space size to determine if
 * a channel may have been created.  SMD can't do this directly, because the
 * necessary partition internals are restricted to just SMEM.
 */
unsigned smem_get_free_space(unsigned to_proc);
#endif /* _ARCH_ARM_MACH_MSM_SMEM_PRIVATE_H_ */