Commit 500a434f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'driver-core-5.19-rc1' of...

Merge tag 'driver-core-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
 "Here is the set of driver core changes for 5.19-rc1.

  Lots of tiny driver core changes and cleanups happened this cycle, but
  the two major things are:

   - firmware_loader reorganization and additions including the ability
     to have XZ compressed firmware images and the ability for userspace
     to initiate the firmware load when it needs to, instead of being
     always initiated by the kernel. FPGA devices specifically want this
     ability to have their firmware changed over the lifetime of the
     system boot, and this allows them to work without having to come up
     with yet-another-custom-uapi interface for loading firmware for
     them.

   - physical location support added to sysfs so that devices that know
     this information, can tell userspace where they are located in a
     common way. Some ACPI devices already support this today, and more
     bus types should support this in the future.

  Smaller changes include:

   - driver_override api cleanups and fixes

   - error path cleanups and fixes

   - get_abi script fixes

   - deferred probe timeout changes.

  It's that last change that I'm the most worried about. It has been
  reported to cause boot problems for a number of systems, and I have a
  tested patch series that resolves this issue. But I didn't get it
  merged into my tree before 5.18-final came out, so it has not gotten
  any linux-next testing.

  I'll send the fixup patches (there are 2) as a follow-on series to this
  pull request.

  All have been tested in linux-next for weeks, with no reported issues
  other than the above-mentioned boot time-outs"

* tag 'driver-core-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (55 commits)
  driver core: fix deadlock in __device_attach
  kernfs: Separate kernfs_pr_cont_buf and rename_lock.
  topology: Remove unused cpu_cluster_mask()
  driver core: Extend deferred probe timeout on driver registration
  MAINTAINERS: add Russ Weight as a firmware loader maintainer
  driver: base: fix UAF when driver_attach failed
  test_firmware: fix end of loop test in upload_read_show()
  driver core: location: Add "back" as a possible output for panel
  driver core: location: Free struct acpi_pld_info *pld
  driver core: Add "*" wildcard support to driver_async_probe cmdline param
  driver core: location: Check for allocations failure
  arch_topology: Trace the update thermal pressure
  kernfs: Rename kernfs_put_open_node to kernfs_unlink_open_file.
  export: fix string handling of namespace in EXPORT_SYMBOL_NS
  rpmsg: use local 'dev' variable
  rpmsg: Fix calling device_lock() on non-initialized device
  firmware_loader: describe 'module' parameter of firmware_upload_register()
  firmware_loader: Move definitions from sysfs_upload.h to sysfs.h
  firmware_loader: Fix configs for sysfs split
  selftests: firmware: Add firmware upload selftests
  ...
parents 6f9b5ed8 b232b02b
What: /sys/class/firmware/.../data
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: The data sysfs file is used for firmware-fallback and for
firmware uploads. Cat a firmware image to this sysfs file
after you echo 1 to the loading sysfs file. When the firmware
image write is complete, echo 0 to the loading sysfs file. This
sequence will signal the completion of the firmware write and
signal the lower-level driver that the firmware data is
available.
What: /sys/class/firmware/.../cancel
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: Write-only. For firmware uploads, write a "1" to this file to
request that the transfer of firmware data to the lower-level
device be canceled. This request will be rejected (EBUSY) if
the update cannot be canceled (e.g. a FLASH write is in
progress) or (ENODEV) if there is no firmware update in progress.
What: /sys/class/firmware/.../error
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: Read-only. Returns a string describing a failed firmware
upload. This string will be in the form of <STATUS>:<ERROR>,
where <STATUS> will be one of the status strings described
for the status sysfs file and <ERROR> will be one of the
following: "hw-error", "timeout", "user-abort", "device-busy",
"invalid-file-size", "read-write-error", "flash-wearout". The
error sysfs file is only meaningful when the current firmware
upload status is "idle". If this file is read while a firmware
transfer is in progress, then the read will fail with EBUSY.
What: /sys/class/firmware/.../loading
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: The loading sysfs file is used for both firmware-fallback and
for firmware uploads. Echo 1 onto the loading file to indicate
you are writing a firmware file to the data sysfs node. Echo
-1 onto this file to abort the data write or echo 0 onto this
file to indicate that the write is complete. For firmware
uploads, the zero value also triggers the transfer of the
firmware data to the lower-level device driver.
What: /sys/class/firmware/.../remaining_size
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: Read-only. For firmware upload, this file contains the size
of the firmware data that remains to be transferred to the
lower-level device driver. The size value is initialized to
the full size of the firmware image that was previously
written to the data sysfs file. This value is periodically
updated during the "transferring" phase of the firmware
upload.
Format: "%u".
What: /sys/class/firmware/.../status
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: Read-only. Returns a string describing the current status of
a firmware upload. The string will be one of the following:
idle, "receiving", "preparing", "transferring", "programming".
What: /sys/class/firmware/.../timeout
Date: July 2022
KernelVersion: 5.19
Contact: Russ Weight <russell.h.weight@intel.com>
Description: This file supports the timeout mechanism for firmware
fallback. This file has no affect on firmware uploads. For
more information on timeouts please see the documentation
for firmware fallback.
What: /sys/devices/.../physical_location
Date: March 2022
Contact: Won Chung <wonchung@google.com>
Description:
This directory contains information on physical location of
the device connection point with respect to the system's
housing.
What: /sys/devices/.../physical_location/panel
Date: March 2022
Contact: Won Chung <wonchung@google.com>
Description:
Describes which panel surface of the system’s housing the
device connection point resides on.
What: /sys/devices/.../physical_location/vertical_position
Date: March 2022
Contact: Won Chung <wonchung@google.com>
Description:
Describes vertical position of the device connection point on
the panel surface.
What: /sys/devices/.../physical_location/horizontal_position
Date: March 2022
Contact: Won Chung <wonchung@google.com>
Description:
Describes horizontal position of the device connection point on
the panel surface.
What: /sys/devices/.../physical_location/dock
Date: March 2022
Contact: Won Chung <wonchung@google.com>
Description:
"Yes" if the device connection point resides in a docking
station or a port replicator. "No" otherwise.
What: /sys/devices/.../physical_location/lid
Date: March 2022
Contact: Won Chung <wonchung@google.com>
Description:
"Yes" if the device connection point resides on the lid of
laptop system. "No" otherwise.
......@@ -979,8 +979,10 @@
[KNL] Debugging option to set a timeout in seconds for
deferred probe to give up waiting on dependencies to
probe. Only specific dependencies (subsystems or
drivers) that have opted in will be ignored. A timeout of 0
will timeout at the end of initcalls. This option will also
drivers) that have opted in will be ignored. A timeout
of 0 will timeout at the end of initcalls. If the time
out hasn't expired, it'll be restarted by each
successful driver registration. This option will also
dump out devices still on the deferred probe list after
retrying.
......@@ -1101,7 +1103,10 @@
driver later using sysfs.
driver_async_probe= [KNL]
List of driver names to be probed asynchronously.
List of driver names to be probed asynchronously. *
matches with all driver names. If * is specified, the
rest of the listed driver names are those that will NOT
match the *.
Format: <driver_name1>,<driver_name2>...
drm.edid_firmware=[<connector>:]<file>[,[<connector>:]<file>]
......
.. SPDX-License-Identifier: GPL-2.0
===================
Firmware Upload API
===================
A device driver that registers with the firmware loader will expose
persistent sysfs nodes to enable users to initiate firmware updates for
that device. It is the responsibility of the device driver and/or the
device itself to perform any validation on the data received. Firmware
upload uses the same *loading* and *data* sysfs files described in the
documentation for firmware fallback. It also adds additional sysfs files
to provide status on the transfer of the firmware image to the device.
Register for firmware upload
============================
A device driver registers for firmware upload by calling
firmware_upload_register(). Among the parameter list is a name to
identify the device under /sys/class/firmware. A user may initiate a
firmware upload by echoing a 1 to the *loading* sysfs file for the target
device. Next, the user writes the firmware image to the *data* sysfs
file. After writing the firmware data, the user echos 0 to the *loading*
sysfs file to signal completion. Echoing 0 to *loading* also triggers the
transfer of the firmware to the lower-lever device driver in the context
of a kernel worker thread.
To use the firmware upload API, write a driver that implements a set of
ops. The probe function calls firmware_upload_register() and the remove
function calls firmware_upload_unregister() such as::
static const struct fw_upload_ops m10bmc_ops = {
.prepare = m10bmc_sec_prepare,
.write = m10bmc_sec_write,
.poll_complete = m10bmc_sec_poll_complete,
.cancel = m10bmc_sec_cancel,
.cleanup = m10bmc_sec_cleanup,
};
static int m10bmc_sec_probe(struct platform_device *pdev)
{
const char *fw_name, *truncate;
struct m10bmc_sec *sec;
struct fw_upload *fwl;
unsigned int len;
sec = devm_kzalloc(&pdev->dev, sizeof(*sec), GFP_KERNEL);
if (!sec)
return -ENOMEM;
sec->dev = &pdev->dev;
sec->m10bmc = dev_get_drvdata(pdev->dev.parent);
dev_set_drvdata(&pdev->dev, sec);
fw_name = dev_name(sec->dev);
truncate = strstr(fw_name, ".auto");
len = (truncate) ? truncate - fw_name : strlen(fw_name);
sec->fw_name = kmemdup_nul(fw_name, len, GFP_KERNEL);
fwl = firmware_upload_register(sec->dev, sec->fw_name, &m10bmc_ops, sec);
if (IS_ERR(fwl)) {
dev_err(sec->dev, "Firmware Upload driver failed to start\n");
kfree(sec->fw_name);
return PTR_ERR(fwl);
}
sec->fwl = fwl;
return 0;
}
static int m10bmc_sec_remove(struct platform_device *pdev)
{
struct m10bmc_sec *sec = dev_get_drvdata(&pdev->dev);
firmware_upload_unregister(sec->fwl);
kfree(sec->fw_name);
return 0;
}
firmware_upload_register
------------------------
.. kernel-doc:: drivers/base/firmware_loader/sysfs_upload.c
:identifiers: firmware_upload_register
firmware_upload_unregister
--------------------------
.. kernel-doc:: drivers/base/firmware_loader/sysfs_upload.c
:identifiers: firmware_upload_unregister
Firmware Upload Ops
-------------------
.. kernel-doc:: include/linux/firmware.h
:identifiers: fw_upload_ops
Firmware Upload Progress Codes
------------------------------
The following progress codes are used internally by the firmware loader.
Corresponding strings are reported through the status sysfs node that
is described below and are documented in the ABI documentation.
.. kernel-doc:: drivers/base/firmware_loader/sysfs_upload.h
:identifiers: fw_upload_prog
Firmware Upload Error Codes
---------------------------
The following error codes may be returned by the driver ops in case of
failure:
.. kernel-doc:: include/linux/firmware.h
:identifiers: fw_upload_err
Sysfs Attributes
================
In addition to the *loading* and *data* sysfs files, there are additional
sysfs files to monitor the status of the data transfer to the target
device and to determine the final pass/fail status of the transfer.
Depending on the device and the size of the firmware image, a firmware
update could take milliseconds or minutes.
The additional sysfs files are:
* status - provides an indication of the progress of a firmware update
* error - provides error information for a failed firmware update
* remaining_size - tracks the data transfer portion of an update
* cancel - echo 1 to this file to cancel the update
......@@ -8,6 +8,7 @@ Linux Firmware API
core
efi/index
request_firmware
fw_upload
other_interfaces
.. only:: subproject and html
......
......@@ -7727,6 +7727,7 @@ F: include/linux/arm_ffa.h
FIRMWARE LOADER (request_firmware)
M: Luis Chamberlain <mcgrof@kernel.org>
M: Russ Weight <russell.h.weight@intel.com>
L: linux-kernel@vger.kernel.org
S: Maintained
F: Documentation/firmware_class/
......
......@@ -98,31 +98,11 @@ static ssize_t driver_override_store(struct device *_dev,
const char *buf, size_t count)
{
struct amba_device *dev = to_amba_device(_dev);
char *driver_override, *old, *cp;
/* We need to keep extra room for a newline */
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
device_lock(_dev);
old = dev->driver_override;
if (strlen(driver_override)) {
dev->driver_override = driver_override;
} else {
kfree(driver_override);
dev->driver_override = NULL;
}
device_unlock(_dev);
int ret;
kfree(old);
ret = driver_set_override(_dev, &dev->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -25,6 +25,7 @@ obj-$(CONFIG_DEV_COREDUMP) += devcoredump.o
obj-$(CONFIG_GENERIC_MSI_IRQ_DOMAIN) += platform-msi.o
obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
obj-$(CONFIG_ACPI) += physical_location.o
obj-y += test/
......
......@@ -19,6 +19,9 @@
#include <linux/rcupdate.h>
#include <linux/sched.h>
#define CREATE_TRACE_POINTS
#include <trace/events/thermal_pressure.h>
static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data);
static struct cpumask scale_freq_counters_mask;
static bool scale_freq_invariant;
......@@ -195,6 +198,8 @@ void topology_update_thermal_pressure(const struct cpumask *cpus,
th_pressure = max_capacity - capacity;
trace_thermal_pressure_update(cpu, th_pressure);
for_each_cpu(cpu, cpus)
WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure);
}
......
......@@ -159,6 +159,7 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
extern int devres_release_all(struct device *dev);
extern void device_block_probing(void);
extern void device_unblock_probing(void);
extern void deferred_probe_extend_timeout(void);
/* /sys/devices directory */
extern struct kset *devices_kset;
......
......@@ -617,7 +617,7 @@ int bus_add_driver(struct device_driver *drv)
if (drv->bus->p->drivers_autoprobe) {
error = driver_attach(drv);
if (error)
goto out_unregister;
goto out_del_list;
}
module_add_driver(drv->owner, drv);
......@@ -644,6 +644,8 @@ int bus_add_driver(struct device_driver *drv)
return 0;
out_del_list:
klist_del(&priv->knode_bus);
out_unregister:
kobject_put(&priv->kobj);
/* drv->p is freed in driver_release() */
......
......@@ -32,6 +32,7 @@
#include <linux/dma-map-ops.h> /* for dma_default_coherent */
#include "base.h"
#include "physical_location.h"
#include "power/power.h"
#ifdef CONFIG_SYSFS_DEPRECATED
......@@ -2649,8 +2650,17 @@ static int device_add_attrs(struct device *dev)
goto err_remove_dev_waiting_for_supplier;
}
if (dev_add_physical_location(dev)) {
error = device_add_group(dev,
&dev_attr_physical_location_group);
if (error)
goto err_remove_dev_removable;
}
return 0;
err_remove_dev_removable:
device_remove_file(dev, &dev_attr_removable);
err_remove_dev_waiting_for_supplier:
device_remove_file(dev, &dev_attr_waiting_for_supplier);
err_remove_dev_online:
......@@ -2672,6 +2682,11 @@ static void device_remove_attrs(struct device *dev)
struct class *class = dev->class;
const struct device_type *type = dev->type;
if (dev->physical_location) {
device_remove_group(dev, &dev_attr_physical_location_group);
kfree(dev->physical_location);
}
device_remove_file(dev, &dev_attr_removable);
device_remove_file(dev, &dev_attr_waiting_for_supplier);
device_remove_file(dev, &dev_attr_online);
......
......@@ -60,6 +60,7 @@ static bool initcalls_done;
/* Save the async probe drivers' name from kernel cmdline */
#define ASYNC_DRV_NAMES_MAX_LEN 256
static char async_probe_drv_names[ASYNC_DRV_NAMES_MAX_LEN];
static bool async_probe_default;
/*
* In some cases, like suspend to RAM or hibernation, It might be reasonable
......@@ -255,7 +256,12 @@ static int deferred_devs_show(struct seq_file *s, void *data)
}
DEFINE_SHOW_ATTRIBUTE(deferred_devs);
#ifdef CONFIG_MODULES
int driver_deferred_probe_timeout = 10;
#else
int driver_deferred_probe_timeout;
#endif
EXPORT_SYMBOL_GPL(driver_deferred_probe_timeout);
static DECLARE_WAIT_QUEUE_HEAD(probe_timeout_waitqueue);
......@@ -274,10 +280,10 @@ __setup("deferred_probe_timeout=", deferred_probe_timeout_setup);
* @dev: device to check
*
* Return:
* -ENODEV if initcalls have completed and modules are disabled.
* -ETIMEDOUT if the deferred probe timeout was set and has expired
* and modules are enabled.
* -EPROBE_DEFER in other cases.
* * -ENODEV if initcalls have completed and modules are disabled.
* * -ETIMEDOUT if the deferred probe timeout was set and has expired
* and modules are enabled.
* * -EPROBE_DEFER in other cases.
*
* Drivers or subsystems can opt-in to calling this function instead of directly
* returning -EPROBE_DEFER.
......@@ -316,6 +322,20 @@ static void deferred_probe_timeout_work_func(struct work_struct *work)
}
static DECLARE_DELAYED_WORK(deferred_probe_timeout_work, deferred_probe_timeout_work_func);
void deferred_probe_extend_timeout(void)
{
/*
* If the work hasn't been queued yet or if the work expired, don't
* start a new one.
*/
if (cancel_delayed_work(&deferred_probe_timeout_work)) {
schedule_delayed_work(&deferred_probe_timeout_work,
driver_deferred_probe_timeout * HZ);
pr_debug("Extended deferred probe timeout by %d secs\n",
driver_deferred_probe_timeout);
}
}
/**
* deferred_probe_initcall() - Enable probing of deferred devices
*
......@@ -799,7 +819,11 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev)
static inline bool cmdline_requested_async_probing(const char *drv_name)
{
return parse_option_str(async_probe_drv_names, drv_name);
bool async_drv;
async_drv = parse_option_str(async_probe_drv_names, drv_name);
return (async_probe_default != async_drv);
}
/* The option format is "driver_async_probe=drv_name1,drv_name2,..." */
......@@ -809,6 +833,8 @@ static int __init save_async_options(char *buf)
pr_warn("Too long list of driver names for 'driver_async_probe'!\n");
strlcpy(async_probe_drv_names, buf, ASYNC_DRV_NAMES_MAX_LEN);
async_probe_default = parse_option_str(async_probe_drv_names, "*");
return 1;
}
__setup("driver_async_probe=", save_async_options);
......@@ -943,6 +969,7 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
static int __device_attach(struct device *dev, bool allow_async)
{
int ret = 0;
bool async = false;
device_lock(dev);
if (dev->p->dead) {
......@@ -981,7 +1008,7 @@ static int __device_attach(struct device *dev, bool allow_async)
*/
dev_dbg(dev, "scheduling asynchronous probe\n");
get_device(dev);
async_schedule_dev(__device_attach_async_helper, dev);
async = true;
} else {
pm_request_idle(dev);
}
......@@ -991,6 +1018,8 @@ static int __device_attach(struct device *dev, bool allow_async)
}
out_unlock:
device_unlock(dev);
if (async)
async_schedule_dev(__device_attach_async_helper, dev);
return ret;
}
......@@ -1084,6 +1113,7 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
__device_driver_lock(dev, dev->parent);
drv = dev->p->async_driver;
dev->p->async_driver = NULL;
ret = driver_probe_device(drv, dev);
__device_driver_unlock(dev, dev->parent);
......@@ -1130,7 +1160,7 @@ static int __driver_attach(struct device *dev, void *data)
*/
dev_dbg(dev, "probing driver %s asynchronously\n", drv->name);
device_lock(dev);
if (!dev->driver) {
if (!dev->driver && !dev->p->async_driver) {
get_device(dev);
dev->p->async_driver = drv;
async_schedule_dev(__driver_attach_async_helper, dev);
......
......@@ -30,6 +30,75 @@ static struct device *next_device(struct klist_iter *i)
return dev;
}
/**
* driver_set_override() - Helper to set or clear driver override.
* @dev: Device to change
* @override: Address of string to change (e.g. &device->driver_override);
* The contents will be freed and hold newly allocated override.
* @s: NUL-terminated string, new driver name to force a match, pass empty
* string to clear it ("" or "\n", where the latter is only for sysfs
* interface).
* @len: length of @s
*
* Helper to set or clear driver override in a device, intended for the cases
* when the driver_override field is allocated by driver/bus code.
*
* Returns: 0 on success or a negative error code on failure.
*/
int driver_set_override(struct device *dev, const char **override,
const char *s, size_t len)
{
const char *new, *old;
char *cp;
if (!override || !s)
return -EINVAL;
/*
* The stored value will be used in sysfs show callback (sysfs_emit()),
* which has a length limit of PAGE_SIZE and adds a trailing newline.
* Thus we can store one character less to avoid truncation during sysfs
* show.
*/
if (len >= (PAGE_SIZE - 1))
return -EINVAL;
if (!len) {
/* Empty string passed - clear override */
device_lock(dev);
old = *override;
*override = NULL;
device_unlock(dev);
kfree(old);
return 0;
}
cp = strnchr(s, len, '\n');
if (cp)
len = cp - s;
new = kstrndup(s, len, GFP_KERNEL);
if (!new)
return -ENOMEM;
device_lock(dev);
old = *override;
if (cp != s) {
*override = new;
} else {
/* "\n" passed - clear override */
kfree(new);
*override = NULL;
}
device_unlock(dev);
kfree(old);
return 0;
}
EXPORT_SYMBOL_GPL(driver_set_override);
/**
* driver_for_each_device - Iterator for devices bound to a driver.
* @drv: Driver we're iterating.
......@@ -177,6 +246,7 @@ int driver_register(struct device_driver *drv)
return ret;
}
kobject_uevent(&drv->p->kobj, KOBJ_ADD);
deferred_probe_extend_timeout();
return ret;
}
......
......@@ -29,6 +29,9 @@ if FW_LOADER
config FW_LOADER_PAGED_BUF
bool
config FW_LOADER_SYSFS
bool
config EXTRA_FIRMWARE
string "Build named firmware blobs into the kernel binary"
help
......@@ -72,6 +75,7 @@ config EXTRA_FIRMWARE_DIR
config FW_LOADER_USER_HELPER
bool "Enable the firmware sysfs fallback mechanism"
select FW_LOADER_SYSFS
select FW_LOADER_PAGED_BUF
help
This option enables a sysfs loading facility to enable firmware
......@@ -159,21 +163,33 @@ config FW_LOADER_USER_HELPER_FALLBACK
config FW_LOADER_COMPRESS
bool "Enable compressed firmware support"
select FW_LOADER_PAGED_BUF
select XZ_DEC
help
This option enables the support for loading compressed firmware
files. The caller of firmware API receives the decompressed file
content. The compressed file is loaded as a fallback, only after
loading the raw file failed at first.
Currently only XZ-compressed files are supported, and they have to
be compressed with either none or crc32 integrity check type (pass
"-C crc32" option to xz command).
Compressed firmware support does not apply to firmware images
that are built into the kernel image (CONFIG_EXTRA_FIRMWARE).
if FW_LOADER_COMPRESS
config FW_LOADER_COMPRESS_XZ
bool "Enable XZ-compressed firmware support"
select FW_LOADER_PAGED_BUF
select XZ_DEC
help
This option adds the support for XZ-compressed files.
The files have to be compressed with either none or crc32
integrity check type (pass "-C crc32" option to xz command).
config FW_LOADER_COMPRESS_ZSTD
bool "Enable ZSTD-compressed firmware support"
select ZSTD_DECOMPRESS
help
This option adds the support for ZSTD-compressed files.
endif # FW_LOADER_COMPRESS
config FW_CACHE
bool "Enable firmware caching during suspend"
depends on PM_SLEEP
......@@ -186,5 +202,19 @@ config FW_CACHE
If unsure, say Y.
config FW_UPLOAD
bool "Enable users to initiate firmware updates using sysfs"
select FW_LOADER_SYSFS
select FW_LOADER_PAGED_BUF
help
Enabling this option will allow device drivers to expose a persistent
sysfs interface that allows firmware updates to be initiated from
userspace. For example, FPGA based PCIe cards load firmware and FPGA
images from local FLASH when the card boots. The images in FLASH may
be updated with new images provided by the user. Enable this device
to support cards that rely on user-initiated updates for firmware files.
If unsure, say N.
endif # FW_LOADER
endmenu
......@@ -6,5 +6,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o
firmware_class-objs := main.o
firmware_class-$(CONFIG_FW_LOADER_USER_HELPER) += fallback.o
firmware_class-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += fallback_platform.o
firmware_class-$(CONFIG_FW_LOADER_SYSFS) += sysfs.o
firmware_class-$(CONFIG_FW_UPLOAD) += sysfs_upload.o
obj-y += builtin/
This diff is collapsed.
......@@ -6,29 +6,7 @@
#include <linux/device.h>
#include "firmware.h"
/**
* struct firmware_fallback_config - firmware fallback configuration settings
*
* Helps describe and fine tune the fallback mechanism.
*
* @force_sysfs_fallback: force the sysfs fallback mechanism to be used
* as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
* Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
* functionality on a kernel where that config entry has been disabled.
* @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
* This emulates the behaviour as if we had set the kernel
* config CONFIG_FW_LOADER_USER_HELPER=n.
* @old_timeout: for internal use
* @loading_timeout: the timeout to wait for the fallback mechanism before
* giving up, in seconds.
*/
struct firmware_fallback_config {
unsigned int force_sysfs_fallback;
unsigned int ignore_sysfs_fallback;
int old_timeout;
int loading_timeout;
};
#include "sysfs.h"
#ifdef CONFIG_FW_LOADER_USER_HELPER
int firmware_fallback_sysfs(struct firmware *fw, const char *name,
......@@ -40,19 +18,6 @@ void kill_pending_fw_fallback_reqs(bool only_kill_custom);
void fw_fallback_set_cache_timeout(void);
void fw_fallback_set_default_timeout(void);
int register_sysfs_loader(void);
void unregister_sysfs_loader(void);
#ifdef CONFIG_SYSCTL
extern int register_firmware_config_sysctl(void);
extern void unregister_firmware_config_sysctl(void);
#else
static inline int register_firmware_config_sysctl(void)
{
return 0;
}
static inline void unregister_firmware_config_sysctl(void) { }
#endif /* CONFIG_SYSCTL */
#else /* CONFIG_FW_LOADER_USER_HELPER */
static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
struct device *device,
......@@ -66,15 +31,6 @@ static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
static inline void fw_fallback_set_cache_timeout(void) { }
static inline void fw_fallback_set_default_timeout(void) { }
static inline int register_sysfs_loader(void)
{
return 0;
}
static inline void unregister_sysfs_loader(void)
{
}
#endif /* CONFIG_FW_LOADER_USER_HELPER */
#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
......
......@@ -87,6 +87,7 @@ struct fw_priv {
};
extern struct mutex fw_lock;
extern struct firmware_cache fw_cache;
static inline bool __fw_state_check(struct fw_priv *fw_priv,
enum fw_status status)
......@@ -149,7 +150,22 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
__fw_state_set(fw_priv, FW_STATUS_DONE);
}
static inline bool fw_state_is_done(struct fw_priv *fw_priv)
{
return __fw_state_check(fw_priv, FW_STATUS_DONE);
}
static inline bool fw_state_is_loading(struct fw_priv *fw_priv)
{
return __fw_state_check(fw_priv, FW_STATUS_LOADING);
}
int alloc_lookup_fw_priv(const char *fw_name, struct firmware_cache *fwc,
struct fw_priv **fw_priv, void *dbuf, size_t size,
size_t offset, u32 opt_flags);
int assign_fw(struct firmware *fw, struct device *device);
void free_fw_priv(struct fw_priv *fw_priv);
void fw_state_init(struct fw_priv *fw_priv);
#ifdef CONFIG_FW_LOADER
bool firmware_is_builtin(const struct firmware *fw);
......
......@@ -35,6 +35,7 @@
#include <linux/syscore_ops.h>
#include <linux/reboot.h>
#include <linux/security.h>
#include <linux/zstd.h>
#include <linux/xz.h>
#include <generated/utsrelease.h>
......@@ -91,9 +92,9 @@ static inline struct fw_priv *to_fw_priv(struct kref *ref)
* guarding for corner cases a global lock should be OK */
DEFINE_MUTEX(fw_lock);
static struct firmware_cache fw_cache;
struct firmware_cache fw_cache;
static void fw_state_init(struct fw_priv *fw_priv)
void fw_state_init(struct fw_priv *fw_priv)
{
struct fw_state *fw_st = &fw_priv->fw_st;
......@@ -163,13 +164,9 @@ static struct fw_priv *__lookup_fw_priv(const char *fw_name)
}
/* Returns 1 for batching firmware requests with the same name */
static int alloc_lookup_fw_priv(const char *fw_name,
struct firmware_cache *fwc,
struct fw_priv **fw_priv,
void *dbuf,
size_t size,
size_t offset,
u32 opt_flags)
int alloc_lookup_fw_priv(const char *fw_name, struct firmware_cache *fwc,
struct fw_priv **fw_priv, void *dbuf, size_t size,
size_t offset, u32 opt_flags)
{
struct fw_priv *tmp;
......@@ -224,7 +221,7 @@ static void __free_fw_priv(struct kref *ref)
kfree(fw_priv);
}
static void free_fw_priv(struct fw_priv *fw_priv)
void free_fw_priv(struct fw_priv *fw_priv)
{
struct firmware_cache *fwc = fw_priv->fwc;
spin_lock(&fwc->lock);
......@@ -253,6 +250,8 @@ void fw_free_paged_buf(struct fw_priv *fw_priv)
fw_priv->pages = NULL;
fw_priv->page_array_size = 0;
fw_priv->nr_pages = 0;
fw_priv->data = NULL;
fw_priv->size = 0;
}
int fw_grow_paged_buf(struct fw_priv *fw_priv, int pages_needed)
......@@ -304,10 +303,74 @@ int fw_map_paged_buf(struct fw_priv *fw_priv)
}
#endif
/*
* ZSTD-compressed firmware support
*/
#ifdef CONFIG_FW_LOADER_COMPRESS_ZSTD
static int fw_decompress_zstd(struct device *dev, struct fw_priv *fw_priv,
size_t in_size, const void *in_buffer)
{
size_t len, out_size, workspace_size;
void *workspace, *out_buf;
zstd_dctx *ctx;
int err;
if (fw_priv->allocated_size) {
out_size = fw_priv->allocated_size;
out_buf = fw_priv->data;
} else {
zstd_frame_header params;
if (zstd_get_frame_header(&params, in_buffer, in_size) ||
params.frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN) {
dev_dbg(dev, "%s: invalid zstd header\n", __func__);
return -EINVAL;
}
out_size = params.frameContentSize;
out_buf = vzalloc(out_size);
if (!out_buf)
return -ENOMEM;
}
workspace_size = zstd_dctx_workspace_bound();
workspace = kvzalloc(workspace_size, GFP_KERNEL);
if (!workspace) {
err = -ENOMEM;
goto error;
}
ctx = zstd_init_dctx(workspace, workspace_size);
if (!ctx) {
dev_dbg(dev, "%s: failed to initialize context\n", __func__);
err = -EINVAL;
goto error;
}
len = zstd_decompress_dctx(ctx, out_buf, out_size, in_buffer, in_size);
if (zstd_is_error(len)) {
dev_dbg(dev, "%s: failed to decompress: %d\n", __func__,
zstd_get_error_code(len));
err = -EINVAL;
goto error;
}
if (!fw_priv->allocated_size)
fw_priv->data = out_buf;
fw_priv->size = len;
err = 0;
error:
kvfree(workspace);
if (err && !fw_priv->allocated_size)
vfree(out_buf);
return err;
}
#endif /* CONFIG_FW_LOADER_COMPRESS_ZSTD */
/*
* XZ-compressed firmware support
*/
#ifdef CONFIG_FW_LOADER_COMPRESS
#ifdef CONFIG_FW_LOADER_COMPRESS_XZ
/* show an error and return the standard error code */
static int fw_decompress_xz_error(struct device *dev, enum xz_ret xz_ret)
{
......@@ -401,7 +464,7 @@ static int fw_decompress_xz(struct device *dev, struct fw_priv *fw_priv,
else
return fw_decompress_xz_pages(dev, fw_priv, in_size, in_buffer);
}
#endif /* CONFIG_FW_LOADER_COMPRESS */
#endif /* CONFIG_FW_LOADER_COMPRESS_XZ */
/* direct firmware loading support */
static char fw_path_para[256];
......@@ -771,7 +834,12 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
if (!(opt_flags & FW_OPT_PARTIAL))
nondirect = true;
#ifdef CONFIG_FW_LOADER_COMPRESS
#ifdef CONFIG_FW_LOADER_COMPRESS_ZSTD
if (ret == -ENOENT && nondirect)
ret = fw_get_filesystem_firmware(device, fw->priv, ".zst",
fw_decompress_zstd);
#endif
#ifdef CONFIG_FW_LOADER_COMPRESS_XZ
if (ret == -ENOENT && nondirect)
ret = fw_get_filesystem_firmware(device, fw->priv, ".xz",
fw_decompress_xz);
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __FIRMWARE_SYSFS_H
#define __FIRMWARE_SYSFS_H
#include <linux/device.h>
#include "firmware.h"
MODULE_IMPORT_NS(FIRMWARE_LOADER_PRIVATE);
extern struct firmware_fallback_config fw_fallback_config;
extern struct device_attribute dev_attr_loading;
#ifdef CONFIG_FW_LOADER_USER_HELPER
/**
* struct firmware_fallback_config - firmware fallback configuration settings
*
* Helps describe and fine tune the fallback mechanism.
*
* @force_sysfs_fallback: force the sysfs fallback mechanism to be used
* as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
* Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
* functionality on a kernel where that config entry has been disabled.
* @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
* This emulates the behaviour as if we had set the kernel
* config CONFIG_FW_LOADER_USER_HELPER=n.
* @old_timeout: for internal use
* @loading_timeout: the timeout to wait for the fallback mechanism before
* giving up, in seconds.
*/
struct firmware_fallback_config {
unsigned int force_sysfs_fallback;
unsigned int ignore_sysfs_fallback;
int old_timeout;
int loading_timeout;
};
/* These getters are vetted to use int properly */
static inline int __firmware_loading_timeout(void)
{
return fw_fallback_config.loading_timeout;
}
/* These setters are vetted to use int properly */
static inline void __fw_fallback_set_timeout(int timeout)
{
fw_fallback_config.loading_timeout = timeout;
}
#endif
#ifdef CONFIG_FW_LOADER_SYSFS
int register_sysfs_loader(void);
void unregister_sysfs_loader(void);
#if defined(CONFIG_FW_LOADER_USER_HELPER) && defined(CONFIG_SYSCTL)
int register_firmware_config_sysctl(void);
void unregister_firmware_config_sysctl(void);
#else
static inline int register_firmware_config_sysctl(void)
{
return 0;
}
static inline void unregister_firmware_config_sysctl(void) { }
#endif /* CONFIG_FW_LOADER_USER_HELPER && CONFIG_SYSCTL */
#else /* CONFIG_FW_LOADER_SYSFS */
static inline int register_sysfs_loader(void)
{
return 0;
}
static inline void unregister_sysfs_loader(void)
{
}
#endif /* CONFIG_FW_LOADER_SYSFS */
struct fw_sysfs {
bool nowait;
struct device dev;
struct fw_priv *fw_priv;
struct firmware *fw;
void *fw_upload_priv;
};
static inline struct fw_sysfs *to_fw_sysfs(struct device *dev)
{
return container_of(dev, struct fw_sysfs, dev);
}
void __fw_load_abort(struct fw_priv *fw_priv);
static inline void fw_load_abort(struct fw_sysfs *fw_sysfs)
{
struct fw_priv *fw_priv = fw_sysfs->fw_priv;
__fw_load_abort(fw_priv);
}
struct fw_sysfs *
fw_create_instance(struct firmware *firmware, const char *fw_name,
struct device *device, u32 opt_flags);
#ifdef CONFIG_FW_UPLOAD
extern struct device_attribute dev_attr_status;
extern struct device_attribute dev_attr_error;
extern struct device_attribute dev_attr_cancel;
extern struct device_attribute dev_attr_remaining_size;
int fw_upload_start(struct fw_sysfs *fw_sysfs);
umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
#else
static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
{
return 0;
}
#endif
#endif /* __FIRMWARE_SYSFS_H */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __SYSFS_UPLOAD_H
#define __SYSFS_UPLOAD_H
#include <linux/device.h>
#include "sysfs.h"
/**
* enum fw_upload_prog - firmware upload progress codes
* @FW_UPLOAD_PROG_IDLE: there is no firmware upload in progress
* @FW_UPLOAD_PROG_RECEIVING: worker thread is receiving firmware data
* @FW_UPLOAD_PROG_PREPARING: target device is preparing for firmware upload
* @FW_UPLOAD_PROG_TRANSFERRING: data is being copied to the device
* @FW_UPLOAD_PROG_PROGRAMMING: device is performing the firmware update
* @FW_UPLOAD_PROG_MAX: Maximum progress code marker
*/
enum fw_upload_prog {
FW_UPLOAD_PROG_IDLE,
FW_UPLOAD_PROG_RECEIVING,
FW_UPLOAD_PROG_PREPARING,
FW_UPLOAD_PROG_TRANSFERRING,
FW_UPLOAD_PROG_PROGRAMMING,
FW_UPLOAD_PROG_MAX
};
struct fw_upload_priv {
struct fw_upload *fw_upload;
struct module *module;
const char *name;
const struct fw_upload_ops *ops;
struct mutex lock; /* protect data structure contents */
struct work_struct work;
const u8 *data; /* pointer to update data */
u32 remaining_size; /* size remaining to transfer */
enum fw_upload_prog progress;
enum fw_upload_prog err_progress; /* progress at time of failure */
enum fw_upload_err err_code; /* security manager error code */
};
#endif /* __SYSFS_UPLOAD_H */
// SPDX-License-Identifier: GPL-2.0
/*
* Device physical location support
*
* Author: Won Chung <wonchung@google.com>
*/
#include <linux/acpi.h>
#include <linux/sysfs.h>
#include "physical_location.h"
bool dev_add_physical_location(struct device *dev)
{
struct acpi_pld_info *pld;
acpi_status status;
if (!has_acpi_companion(dev))
return false;
status = acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld);
if (ACPI_FAILURE(status))
return false;
dev->physical_location =
kzalloc(sizeof(*dev->physical_location), GFP_KERNEL);
if (!dev->physical_location)
return false;
dev->physical_location->panel = pld->panel;
dev->physical_location->vertical_position = pld->vertical_position;
dev->physical_location->horizontal_position = pld->horizontal_position;
dev->physical_location->dock = pld->dock;
dev->physical_location->lid = pld->lid;
ACPI_FREE(pld);
return true;
}
static ssize_t panel_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
const char *panel;
switch (dev->physical_location->panel) {
case DEVICE_PANEL_TOP:
panel = "top";
break;
case DEVICE_PANEL_BOTTOM:
panel = "bottom";
break;
case DEVICE_PANEL_LEFT:
panel = "left";
break;
case DEVICE_PANEL_RIGHT:
panel = "right";
break;
case DEVICE_PANEL_FRONT:
panel = "front";
break;
case DEVICE_PANEL_BACK:
panel = "back";
break;
default:
panel = "unknown";
}
return sysfs_emit(buf, "%s\n", panel);
}
static DEVICE_ATTR_RO(panel);
static ssize_t vertical_position_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
const char *vertical_position;
switch (dev->physical_location->vertical_position) {
case DEVICE_VERT_POS_UPPER:
vertical_position = "upper";
break;
case DEVICE_VERT_POS_CENTER:
vertical_position = "center";
break;
case DEVICE_VERT_POS_LOWER:
vertical_position = "lower";
break;
default:
vertical_position = "unknown";
}
return sysfs_emit(buf, "%s\n", vertical_position);
}
static DEVICE_ATTR_RO(vertical_position);
static ssize_t horizontal_position_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
const char *horizontal_position;
switch (dev->physical_location->horizontal_position) {
case DEVICE_HORI_POS_LEFT:
horizontal_position = "left";
break;
case DEVICE_HORI_POS_CENTER:
horizontal_position = "center";
break;
case DEVICE_HORI_POS_RIGHT:
horizontal_position = "right";
break;
default:
horizontal_position = "unknown";
}
return sysfs_emit(buf, "%s\n", horizontal_position);
}
static DEVICE_ATTR_RO(horizontal_position);
static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n",
dev->physical_location->dock ? "yes" : "no");
}
static DEVICE_ATTR_RO(dock);
static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n",
dev->physical_location->lid ? "yes" : "no");
}
static DEVICE_ATTR_RO(lid);
static struct attribute *dev_attr_physical_location[] = {
&dev_attr_panel.attr,
&dev_attr_vertical_position.attr,
&dev_attr_horizontal_position.attr,
&dev_attr_dock.attr,
&dev_attr_lid.attr,
NULL,
};
const struct attribute_group dev_attr_physical_location_group = {
.name = "physical_location",
.attrs = dev_attr_physical_location,
};
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Device physical location support
*
* Author: Won Chung <wonchung@google.com>
*/
#include <linux/device.h>
#ifdef CONFIG_ACPI
extern bool dev_add_physical_location(struct device *dev);
extern const struct attribute_group dev_attr_physical_location_group;
#else
static inline bool dev_add_physical_location(struct device *dev) { return false; };
static const struct attribute_group dev_attr_physical_location_group = {};
#endif
......@@ -233,7 +233,8 @@ int platform_get_irq_optional(struct platform_device *dev, unsigned int num)
out_not_found:
ret = -ENXIO;
out:
WARN(ret == 0, "0 is an invalid IRQ number\n");
if (WARN(!ret, "0 is an invalid IRQ number\n"))
return -EINVAL;
return ret;
}
EXPORT_SYMBOL_GPL(platform_get_irq_optional);
......@@ -448,7 +449,8 @@ static int __platform_get_irq_byname(struct platform_device *dev,
r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
if (r) {
WARN(r->start == 0, "0 is an invalid IRQ number\n");
if (WARN(!r->start, "0 is an invalid IRQ number\n"))
return -EINVAL;
return r->start;
}
......@@ -1277,31 +1279,11 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct platform_device *pdev = to_platform_device(dev);
char *driver_override, *old, *cp;
/* We need to keep extra room for a newline */
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
device_lock(dev);
old = pdev->driver_override;
if (strlen(driver_override)) {
pdev->driver_override = driver_override;
} else {
kfree(driver_override);
pdev->driver_override = NULL;
}
device_unlock(dev);
int ret;
kfree(old);
ret = driver_set_override(dev, &pdev->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -185,31 +185,14 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
char *driver_override, *old = mc_dev->driver_override;
char *cp;
int ret;
if (WARN_ON(dev->bus != &fsl_mc_bus_type))
return -EINVAL;
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
if (strlen(driver_override)) {
mc_dev->driver_override = driver_override;
} else {
kfree(driver_override);
mc_dev->driver_override = NULL;
}
kfree(old);
ret = driver_set_override(dev, &mc_dev->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -683,7 +683,12 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name,
return ERR_PTR(ret);
}
pdev->driver_override = "imx-scu-clk";
ret = driver_set_override(&pdev->dev, &pdev->driver_override,
"imx-scu-clk", strlen("imx-scu-clk"));
if (ret) {
platform_device_put(pdev);
return ERR_PTR(ret);
}
ret = imx_clk_scu_attach_pd(&pdev->dev, rsrc_id);
if (ret)
......
......@@ -575,31 +575,11 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct hv_device *hv_dev = device_to_hv_device(dev);
char *driver_override, *old, *cp;
/* We need to keep extra room for a newline */
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
device_lock(dev);
old = hv_dev->driver_override;
if (strlen(driver_override)) {
hv_dev->driver_override = driver_override;
} else {
kfree(driver_override);
hv_dev->driver_override = NULL;
}
device_unlock(dev);
int ret;
kfree(old);
ret = driver_set_override(dev, &hv_dev->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -567,31 +567,11 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct pci_dev *pdev = to_pci_dev(dev);
char *driver_override, *old, *cp;
/* We need to keep extra room for a newline */
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
device_lock(dev);
old = pdev->driver_override;
if (strlen(driver_override)) {
pdev->driver_override = driver_override;
} else {
kfree(driver_override);
pdev->driver_override = NULL;
}
device_unlock(dev);
int ret;
kfree(old);
ret = driver_set_override(dev, &pdev->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -400,7 +400,8 @@ field##_store(struct device *dev, struct device_attribute *attr, \
const char *buf, size_t sz) \
{ \
struct rpmsg_device *rpdev = to_rpmsg_device(dev); \
char *new, *old; \
const char *old; \
char *new; \
\
new = kstrndup(buf, sz, GFP_KERNEL); \
if (!new) \
......@@ -592,24 +593,51 @@ static struct bus_type rpmsg_bus = {
.remove = rpmsg_dev_remove,
};
int rpmsg_register_device(struct rpmsg_device *rpdev)
/*
* A helper for registering rpmsg device with driver override and name.
* Drivers should not be using it, but instead rpmsg_register_device().
*/
int rpmsg_register_device_override(struct rpmsg_device *rpdev,
const char *driver_override)
{
struct device *dev = &rpdev->dev;
int ret;
dev_set_name(&rpdev->dev, "%s.%s.%d.%d", dev_name(dev->parent),
if (driver_override)
strcpy(rpdev->id.name, driver_override);
dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
rpdev->id.name, rpdev->src, rpdev->dst);
rpdev->dev.bus = &rpmsg_bus;
dev->bus = &rpmsg_bus;
ret = device_register(&rpdev->dev);
device_initialize(dev);
if (driver_override) {
ret = driver_set_override(dev, &rpdev->driver_override,
driver_override,
strlen(driver_override));
if (ret) {
dev_err(dev, "device_set_override failed: %d\n", ret);
return ret;
}
}
ret = device_add(dev);
if (ret) {
dev_err(dev, "device_register failed: %d\n", ret);
put_device(&rpdev->dev);
dev_err(dev, "device_add failed: %d\n", ret);
kfree(rpdev->driver_override);
rpdev->driver_override = NULL;
put_device(dev);
}
return ret;
}
EXPORT_SYMBOL(rpmsg_register_device_override);
int rpmsg_register_device(struct rpmsg_device *rpdev)
{
return rpmsg_register_device_override(rpdev, NULL);
}
EXPORT_SYMBOL(rpmsg_register_device);
/*
......
......@@ -94,10 +94,7 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev,
*/
static inline int rpmsg_ctrldev_register_device(struct rpmsg_device *rpdev)
{
strcpy(rpdev->id.name, "rpmsg_ctrl");
rpdev->driver_override = "rpmsg_ctrl";
return rpmsg_register_device(rpdev);
return rpmsg_register_device_override(rpdev, "rpmsg_ctrl");
}
#endif
......@@ -20,12 +20,10 @@
*/
int rpmsg_ns_register_device(struct rpmsg_device *rpdev)
{
strcpy(rpdev->id.name, "rpmsg_ns");
rpdev->driver_override = "rpmsg_ns";
rpdev->src = RPMSG_NS_ADDR;
rpdev->dst = RPMSG_NS_ADDR;
return rpmsg_register_device(rpdev);
return rpmsg_register_device_override(rpdev, "rpmsg_ns");
}
EXPORT_SYMBOL(rpmsg_ns_register_device);
......
......@@ -103,7 +103,11 @@ struct subchannel {
struct work_struct todo_work;
struct schib_config config;
u64 dma_mask;
char *driver_override; /* Driver name to force a match */
/*
* Driver name to force a match. Do not set directly, because core
* frees it. Use driver_set_override() to set or clear it.
*/
const char *driver_override;
} __attribute__ ((aligned(8)));
DECLARE_PER_CPU_ALIGNED(struct irb, cio_irb);
......
......@@ -338,31 +338,11 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct subchannel *sch = to_subchannel(dev);
char *driver_override, *old, *cp;
/* We need to keep extra room for a newline */
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
device_lock(dev);
old = sch->driver_override;
if (strlen(driver_override)) {
sch->driver_override = driver_override;
} else {
kfree(driver_override);
sch->driver_override = NULL;
}
device_unlock(dev);
int ret;
kfree(old);
ret = driver_set_override(dev, &sch->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -1434,6 +1434,7 @@ static int of_qcom_slim_ngd_register(struct device *parent,
const struct of_device_id *match;
struct device_node *node;
u32 id;
int ret;
match = of_match_node(qcom_slim_ngd_dt_match, parent->of_node);
data = match->data;
......@@ -1455,7 +1456,17 @@ static int of_qcom_slim_ngd_register(struct device *parent,
}
ngd->id = id;
ngd->pdev->dev.parent = parent;
ngd->pdev->driver_override = QCOM_SLIM_NGD_DRV_NAME;
ret = driver_set_override(&ngd->pdev->dev,
&ngd->pdev->driver_override,
QCOM_SLIM_NGD_DRV_NAME,
strlen(QCOM_SLIM_NGD_DRV_NAME));
if (ret) {
platform_device_put(ngd->pdev);
kfree(ngd);
of_node_put(node);
return ret;
}
ngd->pdev->dev.of_node = node;
ctrl->ngd = ngd;
......
......@@ -71,29 +71,11 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct spi_device *spi = to_spi_device(dev);
const char *end = memchr(buf, '\n', count);
const size_t len = end ? end - buf : count;
const char *driver_override, *old;
/* We need to keep extra room for a newline when displaying value */
if (len >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, len, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
int ret;
device_lock(dev);
old = spi->driver_override;
if (len) {
spi->driver_override = driver_override;
} else {
/* Empty string, disable driver override */
spi->driver_override = NULL;
kfree(driver_override);
}
device_unlock(dev);
kfree(old);
ret = driver_set_override(dev, &spi->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -77,32 +77,11 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count)
{
struct vdpa_device *vdev = dev_to_vdpa(dev);
const char *driver_override, *old;
char *cp;
int ret;
/* We need to keep extra room for a newline */
if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
if (!driver_override)
return -ENOMEM;
cp = strchr(driver_override, '\n');
if (cp)
*cp = '\0';
device_lock(dev);
old = vdev->driver_override;
if (strlen(driver_override)) {
vdev->driver_override = driver_override;
} else {
kfree(driver_override);
vdev->driver_override = NULL;
}
device_unlock(dev);
kfree(old);
ret = driver_set_override(dev, &vdev->driver_override, buf, count);
if (ret)
return ret;
return count;
}
......
......@@ -18,7 +18,15 @@
#include "kernfs-internal.h"
static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */
static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by rename_lock */
/*
* Don't use rename_lock to piggy back on pr_cont_buf. We don't want to
* call pr_cont() while holding rename_lock. Because sometimes pr_cont()
* will perform wakeups when releasing console_sem. Holding rename_lock
* will introduce deadlock if the scheduler reads the kernfs_name in the
* wakeup path.
*/
static DEFINE_SPINLOCK(kernfs_pr_cont_lock);
static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by pr_cont_lock */
static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */
#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb)
......@@ -229,12 +237,12 @@ void pr_cont_kernfs_name(struct kernfs_node *kn)
{
unsigned long flags;
spin_lock_irqsave(&kernfs_rename_lock, flags);
spin_lock_irqsave(&kernfs_pr_cont_lock, flags);
kernfs_name_locked(kn, kernfs_pr_cont_buf, sizeof(kernfs_pr_cont_buf));
kernfs_name(kn, kernfs_pr_cont_buf, sizeof(kernfs_pr_cont_buf));
pr_cont("%s", kernfs_pr_cont_buf);
spin_unlock_irqrestore(&kernfs_rename_lock, flags);
spin_unlock_irqrestore(&kernfs_pr_cont_lock, flags);
}
/**
......@@ -248,10 +256,10 @@ void pr_cont_kernfs_path(struct kernfs_node *kn)
unsigned long flags;
int sz;
spin_lock_irqsave(&kernfs_rename_lock, flags);
spin_lock_irqsave(&kernfs_pr_cont_lock, flags);
sz = kernfs_path_from_node_locked(kn, NULL, kernfs_pr_cont_buf,
sizeof(kernfs_pr_cont_buf));
sz = kernfs_path_from_node(kn, NULL, kernfs_pr_cont_buf,
sizeof(kernfs_pr_cont_buf));
if (sz < 0) {
pr_cont("(error)");
goto out;
......@@ -265,7 +273,7 @@ void pr_cont_kernfs_path(struct kernfs_node *kn)
pr_cont("%s", kernfs_pr_cont_buf);
out:
spin_unlock_irqrestore(&kernfs_rename_lock, flags);
spin_unlock_irqrestore(&kernfs_pr_cont_lock, flags);
}
/**
......@@ -823,13 +831,12 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent,
lockdep_assert_held_read(&kernfs_root(parent)->kernfs_rwsem);
/* grab kernfs_rename_lock to piggy back on kernfs_pr_cont_buf */
spin_lock_irq(&kernfs_rename_lock);
spin_lock_irq(&kernfs_pr_cont_lock);
len = strlcpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf));
if (len >= sizeof(kernfs_pr_cont_buf)) {
spin_unlock_irq(&kernfs_rename_lock);
spin_unlock_irq(&kernfs_pr_cont_lock);
return NULL;
}
......@@ -841,7 +848,7 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent,
parent = kernfs_find_ns(parent, name, ns);
}
spin_unlock_irq(&kernfs_rename_lock);
spin_unlock_irq(&kernfs_pr_cont_lock);
return parent;
}
......
......@@ -33,7 +33,6 @@ static DEFINE_SPINLOCK(kernfs_open_node_lock);
static DEFINE_MUTEX(kernfs_open_file_mutex);
struct kernfs_open_node {
atomic_t refcnt;
atomic_t event;
wait_queue_head_t poll;
struct list_head files; /* goes through kernfs_open_file.list */
......@@ -530,10 +529,8 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
}
on = kn->attr.open;
if (on) {
atomic_inc(&on->refcnt);
if (on)
list_add_tail(&of->list, &on->files);
}
spin_unlock_irq(&kernfs_open_node_lock);
mutex_unlock(&kernfs_open_file_mutex);
......@@ -548,7 +545,6 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
if (!new_on)
return -ENOMEM;
atomic_set(&new_on->refcnt, 0);
atomic_set(&new_on->event, 1);
init_waitqueue_head(&new_on->poll);
INIT_LIST_HEAD(&new_on->files);
......@@ -556,17 +552,19 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
}
/**
* kernfs_put_open_node - put kernfs_open_node
* @kn: target kernfs_nodet
* kernfs_unlink_open_file - Unlink @of from @kn.
*
* @kn: target kernfs_node
* @of: associated kernfs_open_file
*
* Put @kn->attr.open and unlink @of from the files list. If
* reference count reaches zero, disassociate and free it.
* Unlink @of from list of @kn's associated open files. If list of
* associated open files becomes empty, disassociate and free
* kernfs_open_node.
*
* LOCKING:
* None.
*/
static void kernfs_put_open_node(struct kernfs_node *kn,
static void kernfs_unlink_open_file(struct kernfs_node *kn,
struct kernfs_open_file *of)
{
struct kernfs_open_node *on = kn->attr.open;
......@@ -578,7 +576,7 @@ static void kernfs_put_open_node(struct kernfs_node *kn,
if (of)
list_del(&of->list);
if (atomic_dec_and_test(&on->refcnt))
if (list_empty(&on->files))
kn->attr.open = NULL;
else
on = NULL;
......@@ -706,7 +704,7 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
return 0;
err_put_node:
kernfs_put_open_node(kn, of);
kernfs_unlink_open_file(kn, of);
err_seq_release:
seq_release(inode, file);
err_free:
......@@ -752,7 +750,7 @@ static int kernfs_fop_release(struct inode *inode, struct file *filp)
mutex_unlock(&kernfs_open_file_mutex);
}
kernfs_put_open_node(kn, of);
kernfs_unlink_open_file(kn, of);
seq_release(inode, filp);
kfree(of->prealloc_buf);
kfree(of);
......@@ -768,15 +766,24 @@ void kernfs_drain_open_files(struct kernfs_node *kn)
if (!(kn->flags & (KERNFS_HAS_MMAP | KERNFS_HAS_RELEASE)))
return;
spin_lock_irq(&kernfs_open_node_lock);
on = kn->attr.open;
if (on)
atomic_inc(&on->refcnt);
spin_unlock_irq(&kernfs_open_node_lock);
if (!on)
/*
* lockless opportunistic check is safe below because no one is adding to
* ->attr.open at this point of time. This check allows early bail out
* if ->attr.open is already NULL. kernfs_unlink_open_file makes
* ->attr.open NULL only while holding kernfs_open_file_mutex so below
* check under kernfs_open_file_mutex will ensure bailing out if
* ->attr.open became NULL while waiting for the mutex.
*/
if (!kn->attr.open)
return;
mutex_lock(&kernfs_open_file_mutex);
if (!kn->attr.open) {
mutex_unlock(&kernfs_open_file_mutex);
return;
}
on = kn->attr.open;
list_for_each_entry(of, &on->files, list) {
struct inode *inode = file_inode(of->file);
......@@ -789,8 +796,6 @@ void kernfs_drain_open_files(struct kernfs_node *kn)
}
mutex_unlock(&kernfs_open_file_mutex);
kernfs_put_open_node(kn, NULL);
}
/*
......
......@@ -70,7 +70,11 @@ struct amba_device {
unsigned int cid;
struct amba_cs_uci_id uci;
unsigned int irq[AMBA_NR_IRQS];
char *driver_override;
/*
* Driver name to force a match. Do not set directly, because core
* frees it. Use driver_set_override() to set or clear it.
*/
const char *driver_override;
};
struct amba_driver {
......
......@@ -386,6 +386,75 @@ struct dev_msi_info {
#endif
};
/**
* enum device_physical_location_panel - Describes which panel surface of the
* system's housing the device connection point resides on.
* @DEVICE_PANEL_TOP: Device connection point is on the top panel.
* @DEVICE_PANEL_BOTTOM: Device connection point is on the bottom panel.
* @DEVICE_PANEL_LEFT: Device connection point is on the left panel.
* @DEVICE_PANEL_RIGHT: Device connection point is on the right panel.
* @DEVICE_PANEL_FRONT: Device connection point is on the front panel.
* @DEVICE_PANEL_BACK: Device connection point is on the back panel.
* @DEVICE_PANEL_UNKNOWN: The panel with device connection point is unknown.
*/
enum device_physical_location_panel {
DEVICE_PANEL_TOP,
DEVICE_PANEL_BOTTOM,
DEVICE_PANEL_LEFT,
DEVICE_PANEL_RIGHT,
DEVICE_PANEL_FRONT,
DEVICE_PANEL_BACK,
DEVICE_PANEL_UNKNOWN,
};
/**
* enum device_physical_location_vertical_position - Describes vertical
* position of the device connection point on the panel surface.
* @DEVICE_VERT_POS_UPPER: Device connection point is at upper part of panel.
* @DEVICE_VERT_POS_CENTER: Device connection point is at center part of panel.
* @DEVICE_VERT_POS_LOWER: Device connection point is at lower part of panel.
*/
enum device_physical_location_vertical_position {
DEVICE_VERT_POS_UPPER,
DEVICE_VERT_POS_CENTER,
DEVICE_VERT_POS_LOWER,
};
/**
* enum device_physical_location_horizontal_position - Describes horizontal
* position of the device connection point on the panel surface.
* @DEVICE_HORI_POS_LEFT: Device connection point is at left part of panel.
* @DEVICE_HORI_POS_CENTER: Device connection point is at center part of panel.
* @DEVICE_HORI_POS_RIGHT: Device connection point is at right part of panel.
*/
enum device_physical_location_horizontal_position {
DEVICE_HORI_POS_LEFT,
DEVICE_HORI_POS_CENTER,
DEVICE_HORI_POS_RIGHT,
};
/**
* struct device_physical_location - Device data related to physical location
* of the device connection point.
* @panel: Panel surface of the system's housing that the device connection
* point resides on.
* @vertical_position: Vertical position of the device connection point within
* the panel.
* @horizontal_position: Horizontal position of the device connection point
* within the panel.
* @dock: Set if the device connection point resides in a docking station or
* port replicator.
* @lid: Set if this device connection point resides on the lid of laptop
* system.
*/
struct device_physical_location {
enum device_physical_location_panel panel;
enum device_physical_location_vertical_position vertical_position;
enum device_physical_location_horizontal_position horizontal_position;
bool dock;
bool lid;
};
/**
* struct device - The basic device structure
* @parent: The device's "parent" device, the device to which it is attached.
......@@ -451,6 +520,8 @@ struct dev_msi_info {
* device (i.e. the bus driver that discovered the device).
* @iommu_group: IOMMU group the device belongs to.
* @iommu: Per device generic IOMMU runtime data
* @physical_location: Describes physical location of the device connection
* point in the system housing.
* @removable: Whether the device can be removed from the system. This
* should be set by the subsystem / bus driver that discovered
* the device.
......@@ -562,6 +633,8 @@ struct device {
struct iommu_group *iommu_group;
struct dev_iommu *iommu;
struct device_physical_location *physical_location;
enum device_removable removable;
bool offline_disabled:1;
......
......@@ -151,6 +151,8 @@ extern int __must_check driver_create_file(struct device_driver *driver,
extern void driver_remove_file(struct device_driver *driver,
const struct driver_attribute *attr);
int driver_set_override(struct device *dev, const char **override,
const char *s, size_t len);
extern int __must_check driver_for_each_device(struct device_driver *drv,
struct device *start,
void *data,
......
......@@ -2,6 +2,8 @@
#ifndef _LINUX_EXPORT_H
#define _LINUX_EXPORT_H
#include <linux/stringify.h>
/*
* Export symbols from the kernel to modules. Forked from module.h
* to reduce the amount of pointless cruft we feed to gcc when only
......@@ -140,7 +142,6 @@ struct kernel_symbol {
#endif /* CONFIG_MODULES */
#ifdef DEFAULT_SYMBOL_NAMESPACE
#include <linux/stringify.h>
#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE))
#else
#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
......@@ -148,8 +149,8 @@ struct kernel_symbol {
#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_gpl")
#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", #ns)
#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", #ns)
#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", __stringify(ns))
#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", __stringify(ns))
#endif /* !__ASSEMBLY__ */
......
......@@ -17,6 +17,64 @@ struct firmware {
void *priv;
};
/**
* enum fw_upload_err - firmware upload error codes
* @FW_UPLOAD_ERR_NONE: returned to indicate success
* @FW_UPLOAD_ERR_HW_ERROR: error signalled by hardware, see kernel log
* @FW_UPLOAD_ERR_TIMEOUT: SW timed out on handshake with HW/firmware
* @FW_UPLOAD_ERR_CANCELED: upload was cancelled by the user
* @FW_UPLOAD_ERR_BUSY: there is an upload operation already in progress
* @FW_UPLOAD_ERR_INVALID_SIZE: invalid firmware image size
* @FW_UPLOAD_ERR_RW_ERROR: read or write to HW failed, see kernel log
* @FW_UPLOAD_ERR_WEAROUT: FLASH device is approaching wear-out, wait & retry
* @FW_UPLOAD_ERR_MAX: Maximum error code marker
*/
enum fw_upload_err {
FW_UPLOAD_ERR_NONE,
FW_UPLOAD_ERR_HW_ERROR,
FW_UPLOAD_ERR_TIMEOUT,
FW_UPLOAD_ERR_CANCELED,
FW_UPLOAD_ERR_BUSY,
FW_UPLOAD_ERR_INVALID_SIZE,
FW_UPLOAD_ERR_RW_ERROR,
FW_UPLOAD_ERR_WEAROUT,
FW_UPLOAD_ERR_MAX
};
struct fw_upload {
void *dd_handle; /* reference to parent driver */
void *priv; /* firmware loader private fields */
};
/**
* struct fw_upload_ops - device specific operations to support firmware upload
* @prepare: Required: Prepare secure update
* @write: Required: The write() op receives the remaining
* size to be written and must return the actual
* size written or a negative error code. The write()
* op will be called repeatedly until all data is
* written.
* @poll_complete: Required: Check for the completion of the
* HW authentication/programming process.
* @cancel: Required: Request cancellation of update. This op
* is called from the context of a different kernel
* thread, so race conditions need to be considered.
* @cleanup: Optional: Complements the prepare()
* function and is called at the completion
* of the update, on success or failure, if the
* prepare function succeeded.
*/
struct fw_upload_ops {
enum fw_upload_err (*prepare)(struct fw_upload *fw_upload,
const u8 *data, u32 size);
enum fw_upload_err (*write)(struct fw_upload *fw_upload,
const u8 *data, u32 offset,
u32 size, u32 *written);
enum fw_upload_err (*poll_complete)(struct fw_upload *fw_upload);
void (*cancel)(struct fw_upload *fw_upload);
void (*cleanup)(struct fw_upload *fw_upload);
};
struct module;
struct device;
......@@ -112,6 +170,30 @@ static inline int request_partial_firmware_into_buf
#endif
#ifdef CONFIG_FW_UPLOAD
struct fw_upload *
firmware_upload_register(struct module *module, struct device *parent,
const char *name, const struct fw_upload_ops *ops,
void *dd_handle);
void firmware_upload_unregister(struct fw_upload *fw_upload);
#else
static inline struct fw_upload *
firmware_upload_register(struct module *module, struct device *parent,
const char *name, const struct fw_upload_ops *ops,
void *dd_handle)
{
return ERR_PTR(-EINVAL);
}
static inline void firmware_upload_unregister(struct fw_upload *fw_upload)
{
}
#endif
int firmware_request_cache(struct device *device, const char *name);
#endif
......@@ -178,7 +178,9 @@ struct fsl_mc_obj_desc {
* @regions: pointer to array of MMIO region entries
* @irqs: pointer to array of pointers to interrupts allocated to this device
* @resource: generic resource associated with this MC object device, if any.
* @driver_override: driver name to force a match
* @driver_override: driver name to force a match; do not set directly,
* because core frees it; use driver_set_override() to
* set or clear it.
*
* Generic device object for MC object devices that are "attached" to a
* MC bus.
......@@ -212,7 +214,7 @@ struct fsl_mc_device {
struct fsl_mc_device_irq **irqs;
struct fsl_mc_resource *resource;
struct device_link *consumer_link;
char *driver_override;
const char *driver_override;
};
#define to_fsl_mc_device(_dev) \
......
......@@ -1292,7 +1292,11 @@ struct hv_device {
u16 device_id;
struct device device;
char *driver_override; /* Driver name to force a match */
/*
* Driver name to force a match. Do not set directly, because core
* frees it. Use driver_set_override() to set or clear it.
*/
const char *driver_override;
struct vmbus_channel *channel;
struct kset *channels_kset;
......
......@@ -512,7 +512,11 @@ struct pci_dev {
u16 acs_cap; /* ACS Capability offset */
phys_addr_t rom; /* Physical address if not from BAR */
size_t romlen; /* Length if not from BAR */
char *driver_override; /* Driver name to force a match */
/*
* Driver name to force a match. Do not set directly, because core
* frees it. Use driver_set_override() to set or clear it.
*/
const char *driver_override;
unsigned long priv_flags; /* Private flags for the PCI driver */
......
......@@ -31,7 +31,11 @@ struct platform_device {
struct resource *resource;
const struct platform_device_id *id_entry;
char *driver_override; /* Driver name to force a match */
/*
* Driver name to force a match. Do not set directly, because core
* frees it. Use driver_set_override() to set or clear it.
*/
const char *driver_override;
/* MFD cell pointer */
struct mfd_cell *mfd_cell;
......
......@@ -41,7 +41,9 @@ struct rpmsg_channel_info {
* rpmsg_device - device that belong to the rpmsg bus
* @dev: the device struct
* @id: device id (used to match between rpmsg drivers and devices)
* @driver_override: driver name to force a match
* @driver_override: driver name to force a match; do not set directly,
* because core frees it; use driver_set_override() to
* set or clear it.
* @src: local address
* @dst: destination address
* @ept: the rpmsg endpoint of this channel
......@@ -51,7 +53,7 @@ struct rpmsg_channel_info {
struct rpmsg_device {
struct device dev;
struct rpmsg_device_id id;
char *driver_override;
const char *driver_override;
u32 src;
u32 dst;
struct rpmsg_endpoint *ept;
......@@ -163,6 +165,8 @@ static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val)
#if IS_ENABLED(CONFIG_RPMSG)
int rpmsg_register_device_override(struct rpmsg_device *rpdev,
const char *driver_override);
int rpmsg_register_device(struct rpmsg_device *rpdev);
int rpmsg_unregister_device(struct device *parent,
struct rpmsg_channel_info *chinfo);
......@@ -190,6 +194,12 @@ ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept);
#else
static inline int rpmsg_register_device_override(struct rpmsg_device *rpdev,
const char *driver_override)
{
return -ENXIO;
}
static inline int rpmsg_register_device(struct rpmsg_device *rpdev)
{
return -ENXIO;
......
......@@ -138,6 +138,8 @@ extern int spi_delay_exec(struct spi_delay *_delay, struct spi_transfer *xfer);
* for driver coldplugging, and in uevents used for hotplugging
* @driver_override: If the name of a driver is written to this attribute, then
* the device will bind to the named driver and only the named driver.
* Do not set directly, because core frees it; use driver_set_override() to
* set or clear it.
* @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when
* not using a GPIO line)
* @word_delay: delay to be inserted between consecutive
......
......@@ -64,7 +64,9 @@ struct vdpa_mgmt_dev;
* struct vdpa_device - representation of a vDPA device
* @dev: underlying device
* @dma_dev: the actual device that is performing DMA
* @driver_override: driver name to force a match
* @driver_override: driver name to force a match; do not set directly,
* because core frees it; use driver_set_override() to
* set or clear it.
* @config: the configuration ops for this device.
* @cf_lock: Protects get and set access to configuration layout.
* @index: device index
......
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM thermal_pressure
#if !defined(_TRACE_THERMAL_PRESSURE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_THERMAL_PRESSURE_H
#include <linux/tracepoint.h>
TRACE_EVENT(thermal_pressure_update,
TP_PROTO(int cpu, unsigned long thermal_pressure),
TP_ARGS(cpu, thermal_pressure),
TP_STRUCT__entry(
__field(unsigned long, thermal_pressure)
__field(int, cpu)
),
TP_fast_assign(
__entry->thermal_pressure = thermal_pressure;
__entry->cpu = cpu;
),
TP_printk("cpu=%d thermal_pressure=%lu", __entry->cpu, __entry->thermal_pressure)
);
#endif /* _TRACE_THERMAL_PRESSURE_H */
/* This part must be outside protection */
#include <trace/define_trace.h>
This diff is collapsed.
......@@ -981,11 +981,11 @@ __END__
=head1 NAME
abi_book.pl - parse the Linux ABI files and produce a ReST book.
get_abi.pl - parse the Linux ABI files and produce a ReST book.
=head1 SYNOPSIS
B<abi_book.pl> [--debug <level>] [--enable-lineno] [--man] [--help]
B<get_abi.pl> [--debug <level>] [--enable-lineno] [--man] [--help]
[--(no-)rst-source] [--dir=<dir>] [--show-hints]
[--search-string <regex>]
<COMMAND> [<ARGUMENT>]
......
......@@ -4,7 +4,7 @@ CFLAGS = -Wall \
-O2
TEST_PROGS := fw_run_tests.sh
TEST_FILES := fw_fallback.sh fw_filesystem.sh fw_lib.sh
TEST_FILES := fw_fallback.sh fw_filesystem.sh fw_upload.sh fw_lib.sh
TEST_GEN_FILES := fw_namespace
include ../lib.mk
......@@ -3,3 +3,4 @@ CONFIG_FW_LOADER=y
CONFIG_FW_LOADER_USER_HELPER=y
CONFIG_IKCONFIG=y
CONFIG_IKCONFIG_PROC=y
CONFIG_FW_UPLOAD=y
......@@ -11,6 +11,9 @@ TEST_REQS_FW_SET_CUSTOM_PATH="yes"
TEST_DIR=$(dirname $0)
source $TEST_DIR/fw_lib.sh
RUN_XZ="xz -C crc32 --lzma2=dict=2MiB"
RUN_ZSTD="zstd -q"
check_mods
check_setup
verify_reqs
......@@ -211,7 +214,7 @@ read_firmwares()
else
fwfile="$FW"
fi
if [ "$1" = "xzonly" ]; then
if [ "$1" = "componly" ]; then
fwfile="${fwfile}-orig"
fi
for i in $(seq 0 3); do
......@@ -235,7 +238,7 @@ read_partial_firmwares()
fwfile="${FW}"
fi
if [ "$1" = "xzonly" ]; then
if [ "$1" = "componly" ]; then
fwfile="${fwfile}-orig"
fi
......@@ -409,10 +412,8 @@ test_request_firmware_nowait_custom()
config_unset_uevent
RANDOM_FILE_PATH=$(setup_random_file)
RANDOM_FILE="$(basename $RANDOM_FILE_PATH)"
if [ "$2" = "both" ]; then
xz -9 -C crc32 -k $RANDOM_FILE_PATH
elif [ "$2" = "xzonly" ]; then
xz -9 -C crc32 $RANDOM_FILE_PATH
if [ -n "$2" -a "$2" != "normal" ]; then
compress_"$2"_"$COMPRESS_FORMAT" $RANDOM_FILE_PATH
fi
config_set_name $RANDOM_FILE
config_trigger_async
......@@ -435,6 +436,32 @@ test_request_partial_firmware_into_buf()
echo "OK"
}
do_tests ()
{
mode="$1"
suffix="$2"
for i in $(seq 1 5); do
test_batched_request_firmware$suffix $i $mode
done
for i in $(seq 1 5); do
test_batched_request_firmware_into_buf$suffix $i $mode
done
for i in $(seq 1 5); do
test_batched_request_firmware_direct$suffix $i $mode
done
for i in $(seq 1 5); do
test_request_firmware_nowait_uevent$suffix $i $mode
done
for i in $(seq 1 5); do
test_request_firmware_nowait_custom$suffix $i $mode
done
}
# Only continue if batched request triggers are present on the
# test-firmware driver
test_config_present
......@@ -442,25 +469,7 @@ test_config_present
# test with the file present
echo
echo "Testing with the file present..."
for i in $(seq 1 5); do
test_batched_request_firmware $i normal
done
for i in $(seq 1 5); do
test_batched_request_firmware_into_buf $i normal
done
for i in $(seq 1 5); do
test_batched_request_firmware_direct $i normal
done
for i in $(seq 1 5); do
test_request_firmware_nowait_uevent $i normal
done
for i in $(seq 1 5); do
test_request_firmware_nowait_custom $i normal
done
do_tests normal
# Partial loads cannot use fallback, so do not repeat tests.
test_request_partial_firmware_into_buf 0 10
......@@ -472,25 +481,7 @@ test_request_partial_firmware_into_buf 2 10
# a hung task, which would require a hard reset.
echo
echo "Testing with the file missing..."
for i in $(seq 1 5); do
test_batched_request_firmware_nofile $i
done
for i in $(seq 1 5); do
test_batched_request_firmware_into_buf_nofile $i
done
for i in $(seq 1 5); do
test_batched_request_firmware_direct_nofile $i
done
for i in $(seq 1 5); do
test_request_firmware_nowait_uevent_nofile $i
done
for i in $(seq 1 5); do
test_request_firmware_nowait_custom_nofile $i
done
do_tests nofile _nofile
# Partial loads cannot use fallback, so do not repeat tests.
test_request_partial_firmware_into_buf_nofile 0 10
......@@ -498,55 +489,58 @@ test_request_partial_firmware_into_buf_nofile 0 5
test_request_partial_firmware_into_buf_nofile 1 6
test_request_partial_firmware_into_buf_nofile 2 10
test "$HAS_FW_LOADER_COMPRESS" != "yes" && exit 0
test_request_firmware_compressed ()
{
export COMPRESS_FORMAT="$1"
# test with both files present
xz -9 -C crc32 -k $FW
config_set_name $NAME
echo
echo "Testing with both plain and xz files present..."
for i in $(seq 1 5); do
test_batched_request_firmware $i both
done
# test with both files present
compress_both_"$COMPRESS_FORMAT" $FW
compress_both_"$COMPRESS_FORMAT" $FW_INTO_BUF
for i in $(seq 1 5); do
test_batched_request_firmware_into_buf $i both
done
config_set_name $NAME
echo
echo "Testing with both plain and $COMPRESS_FORMAT files present..."
do_tests both
for i in $(seq 1 5); do
test_batched_request_firmware_direct $i both
done
# test with only compressed file present
mv "$FW" "${FW}-orig"
mv "$FW_INTO_BUF" "${FW_INTO_BUF}-orig"
for i in $(seq 1 5); do
test_request_firmware_nowait_uevent $i both
done
config_set_name $NAME
echo
echo "Testing with only $COMPRESS_FORMAT file present..."
do_tests componly
for i in $(seq 1 5); do
test_request_firmware_nowait_custom $i both
done
mv "${FW}-orig" "$FW"
mv "${FW_INTO_BUF}-orig" "$FW_INTO_BUF"
}
# test with only xz file present
mv "$FW" "${FW}-orig"
echo
echo "Testing with only xz file present..."
for i in $(seq 1 5); do
test_batched_request_firmware $i xzonly
done
for i in $(seq 1 5); do
test_batched_request_firmware_into_buf $i xzonly
done
for i in $(seq 1 5); do
test_batched_request_firmware_direct $i xzonly
done
for i in $(seq 1 5); do
test_request_firmware_nowait_uevent $i xzonly
done
for i in $(seq 1 5); do
test_request_firmware_nowait_custom $i xzonly
done
compress_both_XZ ()
{
$RUN_XZ -k "$@"
}
compress_componly_XZ ()
{
$RUN_XZ "$@"
}
compress_both_ZSTD ()
{
$RUN_ZSTD -k "$@"
}
compress_componly_ZSTD ()
{
$RUN_ZSTD --rm "$@"
}
if test "$HAS_FW_LOADER_COMPRESS_XZ" = "yes"; then
test_request_firmware_compressed XZ
fi
if test "$HAS_FW_LOADER_COMPRESS_ZSTD" = "yes"; then
test_request_firmware_compressed ZSTD
fi
exit 0
......@@ -62,7 +62,9 @@ check_setup()
{
HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)"
HAS_FW_LOADER_USER_HELPER_FALLBACK="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)"
HAS_FW_LOADER_COMPRESS="$(kconfig_has CONFIG_FW_LOADER_COMPRESS=y)"
HAS_FW_LOADER_COMPRESS_XZ="$(kconfig_has CONFIG_FW_LOADER_COMPRESS_XZ=y)"
HAS_FW_LOADER_COMPRESS_ZSTD="$(kconfig_has CONFIG_FW_LOADER_COMPRESS_ZSTD=y)"
HAS_FW_UPLOAD="$(kconfig_has CONFIG_FW_UPLOAD=y)"
PROC_FW_IGNORE_SYSFS_FALLBACK="0"
PROC_FW_FORCE_SYSFS_FALLBACK="0"
......@@ -98,9 +100,14 @@ check_setup()
OLD_FWPATH="$(cat /sys/module/firmware_class/parameters/path)"
if [ "$HAS_FW_LOADER_COMPRESS" = "yes" ]; then
if [ "$HAS_FW_LOADER_COMPRESS_XZ" = "yes" ]; then
if ! which xz 2> /dev/null > /dev/null; then
HAS_FW_LOADER_COMPRESS=""
HAS_FW_LOADER_COMPRESS_XZ=""
fi
fi
if [ "$HAS_FW_LOADER_COMPRESS_ZSTD" = "yes" ]; then
if ! which zstd 2> /dev/null > /dev/null; then
HAS_FW_LOADER_COMPRESS_ZSTD=""
fi
fi
}
......@@ -113,6 +120,12 @@ verify_reqs()
exit 0
fi
fi
if [ "$TEST_REQS_FW_UPLOAD" = "yes" ]; then
if [ ! "$HAS_FW_UPLOAD" = "yes" ]; then
echo "firmware upload disabled so ignoring test"
exit 0
fi
fi
}
setup_tmp_file()
......
......@@ -22,6 +22,10 @@ run_tests()
proc_set_force_sysfs_fallback $1
proc_set_ignore_sysfs_fallback $2
$TEST_DIR/fw_fallback.sh
proc_set_force_sysfs_fallback $1
proc_set_ignore_sysfs_fallback $2
$TEST_DIR/fw_upload.sh
}
run_test_config_0001()
......
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This validates the user-initiated fw upload mechanism of the firmware
# loader. It verifies that one or more firmware devices can be created
# for a device driver. It also verifies the data transfer, the
# cancellation support, and the error flows.
set -e
TEST_REQS_FW_UPLOAD="yes"
TEST_DIR=$(dirname $0)
progress_states="preparing transferring programming"
errors="hw-error
timeout
device-busy
invalid-file-size
read-write-error
flash-wearout"
error_abort="user-abort"
fwname1=fw1
fwname2=fw2
fwname3=fw3
source $TEST_DIR/fw_lib.sh
check_mods
check_setup
verify_reqs
trap "upload_finish" EXIT
upload_finish() {
local fwdevs="$fwname1 $fwname2 $fwname3"
for name in $fwdevs; do
if [ -e "$DIR/$name" ]; then
echo -n "$name" > "$DIR"/upload_unregister
fi
done
}
upload_fw() {
local name="$1"
local file="$2"
echo 1 > "$DIR"/"$name"/loading
cat "$file" > "$DIR"/"$name"/data
echo 0 > "$DIR"/"$name"/loading
}
verify_fw() {
local name="$1"
local file="$2"
echo -n "$name" > "$DIR"/config_upload_name
if ! cmp "$file" "$DIR"/upload_read > /dev/null 2>&1; then
echo "$0: firmware compare for $name did not match" >&2
exit 1
fi
echo "$0: firmware upload for $name works" >&2
return 0
}
inject_error() {
local name="$1"
local status="$2"
local error="$3"
echo 1 > "$DIR"/"$name"/loading
echo -n "inject":"$status":"$error" > "$DIR"/"$name"/data
echo 0 > "$DIR"/"$name"/loading
}
await_status() {
local name="$1"
local expected="$2"
local status
local i
let i=0
while [ $i -lt 50 ]; do
status=$(cat "$DIR"/"$name"/status)
if [ "$status" = "$expected" ]; then
return 0;
fi
sleep 1e-03
let i=$i+1
done
echo "$0: Invalid status: Expected $expected, Actual $status" >&2
return 1;
}
await_idle() {
local name="$1"
await_status "$name" "idle"
return $?
}
expect_error() {
local name="$1"
local expected="$2"
local error=$(cat "$DIR"/"$name"/error)
if [ "$error" != "$expected" ]; then
echo "Invalid error: Expected $expected, Actual $error" >&2
return 1
fi
return 0
}
random_firmware() {
local bs="$1"
local count="$2"
local file=$(mktemp -p /tmp uploadfwXXX.bin)
dd if=/dev/urandom of="$file" bs="$bs" count="$count" > /dev/null 2>&1
echo "$file"
}
test_upload_cancel() {
local name="$1"
local status
for status in $progress_states; do
inject_error $name $status $error_abort
if ! await_status $name $status; then
exit 1
fi
echo 1 > "$DIR"/"$name"/cancel
if ! await_idle $name; then
exit 1
fi
if ! expect_error $name "$status":"$error_abort"; then
exit 1
fi
done
echo "$0: firmware upload cancellation works"
return 0
}
test_error_handling() {
local name=$1
local status
local error
for status in $progress_states; do
for error in $errors; do
inject_error $name $status $error
if ! await_idle $name; then
exit 1
fi
if ! expect_error $name "$status":"$error"; then
exit 1
fi
done
done
echo "$0: firmware upload error handling works"
}
test_fw_too_big() {
local name=$1
local fw_too_big=`random_firmware 512 5`
local expected="preparing:invalid-file-size"
upload_fw $name $fw_too_big
rm -f $fw_too_big
if ! await_idle $name; then
exit 1
fi
if ! expect_error $name $expected; then
exit 1
fi
echo "$0: oversized firmware error handling works"
}
echo -n "$fwname1" > "$DIR"/upload_register
echo -n "$fwname2" > "$DIR"/upload_register
echo -n "$fwname3" > "$DIR"/upload_register
test_upload_cancel $fwname1
test_error_handling $fwname1
test_fw_too_big $fwname1
fw_file1=`random_firmware 512 4`
fw_file2=`random_firmware 512 3`
fw_file3=`random_firmware 512 2`
upload_fw $fwname1 $fw_file1
upload_fw $fwname2 $fw_file2
upload_fw $fwname3 $fw_file3
verify_fw ${fwname1} ${fw_file1}
verify_fw ${fwname2} ${fw_file2}
verify_fw ${fwname3} ${fw_file3}
echo -n "$fwname1" > "$DIR"/upload_unregister
echo -n "$fwname2" > "$DIR"/upload_unregister
echo -n "$fwname3" > "$DIR"/upload_unregister
exit 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment