1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2021 Mark Kettenis <kettenis@openbsd.org>
4  */
5 
6 #define LOG_CATEGORY UCLASS_IOMMU
7 
8 #include <common.h>
9 #include <dm.h>
10 
11 #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
dev_iommu_enable(struct udevice * dev)12 int dev_iommu_enable(struct udevice *dev)
13 {
14 	struct ofnode_phandle_args args;
15 	struct udevice *dev_iommu;
16 	int i, count, ret = 0;
17 
18 	count = dev_count_phandle_with_args(dev, "iommus",
19 					    "#iommu-cells", 0);
20 	for (i = 0; i < count; i++) {
21 		ret = dev_read_phandle_with_args(dev, "iommus",
22 						 "#iommu-cells", 0, i, &args);
23 		if (ret) {
24 			debug("%s: dev_read_phandle_with_args failed: %d\n",
25 			      __func__, ret);
26 			return ret;
27 		}
28 
29 		ret = uclass_get_device_by_ofnode(UCLASS_IOMMU, args.node,
30 						  &dev_iommu);
31 		if (ret) {
32 			debug("%s: uclass_get_device_by_ofnode failed: %d\n",
33 			      __func__, ret);
34 			return ret;
35 		}
36 	}
37 
38 	return 0;
39 }
40 #endif
41 
42 UCLASS_DRIVER(iommu) = {
43 	.id		= UCLASS_IOMMU,
44 	.name		= "iommu",
45 };
46