Date: Thu, 15 Jul 2010 01:18:37 +0000 (UTC) From: Jeff Roberson <jeff@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r210095 - projects/ofed/head/sys/ofed/include/linux Message-ID: <201007150118.o6F1Ibdi036566@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jeff Date: Thu Jul 15 01:18:37 2010 New Revision: 210095 URL: http://svn.freebsd.org/changeset/base/210095 Log: - Fill out more of the kobject api. Sponsored by: Isilon Systems, iX Systems, and Panasas. Modified: projects/ofed/head/sys/ofed/include/linux/kobject.h projects/ofed/head/sys/ofed/include/linux/linux_compat.c Modified: projects/ofed/head/sys/ofed/include/linux/kobject.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/kobject.h Thu Jul 15 01:17:40 2010 (r210094) +++ projects/ofed/head/sys/ofed/include/linux/kobject.h Thu Jul 15 01:18:37 2010 (r210095) @@ -29,6 +29,8 @@ #define _LINUX_KOBJECT_H_ #include <machine/stdarg.h> + +#include <linux/kernel.h> #include <linux/kref.h> #include <linux/slab.h> @@ -47,30 +49,41 @@ struct kobject { struct kobj_type *ktype; }; -static inline int -kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, - struct kobject *parent, const char *fmt, ...) +static inline void +kobject_init(struct kobject *kobj, struct kobj_type *ktype) { kref_init(&kobj->kref); kobj->ktype = ktype; kobj->name = NULL; kobj->parent = NULL; - return 0; } static inline void -kobject_init(struct kobject *kobj, struct kobj_type *ktype) +kobject_release(struct kref *kref) { - kref_init(&kobj->kref); - kobj->ktype = ktype; - kobj->name = NULL; - kobj->parent = NULL; + struct kobject *kobj; + + kobj = container_of(kref, struct kobject, kref); + if (kobj->ktype && kobj->ktype->release) + kobj->ktype->release(kobj); } static inline void kobject_put(struct kobject *kobj) { + + if (kobj) + kref_put(&kobj->kref, kobject_release); +} + +static inline struct kobject * +kobject_get(struct kobject *kobj) +{ + + if (kobj) + kref_get(&kobj->kref); + return kobj; } static inline int @@ -117,6 +130,8 @@ kobject_name(const struct kobject *kobj) return kobj->name; } -int kobject_set_name(struct kobject *kobj, const char *fmt, ...); +int kobject_set_name(struct kobject *kobj, const char *fmt, ...); +int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, + struct kobject *parent, const char *fmt, ...); #endif /* _LINUX_KOBJECT_H_ */ Modified: projects/ofed/head/sys/ofed/include/linux/linux_compat.c ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/linux_compat.c Thu Jul 15 01:17:40 2010 (r210094) +++ projects/ofed/head/sys/ofed/include/linux/linux_compat.c Thu Jul 15 01:18:37 2010 (r210095) @@ -33,19 +33,26 @@ #include <sys/sysctl.h> #include <sys/lock.h> #include <sys/mutex.h> +#include <sys/bus.h> #include <machine/stdarg.h> #include <linux/kobject.h> +#include <linux/device.h> #include <linux/slab.h> +#include <linux/module.h> MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat"); +MALLOC_DEFINE(M_LINUX_DMA, "lnxdma", "Linux DMA compat"); #include <linux/rbtree.h> /* Undo Linux compat change. */ #undef RB_ROOT #define RB_ROOT(head) (head)->rbh_root +struct class miscclass; +struct linux_device miscroot; + int panic_cmp(struct rb_node *one, struct rb_node *two) { @@ -66,3 +73,51 @@ kobject_set_name(struct kobject *kobj, c return (error); } + +struct device * +device_create(struct class *class, struct device *parent, dev_t devt, + void *drvdata, const char *fmt, ...) +{ + struct device *dev; + va_list args; + + dev = kzalloc(sizeof(*dev), M_WAITOK); + dev->parent = parent; + dev->devt = devt; + dev->driver_data = drvdata; + va_start(args, fmt); + kobject_set_name_vargs(&dev->kobj, fmt, args); + va_end(args); + device_register(dev); + + return (dev); +} + +int +kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, + struct kobject *parent, const char *fmt, ...) +{ + va_list args; + int error; + + kobject_init(kobj, ktype); + kobj->ktype = ktype; + kobj->parent = parent; + kobj->name = NULL; + + va_start(args, fmt); + error = kobject_set_name_vargs(kobj, fmt, args); + va_end(args); + + return error; +} + +static void +linux_compat_init(void) +{ + miscclass.name = "misc"; + class_register(&miscclass); + miscroot.bsddev = root_bus; +} + +module_init(linux_compat_init);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007150118.o6F1Ibdi036566>