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

gbphy.h (2946B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2/*
      3 * Greybus Bridged-Phy Bus driver
      4 *
      5 * Copyright 2016 Google Inc.
      6 */
      7
      8#ifndef __GBPHY_H
      9#define __GBPHY_H
     10
     11struct gbphy_device {
     12	u32 id;
     13	struct greybus_descriptor_cport *cport_desc;
     14	struct gb_bundle *bundle;
     15	struct list_head list;
     16	struct device dev;
     17};
     18#define to_gbphy_dev(d) container_of(d, struct gbphy_device, dev)
     19
     20static inline void *gb_gbphy_get_data(struct gbphy_device *gdev)
     21{
     22	return dev_get_drvdata(&gdev->dev);
     23}
     24
     25static inline void gb_gbphy_set_data(struct gbphy_device *gdev, void *data)
     26{
     27	dev_set_drvdata(&gdev->dev, data);
     28}
     29
     30struct gbphy_device_id {
     31	__u8 protocol_id;
     32};
     33
     34#define GBPHY_PROTOCOL(p)		\
     35	.protocol_id	= (p),
     36
     37struct gbphy_driver {
     38	const char *name;
     39	int (*probe)(struct gbphy_device *device,
     40		     const struct gbphy_device_id *id);
     41	void (*remove)(struct gbphy_device *device);
     42	const struct gbphy_device_id *id_table;
     43
     44	struct device_driver driver;
     45};
     46#define to_gbphy_driver(d) container_of(d, struct gbphy_driver, driver)
     47
     48int gb_gbphy_register_driver(struct gbphy_driver *driver,
     49			     struct module *owner, const char *mod_name);
     50void gb_gbphy_deregister_driver(struct gbphy_driver *driver);
     51
     52#define gb_gbphy_register(driver) \
     53	gb_gbphy_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
     54#define gb_gbphy_deregister(driver) \
     55	gb_gbphy_deregister_driver(driver)
     56
     57/**
     58 * module_gbphy_driver() - Helper macro for registering a gbphy driver
     59 * @__gbphy_driver: gbphy_driver structure
     60 *
     61 * Helper macro for gbphy drivers to set up proper module init / exit
     62 * functions.  Replaces module_init() and module_exit() and keeps people from
     63 * printing pointless things to the kernel log when their driver is loaded.
     64 */
     65#define module_gbphy_driver(__gbphy_driver)	\
     66	module_driver(__gbphy_driver, gb_gbphy_register, gb_gbphy_deregister)
     67
     68#ifdef CONFIG_PM
     69static inline int gbphy_runtime_get_sync(struct gbphy_device *gbphy_dev)
     70{
     71	struct device *dev = &gbphy_dev->dev;
     72	int ret;
     73
     74	ret = pm_runtime_get_sync(dev);
     75	if (ret < 0) {
     76		dev_err(dev, "pm_runtime_get_sync failed: %d\n", ret);
     77		pm_runtime_put_noidle(dev);
     78		return ret;
     79	}
     80
     81	return 0;
     82}
     83
     84static inline void gbphy_runtime_put_autosuspend(struct gbphy_device *gbphy_dev)
     85{
     86	struct device *dev = &gbphy_dev->dev;
     87
     88	pm_runtime_mark_last_busy(dev);
     89	pm_runtime_put_autosuspend(dev);
     90}
     91
     92static inline void gbphy_runtime_get_noresume(struct gbphy_device *gbphy_dev)
     93{
     94	pm_runtime_get_noresume(&gbphy_dev->dev);
     95}
     96
     97static inline void gbphy_runtime_put_noidle(struct gbphy_device *gbphy_dev)
     98{
     99	pm_runtime_put_noidle(&gbphy_dev->dev);
    100}
    101#else
    102static inline int gbphy_runtime_get_sync(struct gbphy_device *gbphy_dev) { return 0; }
    103static inline void gbphy_runtime_put_autosuspend(struct gbphy_device *gbphy_dev) {}
    104static inline void gbphy_runtime_get_noresume(struct gbphy_device *gbphy_dev) {}
    105static inline void gbphy_runtime_put_noidle(struct gbphy_device *gbphy_dev) {}
    106#endif
    107
    108#endif /* __GBPHY_H */
    109