From: heiko@sntech.de
To: linux-riscv@lists.infradead.org
Cc: palmer@dabbelt.com, aou@eecs.berkeley.edu,
conor.dooley@microchip.com, ajones@ventanamicro.com,
Ben Dooks <ben.dooks@codethink.co.uk>
Subject: Re: [PATCH 2/2] riscv: mm: add pgprot_dmacoherent for zicbom
Date: Wed, 08 Mar 2023 14:19:35 +0100 [thread overview]
Message-ID: <1772602.TLkxdtWsSY@diego> (raw)
In-Reply-To: <226aa2ae-dfa0-d947-0aaf-4407e0c0bc5b@codethink.co.uk>
Am Mittwoch, 8. März 2023, 10:35:14 CET schrieb Ben Dooks:
> On 07/03/2023 20:58, Ben Dooks wrote:
> > If the system uses both ZICBOM and SVPBMT then currently SVPBMT will be
> > used for DMA allocated memory even though ZICBOM gives us the cache ops
> > to use cached memory and clean/flush them as needed by the DMA code.
> >
> > Fix this by adding pgprot_dmacoherent() which is used by the allocator
> > code to map the dma memory, thus allowing the return of suitably mapped
> > memory for any use of dma_alloc_attrs() code. This s uses the added
> > riscv_page_dmacoherent() which will work out the correct page flags to
> > return using ALT_SVPBMT_ZICBOM() to runtime patch the right result.
> >
> > Note, we can't just disable SVPBMT as it will be neede for things like
> > ioremap() which don't have assoicated cache management operations.
> >
> > Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> > ---
> > arch/riscv/include/asm/errata_list.h | 16 ++++++++++++++++
> > arch/riscv/include/asm/pgtable-64.h | 10 ++++++++++
> > 2 files changed, 26 insertions(+)
> >
> > diff --git a/arch/riscv/include/asm/errata_list.h b/arch/riscv/include/asm/errata_list.h
> > index fb1a810f3d8c..49ed2e7984a7 100644
> > --- a/arch/riscv/include/asm/errata_list.h
> > +++ b/arch/riscv/include/asm/errata_list.h
> > @@ -62,6 +62,22 @@ asm(ALTERNATIVE_2("li %0, 0\t\nnop", \
> > "I"(ALT_SVPBMT_SHIFT), \
> > "I"(ALT_THEAD_PBMT_SHIFT))
> >
> > +#define ALT_SVPBMT_ZICBOM(_val, prot) \
> > +asm(ALTERNATIVE_3("li %0, 0\t\nnop", \
> > + "li %0, %1\t\nslli %0,%0,%3", 0, \
> > + RISCV_ISA_EXT_SVPBMT, CONFIG_RISCV_ISA_SVPBMT, \
> > + "li %0, 0\t\nnop", 0, \
> > + RISCV_ISA_EXT_ZICBOM, CONFIG_RISCV_ISA_ZICBOM, \
>
> so, I tink this needs to be selected on CONFIG_RISCV_DMA_NONCOHERENT
> as just having ZICBOM in the ISA isn't enough to actually use it, you'll
> need the dma-noncoherent.o being built to do the cache management.
CONFIG_RISCV_ISA_ZICBOM does a
select RISCV_DMA_NONCOHERENT
same as CONFIG_ERRATA_THEAD_CMO
So dma-noncoherent gets build if you enable at least one of them.
What am I missing?
> > + "li %0, %2\t\nslli %0,%0,%4", THEAD_VENDOR_ID, \
> > + ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \
> > + : "=r"(_val) \
> > + : "I"(prot##_SVPBMT >> ALT_SVPBMT_SHIFT), \
> > + "I"(prot##_THEAD >> ALT_THEAD_PBMT_SHIFT), \
> > + "I"(ALT_SVPBMT_SHIFT), \
> > + "I"(ALT_THEAD_PBMT_SHIFT))
> > +
> > +
> > +
> > #ifdef CONFIG_ERRATA_THEAD_PBMT
> > /*
> > * IO/NOCACHE memory types are handled together with svpbmt,
> > diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
> > index 42a042c0e13e..e0d2e5fda5a4 100644
> > --- a/arch/riscv/include/asm/pgtable-64.h
> > +++ b/arch/riscv/include/asm/pgtable-64.h
> > @@ -126,10 +126,20 @@ static inline u64 riscv_page_io(void)
> > return val;
> > }
> >
> > +static inline u64 riscv_page_dmacoherent(void)
> > +{
> > + u64 val;
> > +
> > + ALT_SVPBMT_ZICBOM(val, _PAGE_IO);
> > + return val;
> > +}
> > +
> > #define _PAGE_NOCACHE riscv_page_nocache()
> > #define _PAGE_IO riscv_page_io()
> > #define _PAGE_MTMASK riscv_page_mtmask()
> >
> > +#define pgprot_dmacoherent(__prot) __pgprot(pgprot_val(__prot) | riscv_page_dmacoherent())
> > +
> > /* Set of bits to preserve across pte_modify() */
> > #define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \
> > _PAGE_WRITE | _PAGE_EXEC | \
>
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2023-03-08 13:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 20:58 ZICBOM and SVPBMT in same system Ben Dooks
2023-03-07 20:58 ` [PATCH 1/2] riscv: alternatives: add 3-config alternative set Ben Dooks
2023-03-07 21:31 ` Conor Dooley
2023-03-08 9:34 ` Ben Dooks
2023-03-07 20:58 ` [PATCH 2/2] riscv: mm: add pgprot_dmacoherent for zicbom Ben Dooks
2023-03-08 9:35 ` Ben Dooks
2023-03-08 10:13 ` Conor Dooley
2023-03-08 13:19 ` heiko [this message]
2023-03-08 14:48 ` Ben Dooks
2023-03-24 17:30 ` Ben Dooks
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=1772602.TLkxdtWsSY@diego \
--to=heiko@sntech.de \
--cc=ajones@ventanamicro.com \
--cc=aou@eecs.berkeley.edu \
--cc=ben.dooks@codethink.co.uk \
--cc=conor.dooley@microchip.com \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.