2018-05-16 23:49:58 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-11-01 19:14:28 +00:00
|
|
|
/*
|
|
|
|
* FPGA Bridge Framework Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2016 Altera Corporation, All Rights Reserved.
|
2017-11-15 20:20:11 +00:00
|
|
|
* Copyright (C) 2017 Intel Corporation
|
2016-11-01 19:14:28 +00:00
|
|
|
*/
|
|
|
|
#include <linux/fpga/fpga-bridge.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
static DEFINE_IDA(fpga_bridge_ida);
|
2023-08-11 07:30:41 +00:00
|
|
|
static const struct class fpga_bridge_class;
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
/* Lock for adding/removing bridges to linked lists*/
|
2020-12-28 13:51:35 +00:00
|
|
|
static DEFINE_SPINLOCK(bridge_list_lock);
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_bridge_enable - Enable transactions on the bridge
|
|
|
|
*
|
|
|
|
* @bridge: FPGA bridge
|
|
|
|
*
|
|
|
|
* Return: 0 for success, error code otherwise.
|
|
|
|
*/
|
|
|
|
int fpga_bridge_enable(struct fpga_bridge *bridge)
|
|
|
|
{
|
|
|
|
dev_dbg(&bridge->dev, "enable\n");
|
|
|
|
|
2024-02-01 15:57:12 +00:00
|
|
|
if (bridge->br_ops->enable_set)
|
2016-11-01 19:14:28 +00:00
|
|
|
return bridge->br_ops->enable_set(bridge, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridge_enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_bridge_disable - Disable transactions on the bridge
|
|
|
|
*
|
|
|
|
* @bridge: FPGA bridge
|
|
|
|
*
|
|
|
|
* Return: 0 for success, error code otherwise.
|
|
|
|
*/
|
|
|
|
int fpga_bridge_disable(struct fpga_bridge *bridge)
|
|
|
|
{
|
|
|
|
dev_dbg(&bridge->dev, "disable\n");
|
|
|
|
|
2024-02-01 15:57:12 +00:00
|
|
|
if (bridge->br_ops->enable_set)
|
2016-11-01 19:14:28 +00:00
|
|
|
return bridge->br_ops->enable_set(bridge, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridge_disable);
|
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
static struct fpga_bridge *__fpga_bridge_get(struct device *bridge_dev,
|
2017-11-15 20:20:11 +00:00
|
|
|
struct fpga_image_info *info)
|
2016-11-01 19:14:28 +00:00
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge;
|
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
bridge = to_fpga_bridge(bridge_dev);
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
bridge->info = info;
|
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
if (!mutex_trylock(&bridge->mutex))
|
|
|
|
return ERR_PTR(-EBUSY);
|
2016-11-01 19:14:28 +00:00
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
if (!try_module_get(bridge->br_ops_owner)) {
|
|
|
|
mutex_unlock(&bridge->mutex);
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
}
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
dev_dbg(&bridge->dev, "get\n");
|
|
|
|
|
|
|
|
return bridge;
|
|
|
|
}
|
2017-11-15 20:20:11 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:45 +00:00
|
|
|
* of_fpga_bridge_get - get an exclusive reference to an fpga bridge
|
2017-11-15 20:20:11 +00:00
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* @np: node pointer of an FPGA bridge.
|
|
|
|
* @info: fpga image specific information.
|
2017-11-15 20:20:11 +00:00
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Return:
|
|
|
|
* * fpga_bridge struct pointer if successful.
|
|
|
|
* * -EBUSY if someone already has a reference to the bridge.
|
|
|
|
* * -ENODEV if @np is not an FPGA Bridge or can't take parent driver refcount.
|
2017-11-15 20:20:11 +00:00
|
|
|
*/
|
|
|
|
struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
|
|
|
|
struct fpga_image_info *info)
|
|
|
|
{
|
2024-03-22 17:18:37 +00:00
|
|
|
struct fpga_bridge *bridge;
|
|
|
|
struct device *bridge_dev;
|
2017-11-15 20:20:11 +00:00
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
bridge_dev = class_find_device_by_of_node(&fpga_bridge_class, np);
|
|
|
|
if (!bridge_dev)
|
2017-11-15 20:20:11 +00:00
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
bridge = __fpga_bridge_get(bridge_dev, info);
|
|
|
|
if (IS_ERR(bridge))
|
|
|
|
put_device(bridge_dev);
|
|
|
|
|
|
|
|
return bridge;
|
2017-11-15 20:20:11 +00:00
|
|
|
}
|
2016-11-01 19:14:28 +00:00
|
|
|
EXPORT_SYMBOL_GPL(of_fpga_bridge_get);
|
|
|
|
|
2017-11-15 20:20:11 +00:00
|
|
|
static int fpga_bridge_dev_match(struct device *dev, const void *data)
|
|
|
|
{
|
|
|
|
return dev->parent == data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:45 +00:00
|
|
|
* fpga_bridge_get - get an exclusive reference to an fpga bridge
|
2017-11-15 20:20:11 +00:00
|
|
|
* @dev: parent device that fpga bridge was registered with
|
2023-03-01 14:03:08 +00:00
|
|
|
* @info: fpga image specific information
|
2017-11-15 20:20:11 +00:00
|
|
|
*
|
2021-06-08 21:23:45 +00:00
|
|
|
* Given a device, get an exclusive reference to an fpga bridge.
|
2017-11-15 20:20:11 +00:00
|
|
|
*
|
2018-09-12 14:43:24 +00:00
|
|
|
* Return: fpga bridge struct or IS_ERR() condition containing error code.
|
2017-11-15 20:20:11 +00:00
|
|
|
*/
|
|
|
|
struct fpga_bridge *fpga_bridge_get(struct device *dev,
|
|
|
|
struct fpga_image_info *info)
|
|
|
|
{
|
2024-03-22 17:18:37 +00:00
|
|
|
struct fpga_bridge *bridge;
|
2017-11-15 20:20:11 +00:00
|
|
|
struct device *bridge_dev;
|
|
|
|
|
2023-08-11 07:30:41 +00:00
|
|
|
bridge_dev = class_find_device(&fpga_bridge_class, NULL, dev,
|
2017-11-15 20:20:11 +00:00
|
|
|
fpga_bridge_dev_match);
|
|
|
|
if (!bridge_dev)
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
2024-03-22 17:18:37 +00:00
|
|
|
bridge = __fpga_bridge_get(bridge_dev, info);
|
|
|
|
if (IS_ERR(bridge))
|
|
|
|
put_device(bridge_dev);
|
|
|
|
|
|
|
|
return bridge;
|
2017-11-15 20:20:11 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridge_get);
|
|
|
|
|
2016-11-01 19:14:28 +00:00
|
|
|
/**
|
|
|
|
* fpga_bridge_put - release a reference to a bridge
|
|
|
|
*
|
|
|
|
* @bridge: FPGA bridge
|
|
|
|
*/
|
|
|
|
void fpga_bridge_put(struct fpga_bridge *bridge)
|
|
|
|
{
|
|
|
|
dev_dbg(&bridge->dev, "put\n");
|
|
|
|
|
|
|
|
bridge->info = NULL;
|
2024-03-22 17:18:37 +00:00
|
|
|
module_put(bridge->br_ops_owner);
|
2016-11-01 19:14:28 +00:00
|
|
|
mutex_unlock(&bridge->mutex);
|
|
|
|
put_device(&bridge->dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridge_put);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_bridges_enable - enable bridges in a list
|
|
|
|
* @bridge_list: list of FPGA bridges
|
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Enable each bridge in the list. If list is empty, do nothing.
|
2016-11-01 19:14:28 +00:00
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Return: 0 for success or empty bridge list or an error code otherwise.
|
2016-11-01 19:14:28 +00:00
|
|
|
*/
|
|
|
|
int fpga_bridges_enable(struct list_head *bridge_list)
|
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge;
|
|
|
|
int ret;
|
|
|
|
|
2017-03-10 20:47:11 +00:00
|
|
|
list_for_each_entry(bridge, bridge_list, node) {
|
2016-11-01 19:14:28 +00:00
|
|
|
ret = fpga_bridge_enable(bridge);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridges_enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_bridges_disable - disable bridges in a list
|
|
|
|
*
|
|
|
|
* @bridge_list: list of FPGA bridges
|
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Disable each bridge in the list. If list is empty, do nothing.
|
2016-11-01 19:14:28 +00:00
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Return: 0 for success or empty bridge list or an error code otherwise.
|
2016-11-01 19:14:28 +00:00
|
|
|
*/
|
|
|
|
int fpga_bridges_disable(struct list_head *bridge_list)
|
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge;
|
|
|
|
int ret;
|
|
|
|
|
2017-03-10 20:47:11 +00:00
|
|
|
list_for_each_entry(bridge, bridge_list, node) {
|
2016-11-01 19:14:28 +00:00
|
|
|
ret = fpga_bridge_disable(bridge);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridges_disable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_bridges_put - put bridges
|
|
|
|
*
|
|
|
|
* @bridge_list: list of FPGA bridges
|
|
|
|
*
|
|
|
|
* For each bridge in the list, put the bridge and remove it from the list.
|
|
|
|
* If list is empty, do nothing.
|
|
|
|
*/
|
|
|
|
void fpga_bridges_put(struct list_head *bridge_list)
|
|
|
|
{
|
2017-03-10 20:47:11 +00:00
|
|
|
struct fpga_bridge *bridge, *next;
|
2016-11-01 19:14:28 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2017-03-10 20:47:11 +00:00
|
|
|
list_for_each_entry_safe(bridge, next, bridge_list, node) {
|
2016-11-01 19:14:28 +00:00
|
|
|
fpga_bridge_put(bridge);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&bridge_list_lock, flags);
|
|
|
|
list_del(&bridge->node);
|
|
|
|
spin_unlock_irqrestore(&bridge_list_lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridges_put);
|
|
|
|
|
|
|
|
/**
|
2017-11-15 20:20:11 +00:00
|
|
|
* of_fpga_bridge_get_to_list - get a bridge, add it to a list
|
2016-11-01 19:14:28 +00:00
|
|
|
*
|
2021-06-08 21:23:45 +00:00
|
|
|
* @np: node pointer of an FPGA bridge
|
2016-11-01 19:14:28 +00:00
|
|
|
* @info: fpga image specific information
|
|
|
|
* @bridge_list: list of FPGA bridges
|
|
|
|
*
|
2021-05-28 15:05:57 +00:00
|
|
|
* Get an exclusive reference to the bridge and it to the list.
|
2016-11-01 19:14:28 +00:00
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Return: 0 for success, error code from of_fpga_bridge_get() otherwise.
|
2016-11-01 19:14:28 +00:00
|
|
|
*/
|
2017-11-15 20:20:11 +00:00
|
|
|
int of_fpga_bridge_get_to_list(struct device_node *np,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
struct list_head *bridge_list)
|
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
bridge = of_fpga_bridge_get(np, info);
|
|
|
|
if (IS_ERR(bridge))
|
|
|
|
return PTR_ERR(bridge);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&bridge_list_lock, flags);
|
|
|
|
list_add(&bridge->node, bridge_list);
|
|
|
|
spin_unlock_irqrestore(&bridge_list_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(of_fpga_bridge_get_to_list);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_bridge_get_to_list - given device, get a bridge, add it to a list
|
|
|
|
*
|
|
|
|
* @dev: FPGA bridge device
|
|
|
|
* @info: fpga image specific information
|
|
|
|
* @bridge_list: list of FPGA bridges
|
|
|
|
*
|
2021-05-28 15:05:57 +00:00
|
|
|
* Get an exclusive reference to the bridge and it to the list.
|
2017-11-15 20:20:11 +00:00
|
|
|
*
|
2023-07-06 14:27:55 +00:00
|
|
|
* Return: 0 for success, error code from fpga_bridge_get() otherwise.
|
2017-11-15 20:20:11 +00:00
|
|
|
*/
|
|
|
|
int fpga_bridge_get_to_list(struct device *dev,
|
2016-11-01 19:14:28 +00:00
|
|
|
struct fpga_image_info *info,
|
|
|
|
struct list_head *bridge_list)
|
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2017-11-15 20:20:11 +00:00
|
|
|
bridge = fpga_bridge_get(dev, info);
|
2016-11-01 19:14:28 +00:00
|
|
|
if (IS_ERR(bridge))
|
|
|
|
return PTR_ERR(bridge);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&bridge_list_lock, flags);
|
|
|
|
list_add(&bridge->node, bridge_list);
|
|
|
|
spin_unlock_irqrestore(&bridge_list_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridge_get_to_list);
|
|
|
|
|
|
|
|
static ssize_t name_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge = to_fpga_bridge(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", bridge->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t state_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge = to_fpga_bridge(dev);
|
fpga: bridge: return errors in the show() method of the "state" attribute
This patch changes the show() method of the "state" sysfs attribute to
propagate errors returned by the enable_show() op. In this way,
userspace can distinguish between when the bridge is actually "enabled"
(i.e., allowing signals) or "disabled" (i.e., gating signals), or when
there is an error.
Currently, enable_show() returns an integer representing the bridge's
state (enabled or disabled) or an error code. However, this integer
value is interpreted in state_show() as a bool, resulting in the method
printing "enabled" (i.e., the bridge allows signals to pass), without
propagating the error, even when enable_show() returns an error code.
Signed-off-by: Marco Pagani <marpagan@redhat.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20230125140622.176870-1-marpagan@redhat.com
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2023-01-25 14:06:22 +00:00
|
|
|
int state = 1;
|
2016-11-01 19:14:28 +00:00
|
|
|
|
2024-02-01 15:57:12 +00:00
|
|
|
if (bridge->br_ops->enable_show) {
|
fpga: bridge: return errors in the show() method of the "state" attribute
This patch changes the show() method of the "state" sysfs attribute to
propagate errors returned by the enable_show() op. In this way,
userspace can distinguish between when the bridge is actually "enabled"
(i.e., allowing signals) or "disabled" (i.e., gating signals), or when
there is an error.
Currently, enable_show() returns an integer representing the bridge's
state (enabled or disabled) or an error code. However, this integer
value is interpreted in state_show() as a bool, resulting in the method
printing "enabled" (i.e., the bridge allows signals to pass), without
propagating the error, even when enable_show() returns an error code.
Signed-off-by: Marco Pagani <marpagan@redhat.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20230125140622.176870-1-marpagan@redhat.com
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2023-01-25 14:06:22 +00:00
|
|
|
state = bridge->br_ops->enable_show(bridge);
|
|
|
|
if (state < 0)
|
|
|
|
return state;
|
|
|
|
}
|
2016-11-01 19:14:28 +00:00
|
|
|
|
fpga: bridge: return errors in the show() method of the "state" attribute
This patch changes the show() method of the "state" sysfs attribute to
propagate errors returned by the enable_show() op. In this way,
userspace can distinguish between when the bridge is actually "enabled"
(i.e., allowing signals) or "disabled" (i.e., gating signals), or when
there is an error.
Currently, enable_show() returns an integer representing the bridge's
state (enabled or disabled) or an error code. However, this integer
value is interpreted in state_show() as a bool, resulting in the method
printing "enabled" (i.e., the bridge allows signals to pass), without
propagating the error, even when enable_show() returns an error code.
Signed-off-by: Marco Pagani <marpagan@redhat.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20230125140622.176870-1-marpagan@redhat.com
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2023-01-25 14:06:22 +00:00
|
|
|
return sysfs_emit(buf, "%s\n", state ? "enabled" : "disabled");
|
2016-11-01 19:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RO(name);
|
|
|
|
static DEVICE_ATTR_RO(state);
|
|
|
|
|
|
|
|
static struct attribute *fpga_bridge_attrs[] = {
|
|
|
|
&dev_attr_name.attr,
|
|
|
|
&dev_attr_state.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
ATTRIBUTE_GROUPS(fpga_bridge);
|
|
|
|
|
|
|
|
/**
|
2024-03-22 17:18:37 +00:00
|
|
|
* __fpga_bridge_register - create and register an FPGA Bridge device
|
2021-06-14 17:09:05 +00:00
|
|
|
* @parent: FPGA bridge device from pdev
|
2016-11-01 19:14:28 +00:00
|
|
|
* @name: FPGA bridge name
|
|
|
|
* @br_ops: pointer to structure of fpga bridge ops
|
|
|
|
* @priv: FPGA bridge private data
|
2024-03-22 17:18:37 +00:00
|
|
|
* @owner: owner module containing the br_ops
|
2016-11-01 19:14:28 +00:00
|
|
|
*
|
2021-11-19 01:55:52 +00:00
|
|
|
* Return: struct fpga_bridge pointer or ERR_PTR()
|
2016-11-01 19:14:28 +00:00
|
|
|
*/
|
2021-11-19 01:55:52 +00:00
|
|
|
struct fpga_bridge *
|
2024-03-22 17:18:37 +00:00
|
|
|
__fpga_bridge_register(struct device *parent, const char *name,
|
|
|
|
const struct fpga_bridge_ops *br_ops,
|
|
|
|
void *priv, struct module *owner)
|
2016-11-01 19:14:28 +00:00
|
|
|
{
|
|
|
|
struct fpga_bridge *bridge;
|
2020-06-08 12:54:46 +00:00
|
|
|
int id, ret;
|
2016-11-01 19:14:28 +00:00
|
|
|
|
2021-11-19 01:55:52 +00:00
|
|
|
if (!br_ops) {
|
|
|
|
dev_err(parent, "Attempt to register without fpga_bridge_ops\n");
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:14:28 +00:00
|
|
|
if (!name || !strlen(name)) {
|
2021-06-14 17:09:05 +00:00
|
|
|
dev_err(parent, "Attempt to register with no name!\n");
|
2021-11-19 01:55:52 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
2016-11-01 19:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
|
|
|
|
if (!bridge)
|
2021-11-19 01:55:52 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2016-11-01 19:14:28 +00:00
|
|
|
|
2022-05-27 08:59:15 +00:00
|
|
|
id = ida_alloc(&fpga_bridge_ida, GFP_KERNEL);
|
2021-11-19 01:55:52 +00:00
|
|
|
if (id < 0) {
|
|
|
|
ret = id;
|
2016-11-01 19:14:28 +00:00
|
|
|
goto error_kfree;
|
2021-11-19 01:55:52 +00:00
|
|
|
}
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
mutex_init(&bridge->mutex);
|
|
|
|
INIT_LIST_HEAD(&bridge->node);
|
|
|
|
|
|
|
|
bridge->name = name;
|
|
|
|
bridge->br_ops = br_ops;
|
2024-03-22 17:18:37 +00:00
|
|
|
bridge->br_ops_owner = owner;
|
2016-11-01 19:14:28 +00:00
|
|
|
bridge->priv = priv;
|
|
|
|
|
2017-11-15 20:20:28 +00:00
|
|
|
bridge->dev.groups = br_ops->groups;
|
2023-08-11 07:30:41 +00:00
|
|
|
bridge->dev.class = &fpga_bridge_class;
|
2021-06-14 17:09:05 +00:00
|
|
|
bridge->dev.parent = parent;
|
|
|
|
bridge->dev.of_node = parent->of_node;
|
2016-11-01 19:14:28 +00:00
|
|
|
bridge->dev.id = id;
|
|
|
|
|
|
|
|
ret = dev_set_name(&bridge->dev, "br%d", id);
|
|
|
|
if (ret)
|
|
|
|
goto error_device;
|
|
|
|
|
2021-11-19 01:55:52 +00:00
|
|
|
ret = device_register(&bridge->dev);
|
|
|
|
if (ret) {
|
|
|
|
put_device(&bridge->dev);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
2023-04-04 13:31:02 +00:00
|
|
|
of_platform_populate(bridge->dev.of_node, NULL, NULL, &bridge->dev);
|
|
|
|
|
2018-05-16 23:49:56 +00:00
|
|
|
return bridge;
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
error_device:
|
2022-05-27 08:59:15 +00:00
|
|
|
ida_free(&fpga_bridge_ida, id);
|
2016-11-01 19:14:28 +00:00
|
|
|
error_kfree:
|
|
|
|
kfree(bridge);
|
|
|
|
|
2021-11-19 01:55:52 +00:00
|
|
|
return ERR_PTR(ret);
|
2016-11-01 19:14:28 +00:00
|
|
|
}
|
2024-03-22 17:18:37 +00:00
|
|
|
EXPORT_SYMBOL_GPL(__fpga_bridge_register);
|
2016-11-01 19:14:28 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:45 +00:00
|
|
|
* fpga_bridge_unregister - unregister an FPGA bridge
|
2018-10-15 22:20:02 +00:00
|
|
|
*
|
|
|
|
* @bridge: FPGA bridge struct
|
|
|
|
*
|
2021-06-08 21:23:45 +00:00
|
|
|
* This function is intended for use in an FPGA bridge driver's remove function.
|
2016-11-01 19:14:28 +00:00
|
|
|
*/
|
2018-05-16 23:49:56 +00:00
|
|
|
void fpga_bridge_unregister(struct fpga_bridge *bridge)
|
2016-11-01 19:14:28 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If the low level driver provides a method for putting bridge into
|
|
|
|
* a desired state upon unregister, do it.
|
|
|
|
*/
|
2024-02-01 15:57:12 +00:00
|
|
|
if (bridge->br_ops->fpga_bridge_remove)
|
2016-11-01 19:14:28 +00:00
|
|
|
bridge->br_ops->fpga_bridge_remove(bridge);
|
|
|
|
|
|
|
|
device_unregister(&bridge->dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_bridge_unregister);
|
|
|
|
|
|
|
|
static void fpga_bridge_dev_release(struct device *dev)
|
|
|
|
{
|
2021-11-19 01:55:52 +00:00
|
|
|
struct fpga_bridge *bridge = to_fpga_bridge(dev);
|
|
|
|
|
2022-05-27 08:59:15 +00:00
|
|
|
ida_free(&fpga_bridge_ida, bridge->dev.id);
|
2021-11-19 01:55:52 +00:00
|
|
|
kfree(bridge);
|
2016-11-01 19:14:28 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 07:30:41 +00:00
|
|
|
static const struct class fpga_bridge_class = {
|
|
|
|
.name = "fpga_bridge",
|
|
|
|
.dev_groups = fpga_bridge_groups,
|
|
|
|
.dev_release = fpga_bridge_dev_release,
|
|
|
|
};
|
|
|
|
|
2016-11-01 19:14:28 +00:00
|
|
|
static int __init fpga_bridge_dev_init(void)
|
|
|
|
{
|
2023-08-11 07:30:41 +00:00
|
|
|
return class_register(&fpga_bridge_class);
|
2016-11-01 19:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit fpga_bridge_dev_exit(void)
|
|
|
|
{
|
2023-08-11 07:30:41 +00:00
|
|
|
class_unregister(&fpga_bridge_class);
|
2016-11-01 19:14:28 +00:00
|
|
|
ida_destroy(&fpga_bridge_ida);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("FPGA Bridge Driver");
|
2017-11-15 20:20:11 +00:00
|
|
|
MODULE_AUTHOR("Alan Tull <atull@kernel.org>");
|
2016-11-01 19:14:28 +00:00
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
|
|
|
|
subsys_initcall(fpga_bridge_dev_init);
|
|
|
|
module_exit(fpga_bridge_dev_exit);
|