lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <93708a21-3444-f68e-c834-a4f769a0acba@milecki.pl>
Date:   Fri, 5 Mar 2021 11:24:35 +0100
From:   Rafał Miłecki <rafal@...ecki.pl>
To:     Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
        Rafał Miłecki <zajec5@...il.com>,
        Rob Herring <robh+dt@...nel.org>
Cc:     devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        linux-mips@...r.kernel.org,
        Florian Fainelli <f.fainelli@...il.com>,
        Vivek Unune <npcomplete13@...il.com>,
        bcm-kernel-feedback-list@...adcom.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] nvmem: iomap: new driver exposing NVMEM accessible
 using I/O mapping

On 05.03.2021 11:02, Srinivas Kandagatla wrote:
> On 04/03/2021 14:41, Rafał Miłecki wrote:
>> From: Rafał Miłecki <rafal@...ecki.pl>
>>
>> This is a generic NVMEM access method used e.g. by Broadcom for their
>> NVRAM on MIPS and Northstar devices.
>>
>> Signed-off-by: Rafał Miłecki <rafal@...ecki.pl>
>> ---
>>   drivers/nvmem/Kconfig  |  7 +++
>>   drivers/nvmem/Makefile |  2 +
>>   drivers/nvmem/iomap.c  | 99 ++++++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 108 insertions(+)
>>   create mode 100644 drivers/nvmem/iomap.c
>>
>> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
>> index 75d2594c16e1..3d5c5684685d 100644
>> --- a/drivers/nvmem/Kconfig
>> +++ b/drivers/nvmem/Kconfig
>> @@ -278,4 +278,11 @@ config NVMEM_RMEM
>>         This driver can also be built as a module. If so, the module
>>         will be called nvmem-rmem.
>> +
>> +config NVMEM_IOMAP
>> +    tristate "I/O mapped NVMEM support"
>> +    depends on HAS_IOMEM
>> +    help
>> +      This driver supports NVMEM that can be accessed using I/O mapping.
>> +
>>   endif
>> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
>> index 5376b8e0dae5..88a3b6979c53 100644
>> --- a/drivers/nvmem/Makefile
>> +++ b/drivers/nvmem/Makefile
>> @@ -57,3 +57,5 @@ obj-$(CONFIG_SPRD_EFUSE)    += nvmem_sprd_efuse.o
>>   nvmem_sprd_efuse-y        := sprd-efuse.o
>>   obj-$(CONFIG_NVMEM_RMEM)     += nvmem-rmem.o
>>   nvmem-rmem-y            := rmem.o
>> +obj-$(CONFIG_NVMEM_IOMAP)    += nvmem_iomap.o
>> +nvmem_iomap-y            := iomap.o
>> diff --git a/drivers/nvmem/iomap.c b/drivers/nvmem/iomap.c
>> new file mode 100644
>> index 000000000000..ab6b40858a64
>> --- /dev/null
>> +++ b/drivers/nvmem/iomap.c
>> @@ -0,0 +1,99 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (C) 2021 Rafał Miłecki <rafal@...ecki.pl>
>> + */
>> +
>> +#include <linux/io.h>
>> +#include <linux/mod_devicetable.h>
>> +#include <linux/module.h>
>> +#include <linux/nvmem-provider.h>
>> +#include <linux/platform_device.h>
>> +
>> +struct iomap {
>> +    struct device *dev;
>> +    void __iomem *base;
>> +};
>> +
>> +static int iomap_read(void *context, unsigned int offset, void *val,
>> +              size_t bytes)
>> +{
>> +    struct iomap *priv = context;
>> +    u8 *src = priv->base + offset;
>> +    u8 *dst = val;
>> +    size_t tmp;
>> +
>> +    tmp = offset % 4;
>> +    memcpy_fromio(dst, src, tmp);
>> +    dst += tmp;
>> +    src += tmp;
>> +    bytes -= tmp;
>> +
>> +    tmp = rounddown(bytes, 4);
>> +    __ioread32_copy(dst, src, tmp / 4);
>> +    dst += tmp;
>> +    src += tmp;
>> +    bytes -= tmp;
>> +
>> +    memcpy_fromio(dst, src, bytes);
>> +
> 
> 
> You could just do this!
> 
>      while (bytes--)
>          *val++ = readb(priv->base + offset + i++);

Do you mean that as replacement for "memcpy_fromio" or the whole
function code?
The reason for using __ioread32_copy() was to improve reading
performance (using aligned 32 bit access where possible). I'm not sure
if that really matters?

P.S.
Please don't yell at me in every sentence :( Makes me a bit sad :(

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ