qnoc-qos-rpm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/interconnect.h>
  6. #include <linux/interconnect-provider.h>
  7. #include <linux/module.h>
  8. #include "icc-rpm.h"
  9. #include "qnoc-qos-rpm.h"
  10. #define QOSGEN_MAINCTL_LO(p, qp) ((p)->offsets[qp] + \
  11. (p)->regs[QOSGEN_OFF_MAINCTL_LO])
  12. #define QOS_SLV_URG_MSG_EN_SHFT 3
  13. #define QOS_DFLT_PRIO_MASK 0x7
  14. #define QOS_DFLT_PRIO_SHFT 4
  15. #define QOS_DISABLE_SHIFT 24
  16. #define QOSGEN_M_BKE_HEALTH(p, qp, n) ((p)->offsets[qp] + ((n) * 4) + \
  17. (p)->regs[QOSGEN_OFF_MPORT_BKE_HEALTH])
  18. #define QOS_PRIOLVL_MASK 0x7
  19. #define QOS_PRIOLVL_SHFT 0x0
  20. #define QOS_AREQPRIO_MASK 0x70
  21. #define QOS_AREQPRIO_SHFT 0x8
  22. #define QOSGEN_M_BKE_EN(p, qp) ((p)->offsets[qp] + \
  23. (p)->regs[QOSGEN_OFF_MPORT_BKE_EN])
  24. #define QOS_BKE_EN_MASK 0x1
  25. #define QOS_BKE_EN_SHFT 0x0
  26. #define NUM_BKE_HEALTH_LEVELS 4
  27. const u8 icc_qnoc_qos_regs[][QOSGEN_OFF_MAX_REGS] = {
  28. [ICC_QNOC_QOSGEN_TYPE_RPMH] = {
  29. [QOSGEN_OFF_MAINCTL_LO] = 0x8,
  30. [QOSGEN_OFF_LIMITBW_LO] = 0x18,
  31. [QOSGEN_OFF_SHAPING_LO] = 0x20,
  32. [QOSGEN_OFF_SHAPING_HI] = 0x24,
  33. [QOSGEN_OFF_REGUL0CTL_LO] = 0x40,
  34. [QOSGEN_OFF_REGUL0BW_LO] = 0x48,
  35. },
  36. };
  37. EXPORT_SYMBOL(icc_qnoc_qos_regs);
  38. const u8 icc_bimc_qos_regs[][QOSGEN_OFF_MAX_REGS] = {
  39. [ICC_QNOC_QOSGEN_TYPE_RPMH] = {
  40. [QOSGEN_OFF_MPORT_BKE_EN] = 0x0,
  41. [QOSGEN_OFF_MPORT_BKE_HEALTH] = 0x40,
  42. },
  43. };
  44. EXPORT_SYMBOL(icc_bimc_qos_regs);
  45. /**
  46. * qcom_icc_set_qos - initialize static QoS configurations
  47. * @node: qcom icc node to operate on
  48. */
  49. static void qcom_icc_set_qos(struct qcom_icc_node *node)
  50. {
  51. struct qcom_icc_qosbox *qos = node->qosbox;
  52. int port;
  53. if (!node->regmap)
  54. return;
  55. if (!qos)
  56. return;
  57. for (port = 0; port < qos->num_ports; port++) {
  58. regmap_update_bits(node->regmap, QOSGEN_MAINCTL_LO(qos, port),
  59. BIT(QOS_DISABLE_SHIFT),
  60. qos->config->prio_fwd_disable << QOS_DISABLE_SHIFT);
  61. regmap_update_bits(node->regmap, QOSGEN_MAINCTL_LO(qos, port),
  62. QOS_DFLT_PRIO_MASK << QOS_DFLT_PRIO_SHFT,
  63. qos->config->prio << QOS_DFLT_PRIO_SHFT);
  64. regmap_update_bits(node->regmap, QOSGEN_MAINCTL_LO(qos, port),
  65. BIT(QOS_SLV_URG_MSG_EN_SHFT),
  66. qos->config->urg_fwd << QOS_SLV_URG_MSG_EN_SHFT);
  67. }
  68. }
  69. const struct qcom_icc_noc_ops qcom_qnoc4_ops = {
  70. .set_qos = qcom_icc_set_qos,
  71. };
  72. EXPORT_SYMBOL(qcom_qnoc4_ops);
  73. /**
  74. * qcom_icc_set_bimc_qos - initialize static QoS configurations
  75. * @node: qcom icc node to operate on
  76. */
  77. static void qcom_icc_set_bimc_qos(struct qcom_icc_node *node)
  78. {
  79. struct qcom_icc_qosbox *qos = node->qosbox;
  80. int port, i;
  81. if (!node->regmap)
  82. return;
  83. if (!qos)
  84. return;
  85. for (port = 0; port < qos->num_ports; port++) {
  86. for (i = 0; i < NUM_BKE_HEALTH_LEVELS; i++) {
  87. regmap_update_bits(node->regmap,
  88. QOSGEN_M_BKE_HEALTH(qos, port, i),
  89. ((qos->config->prio << QOS_PRIOLVL_SHFT) |
  90. (qos->config->prio << QOS_AREQPRIO_SHFT)),
  91. (QOS_PRIOLVL_MASK | QOS_AREQPRIO_MASK));
  92. }
  93. regmap_update_bits(node->regmap,
  94. QOSGEN_M_BKE_EN(qos, port),
  95. qos->config->bke_enable << QOS_BKE_EN_SHFT,
  96. QOS_BKE_EN_MASK);
  97. }
  98. }
  99. const struct qcom_icc_noc_ops qcom_bimc_ops = {
  100. .set_qos = qcom_icc_set_bimc_qos,
  101. };
  102. EXPORT_SYMBOL(qcom_bimc_ops);
  103. MODULE_LICENSE("GPL");