2019-06-04 08:11:33 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2016-11-16 20:46:13 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2022-09-23 09:26:41 +00:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/uuid.h>
|
|
|
|
|
2021-04-06 19:40:28 +00:00
|
|
|
struct mdev_type;
|
|
|
|
|
2021-04-06 19:40:26 +00:00
|
|
|
struct mdev_device {
|
|
|
|
struct device dev;
|
|
|
|
guid_t uuid;
|
|
|
|
struct list_head next;
|
2021-04-06 19:40:28 +00:00
|
|
|
struct mdev_type *type;
|
2021-04-06 19:40:26 +00:00
|
|
|
bool active;
|
|
|
|
};
|
|
|
|
|
2022-09-23 09:26:43 +00:00
|
|
|
struct mdev_type {
|
|
|
|
/* set by the driver before calling mdev_register parent: */
|
|
|
|
const char *sysfs_name;
|
2022-09-23 09:26:49 +00:00
|
|
|
const char *pretty_name;
|
2022-09-23 09:26:43 +00:00
|
|
|
|
|
|
|
/* set by the core, can be used drivers */
|
|
|
|
struct mdev_parent *parent;
|
|
|
|
|
|
|
|
/* internal only */
|
|
|
|
struct kobject kobj;
|
|
|
|
struct kobject *devices_kobj;
|
|
|
|
};
|
|
|
|
|
2022-09-23 09:26:42 +00:00
|
|
|
/* 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;
|
2022-09-23 09:26:43 +00:00
|
|
|
struct mdev_type **types;
|
|
|
|
unsigned int nr_types;
|
2022-09-23 09:26:52 +00:00
|
|
|
atomic_t available_instances;
|
2022-09-23 09:26:42 +00:00
|
|
|
};
|
|
|
|
|
2021-04-06 19:40:26 +00:00
|
|
|
static inline struct mdev_device *to_mdev_device(struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct mdev_device, dev);
|
|
|
|
}
|
2016-11-16 20:46:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mdev_driver - Mediated device driver
|
2022-09-23 09:26:48 +00:00
|
|
|
* @device_api: string to return for the device_api sysfs
|
2022-09-23 09:26:52 +00:00
|
|
|
* @max_instances: maximum number of instances supported (optional)
|
2016-11-16 20:46:13 +00:00
|
|
|
* @probe: called when new device created
|
|
|
|
* @remove: called when device removed
|
2022-09-23 09:26:50 +00:00
|
|
|
* @get_available: Return the max number of instances that can be created
|
2022-09-23 09:26:51 +00:00
|
|
|
* @show_description: Print a description of the mtype
|
2016-11-16 20:46:13 +00:00
|
|
|
* @driver: device driver structure
|
|
|
|
**/
|
|
|
|
struct mdev_driver {
|
2022-09-23 09:26:48 +00:00
|
|
|
const char *device_api;
|
2022-09-23 09:26:52 +00:00
|
|
|
unsigned int max_instances;
|
2021-04-06 19:40:26 +00:00
|
|
|
int (*probe)(struct mdev_device *dev);
|
|
|
|
void (*remove)(struct mdev_device *dev);
|
2022-09-23 09:26:50 +00:00
|
|
|
unsigned int (*get_available)(struct mdev_type *mtype);
|
2022-09-23 09:26:51 +00:00
|
|
|
ssize_t (*show_description)(struct mdev_type *mtype, char *buf);
|
2016-11-16 20:46:13 +00:00
|
|
|
struct device_driver driver;
|
|
|
|
};
|
|
|
|
|
2022-09-23 09:26:42 +00:00
|
|
|
int mdev_register_parent(struct mdev_parent *parent, struct device *dev,
|
2022-09-23 09:26:43 +00:00
|
|
|
struct mdev_driver *mdev_driver, struct mdev_type **types,
|
|
|
|
unsigned int nr_types);
|
2022-09-23 09:26:42 +00:00
|
|
|
void mdev_unregister_parent(struct mdev_parent *parent);
|
2016-11-16 20:46:13 +00:00
|
|
|
|
2021-04-06 19:40:27 +00:00
|
|
|
int mdev_register_driver(struct mdev_driver *drv);
|
2019-04-30 22:49:30 +00:00
|
|
|
void mdev_unregister_driver(struct mdev_driver *drv);
|
2016-11-16 20:46:13 +00:00
|
|
|
|
2021-04-06 19:40:26 +00:00
|
|
|
static inline struct device *mdev_dev(struct mdev_device *mdev)
|
|
|
|
{
|
|
|
|
return &mdev->dev;
|
|
|
|
}
|
2016-12-30 15:13:41 +00:00
|
|
|
|
2016-11-16 20:46:13 +00:00
|
|
|
#endif /* MDEV_H */
|