Re: [PATCH RFC 1/2] regmap: add option to disable debugfs

From: Mark Brown
Date: Mon Jun 20 2022 - 13:51:39 EST


On Mon, Jun 20, 2022 at 04:15:40PM +0000, Aisheng Dong wrote:

> > The driver is going to need to power the device back up to access the volatile
> > registers so it can take the device out of cache only mode when it's doing that
> > can't it?

> Sorry, I didn't quite get it.
> There's no problem in driver to access volatile registers as it usually will power up
> device first by rpm.

So the runtime power managment seems like a good place to manage cache
only mode.

> But for debugfs, from what I saw in code, if there's a volatile register, _regmap_read()
> will bypass cache and try to read the register value from HW.
> Then system may hang as no one powered up the device before.
> Anything I missed?

> static int _regmap_read(struct regmap *map, unsigned int reg,
> unsigned int *val)
> {
> int ret;
> void *context = _regmap_map_get_context(map);
>
> if (!map->cache_bypass) {
> ret = regcache_read(map, reg, val);
> if (ret == 0)
> return 0;
> }
>
> ret = map->reg_read(context, reg, val);

That's not what the code is upstream, upstream between the cache_bypass
check and the reg_read we have

if (map->cache_only)
return -EBUSY;

if (!regmap_readable(map, reg))
return -EIO;

so if we can't satisfy the read from the cache then we'll hit the
cache_only check and return -EBUSY before we start trying to do any
physical I/O. The debugfs code will handle that gracefully, indicating
that it couldn't get a value for the volatile register by showing all Xs
for the value. If none of the registers are cached then the file won't
be terribly useful but it at least shouldn't cause any errors with
accessing the device when it's powered down.

> Or you mean simply forgetting about volatile registers and let debugfs
> to read the stale value from cache?

We shouldn't cache anything for volatile registers, if we are then
that's an issue.

Attachment: signature.asc
Description: PGP signature