1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2022, Linaro Limited
4 */
5
6 #define LOG_CATEGORY UCLASS_FWU_MDATA
7
8 #include <dm.h>
9 #include <efi_loader.h>
10 #include <fwu.h>
11 #include <fwu_mdata.h>
12 #include <log.h>
13
14 #include <linux/errno.h>
15 #include <linux/types.h>
16
17 /**
18 * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata()
19 *
20 * Return: 0 if OK, -ve on error
21 */
fwu_read_mdata(struct udevice * dev,struct fwu_mdata * mdata,bool primary,uint32_t size)22 int fwu_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary,
23 uint32_t size)
24 {
25 const struct fwu_mdata_ops *ops = device_get_ops(dev);
26
27 if (!ops->read_mdata) {
28 log_debug("read_mdata() method not defined\n");
29 return -ENOSYS;
30 }
31
32 return ops->read_mdata(dev, mdata, primary, size);
33 }
34
35 /**
36 * fwu_write_mdata() - Wrapper around fwu_mdata_ops.write_mdata()
37 *
38 * Return: 0 if OK, -ve on error
39 */
fwu_write_mdata(struct udevice * dev,struct fwu_mdata * mdata,bool primary,uint32_t size)40 int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary,
41 uint32_t size)
42 {
43 const struct fwu_mdata_ops *ops = device_get_ops(dev);
44
45 if (!ops->write_mdata) {
46 log_debug("write_mdata() method not defined\n");
47 return -ENOSYS;
48 }
49
50 return ops->write_mdata(dev, mdata, primary, size);
51 }
52
53 UCLASS_DRIVER(fwu_mdata) = {
54 .id = UCLASS_FWU_MDATA,
55 .name = "fwu-mdata",
56 };
57