blob: b19c534ebc43c81980f68b7170955ef8343b376a [file] [log] [blame]
Ramon Friedcf1e49f2018-07-02 02:57:55 +03001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
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
5 * in the SoC.
6 *
7 * Allocation can be done globally for all processors or to an individual processor.
8 * This is controlled by the @host parameter.
9 *
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.
12 *
13 * Copyright (c) 2018 Ramon Fried <ramon.fried@gmail.com>
14 */
15
16#ifndef _smemh_
17#define _smemh_
18
19/* struct smem_ops: Operations for the SMEM uclass */
20struct smem_ops {
21 /**
22 * alloc() - allocate space for a smem item
23 *
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
28 */
29 int (*alloc)(unsigned int host,
30 unsigned int item, size_t size);
31
32 /**
33 * get() - Resolve ptr of size of a smem item
34 *
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
39 */
40 void *(*get)(unsigned int host,
41 unsigned int item, size_t *size);
42
43 /**
44 * get_free_space() - Get free space in smem in bytes
45 *
46 * @host: the remote processor identifying a partition, or -1
47 * for all processors.
48 * @return free space, -ve on error
49 */
50 int (*get_free_space)(unsigned int host);
51};
52
53#define smem_get_ops(dev) ((struct smem_ops *)(dev)->driver->ops)
54
55/**
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
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010060 * Return: 0 if OK, -ve on error
Ramon Friedcf1e49f2018-07-02 02:57:55 +030061 *
62 * Allocate space for a given smem item of size @size, given that the item is
63 * not yet allocated.
64 */
65int smem_alloc(struct udevice *dev, unsigned int host, unsigned int item, size_t size);
66
67/**
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
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010072 * Return: pointer on success, NULL on error
Ramon Friedcf1e49f2018-07-02 02:57:55 +030073 *
74 * Looks up smem item and returns pointer to it. Size of smem
75 * item is returned in @size.
76 */
77void *smem_get(struct udevice *dev, unsigned int host, unsigned int item, size_t *size);
78
79/**
80 * smem_get_free_space() - retrieve amount of free space in a partition
81 * @host: the remote processor identifying a partition, or -1
82 * for all processors.
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010083 * Return: size in bytes, -ve on error
Ramon Friedcf1e49f2018-07-02 02:57:55 +030084 *
85 * To be used by smem clients as a quick way to determine if any new
86 * allocations has been made.
87 */
88int smem_get_free_space(struct udevice *dev, unsigned int host);
89
90#endif /* _smem_h_ */