2012-11-01 04:45:02 +07:00
|
|
|
/*
|
|
|
|
* ACPI support for platform bus type.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012, Intel Corporation
|
|
|
|
* Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
|
|
* Mathias Nyman <mathias.nyman@linux.intel.com>
|
|
|
|
* Rafael J. Wysocki <rafael.j.wysocki@intel.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/device.h>
|
2013-01-18 20:46:01 +07:00
|
|
|
#include <linux/err.h>
|
2012-11-01 04:45:02 +07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2014-09-24 15:00:37 +07:00
|
|
|
#include <linux/dma-mapping.h>
|
2012-11-01 04:45:02 +07:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2012-11-26 16:35:07 +07:00
|
|
|
#include "internal.h"
|
|
|
|
|
2012-11-01 04:45:02 +07:00
|
|
|
ACPI_MODULE_NAME("platform");
|
|
|
|
|
2014-05-30 19:35:34 +07:00
|
|
|
static const struct acpi_device_id forbidden_id_list[] = {
|
|
|
|
{"PNP0000", 0}, /* PIC */
|
|
|
|
{"PNP0100", 0}, /* Timer */
|
|
|
|
{"PNP0200", 0}, /* AT DMA Controller */
|
|
|
|
{"", 0},
|
2013-01-30 20:27:40 +07:00
|
|
|
};
|
|
|
|
|
2012-11-01 04:45:02 +07:00
|
|
|
/**
|
|
|
|
* acpi_create_platform_device - Create platform device for ACPI device node
|
|
|
|
* @adev: ACPI device node to create a platform device for.
|
|
|
|
*
|
|
|
|
* Check if the given @adev can be represented as a platform device and, if
|
|
|
|
* that's the case, create and register a platform device, populate its common
|
|
|
|
* resources and returns a pointer to it. Otherwise, return %NULL.
|
|
|
|
*
|
2013-01-18 21:09:35 +07:00
|
|
|
* Name of the platform device will be the same as @adev's.
|
2012-11-01 04:45:02 +07:00
|
|
|
*/
|
2014-05-25 19:38:52 +07:00
|
|
|
struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
|
2012-11-01 04:45:02 +07:00
|
|
|
{
|
|
|
|
struct platform_device *pdev = NULL;
|
|
|
|
struct acpi_device *acpi_parent;
|
ACPI / platform: Initialize ACPI handles of platform devices in advance
The current platform device creation and registration code in
acpi_create_platform_device() is quite convoluted. This function
takes an ACPI device node as an argument and eventually calls
platform_device_register_resndata() to create and register a
platform device object on the basis of the information contained
in that code. However, it doesn't associate the new platform
device with the ACPI node directly, but instead it relies on
acpi_platform_notify(), called from within device_add(), to find
that ACPI node again with the help of acpi_platform_find_device()
and acpi_platform_match() and then attach the new platform device
to it. This causes an additional ACPI namespace walk to happen and
is clearly suboptimal.
Use the observation that it is now possible to initialize the ACPI
handle of a device before calling device_add() for it to make this
code more straightforward. Namely, add a new field to struct
platform_device_info allowing us to pass the ACPI handle of interest
to platform_device_register_full(), which will then use it to
initialize the new device's ACPI handle before registering it.
This will cause acpi_platform_notify() to use the ACPI handle from
the device structure directly instead of using the .find_device()
routine provided by the device's bus type. In consequence,
acpi_platform_bus, acpi_platform_find_device(), and
acpi_platform_match() are not necessary any more, so remove them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-21 06:21:59 +07:00
|
|
|
struct platform_device_info pdevinfo;
|
2015-02-05 12:44:43 +07:00
|
|
|
struct resource_entry *rentry;
|
ACPI: Centralized processing of ACPI device resources
Currently, whoever wants to use ACPI device resources has to call
acpi_walk_resources() to browse the buffer returned by the _CRS
method for the given device and create filters passed to that
routine to apply to the individual resource items. This generally
is cumbersome, time-consuming and inefficient. Moreover, it may
be problematic if resource conflicts need to be resolved, because
the different users of _CRS will need to do that in a consistent
way. However, if there are resource conflicts, the ACPI core
should be able to resolve them centrally instead of relying on
various users of acpi_walk_resources() to handle them correctly
together.
For this reason, introduce a new function, acpi_dev_get_resources(),
that can be used by subsystems to obtain a list of struct resource
objects corresponding to the ACPI device resources returned by
_CRS and, if necessary, to apply additional preprocessing routine
to the ACPI resources before converting them to the struct resource
format.
Make the ACPI code that creates platform device objects use
acpi_dev_get_resources() for resource processing instead of executing
acpi_walk_resources() twice by itself, which causes it to be much
more straightforward and easier to follow.
In the future, acpi_dev_get_resources() can be extended to meet
the needs of the ACPI PNP subsystem and other users of _CRS in
the kernel.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2012-11-15 06:30:21 +07:00
|
|
|
struct list_head resource_list;
|
2013-07-23 06:51:20 +07:00
|
|
|
struct resource *resources = NULL;
|
ACPI: Centralized processing of ACPI device resources
Currently, whoever wants to use ACPI device resources has to call
acpi_walk_resources() to browse the buffer returned by the _CRS
method for the given device and create filters passed to that
routine to apply to the individual resource items. This generally
is cumbersome, time-consuming and inefficient. Moreover, it may
be problematic if resource conflicts need to be resolved, because
the different users of _CRS will need to do that in a consistent
way. However, if there are resource conflicts, the ACPI core
should be able to resolve them centrally instead of relying on
various users of acpi_walk_resources() to handle them correctly
together.
For this reason, introduce a new function, acpi_dev_get_resources(),
that can be used by subsystems to obtain a list of struct resource
objects corresponding to the ACPI device resources returned by
_CRS and, if necessary, to apply additional preprocessing routine
to the ACPI resources before converting them to the struct resource
format.
Make the ACPI code that creates platform device objects use
acpi_dev_get_resources() for resource processing instead of executing
acpi_walk_resources() twice by itself, which causes it to be much
more straightforward and easier to follow.
In the future, acpi_dev_get_resources() can be extended to meet
the needs of the ACPI PNP subsystem and other users of _CRS in
the kernel.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2012-11-15 06:30:21 +07:00
|
|
|
int count;
|
2012-11-01 04:45:02 +07:00
|
|
|
|
|
|
|
/* If the ACPI node already has a physical device attached, skip it. */
|
|
|
|
if (adev->physical_node_count)
|
2014-05-25 19:38:52 +07:00
|
|
|
return NULL;
|
2012-11-01 04:45:02 +07:00
|
|
|
|
2014-05-30 19:35:34 +07:00
|
|
|
if (!acpi_match_device_ids(adev, forbidden_id_list))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
ACPI: Centralized processing of ACPI device resources
Currently, whoever wants to use ACPI device resources has to call
acpi_walk_resources() to browse the buffer returned by the _CRS
method for the given device and create filters passed to that
routine to apply to the individual resource items. This generally
is cumbersome, time-consuming and inefficient. Moreover, it may
be problematic if resource conflicts need to be resolved, because
the different users of _CRS will need to do that in a consistent
way. However, if there are resource conflicts, the ACPI core
should be able to resolve them centrally instead of relying on
various users of acpi_walk_resources() to handle them correctly
together.
For this reason, introduce a new function, acpi_dev_get_resources(),
that can be used by subsystems to obtain a list of struct resource
objects corresponding to the ACPI device resources returned by
_CRS and, if necessary, to apply additional preprocessing routine
to the ACPI resources before converting them to the struct resource
format.
Make the ACPI code that creates platform device objects use
acpi_dev_get_resources() for resource processing instead of executing
acpi_walk_resources() twice by itself, which causes it to be much
more straightforward and easier to follow.
In the future, acpi_dev_get_resources() can be extended to meet
the needs of the ACPI PNP subsystem and other users of _CRS in
the kernel.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2012-11-15 06:30:21 +07:00
|
|
|
INIT_LIST_HEAD(&resource_list);
|
|
|
|
count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
|
2013-08-07 06:11:33 +07:00
|
|
|
if (count < 0) {
|
2014-05-25 19:38:52 +07:00
|
|
|
return NULL;
|
2013-08-07 06:11:33 +07:00
|
|
|
} else if (count > 0) {
|
|
|
|
resources = kmalloc(count * sizeof(struct resource),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!resources) {
|
|
|
|
dev_err(&adev->dev, "No memory for resources\n");
|
|
|
|
acpi_dev_free_resource_list(&resource_list);
|
2014-05-25 19:38:52 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2013-08-07 06:11:33 +07:00
|
|
|
}
|
|
|
|
count = 0;
|
|
|
|
list_for_each_entry(rentry, &resource_list, node)
|
2015-02-05 12:44:43 +07:00
|
|
|
resources[count++] = *rentry->res;
|
2012-11-01 04:45:02 +07:00
|
|
|
|
ACPI: Centralized processing of ACPI device resources
Currently, whoever wants to use ACPI device resources has to call
acpi_walk_resources() to browse the buffer returned by the _CRS
method for the given device and create filters passed to that
routine to apply to the individual resource items. This generally
is cumbersome, time-consuming and inefficient. Moreover, it may
be problematic if resource conflicts need to be resolved, because
the different users of _CRS will need to do that in a consistent
way. However, if there are resource conflicts, the ACPI core
should be able to resolve them centrally instead of relying on
various users of acpi_walk_resources() to handle them correctly
together.
For this reason, introduce a new function, acpi_dev_get_resources(),
that can be used by subsystems to obtain a list of struct resource
objects corresponding to the ACPI device resources returned by
_CRS and, if necessary, to apply additional preprocessing routine
to the ACPI resources before converting them to the struct resource
format.
Make the ACPI code that creates platform device objects use
acpi_dev_get_resources() for resource processing instead of executing
acpi_walk_resources() twice by itself, which causes it to be much
more straightforward and easier to follow.
In the future, acpi_dev_get_resources() can be extended to meet
the needs of the ACPI PNP subsystem and other users of _CRS in
the kernel.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2012-11-15 06:30:21 +07:00
|
|
|
acpi_dev_free_resource_list(&resource_list);
|
2012-11-01 04:45:02 +07:00
|
|
|
}
|
|
|
|
|
ACPI / platform: Initialize ACPI handles of platform devices in advance
The current platform device creation and registration code in
acpi_create_platform_device() is quite convoluted. This function
takes an ACPI device node as an argument and eventually calls
platform_device_register_resndata() to create and register a
platform device object on the basis of the information contained
in that code. However, it doesn't associate the new platform
device with the ACPI node directly, but instead it relies on
acpi_platform_notify(), called from within device_add(), to find
that ACPI node again with the help of acpi_platform_find_device()
and acpi_platform_match() and then attach the new platform device
to it. This causes an additional ACPI namespace walk to happen and
is clearly suboptimal.
Use the observation that it is now possible to initialize the ACPI
handle of a device before calling device_add() for it to make this
code more straightforward. Namely, add a new field to struct
platform_device_info allowing us to pass the ACPI handle of interest
to platform_device_register_full(), which will then use it to
initialize the new device's ACPI handle before registering it.
This will cause acpi_platform_notify() to use the ACPI handle from
the device structure directly instead of using the .find_device()
routine provided by the device's bus type. In consequence,
acpi_platform_bus, acpi_platform_find_device(), and
acpi_platform_match() are not necessary any more, so remove them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-21 06:21:59 +07:00
|
|
|
memset(&pdevinfo, 0, sizeof(pdevinfo));
|
2012-11-01 04:45:02 +07:00
|
|
|
/*
|
|
|
|
* If the ACPI node has a parent and that parent has a physical device
|
|
|
|
* attached to it, that physical device should be the parent of the
|
|
|
|
* platform device we are about to create.
|
|
|
|
*/
|
ACPI / platform: Initialize ACPI handles of platform devices in advance
The current platform device creation and registration code in
acpi_create_platform_device() is quite convoluted. This function
takes an ACPI device node as an argument and eventually calls
platform_device_register_resndata() to create and register a
platform device object on the basis of the information contained
in that code. However, it doesn't associate the new platform
device with the ACPI node directly, but instead it relies on
acpi_platform_notify(), called from within device_add(), to find
that ACPI node again with the help of acpi_platform_find_device()
and acpi_platform_match() and then attach the new platform device
to it. This causes an additional ACPI namespace walk to happen and
is clearly suboptimal.
Use the observation that it is now possible to initialize the ACPI
handle of a device before calling device_add() for it to make this
code more straightforward. Namely, add a new field to struct
platform_device_info allowing us to pass the ACPI handle of interest
to platform_device_register_full(), which will then use it to
initialize the new device's ACPI handle before registering it.
This will cause acpi_platform_notify() to use the ACPI handle from
the device structure directly instead of using the .find_device()
routine provided by the device's bus type. In consequence,
acpi_platform_bus, acpi_platform_find_device(), and
acpi_platform_match() are not necessary any more, so remove them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-21 06:21:59 +07:00
|
|
|
pdevinfo.parent = NULL;
|
2012-11-01 04:45:02 +07:00
|
|
|
acpi_parent = adev->parent;
|
|
|
|
if (acpi_parent) {
|
|
|
|
struct acpi_device_physical_node *entry;
|
|
|
|
struct list_head *list;
|
|
|
|
|
|
|
|
mutex_lock(&acpi_parent->physical_node_lock);
|
|
|
|
list = &acpi_parent->physical_node_list;
|
|
|
|
if (!list_empty(list)) {
|
|
|
|
entry = list_first_entry(list,
|
|
|
|
struct acpi_device_physical_node,
|
|
|
|
node);
|
ACPI / platform: Initialize ACPI handles of platform devices in advance
The current platform device creation and registration code in
acpi_create_platform_device() is quite convoluted. This function
takes an ACPI device node as an argument and eventually calls
platform_device_register_resndata() to create and register a
platform device object on the basis of the information contained
in that code. However, it doesn't associate the new platform
device with the ACPI node directly, but instead it relies on
acpi_platform_notify(), called from within device_add(), to find
that ACPI node again with the help of acpi_platform_find_device()
and acpi_platform_match() and then attach the new platform device
to it. This causes an additional ACPI namespace walk to happen and
is clearly suboptimal.
Use the observation that it is now possible to initialize the ACPI
handle of a device before calling device_add() for it to make this
code more straightforward. Namely, add a new field to struct
platform_device_info allowing us to pass the ACPI handle of interest
to platform_device_register_full(), which will then use it to
initialize the new device's ACPI handle before registering it.
This will cause acpi_platform_notify() to use the ACPI handle from
the device structure directly instead of using the .find_device()
routine provided by the device's bus type. In consequence,
acpi_platform_bus, acpi_platform_find_device(), and
acpi_platform_match() are not necessary any more, so remove them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-21 06:21:59 +07:00
|
|
|
pdevinfo.parent = entry->dev;
|
2012-11-01 04:45:02 +07:00
|
|
|
}
|
|
|
|
mutex_unlock(&acpi_parent->physical_node_lock);
|
|
|
|
}
|
ACPI / platform: Initialize ACPI handles of platform devices in advance
The current platform device creation and registration code in
acpi_create_platform_device() is quite convoluted. This function
takes an ACPI device node as an argument and eventually calls
platform_device_register_resndata() to create and register a
platform device object on the basis of the information contained
in that code. However, it doesn't associate the new platform
device with the ACPI node directly, but instead it relies on
acpi_platform_notify(), called from within device_add(), to find
that ACPI node again with the help of acpi_platform_find_device()
and acpi_platform_match() and then attach the new platform device
to it. This causes an additional ACPI namespace walk to happen and
is clearly suboptimal.
Use the observation that it is now possible to initialize the ACPI
handle of a device before calling device_add() for it to make this
code more straightforward. Namely, add a new field to struct
platform_device_info allowing us to pass the ACPI handle of interest
to platform_device_register_full(), which will then use it to
initialize the new device's ACPI handle before registering it.
This will cause acpi_platform_notify() to use the ACPI handle from
the device structure directly instead of using the .find_device()
routine provided by the device's bus type. In consequence,
acpi_platform_bus, acpi_platform_find_device(), and
acpi_platform_match() are not necessary any more, so remove them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-21 06:21:59 +07:00
|
|
|
pdevinfo.name = dev_name(&adev->dev);
|
|
|
|
pdevinfo.id = -1;
|
|
|
|
pdevinfo.res = resources;
|
|
|
|
pdevinfo.num_res = count;
|
2015-03-17 05:49:03 +07:00
|
|
|
pdevinfo.fwnode = acpi_fwnode_handle(adev);
|
2014-09-24 15:00:37 +07:00
|
|
|
pdevinfo.dma_mask = DMA_BIT_MASK(32);
|
ACPI / platform: Initialize ACPI handles of platform devices in advance
The current platform device creation and registration code in
acpi_create_platform_device() is quite convoluted. This function
takes an ACPI device node as an argument and eventually calls
platform_device_register_resndata() to create and register a
platform device object on the basis of the information contained
in that code. However, it doesn't associate the new platform
device with the ACPI node directly, but instead it relies on
acpi_platform_notify(), called from within device_add(), to find
that ACPI node again with the help of acpi_platform_find_device()
and acpi_platform_match() and then attach the new platform device
to it. This causes an additional ACPI namespace walk to happen and
is clearly suboptimal.
Use the observation that it is now possible to initialize the ACPI
handle of a device before calling device_add() for it to make this
code more straightforward. Namely, add a new field to struct
platform_device_info allowing us to pass the ACPI handle of interest
to platform_device_register_full(), which will then use it to
initialize the new device's ACPI handle before registering it.
This will cause acpi_platform_notify() to use the ACPI handle from
the device structure directly instead of using the .find_device()
routine provided by the device's bus type. In consequence,
acpi_platform_bus, acpi_platform_find_device(), and
acpi_platform_match() are not necessary any more, so remove them.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-21 06:21:59 +07:00
|
|
|
pdev = platform_device_register_full(&pdevinfo);
|
2014-05-25 19:38:52 +07:00
|
|
|
if (IS_ERR(pdev))
|
2012-11-01 04:45:02 +07:00
|
|
|
dev_err(&adev->dev, "platform device creation failed: %ld\n",
|
|
|
|
PTR_ERR(pdev));
|
2014-05-25 19:38:52 +07:00
|
|
|
else
|
2012-11-01 04:45:02 +07:00
|
|
|
dev_dbg(&adev->dev, "created platform device %s\n",
|
|
|
|
dev_name(&pdev->dev));
|
|
|
|
|
ACPI: Centralized processing of ACPI device resources
Currently, whoever wants to use ACPI device resources has to call
acpi_walk_resources() to browse the buffer returned by the _CRS
method for the given device and create filters passed to that
routine to apply to the individual resource items. This generally
is cumbersome, time-consuming and inefficient. Moreover, it may
be problematic if resource conflicts need to be resolved, because
the different users of _CRS will need to do that in a consistent
way. However, if there are resource conflicts, the ACPI core
should be able to resolve them centrally instead of relying on
various users of acpi_walk_resources() to handle them correctly
together.
For this reason, introduce a new function, acpi_dev_get_resources(),
that can be used by subsystems to obtain a list of struct resource
objects corresponding to the ACPI device resources returned by
_CRS and, if necessary, to apply additional preprocessing routine
to the ACPI resources before converting them to the struct resource
format.
Make the ACPI code that creates platform device objects use
acpi_dev_get_resources() for resource processing instead of executing
acpi_walk_resources() twice by itself, which causes it to be much
more straightforward and easier to follow.
In the future, acpi_dev_get_resources() can be extended to meet
the needs of the ACPI PNP subsystem and other users of _CRS in
the kernel.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2012-11-15 06:30:21 +07:00
|
|
|
kfree(resources);
|
2014-05-25 19:38:52 +07:00
|
|
|
return pdev;
|
|
|
|
}
|
2014-03-14 13:06:25 +07:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_create_platform_device);
|