device.h revision 331756
1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5299674Shselasky * Copyright (c) 2013-2016 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/device.h 331756 2018-03-30 02:04:46Z emaste $ 30219820Sjeff */ 31219820Sjeff#ifndef _LINUX_DEVICE_H_ 32219820Sjeff#define _LINUX_DEVICE_H_ 33219820Sjeff 34299933Shselasky#include <linux/err.h> 35219820Sjeff#include <linux/types.h> 36219820Sjeff#include <linux/kobject.h> 37290335Shselasky#include <linux/sysfs.h> 38219820Sjeff#include <linux/list.h> 39219820Sjeff#include <linux/compiler.h> 40219820Sjeff#include <linux/types.h> 41219820Sjeff#include <linux/module.h> 42219820Sjeff#include <linux/workqueue.h> 43219820Sjeff#include <linux/sysfs.h> 44219820Sjeff#include <linux/kdev_t.h> 45219820Sjeff#include <asm/atomic.h> 46219820Sjeff 47219820Sjeff#include <sys/bus.h> 48219820Sjeff 49328653Shselaskystruct device; 50328653Shselaskystruct fwnode_handle; 51328653Shselasky 52219820Sjeffstruct class { 53219820Sjeff const char *name; 54219820Sjeff struct module *owner; 55219820Sjeff struct kobject kobj; 56219820Sjeff devclass_t bsdclass; 57328653Shselasky const struct dev_pm_ops *pm; 58219820Sjeff void (*class_release)(struct class *class); 59219820Sjeff void (*dev_release)(struct device *dev); 60270710Shselasky char * (*devnode)(struct device *dev, umode_t *mode); 61219820Sjeff}; 62219820Sjeff 63328653Shselaskystruct dev_pm_ops { 64328653Shselasky int (*suspend)(struct device *dev); 65328653Shselasky int (*suspend_late)(struct device *dev); 66328653Shselasky int (*resume)(struct device *dev); 67328653Shselasky int (*resume_early)(struct device *dev); 68328653Shselasky int (*freeze)(struct device *dev); 69328653Shselasky int (*freeze_late)(struct device *dev); 70328653Shselasky int (*thaw)(struct device *dev); 71328653Shselasky int (*thaw_early)(struct device *dev); 72328653Shselasky int (*poweroff)(struct device *dev); 73328653Shselasky int (*poweroff_late)(struct device *dev); 74328653Shselasky int (*restore)(struct device *dev); 75328653Shselasky int (*restore_early)(struct device *dev); 76328653Shselasky int (*runtime_suspend)(struct device *dev); 77328653Shselasky int (*runtime_resume)(struct device *dev); 78328653Shselasky int (*runtime_idle)(struct device *dev); 79328653Shselasky}; 80328653Shselasky 81328653Shselaskystruct device_driver { 82328653Shselasky const char *name; 83328653Shselasky const struct dev_pm_ops *pm; 84328653Shselasky}; 85328653Shselasky 86328653Shselaskystruct device_type { 87328653Shselasky const char *name; 88328653Shselasky}; 89328653Shselasky 90219820Sjeffstruct device { 91219820Sjeff struct device *parent; 92219820Sjeff struct list_head irqents; 93219820Sjeff device_t bsddev; 94311801Shselasky /* 95311801Shselasky * The following flag is used to determine if the LinuxKPI is 96311801Shselasky * responsible for detaching the BSD device or not. If the 97311801Shselasky * LinuxKPI got the BSD device using devclass_get_device(), it 98311801Shselasky * must not try to detach or delete it, because it's already 99311801Shselasky * done somewhere else. 100311801Shselasky */ 101311801Shselasky bool bsddev_attached_here; 102328653Shselasky struct device_driver *driver; 103328653Shselasky struct device_type *type; 104219820Sjeff dev_t devt; 105219820Sjeff struct class *class; 106219820Sjeff void (*release)(struct device *dev); 107219820Sjeff struct kobject kobj; 108219820Sjeff uint64_t *dma_mask; 109219820Sjeff void *driver_data; 110219820Sjeff unsigned int irq; 111310246Shselasky#define LINUX_IRQ_INVALID 65535 112219820Sjeff unsigned int msix; 113219820Sjeff unsigned int msix_max; 114299933Shselasky const struct attribute_group **groups; 115328653Shselasky struct fwnode_handle *fwnode; 116328653Shselasky 117328653Shselasky spinlock_t devres_lock; 118328653Shselasky struct list_head devres_head; 119219820Sjeff}; 120219820Sjeff 121292987Shselaskyextern struct device linux_root_device; 122292987Shselaskyextern struct kobject linux_class_root; 123292987Shselaskyextern const struct kobj_type linux_dev_ktype; 124292987Shselaskyextern const struct kobj_type linux_class_ktype; 125219820Sjeff 126219820Sjeffstruct class_attribute { 127331756Semaste struct attribute attr; 128331756Semaste ssize_t (*show)(struct class *, struct class_attribute *, char *); 129331756Semaste ssize_t (*store)(struct class *, struct class_attribute *, const char *, size_t); 130331756Semaste const void *(*namespace)(struct class *, const struct class_attribute *); 131219820Sjeff}; 132270710Shselasky 133219820Sjeff#define CLASS_ATTR(_name, _mode, _show, _store) \ 134219820Sjeff struct class_attribute class_attr_##_name = \ 135219820Sjeff { { #_name, NULL, _mode }, _show, _store } 136219820Sjeff 137219820Sjeffstruct device_attribute { 138219820Sjeff struct attribute attr; 139219820Sjeff ssize_t (*show)(struct device *, 140270710Shselasky struct device_attribute *, char *); 141219820Sjeff ssize_t (*store)(struct device *, 142270710Shselasky struct device_attribute *, const char *, 143270710Shselasky size_t); 144219820Sjeff}; 145219820Sjeff 146219820Sjeff#define DEVICE_ATTR(_name, _mode, _show, _store) \ 147219820Sjeff struct device_attribute dev_attr_##_name = \ 148328653Shselasky __ATTR(_name, _mode, _show, _store) 149328653Shselasky#define DEVICE_ATTR_RO(_name) \ 150328653Shselasky struct device_attribute dev_attr_##_name = __ATTR_RO(_name) 151328653Shselasky#define DEVICE_ATTR_WO(_name) \ 152328653Shselasky struct device_attribute dev_attr_##_name = __ATTR_WO(_name) 153328653Shselasky#define DEVICE_ATTR_RW(_name) \ 154328653Shselasky struct device_attribute dev_attr_##_name = __ATTR_RW(_name) 155219820Sjeff 156270710Shselasky/* Simple class attribute that is just a static string */ 157270710Shselaskystruct class_attribute_string { 158270710Shselasky struct class_attribute attr; 159270710Shselasky char *str; 160270710Shselasky}; 161270710Shselasky 162270710Shselaskystatic inline ssize_t 163270710Shselaskyshow_class_attr_string(struct class *class, 164270710Shselasky struct class_attribute *attr, char *buf) 165270710Shselasky{ 166270710Shselasky struct class_attribute_string *cs; 167270710Shselasky cs = container_of(attr, struct class_attribute_string, attr); 168270710Shselasky return snprintf(buf, PAGE_SIZE, "%s\n", cs->str); 169270710Shselasky} 170270710Shselasky 171270710Shselasky/* Currently read-only only */ 172270710Shselasky#define _CLASS_ATTR_STRING(_name, _mode, _str) \ 173270710Shselasky { __ATTR(_name, _mode, show_class_attr_string, NULL), _str } 174270710Shselasky#define CLASS_ATTR_STRING(_name, _mode, _str) \ 175270710Shselasky struct class_attribute_string class_attr_##_name = \ 176270710Shselasky _CLASS_ATTR_STRING(_name, _mode, _str) 177270710Shselasky 178219820Sjeff#define dev_err(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) 179219820Sjeff#define dev_warn(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) 180219820Sjeff#define dev_info(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) 181299933Shselasky#define dev_notice(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) 182328653Shselasky#define dev_dbg(dev, fmt, ...) do { } while (0) 183219820Sjeff#define dev_printk(lvl, dev, fmt, ...) \ 184219820Sjeff device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) 185219820Sjeff 186328653Shselasky#define dev_err_ratelimited(dev, ...) do { \ 187328653Shselasky static linux_ratelimit_t __ratelimited; \ 188328653Shselasky if (linux_ratelimited(&__ratelimited)) \ 189328653Shselasky dev_err(dev, __VA_ARGS__); \ 190328653Shselasky} while (0) 191328653Shselasky 192328653Shselasky#define dev_warn_ratelimited(dev, ...) do { \ 193328653Shselasky static linux_ratelimit_t __ratelimited; \ 194328653Shselasky if (linux_ratelimited(&__ratelimited)) \ 195328653Shselasky dev_warn(dev, __VA_ARGS__); \ 196328653Shselasky} while (0) 197328653Shselasky 198219820Sjeffstatic inline void * 199299933Shselaskydev_get_drvdata(const struct device *dev) 200219820Sjeff{ 201219820Sjeff 202219820Sjeff return dev->driver_data; 203219820Sjeff} 204219820Sjeff 205219820Sjeffstatic inline void 206219820Sjeffdev_set_drvdata(struct device *dev, void *data) 207219820Sjeff{ 208219820Sjeff 209219820Sjeff dev->driver_data = data; 210219820Sjeff} 211219820Sjeff 212219820Sjeffstatic inline struct device * 213219820Sjeffget_device(struct device *dev) 214219820Sjeff{ 215219820Sjeff 216219820Sjeff if (dev) 217219820Sjeff kobject_get(&dev->kobj); 218219820Sjeff 219219820Sjeff return (dev); 220219820Sjeff} 221219820Sjeff 222219820Sjeffstatic inline char * 223219820Sjeffdev_name(const struct device *dev) 224219820Sjeff{ 225219820Sjeff 226331756Semaste return kobject_name(&dev->kobj); 227219820Sjeff} 228219820Sjeff 229219820Sjeff#define dev_set_name(_dev, _fmt, ...) \ 230219820Sjeff kobject_set_name(&(_dev)->kobj, (_fmt), ##__VA_ARGS__) 231219820Sjeff 232219820Sjeffstatic inline void 233219820Sjeffput_device(struct device *dev) 234219820Sjeff{ 235219820Sjeff 236219820Sjeff if (dev) 237219820Sjeff kobject_put(&dev->kobj); 238219820Sjeff} 239219820Sjeff 240219820Sjeffstatic inline int 241219820Sjeffclass_register(struct class *class) 242219820Sjeff{ 243219820Sjeff 244219820Sjeff class->bsdclass = devclass_create(class->name); 245292987Shselasky kobject_init(&class->kobj, &linux_class_ktype); 246219820Sjeff kobject_set_name(&class->kobj, class->name); 247292987Shselasky kobject_add(&class->kobj, &linux_class_root, class->name); 248219820Sjeff 249219820Sjeff return (0); 250219820Sjeff} 251219820Sjeff 252219820Sjeffstatic inline void 253219820Sjeffclass_unregister(struct class *class) 254219820Sjeff{ 255219820Sjeff 256219820Sjeff kobject_put(&class->kobj); 257219820Sjeff} 258219820Sjeff 259299933Shselaskystatic inline struct device *kobj_to_dev(struct kobject *kobj) 260299933Shselasky{ 261299933Shselasky return container_of(kobj, struct device, kobj); 262299933Shselasky} 263299933Shselasky 264219820Sjeff/* 265299933Shselasky * Devices are registered and created for exporting to sysfs. Create 266219820Sjeff * implies register and register assumes the device fields have been 267219820Sjeff * setup appropriately before being called. 268219820Sjeff */ 269299933Shselaskystatic inline void 270299933Shselaskydevice_initialize(struct device *dev) 271299933Shselasky{ 272311801Shselasky device_t bsddev = NULL; 273311801Shselasky int unit = -1; 274299933Shselasky 275299933Shselasky if (dev->devt) { 276311801Shselasky unit = MINOR(dev->devt); 277299933Shselasky bsddev = devclass_get_device(dev->class->bsdclass, unit); 278311801Shselasky dev->bsddev_attached_here = false; 279311801Shselasky } else if (dev->parent == NULL) { 280311801Shselasky bsddev = devclass_get_device(dev->class->bsdclass, 0); 281311801Shselasky dev->bsddev_attached_here = false; 282311801Shselasky } else { 283311801Shselasky dev->bsddev_attached_here = true; 284299933Shselasky } 285311801Shselasky 286311801Shselasky if (bsddev == NULL && dev->parent != NULL) { 287311801Shselasky bsddev = device_add_child(dev->parent->bsddev, 288311801Shselasky dev->class->kobj.name, unit); 289311801Shselasky } 290311801Shselasky 291299933Shselasky if (bsddev != NULL) 292299933Shselasky device_set_softc(bsddev, dev); 293299933Shselasky 294299933Shselasky dev->bsddev = bsddev; 295311801Shselasky MPASS(dev->bsddev != NULL); 296299933Shselasky kobject_init(&dev->kobj, &linux_dev_ktype); 297328653Shselasky 298328653Shselasky spin_lock_init(&dev->devres_lock); 299328653Shselasky INIT_LIST_HEAD(&dev->devres_head); 300299933Shselasky} 301299933Shselasky 302219820Sjeffstatic inline int 303299933Shselaskydevice_add(struct device *dev) 304311801Shselasky{ 305299933Shselasky if (dev->bsddev != NULL) { 306299933Shselasky if (dev->devt == 0) 307299933Shselasky dev->devt = makedev(0, device_get_unit(dev->bsddev)); 308299933Shselasky } 309299933Shselasky kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev)); 310299933Shselasky return (0); 311299933Shselasky} 312299933Shselasky 313299933Shselaskystatic inline void 314299933Shselaskydevice_create_release(struct device *dev) 315299933Shselasky{ 316299933Shselasky kfree(dev); 317299933Shselasky} 318299933Shselasky 319299933Shselaskystatic inline struct device * 320299933Shselaskydevice_create_groups_vargs(struct class *class, struct device *parent, 321299933Shselasky dev_t devt, void *drvdata, const struct attribute_group **groups, 322299933Shselasky const char *fmt, va_list args) 323299933Shselasky{ 324299933Shselasky struct device *dev = NULL; 325299933Shselasky int retval = -ENODEV; 326299933Shselasky 327299933Shselasky if (class == NULL || IS_ERR(class)) 328299933Shselasky goto error; 329299933Shselasky 330299933Shselasky dev = kzalloc(sizeof(*dev), GFP_KERNEL); 331299933Shselasky if (!dev) { 332299933Shselasky retval = -ENOMEM; 333299933Shselasky goto error; 334299933Shselasky } 335299933Shselasky 336299933Shselasky dev->devt = devt; 337299933Shselasky dev->class = class; 338299933Shselasky dev->parent = parent; 339299933Shselasky dev->groups = groups; 340299933Shselasky dev->release = device_create_release; 341311801Shselasky /* device_initialize() needs the class and parent to be set */ 342311801Shselasky device_initialize(dev); 343299933Shselasky dev_set_drvdata(dev, drvdata); 344299933Shselasky 345299933Shselasky retval = kobject_set_name_vargs(&dev->kobj, fmt, args); 346299933Shselasky if (retval) 347299933Shselasky goto error; 348299933Shselasky 349299933Shselasky retval = device_add(dev); 350299933Shselasky if (retval) 351299933Shselasky goto error; 352299933Shselasky 353299933Shselasky return dev; 354299933Shselasky 355299933Shselaskyerror: 356299933Shselasky put_device(dev); 357299933Shselasky return ERR_PTR(retval); 358299933Shselasky} 359299933Shselasky 360299933Shselaskystatic inline struct device * 361299933Shselaskydevice_create_with_groups(struct class *class, 362299933Shselasky struct device *parent, dev_t devt, void *drvdata, 363299933Shselasky const struct attribute_group **groups, const char *fmt, ...) 364299933Shselasky{ 365299933Shselasky va_list vargs; 366299933Shselasky struct device *dev; 367299933Shselasky 368299933Shselasky va_start(vargs, fmt); 369299933Shselasky dev = device_create_groups_vargs(class, parent, devt, drvdata, 370299933Shselasky groups, fmt, vargs); 371299933Shselasky va_end(vargs); 372299933Shselasky return dev; 373299933Shselasky} 374299933Shselasky 375328653Shselaskystatic inline bool 376328653Shselaskydevice_is_registered(struct device *dev) 377328653Shselasky{ 378328653Shselasky 379328653Shselasky return (dev->bsddev != NULL); 380328653Shselasky} 381328653Shselasky 382299933Shselaskystatic inline int 383219820Sjeffdevice_register(struct device *dev) 384219820Sjeff{ 385311801Shselasky device_t bsddev = NULL; 386311801Shselasky int unit = -1; 387219820Sjeff 388328653Shselasky if (device_is_registered(dev)) 389311801Shselasky goto done; 390299674Shselasky 391219820Sjeff if (dev->devt) { 392219820Sjeff unit = MINOR(dev->devt); 393219820Sjeff bsddev = devclass_get_device(dev->class->bsdclass, unit); 394311801Shselasky dev->bsddev_attached_here = false; 395299674Shselasky } else if (dev->parent == NULL) { 396299674Shselasky bsddev = devclass_get_device(dev->class->bsdclass, 0); 397311801Shselasky dev->bsddev_attached_here = false; 398311801Shselasky } else { 399311801Shselasky dev->bsddev_attached_here = true; 400299674Shselasky } 401299931Shselasky if (bsddev == NULL && dev->parent != NULL) { 402219820Sjeff bsddev = device_add_child(dev->parent->bsddev, 403219820Sjeff dev->class->kobj.name, unit); 404299931Shselasky } 405299931Shselasky if (bsddev != NULL) { 406219820Sjeff if (dev->devt == 0) 407219820Sjeff dev->devt = makedev(0, device_get_unit(bsddev)); 408219820Sjeff device_set_softc(bsddev, dev); 409219820Sjeff } 410219820Sjeff dev->bsddev = bsddev; 411311801Shselaskydone: 412292987Shselasky kobject_init(&dev->kobj, &linux_dev_ktype); 413219820Sjeff kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev)); 414219820Sjeff 415219820Sjeff return (0); 416219820Sjeff} 417219820Sjeff 418219820Sjeffstatic inline void 419219820Sjeffdevice_unregister(struct device *dev) 420219820Sjeff{ 421219820Sjeff device_t bsddev; 422219820Sjeff 423219820Sjeff bsddev = dev->bsddev; 424299933Shselasky dev->bsddev = NULL; 425299933Shselasky 426311801Shselasky if (bsddev != NULL && dev->bsddev_attached_here) { 427299960Shselasky mtx_lock(&Giant); 428219820Sjeff device_delete_child(device_get_parent(bsddev), bsddev); 429299960Shselasky mtx_unlock(&Giant); 430299960Shselasky } 431219820Sjeff put_device(dev); 432219820Sjeff} 433219820Sjeff 434299933Shselaskystatic inline void 435299933Shselaskydevice_del(struct device *dev) 436299933Shselasky{ 437299933Shselasky device_t bsddev; 438299933Shselasky 439299933Shselasky bsddev = dev->bsddev; 440299933Shselasky dev->bsddev = NULL; 441299933Shselasky 442311801Shselasky if (bsddev != NULL && dev->bsddev_attached_here) { 443299960Shselasky mtx_lock(&Giant); 444299933Shselasky device_delete_child(device_get_parent(bsddev), bsddev); 445299960Shselasky mtx_unlock(&Giant); 446299960Shselasky } 447299933Shselasky} 448299933Shselasky 449219820Sjeffstruct device *device_create(struct class *class, struct device *parent, 450219820Sjeff dev_t devt, void *drvdata, const char *fmt, ...); 451219820Sjeff 452219820Sjeffstatic inline void 453219820Sjeffdevice_destroy(struct class *class, dev_t devt) 454219820Sjeff{ 455219820Sjeff device_t bsddev; 456219820Sjeff int unit; 457219820Sjeff 458219820Sjeff unit = MINOR(devt); 459219820Sjeff bsddev = devclass_get_device(class->bsdclass, unit); 460299933Shselasky if (bsddev != NULL) 461219820Sjeff device_unregister(device_get_softc(bsddev)); 462219820Sjeff} 463219820Sjeff 464219820Sjeffstatic inline void 465292987Shselaskylinux_class_kfree(struct class *class) 466219820Sjeff{ 467219820Sjeff 468219820Sjeff kfree(class); 469219820Sjeff} 470219820Sjeff 471219820Sjeffstatic inline struct class * 472219820Sjeffclass_create(struct module *owner, const char *name) 473219820Sjeff{ 474219820Sjeff struct class *class; 475219820Sjeff int error; 476219820Sjeff 477219820Sjeff class = kzalloc(sizeof(*class), M_WAITOK); 478219820Sjeff class->owner = owner; 479328653Shselasky class->name = name; 480292987Shselasky class->class_release = linux_class_kfree; 481219820Sjeff error = class_register(class); 482219820Sjeff if (error) { 483219820Sjeff kfree(class); 484219820Sjeff return (NULL); 485219820Sjeff } 486219820Sjeff 487219820Sjeff return (class); 488219820Sjeff} 489219820Sjeff 490219820Sjeffstatic inline void 491219820Sjeffclass_destroy(struct class *class) 492219820Sjeff{ 493219820Sjeff 494219820Sjeff if (class == NULL) 495219820Sjeff return; 496219820Sjeff class_unregister(class); 497219820Sjeff} 498219820Sjeff 499219820Sjeffstatic inline int 500219820Sjeffdevice_create_file(struct device *dev, const struct device_attribute *attr) 501219820Sjeff{ 502219820Sjeff 503219820Sjeff if (dev) 504219820Sjeff return sysfs_create_file(&dev->kobj, &attr->attr); 505219820Sjeff return -EINVAL; 506219820Sjeff} 507219820Sjeff 508219820Sjeffstatic inline void 509219820Sjeffdevice_remove_file(struct device *dev, const struct device_attribute *attr) 510219820Sjeff{ 511219820Sjeff 512219820Sjeff if (dev) 513219820Sjeff sysfs_remove_file(&dev->kobj, &attr->attr); 514219820Sjeff} 515219820Sjeff 516219820Sjeffstatic inline int 517219820Sjeffclass_create_file(struct class *class, const struct class_attribute *attr) 518219820Sjeff{ 519219820Sjeff 520219820Sjeff if (class) 521219820Sjeff return sysfs_create_file(&class->kobj, &attr->attr); 522219820Sjeff return -EINVAL; 523219820Sjeff} 524219820Sjeff 525219820Sjeffstatic inline void 526219820Sjeffclass_remove_file(struct class *class, const struct class_attribute *attr) 527219820Sjeff{ 528219820Sjeff 529219820Sjeff if (class) 530219820Sjeff sysfs_remove_file(&class->kobj, &attr->attr); 531219820Sjeff} 532219820Sjeff 533292987Shselaskystatic inline int 534292987Shselaskydev_to_node(struct device *dev) 535255932Salfred{ 536331756Semaste return -1; 537255932Salfred} 538255932Salfred 539285088Shselaskychar *kvasprintf(gfp_t, const char *, va_list); 540278865Shselaskychar *kasprintf(gfp_t, const char *, ...); 541270710Shselasky 542219820Sjeff#endif /* _LINUX_DEVICE_H_ */ 543