xref: /openbmc/u-boot/drivers/smem/smem-uclass.c (revision e0ed8332)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2018 Ramon Fried <ramon.fried@gmail.com>
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <smem.h>
9 
smem_alloc(struct udevice * dev,unsigned int host,unsigned int item,size_t size)10 int smem_alloc(struct udevice *dev, unsigned int host,
11 		unsigned int item, size_t size)
12 {
13 	struct smem_ops *ops = smem_get_ops(dev);
14 
15 	if (!ops->alloc)
16 		return -ENOSYS;
17 
18 	return ops->alloc(host, item, size);
19 }
20 
smem_get(struct udevice * dev,unsigned int host,unsigned int item,size_t * size)21 void *smem_get(struct udevice *dev, unsigned int host,
22 		unsigned int item, size_t *size)
23 {
24 	struct smem_ops *ops = smem_get_ops(dev);
25 
26 	if (!ops->get)
27 		return NULL;
28 
29 	return ops->get(host, item, size);
30 }
31 
smem_get_free_space(struct udevice * dev,unsigned int host)32 int smem_get_free_space(struct udevice *dev, unsigned int host)
33 {
34 	struct smem_ops *ops = smem_get_ops(dev);
35 
36 	if (!ops->get_free_space)
37 		return -ENOSYS;
38 
39 	return ops->get_free_space(host);
40 }
41 
42 UCLASS_DRIVER(smem) = {
43 	.id     = UCLASS_SMEM,
44 	.name       = "smem",
45 };
46