eventmgr.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include <linux/types.h>
  24. #include <linux/kernel.h>
  25. #include <linux/slab.h>
  26. #include "eventmgr.h"
  27. #include "hwmgr.h"
  28. #include "eventinit.h"
  29. #include "eventmanagement.h"
  30. static int pem_init(struct pp_eventmgr *eventmgr)
  31. {
  32. int result = 0;
  33. struct pem_event_data event_data = { {0} };
  34. /* Initialize PowerPlay feature info */
  35. pem_init_feature_info(eventmgr);
  36. /* Initialize event action chains */
  37. pem_init_event_action_chains(eventmgr);
  38. /* Call initialization event */
  39. result = pem_handle_event(eventmgr, AMD_PP_EVENT_INITIALIZE, &event_data);
  40. /* if (0 != result)
  41. return result; */
  42. /* Register interrupt callback functions */
  43. result = pem_register_interrupts(eventmgr);
  44. return 0;
  45. }
  46. static void pem_fini(struct pp_eventmgr *eventmgr)
  47. {
  48. struct pem_event_data event_data = { {0} };
  49. pem_uninit_featureInfo(eventmgr);
  50. pem_unregister_interrupts(eventmgr);
  51. pem_handle_event(eventmgr, AMD_PP_EVENT_UNINITIALIZE, &event_data);
  52. }
  53. int eventmgr_early_init(struct pp_instance *handle)
  54. {
  55. struct pp_eventmgr *eventmgr;
  56. if (handle == NULL)
  57. return -EINVAL;
  58. eventmgr = kzalloc(sizeof(struct pp_eventmgr), GFP_KERNEL);
  59. if (eventmgr == NULL)
  60. return -ENOMEM;
  61. eventmgr->hwmgr = handle->hwmgr;
  62. handle->eventmgr = eventmgr;
  63. eventmgr->platform_descriptor = &(eventmgr->hwmgr->platform_descriptor);
  64. eventmgr->pp_eventmgr_init = pem_init;
  65. eventmgr->pp_eventmgr_fini = pem_fini;
  66. return 0;
  67. }
  68. static int pem_handle_event_unlocked(struct pp_eventmgr *eventmgr, enum amd_pp_event event, struct pem_event_data *data)
  69. {
  70. if (eventmgr == NULL || event >= AMD_PP_EVENT_MAX || data == NULL)
  71. return -EINVAL;
  72. return pem_excute_event_chain(eventmgr, eventmgr->event_chain[event], data);
  73. }
  74. int pem_handle_event(struct pp_eventmgr *eventmgr, enum amd_pp_event event, struct pem_event_data *event_data)
  75. {
  76. int r = 0;
  77. r = pem_handle_event_unlocked(eventmgr, event, event_data);
  78. return r;
  79. }
  80. bool pem_is_hw_access_blocked(struct pp_eventmgr *eventmgr)
  81. {
  82. return (eventmgr->block_adjust_power_state || phm_is_hw_access_blocked(eventmgr->hwmgr));
  83. }