aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-07-17 16:54:01 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-07-17 16:54:01 -0400
commit5894b0c46e49b5ecc25f22b2d1b8232aab00ce97 (patch)
tree2e8d6c046f20a7eefb3694fbaf81717a2d36e92e
parent68c6b148daa6e45a85b31ef60ed9c9bfd556fff0 (diff)
ACPI / scan: Move bus operations and notification routines to bus.c
To reduce the size of scan.c and improve the readability of it, move code related to device notification, the definitions of the ACPI bus operations and the driver management code to drivers/acpi/bus.c. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/bus.c184
-rw-r--r--drivers/acpi/scan.c183
2 files changed, 184 insertions, 183 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index ce805809b00b..2f50fc4be1d4 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -423,6 +423,65 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
423 acpi_evaluate_ost(handle, type, ost_code, NULL); 423 acpi_evaluate_ost(handle, type, ost_code, NULL);
424} 424}
425 425
426static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
427{
428 struct acpi_device *device = data;
429
430 device->driver->ops.notify(device, event);
431}
432
433static void acpi_device_notify_fixed(void *data)
434{
435 struct acpi_device *device = data;
436
437 /* Fixed hardware devices have no handles */
438 acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
439}
440
441static u32 acpi_device_fixed_event(void *data)
442{
443 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_device_notify_fixed, data);
444 return ACPI_INTERRUPT_HANDLED;
445}
446
447static int acpi_device_install_notify_handler(struct acpi_device *device)
448{
449 acpi_status status;
450
451 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
452 status =
453 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
454 acpi_device_fixed_event,
455 device);
456 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
457 status =
458 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
459 acpi_device_fixed_event,
460 device);
461 else
462 status = acpi_install_notify_handler(device->handle,
463 ACPI_DEVICE_NOTIFY,
464 acpi_device_notify,
465 device);
466
467 if (ACPI_FAILURE(status))
468 return -EINVAL;
469 return 0;
470}
471
472static void acpi_device_remove_notify_handler(struct acpi_device *device)
473{
474 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
475 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
476 acpi_device_fixed_event);
477 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
478 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
479 acpi_device_fixed_event);
480 else
481 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
482 acpi_device_notify);
483}
484
426/* -------------------------------------------------------------------------- 485/* --------------------------------------------------------------------------
427 Device Matching 486 Device Matching
428 -------------------------------------------------------------------------- */ 487 -------------------------------------------------------------------------- */
@@ -618,6 +677,131 @@ bool acpi_driver_match_device(struct device *dev,
618EXPORT_SYMBOL_GPL(acpi_driver_match_device); 677EXPORT_SYMBOL_GPL(acpi_driver_match_device);
619 678
620/* -------------------------------------------------------------------------- 679/* --------------------------------------------------------------------------
680 ACPI Driver Management
681 -------------------------------------------------------------------------- */
682
683/**
684 * acpi_bus_register_driver - register a driver with the ACPI bus
685 * @driver: driver being registered
686 *
687 * Registers a driver with the ACPI bus. Searches the namespace for all
688 * devices that match the driver's criteria and binds. Returns zero for
689 * success or a negative error status for failure.
690 */
691int acpi_bus_register_driver(struct acpi_driver *driver)
692{
693 int ret;
694
695 if (acpi_disabled)
696 return -ENODEV;
697 driver->drv.name = driver->name;
698 driver->drv.bus = &acpi_bus_type;
699 driver->drv.owner = driver->owner;
700
701 ret = driver_register(&driver->drv);
702 return ret;
703}
704
705EXPORT_SYMBOL(acpi_bus_register_driver);
706
707/**
708 * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
709 * @driver: driver to unregister
710 *
711 * Unregisters a driver with the ACPI bus. Searches the namespace for all
712 * devices that match the driver's criteria and unbinds.
713 */
714void acpi_bus_unregister_driver(struct acpi_driver *driver)
715{
716 driver_unregister(&driver->drv);
717}
718
719EXPORT_SYMBOL(acpi_bus_unregister_driver);
720
721/* --------------------------------------------------------------------------
722 ACPI Bus operations
723 -------------------------------------------------------------------------- */
724
725static int acpi_bus_match(struct device *dev, struct device_driver *drv)
726{
727 struct acpi_device *acpi_dev = to_acpi_device(dev);
728 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
729
730 return acpi_dev->flags.match_driver
731 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
732}
733
734static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
735{
736 return __acpi_device_uevent_modalias(to_acpi_device(dev), env);
737}
738
739static int acpi_device_probe(struct device *dev)
740{
741 struct acpi_device *acpi_dev = to_acpi_device(dev);
742 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
743 int ret;
744
745 if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev))
746 return -EINVAL;
747
748 if (!acpi_drv->ops.add)
749 return -ENOSYS;
750
751 ret = acpi_drv->ops.add(acpi_dev);
752 if (ret)
753 return ret;
754
755 acpi_dev->driver = acpi_drv;
756 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
757 "Driver [%s] successfully bound to device [%s]\n",
758 acpi_drv->name, acpi_dev->pnp.bus_id));
759
760 if (acpi_drv->ops.notify) {
761 ret = acpi_device_install_notify_handler(acpi_dev);
762 if (ret) {
763 if (acpi_drv->ops.remove)
764 acpi_drv->ops.remove(acpi_dev);
765
766 acpi_dev->driver = NULL;
767 acpi_dev->driver_data = NULL;
768 return ret;
769 }
770 }
771
772 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
773 acpi_drv->name, acpi_dev->pnp.bus_id));
774 get_device(dev);
775 return 0;
776}
777
778static int acpi_device_remove(struct device * dev)
779{
780 struct acpi_device *acpi_dev = to_acpi_device(dev);
781 struct acpi_driver *acpi_drv = acpi_dev->driver;
782
783 if (acpi_drv) {
784 if (acpi_drv->ops.notify)
785 acpi_device_remove_notify_handler(acpi_dev);
786 if (acpi_drv->ops.remove)
787 acpi_drv->ops.remove(acpi_dev);
788 }
789 acpi_dev->driver = NULL;
790 acpi_dev->driver_data = NULL;
791
792 put_device(dev);
793 return 0;
794}
795
796struct bus_type acpi_bus_type = {
797 .name = "acpi",
798 .match = acpi_bus_match,
799 .probe = acpi_device_probe,
800 .remove = acpi_device_remove,
801 .uevent = acpi_device_uevent,
802};
803
804/* --------------------------------------------------------------------------
621 Initialization/Cleanup 805 Initialization/Cleanup
622 -------------------------------------------------------------------------- */ 806 -------------------------------------------------------------------------- */
623 807
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 68877bc22357..f541f689ae80 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -444,10 +444,6 @@ void acpi_device_hotplug(struct acpi_device *adev, u32 src)
444 unlock_device_hotplug(); 444 unlock_device_hotplug();
445} 445}
446 446
447/* --------------------------------------------------------------------------
448 ACPI Bus operations
449 -------------------------------------------------------------------------- */
450
451static void acpi_free_power_resources_lists(struct acpi_device *device) 447static void acpi_free_power_resources_lists(struct acpi_device *device)
452{ 448{
453 int i; 449 int i;
@@ -474,144 +470,6 @@ static void acpi_device_release(struct device *dev)
474 kfree(acpi_dev); 470 kfree(acpi_dev);
475} 471}
476 472
477static int acpi_bus_match(struct device *dev, struct device_driver *drv)
478{
479 struct acpi_device *acpi_dev = to_acpi_device(dev);
480 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
481
482 return acpi_dev->flags.match_driver
483 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
484}
485
486static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
487{
488 return __acpi_device_uevent_modalias(to_acpi_device(dev), env);
489}
490
491static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
492{
493 struct acpi_device *device = data;
494
495 device->driver->ops.notify(device, event);
496}
497
498static void acpi_device_notify_fixed(void *data)
499{
500 struct acpi_device *device = data;
501
502 /* Fixed hardware devices have no handles */
503 acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
504}
505
506static u32 acpi_device_fixed_event(void *data)
507{
508 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_device_notify_fixed, data);
509 return ACPI_INTERRUPT_HANDLED;
510}
511
512static int acpi_device_install_notify_handler(struct acpi_device *device)
513{
514 acpi_status status;
515
516 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
517 status =
518 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
519 acpi_device_fixed_event,
520 device);
521 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
522 status =
523 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
524 acpi_device_fixed_event,
525 device);
526 else
527 status = acpi_install_notify_handler(device->handle,
528 ACPI_DEVICE_NOTIFY,
529 acpi_device_notify,
530 device);
531
532 if (ACPI_FAILURE(status))
533 return -EINVAL;
534 return 0;
535}
536
537static void acpi_device_remove_notify_handler(struct acpi_device *device)
538{
539 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
540 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
541 acpi_device_fixed_event);
542 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
543 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
544 acpi_device_fixed_event);
545 else
546 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
547 acpi_device_notify);
548}
549
550static int acpi_device_probe(struct device *dev)
551{
552 struct acpi_device *acpi_dev = to_acpi_device(dev);
553 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
554 int ret;
555
556 if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev))
557 return -EINVAL;
558
559 if (!acpi_drv->ops.add)
560 return -ENOSYS;
561
562 ret = acpi_drv->ops.add(acpi_dev);
563 if (ret)
564 return ret;
565
566 acpi_dev->driver = acpi_drv;
567 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
568 "Driver [%s] successfully bound to device [%s]\n",
569 acpi_drv->name, acpi_dev->pnp.bus_id));
570
571 if (acpi_drv->ops.notify) {
572 ret = acpi_device_install_notify_handler(acpi_dev);
573 if (ret) {
574 if (acpi_drv->ops.remove)
575 acpi_drv->ops.remove(acpi_dev);
576
577 acpi_dev->driver = NULL;
578 acpi_dev->driver_data = NULL;
579 return ret;
580 }
581 }
582
583 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
584 acpi_drv->name, acpi_dev->pnp.bus_id));
585 get_device(dev);
586 return 0;
587}
588
589static int acpi_device_remove(struct device * dev)
590{
591 struct acpi_device *acpi_dev = to_acpi_device(dev);
592 struct acpi_driver *acpi_drv = acpi_dev->driver;
593
594 if (acpi_drv) {
595 if (acpi_drv->ops.notify)
596 acpi_device_remove_notify_handler(acpi_dev);
597 if (acpi_drv->ops.remove)
598 acpi_drv->ops.remove(acpi_dev);
599 }
600 acpi_dev->driver = NULL;
601 acpi_dev->driver_data = NULL;
602
603 put_device(dev);
604 return 0;
605}
606
607struct bus_type acpi_bus_type = {
608 .name = "acpi",
609 .match = acpi_bus_match,
610 .probe = acpi_device_probe,
611 .remove = acpi_device_remove,
612 .uevent = acpi_device_uevent,
613};
614
615static void acpi_device_del(struct acpi_device *device) 473static void acpi_device_del(struct acpi_device *device)
616{ 474{
617 mutex_lock(&acpi_device_lock); 475 mutex_lock(&acpi_device_lock);
@@ -859,47 +717,6 @@ struct acpi_device *acpi_get_next_child(struct device *dev,
859} 717}
860 718
861/* -------------------------------------------------------------------------- 719/* --------------------------------------------------------------------------
862 Driver Management
863 -------------------------------------------------------------------------- */
864/**
865 * acpi_bus_register_driver - register a driver with the ACPI bus
866 * @driver: driver being registered
867 *
868 * Registers a driver with the ACPI bus. Searches the namespace for all
869 * devices that match the driver's criteria and binds. Returns zero for
870 * success or a negative error status for failure.
871 */
872int acpi_bus_register_driver(struct acpi_driver *driver)
873{
874 int ret;
875
876 if (acpi_disabled)
877 return -ENODEV;
878 driver->drv.name = driver->name;
879 driver->drv.bus = &acpi_bus_type;
880 driver->drv.owner = driver->owner;
881
882 ret = driver_register(&driver->drv);
883 return ret;
884}
885
886EXPORT_SYMBOL(acpi_bus_register_driver);
887
888/**
889 * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
890 * @driver: driver to unregister
891 *
892 * Unregisters a driver with the ACPI bus. Searches the namespace for all
893 * devices that match the driver's criteria and unbinds.
894 */
895void acpi_bus_unregister_driver(struct acpi_driver *driver)
896{
897 driver_unregister(&driver->drv);
898}
899
900EXPORT_SYMBOL(acpi_bus_unregister_driver);
901
902/* --------------------------------------------------------------------------
903 Device Enumeration 720 Device Enumeration
904 -------------------------------------------------------------------------- */ 721 -------------------------------------------------------------------------- */
905static struct acpi_device *acpi_bus_get_parent(acpi_handle handle) 722static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)