cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

mdev.h (2663B)


      1/* SPDX-License-Identifier: GPL-2.0-only */
      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>
      8 */
      9
     10#ifndef MDEV_H
     11#define MDEV_H
     12
     13struct mdev_type;
     14
     15struct mdev_device {
     16	struct device dev;
     17	guid_t uuid;
     18	struct list_head next;
     19	struct mdev_type *type;
     20	bool active;
     21};
     22
     23static inline struct mdev_device *to_mdev_device(struct device *dev)
     24{
     25	return container_of(dev, struct mdev_device, dev);
     26}
     27
     28unsigned int mdev_get_type_group_id(struct mdev_device *mdev);
     29unsigned int mtype_get_type_group_id(struct mdev_type *mtype);
     30struct device *mtype_get_parent_dev(struct mdev_type *mtype);
     31
     32/* interface for exporting mdev supported type attributes */
     33struct mdev_type_attribute {
     34	struct attribute attr;
     35	ssize_t (*show)(struct mdev_type *mtype,
     36			struct mdev_type_attribute *attr, char *buf);
     37	ssize_t (*store)(struct mdev_type *mtype,
     38			 struct mdev_type_attribute *attr, const char *buf,
     39			 size_t count);
     40};
     41
     42#define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
     43struct mdev_type_attribute mdev_type_attr_##_name =		\
     44	__ATTR(_name, _mode, _show, _store)
     45#define MDEV_TYPE_ATTR_RW(_name) \
     46	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
     47#define MDEV_TYPE_ATTR_RO(_name) \
     48	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
     49#define MDEV_TYPE_ATTR_WO(_name) \
     50	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
     51
     52/**
     53 * struct mdev_driver - Mediated device driver
     54 * @probe: called when new device created
     55 * @remove: called when device removed
     56 * @supported_type_groups: Attributes to define supported types. It is mandatory
     57 *			to provide supported types.
     58 * @driver: device driver structure
     59 *
     60 **/
     61struct mdev_driver {
     62	int (*probe)(struct mdev_device *dev);
     63	void (*remove)(struct mdev_device *dev);
     64	struct attribute_group **supported_type_groups;
     65	struct device_driver driver;
     66};
     67
     68static inline const guid_t *mdev_uuid(struct mdev_device *mdev)
     69{
     70	return &mdev->uuid;
     71}
     72
     73extern struct bus_type mdev_bus_type;
     74
     75int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver);
     76void mdev_unregister_device(struct device *dev);
     77
     78int mdev_register_driver(struct mdev_driver *drv);
     79void mdev_unregister_driver(struct mdev_driver *drv);
     80
     81struct device *mdev_parent_dev(struct mdev_device *mdev);
     82static inline struct device *mdev_dev(struct mdev_device *mdev)
     83{
     84	return &mdev->dev;
     85}
     86static inline struct mdev_device *mdev_from_dev(struct device *dev)
     87{
     88	return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL;
     89}
     90
     91#endif /* MDEV_H */