Message ID | 1456959056-12316-4-git-send-email-toshi.kani@hpe.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
On Wed, Mar 2, 2016 at 2:50 PM, Toshi Kani <toshi.kani@hpe.com> wrote: > insert_resource() and remove_resouce() are called by producers > of resources, such as FW modules and bus drivers. These modules > may be implemented as loadable modules. > > Add device-managed implementaions of insert_resource() and > remove_resouce() functions. > > Signed-off-by: Toshi Kani <toshi.kani@hpe.com> > Cc: Ingo Molnar <mingo@kernel.org> > Cc: Borislav Petkov <bp@suse.de> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Dan Williams <dan.j.williams@intel.com> > --- > include/linux/ioport.h | 5 +++ > kernel/resource.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 74 insertions(+) > > diff --git a/include/linux/ioport.h b/include/linux/ioport.h > index 8017b8b..3580038 100644 > --- a/include/linux/ioport.h > +++ b/include/linux/ioport.h > @@ -259,6 +259,11 @@ extern struct resource * __devm_request_region(struct device *dev, > > extern void __devm_release_region(struct device *dev, struct resource *parent, > resource_size_t start, resource_size_t n); > + > +extern int devm_insert_resource(struct device *dev, struct resource *root, > + struct resource *new); > +extern void devm_remove_resource(struct device *dev, struct resource *old); > + > extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size); > extern int iomem_is_exclusive(u64 addr); > > diff --git a/kernel/resource.c b/kernel/resource.c > index effb6ee..b1a3394 100644 > --- a/kernel/resource.c > +++ b/kernel/resource.c > @@ -1449,6 +1449,75 @@ void __devm_release_region(struct device *dev, struct resource *parent, > EXPORT_SYMBOL(__devm_release_region); > > /* > + * Remove function for devm_insert_resource() and devm_remove_resource(). > + */ > +static void devm_resource_remove(struct device *dev, void *ptr) > +{ > + struct resource **r = ptr; > + > + remove_resource(*r); > +} > + Maybe call this __devm_remove_resource? I think this makes it clearer that it is a private helper function. I was initially confused about the difference between devm_resource_remove and devm_remove_resource. -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2016-03-03 at 14:45 -0800, Dan Williams wrote: > On Wed, Mar 2, 2016 at 2:50 PM, Toshi Kani <toshi.kani@hpe.com> wrote: : > > > > diff --git a/kernel/resource.c b/kernel/resource.c > > index effb6ee..b1a3394 100644 > > --- a/kernel/resource.c > > +++ b/kernel/resource.c > > @@ -1449,6 +1449,75 @@ void __devm_release_region(struct device *dev, > > struct resource *parent, > > EXPORT_SYMBOL(__devm_release_region); > > > > /* > > + * Remove function for devm_insert_resource() and > > devm_remove_resource(). > > + */ > > +static void devm_resource_remove(struct device *dev, void *ptr) > > +{ > > + struct resource **r = ptr; > > + > > + remove_resource(*r); > > +} > > + > > Maybe call this __devm_remove_resource? I think this makes it clearer > that it is a private helper function. I was initially confused about > the difference between devm_resource_remove and devm_remove_resource. Will do. I followed the naming convention of devm_resource_release() in the same file, but I agree that this is confusing. Thanks, -Toshi -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 8017b8b..3580038 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -259,6 +259,11 @@ extern struct resource * __devm_request_region(struct device *dev, extern void __devm_release_region(struct device *dev, struct resource *parent, resource_size_t start, resource_size_t n); + +extern int devm_insert_resource(struct device *dev, struct resource *root, + struct resource *new); +extern void devm_remove_resource(struct device *dev, struct resource *old); + extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size); extern int iomem_is_exclusive(u64 addr); diff --git a/kernel/resource.c b/kernel/resource.c index effb6ee..b1a3394 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1449,6 +1449,75 @@ void __devm_release_region(struct device *dev, struct resource *parent, EXPORT_SYMBOL(__devm_release_region); /* + * Remove function for devm_insert_resource() and devm_remove_resource(). + */ +static void devm_resource_remove(struct device *dev, void *ptr) +{ + struct resource **r = ptr; + + remove_resource(*r); +} + +/** + * devm_insert_resource() - insert an I/O or memory resource + * @dev: device for which to produce the resource + * @root: root of the resource tree + * @new: descriptor of the new resource + * + * This is a device-managed version of insert_resource(). There is usually + * no need to release resources requested by this function explicitly since + * that will be taken care of when the device is unbound from its bus driver. + * If for some reason the resource needs to be released explicitly, because + * of ordering issues for example, bus drivers must call devm_remove_resource() + * rather than the regular remove_resource(). + * + * devm_insert_resource() is intended for producers of resources, such as + * FW modules and bus drivers. + * + * Returns 0 on success or a negative error code on failure. + */ +int devm_insert_resource(struct device *dev, struct resource *root, + struct resource *new) +{ + struct resource **ptr; + int ret; + + ptr = devres_alloc(devm_resource_remove, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + *ptr = new; + + ret = insert_resource(root, new); + if (ret) { + dev_err(dev, "unable to insert resource: %pR (%d)\n", new, ret); + devres_free(ptr); + return -EBUSY; + } + + devres_add(dev, ptr); + return 0; +} +EXPORT_SYMBOL_GPL(devm_insert_resource); + +/** + * devm_remove_resource() - remove a previously inserted resource + * @dev: device for which to remove the resource + * @old: descriptor of the resource + * + * Remove a resource previously inserted using devm_insert_resource(). + * + * devm_remove_resource() is intended for producers of resources, such as + * FW modules and bus drivers. + */ +void devm_remove_resource(struct device *dev, struct resource *old) +{ + WARN_ON(devres_release(dev, devm_resource_remove, devm_resource_match, + old)); +} +EXPORT_SYMBOL_GPL(devm_remove_resource); + +/* * Called from init/main.c to reserve IO ports. */ #define MAXRESERVE 4
insert_resource() and remove_resouce() are called by producers of resources, such as FW modules and bus drivers. These modules may be implemented as loadable modules. Add device-managed implementaions of insert_resource() and remove_resouce() functions. Signed-off-by: Toshi Kani <toshi.kani@hpe.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Borislav Petkov <bp@suse.de> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dan Williams <dan.j.williams@intel.com> --- include/linux/ioport.h | 5 +++ kernel/resource.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html