[PATCH v1 2/7] nvmem: rmem: add write and protect support
Sascha Hauer
s.hauer at pengutronix.de
Mon Jun 2 02:33:53 PDT 2025
On Fri, May 30, 2025 at 01:41:01PM +0200, Oleksij Rempel wrote:
> Add reg_write and reg_protect operations to the rmem NVMEM driver.
> This makes rmem devices writable (they were previously read-only via the
> NVMEM interface due to lacking reg_write) and allows specific regions
> to be marked read-only.
>
> The primary motivation is to improve testing of NVMEM consumer code that
> handles write protection, by enabling rmem to emulate such hardware,
> particularly in sandbox environments.
This is some quite complex code with lots of possibilities to introduce
bugs. nvmem devices are rather small and your motivation is debugging,
so I suggest to invest 1/8 of the nvmem device in memory and use a
bitmap instead of lists of ranges.
> +/**
> + * rmem_ranges_overlap - Check if two memory ranges overlap.
> + * @offset1: Starting offset of the first range.
> + * @len1: Length of the first range.
> + * @offset2: Starting offset of the second range.
> + * @len2: Length of the second range.
> + *
> + * Compares two memory ranges, defined by their starting offsets and
> + * lengths, to determine if they have any common region. Ranges with
> + * zero length are considered non-overlapping.
> + *
> + * The ranges are treated as inclusive, i.e., a range starting at @offset
> + * with length @len covers all bytes from @offset to @offset + @len - 1.
> + *
> + * Return: True if the ranges overlap, false otherwise.
> + */
> +static bool rmem_ranges_overlap(unsigned int offset1, size_t len1,
> + unsigned int offset2, size_t len2)
> +{
We already have region_overlap_size() for this.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list