xref: /haiku/src/libs/compat/freebsd_network/device.h (revision 52f7c9389475e19fc21487b38064b4390eeb6fea)
1 /*
2  * Copyright 2009, Colin Günther, coling@gmx.de. All Rights Reserved.
3  * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved.
4  * Copyright 2007, Hugo Santos. All Rights Reserved.
5  * Copyright 2004, Marcus Overhagen. All Rights Reserved.
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 
25 #include "shared.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 struct root_device_softc {
32 	enum {
33 		BUS_INVALID = 0,
34 		BUS_pci,
35 		BUS_uhub,
36 	} bus;
37 
38 	struct pci_info	pci_info;
39 	bool			is_msi;
40 	bool			is_msix;
41 
42 	struct freebsd_usb_device* usb_dev;
43 };
44 
45 enum {
46 	DEVICE_OPEN			= 1 << 0,
47 	DEVICE_CLOSED		= 1 << 1,
48 	DEVICE_NON_BLOCK	= 1 << 2,
49 	DEVICE_DESC_ALLOCED	= 1 << 3,
50 	DEVICE_ATTACHED		= 1 << 4,
51 	DEVICE_SOFTC_SET	= 1 << 5  // Set through device_set_softc().
52 };
53 
54 
55 extern struct net_stack_module_info *gStack;
56 extern pci_module_info *gPci;
57 extern struct pci_x86_module_info *gPCIx86;
58 
59 
60 static inline void
61 __unimplemented(const char *method)
62 {
63 	char msg[128];
64 	snprintf(msg, sizeof(msg), "fbsd compat, unimplemented: %s", method);
65 	panic(msg);
66 }
67 
68 #define UNIMPLEMENTED() __unimplemented(__FUNCTION__)
69 
70 status_t init_mbufs(void);
71 void uninit_mbufs(void);
72 
73 status_t init_mutexes(void);
74 void uninit_mutexes(void);
75 
76 status_t init_taskqueues(void);
77 void uninit_taskqueues(void);
78 
79 status_t init_hard_clock(void);
80 void uninit_hard_clock(void);
81 
82 status_t init_callout(void);
83 void uninit_callout(void);
84 
85 status_t init_pci();
86 void uninit_pci();
87 
88 status_t init_usb();
89 void uninit_usb();
90 
91 status_t get_next_usb_device(uint32* cookie, struct freebsd_usb_device* result);
92 status_t get_usb_device_attach_arg(struct freebsd_usb_device* device, struct usb_attach_arg* uaa);
93 
94 device_t find_root_device(int);
95 pci_info* get_device_pci_info(device_t dev);
96 
97 void driver_printf(const char *format, ...)
98 	__attribute__ ((format (__printf__, 1, 2)));
99 int driver_vprintf(const char *format, va_list vl);
100 
101 void device_sprintf_name(device_t dev, const char *format, ...)
102 	__attribute__ ((format (__printf__, 2, 3)));
103 
104 void ifq_init(struct ifqueue *, const char *);
105 void ifq_uninit(struct ifqueue *);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif	/* DEVICE_H */
112