]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fpga: dfl: factor out feature device data from platform device data
authorPeter Colberg <peter.colberg@intel.com>
Wed, 20 Nov 2024 01:10:26 +0000 (20:10 -0500)
committerXu Yilun <yilun.xu@linux.intel.com>
Wed, 18 Dec 2024 14:28:48 +0000 (22:28 +0800)
Add a structure dfl_feature_dev_data to hold the DFL enumeration
info previously held in dfl_feature_platform_data. Allocate the new
structure using device-managed memory whose lifetime is bound to the
lifetime of the physical DFL, e.g., PCIe FPGA device. In a subsequent
commit, this will allow the feature platform device to be completely
destroyed and recreated on port release and assign, respectively, while
retaining the feature data in the new dfl_feature_dev_data structure.

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20241120011035.230574-11-peter.colberg@intel.com
Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
drivers/fpga/dfl.c
drivers/fpga/dfl.h

index 081b55d2297344437c1c060c7fb768595aa5d9c0..1d1f2330beef2257ce7d6d56a1ccff2d701372fd 100644 (file)
@@ -752,13 +752,7 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)
        if (WARN_ON_ONCE(type >= DFL_ID_MAX))
                return ERR_PTR(-EINVAL);
 
-       /*
-        * we do not need to care for the memory which is associated with
-        * the platform device. After calling platform_device_unregister(),
-        * it will be automatically freed by device's release() callback,
-        * platform_device_release().
-        */
-       fdata = kzalloc(struct_size(fdata, features, binfo->feature_num), GFP_KERNEL);
+       fdata = devm_kzalloc(binfo->dev, struct_size(fdata, features, binfo->feature_num), GFP_KERNEL);
        if (!fdata)
                return ERR_PTR(-ENOMEM);
 
@@ -779,8 +773,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)
         */
        WARN_ON(fdata->disable_count);
 
-       fdev->dev.platform_data = fdata;
-
        /* each sub feature has one MMIO resource */
        fdev->num_resources = binfo->feature_num;
        fdev->resource = kcalloc(binfo->feature_num, sizeof(*fdev->resource),
@@ -882,12 +874,18 @@ build_info_create_dev(struct build_feature_devs_info *binfo)
  */
 static int feature_dev_register(struct dfl_feature_dev_data *fdata)
 {
+       struct dfl_feature_platform_data pdata = {};
        struct platform_device *fdev = fdata->dev;
        int ret;
 
        fdev->dev.parent = &fdata->dfl_cdev->region->dev;
        fdev->dev.devt = dfl_get_devt(dfl_devs[fdata->type].devt_type, fdev->id);
 
+       pdata.fdata = fdata;
+       ret = platform_device_add_data(fdev, &pdata, sizeof(pdata));
+       if (ret)
+               return ret;
+
        ret = platform_device_add(fdev);
        if (ret)
                return ret;
index bbd74e1744a8fd1ddcfce8b3f0c61e5b914a2d96..bcbdfcdb974207e38e23fe69ef979deb59e3eb81 100644 (file)
 #define PORT_UINT_CAP_INT_NUM  GENMASK_ULL(11, 0)      /* Interrupts num */
 #define PORT_UINT_CAP_FST_VECT GENMASK_ULL(23, 12)     /* First Vector */
 
-struct dfl_feature_platform_data;
-#define dfl_feature_dev_data dfl_feature_platform_data
+struct dfl_feature_dev_data;
 
 /**
  * struct dfl_fpga_port_ops - port ops
@@ -304,26 +303,24 @@ struct dfl_feature {
 #define FEATURE_DEV_ID_UNUSED  (-1)
 
 /**
- * struct dfl_feature_platform_data - platform data for feature devices
+ * struct dfl_feature_dev_data - dfl enumeration data for dfl feature dev.
  *
- * @node: node to link feature devs to container device's port_dev_list.
- * @lock: mutex to protect platform data.
- * @cdev: cdev of feature dev.
- * @dev: ptr to platform device linked with this platform data.
+ * @node: node to link the data structure to container device's port_dev_list.
+ * @lock: mutex to protect feature dev data.
+ * @dev: ptr to the feature's platform device linked with this structure.
  * @type: type of DFL FIU for the feature dev. See enum dfl_id_type.
  * @dfl_cdev: ptr to container device.
- * @id: id used for this feature device.
+ * @id: id used for the feature device.
  * @disable_count: count for port disable.
  * @excl_open: set on feature device exclusive open.
  * @open_count: count for feature device open.
  * @num: number for sub features.
  * @private: ptr to feature dev private data.
- * @features: sub features of this feature dev.
+ * @features: sub features for the feature dev.
  */
-struct dfl_feature_platform_data {
+struct dfl_feature_dev_data {
        struct list_head node;
        struct mutex lock;
-       struct cdev cdev;
        struct platform_device *dev;
        enum dfl_id_type type;
        struct dfl_fpga_cdev *dfl_cdev;
@@ -336,6 +333,17 @@ struct dfl_feature_platform_data {
        struct dfl_feature features[];
 };
 
+/**
+ * struct dfl_feature_platform_data - platform data for feature devices
+ *
+ * @cdev: cdev of feature dev.
+ * @fdata: dfl enumeration data for the dfl feature device.
+ */
+struct dfl_feature_platform_data {
+       struct cdev cdev;
+       struct dfl_feature_dev_data *fdata;
+};
+
 static inline
 int dfl_feature_dev_use_begin(struct dfl_feature_dev_data *fdata,
                              bool excl)
@@ -404,14 +412,14 @@ int dfl_fpga_dev_ops_register(struct platform_device *pdev,
                              struct module *owner);
 void dfl_fpga_dev_ops_unregister(struct platform_device *pdev);
 
-static inline struct dfl_feature_platform_data *
+static inline struct dfl_feature_dev_data *
 dfl_fpga_inode_to_feature_dev_data(struct inode *inode)
 {
        struct dfl_feature_platform_data *pdata;
 
        pdata = container_of(inode->i_cdev, struct dfl_feature_platform_data,
                             cdev);
-       return pdata;
+       return pdata->fdata;
 }
 
 #define dfl_fpga_dev_for_each_feature(fdata, feature)                      \
@@ -442,7 +450,13 @@ dfl_get_feature_ioaddr_by_id(struct dfl_feature_dev_data *fdata, u16 id)
        return NULL;
 }
 
-#define to_dfl_feature_dev_data dev_get_platdata
+static inline struct dfl_feature_dev_data *
+to_dfl_feature_dev_data(struct device *dev)
+{
+       struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+
+       return pdata->fdata;
+}
 
 static inline
 struct device *dfl_fpga_fdata_to_parent(struct dfl_feature_dev_data *fdata)