gov_user_space.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * user_space.c - A simple user space Thermal events notifier
  4. *
  5. * Copyright (C) 2012 Intel Corp
  6. * Copyright (C) 2012 Durgadoss R <durgadoss.r@intel.com>
  7. *
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/thermal.h>
  14. #include "thermal_core.h"
  15. static int user_space_bind(struct thermal_zone_device *tz)
  16. {
  17. pr_info_once("Consider using thermal netlink events interface\n");
  18. return 0;
  19. }
  20. /**
  21. * notify_user_space - Notifies user space about thermal events
  22. * @tz: thermal_zone_device
  23. * @trip: trip point
  24. * @crossed_up: whether or not the trip has been crossed on the way up
  25. *
  26. * This function notifies the user space through UEvents.
  27. */
  28. static void notify_user_space(struct thermal_zone_device *tz,
  29. const struct thermal_trip *trip,
  30. bool crossed_up)
  31. {
  32. char *thermal_prop[5];
  33. int i;
  34. lockdep_assert_held(&tz->lock);
  35. thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
  36. thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
  37. thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d",
  38. thermal_zone_trip_id(tz, trip));
  39. thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
  40. thermal_prop[4] = NULL;
  41. kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
  42. for (i = 0; i < 4; ++i)
  43. kfree(thermal_prop[i]);
  44. }
  45. static struct thermal_governor thermal_gov_user_space = {
  46. .name = "user_space",
  47. .trip_crossed = notify_user_space,
  48. .bind_to_tz = user_space_bind,
  49. };
  50. THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);