From: Toshi Kani <toshi.kani@hpe.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@suse.de>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Andrew Morton <akpm@linux-foundation.org>,
"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>,
Linux ACPI <linux-acpi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"torvalds@linux-foundation.org" <torvalds@linux-foundation.org>
Subject: Re: [PATCH v2-UPDATE 3/4] resource: Add device-managed insert/remove_resource()
Date: Mon, 07 Mar 2016 16:03:07 -0700 [thread overview]
Message-ID: <1457391787.15454.399.camel@hpe.com> (raw)
In-Reply-To: <CAPcyv4g8+6LBW08JZ3Ym0mAuo1bcwjGTeHrzS0p=QoJb4Mqeag@mail.gmail.com>
On Mon, 2016-03-07 at 10:14 -0800, Dan Williams wrote:
:
> > +/**
> > + * 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_remove_resource, 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);
>
> The only hesitation I have with this is that the kernel has gotten by
> a long time without allowing external modules to insert resources. If
> keeping it private all this time was purposeful then maybe we should
> make this new NVDIMM-need to call insert_resource() private to the
> nfit driver and built-in-only.
Here is some background info on this:
- External modules can already insert resources via platform_device_add(),
which is used for inserting resources that may not be enumerated by
standard FW interfaces. There are over 200 callers already.
- PCI mmcfg driver and ACPI HPET driver find their resources from ACPI, and
call insert_resource() to insert them, which is similar to what this
patchset tries to do with ACPI NFIT. Both PCI and HPET drivers do not
support unloading, however.
# cat /proc/iomem
:
80000000-8fffffff : PCI MMCONFIG 0000 [bus 00-ff]
80000000-8fffffff : reserved
:
fed00000-fed003ff : HPET 0
fed00000-fed003ff : PNP0103:00
- Existing FW modules and bus drivers using insert_resource() are built-
into the kernel, and insert_resource() is not exported. I think this is
because these modules did not have to (or may not) support unloading.
- Both the NFIT driver and NVDIMM bus drivers are new and support
unloading. This calls for an exported interface for insert_resource().
- devm impl of insert/remove_resource() is added to assure that resources
are properly released on unloading. Exporting devm interfaces makes sense
(to me).
- However, devm_insert/remove_resource() should not be confused with
devm_request/release_resource(). Hence, this patchset adds comments to
clarify that they are used for producers of resources. The same comments
are added to insert/remove_resource() as well.
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
next prev parent reply other threads:[~2016-03-07 22:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 16:14 [PATCH v2-UPDATE 3/4] resource: Add device-managed insert/remove_resource() Toshi Kani
2016-03-07 18:14 ` Dan Williams
2016-03-07 23:03 ` Toshi Kani [this message]
2016-03-08 2:21 ` Dan Williams
2016-03-08 12:02 ` Ingo Molnar
2016-03-08 17:41 ` Toshi Kani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457391787.15454.399.camel@hpe.com \
--to=toshi.kani@hpe.com \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=dan.j.williams@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=mingo@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).