diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:49:45 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:49:45 +0000 |
commit | 2c3c1048746a4622d8c89a29670120dc8fab93c4 (patch) | |
tree | 848558de17fb3008cdf4d861b01ac7781903ce39 /include/linux/mdev.h | |
parent | Initial commit. (diff) | |
download | linux-2c3c1048746a4622d8c89a29670120dc8fab93c4.tar.xz linux-2c3c1048746a4622d8c89a29670120dc8fab93c4.zip |
Adding upstream version 6.1.76.upstream/6.1.76upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/linux/mdev.h')
-rw-r--r-- | include/linux/mdev.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/include/linux/mdev.h b/include/linux/mdev.h new file mode 100644 index 000000000..139d05b26 --- /dev/null +++ b/include/linux/mdev.h @@ -0,0 +1,89 @@ +/* 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 + +#include <linux/device.h> +#include <linux/uuid.h> + +struct mdev_type; + +struct mdev_device { + struct device dev; + guid_t uuid; + struct list_head next; + struct mdev_type *type; + bool active; +}; + +struct mdev_type { + /* set by the driver before calling mdev_register parent: */ + const char *sysfs_name; + const char *pretty_name; + + /* set by the core, can be used drivers */ + struct mdev_parent *parent; + + /* internal only */ + struct kobject kobj; + struct kobject *devices_kobj; +}; + +/* embedded into the struct device that the mdev devices hang off */ +struct mdev_parent { + struct device *dev; + struct mdev_driver *mdev_driver; + struct kset *mdev_types_kset; + /* Synchronize device creation/removal with parent unregistration */ + struct rw_semaphore unreg_sem; + struct mdev_type **types; + unsigned int nr_types; + atomic_t available_instances; +}; + +static inline struct mdev_device *to_mdev_device(struct device *dev) +{ + return container_of(dev, struct mdev_device, dev); +} + +/** + * struct mdev_driver - Mediated device driver + * @device_api: string to return for the device_api sysfs + * @max_instances: maximum number of instances supported (optional) + * @probe: called when new device created + * @remove: called when device removed + * @get_available: Return the max number of instances that can be created + * @show_description: Print a description of the mtype + * @driver: device driver structure + **/ +struct mdev_driver { + const char *device_api; + unsigned int max_instances; + int (*probe)(struct mdev_device *dev); + void (*remove)(struct mdev_device *dev); + unsigned int (*get_available)(struct mdev_type *mtype); + ssize_t (*show_description)(struct mdev_type *mtype, char *buf); + struct device_driver driver; +}; + +int mdev_register_parent(struct mdev_parent *parent, struct device *dev, + struct mdev_driver *mdev_driver, struct mdev_type **types, + unsigned int nr_types); +void mdev_unregister_parent(struct mdev_parent *parent); + +int mdev_register_driver(struct mdev_driver *drv); +void mdev_unregister_driver(struct mdev_driver *drv); + +static inline struct device *mdev_dev(struct mdev_device *mdev) +{ + return &mdev->dev; +} + +#endif /* MDEV_H */ |