freebsd_iflib: Import compatibility files.
These are the portions of "freebsd_iflib.a" that I've written and do not come from FreeBSD. As the import of iflib itself will be quite large, having a separate commit for these made sense.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2018, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _device_if_h_
|
||||
#define _device_if_h_
|
||||
|
||||
void* DEVICE_REGISTER(device_t dev);
|
||||
|
||||
#endif /* _device_if_h_ */
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2018, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _SYS_KOBJ_H_
|
||||
#define _SYS_KOBJ_H_
|
||||
|
||||
|
||||
typedef struct kobj* kobj_t;
|
||||
typedef driver_t* kobj_class_t;
|
||||
typedef const struct device_method kobj_method_t;
|
||||
typedef device_method_signature_t kobjop_t;
|
||||
typedef void* kobj_ops_t;
|
||||
typedef struct kobjop_desc* kobjop_desc_t;
|
||||
|
||||
struct kobjop_desc {
|
||||
int32 id;
|
||||
kobj_method_t deflt; /* default implementation */
|
||||
};
|
||||
|
||||
|
||||
/* kobj */
|
||||
struct kobj_ops {
|
||||
kobj_class_t cls;
|
||||
};
|
||||
|
||||
#define KOBJ_FIELDS \
|
||||
struct kobj_ops ops
|
||||
|
||||
struct kobj {
|
||||
KOBJ_FIELDS;
|
||||
};
|
||||
|
||||
|
||||
/* this *must* be kept in sync with driver_t as defined in haiku-module.h */
|
||||
#define KOBJ_CLASS_FIELDS \
|
||||
const char* name; \
|
||||
kobj_method_t* methods; \
|
||||
size_t size; /* object size */
|
||||
|
||||
|
||||
#define KOBJOPLOOKUP(OPS,OP) do { \
|
||||
kobjop_desc_t _desc = &OP##_##desc; \
|
||||
kobj_method_t* _ce = NULL; \
|
||||
_ce = kobj_lookup_method(OPS.cls, \
|
||||
NULL, _desc); \
|
||||
_m = _ce->method; \
|
||||
} while(0)
|
||||
|
||||
|
||||
void kobj_init(kobj_t obj, kobj_class_t cls);
|
||||
kobj_method_t* kobj_lookup_method(kobj_class_t cls, kobj_method_t **cep,
|
||||
kobjop_desc_t desc);
|
||||
int kobj_error_method(void);
|
||||
|
||||
|
||||
/* we don't need these functions */
|
||||
static inline void kobj_class_compile(kobj_class_t cls) {}
|
||||
static inline void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops) {}
|
||||
static inline void kobj_class_free(kobj_class_t cls) {}
|
||||
static inline void kobj_init_static(kobj_t obj, kobj_class_t cls) {}
|
||||
|
||||
|
||||
#endif /* !_SYS_KOBJ_H_ */
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2018, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _FBSD_COMPAT_IFLIB_SYS_KTHREAD_H_
|
||||
#define _FBSD_COMPAT_IFLIB_SYS_KTHREAD_H_
|
||||
|
||||
/* include the real sys/kthread.h */
|
||||
#include_next <sys/kthread.h>
|
||||
|
||||
#include <sys/pcpu.h>
|
||||
|
||||
|
||||
#define SRQ_BORING 0
|
||||
|
||||
void sched_prio(struct thread* td, u_char prio);
|
||||
void sched_add(struct thread* td, int flags);
|
||||
|
||||
int kthread_add(void (*func)(void *), void *arg, void* p,
|
||||
struct thread** newtdp, int flags, int pages, const char* fmt, ...);
|
||||
void kthread_exit();
|
||||
|
||||
#define thread_lock(td)
|
||||
#define thread_unlock(td)
|
||||
|
||||
|
||||
#endif /* _FBSD_COMPAT_IFLIB_SYS_KTHREAD_H_ */
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2018, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <util/list.h>
|
||||
#include <sys/haiku-module.h>
|
||||
#include <device_if.h>
|
||||
|
||||
#include "../freebsd_network/shared.h"
|
||||
|
||||
|
||||
void*
|
||||
DEVICE_REGISTER(device_t dev)
|
||||
{
|
||||
return dev->methods.device_register(dev);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2018-2019, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
|
||||
static kobj_method_t kobj_default_method = {
|
||||
"kobj_default_method", 0, (kobjop_t)kobj_error_method
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
kobj_init(kobj_t obj, kobj_class_t cls)
|
||||
{
|
||||
obj->ops.cls = cls;
|
||||
}
|
||||
|
||||
|
||||
kobj_method_t*
|
||||
kobj_lookup_method(kobj_class_t class, kobj_method_t** cep,
|
||||
kobjop_desc_t desc)
|
||||
{
|
||||
int32 i, id;
|
||||
kobj_method_t* ret = NULL;
|
||||
|
||||
id = desc->id;
|
||||
if (id == 0)
|
||||
id = desc->deflt.id;
|
||||
|
||||
for (i = 0; class->methods[i].name != NULL; i++) {
|
||||
kobj_method_t* mth = &class->methods[i];
|
||||
if (mth->id != id)
|
||||
continue;
|
||||
|
||||
ret = mth;
|
||||
break;
|
||||
}
|
||||
if (ret == NULL || ret->method == NULL)
|
||||
ret = &desc->deflt;
|
||||
if (ret == NULL || ret->method == NULL)
|
||||
ret = &kobj_default_method;
|
||||
|
||||
if (cep != NULL)
|
||||
*cep = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
kobj_error_method(void)
|
||||
{
|
||||
return ENXIO;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2018, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kthread.h>
|
||||
}
|
||||
|
||||
#include <thread.h>
|
||||
|
||||
|
||||
int
|
||||
kthread_add(void (*func)(void *), void *arg, void* p,
|
||||
struct thread **newtdp, int flags, int pages, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(name, sizeof(name), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
thread_id id = spawn_kernel_thread((status_t (*)(void *))func, /* HACK! */
|
||||
name, B_NORMAL_PRIORITY, arg);
|
||||
if (id < 0)
|
||||
return id;
|
||||
if (newtdp != NULL) {
|
||||
intptr_t thread = id;
|
||||
*newtdp = (struct thread*)thread;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sched_prio(struct thread* td, u_char prio)
|
||||
{
|
||||
set_thread_priority((thread_id)td, prio);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sched_add(struct thread* td, int /* flags */)
|
||||
{
|
||||
resume_thread((thread_id)td);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
kthread_exit()
|
||||
{
|
||||
thread_exit();
|
||||
}
|
||||
Reference in New Issue
Block a user