gov_user_space.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /**
  16. * notify_user_space - Notifies user space about thermal events
  17. * @tz: thermal_zone_device
  18. * @trip: trip point index
  19. *
  20. * This function notifies the user space through UEvents.
  21. */
  22. static int notify_user_space(struct thermal_zone_device *tz, int trip)
  23. {
  24. char *thermal_prop[5];
  25. int i;
  26. mutex_lock(&tz->lock);
  27. thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
  28. thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
  29. thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
  30. thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
  31. thermal_prop[4] = NULL;
  32. kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
  33. for (i = 0; i < 4; ++i)
  34. kfree(thermal_prop[i]);
  35. mutex_unlock(&tz->lock);
  36. return 0;
  37. }
  38. static struct thermal_governor thermal_gov_user_space = {
  39. .name = "user_space",
  40. .throttle = notify_user_space,
  41. };
  42. THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);