1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __ASM_GENERIC_DEVICE_H__
3 #define __ASM_GENERIC_DEVICE_H__
4 
5 #include <xen/stdbool.h>
6 
7 enum device_type
8 {
9 #ifdef CONFIG_HAS_DEVICE_TREE
10     DEV_DT,
11 #endif
12     DEV_PCI
13 };
14 
15 enum device_class
16 {
17     DEVICE_SERIAL,
18     DEVICE_IOMMU,
19     DEVICE_INTERRUPT_CONTROLLER,
20     DEVICE_PCI_HOSTBRIDGE,
21     /* Use for error */
22     DEVICE_UNKNOWN,
23 };
24 
25 /* struct device - The basic device structure */
26 struct device
27 {
28     enum device_type type;
29 #ifdef CONFIG_HAS_DEVICE_TREE
30     struct dt_device_node *of_node; /* Used by drivers imported from Linux */
31 #endif
32 #ifdef CONFIG_HAS_PASSTHROUGH
33     void *iommu; /* IOMMU private data */;
34     struct iommu_fwspec *iommu_fwspec; /* per-device IOMMU instance data */
35 #endif
36 };
37 
38 typedef struct device device_t;
39 
40 #ifdef CONFIG_HAS_DEVICE_TREE
41 
42 #include <xen/device_tree.h>
43 
44 #define dev_is_dt(dev)  ((dev)->type == DEV_DT)
45 
46 /**
47  *  device_init - Initialize a device
48  *  @dev: device to initialize
49  *  @class: class of the device (serial, network...)
50  *  @data: specific data for initializing the device
51  *
52  *  Return 0 on success.
53  */
54 int device_init(struct dt_device_node *dev, enum device_class class,
55                 const void *data);
56 
57 /**
58  * device_get_type - Get the type of the device
59  * @dev: device to match
60  *
61  * Return the device type on success or DEVICE_ANY on failure
62  */
63 enum device_class device_get_class(const struct dt_device_node *dev);
64 
65 #define DT_DEVICE_START(dev_name, ident, cls)                   \
66 static const struct device_desc __dev_desc_##dev_name __used    \
67 __section(".dev.info") = {                                      \
68     .name = ident,                                              \
69     .class = cls,
70 
71 #define DT_DEVICE_END                                           \
72 };
73 
74 struct device_desc {
75     /* Device name */
76     const char *name;
77     /* Device class */
78     enum device_class class;
79 
80     /* List of devices supported by this driver */
81     const struct dt_device_match *dt_match;
82     /*
83      * Device initialization.
84      *
85      * -EAGAIN is used to indicate that device probing is deferred.
86      */
87     int (*init)(struct dt_device_node *dev, const void *data);
88 };
89 
90 #else /* !CONFIG_HAS_DEVICE_TREE */
91 #define dev_is_dt(dev) ((void)(dev), false)
92 #endif /* CONFIG_HAS_DEVICE_TREE */
93 
94 #define dev_is_pci(dev) ((dev)->type == DEV_PCI)
95 
96 #ifdef CONFIG_ACPI
97 
98 struct acpi_device_desc {
99     /* Device name */
100     const char *name;
101     /* Device class */
102     enum device_class class;
103     /* type of device supported by the driver */
104     const int class_type;
105     /* Device initialization */
106     int (*init)(const void *data);
107 };
108 
109 /**
110  *  acpi_device_init - Initialize a device
111  *  @class: class of the device (serial, network...)
112  *  @data: specific data for initializing the device
113  *
114  *  Return 0 on success.
115  */
116 int acpi_device_init(enum device_class class,
117                      const void *data, int class_type);
118 
119 #define ACPI_DEVICE_START(dev_name, ident, cls)                     \
120 static const struct acpi_device_desc __dev_desc_##dev_name __used   \
121 __section(".adev.info") = {                                         \
122     .name = ident,                                                  \
123     .class = cls,
124 
125 #define ACPI_DEVICE_END                                             \
126 };
127 
128 #endif /* CONFIG_ACPI */
129 
130 #endif /* __ASM_GENERIC_DEVICE_H__ */
131 
132 /*
133  * Local variables:
134  * mode: C
135  * c-file-style: "BSD"
136  * c-basic-offset: 4
137  * indent-tabs-mode: nil
138  * End:
139  */
140