mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Yinghai Lu <yinghai@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Len Brown <lenb@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Vinod Koul <vinod.koul@intel.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	Thierry Reding <treding@nvidia.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Travis <travis@sgi.com>, Tony Luck <tony.luck@intel.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org,
	dmaengine@vger.kernel.org
Subject: Re: [RFC Patch 17/19] resources: Move struct resource_list_entry from ACPI into resource core
Date: Wed, 21 Jan 2015 02:10:25 +0100	[thread overview]
Message-ID: <3428063.tN1BxOoXSN@vostro.rjw.lan> (raw)
In-Reply-To: <1420684386-5975-18-git-send-email-jiang.liu@linux.intel.com>

On Thursday, January 08, 2015 10:33:04 AM Jiang Liu wrote:
> Currently ACPI, PCI and pnp all implement the same resource list
> management with different data structure. We need to transfer from
> one data structure into another when passing resources from one
> subsystem into another subsystem. Sp move struct resource_list_entry
> from ACPI into resource core, so it could be reused by different
> subystems and avoid the data structure conversion.
> 
> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
> ---
>  drivers/acpi/acpi_lpss.c     |    6 +++---
>  drivers/acpi/acpi_platform.c |    2 +-
>  drivers/acpi/resource.c      |   13 ++++--------
>  drivers/dma/acpi-dma.c       |    8 +++----
>  include/linux/acpi.h         |    6 ------
>  include/linux/ioport.h       |   25 ++++++++++++++++++++++
>  kernel/resource.c            |   48 ++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 85 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
> index 4f3febf8a589..39b548dba70b 100644
> --- a/drivers/acpi/acpi_lpss.c
> +++ b/drivers/acpi/acpi_lpss.c
> @@ -333,12 +333,12 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
>  		goto err_out;
>  
>  	list_for_each_entry(rentry, &resource_list, node)
> -		if (resource_type(&rentry->res) == IORESOURCE_MEM) {
> +		if (resource_type(rentry->res) == IORESOURCE_MEM) {
>  			if (dev_desc->prv_size_override)
>  				pdata->mmio_size = dev_desc->prv_size_override;
>  			else
> -				pdata->mmio_size = resource_size(&rentry->res);
> -			pdata->mmio_base = ioremap(rentry->res.start,
> +				pdata->mmio_size = resource_size(rentry->res);
> +			pdata->mmio_base = ioremap(rentry->res->start,
>  						   pdata->mmio_size);
>  			break;
>  		}
> diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
> index 6ba8beb6b9d2..238e32b9cbb0 100644
> --- a/drivers/acpi/acpi_platform.c
> +++ b/drivers/acpi/acpi_platform.c
> @@ -71,7 +71,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
>  		}
>  		count = 0;
>  		list_for_each_entry(rentry, &resource_list, node)
> -			resources[count++] = rentry->res;
> +			resources[count++] = *rentry->res;
>  
>  		acpi_dev_free_resource_list(&resource_list);
>  	}
> diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
> index 8ea7c26d6915..c0dc038274d4 100644
> --- a/drivers/acpi/resource.c
> +++ b/drivers/acpi/resource.c
> @@ -444,12 +444,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_resource_interrupt);
>   */
>  void acpi_dev_free_resource_list(struct list_head *list)
>  {
> -	struct resource_list_entry *rentry, *re;
> -
> -	list_for_each_entry_safe(rentry, re, list, node) {
> -		list_del(&rentry->node);
> -		kfree(rentry);
> -	}
> +	resource_list_free_list(list);
>  }
>  EXPORT_SYMBOL_GPL(acpi_dev_free_resource_list);
>  
> @@ -467,14 +462,14 @@ static acpi_status acpi_dev_new_resource_entry(struct resource *r,
>  {
>  	struct resource_list_entry *rentry;
>  
> -	rentry = kmalloc(sizeof(*rentry), GFP_KERNEL);
> +	rentry = resource_list_alloc(NULL, 0);
>  	if (!rentry) {
>  		c->error = -ENOMEM;
>  		return AE_NO_MEMORY;
>  	}
> -	rentry->res = *r;
> +	*rentry->res = *r;
>  	rentry->offset = offset;
> -	list_add_tail(&rentry->node, c->list);
> +	resource_list_insert(c->list, rentry, true);
>  	c->count++;
>  	return AE_OK;
>  }
> diff --git a/drivers/dma/acpi-dma.c b/drivers/dma/acpi-dma.c
> index de361a156b34..1ce84abe0924 100644
> --- a/drivers/dma/acpi-dma.c
> +++ b/drivers/dma/acpi-dma.c
> @@ -56,10 +56,10 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
>  		return 0;
>  
>  	list_for_each_entry(rentry, &resource_list, node) {
> -		if (resource_type(&rentry->res) == IORESOURCE_MEM)
> -			mem = rentry->res.start;
> -		else if (resource_type(&rentry->res) == IORESOURCE_IRQ)
> -			irq = rentry->res.start;
> +		if (resource_type(rentry->res) == IORESOURCE_MEM)
> +			mem = rentry->res->start;
> +		else if (resource_type(rentry->res) == IORESOURCE_IRQ)
> +			irq = rentry->res->start;
>  	}
>  
>  	acpi_dev_free_resource_list(&resource_list);
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 1df4a0211ae5..6d7f7edca22c 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -297,12 +297,6 @@ unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable);
>  bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,
>  				 struct resource *res);
>  
> -struct resource_list_entry {
> -	struct list_head node;
> -	struct resource res;
> -	resource_size_t offset;
> -};
> -
>  void acpi_dev_free_resource_list(struct list_head *list);
>  int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
>  			   int (*preproc)(struct acpi_resource *, void *),
> diff --git a/include/linux/ioport.h b/include/linux/ioport.h
> index 2c5250222278..a6f4841ca40c 100644
> --- a/include/linux/ioport.h
> +++ b/include/linux/ioport.h
> @@ -11,6 +11,7 @@
>  #ifndef __ASSEMBLY__
>  #include <linux/compiler.h>
>  #include <linux/types.h>
> +
>  /*
>   * Resources are tree-like, allowing
>   * nesting etc..
> @@ -255,6 +256,30 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
>         return (r1->start <= r2->end && r1->end >= r2->start);
>  }
>  
> +/*
> + * Common resource list management data structure and interfaces to support
> + * ACPI, PNP and PCI host bridge etc.
> + */
> +struct resource_list_entry {
> +	struct list_head	node;
> +	struct resource		*res;	/* In master (CPU) address space */
> +	resource_size_t		offset;	/* Translation offset for bridge */
> +	struct resource		__res;	/* Default storage for res */
> +};
> +
> +extern struct resource_list_entry *resource_list_alloc(struct resource *res,
> +						       size_t extra_size);
> +extern void resource_list_free(struct resource_list_entry *entry);
> +extern void resource_list_insert(struct list_head *head,
> +				 struct resource_list_entry *entry, bool tail);
> +extern void resource_list_delete(struct resource_list_entry *entry);
> +extern void resource_list_free_list(struct list_head *head);
> +
> +#define resource_list_for_each_entry(entry, list)	\
> +	list_for_each_entry((entry), (list), node)
> +
> +#define resource_list_for_each_entry_safe(entry, tmp, list)	\
> +	list_for_each_entry_safe((entry), (tmp), (list), node)
>  
>  #endif /* __ASSEMBLY__ */
>  #endif	/* _LINUX_IOPORT_H */
> diff --git a/kernel/resource.c b/kernel/resource.c
> index 0bcebffc4e77..414183809383 100644
> --- a/kernel/resource.c
> +++ b/kernel/resource.c
> @@ -1529,6 +1529,54 @@ int iomem_is_exclusive(u64 addr)
>  	return err;
>  }
>  
> +struct resource_list_entry *resource_list_alloc(struct resource *res,
> +						size_t extra_size)

What about create_resource_list_entry()?  Less confusing surely.

> +{
> +	struct resource_list_entry *entry;
> +
> +	entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL);
> +	if (entry) {
> +		INIT_LIST_HEAD(&entry->node);
> +		entry->res = res ? res : &entry->__res;
> +	}
> +
> +	return entry;
> +}
> +EXPORT_SYMBOL(resource_list_alloc);
> +
> +void resource_list_free(struct resource_list_entry *entry)
> +{
> +	kfree(entry);
> +}
> +EXPORT_SYMBOL(resource_list_free);

Well, I'm not sure I like this.  The name suggests that it would free the
entire list and what's wrong with using kfree() directly on "entry" anyway?

> +
> +void resource_list_insert(struct list_head *head,
> +			  struct resource_list_entry *entry, bool tail)

I would call this resource_list_add() if anything.

Also it may be better to have two helpers, one for "add" and one for "add_tail"
(and perhaps define them as static inline?).

And why change the ordering between "head" and "entry".  That's alomost
guaranteed to confuse people.

> +{
> +	if (tail)
> +		list_add_tail(&entry->node, head);
> +	else
> +		list_add(&entry->node, head);
> +}
> +EXPORT_SYMBOL(resource_list_insert);
> +
> +void resource_list_delete(struct resource_list_entry *entry)
> +{
> +	list_del(&entry->node);
> +}
> +EXPORT_SYMBOL(resource_list_delete);

Couldn't this be a static inline)?

Or maybe we can combine the "list_del" with "kfree" in one function?

> +
> +void resource_list_free_list(struct list_head *head)
> +{
> +	struct resource_list_entry *entry, *tmp;
> +
> +	list_for_each_entry_safe(entry, tmp, head, node) {
> +		list_del(&entry->node);
> +		resource_list_free(entry);
> +	}
> +}
> +EXPORT_SYMBOL(resource_list_free_list);
> +
>  static int __init strict_iomem(char *str)
>  {
>  	if (strstr(str, "relaxed"))
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

  reply	other threads:[~2015-01-21  0:47 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-08  2:32 [RFC Patch 00/19] Improve ACPI resource parsing interfaces and data structures Jiang Liu
2015-01-08  2:32 ` [RFC Patch 01/19] ACPI: Remove redundant check in function acpi_dev_resource_address_space() Jiang Liu
2015-01-08  2:32 ` [RFC Patch 02/19] ACPI: Implement proper length checks for mem resources Jiang Liu
2015-01-08  2:32 ` [RFC Patch 03/19] ACPI: Use the length check for io resources as well Jiang Liu
2015-01-08  2:32 ` [RFC Patch 04/19] ACPI: Let the parser return false for disabled resources Jiang Liu
2015-01-08  2:32 ` [RFC Patch 05/19] ACPI: Provide union for address_space64 and ext_address_space64 Jiang Liu
2015-01-21  0:32   ` Rafael J. Wysocki
2015-01-22  2:32   ` Zheng, Lv
2015-01-22  2:57     ` Jiang Liu
2015-01-22  3:24       ` Zheng, Lv
2015-01-22 10:38         ` Thomas Gleixner
2015-01-08  2:32 ` [RFC Patch 06/19] ACPI: Unify the parsing of address_space and ext_address_space Jiang Liu
2015-01-08  2:32 ` [RFC Patch 07/19] ACPI: Move the window flag logic to the combined parser Jiang Liu
2015-01-08  2:32 ` [RFC Patch 08/19] ACPI: Add prefetch decoding to the address space parser Jiang Liu
2015-01-21  0:35   ` Rafael J. Wysocki
2015-01-21  5:26     ` Jiang Liu
2015-01-21 14:48       ` Rafael J. Wysocki
2015-01-08  2:32 ` [RFC Patch 09/19] ACPI: Fix a bug in parsing ACPI Memroy24 resource Jiang Liu
2015-01-21  0:42   ` Rafael J. Wysocki
2015-01-21  2:15     ` Jiang Liu
2015-01-21  2:59       ` Rafael J. Wysocki
2015-01-21  2:48         ` Jiang Liu
2015-01-08  2:32 ` [RFC Patch 10/19] ACPI: Normalize return value of resource parser functions Jiang Liu
2015-01-08  2:32 ` [RFC Patch 11/19] ACPI: Set flag IORESOURCE_UNSET for unassigned resources Jiang Liu
2015-01-08  2:32 ` [RFC Patch 12/19] ACPI: Enforce stricter checks for address space descriptors Jiang Liu
2015-01-21  0:45   ` Rafael J. Wysocki
2015-01-21  2:18     ` Jiang Liu
2015-01-21  3:01       ` Rafael J. Wysocki
2015-01-08  2:33 ` [RFC Patch 13/19] ACPI: Return translation offset when parsing ACPI address space resources Jiang Liu
2015-01-08  2:33 ` [RFC Patch 14/19] ACPI: Translate resource into master side address for bridge window resources Jiang Liu
2015-01-21  0:50   ` Rafael J. Wysocki
2015-01-21  5:36     ` Jiang Liu
2015-01-21 14:48       ` Rafael J. Wysocki
2015-01-08  2:33 ` [RFC Patch 15/19] ACPI: Add field offset to struct resource_list_entry Jiang Liu
2015-01-21  0:53   ` Rafael J. Wysocki
2015-01-21  5:37     ` Jiang Liu
2015-01-21 14:47       ` Rafael J. Wysocki
2015-01-21 15:01         ` Jiang Liu
2015-01-08  2:33 ` [RFC Patch 16/19] ACPI: Introduce helper function acpi_dev_filter_resource_type() Jiang Liu
2015-01-15 21:30   ` Thomas Gleixner
2015-01-16  0:58     ` Jiang Liu
2015-01-08  2:33 ` [RFC Patch 17/19] resources: Move struct resource_list_entry from ACPI into resource core Jiang Liu
2015-01-21  1:10   ` Rafael J. Wysocki [this message]
2015-01-21  6:37     ` Jiang Liu
2015-01-21  9:43       ` Thomas Gleixner
2015-01-21 12:32         ` Jiang Liu
2015-01-08  2:33 ` [RFC Patch 18/19] PCI: Use common resource list management code instead of private implementation Jiang Liu
2015-01-08  2:33 ` [RFC Patch 19/19] x86/PCI/ACPI: Use common ACPI resource interfaces to simplify implementation Jiang Liu
2015-01-11 22:38 ` [RFC Patch 00/19] Improve ACPI resource parsing interfaces and data structures Rafael J. Wysocki
2015-01-19 14:26   ` Jiang Liu
2015-01-19 15:06     ` Rafael J. Wysocki

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=3428063.tN1BxOoXSN@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=akpm@linux-foundation.org \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=jiang.liu@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=travis@sgi.com \
    --cc=treding@nvidia.com \
    --cc=vgoyal@redhat.com \
    --cc=vinod.koul@intel.com \
    --cc=x86@kernel.org \
    --cc=yinghai@kernel.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

all inboxes | Powered by JetHome®