mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH] ARM64: Implement mem*_*io()
Date: Tue, 22 Jun 2021 10:03:57 +0200	[thread overview]
Message-ID: <fa4d9a01-1aa0-1678-7da9-cbe44e279b47@pengutronix.de> (raw)
In-Reply-To: <20210622075413.6659-1-s.hauer@pengutronix.de>

Hello Sascha,

On 22.06.21 09:54, Sascha Hauer wrote:
> This adds memset_io(), memcpy_fromio() and memcpy_toio(). These have not
> been defined for ARM64 previously. The code is directly taken from the
> Kernel.

With some compile-time changes this could be made generic for other
arches as well and go into lib/. See below.

Atmel Quad-SPI driver is the only current user and I could test your generic
implementation on it to make sure we don't break anything.

> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/lib64/Makefile |  2 +-
>  arch/arm/lib64/io.c     | 98 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 99 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/lib64/io.c
> 
> diff --git a/arch/arm/lib64/Makefile b/arch/arm/lib64/Makefile
> index 69cb3d8ea1..a004af4867 100644
> --- a/arch/arm/lib64/Makefile
> +++ b/arch/arm/lib64/Makefile
> @@ -6,5 +6,5 @@ obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o string.o
>  extra-y += barebox.lds
>  obj-pbl-y   += runtime-offset.o
>  obj-pbl-y   += setjmp.o
> -
> +obj-y += io.o
>  pbl-y	+= div0.o pbl.o
> diff --git a/arch/arm/lib64/io.c b/arch/arm/lib64/io.c
> new file mode 100644
> index 0000000000..fdf2117cc8
> --- /dev/null
> +++ b/arch/arm/lib64/io.c
> @@ -0,0 +1,98 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Based on arch/arm/kernel/io.c
> + *
> + * Copyright (C) 2012 ARM Ltd.
> + */
> +
> +#include <linux/export.h>
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <io.h>
#define read_word (either readl/readq depending on CONFIG_64BIT)

> +
> +/*
> + * Copy data from IO memory space to "real" memory space.
> + */
> +void memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
> +{
> +	while (count && !IS_ALIGNED((unsigned long)from, 8)) {

s/8/sizeof(long)/ as well as all 8 below

> +		*(u8 *)to = __raw_readb(from);
> +		from++;
> +		to++;
> +		count--;
> +	}
> +
> +	while (count >= 8) {
> +		*(u64 *)to = __raw_readq(from);

read_word.

> +		from += 8;
> +		to += 8;
> +		count -= 8;
> +	}
> +
> +	while (count) {
> +		*(u8 *)to = __raw_readb(from);
> +		from++;
> +		to++;
> +		count--;
> +	}
> +}
> +EXPORT_SYMBOL(memcpy_fromio);
> +
> +/*
> + * Copy data from "real" memory space to IO memory space.
> + */
> +void memcpy_toio(volatile void __iomem *to, const void *from, size_t count)

Same here.

> +{
> +	while (count && !IS_ALIGNED((unsigned long)to, 8)) {
> +		__raw_writeb(*(u8 *)from, to);
> +		from++;
> +		to++;
> +		count--;
> +	}
> +
> +	while (count >= 8) {
> +		__raw_writeq(*(u64 *)from, to);
> +		from += 8;
> +		to += 8;
> +		count -= 8;
> +	}
> +
> +	while (count) {
> +		__raw_writeb(*(u8 *)from, to);
> +		from++;
> +		to++;
> +		count--;
> +	}
> +}
> +EXPORT_SYMBOL(memcpy_toio);
> +
> +/*
> + * "memset" on IO memory space.
> + */
> +void memset_io(volatile void __iomem *dst, int c, size_t count)
> +{
> +	u64 qc = (u8)c;
> +
> +	qc |= qc << 8;
> +	qc |= qc << 16;
> +	qc |= qc << 32;
> +
> +	while (count && !IS_ALIGNED((unsigned long)dst, 8)) {
> +		__raw_writeb(c, dst);
> +		dst++;
> +		count--;
> +	}
> +
> +	while (count >= 8) {
> +		__raw_writeq(qc, dst);
> +		dst += 8;
> +		count -= 8;
> +	}
> +
> +	while (count) {
> +		__raw_writeb(c, dst);
> +		dst++;
> +		count--;
> +	}
> +}
> +EXPORT_SYMBOL(memset_io);
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


      reply	other threads:[~2021-06-22  8:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22  7:54 Sascha Hauer
2021-06-22  8:03 ` Ahmad Fatoum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fa4d9a01-1aa0-1678-7da9-cbe44e279b47@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox