1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5270710Shselasky * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28289644Shselasky * 29289644Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/kobject.h 331756 2018-03-30 02:04:46Z emaste $ 30219820Sjeff */ 31219820Sjeff#ifndef _LINUX_KOBJECT_H_ 32219820Sjeff#define _LINUX_KOBJECT_H_ 33219820Sjeff 34219820Sjeff#include <machine/stdarg.h> 35219820Sjeff 36219820Sjeff#include <linux/kernel.h> 37219820Sjeff#include <linux/kref.h> 38328653Shselasky#include <linux/list.h> 39219820Sjeff#include <linux/slab.h> 40219820Sjeff 41219820Sjeffstruct kobject; 42219820Sjeffstruct sysctl_oid; 43219820Sjeff 44219820Sjeffstruct kobj_type { 45219820Sjeff void (*release)(struct kobject *kobj); 46219820Sjeff const struct sysfs_ops *sysfs_ops; 47219820Sjeff struct attribute **default_attrs; 48219820Sjeff}; 49219820Sjeff 50292987Shselaskyextern const struct kobj_type linux_kfree_type; 51219820Sjeff 52219820Sjeffstruct kobject { 53219820Sjeff struct kobject *parent; 54219820Sjeff char *name; 55219820Sjeff struct kref kref; 56292987Shselasky const struct kobj_type *ktype; 57219820Sjeff struct list_head entry; 58219820Sjeff struct sysctl_oid *oidp; 59219820Sjeff}; 60219820Sjeff 61270710Shselaskyextern struct kobject *mm_kobj; 62270710Shselasky 63290335Shselaskystruct attribute { 64331756Semaste const char *name; 65290335Shselasky struct module *owner; 66290335Shselasky mode_t mode; 67290335Shselasky}; 68290335Shselasky 69290335Shselaskystruct kobj_attribute { 70331756Semaste struct attribute attr; 71331756Semaste ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, 72331756Semaste char *buf); 73331756Semaste ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, 74331756Semaste const char *buf, size_t count); 75290335Shselasky}; 76290335Shselasky 77219820Sjeffstatic inline void 78292987Shselaskykobject_init(struct kobject *kobj, const struct kobj_type *ktype) 79219820Sjeff{ 80219820Sjeff 81219820Sjeff kref_init(&kobj->kref); 82219820Sjeff INIT_LIST_HEAD(&kobj->entry); 83219820Sjeff kobj->ktype = ktype; 84219820Sjeff kobj->oidp = NULL; 85219820Sjeff} 86219820Sjeff 87292987Shselaskyvoid linux_kobject_release(struct kref *kref); 88219820Sjeff 89219820Sjeffstatic inline void 90219820Sjeffkobject_put(struct kobject *kobj) 91219820Sjeff{ 92219820Sjeff 93219820Sjeff if (kobj) 94292987Shselasky kref_put(&kobj->kref, linux_kobject_release); 95219820Sjeff} 96219820Sjeff 97219820Sjeffstatic inline struct kobject * 98219820Sjeffkobject_get(struct kobject *kobj) 99219820Sjeff{ 100219820Sjeff 101219820Sjeff if (kobj) 102219820Sjeff kref_get(&kobj->kref); 103219820Sjeff return kobj; 104219820Sjeff} 105219820Sjeff 106292834Shselaskyint kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list); 107219820Sjeffint kobject_add(struct kobject *kobj, struct kobject *parent, 108219820Sjeff const char *fmt, ...); 109219820Sjeff 110219820Sjeffstatic inline struct kobject * 111219820Sjeffkobject_create(void) 112219820Sjeff{ 113219820Sjeff struct kobject *kobj; 114219820Sjeff 115219820Sjeff kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); 116219820Sjeff if (kobj == NULL) 117219820Sjeff return (NULL); 118292987Shselasky kobject_init(kobj, &linux_kfree_type); 119219820Sjeff 120219820Sjeff return (kobj); 121219820Sjeff} 122219820Sjeff 123219820Sjeffstatic inline struct kobject * 124219820Sjeffkobject_create_and_add(const char *name, struct kobject *parent) 125219820Sjeff{ 126219820Sjeff struct kobject *kobj; 127219820Sjeff 128219820Sjeff kobj = kobject_create(); 129219820Sjeff if (kobj == NULL) 130219820Sjeff return (NULL); 131219820Sjeff if (kobject_add(kobj, parent, "%s", name) == 0) 132219820Sjeff return (kobj); 133219820Sjeff kobject_put(kobj); 134219820Sjeff 135219820Sjeff return (NULL); 136219820Sjeff} 137219820Sjeff 138328653Shselaskystatic inline void 139328653Shselaskykobject_del(struct kobject *kobj __unused) 140328653Shselasky{ 141328653Shselasky} 142328653Shselasky 143219820Sjeffstatic inline char * 144219820Sjeffkobject_name(const struct kobject *kobj) 145219820Sjeff{ 146219820Sjeff 147219820Sjeff return kobj->name; 148219820Sjeff} 149219820Sjeff 150219820Sjeffint kobject_set_name(struct kobject *kobj, const char *fmt, ...); 151292987Shselaskyint kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype, 152219820Sjeff struct kobject *parent, const char *fmt, ...); 153219820Sjeff 154219820Sjeff#endif /* _LINUX_KOBJECT_H_ */ 155