Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
7b96953b KW |
2 | /* |
3 | * Mediated device definition | |
4 | * | |
5 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | |
6 | * Author: Neo Jia <cjia@nvidia.com> | |
7 | * Kirti Wankhede <kwankhede@nvidia.com> | |
7b96953b KW |
8 | */ |
9 | ||
10 | #ifndef MDEV_H | |
11 | #define MDEV_H | |
12 | ||
bdef2b78 CH |
13 | #include <linux/device.h> |
14 | #include <linux/uuid.h> | |
15 | ||
417fd5bf JG |
16 | struct mdev_type; |
17 | ||
2a3d15f2 JG |
18 | struct mdev_device { |
19 | struct device dev; | |
2a3d15f2 | 20 | guid_t uuid; |
2a3d15f2 | 21 | struct list_head next; |
417fd5bf | 22 | struct mdev_type *type; |
2a3d15f2 JG |
23 | bool active; |
24 | }; | |
25 | ||
da44c340 CH |
26 | struct mdev_type { |
27 | /* set by the driver before calling mdev_register parent: */ | |
28 | const char *sysfs_name; | |
0bc79069 | 29 | const char *pretty_name; |
da44c340 CH |
30 | |
31 | /* set by the core, can be used drivers */ | |
32 | struct mdev_parent *parent; | |
33 | ||
34 | /* internal only */ | |
35 | struct kobject kobj; | |
36 | struct kobject *devices_kobj; | |
37 | }; | |
38 | ||
89345d51 CH |
39 | /* embedded into the struct device that the mdev devices hang off */ |
40 | struct mdev_parent { | |
41 | struct device *dev; | |
42 | struct mdev_driver *mdev_driver; | |
43 | struct kset *mdev_types_kset; | |
89345d51 CH |
44 | /* Synchronize device creation/removal with parent unregistration */ |
45 | struct rw_semaphore unreg_sem; | |
da44c340 CH |
46 | struct mdev_type **types; |
47 | unsigned int nr_types; | |
89345d51 CH |
48 | }; |
49 | ||
2a3d15f2 JG |
50 | static inline struct mdev_device *to_mdev_device(struct device *dev) |
51 | { | |
52 | return container_of(dev, struct mdev_device, dev); | |
53 | } | |
7b96953b | 54 | |
7b96953b KW |
55 | /** |
56 | * struct mdev_driver - Mediated device driver | |
290aac5d | 57 | * @device_api: string to return for the device_api sysfs |
7b96953b KW |
58 | * @probe: called when new device created |
59 | * @remove: called when device removed | |
f2fbc72e | 60 | * @get_available: Return the max number of instances that can be created |
685a1537 | 61 | * @show_description: Print a description of the mtype |
7b96953b | 62 | * @driver: device driver structure |
7b96953b KW |
63 | **/ |
64 | struct mdev_driver { | |
290aac5d | 65 | const char *device_api; |
2a3d15f2 JG |
66 | int (*probe)(struct mdev_device *dev); |
67 | void (*remove)(struct mdev_device *dev); | |
f2fbc72e | 68 | unsigned int (*get_available)(struct mdev_type *mtype); |
685a1537 | 69 | ssize_t (*show_description)(struct mdev_type *mtype, char *buf); |
7b96953b KW |
70 | struct device_driver driver; |
71 | }; | |
72 | ||
89345d51 | 73 | int mdev_register_parent(struct mdev_parent *parent, struct device *dev, |
da44c340 CH |
74 | struct mdev_driver *mdev_driver, struct mdev_type **types, |
75 | unsigned int nr_types); | |
89345d51 | 76 | void mdev_unregister_parent(struct mdev_parent *parent); |
7b96953b | 77 | |
91b9969d | 78 | int mdev_register_driver(struct mdev_driver *drv); |
50732af3 | 79 | void mdev_unregister_driver(struct mdev_driver *drv); |
7b96953b | 80 | |
2a3d15f2 JG |
81 | static inline struct device *mdev_dev(struct mdev_device *mdev) |
82 | { | |
83 | return &mdev->dev; | |
84 | } | |
9372e6fe | 85 | |
7b96953b | 86 | #endif /* MDEV_H */ |