]> Git Repo - linux.git/commitdiff
regmap: Merge up fixes from mainline
authorMark Brown <[email protected]>
Sun, 23 Jul 2023 22:34:06 +0000 (23:34 +0100)
committerMark Brown <[email protected]>
Sun, 23 Jul 2023 22:34:06 +0000 (23:34 +0100)
There's several things here that will really help my CI.

1  2 
drivers/base/regmap/regcache-rbtree.c
drivers/base/regmap/regcache.c
drivers/base/regmap/regmap-kunit.c
drivers/base/regmap/regmap.c

index ae6b8788d5f3ff18b0b2257f166fa583a2a2b598,584bcc55f56e36f3e81b63558e3d0172d2fb4b5c..06788965aa2939a273e99f4a12747926452b510c
@@@ -277,7 -277,7 +277,7 @@@ static int regcache_rbtree_insert_to_bl
  
        blk = krealloc(rbnode->block,
                       blklen * map->cache_word_size,
 -                     GFP_KERNEL);
 +                     map->alloc_flags);
        if (!blk)
                return -ENOMEM;
  
        if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
                present = krealloc(rbnode->cache_present,
                                   BITS_TO_LONGS(blklen) * sizeof(*present),
 -                                 GFP_KERNEL);
 +                                 map->alloc_flags);
                if (!present)
                        return -ENOMEM;
  
@@@ -320,7 -320,7 +320,7 @@@ regcache_rbtree_node_alloc(struct regma
        const struct regmap_range *range;
        int i;
  
 -      rbnode = kzalloc(sizeof(*rbnode), GFP_KERNEL);
 +      rbnode = kzalloc(sizeof(*rbnode), map->alloc_flags);
        if (!rbnode)
                return NULL;
  
        }
  
        rbnode->block = kmalloc_array(rbnode->blklen, map->cache_word_size,
 -                                    GFP_KERNEL);
 +                                    map->alloc_flags);
        if (!rbnode->block)
                goto err_free;
  
        rbnode->cache_present = kcalloc(BITS_TO_LONGS(rbnode->blklen),
                                        sizeof(*rbnode->cache_present),
 -                                      GFP_KERNEL);
 +                                      map->alloc_flags);
        if (!rbnode->cache_present)
                goto err_free_block;
  
@@@ -471,6 -471,8 +471,8 @@@ static int regcache_rbtree_sync(struct 
        unsigned int start, end;
        int ret;
  
+       map->async = true;
        rbtree_ctx = map->cache;
        for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
                rbnode = rb_entry(node, struct regcache_rbtree_node, node);
                        return ret;
        }
  
+       map->async = false;
        return regmap_async_complete(map);
  }
  
index 8accf6292fe1258af0a0d8514bdc5fa6dc382aa7,7d3e47436056e57780beaa3ddf792a014833f606..c5d151e9c4815909f2e5ddf82c8a543bcefd197e
@@@ -368,8 -368,6 +368,6 @@@ int regcache_sync(struct regmap *map
        if (!map->cache_dirty)
                goto out;
  
-       map->async = true;
        /* Apply any patch first */
        map->cache_bypass = true;
        for (i = 0; i < map->patch_regs; i++) {
  
  out:
        /* Restore the bypass state */
-       map->async = false;
        map->cache_bypass = bypass;
        map->no_sync_defaults = false;
        map->unlock(map->lock_arg);
@@@ -561,29 -558,6 +558,29 @@@ void regcache_cache_bypass(struct regma
  }
  EXPORT_SYMBOL_GPL(regcache_cache_bypass);
  
 +/**
 + * regcache_reg_cached - Check if a register is cached
 + *
 + * @map: map to check
 + * @reg: register to check
 + *
 + * Reports if a register is cached.
 + */
 +bool regcache_reg_cached(struct regmap *map, unsigned int reg)
 +{
 +      unsigned int val;
 +      int ret;
 +
 +      map->lock(map->lock_arg);
 +
 +      ret = regcache_read(map, reg, &val);
 +
 +      map->unlock(map->lock_arg);
 +
 +      return ret == 0;
 +}
 +EXPORT_SYMBOL_GPL(regcache_reg_cached);
 +
  void regcache_set_val(struct regmap *map, void *base, unsigned int idx,
                      unsigned int val)
  {
                cache[idx] = val;
                break;
        }
 -#ifdef CONFIG_64BIT
 -      case 8: {
 -              u64 *cache = base;
 -
 -              cache[idx] = val;
 -              break;
 -      }
 -#endif
        default:
                BUG();
        }
@@@ -645,6 -627,13 +642,6 @@@ unsigned int regcache_get_val(struct re
  
                return cache[idx];
        }
 -#ifdef CONFIG_64BIT
 -      case 8: {
 -              const u64 *cache = base;
 -
 -              return cache[idx];
 -      }
 -#endif
        default:
                BUG();
        }
index 8dd96a55d976c1c57598571179eeb603032e35b5,9ff3018a46aac8922285c9d8611178e459241ddb..264d29b3fced0b7e389c31b6e7da7681daefeb35
@@@ -58,6 -58,9 +58,9 @@@ static struct regmap *gen_regmap(struc
        int i;
        struct reg_default *defaults;
  
+       config->disable_locking = config->cache_type == REGCACHE_RBTREE ||
+                                       config->cache_type == REGCACHE_MAPLE;
        buf = kmalloc(size, GFP_KERNEL);
        if (!buf)
                return ERR_PTR(-ENOMEM);
@@@ -833,45 -836,6 +836,45 @@@ static void cache_drop(struct kunit *te
        regmap_exit(map);
  }
  
 +static void cache_present(struct kunit *test)
 +{
 +      struct regcache_types *t = (struct regcache_types *)test->param_value;
 +      struct regmap *map;
 +      struct regmap_config config;
 +      struct regmap_ram_data *data;
 +      unsigned int val;
 +      int i;
 +
 +      config = test_regmap_config;
 +      config.cache_type = t->type;
 +
 +      map = gen_regmap(&config, &data);
 +      KUNIT_ASSERT_FALSE(test, IS_ERR(map));
 +      if (IS_ERR(map))
 +              return;
 +
 +      for (i = 0; i < BLOCK_TEST_SIZE; i++)
 +              data->read[i] = false;
 +
 +      /* No defaults so no registers cached. */
 +      for (i = 0; i < BLOCK_TEST_SIZE; i++)
 +              KUNIT_ASSERT_FALSE(test, regcache_reg_cached(map, i));
 +
 +      /* We didn't trigger any reads */
 +      for (i = 0; i < BLOCK_TEST_SIZE; i++)
 +              KUNIT_ASSERT_FALSE(test, data->read[i]);
 +
 +      /* Fill the cache */
 +      for (i = 0; i < BLOCK_TEST_SIZE; i++)
 +              KUNIT_EXPECT_EQ(test, 0, regmap_read(map, i, &val));
 +
 +      /* Now everything should be cached */
 +      for (i = 0; i < BLOCK_TEST_SIZE; i++)
 +              KUNIT_ASSERT_TRUE(test, regcache_reg_cached(map, i));
 +
 +      regmap_exit(map);
 +}
 +
  struct raw_test_types {
        const char *name;
  
@@@ -928,6 -892,8 +931,8 @@@ static struct regmap *gen_raw_regmap(st
  
        config->cache_type = test_type->cache_type;
        config->val_format_endian = test_type->val_endian;
+       config->disable_locking = config->cache_type == REGCACHE_RBTREE ||
+                                       config->cache_type == REGCACHE_MAPLE;
  
        buf = kmalloc(size, GFP_KERNEL);
        if (!buf)
@@@ -1211,7 -1177,6 +1216,7 @@@ static struct kunit_case regmap_test_ca
        KUNIT_CASE_PARAM(cache_sync_readonly, real_cache_types_gen_params),
        KUNIT_CASE_PARAM(cache_sync_patch, real_cache_types_gen_params),
        KUNIT_CASE_PARAM(cache_drop, sparse_cache_types_gen_params),
 +      KUNIT_CASE_PARAM(cache_present, sparse_cache_types_gen_params),
  
        KUNIT_CASE_PARAM(raw_read_defaults_single, raw_test_types_gen_params),
        KUNIT_CASE_PARAM(raw_read_defaults, raw_test_types_gen_params),
index 8b37451fa9315fd3a8d42805745c6234382de035,1bfd1727b4da7d9cf8b0ff1c0a44dc67e5cf0389..884cb51c8f67291fc25724c05ec03aa6f56f02ac
@@@ -311,6 -311,26 +311,6 @@@ static void regmap_format_32_native(voi
        memcpy(buf, &v, sizeof(v));
  }
  
 -#ifdef CONFIG_64BIT
 -static void regmap_format_64_be(void *buf, unsigned int val, unsigned int shift)
 -{
 -      put_unaligned_be64((u64) val << shift, buf);
 -}
 -
 -static void regmap_format_64_le(void *buf, unsigned int val, unsigned int shift)
 -{
 -      put_unaligned_le64((u64) val << shift, buf);
 -}
 -
 -static void regmap_format_64_native(void *buf, unsigned int val,
 -                                  unsigned int shift)
 -{
 -      u64 v = (u64) val << shift;
 -
 -      memcpy(buf, &v, sizeof(v));
 -}
 -#endif
 -
  static void regmap_parse_inplace_noop(void *buf)
  {
  }
@@@ -391,6 -411,40 +391,6 @@@ static unsigned int regmap_parse_32_nat
        return v;
  }
  
 -#ifdef CONFIG_64BIT
 -static unsigned int regmap_parse_64_be(const void *buf)
 -{
 -      return get_unaligned_be64(buf);
 -}
 -
 -static unsigned int regmap_parse_64_le(const void *buf)
 -{
 -      return get_unaligned_le64(buf);
 -}
 -
 -static void regmap_parse_64_be_inplace(void *buf)
 -{
 -      u64 v =  get_unaligned_be64(buf);
 -
 -      memcpy(buf, &v, sizeof(v));
 -}
 -
 -static void regmap_parse_64_le_inplace(void *buf)
 -{
 -      u64 v = get_unaligned_le64(buf);
 -
 -      memcpy(buf, &v, sizeof(v));
 -}
 -
 -static unsigned int regmap_parse_64_native(const void *buf)
 -{
 -      u64 v;
 -
 -      memcpy(&v, buf, sizeof(v));
 -      return v;
 -}
 -#endif
 -
  static void regmap_lock_hwlock(void *__map)
  {
        struct regmap *map = __map;
@@@ -951,6 -1005,24 +951,6 @@@ struct regmap *__regmap_init(struct dev
                }
                break;
  
 -#ifdef CONFIG_64BIT
 -      case 64:
 -              switch (reg_endian) {
 -              case REGMAP_ENDIAN_BIG:
 -                      map->format.format_reg = regmap_format_64_be;
 -                      break;
 -              case REGMAP_ENDIAN_LITTLE:
 -                      map->format.format_reg = regmap_format_64_le;
 -                      break;
 -              case REGMAP_ENDIAN_NATIVE:
 -                      map->format.format_reg = regmap_format_64_native;
 -                      break;
 -              default:
 -                      goto err_hwlock;
 -              }
 -              break;
 -#endif
 -
        default:
                goto err_hwlock;
        }
                        goto err_hwlock;
                }
                break;
 -#ifdef CONFIG_64BIT
 -      case 64:
 -              switch (val_endian) {
 -              case REGMAP_ENDIAN_BIG:
 -                      map->format.format_val = regmap_format_64_be;
 -                      map->format.parse_val = regmap_parse_64_be;
 -                      map->format.parse_inplace = regmap_parse_64_be_inplace;
 -                      break;
 -              case REGMAP_ENDIAN_LITTLE:
 -                      map->format.format_val = regmap_format_64_le;
 -                      map->format.parse_val = regmap_parse_64_le;
 -                      map->format.parse_inplace = regmap_parse_64_le_inplace;
 -                      break;
 -              case REGMAP_ENDIAN_NATIVE:
 -                      map->format.format_val = regmap_format_64_native;
 -                      map->format.parse_val = regmap_parse_64_native;
 -                      break;
 -              default:
 -                      goto err_hwlock;
 -              }
 -              break;
 -#endif
        }
  
        if (map->format.format_write) {
@@@ -1988,8 -2082,6 +1988,6 @@@ int _regmap_raw_write(struct regmap *ma
        size_t val_count = val_len / val_bytes;
        size_t chunk_count, chunk_bytes;
        size_t chunk_regs = val_count;
-       size_t max_data = map->max_raw_write - map->format.reg_bytes -
-                       map->format.pad_bytes;
        int ret, i;
  
        if (!val_count)
  
        if (map->use_single_write)
                chunk_regs = 1;
-       else if (map->max_raw_write && val_len > max_data)
-               chunk_regs = max_data / val_bytes;
+       else if (map->max_raw_write && val_len > map->max_raw_write)
+               chunk_regs = map->max_raw_write / val_bytes;
  
        chunk_count = val_count / chunk_regs;
        chunk_bytes = chunk_regs * val_bytes;
@@@ -2066,6 -2158,9 +2064,6 @@@ static int regmap_noinc_readwrite(struc
        u8 *u8p;
        u16 *u16p;
        u32 *u32p;
 -#ifdef CONFIG_64BIT
 -      u64 *u64p;
 -#endif
        int ret;
        int i;
  
                if (write)
                        lastval = (unsigned int)u32p[val_count - 1];
                break;
 -#ifdef CONFIG_64BIT
 -      case 8:
 -              u64p = val;
 -              if (write)
 -                      lastval = (unsigned int)u64p[val_count - 1];
 -              break;
 -#endif
        default:
                return -EINVAL;
        }
                        case 4:
                                pr_cont("%x", u32p[i]);
                                break;
 -#ifdef CONFIG_64BIT
 -                      case 8:
 -                              pr_cont("%llx", u64p[i]);
 -                              break;
 -#endif
                        default:
                                break;
                        }
@@@ -2329,6 -2436,11 +2327,6 @@@ int regmap_bulk_write(struct regmap *ma
                        case 4:
                                ival = *(u32 *)(val + (i * val_bytes));
                                break;
 -#ifdef CONFIG_64BIT
 -                      case 8:
 -                              ival = *(u64 *)(val + (i * val_bytes));
 -                              break;
 -#endif
                        default:
                                ret = -EINVAL;
                                goto out;
@@@ -3093,6 -3205,9 +3091,6 @@@ int regmap_bulk_read(struct regmap *map
                for (i = 0; i < val_count * val_bytes; i += val_bytes)
                        map->format.parse_inplace(val + i);
        } else {
 -#ifdef CONFIG_64BIT
 -              u64 *u64 = val;
 -#endif
                u32 *u32 = val;
                u16 *u16 = val;
                u8 *u8 = val;
                                goto out;
  
                        switch (map->format.val_bytes) {
 -#ifdef CONFIG_64BIT
 -                      case 8:
 -                              u64[i] = ival;
 -                              break;
 -#endif
                        case 4:
                                u32[i] = ival;
                                break;
This page took 0.13934 seconds and 4 git commands to generate.