1 /*
2 * Copyright 2022, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _FBSD_COMPAT_SYS_BUS_H_
6 #define _FBSD_COMPAT_SYS_BUS_H_
7
8
9 #include <sys/haiku-module.h>
10
11 #include <sys/_bus_dma.h>
12 #include <sys/_bus_macros.h>
13
14 #include <sys/queue.h>
15
16
17 #define FILTER_STRAY B_UNHANDLED_INTERRUPT
18 #define FILTER_HANDLED B_HANDLED_INTERRUPT
19 #define FILTER_SCHEDULE_THREAD B_INVOKE_SCHEDULER
20
21 /* Note that we reversed the original order, so whenever actual (negative)
22 numbers are used in a driver, we have to change it. */
23 #define BUS_PROBE_SPECIFIC 0
24 #define BUS_PROBE_LOW_PRIORITY 10
25 #define BUS_PROBE_DEFAULT 20
26 #define BUS_PROBE_GENERIC 100
27
28 #define __BUS_ACCESSOR(varp, var, ivarp, ivar, type) \
29 \
30 static __inline type varp ## _get_ ## var(device_t dev) \
31 { \
32 return 0; \
33 } \
34 \
35 static __inline void varp ## _set_ ## var(device_t dev, type t) \
36 { \
37 }
38
39
40 struct resource;
41
42 struct resource_spec {
43 int type;
44 int rid;
45 int flags;
46 };
47
48 enum intr_type {
49 INTR_TYPE_NET = 4,
50 INTR_MPSAFE = 512,
51 };
52
53
54 int bus_generic_detach(device_t dev);
55 int bus_generic_suspend(device_t dev);
56 int bus_generic_resume(device_t dev);
57 void bus_generic_shutdown(device_t dev);
58
59 typedef int (driver_filter_t)(void *arg);
60 typedef void driver_intr_t(void *);
61
62
63 int resource_int_value(const char *name, int unit, const char *resname,
64 int *result);
65 int resource_disabled(const char *name, int unit);
66
67 struct resource *bus_alloc_resource(device_t dev, int type, int *rid,
68 unsigned long start, unsigned long end, unsigned long count, uint32 flags);
69 int bus_release_resource(device_t dev, int type, int rid, struct resource *r);
70 int bus_alloc_resources(device_t dev, struct resource_spec *resourceSpec,
71 struct resource **resources);
72 void bus_release_resources(device_t dev,
73 const struct resource_spec *resourceSpec, struct resource **resources);
74
75 int bus_child_present(device_t child);
76 void bus_enumerate_hinted_children(device_t bus);
77
78 static inline struct resource *
bus_alloc_resource_any(device_t dev,int type,int * rid,uint32 flags)79 bus_alloc_resource_any(device_t dev, int type, int *rid, uint32 flags)
80 {
81 return bus_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
82 }
83
84 static inline struct resource *
bus_alloc_resource_anywhere(device_t dev,int type,int * rid,unsigned long count,uint32 flags)85 bus_alloc_resource_anywhere(device_t dev, int type, int *rid,
86 unsigned long count, uint32 flags)
87 {
88 return (bus_alloc_resource(dev, type, rid, 0, ~0, count, flags));
89 }
90
91 bus_dma_tag_t bus_get_dma_tag(device_t dev);
92
93 int bus_setup_intr(device_t dev, struct resource *r, int flags,
94 driver_filter_t* filter, driver_intr_t handler, void *arg, void **_cookie);
95 int bus_teardown_intr(device_t dev, struct resource *r, void *cookie);
96 int bus_bind_intr(device_t dev, struct resource *r, int cpu);
97 int bus_describe_intr(device_t dev, struct resource *irq, void *cookie,
98 const char* fmt, ...);
99
100 const char *device_get_name(device_t dev);
101 const char *device_get_nameunit(device_t dev);
102 int device_get_unit(device_t dev);
103 void *device_get_softc(device_t dev);
104 void device_set_softc(device_t dev, void *softc);
105 int device_printf(device_t dev, const char *, ...) __printflike(2, 3);
106 void device_set_desc(device_t dev, const char *desc);
107 void device_set_desc_copy(device_t dev, const char *desc);
108 const char *device_get_desc(device_t dev);
109 device_t device_get_parent(device_t dev);
110 u_int32_t device_get_flags(device_t dev);
111 devclass_t device_get_devclass(device_t dev);
112 int device_get_children(device_t dev, device_t **devlistp, int *devcountp);
113
114 void device_set_ivars(device_t dev, void *);
115 void *device_get_ivars(device_t dev);
116
117 device_t device_add_child(device_t dev, const char* name, int unit);
118 device_t device_add_child_driver(device_t dev, const char* name, driver_t* driver,
119 int unit);
120 int device_delete_child(device_t dev, device_t child);
121 int device_is_attached(device_t dev);
122 int device_attach(device_t dev);
123 int device_detach(device_t dev);
124 int bus_print_child_header(device_t dev, device_t child);
125 int bus_print_child_footer(device_t dev, device_t child);
126 int bus_generic_print_child(device_t dev, device_t child);
127 void bus_generic_driver_added(device_t dev, driver_t *driver);
128 int bus_generic_attach(device_t dev);
129 int device_set_driver(device_t dev, driver_t *driver);
130 int device_is_alive(device_t dev);
131
132
133 static inline struct sysctl_ctx_list *
device_get_sysctl_ctx(device_t dev)134 device_get_sysctl_ctx(device_t dev)
135 {
136 return NULL;
137 }
138
139
140 static inline void *
device_get_sysctl_tree(device_t dev)141 device_get_sysctl_tree(device_t dev)
142 {
143 return NULL;
144 }
145
146 devclass_t devclass_find(const char *classname);
147 device_t devclass_get_device(devclass_t dc, int unit);
148 int devclass_get_maxunit(devclass_t dc);
149
150 #endif /* _FBSD_COMPAT_SYS_BUS_H_ */
151