Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1732549

Re: [PATCH v4 13/18] fpga: region: add register/unregister functions

From Alan Tull <atull@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH v4 13/18] fpga: region: add register/unregister functions
Date 2017-09-14 22:10 +0200
Message-ID <upICt-19d-7@gated-at.bofh.it> (permalink)
References <upmLD-3Lv-3@gated-at.bofh.it> <upmVk-3P1-9@gated-at.bofh.it> <upzfP-3Eb-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Sep 14, 2017 at 4:56 AM, Wu Hao <hao.wu@intel.com> wrote:
> On Thu, Sep 14, 2017 at 04:48:36AM +0800, Alan Tull wrote:
>> Another step in separating common code from device tree specific
>> code for FPGA regions.
>>
>> * add FPGA region register/unregister functions.
>> * add the register/unregister functions to the header
>> * use devm_kzalloc to alloc the region.
>> * add a method for getting bridges to the region struct
>> * add priv to the region struct
>> * use region->info in of_fpga_region_get_bridges
>>
>> Signed-off-by: Alan Tull <atull@kernel.org>
>> ---
>> v2: split out from another patch
>> v3: use region->info, remove info param where applicable
>> v4: no change to this patch in this version of patchset
>> ---
>>  drivers/fpga/fpga-region.c       | 106 ++++++++++++++++++++++++---------------
>>  include/linux/fpga/fpga-region.h |   7 +++
>>  2 files changed, 72 insertions(+), 41 deletions(-)
>>
>> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
>> index 92ab216..ce57383 100644
>> --- a/drivers/fpga/fpga-region.c
>> +++ b/drivers/fpga/fpga-region.c
>> @@ -143,7 +143,6 @@ static struct fpga_manager *of_fpga_region_get_mgr(struct device_node *np)
>>  /**
>>   * of_fpga_region_get_bridges - create a list of bridges
>>   * @region: FPGA region
>> - * @info: FPGA image info
>>   *
>>   * Create a list of bridges including the parent bridge and the bridges
>>   * specified by "fpga-bridges" property.  Note that the
>> @@ -156,11 +155,11 @@ static struct fpga_manager *of_fpga_region_get_mgr(struct device_node *np)
>>   * Return 0 for success (even if there are no bridges specified)
>>   * or -EBUSY if any of the bridges are in use.
>>   */
>> -static int of_fpga_region_get_bridges(struct fpga_region *region,
>> -                                   struct fpga_image_info *info)
>> +static int of_fpga_region_get_bridges(struct fpga_region *region)
>>  {
>>       struct device *dev = &region->dev;
>>       struct device_node *region_np = dev->of_node;
>> +     struct fpga_image_info *info = region->info;
>>       struct device_node *br, *np, *parent_br = NULL;
>>       int i, ret;
>>
>> @@ -192,7 +191,7 @@ static int of_fpga_region_get_bridges(struct fpga_region *region,
>>                       continue;
>>
>>               /* If node is a bridge, get it and add to list */
>> -             ret = of_fpga_bridge_get_to_list(br, region->info,
>> +             ret = of_fpga_bridge_get_to_list(br, info,
>>                                                &region->bridge_list);
>>
>>               /* If any of the bridges are in use, give up */
>> @@ -229,10 +228,16 @@ int fpga_region_program_fpga(struct fpga_region *region)
>>               goto err_put_region;
>>       }
>>
>> -     ret = of_fpga_region_get_bridges(region, info);
>> -     if (ret) {
>> -             dev_err(dev, "failed to get FPGA bridges\n");
>> -             goto err_unlock_mgr;
>> +     /*
>> +      * In some cases, we already have a list of bridges in the
>> +      * fpga region struct.  Or we don't have any bridges.
>> +      */
>> +     if (region->get_bridges) {
>> +             ret = region->get_bridges(region);
>> +             if (ret) {
>> +                     dev_err(dev, "failed to get fpga region bridges\n");
>> +                     goto err_unlock_mgr;
>> +             }
>>       }
>>
>>       ret = fpga_bridges_disable(&region->bridge_list);
>> @@ -259,7 +264,8 @@ int fpga_region_program_fpga(struct fpga_region *region)
>>       return 0;
>>
>>  err_put_br:
>> -     fpga_bridges_put(&region->bridge_list);
>> +     if (region->get_bridges)
>> +             fpga_bridges_put(&region->bridge_list);
>>  err_unlock_mgr:
>>       fpga_mgr_unlock(region->mgr);
>>  err_put_region:
>> @@ -522,39 +528,20 @@ static struct notifier_block fpga_region_of_nb = {
>>       .notifier_call = of_fpga_region_notify,
>>  };
>>
>> -static int of_fpga_region_probe(struct platform_device *pdev)
>> +int fpga_region_register(struct device *dev, struct fpga_region *region)
>>  {
>> -     struct device *dev = &pdev->dev;
>> -     struct device_node *np = dev->of_node;
>> -     struct fpga_region *region;
>> -     struct fpga_manager *mgr;
>>       int id, ret = 0;
>>
>> -     mgr = of_fpga_region_get_mgr(np);
>> -     if (IS_ERR(mgr))
>> -             return -EPROBE_DEFER;
>> -
>> -     region = kzalloc(sizeof(*region), GFP_KERNEL);
>> -     if (!region) {
>> -             ret = -ENOMEM;
>> -             goto err_put_mgr;
>> -     }
>> -
>> -     region->mgr = mgr;
>> -
>>       id = ida_simple_get(&fpga_region_ida, 0, 0, GFP_KERNEL);
>> -     if (id < 0) {
>> -             ret = id;
>> -             goto err_kfree;
>> -     }
>> +     if (id < 0)
>> +             return id;
>>
>>       mutex_init(&region->mutex);
>>       INIT_LIST_HEAD(&region->bridge_list);
>> -
>>       device_initialize(&region->dev);
>>       region->dev.class = fpga_region_class;
>>       region->dev.parent = dev;
>> -     region->dev.of_node = np;
>> +     region->dev.of_node = dev->of_node;
>>       region->dev.id = id;
>>       dev_set_drvdata(dev, region);
>>
>> @@ -566,19 +553,58 @@ static int of_fpga_region_probe(struct platform_device *pdev)
>>       if (ret)
>>               goto err_remove;
>>
>> +     return 0;
>> +
>> +err_remove:
>> +     ida_simple_remove(&fpga_region_ida, id);
>> +     return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(fpga_region_register);
>> +
>> +int fpga_region_unregister(struct fpga_region *region)
>> +{
>> +     device_unregister(&region->dev);
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(fpga_region_unregister);
>> +
>> +static int of_fpga_region_probe(struct platform_device *pdev)
>> +{
>> +     struct device *dev = &pdev->dev;
>> +     struct device_node *np = dev->of_node;
>> +     struct fpga_region *region;
>> +     struct fpga_manager *mgr;
>> +     int ret;
>> +
>> +     /* Find the FPGA mgr specified by region or parent region. */
>> +     mgr = of_fpga_region_get_mgr(np);
>> +     if (IS_ERR(mgr))
>> +             return -EPROBE_DEFER;
>> +
>> +     region = devm_kzalloc(dev, sizeof(*region), GFP_KERNEL);
>> +     if (!region) {
>> +             ret = -ENOMEM;
>> +             goto eprobe_mgr_put;
>> +     }
>> +
>> +     region->mgr = mgr;
>> +
>> +     /* Specify how to get bridges for this type of region. */
>> +     region->get_bridges = of_fpga_region_get_bridges;
>> +
>> +     ret = fpga_region_register(dev, region);
>> +     if (ret)
>> +             goto eprobe_mgr_put;
>> +
>>       of_platform_populate(np, fpga_region_of_match, NULL, &region->dev);
>>
>>       dev_info(dev, "FPGA Region probed\n");
>>
>>       return 0;
>>
>> -err_remove:
>> -     ida_simple_remove(&fpga_region_ida, id);
>> -err_kfree:
>> -     kfree(region);
>> -err_put_mgr:
>> +eprobe_mgr_put:
>>       fpga_mgr_put(mgr);
>> -
>>       return ret;
>>  }
>>
>> @@ -586,8 +612,7 @@ static int of_fpga_region_remove(struct platform_device *pdev)
>>  {
>>       struct fpga_region *region = platform_get_drvdata(pdev);
>>
>> -     device_unregister(&region->dev);
>> -     fpga_mgr_put(region->mgr);
>> +     fpga_region_unregister(region);
>
> Hi Alan
>
> Do you think if we need to keep fpga_mgr_put(region->mgr) in this remove
> function? :)

Hi Hao,

Thanks for catching that!  I'll add it back in.

Alan

>
> Thanks
> Hao

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/18]  Enable upper layers using FPGA region w/o device tree Alan Tull <atull@kernel.org> - 2017-09-13 22:50 +0200
  [PATCH v4 10/18] fpga: region: separate out code that parses the overlay Alan Tull <atull@kernel.org> - 2017-09-13 22:50 +0200
  [PATCH v4 18/18] fpga: add attribute groups Alan Tull <atull@kernel.org> - 2017-09-13 22:50 +0200
  [PATCH v4 16/18] fpga: of-fpga-region: accept overlays that don't program FPGA Alan Tull <atull@kernel.org> - 2017-09-13 22:50 +0200
  [PATCH v4 02/18] fpga: mgr: API change to replace fpga load functions with single function Alan Tull <atull@kernel.org> - 2017-09-13 22:50 +0200
  [PATCH v4 17/18] fpga: clean up fpga Kconfig Alan Tull <atull@kernel.org> - 2017-09-13 22:50 +0200
    Re: [PATCH v4 17/18] fpga: clean up fpga Kconfig matthew.gerlach@linux.intel.com - 2017-09-14 18:00 +0200
      Re: [PATCH v4 17/18] fpga: clean up fpga Kconfig Alan Tull <atull@kernel.org> - 2017-09-14 22:50 +0200
  [PATCH v4 06/18] fpga: region: get mgr early on Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 14/18] fpga: region: add fpga_region_class_find Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 05/18] fpga: region: remove unneeded of_node_get and put Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 13/18] fpga: region: add register/unregister functions Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
    Re: [PATCH v4 13/18] fpga: region: add register/unregister functions Wu Hao <hao.wu@intel.com> - 2017-09-14 12:10 +0200
      Re: [PATCH v4 13/18] fpga: region: add register/unregister functions Alan Tull <atull@kernel.org> - 2017-09-14 22:10 +0200
  [PATCH v4 11/18] fpga: region: add fpga-region.h header Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
    Re: [PATCH v4 11/18] fpga: region: add fpga-region.h header Wu Hao <hao.wu@intel.com> - 2017-09-14 12:00 +0200
      Re: [PATCH v4 11/18] fpga: region: add fpga-region.h header Alan Tull <atull@kernel.org> - 2017-09-14 21:40 +0200
  [PATCH v4 15/18] fpga: region: move device tree support to of-fpga-region.c Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
    Re: [PATCH v4 15/18] fpga: region: move device tree support to  of-fpga-region.c matthew.gerlach@linux.intel.com - 2017-09-14 18:00 +0200
  [PATCH v4 03/18] fpga: mgr: separate getting/locking FPGA manager Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 09/18] fpga: region: use image info as parameter for programming region Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 01/18] fpga: bridge: support getting bridge from device Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
    Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from  device matthew.gerlach@linux.intel.com - 2017-09-14 01:40 +0200
      Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Alan Tull <atull@kernel.org> - 2017-09-14 21:30 +0200
        Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from  device matthew.gerlach@linux.intel.com - 2017-09-15 00:30 +0200
          Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Moritz Fischer <mdf@kernel.org> - 2017-09-15 01:00 +0200
            Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Alan Tull <atull@kernel.org> - 2017-09-19 18:10 +0200
    Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Moritz Fischer <mdf@kernel.org> - 2017-09-18 20:00 +0200
      Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Alan Tull <atull@kernel.org> - 2017-09-18 23:00 +0200
    Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Moritz Fischer <mdf@kernel.org> - 2017-09-19 01:00 +0200
      Re: [PATCH v4 01/18] fpga: bridge: support getting bridge from device Alan Tull <atull@kernel.org> - 2017-09-19 17:40 +0200
  [PATCH v4 12/18] fpga: region: rename some functions prior to moving Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 07/18] fpga: region: check for child regions before allocing image info Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200
  [PATCH v4 08/18] fpga: region: fix slow warning with more than one overlay Alan Tull <atull@kernel.org> - 2017-09-13 23:00 +0200

csiph-web