2 * Copyright 2007, Hugo Santos. All Rights Reserved.
3 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved.
4 * Copyright 2004, Marcus Overhagen. All Rights Reserved.
5 * Distributed under the terms of the MIT License.
9 /*! Driver functions that adapt the FreeBSD driver to Haiku's driver API.
10 The actual driver functions are exported by the HAIKU_FBSD_DRIVER_GLUE
11 macro, and just call the functions here.
18 #include <sys/sockio.h>
21 #include <ether_driver.h>
24 #include <compat/sys/haiku-module.h>
26 #include <compat/sys/bus.h>
27 #include <compat/sys/mbuf.h>
28 #include <compat/net/ethernet.h>
31 //#define TRACE_DRIVER
33 # define TRACE(x) dprintf x
39 const char *gDeviceNameList
[MAX_DEVICES
+ 1];
40 struct ifnet
*gDevices
[MAX_DEVICES
];
45 init_root_device(device_t
*_root
)
47 static driver_t sRootDriver
= {
50 sizeof(struct root_device_softc
)
53 device_t root
= device_add_child(NULL
, NULL
, 0);
57 root
->softc
= malloc(sizeof(struct root_device_softc
));
58 if (root
->softc
== NULL
) {
59 device_delete_child(NULL
, root
);
63 bzero(root
->softc
, sizeof(struct root_device_softc
));
64 root
->driver
= &sRootDriver
;
75 add_child_device(driver_t
*driver
, device_t root
, device_t
*_child
)
77 device_t child
= device_add_child(root
, driver
->name
, 0);
90 get_pci_info(struct device
*device
)
92 return &((struct root_device_softc
*)device
->softc
)->pci_info
;
96 // #pragma mark - Haiku Driver API
100 _fbsd_init_hardware(driver_t
*drivers
[])
102 status_t status
= B_ENTRY_NOT_FOUND
;
105 driver_t
*driver
= NULL
;
108 if (get_module(B_PCI_MODULE_NAME
, (module_info
**)&gPci
) < B_OK
)
111 status
= init_root_device(&root
);
115 for (info
= get_pci_info(root
); gPci
->get_nth_pci_info(i
, info
) == B_OK
;
120 for (index
= 0; drivers
[index
] && gDeviceCount
< MAX_DEVICES
121 && driver
== NULL
; index
++) {
124 status
= add_child_device(drivers
[index
], root
, &device
);
128 result
= device
->methods
.probe(device
);
130 TRACE(("%s, found %s at %d\n", gDriverName
,
131 device_get_desc(device
), i
));
132 driver
= drivers
[index
];
134 device_delete_child(root
, device
);
141 device_delete_child(NULL
, root
);
143 if (driver
== NULL
) {
145 TRACE(("%s: no hardware found.\n", gDriverName
));
148 put_module(B_PCI_MODULE_NAME
);
149 TRACE(("%s: status 0x%lx\n", gDriverName
, status
));
156 _fbsd_init_drivers(driver_t
*drivers
[])
164 status
= get_module(B_PCI_MODULE_NAME
, (module_info
**)&gPci
);
168 // if it fails we just don't support x86 specific features (like MSIs)
169 if (get_module(B_PCI_X86_MODULE_NAME
, (module_info
**)&gPCIx86
) != B_OK
)
172 status
= init_hard_clock();
176 status
= init_mutexes();
180 status
= init_mbufs();
184 status
= init_callout();
190 if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES
)) {
191 status
= init_taskqueues();
196 status
= init_wlan_stack();
200 status
= init_root_device(&root
);
204 for (info
= get_pci_info(root
); gPci
->get_nth_pci_info(i
, info
) == B_OK
;
207 driver_t
*driver
= NULL
;
209 for (index
= 0; drivers
[index
] && gDeviceCount
< MAX_DEVICES
; index
++) {
212 status
= add_child_device(drivers
[index
], root
, &device
);
216 result
= device
->methods
.probe(device
);
217 if (result
>= 0 && (driver
== NULL
|| result
> best
)) {
218 TRACE(("%s, found %s at %d (%d)\n", gDriverName
,
219 device_get_desc(device
), i
, result
));
220 driver
= drivers
[index
];
223 device_delete_child(root
, device
);
226 if (driver
!= NULL
) {
228 status
= add_child_device(driver
, root
, &device
);
231 if (device_attach(device
) == 0) {
232 dprintf("%s: init_driver(%p) at %d\n", gDriverName
, driver
, i
);
234 device_delete_child(root
, device
);
238 if (gDeviceCount
> 0)
241 device_delete_child(NULL
, root
);
250 if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES
))
261 put_module(B_PCI_MODULE_NAME
);
263 put_module(B_PCI_X86_MODULE_NAME
);
270 _fbsd_uninit_drivers(driver_t
*drivers
[])
274 for (i
= 0; drivers
[i
]; i
++)
275 TRACE(("%s: uninit_driver(%p)\n", gDriverName
, drivers
[i
]));
277 for (i
= 0; i
< gDeviceCount
; i
++) {
278 device_delete_child(NULL
, gDevices
[i
]->root_device
);
282 uninit_bounce_pages();
284 if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES
))
290 put_module(B_PCI_MODULE_NAME
);
292 put_module(B_PCI_X86_MODULE_NAME
);