1 /*
2 * xen/arch/arm/device.c
3 *
4 * Helpers to use a device retrieved via the device tree.
5 *
6 * Julien Grall <julien.grall@linaro.org>
7 * Copyright (C) 2013 Linaro Limited.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20 #include <asm/device.h>
21 #include <xen/errno.h>
22 #include <xen/lib.h>
23
24 extern const struct device_desc _sdevice[], _edevice[];
25 extern const struct acpi_device_desc _asdevice[], _aedevice[];
26
device_init(struct dt_device_node * dev,enum device_class class,const void * data)27 int __init device_init(struct dt_device_node *dev, enum device_class class,
28 const void *data)
29 {
30 const struct device_desc *desc;
31
32 ASSERT(dev != NULL);
33
34 if ( !dt_device_is_available(dev) || dt_device_for_passthrough(dev) )
35 return -ENODEV;
36
37 for ( desc = _sdevice; desc != _edevice; desc++ )
38 {
39 if ( desc->class != class )
40 continue;
41
42 if ( dt_match_node(desc->dt_match, dev) )
43 {
44 ASSERT(desc->init != NULL);
45
46 return desc->init(dev, data);
47 }
48
49 }
50
51 return -EBADF;
52 }
53
acpi_device_init(enum device_class class,const void * data,int class_type)54 int __init acpi_device_init(enum device_class class, const void *data, int class_type)
55 {
56 const struct acpi_device_desc *desc;
57
58 for ( desc = _asdevice; desc != _aedevice; desc++ )
59 {
60 if ( ( desc->class != class ) || ( desc->class_type != class_type ) )
61 continue;
62
63 ASSERT(desc->init != NULL);
64
65 return desc->init(data);
66 }
67
68 return -EBADF;
69 }
70
device_get_class(const struct dt_device_node * dev)71 enum device_class device_get_class(const struct dt_device_node *dev)
72 {
73 const struct device_desc *desc;
74
75 ASSERT(dev != NULL);
76
77 for ( desc = _sdevice; desc != _edevice; desc++ )
78 {
79 if ( dt_match_node(desc->dt_match, dev) )
80 return desc->class;
81 }
82
83 return DEVICE_UNKNOWN;
84 }
85
86 /*
87 * Local variables:
88 * mode: C
89 * c-file-style: "BSD"
90 * c-basic-offset: 4
91 * indent-tabs-mode: nil
92 * End:
93 */
94