From 0ec64b89a9ddebabb9126e808693c86d12e8b7bb Mon Sep 17 00:00:00 2001 From: beveloper Date: Sun, 9 May 2004 18:58:17 +0000 Subject: [PATCH] Added a new timer function which can be used similar to the BeOS kernel add_timer function. The difference is that these callback functions will be executed in thread (not interrupt) context, and that they shouldn't crash (as add_timer does). Integrated the timer funtions into the timeout() and untimeout() FreeBSD emulation framework. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7474 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/network/ipro1000/Jamfile | 11 +++-- .../kernel/drivers/network/ipro1000/driver.c | 23 ++++++--- .../drivers/network/ipro1000/if_em_osdep.c | 28 +++-------- .../drivers/network/ipro1000/if_em_osdep.h | 11 ++--- .../kernel/drivers/network/ipro1000/timer.c | 49 +++++++++++++++++++ .../kernel/drivers/network/ipro1000/timer.h | 42 ++++++++++++++++ 6 files changed, 125 insertions(+), 39 deletions(-) create mode 100644 src/add-ons/kernel/drivers/network/ipro1000/timer.c create mode 100644 src/add-ons/kernel/drivers/network/ipro1000/timer.h diff --git a/src/add-ons/kernel/drivers/network/ipro1000/Jamfile b/src/add-ons/kernel/drivers/network/ipro1000/Jamfile index f9d3cc164c..de1621dde8 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/Jamfile +++ b/src/add-ons/kernel/drivers/network/ipro1000/Jamfile @@ -7,13 +7,14 @@ SubDirCcFlags -Wall ; UsePrivateHeaders net ; R5KernelAddon ipro1000 : kernel drivers bin : - driver.c - device.c - if_compat.c + driver.c + device.c + if_compat.c if_em.c if_em_hw.c - if_em_osdep.c - mempool.c + if_em_osdep.c + mempool.c + timer.c util.c ; diff --git a/src/add-ons/kernel/drivers/network/ipro1000/driver.c b/src/add-ons/kernel/drivers/network/ipro1000/driver.c index c1705a51ef..483178bf11 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/driver.c +++ b/src/add-ons/kernel/drivers/network/ipro1000/driver.c @@ -25,6 +25,7 @@ //#define DEBUG #include "debug.h" +#include "timer.h" #include "device.h" #include "driver.h" #include "mempool.h" @@ -130,7 +131,7 @@ init_driver(void) if (info) { char name[64]; sprintf(name, "net/ipro1000/%d", cards); - TRACE("/dev/%s is a %s\n", name, info); + PRINT("/dev/%s is a %s\n", name, info); gDevList[cards] = item; gDevNameList[cards] = strdup(name); gDevNameList[cards + 1] = NULL; @@ -148,16 +149,24 @@ init_driver(void) free(item); if (!cards) - goto err; + goto err_cards; + + if (initialize_timer() != B_OK) { + ERROR("timer init failed\n"); + goto err_timer; + } - if (mempool_init(cards * 768) != 0) { - TRACE("mempool init failed\n"); - goto err; + if (mempool_init(cards * 768) != B_OK) { + ERROR("mempool init failed\n"); + goto err_mempool; } return B_OK; -err: +err_mempool: + terminate_timer(); +err_timer: +err_cards: put_module(B_PCI_MODULE_NAME); return B_ERROR; } @@ -169,6 +178,8 @@ uninit_driver(void) int32 i; TRACE("uninit_driver()\n"); + + terminate_timer(); mempool_exit(); diff --git a/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.c b/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.c index e2c7278922..04ce9c994b 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.c +++ b/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.c @@ -50,38 +50,24 @@ contigfree(void *p, int p1, int p2) delete_area(area_for(p)); } -static int32 -timer_dispatch_hook(timer *t) -{ - struct callout_handle *h = (struct callout_handle *)t; - TRACE("timer_dispatch_hook\n"); - h->func(h->cookie); - return 0; -} - void callout_handle_init(struct callout_handle *handle) { - memset(handle, 0, sizeof(*handle)); + handle->timer = -1; } struct callout_handle -timeout(timeout_func func, void *cookie, bigtime_t timeout) +timeout(timer_function func, void *cookie, bigtime_t timeout) { - struct callout_handle h; - - h.func = func; - h.cookie = cookie; - -// add_timer(&h.t, timer_dispatch_hook, timeout, B_ONE_SHOT_RELATIVE_TIMER); - - return h; + struct callout_handle handle; + handle.timer = create_timer(func, cookie, timeout, B_ONE_SHOT_RELATIVE_TIMER); + return handle; } void -untimeout(timeout_func func, void *cookie, struct callout_handle handle) +untimeout(timer_function func, void *cookie, struct callout_handle handle) { -// cancel_timer(&handle.t); + delete_timer(handle.timer); } struct resource * diff --git a/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h b/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h index f7253bfeb0..7ddadb719b 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h +++ b/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h @@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "driver.h" #include "device.h" #include "debug.h" +#include "timer.h" #define DBG 0 @@ -159,18 +160,14 @@ static inline unsigned long vtophys(unsigned long virtual_addr) #define PAGE_SIZE 4096 -typedef void (*timeout_func)(void *); - struct callout_handle { - struct timer t; // must be on top - timeout_func func; - void *cookie; + timer_id timer; }; void callout_handle_init(struct callout_handle *handle); -struct callout_handle timeout(timeout_func func, void *cookie, bigtime_t timeout); -void untimeout(timeout_func func, void *cookie, struct callout_handle handle); +struct callout_handle timeout(timer_function func, void *cookie, bigtime_t timeout); +void untimeout(timer_function func, void *cookie, struct callout_handle handle); // resource management diff --git a/src/add-ons/kernel/drivers/network/ipro1000/timer.c b/src/add-ons/kernel/drivers/network/ipro1000/timer.c new file mode 100644 index 0000000000..cfc7ca61ee --- /dev/null +++ b/src/add-ons/kernel/drivers/network/ipro1000/timer.c @@ -0,0 +1,49 @@ +/* Intel PRO/1000 Family Driver + * Copyright (C) 2004 Marcus Overhagen . All rights reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies, and that both the + * copyright notice and this permission notice appear in supporting documentation. + * + * Marcus Overhagen makes no representations about the suitability of this software + * for any purpose. It is provided "as is" without express or implied warranty. + * + * MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS + * OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include +#include +#include +#include "debug.h" +#include "timer.h" + +timer_id +create_timer(timer_function func, void *cookie, bigtime_t period, uint32 flags) +{ + return 0; +} + +status_t +delete_timer(timer_id id) +{ + return B_OK; +} + +status_t +initialize_timer(void) +{ + return B_OK; +} + +status_t +terminate_timer(void) +{ + return B_OK; +} + + diff --git a/src/add-ons/kernel/drivers/network/ipro1000/timer.h b/src/add-ons/kernel/drivers/network/ipro1000/timer.h new file mode 100644 index 0000000000..394e110aaa --- /dev/null +++ b/src/add-ons/kernel/drivers/network/ipro1000/timer.h @@ -0,0 +1,42 @@ +/* Intel PRO/1000 Family Driver + * Copyright (C) 2004 Marcus Overhagen . All rights reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies, and that both the + * copyright notice and this permission notice appear in supporting documentation. + * + * Marcus Overhagen makes no representations about the suitability of this software + * for any purpose. It is provided "as is" without express or implied warranty. + * + * MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS + * OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY + * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef __TIMER_H +#define __TIMER_H + +#include + +// Since the BeOS kernel timers are executed in interrupt context, +// a new timer has been created. The timers are executed in thread +// context, and are passed a cookie. + +typedef int32 timer_id; + +typedef void (*timer_function)(void *cookie); + +// create_timer() cannot be called from interrupt context. +// flags can be B_ONE_SHOT_ABSOLUTE_TIMER, B_ONE_SHOT_RELATIVE_TIMER or B_PERIODIC_TIMER + +timer_id create_timer(timer_function func, void *cookie, bigtime_t period, uint32 flags); +status_t delete_timer(timer_id id); + + +status_t initialize_timer(void); +status_t terminate_timer(void); + +#endif