mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
![Jason Gunthorpe](/assets/img/avatar_default.png)
This is only used by one sample to print a fixed string that is pointless. In general, having a device driver attach sysfs attributes to the parent is horrific. This should never happen, and always leads to some kind of liftime bug as it become very difficult for the sysfs attribute to go back to any data owned by the device driver. Remove the general mechanism to create this abuse. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Zhi Wang <zhi.a.wang@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-32-hch@lst.de Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com> Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>
117 lines
3.4 KiB
C
117 lines
3.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Mediated device definition
|
|
*
|
|
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
|
* Author: Neo Jia <cjia@nvidia.com>
|
|
* Kirti Wankhede <kwankhede@nvidia.com>
|
|
*/
|
|
|
|
#ifndef MDEV_H
|
|
#define MDEV_H
|
|
|
|
struct mdev_type;
|
|
|
|
struct mdev_device {
|
|
struct device dev;
|
|
guid_t uuid;
|
|
void *driver_data;
|
|
struct list_head next;
|
|
struct mdev_type *type;
|
|
bool active;
|
|
};
|
|
|
|
static inline struct mdev_device *to_mdev_device(struct device *dev)
|
|
{
|
|
return container_of(dev, struct mdev_device, dev);
|
|
}
|
|
|
|
unsigned int mdev_get_type_group_id(struct mdev_device *mdev);
|
|
unsigned int mtype_get_type_group_id(struct mdev_type *mtype);
|
|
struct device *mtype_get_parent_dev(struct mdev_type *mtype);
|
|
|
|
/**
|
|
* struct mdev_parent_ops - Structure to be registered for each parent device to
|
|
* register the device to mdev module.
|
|
*
|
|
* @owner: The module owner.
|
|
* @device_driver: Which device driver to probe() on newly created devices
|
|
* @mdev_attr_groups: Attributes of the mediated device.
|
|
* @supported_type_groups: Attributes to define supported types. It is mandatory
|
|
* to provide supported types.
|
|
*
|
|
* Parent device that support mediated device should be registered with mdev
|
|
* module with mdev_parent_ops structure.
|
|
**/
|
|
struct mdev_parent_ops {
|
|
struct module *owner;
|
|
struct mdev_driver *device_driver;
|
|
const struct attribute_group **mdev_attr_groups;
|
|
struct attribute_group **supported_type_groups;
|
|
};
|
|
|
|
/* interface for exporting mdev supported type attributes */
|
|
struct mdev_type_attribute {
|
|
struct attribute attr;
|
|
ssize_t (*show)(struct mdev_type *mtype,
|
|
struct mdev_type_attribute *attr, char *buf);
|
|
ssize_t (*store)(struct mdev_type *mtype,
|
|
struct mdev_type_attribute *attr, const char *buf,
|
|
size_t count);
|
|
};
|
|
|
|
#define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \
|
|
struct mdev_type_attribute mdev_type_attr_##_name = \
|
|
__ATTR(_name, _mode, _show, _store)
|
|
#define MDEV_TYPE_ATTR_RW(_name) \
|
|
struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
|
|
#define MDEV_TYPE_ATTR_RO(_name) \
|
|
struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
|
|
#define MDEV_TYPE_ATTR_WO(_name) \
|
|
struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
|
|
|
|
/**
|
|
* struct mdev_driver - Mediated device driver
|
|
* @probe: called when new device created
|
|
* @remove: called when device removed
|
|
* @driver: device driver structure
|
|
*
|
|
**/
|
|
struct mdev_driver {
|
|
int (*probe)(struct mdev_device *dev);
|
|
void (*remove)(struct mdev_device *dev);
|
|
struct device_driver driver;
|
|
};
|
|
|
|
static inline void *mdev_get_drvdata(struct mdev_device *mdev)
|
|
{
|
|
return mdev->driver_data;
|
|
}
|
|
static inline void mdev_set_drvdata(struct mdev_device *mdev, void *data)
|
|
{
|
|
mdev->driver_data = data;
|
|
}
|
|
static inline const guid_t *mdev_uuid(struct mdev_device *mdev)
|
|
{
|
|
return &mdev->uuid;
|
|
}
|
|
|
|
extern struct bus_type mdev_bus_type;
|
|
|
|
int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
|
|
void mdev_unregister_device(struct device *dev);
|
|
|
|
int mdev_register_driver(struct mdev_driver *drv);
|
|
void mdev_unregister_driver(struct mdev_driver *drv);
|
|
|
|
struct device *mdev_parent_dev(struct mdev_device *mdev);
|
|
static inline struct device *mdev_dev(struct mdev_device *mdev)
|
|
{
|
|
return &mdev->dev;
|
|
}
|
|
static inline struct mdev_device *mdev_from_dev(struct device *dev)
|
|
{
|
|
return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL;
|
|
}
|
|
|
|
#endif /* MDEV_H */
|