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

sysfs.h (3218B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef __FIRMWARE_SYSFS_H
      3#define __FIRMWARE_SYSFS_H
      4
      5#include <linux/device.h>
      6
      7#include "firmware.h"
      8
      9MODULE_IMPORT_NS(FIRMWARE_LOADER_PRIVATE);
     10
     11extern struct firmware_fallback_config fw_fallback_config;
     12extern struct device_attribute dev_attr_loading;
     13
     14#ifdef CONFIG_FW_LOADER_USER_HELPER
     15/**
     16 * struct firmware_fallback_config - firmware fallback configuration settings
     17 *
     18 * Helps describe and fine tune the fallback mechanism.
     19 *
     20 * @force_sysfs_fallback: force the sysfs fallback mechanism to be used
     21 *	as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
     22 *	Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
     23 *	functionality on a kernel where that config entry has been disabled.
     24 * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
     25 *	This emulates the behaviour as if we had set the kernel
     26 *	config CONFIG_FW_LOADER_USER_HELPER=n.
     27 * @old_timeout: for internal use
     28 * @loading_timeout: the timeout to wait for the fallback mechanism before
     29 *	giving up, in seconds.
     30 */
     31struct firmware_fallback_config {
     32	unsigned int force_sysfs_fallback;
     33	unsigned int ignore_sysfs_fallback;
     34	int old_timeout;
     35	int loading_timeout;
     36};
     37
     38/* These getters are vetted to use int properly */
     39static inline int __firmware_loading_timeout(void)
     40{
     41	return fw_fallback_config.loading_timeout;
     42}
     43
     44/* These setters are vetted to use int properly */
     45static inline void __fw_fallback_set_timeout(int timeout)
     46{
     47	fw_fallback_config.loading_timeout = timeout;
     48}
     49#endif
     50
     51#ifdef CONFIG_FW_LOADER_SYSFS
     52int register_sysfs_loader(void);
     53void unregister_sysfs_loader(void);
     54#if defined(CONFIG_FW_LOADER_USER_HELPER) && defined(CONFIG_SYSCTL)
     55int register_firmware_config_sysctl(void);
     56void unregister_firmware_config_sysctl(void);
     57#else
     58static inline int register_firmware_config_sysctl(void)
     59{
     60	return 0;
     61}
     62
     63static inline void unregister_firmware_config_sysctl(void) { }
     64#endif /* CONFIG_FW_LOADER_USER_HELPER && CONFIG_SYSCTL */
     65#else /* CONFIG_FW_LOADER_SYSFS */
     66static inline int register_sysfs_loader(void)
     67{
     68	return 0;
     69}
     70
     71static inline void unregister_sysfs_loader(void)
     72{
     73}
     74#endif /* CONFIG_FW_LOADER_SYSFS */
     75
     76struct fw_sysfs {
     77	bool nowait;
     78	struct device dev;
     79	struct fw_priv *fw_priv;
     80	struct firmware *fw;
     81	void *fw_upload_priv;
     82};
     83
     84static inline struct fw_sysfs *to_fw_sysfs(struct device *dev)
     85{
     86	return container_of(dev, struct fw_sysfs, dev);
     87}
     88
     89void __fw_load_abort(struct fw_priv *fw_priv);
     90
     91static inline void fw_load_abort(struct fw_sysfs *fw_sysfs)
     92{
     93	struct fw_priv *fw_priv = fw_sysfs->fw_priv;
     94
     95	__fw_load_abort(fw_priv);
     96}
     97
     98struct fw_sysfs *
     99fw_create_instance(struct firmware *firmware, const char *fw_name,
    100		   struct device *device, u32 opt_flags);
    101
    102#ifdef CONFIG_FW_UPLOAD
    103extern struct device_attribute dev_attr_status;
    104extern struct device_attribute dev_attr_error;
    105extern struct device_attribute dev_attr_cancel;
    106extern struct device_attribute dev_attr_remaining_size;
    107
    108int fw_upload_start(struct fw_sysfs *fw_sysfs);
    109umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
    110#else
    111static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
    112{
    113	return 0;
    114}
    115#endif
    116
    117#endif /* __FIRMWARE_SYSFS_H */