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
This commit is contained in:
Hugo Santos
2007-05-04 14:22:35 +00:00
parent 8c5520d67a
commit 747c938b9b
3 changed files with 92 additions and 76 deletions
@@ -6,6 +6,8 @@
#include <sys/systm.h>
#include <sys/sysctl.h>
#include <sys/haiku-module.h>
// 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);
@@ -0,0 +1,71 @@
/*
* Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos, [email protected]
*/
#ifndef _FBSD_COMPAT_SYS_HAIKU_MODULE_H_
#define _FBSD_COMPAT_SYS_HAIKU_MODULE_H_
#include <Drivers.h> /* 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
+19 -40
View File
@@ -13,17 +13,15 @@
#include <stdlib.h>
#include <Drivers.h>
#include <compat/sys/bus.h>
#include <compat/sys/haiku-module.h>
#include <compat/sys/mbuf.h>
#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;
}