1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * The shared memory system is an allocate-only heap structure that
4 * consists of one of more memory areas that can be accessed by the processors
7 * Allocation can be done globally for all processors or to an individual processor.
8 * This is controlled by the @host parameter.
10 * Allocation and management of heap can be implemented in various ways,
11 * The @item parameter should be used as an index/hash to the memory region.
13 * Copyright (c) 2018 Ramon Fried <ramon.fried@gmail.com>
19 /* struct smem_ops: Operations for the SMEM uclass */
22 * alloc() - allocate space for a smem item
24 * @host: remote processor id, or -1 for all processors.
25 * @item: smem item handle
26 * @size: number of bytes to be allocated
27 * @return 0 if OK, -ve on error
29 int (*alloc)(unsigned int host,
30 unsigned int item, size_t size);
33 * get() - Resolve ptr of size of a smem item
35 * @host: the remote processor, of -1 for all processors.
36 * @item: smem item handle
37 * @size: pointer to be filled out with the size of the item
38 * @return pointer on success, NULL on error
40 void *(*get)(unsigned int host,
41 unsigned int item, size_t *size);
44 * get_free_space() - Get free space in smem in bytes
46 * @host: the remote processor identifying a partition, or -1
48 * @return free space, -ve on error
50 int (*get_free_space)(unsigned int host);
53 #define smem_get_ops(dev) ((struct smem_ops *)(dev)->driver->ops)
56 * smem_alloc() - allocate space for a smem item
57 * @host: remote processor id, or -1
58 * @item: smem item handle
59 * @size: number of bytes to be allocated
60 * Return: 0 if OK, -ve on error
62 * Allocate space for a given smem item of size @size, given that the item is
65 int smem_alloc(struct udevice *dev, unsigned int host, unsigned int item, size_t size);
68 * smem_get() - resolve ptr of size of a smem item
69 * @host: the remote processor, or -1 for all processors.
70 * @item: smem item handle
71 * @size: pointer to be filled out with size of the item
72 * Return: pointer on success, NULL on error
74 * Looks up smem item and returns pointer to it. Size of smem
75 * item is returned in @size.
77 void *smem_get(struct udevice *dev, unsigned int host, unsigned int item, size_t *size);
80 * smem_get_free_space() - retrieve amount of free space in a partition
81 * @host: the remote processor identifying a partition, or -1
83 * Return: size in bytes, -ve on error
85 * To be used by smem clients as a quick way to determine if any new
86 * allocations has been made.
88 int smem_get_free_space(struct udevice *dev, unsigned int host);