From 336ce7039c6658a6a6bbff64a4c8d756c28bcd45 Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Fri, 4 May 2007 11:26:37 +0000 Subject: [PATCH] freebsd compat. layer: some initial glue code git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21013 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../drivers/network/fxp/dev/fxp/Jamfile | 1 + .../kernel/drivers/network/fxp/dev/fxp/glue.c | 3 + .../compat/freebsd_network/compat/sys/bus.h | 16 +++- src/libs/compat/freebsd_network/device.c | 84 ++++++++++++++++++- src/libs/compat/freebsd_network/mii.c | 5 ++ 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c diff --git a/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile b/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile index ef155a38aa..639abc2293 100644 --- a/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile +++ b/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile @@ -11,6 +11,7 @@ SubDirCcFlags [ FDefines _KERNEL=1 ] ; KernelAddon fxp : if_fxp.c + glue.c : libfreebsd_network.a ; diff --git a/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c b/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c new file mode 100644 index 0000000000..7fb82054f5 --- /dev/null +++ b/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c @@ -0,0 +1,3 @@ +#include + +HAIKU_FBSD_DRIVER_GLUE(fxp, pci) diff --git a/src/libs/compat/freebsd_network/compat/sys/bus.h b/src/libs/compat/freebsd_network/compat/sys/bus.h index 20ceda08e1..d6b4da3ed1 100644 --- a/src/libs/compat/freebsd_network/compat/sys/bus.h +++ b/src/libs/compat/freebsd_network/compat/sys/bus.h @@ -133,9 +133,21 @@ 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 BUS_PROBE_DEFAULT 20 -#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) +#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); diff --git a/src/libs/compat/freebsd_network/device.c b/src/libs/compat/freebsd_network/device.c index 060c92cc71..76cc16a761 100644 --- a/src/libs/compat/freebsd_network/device.c +++ b/src/libs/compat/freebsd_network/device.c @@ -11,11 +11,21 @@ #include "device.h" #include +#include #include #include +#define MAX_DEVICES 8 + + +int32 api_version = B_CUR_DRIVER_API_VERSION; + + +static char *sDevNameList[MAX_DEVICES + 1]; + + static status_t compat_open(const char *name, uint32 flags, void **cookie) { @@ -70,7 +80,7 @@ compat_read(void *cookie, off_t position, void *buf, size_t *numBytes) IF_DEQUEUE(&dev->receive_queue, mb); } while (mb == NULL); - len = min_c(max_c(mb->m_len, 0), *numBytes); + len = min_c(max_c((size_t)mb->m_len, 0), *numBytes); // TODO we need something that cna join various chunks memcpy(buf, mtod(mb, const void *), len); @@ -94,3 +104,75 @@ compat_control(void *cookie, uint32 op, void *arg, size_t len) { return B_ERROR; } + + +static device_hooks sDeviceHooks = { + compat_open, + compat_close, + compat_free, + compat_control, + compat_read, + compat_write, +}; + + +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() +{ + struct device fakeDevice; + pci_info info; + int i; + + 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) + return B_OK; + } + + return B_ERROR; +} + + +status_t +init_driver() +{ + return B_ERROR; +} + + +void +uninit_driver() +{ +} + + +const char ** +publish_devices() +{ + return (const char **)sDevNameList; +} + + +device_hooks * +find_device(const char *name) +{ + return &sDeviceHooks; +} diff --git a/src/libs/compat/freebsd_network/mii.c b/src/libs/compat/freebsd_network/mii.c index b0e376c037..a0785927cf 100644 --- a/src/libs/compat/freebsd_network/mii.c +++ b/src/libs/compat/freebsd_network/mii.c @@ -14,6 +14,11 @@ #include +driver_t miibus_driver = { + "mii", +}; + + int mii_phy_probe(device_t dev, device_t *miiDev, ifm_change_cb_t change, ifm_stat_cb_t stat)