[PATCH v10 03/10] mtd: intel-dg: implement access functions
Raag Jadav
raag.jadav at intel.com
Wed May 21 20:26:24 UTC 2025
On Thu, May 15, 2025 at 04:33:38PM +0300, Alexander Usyskin wrote:
> Implement read(), erase() and write() functions.
...
> +__maybe_unused
> +static ssize_t idg_write(struct intel_dg_nvm *nvm, u8 region,
> + loff_t to, size_t len, const unsigned char *buf)
> +{
> + size_t i;
> + size_t len8;
> + size_t len4;
> + size_t to4;
> + size_t to_shift;
> + size_t len_s = len;
> + ssize_t ret;
> +
> + idg_nvm_set_region_id(nvm, region);
> +
> + to4 = ALIGN_DOWN(to, sizeof(u32));
> + to_shift = min(sizeof(u32) - ((size_t)to - to4), len);
> + if (to - to4) {
> + ret = idg_nvm_rewrite_partial(nvm, to4, to - to4, to_shift, (uint32_t *)&buf[0]);
Forgot to add, you're using both uint32_t and u32.
Perhaps make it consistent?
> + if (ret < 0)
> + return ret;
> +
> + buf += to_shift;
> + to += to_shift;
> + len_s -= to_shift;
> + }
> +
> + len8 = ALIGN_DOWN(len_s, sizeof(u64));
> + for (i = 0; i < len8; i += sizeof(u64)) {
> + u64 data;
> +
> + memcpy(&data, &buf[i], sizeof(u64));
> + idg_nvm_write64(nvm, to + i, data);
> + if (idg_nvm_error(nvm))
> + return -EIO;
> + }
> +
> + len4 = len_s - len8;
> + if (len4 >= sizeof(u32)) {
> + u32 data;
> +
> + memcpy(&data, &buf[i], sizeof(u32));
> + idg_nvm_write32(nvm, to + i, data);
> + if (idg_nvm_error(nvm))
> + return -EIO;
> + i += sizeof(u32);
> + len4 -= sizeof(u32);
> + }
> +
> + if (len4 > 0) {
> + ret = idg_nvm_rewrite_partial(nvm, to + i, 0, len4, (uint32_t *)&buf[i]);
Ditto (and also in all other places if any).
> + if (ret < 0)
> + return ret;
> + }
> +
> + return len;
> +}
Raag
More information about the Intel-gfx
mailing list