sde_hw_blk.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2019, 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  6. #include <linux/mutex.h>
  7. #include <linux/errno.h>
  8. #include <linux/slab.h>
  9. #include "sde_hw_mdss.h"
  10. #include "sde_hw_blk.h"
  11. /* Serialization lock for sde_hw_blk_list */
  12. static DEFINE_MUTEX(sde_hw_blk_lock);
  13. /* List of all hw block objects */
  14. static LIST_HEAD(sde_hw_blk_list);
  15. /**
  16. * sde_hw_blk_init - initialize hw block object
  17. * @type: hw block type - enum sde_hw_blk_type
  18. * @id: instance id of the hw block
  19. * @ops: Pointer to block operations
  20. * return: 0 if success; error code otherwise
  21. */
  22. int sde_hw_blk_init(struct sde_hw_blk *hw_blk, u32 type, int id,
  23. struct sde_hw_blk_ops *ops)
  24. {
  25. if (!hw_blk) {
  26. pr_err("invalid parameters\n");
  27. return -EINVAL;
  28. }
  29. INIT_LIST_HEAD(&hw_blk->list);
  30. hw_blk->type = type;
  31. hw_blk->id = id;
  32. atomic_set(&hw_blk->refcount, 0);
  33. if (ops)
  34. hw_blk->ops = *ops;
  35. mutex_lock(&sde_hw_blk_lock);
  36. list_add(&hw_blk->list, &sde_hw_blk_list);
  37. mutex_unlock(&sde_hw_blk_lock);
  38. return 0;
  39. }
  40. /**
  41. * sde_hw_blk_destroy - destroy hw block object.
  42. * @hw_blk: pointer to hw block object
  43. * return: none
  44. */
  45. void sde_hw_blk_destroy(struct sde_hw_blk *hw_blk)
  46. {
  47. if (!hw_blk) {
  48. pr_err("invalid parameters\n");
  49. return;
  50. }
  51. if (atomic_read(&hw_blk->refcount))
  52. pr_err("hw_blk:%d.%d invalid refcount\n", hw_blk->type,
  53. hw_blk->id);
  54. mutex_lock(&sde_hw_blk_lock);
  55. list_del(&hw_blk->list);
  56. mutex_unlock(&sde_hw_blk_lock);
  57. }