From 747c938b9b5f92da067800cd995378e20ba23760 Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Fri, 4 May 2007 14:22:35 +0000 Subject: [PATCH] freebsd compat. layer: now the glue code properly references the required methods so we have proper linkage with gcc 4 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21017 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../compat/freebsd_network/compat/sys/bus.h | 38 +--------- .../freebsd_network/compat/sys/haiku-module.h | 71 +++++++++++++++++++ src/libs/compat/freebsd_network/device.c | 59 +++++---------- 3 files changed, 92 insertions(+), 76 deletions(-) create mode 100644 src/libs/compat/freebsd_network/compat/sys/haiku-module.h diff --git a/src/libs/compat/freebsd_network/compat/sys/bus.h b/src/libs/compat/freebsd_network/compat/sys/bus.h index d6b4da3ed1..e124e73952 100644 --- a/src/libs/compat/freebsd_network/compat/sys/bus.h +++ b/src/libs/compat/freebsd_network/compat/sys/bus.h @@ -6,6 +6,8 @@ #include #include +#include + // TODO per platform, these are x86 typedef uint32_t bus_addr_t; typedef uint32_t bus_size_t; @@ -85,26 +87,6 @@ bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, } -typedef struct device *device_t; -typedef struct devclass *devclass_t; - -typedef int (*device_method_signature_t)(device_t dev); - -struct device_method { - const char *name; - device_method_signature_t method; -}; - -typedef struct device_method device_method_t; - -#define DEVMETHOD(name, func) { #name, (device_method_signature_t)func } - -typedef struct { - const char *name; - device_method_t *methods; - size_t size; -} driver_t; - enum intr_type { INTR_TYPE_NET = 4, INTR_MPSAFE = 512, @@ -133,22 +115,6 @@ int bus_setup_intr(device_t dev, struct resource *r, int flags, driver_intr_t handler, void *arg, void **cookiep); int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); -#define BUS_PROBE_DEFAULT 20 - -#define DRIVER_MODULE_NAME(name, busname) \ - __fbsd_##name##busname - -driver_t *__fbsd_driver(void); - -#define HAIKU_FBSD_DRIVER_GLUE(name, busname) \ - driver_t *__fbsd_driver() { \ - extern driver_t *DRIVER_MODULE_NAME(name, busname); \ - return DRIVER_MODULE_NAME(name, busname); \ - } - -#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ - driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver) - const char *device_get_name(device_t dev); const char *device_get_nameunit(device_t dev); int device_get_unit(device_t dev); diff --git a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h new file mode 100644 index 0000000000..bdfe50347c --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h @@ -0,0 +1,71 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos@gmail.com + */ +#ifndef _FBSD_COMPAT_SYS_HAIKU_MODULE_H_ +#define _FBSD_COMPAT_SYS_HAIKU_MODULE_H_ + +#include /* for device_hooks */ + +typedef struct device *device_t; +typedef struct devclass *devclass_t; + +typedef int (*device_method_signature_t)(device_t dev); + +struct device_method { + const char *name; + device_method_signature_t method; +}; + +typedef struct device_method device_method_t; + +#define DEVMETHOD(name, func) { #name, (device_method_signature_t)func } + +typedef struct { + const char *name; + device_method_t *methods; + size_t size; +} driver_t; + +#define BUS_PROBE_DEFAULT 20 + +#define DRIVER_MODULE_NAME(name, busname) \ + __fbsd_##name##busname + +status_t _fbsd_init_hardware(driver_t *); +status_t _fbsd_init_driver(driver_t *); +void _fbsd_uninit_driver(driver_t *); + +/* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to + * force the rest of the stuff to be linked back with the driver. + * While gcc 2.95 packs everything from the static library onto + * the final binary, gcc 4.x rightfuly doesn't. */ + +#define HAIKU_FBSD_DRIVER_GLUE(name, busname) \ + extern char *gDevNameList[]; \ + extern device_hooks gDeviceHooks; \ + extern driver_t *DRIVER_MODULE_NAME(name, busname); \ + int32 api_version = B_CUR_DRIVER_API_VERSION; \ + status_t init_hardware() \ + { \ + return _fbsd_init_hardware(DRIVER_MODULE_NAME(name, busname)); \ + } \ + status_t init_driver() \ + { \ + return _fbsd_init_driver(DRIVER_MODULE_NAME(name, busname)); \ + } \ + void uninit_driver() \ + { \ + _fbsd_uninit_driver(DRIVER_MODULE_NAME(name, busname)); \ + } \ + const char **publish_devices() { return (const char **)gDevNameList; } \ + device_hooks *find_device(const char *name) { return &gDeviceHooks; } + +#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ + driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver) + + +#endif diff --git a/src/libs/compat/freebsd_network/device.c b/src/libs/compat/freebsd_network/device.c index 76cc16a761..63537d2c5f 100644 --- a/src/libs/compat/freebsd_network/device.c +++ b/src/libs/compat/freebsd_network/device.c @@ -13,17 +13,15 @@ #include #include -#include +#include + #include #define MAX_DEVICES 8 -int32 api_version = B_CUR_DRIVER_API_VERSION; - - -static char *sDevNameList[MAX_DEVICES + 1]; +char *gDevNameList[MAX_DEVICES + 1]; static status_t @@ -106,7 +104,7 @@ compat_control(void *cookie, uint32 op, void *arg, size_t len) } -static device_hooks sDeviceHooks = { +device_hooks gDeviceHooks = { compat_open, compat_close, compat_free, @@ -116,34 +114,29 @@ static device_hooks sDeviceHooks = { }; -static int -_device_probe(device_t dev) -{ - device_method_t *methods = __fbsd_driver()->methods; - int i; - - for (i = 0; methods[i].name != NULL; i++) { - if (!strcmp(methods[i].name, "device_probe")) - return methods[i].method(dev); - } - - panic("fsbd compat layer: method missing, device_probe"); - return -1; -} - - status_t -init_hardware() +_fbsd_init_hardware(driver_t *driver) { + device_method_signature_t probe = NULL; struct device fakeDevice; pci_info info; int i; + for (i = 0; probe == NULL && driver->methods[i].name != NULL; i++) { + if (strcmp(driver->methods[i].name, "device_probe") == 0) + probe = driver->methods[i].method; + } + + if (probe == NULL) { + dprintf("_fbsd_init_hardware: driver has no device_probe method.\n"); + return B_ERROR; + } + memset(&fakeDevice, 0, sizeof(struct device)); fakeDevice.pciInfo = &info; for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK; i++) { - if (_device_probe(&fakeDevice) >= 0) + if (probe(&fakeDevice) >= 0) return B_OK; } @@ -152,27 +145,13 @@ init_hardware() status_t -init_driver() +_fbsd_init_driver(driver_t *driver) { return B_ERROR; } void -uninit_driver() +_fbsd_uninit_driver(driver_t *driver) { } - - -const char ** -publish_devices() -{ - return (const char **)sDevNameList; -} - - -device_hooks * -find_device(const char *name) -{ - return &sDeviceHooks; -}