gov_user_space.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <[email protected]>
  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 index
  24. *
  25. * This function notifies the user space through UEvents.
  26. */
  27. static int notify_user_space(struct thermal_zone_device *tz, int trip)
  28. {
  29. char *thermal_prop[5];
  30. int i;
  31. lockdep_assert_held(&tz->lock);
  32. thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
  33. thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
  34. thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
  35. thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
  36. thermal_prop[4] = NULL;
  37. kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
  38. for (i = 0; i < 4; ++i)
  39. kfree(thermal_prop[i]);
  40. return 0;
  41. }
  42. static struct thermal_governor thermal_gov_user_space = {
  43. .name = "user_space",
  44. .throttle = notify_user_space,
  45. .bind_to_tz = user_space_bind,
  46. };
  47. THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);