aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiang Liu <jiang.liu@linux.intel.com>2015-02-05 00:44:43 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-02-05 09:09:25 -0500
commit90e97820619dc912b52cc9d103272819d8b51259 (patch)
tree20e8c3000c47b0dea7eca79ef7c49db916606d65
parent62d1141ff34e35de496ba06491c8e854b23b3f3e (diff)
resources: Move struct resource_list_entry from ACPI into resource core
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. So move struct resource_list_entry from ACPI into resource core and rename it as resource_entry, then it could be reused by different subystems and avoid the data structure conversion. Introduce dedicated header file resource_ext.h instead of embedding it into ioport.h to avoid header file inclusion order issues. Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com> Acked-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/acpi_lpss.c8
-rw-r--r--drivers/acpi/acpi_platform.c4
-rw-r--r--drivers/acpi/resource.c17
-rw-r--r--drivers/dma/acpi-dma.c10
-rw-r--r--include/linux/acpi.h12
-rw-r--r--include/linux/resource_ext.h77
-rw-r--r--kernel/resource.c25
7 files changed, 120 insertions, 33 deletions
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 4f3febf8a589..dfd1b8095dad 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -313,7 +313,7 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
313{ 313{
314 struct lpss_device_desc *dev_desc; 314 struct lpss_device_desc *dev_desc;
315 struct lpss_private_data *pdata; 315 struct lpss_private_data *pdata;
316 struct resource_list_entry *rentry; 316 struct resource_entry *rentry;
317 struct list_head resource_list; 317 struct list_head resource_list;
318 struct platform_device *pdev; 318 struct platform_device *pdev;
319 int ret; 319 int ret;
@@ -333,12 +333,12 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
333 goto err_out; 333 goto err_out;
334 334
335 list_for_each_entry(rentry, &resource_list, node) 335 list_for_each_entry(rentry, &resource_list, node)
336 if (resource_type(&rentry->res) == IORESOURCE_MEM) { 336 if (resource_type(rentry->res) == IORESOURCE_MEM) {
337 if (dev_desc->prv_size_override) 337 if (dev_desc->prv_size_override)
338 pdata->mmio_size = dev_desc->prv_size_override; 338 pdata->mmio_size = dev_desc->prv_size_override;
339 else 339 else
340 pdata->mmio_size = resource_size(&rentry->res); 340 pdata->mmio_size = resource_size(rentry->res);
341 pdata->mmio_base = ioremap(rentry->res.start, 341 pdata->mmio_base = ioremap(rentry->res->start,
342 pdata->mmio_size); 342 pdata->mmio_size);
343 break; 343 break;
344 } 344 }
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 6ba8beb6b9d2..1284138e42ab 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -45,7 +45,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
45 struct platform_device *pdev = NULL; 45 struct platform_device *pdev = NULL;
46 struct acpi_device *acpi_parent; 46 struct acpi_device *acpi_parent;
47 struct platform_device_info pdevinfo; 47 struct platform_device_info pdevinfo;
48 struct resource_list_entry *rentry; 48 struct resource_entry *rentry;
49 struct list_head resource_list; 49 struct list_head resource_list;
50 struct resource *resources = NULL; 50 struct resource *resources = NULL;
51 int count; 51 int count;
@@ -71,7 +71,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
71 } 71 }
72 count = 0; 72 count = 0;
73 list_for_each_entry(rentry, &resource_list, node) 73 list_for_each_entry(rentry, &resource_list, node)
74 resources[count++] = rentry->res; 74 resources[count++] = *rentry->res;
75 75
76 acpi_dev_free_resource_list(&resource_list); 76 acpi_dev_free_resource_list(&resource_list);
77 } 77 }
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 3ea0d17eb951..4752b9939987 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -444,12 +444,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_resource_interrupt);
444 */ 444 */
445void acpi_dev_free_resource_list(struct list_head *list) 445void acpi_dev_free_resource_list(struct list_head *list)
446{ 446{
447 struct resource_list_entry *rentry, *re; 447 resource_list_free(list);
448
449 list_for_each_entry_safe(rentry, re, list, node) {
450 list_del(&rentry->node);
451 kfree(rentry);
452 }
453} 448}
454EXPORT_SYMBOL_GPL(acpi_dev_free_resource_list); 449EXPORT_SYMBOL_GPL(acpi_dev_free_resource_list);
455 450
@@ -464,16 +459,16 @@ struct res_proc_context {
464static acpi_status acpi_dev_new_resource_entry(struct resource_win *win, 459static acpi_status acpi_dev_new_resource_entry(struct resource_win *win,
465 struct res_proc_context *c) 460 struct res_proc_context *c)
466{ 461{
467 struct resource_list_entry *rentry; 462 struct resource_entry *rentry;
468 463
469 rentry = kmalloc(sizeof(*rentry), GFP_KERNEL); 464 rentry = resource_list_create_entry(NULL, 0);
470 if (!rentry) { 465 if (!rentry) {
471 c->error = -ENOMEM; 466 c->error = -ENOMEM;
472 return AE_NO_MEMORY; 467 return AE_NO_MEMORY;
473 } 468 }
474 rentry->res = win->res; 469 *rentry->res = win->res;
475 rentry->offset = win->offset; 470 rentry->offset = win->offset;
476 list_add_tail(&rentry->node, c->list); 471 resource_list_add_tail(rentry, c->list);
477 c->count++; 472 c->count++;
478 return AE_OK; 473 return AE_OK;
479} 474}
@@ -534,7 +529,7 @@ static acpi_status acpi_dev_process_resource(struct acpi_resource *ares,
534 * returned as the final error code. 529 * returned as the final error code.
535 * 530 *
536 * The resultant struct resource objects are put on the list pointed to by 531 * The resultant struct resource objects are put on the list pointed to by
537 * @list, that must be empty initially, as members of struct resource_list_entry 532 * @list, that must be empty initially, as members of struct resource_entry
538 * objects. Callers of this routine should use %acpi_dev_free_resource_list() to 533 * objects. Callers of this routine should use %acpi_dev_free_resource_list() to
539 * free that list. 534 * free that list.
540 * 535 *
diff --git a/drivers/dma/acpi-dma.c b/drivers/dma/acpi-dma.c
index de361a156b34..5a635646e05c 100644
--- a/drivers/dma/acpi-dma.c
+++ b/drivers/dma/acpi-dma.c
@@ -43,7 +43,7 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
43{ 43{
44 const struct acpi_csrt_shared_info *si; 44 const struct acpi_csrt_shared_info *si;
45 struct list_head resource_list; 45 struct list_head resource_list;
46 struct resource_list_entry *rentry; 46 struct resource_entry *rentry;
47 resource_size_t mem = 0, irq = 0; 47 resource_size_t mem = 0, irq = 0;
48 int ret; 48 int ret;
49 49
@@ -56,10 +56,10 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
56 return 0; 56 return 0;
57 57
58 list_for_each_entry(rentry, &resource_list, node) { 58 list_for_each_entry(rentry, &resource_list, node) {
59 if (resource_type(&rentry->res) == IORESOURCE_MEM) 59 if (resource_type(rentry->res) == IORESOURCE_MEM)
60 mem = rentry->res.start; 60 mem = rentry->res->start;
61 else if (resource_type(&rentry->res) == IORESOURCE_IRQ) 61 else if (resource_type(rentry->res) == IORESOURCE_IRQ)
62 irq = rentry->res.start; 62 irq = rentry->res->start;
63 } 63 }
64 64
65 acpi_dev_free_resource_list(&resource_list); 65 acpi_dev_free_resource_list(&resource_list);
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index e818decb631f..e53822148b6a 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -27,6 +27,7 @@
27 27
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/ioport.h> /* for struct resource */ 29#include <linux/ioport.h> /* for struct resource */
30#include <linux/resource_ext.h>
30#include <linux/device.h> 31#include <linux/device.h>
31#include <linux/property.h> 32#include <linux/property.h>
32 33
@@ -285,11 +286,6 @@ extern int pnpacpi_disabled;
285 286
286#define PXM_INVAL (-1) 287#define PXM_INVAL (-1)
287 288
288struct resource_win {
289 struct resource res;
290 resource_size_t offset;
291};
292
293bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res); 289bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res);
294bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res); 290bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res);
295bool acpi_dev_resource_address_space(struct acpi_resource *ares, 291bool acpi_dev_resource_address_space(struct acpi_resource *ares,
@@ -300,12 +296,6 @@ unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable);
300bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, 296bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,
301 struct resource *res); 297 struct resource *res);
302 298
303struct resource_list_entry {
304 struct list_head node;
305 struct resource res;
306 resource_size_t offset;
307};
308
309void acpi_dev_free_resource_list(struct list_head *list); 299void acpi_dev_free_resource_list(struct list_head *list);
310int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list, 300int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
311 int (*preproc)(struct acpi_resource *, void *), 301 int (*preproc)(struct acpi_resource *, void *),
diff --git a/include/linux/resource_ext.h b/include/linux/resource_ext.h
new file mode 100644
index 000000000000..e2bf63d881d4
--- /dev/null
+++ b/include/linux/resource_ext.h
@@ -0,0 +1,77 @@
1/*
2 * Copyright (C) 2015, Intel Corporation
3 * Author: Jiang Liu <jiang.liu@linux.intel.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14#ifndef _LINUX_RESOURCE_EXT_H
15#define _LINUX_RESOURCE_EXT_H
16#include <linux/types.h>
17#include <linux/list.h>
18#include <linux/ioport.h>
19#include <linux/slab.h>
20
21/* Represent resource window for bridge devices */
22struct resource_win {
23 struct resource res; /* In master (CPU) address space */
24 resource_size_t offset; /* Translation offset for bridge */
25};
26
27/*
28 * Common resource list management data structure and interfaces to support
29 * ACPI, PNP and PCI host bridge etc.
30 */
31struct resource_entry {
32 struct list_head node;
33 struct resource *res; /* In master (CPU) address space */
34 resource_size_t offset; /* Translation offset for bridge */
35 struct resource __res; /* Default storage for res */
36};
37
38extern struct resource_entry *
39resource_list_create_entry(struct resource *res, size_t extra_size);
40extern void resource_list_free(struct list_head *head);
41
42static inline void resource_list_add(struct resource_entry *entry,
43 struct list_head *head)
44{
45 list_add(&entry->node, head);
46}
47
48static inline void resource_list_add_tail(struct resource_entry *entry,
49 struct list_head *head)
50{
51 list_add_tail(&entry->node, head);
52}
53
54static inline void resource_list_del(struct resource_entry *entry)
55{
56 list_del(&entry->node);
57}
58
59static inline void resource_list_free_entry(struct resource_entry *entry)
60{
61 kfree(entry);
62}
63
64static inline void
65resource_list_destroy_entry(struct resource_entry *entry)
66{
67 resource_list_del(entry);
68 resource_list_free_entry(entry);
69}
70
71#define resource_list_for_each_entry(entry, list) \
72 list_for_each_entry((entry), (list), node)
73
74#define resource_list_for_each_entry_safe(entry, tmp, list) \
75 list_for_each_entry_safe((entry), (tmp), (list), node)
76
77#endif /* _LINUX_RESOURCE_EXT_H */
diff --git a/kernel/resource.c b/kernel/resource.c
index 0bcebffc4e77..19f2357dfda3 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -22,6 +22,7 @@
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/pfn.h> 23#include <linux/pfn.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/resource_ext.h>
25#include <asm/io.h> 26#include <asm/io.h>
26 27
27 28
@@ -1529,6 +1530,30 @@ int iomem_is_exclusive(u64 addr)
1529 return err; 1530 return err;
1530} 1531}
1531 1532
1533struct resource_entry *resource_list_create_entry(struct resource *res,
1534 size_t extra_size)
1535{
1536 struct resource_entry *entry;
1537
1538 entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL);
1539 if (entry) {
1540 INIT_LIST_HEAD(&entry->node);
1541 entry->res = res ? res : &entry->__res;
1542 }
1543
1544 return entry;
1545}
1546EXPORT_SYMBOL(resource_list_create_entry);
1547
1548void resource_list_free(struct list_head *head)
1549{
1550 struct resource_entry *entry, *tmp;
1551
1552 list_for_each_entry_safe(entry, tmp, head, node)
1553 resource_list_destroy_entry(entry);
1554}
1555EXPORT_SYMBOL(resource_list_free);
1556
1532static int __init strict_iomem(char *str) 1557static int __init strict_iomem(char *str)
1533{ 1558{
1534 if (strstr(str, "relaxed")) 1559 if (strstr(str, "relaxed"))