On 4/9/23 18:47, Jonathan Cameron wrote:
As an encoded version of these key configuration parameters is
a register, provide functions to extract it again so as to avoid
the need for duplicating the storage.

Signed-off-by: Jonathan Cameron <jonathan.came...@huawei.com>
---
  include/hw/cxl/cxl_component.h | 14 ++++++++++++++
  hw/cxl/cxl-component-utils.c   | 17 +++++++++++++++++
  2 files changed, 31 insertions(+)

diff --git a/include/hw/cxl/cxl_component.h b/include/hw/cxl/cxl_component.h
index 42c7e581a7..f0ad9cf7de 100644
--- a/include/hw/cxl/cxl_component.h
+++ b/include/hw/cxl/cxl_component.h
@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)
      return 0;
  }
+static inline int cxl_decoder_count_dec(int enc_cnt)
+{
+    switch (enc_cnt) {
+    case 0: return 1;
+    case 1: return 2;
+    case 2: return 4;
+    case 3: return 6;
+    case 4: return 8;
+    case 5: return 10;
+    }
+    return 0;
+}

Why inline?

Alternatively:

  unsigned cxl_decoder_count_dec(unsigned enc_cnt)
  {
      return enc_cnt <= 5 ? 2 * enc_cnt : 0;
  }


Reply via email to