From: Stefan Bruens <stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
To: Maxime Ripard
<maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
Cc: "Stefan Brüns"
<stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>,
linux-sunxi <linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
dmaengine-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Chen-Yu Tsai" <wens-jdAy2FN1RRM@public.gmane.org>,
"Rob Herring" <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: Re: [PATCH 1/3] dmaengine: sun6i: Correct DMA support on H3
Date: Fri, 1 Sep 2017 05:04:54 +0200 [thread overview]
Message-ID: <a649f98d4ac44abc873c5110ce9363e5@rwthex-w2-b.rwth-ad.de> (raw)
In-Reply-To: <20170831145135.c6a2wubcf6xu34tz-ZC1Zs529Oq4@public.gmane.org>
On Donnerstag, 31. August 2017 16:51:35 CEST Maxime Ripard wrote:
> Hi,
>
> On Thu, Aug 31, 2017 at 01:36:07AM +0200, Stefan Brüns wrote:
> > +/* Between SoC generations, there are some significant differences:
> > + * - A23 added a clock gate register
> > + * - the H3 burst length field has a different offset
> > + */
>
> This is not the proper comment style.
>
> > +enum dmac_variant {
> > + DMAC_VARIANT_A31,
> > + DMAC_VARIANT_A23,
> > + DMAC_VARIANT_H3,
> > +};
> > +
>
> And this is redundant with what we already have in our structures.
Actually, its not. For H3, there are currently at least 3 register compatible
SoCs: H5 is identical, R40 has 16 dma channels, A64 has 8 channels. So if the
current config structure is kept, we need 3 different compatible strings. Same
for the A23, which is register compatible to e.g. A83t and V3s, but with
different numbers of DMA channels.
So either you decorate the code with a cascade of
if ((of_is_compatible(..A23..) || of_is_compatible(..A83T..) || ...) {
} else if ((of_is_compatible(..H3..) || of_is_compatible(..A64..) || ...) {
} else { /* A31 */
}
in a number of places, or you do it just once.
>
> > /*
> >
> > * Hardware channels / ports representation
> > *
> >
> > @@ -101,6 +116,7 @@ struct sun6i_dma_config {
> >
> > u32 nr_max_channels;
> > u32 nr_max_requests;
> > u32 nr_max_vchans;
> >
> > + enum dmac_variant dmac_variant;
> >
> > };
> >
> > /*
> >
> > @@ -240,8 +256,12 @@ static inline s8 convert_burst(u32 maxburst)
> >
> > switch (maxburst) {
> >
> > case 1:
> > return 0;
> >
> > + case 4:
> > + return 1;
> >
> > case 8:
> > return 2;
> >
> > + case 16:
> > + return 3;
> >
> > default:
> > return -EINVAL;
> >
> > }
> >
> > @@ -249,11 +269,7 @@ static inline s8 convert_burst(u32 maxburst)
> >
> > static inline s8 convert_buswidth(enum dma_slave_buswidth addr_width)
> > {
> >
> > - if ((addr_width < DMA_SLAVE_BUSWIDTH_1_BYTE) ||
> > - (addr_width > DMA_SLAVE_BUSWIDTH_4_BYTES))
> > - return -EINVAL;
> > -
> > - return addr_width >> 1;
> > + return ilog2(addr_width);
> >
> > }
>
> This isn't really the same operation. There should be some explanation
> about why it's the right thing to do.
For 1, 2 and 4 it is the same. The correct register value for 8 bytes,
supported by H3, H5, A64 and R40, is 3.
>
> > static size_t sun6i_get_chan_size(struct sun6i_pchan *pchan)
> >
> > @@ -499,45 +515,58 @@ static int set_config(struct sun6i_dma_dev *sdev,
> >
> > enum dma_transfer_direction direction,
> > u32 *p_cfg)
> >
> > {
> >
> > + enum dma_slave_buswidth src_addr_width, dst_addr_width;
> > + u32 src_maxburst, dst_maxburst, supported_burst_length;
> >
> > s8 src_width, dst_width, src_burst, dst_burst;
> >
> > + src_addr_width = sconfig->src_addr_width;
> > + dst_addr_width = sconfig->dst_addr_width;
> > + src_maxburst = sconfig->src_maxburst;
> > + dst_maxburst = sconfig->dst_maxburst;
> > +
> > + if (sdev->cfg->dmac_variant == DMAC_VARIANT_H3)
> > + supported_burst_length = BIT(1) | BIT(4) | BIT(8) | BIT(16);
> > + else
> > + supported_burst_length = BIT(1) | BIT(8);
>
> This could be stored in the structure for example.
Which one? sun6i_dma_dev? sun6i_dma_config?
> > switch (direction) {
> >
> > case DMA_MEM_TO_DEV:
> > - src_burst = convert_burst(sconfig->src_maxburst ?
> > - sconfig->src_maxburst : 8);
> > - src_width = convert_buswidth(sconfig->src_addr_width !=
> > - DMA_SLAVE_BUSWIDTH_UNDEFINED ?
> > - sconfig->src_addr_width :
> > - DMA_SLAVE_BUSWIDTH_4_BYTES);
> > - dst_burst = convert_burst(sconfig->dst_maxburst);
> > - dst_width = convert_buswidth(sconfig->dst_addr_width);
> > + if (src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
> > + src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
> > + src_maxburst = src_maxburst ? src_maxburst : 8;
> >
> > break;
> >
> > case DMA_DEV_TO_MEM:
> > - src_burst = convert_burst(sconfig->src_maxburst);
> > - src_width = convert_buswidth(sconfig->src_addr_width);
> > - dst_burst = convert_burst(sconfig->dst_maxburst ?
> > - sconfig->dst_maxburst : 8);
> > - dst_width = convert_buswidth(sconfig->dst_addr_width !=
> > - DMA_SLAVE_BUSWIDTH_UNDEFINED ?
> > - sconfig->dst_addr_width :
> > - DMA_SLAVE_BUSWIDTH_4_BYTES);
> > + if (dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
> > + dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
> > + dst_maxburst = dst_maxburst ? dst_maxburst : 8;
> >
> > break;
> >
> > default:
> > return -EINVAL;
> >
> > }
> >
> > - if (src_burst < 0)
> > - return src_burst;
> > - if (src_width < 0)
> > - return src_width;
> > - if (dst_burst < 0)
> > - return dst_burst;
> > - if (dst_width < 0)
> > - return dst_width;
> > -
> > - *p_cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) |
> > - DMA_CHAN_CFG_SRC_WIDTH(src_width) |
> > - DMA_CHAN_CFG_DST_BURST(dst_burst) |
> > + if (!(BIT(src_addr_width) & sdev->slave.src_addr_widths))
> > + return -EINVAL;
> > + if (!(BIT(dst_addr_width) & sdev->slave.dst_addr_widths))
> > + return -EINVAL;
> > + if (!(BIT(src_maxburst) & supported_burst_length))
> > + return -EINVAL;
> > + if (!(BIT(dst_maxburst) & supported_burst_length))
> > + return -EINVAL;
> > +
> > + src_width = convert_buswidth(src_addr_width);
> > + dst_width = convert_buswidth(dst_addr_width);
> > + dst_burst = convert_burst(dst_maxburst);
> > + src_burst = convert_burst(src_maxburst);
>
> I'm not sure what you're trying to do here. Could you split your patch
> by logical change, this doesn't seem related to just supporting the
> H3, but a heavier refactoring.
Untangling 3 independent steps - handling of DMA_SLAVE_BUSWIDTH_UNDEFINED,
range checking, and conversion to register value. As the valid ranges depend
on the controller, the code is much easier to read if the range check is done
first, and then the conversion.
Kind regards,
Stefan
--
Stefan Brüns / Bergstraße 21 / 52062 Aachen
home: +49 241 53809034 mobile: +49 151 50412019
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
next prev parent reply other threads:[~2017-09-01 3:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-30 23:36 [PATCH 0/3] dmaengine: Fix DMA on current allwinner SoCs, add A64 support Stefan Brüns
2017-08-30 23:36 ` [PATCH 1/3] dmaengine: sun6i: Correct DMA support on H3 Stefan Brüns
2017-08-31 14:51 ` Maxime Ripard
[not found] ` <20170831145135.c6a2wubcf6xu34tz-ZC1Zs529Oq4@public.gmane.org>
2017-09-01 3:04 ` Stefan Bruens [this message]
2017-09-01 13:35 ` Maxime Ripard
2017-09-01 14:42 ` Brüns, Stefan
2017-09-01 14:51 ` taskboxtester
2017-09-04 6:50 ` Maxime Ripard
2017-08-30 23:36 ` [PATCH 2/3] arm64: allwinner: a64: Add device node for DMA controller Stefan Brüns
[not found] ` <20170830233609.13855-3-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
2017-09-11 22:00 ` Rob Herring
2017-08-30 23:36 ` [PATCH 3/3] dmaengine: sun6i: Add support for Allwinner A64 Stefan Brüns
2017-08-31 11:44 ` Code Kipper
[not found] ` <20170830233609.13855-4-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
2017-08-31 14:52 ` Maxime Ripard
[not found] ` <20170831145246.p4k3uakbn67na3pv-ZC1Zs529Oq4@public.gmane.org>
2017-08-31 16:35 ` Code Kipper
2017-09-01 0:31 ` Andre Przywara
[not found] ` <20170901003135.10058-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2017-09-01 1:19 ` Stefan Bruens
2017-09-01 22:32 ` André Przywara
[not found] ` <d397d87b-5004-c8af-e590-037befc9b2b6-5wv7dgnIgG8@public.gmane.org>
2017-09-02 0:38 ` Stefan Bruens
2017-09-02 2:02 ` Stefan Bruens
[not found] ` <2607878.Us0MSlEf6n-KVr1ISHqF63jSbz6xCtQhw@public.gmane.org>
2017-09-03 23:14 ` André Przywara
2017-09-01 6:04 ` Maxime Ripard
2017-09-01 22:35 ` André Przywara
[not found] ` <743ae23a-372a-762b-c345-b914f09fd718-5wv7dgnIgG8@public.gmane.org>
2017-09-04 7:04 ` Maxime Ripard
2017-09-04 8:14 ` André Przywara
2017-09-08 14:39 ` Maxime Ripard
2017-09-08 14:57 ` Andre Przywara
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=a649f98d4ac44abc873c5110ce9363e5@rwthex-w2-b.rwth-ad.de \
--to=stefan.bruens-va1bhqpz9fbzxben9dutxg@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dmaengine-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
--cc=maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=wens-jdAy2FN1RRM@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).