xref: /haiku/src/libs/compat/freebsd_network/device.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved.
3  * Copyright 2007, Hugo Santos. All Rights Reserved.
4  * Copyright 2004, Marcus Overhagen. All Rights Reserved.
5  *
6  * Distributed under the terms of the MIT License.
7  */
8 #ifndef DEVICE_H
9 #define DEVICE_H
10 
11 
12 #include <stdint.h>
13 #include <stdio.h>
14 
15 #include <KernelExport.h>
16 #include <drivers/PCI.h>
17 
18 #include <util/list.h>
19 
20 #include <net_stack.h>
21 
22 #include <compat/sys/kernel.h>
23 #include <compat/net/if.h>
24 #include <compat/net/if_var.h>
25 
26 
27 #define MAX_DEVICES	8
28 
29 struct ifnet;
30 
31 struct device {
32 	struct device	*parent;
33 	struct device	*root;
34 
35 	driver_t		*driver;
36 	struct list		children;
37 
38 	int32			flags;
39 
40 	char			device_name[128];
41 	int				unit;
42 	char			nameunit[64];
43 	const char		*description;
44 	void			*softc;
45 	void			*ivars;
46 
47 	struct {
48 		int (*probe)(device_t dev);
49 		int (*attach)(device_t dev);
50 		int (*detach)(device_t dev);
51 		int (*suspend)(device_t dev);
52 		int (*resume)(device_t dev);
53 		void (*shutdown)(device_t dev);
54 
55 		int (*miibus_readreg)(device_t, int, int);
56 		int (*miibus_writereg)(device_t, int, int, int);
57 		void (*miibus_statchg)(device_t);
58 		void (*miibus_linkchg)(device_t);
59 		void (*miibus_mediainit)(device_t);
60 	} methods;
61 
62 	struct list_link link;
63 };
64 
65 struct root_device_softc {
66 	struct pci_info	pci_info;
67 };
68 
69 enum {
70 	DEVICE_OPEN			= 1 << 0,
71 	DEVICE_CLOSED		= 1 << 1,
72 	DEVICE_NON_BLOCK	= 1 << 2,
73 	DEVICE_DESC_ALLOCED	= 1 << 3,
74 	DEVICE_ATTACHED		= 1 << 4
75 };
76 
77 
78 extern struct net_stack_module_info *gStack;
79 extern pci_module_info *gPci;
80 
81 extern const char *gDeviceNameList[];
82 extern struct ifnet *gDevices[];
83 extern int32 gDeviceCount;
84 
85 
86 static inline void
87 __unimplemented(const char *method)
88 {
89 	char msg[128];
90 	snprintf(msg, sizeof(msg), "fbsd compat, unimplemented: %s", method);
91 	panic(msg);
92 }
93 
94 
95 #define UNIMPLEMENTED() __unimplemented(__FUNCTION__)
96 
97 status_t init_mbufs(void);
98 void uninit_mbufs(void);
99 
100 status_t init_mutexes(void);
101 void uninit_mutexes(void);
102 
103 status_t init_taskqueues(void);
104 void uninit_taskqueues(void);
105 
106 device_t find_root_device(int unit);
107 
108 /* busdma_machdep.c */
109 void init_bounce_pages(void);
110 void uninit_bounce_pages(void);
111 
112 void driver_printf(const char *format, ...)
113 	__attribute__ ((format (__printf__, 1, 2)));
114 void driver_vprintf(const char *format, va_list vl);
115 
116 void device_sprintf_name(device_t dev, const char *format, ...)
117 	__attribute__ ((format (__printf__, 2, 3)));
118 
119 void ifq_init(struct ifqueue *ifq, const char *name);
120 void ifq_uninit(struct ifqueue *ifq);
121 
122 #endif	/* DEVICE_H */
123