diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2013-01-10 13:18:41 -0500 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2013-01-10 13:18:41 -0500 |
commit | 295a7f6235bfa21be3454aebc1bea1eaf0b74fb7 (patch) | |
tree | ae253b12eb331e1d093a3f348b4f8045e80f5e53 /drivers/acpi/scan.c | |
parent | b3e65e1f9185a2eb034defe4270ba178ba70b9a9 (diff) | |
parent | f95988de06ea62ef5bd861f06e9ef56cea405ed1 (diff) |
Merge branch 'acpi-scan' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm into pci/yinghai-survey-resources+acpi-scan
* 'acpi-scan' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
ACPI / scan: Treat power resources in a special way
ACPI: Remove unused struct acpi_pci_root.id member
ACPI: Drop ACPI device .bind() and .unbind() callbacks
ACPI / PCI: Move the _PRT setup and cleanup code to pci-acpi.c
ACPI / PCI: Rework the setup and cleanup of device wakeup
ACPI: Add .setup() and .cleanup() callbacks to struct acpi_bus_type
ACPI: Make acpi_bus_scan() and acpi_bus_add() take only one argument
ACPI: Replace ACPI device add_type field with a match_driver flag
ACPI: Drop the second argument of acpi_bus_scan()
ACPI: Remove the arguments of acpi_bus_add() that are not used
ACPI: Remove acpi_start_single_object() and acpi_bus_start()
ACPI / PCI: Fold acpi_pci_root_start() into acpi_pci_root_add()
ACPI: Change the ordering of acpi_bus_check_add()
ACPI: Replace struct acpi_bus_ops with enum type
ACPI: Reduce the usage of struct acpi_bus_ops
ACPI: Make acpi_bus_add() and acpi_bus_start() visibly different
ACPI: Change the ordering of PCI root bridge driver registrarion
ACPI: Separate adding ACPI device objects from probing ACPI drivers
Conflicts:
drivers/acpi/pci_root.c
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r-- | drivers/acpi/scan.c | 208 |
1 files changed, 77 insertions, 131 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 53502d1bbf26..e380345b643a 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -494,7 +494,8 @@ static int acpi_bus_match(struct device *dev, struct device_driver *drv) | |||
494 | struct acpi_device *acpi_dev = to_acpi_device(dev); | 494 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
495 | struct acpi_driver *acpi_drv = to_acpi_driver(drv); | 495 | struct acpi_driver *acpi_drv = to_acpi_driver(drv); |
496 | 496 | ||
497 | return !acpi_match_device_ids(acpi_dev, acpi_drv->ids); | 497 | return acpi_dev->flags.match_driver |
498 | && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); | ||
498 | } | 499 | } |
499 | 500 | ||
500 | static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) | 501 | static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
@@ -570,7 +571,6 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device) | |||
570 | } | 571 | } |
571 | 572 | ||
572 | static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); | 573 | static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); |
573 | static int acpi_start_single_object(struct acpi_device *); | ||
574 | static int acpi_device_probe(struct device * dev) | 574 | static int acpi_device_probe(struct device * dev) |
575 | { | 575 | { |
576 | struct acpi_device *acpi_dev = to_acpi_device(dev); | 576 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
@@ -579,9 +579,6 @@ static int acpi_device_probe(struct device * dev) | |||
579 | 579 | ||
580 | ret = acpi_bus_driver_init(acpi_dev, acpi_drv); | 580 | ret = acpi_bus_driver_init(acpi_dev, acpi_drv); |
581 | if (!ret) { | 581 | if (!ret) { |
582 | if (acpi_dev->bus_ops.acpi_op_start) | ||
583 | acpi_start_single_object(acpi_dev); | ||
584 | |||
585 | if (acpi_drv->ops.notify) { | 582 | if (acpi_drv->ops.notify) { |
586 | ret = acpi_device_install_notify_handler(acpi_dev); | 583 | ret = acpi_device_install_notify_handler(acpi_dev); |
587 | if (ret) { | 584 | if (ret) { |
@@ -760,24 +757,6 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver) | |||
760 | return 0; | 757 | return 0; |
761 | } | 758 | } |
762 | 759 | ||
763 | static int acpi_start_single_object(struct acpi_device *device) | ||
764 | { | ||
765 | int result = 0; | ||
766 | struct acpi_driver *driver; | ||
767 | |||
768 | |||
769 | if (!(driver = device->driver)) | ||
770 | return 0; | ||
771 | |||
772 | if (driver->ops.start) { | ||
773 | result = driver->ops.start(device); | ||
774 | if (result && driver->ops.remove) | ||
775 | driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); | ||
776 | } | ||
777 | |||
778 | return result; | ||
779 | } | ||
780 | |||
781 | /** | 760 | /** |
782 | * acpi_bus_register_driver - register a driver with the ACPI bus | 761 | * acpi_bus_register_driver - register a driver with the ACPI bus |
783 | * @driver: driver being registered | 762 | * @driver: driver being registered |
@@ -1406,13 +1385,6 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) | |||
1406 | if (!rmdevice) | 1385 | if (!rmdevice) |
1407 | return 0; | 1386 | return 0; |
1408 | 1387 | ||
1409 | /* | ||
1410 | * unbind _ADR-Based Devices when hot removal | ||
1411 | */ | ||
1412 | if (dev->flags.bus_address) { | ||
1413 | if ((dev->parent) && (dev->parent->ops.unbind)) | ||
1414 | dev->parent->ops.unbind(dev); | ||
1415 | } | ||
1416 | acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); | 1388 | acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); |
1417 | 1389 | ||
1418 | return 0; | 1390 | return 0; |
@@ -1420,8 +1392,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) | |||
1420 | 1392 | ||
1421 | static int acpi_add_single_object(struct acpi_device **child, | 1393 | static int acpi_add_single_object(struct acpi_device **child, |
1422 | acpi_handle handle, int type, | 1394 | acpi_handle handle, int type, |
1423 | unsigned long long sta, | 1395 | unsigned long long sta, bool match_driver) |
1424 | struct acpi_bus_ops *ops) | ||
1425 | { | 1396 | { |
1426 | int result; | 1397 | int result; |
1427 | struct acpi_device *device; | 1398 | struct acpi_device *device; |
@@ -1437,7 +1408,6 @@ static int acpi_add_single_object(struct acpi_device **child, | |||
1437 | device->device_type = type; | 1408 | device->device_type = type; |
1438 | device->handle = handle; | 1409 | device->handle = handle; |
1439 | device->parent = acpi_bus_get_parent(handle); | 1410 | device->parent = acpi_bus_get_parent(handle); |
1440 | device->bus_ops = *ops; /* workround for not call .start */ | ||
1441 | STRUCT_TO_INT(device->status) = sta; | 1411 | STRUCT_TO_INT(device->status) = sta; |
1442 | 1412 | ||
1443 | acpi_device_get_busid(device); | 1413 | acpi_device_get_busid(device); |
@@ -1488,16 +1458,9 @@ static int acpi_add_single_object(struct acpi_device **child, | |||
1488 | if ((result = acpi_device_set_context(device))) | 1458 | if ((result = acpi_device_set_context(device))) |
1489 | goto end; | 1459 | goto end; |
1490 | 1460 | ||
1461 | device->flags.match_driver = match_driver; | ||
1491 | result = acpi_device_register(device); | 1462 | result = acpi_device_register(device); |
1492 | 1463 | ||
1493 | /* | ||
1494 | * Bind _ADR-Based Devices when hot add | ||
1495 | */ | ||
1496 | if (device->flags.bus_address) { | ||
1497 | if (device->parent && device->parent->ops.bind) | ||
1498 | device->parent->ops.bind(device); | ||
1499 | } | ||
1500 | |||
1501 | end: | 1464 | end: |
1502 | if (!result) { | 1465 | if (!result) { |
1503 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | 1466 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
@@ -1519,16 +1482,12 @@ end: | |||
1519 | 1482 | ||
1520 | static void acpi_bus_add_power_resource(acpi_handle handle) | 1483 | static void acpi_bus_add_power_resource(acpi_handle handle) |
1521 | { | 1484 | { |
1522 | struct acpi_bus_ops ops = { | ||
1523 | .acpi_op_add = 1, | ||
1524 | .acpi_op_start = 1, | ||
1525 | }; | ||
1526 | struct acpi_device *device = NULL; | 1485 | struct acpi_device *device = NULL; |
1527 | 1486 | ||
1528 | acpi_bus_get_device(handle, &device); | 1487 | acpi_bus_get_device(handle, &device); |
1529 | if (!device) | 1488 | if (!device) |
1530 | acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER, | 1489 | acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER, |
1531 | ACPI_STA_DEFAULT, &ops); | 1490 | ACPI_STA_DEFAULT, true); |
1532 | } | 1491 | } |
1533 | 1492 | ||
1534 | static int acpi_bus_type_and_status(acpi_handle handle, int *type, | 1493 | static int acpi_bus_type_and_status(acpi_handle handle, int *type, |
@@ -1570,16 +1529,19 @@ static int acpi_bus_type_and_status(acpi_handle handle, int *type, | |||
1570 | return 0; | 1529 | return 0; |
1571 | } | 1530 | } |
1572 | 1531 | ||
1573 | static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl, | 1532 | static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, |
1574 | void *context, void **return_value) | 1533 | void *not_used, void **return_value) |
1575 | { | 1534 | { |
1576 | struct acpi_bus_ops *ops = context; | 1535 | struct acpi_device *device = NULL; |
1577 | int type; | 1536 | int type; |
1578 | unsigned long long sta; | 1537 | unsigned long long sta; |
1579 | struct acpi_device *device; | ||
1580 | acpi_status status; | 1538 | acpi_status status; |
1581 | int result; | 1539 | int result; |
1582 | 1540 | ||
1541 | acpi_bus_get_device(handle, &device); | ||
1542 | if (device) | ||
1543 | goto out; | ||
1544 | |||
1583 | result = acpi_bus_type_and_status(handle, &type, &sta); | 1545 | result = acpi_bus_type_and_status(handle, &type, &sta); |
1584 | if (result) | 1546 | if (result) |
1585 | return AE_OK; | 1547 | return AE_OK; |
@@ -1596,97 +1558,89 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl, | |||
1596 | return AE_CTRL_DEPTH; | 1558 | return AE_CTRL_DEPTH; |
1597 | } | 1559 | } |
1598 | 1560 | ||
1599 | /* | 1561 | acpi_add_single_object(&device, handle, type, sta, |
1600 | * We may already have an acpi_device from a previous enumeration. If | 1562 | type == ACPI_BUS_TYPE_POWER); |
1601 | * so, we needn't add it again, but we may still have to start it. | ||
1602 | */ | ||
1603 | device = NULL; | ||
1604 | acpi_bus_get_device(handle, &device); | ||
1605 | if (ops->acpi_op_add && !device) { | ||
1606 | acpi_add_single_object(&device, handle, type, sta, ops); | ||
1607 | /* Is the device a known good platform device? */ | ||
1608 | if (device | ||
1609 | && !acpi_match_device_ids(device, acpi_platform_device_ids)) | ||
1610 | acpi_create_platform_device(device); | ||
1611 | } | ||
1612 | |||
1613 | if (!device) | 1563 | if (!device) |
1614 | return AE_CTRL_DEPTH; | 1564 | return AE_CTRL_DEPTH; |
1615 | 1565 | ||
1616 | if (ops->acpi_op_start && !(ops->acpi_op_add)) { | 1566 | device->flags.match_driver = true; |
1617 | status = acpi_start_single_object(device); | ||
1618 | if (ACPI_FAILURE(status)) | ||
1619 | return AE_CTRL_DEPTH; | ||
1620 | } | ||
1621 | 1567 | ||
1568 | out: | ||
1622 | if (!*return_value) | 1569 | if (!*return_value) |
1623 | *return_value = device; | 1570 | *return_value = device; |
1571 | |||
1624 | return AE_OK; | 1572 | return AE_OK; |
1625 | } | 1573 | } |
1626 | 1574 | ||
1627 | static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops, | 1575 | static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used, |
1628 | struct acpi_device **child) | 1576 | void *not_used, void **ret_not_used) |
1629 | { | 1577 | { |
1630 | acpi_status status; | 1578 | acpi_status status = AE_OK; |
1631 | void *device = NULL; | 1579 | struct acpi_device *device; |
1580 | unsigned long long sta_not_used; | ||
1581 | int type_not_used; | ||
1632 | 1582 | ||
1633 | status = acpi_bus_check_add(handle, 0, ops, &device); | 1583 | /* |
1634 | if (ACPI_SUCCESS(status)) | 1584 | * Ignore errors ignored by acpi_bus_check_add() to avoid terminating |
1635 | acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, | 1585 | * namespace walks prematurely. |
1636 | acpi_bus_check_add, NULL, ops, &device); | 1586 | */ |
1587 | if (acpi_bus_type_and_status(handle, &type_not_used, &sta_not_used)) | ||
1588 | return AE_OK; | ||
1637 | 1589 | ||
1638 | if (child) | 1590 | if (acpi_bus_get_device(handle, &device)) |
1639 | *child = device; | 1591 | return AE_CTRL_DEPTH; |
1640 | 1592 | ||
1641 | if (device) | 1593 | if (!acpi_match_device_ids(device, acpi_platform_device_ids)) { |
1642 | return 0; | 1594 | /* This is a known good platform device. */ |
1643 | else | 1595 | acpi_create_platform_device(device); |
1644 | return -ENODEV; | 1596 | } else if (device_attach(&device->dev)) { |
1597 | status = AE_CTRL_DEPTH; | ||
1598 | } | ||
1599 | return status; | ||
1645 | } | 1600 | } |
1646 | 1601 | ||
1647 | /* | 1602 | static int acpi_bus_scan(acpi_handle handle) |
1648 | * acpi_bus_add and acpi_bus_start | ||
1649 | * | ||
1650 | * scan a given ACPI tree and (probably recently hot-plugged) | ||
1651 | * create and add or starts found devices. | ||
1652 | * | ||
1653 | * If no devices were found -ENODEV is returned which does not | ||
1654 | * mean that this is a real error, there just have been no suitable | ||
1655 | * ACPI objects in the table trunk from which the kernel could create | ||
1656 | * a device and add/start an appropriate driver. | ||
1657 | */ | ||
1658 | |||
1659 | int | ||
1660 | acpi_bus_add(struct acpi_device **child, | ||
1661 | struct acpi_device *parent, acpi_handle handle, int type) | ||
1662 | { | 1603 | { |
1663 | struct acpi_bus_ops ops; | 1604 | void *device = NULL; |
1664 | 1605 | ||
1665 | memset(&ops, 0, sizeof(ops)); | 1606 | if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device))) |
1666 | ops.acpi_op_add = 1; | 1607 | acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, |
1608 | acpi_bus_check_add, NULL, NULL, &device); | ||
1667 | 1609 | ||
1668 | return acpi_bus_scan(handle, &ops, child); | 1610 | if (!device) |
1669 | } | 1611 | return -ENODEV; |
1670 | EXPORT_SYMBOL(acpi_bus_add); | ||
1671 | 1612 | ||
1672 | int acpi_bus_start(struct acpi_device *device) | 1613 | if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL))) |
1673 | { | 1614 | acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, |
1674 | struct acpi_bus_ops ops; | 1615 | acpi_bus_device_attach, NULL, NULL, NULL); |
1675 | int result; | ||
1676 | 1616 | ||
1677 | if (!device) | 1617 | return 0; |
1678 | return -EINVAL; | 1618 | } |
1679 | 1619 | ||
1680 | memset(&ops, 0, sizeof(ops)); | 1620 | /** |
1681 | ops.acpi_op_start = 1; | 1621 | * acpi_bus_add - Add ACPI device node objects in a given namespace scope. |
1622 | * @handle: Root of the namespace scope to scan. | ||
1623 | * | ||
1624 | * Scan a given ACPI tree (probably recently hot-plugged) and create and add | ||
1625 | * found devices. | ||
1626 | * | ||
1627 | * If no devices were found, -ENODEV is returned, but it does not mean that | ||
1628 | * there has been a real error. There just have been no suitable ACPI objects | ||
1629 | * in the table trunk from which the kernel could create a device and add an | ||
1630 | * appropriate driver. | ||
1631 | */ | ||
1632 | int acpi_bus_add(acpi_handle handle) | ||
1633 | { | ||
1634 | int err; | ||
1682 | 1635 | ||
1683 | result = acpi_bus_scan(device->handle, &ops, NULL); | 1636 | err = acpi_bus_scan(handle); |
1637 | if (err) | ||
1638 | return err; | ||
1684 | 1639 | ||
1685 | acpi_update_all_gpes(); | 1640 | acpi_update_all_gpes(); |
1686 | 1641 | return 0; | |
1687 | return result; | ||
1688 | } | 1642 | } |
1689 | EXPORT_SYMBOL(acpi_bus_start); | 1643 | EXPORT_SYMBOL(acpi_bus_add); |
1690 | 1644 | ||
1691 | int acpi_bus_trim(struct acpi_device *start, int rmdevice) | 1645 | int acpi_bus_trim(struct acpi_device *start, int rmdevice) |
1692 | { | 1646 | { |
@@ -1747,11 +1701,6 @@ static int acpi_bus_scan_fixed(void) | |||
1747 | { | 1701 | { |
1748 | int result = 0; | 1702 | int result = 0; |
1749 | struct acpi_device *device = NULL; | 1703 | struct acpi_device *device = NULL; |
1750 | struct acpi_bus_ops ops; | ||
1751 | |||
1752 | memset(&ops, 0, sizeof(ops)); | ||
1753 | ops.acpi_op_add = 1; | ||
1754 | ops.acpi_op_start = 1; | ||
1755 | 1704 | ||
1756 | /* | 1705 | /* |
1757 | * Enumerate all fixed-feature devices. | 1706 | * Enumerate all fixed-feature devices. |
@@ -1759,16 +1708,14 @@ static int acpi_bus_scan_fixed(void) | |||
1759 | if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) { | 1708 | if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) { |
1760 | result = acpi_add_single_object(&device, NULL, | 1709 | result = acpi_add_single_object(&device, NULL, |
1761 | ACPI_BUS_TYPE_POWER_BUTTON, | 1710 | ACPI_BUS_TYPE_POWER_BUTTON, |
1762 | ACPI_STA_DEFAULT, | 1711 | ACPI_STA_DEFAULT, true); |
1763 | &ops); | ||
1764 | device_init_wakeup(&device->dev, true); | 1712 | device_init_wakeup(&device->dev, true); |
1765 | } | 1713 | } |
1766 | 1714 | ||
1767 | if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) { | 1715 | if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) { |
1768 | result = acpi_add_single_object(&device, NULL, | 1716 | result = acpi_add_single_object(&device, NULL, |
1769 | ACPI_BUS_TYPE_SLEEP_BUTTON, | 1717 | ACPI_BUS_TYPE_SLEEP_BUTTON, |
1770 | ACPI_STA_DEFAULT, | 1718 | ACPI_STA_DEFAULT, true); |
1771 | &ops); | ||
1772 | } | 1719 | } |
1773 | 1720 | ||
1774 | return result; | 1721 | return result; |
@@ -1777,11 +1724,6 @@ static int acpi_bus_scan_fixed(void) | |||
1777 | int __init acpi_scan_init(void) | 1724 | int __init acpi_scan_init(void) |
1778 | { | 1725 | { |
1779 | int result; | 1726 | int result; |
1780 | struct acpi_bus_ops ops; | ||
1781 | |||
1782 | memset(&ops, 0, sizeof(ops)); | ||
1783 | ops.acpi_op_add = 1; | ||
1784 | ops.acpi_op_start = 1; | ||
1785 | 1727 | ||
1786 | result = bus_register(&acpi_bus_type); | 1728 | result = bus_register(&acpi_bus_type); |
1787 | if (result) { | 1729 | if (result) { |
@@ -1790,12 +1732,16 @@ int __init acpi_scan_init(void) | |||
1790 | } | 1732 | } |
1791 | 1733 | ||
1792 | acpi_power_init(); | 1734 | acpi_power_init(); |
1735 | acpi_pci_root_init(); | ||
1793 | 1736 | ||
1794 | /* | 1737 | /* |
1795 | * Enumerate devices in the ACPI namespace. | 1738 | * Enumerate devices in the ACPI namespace. |
1796 | */ | 1739 | */ |
1797 | result = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root); | 1740 | result = acpi_bus_scan(ACPI_ROOT_OBJECT); |
1741 | if (result) | ||
1742 | return result; | ||
1798 | 1743 | ||
1744 | result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root); | ||
1799 | if (!result) | 1745 | if (!result) |
1800 | result = acpi_bus_scan_fixed(); | 1746 | result = acpi_bus_scan_fixed(); |
1801 | 1747 | ||