2019-09-10 18:57:06

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v2 0/3] dmaengine: bindings/edma: dma-channel-mask to array

Hi,

Changes since v1:
- Extend the common dma-channel-mask to uint32-array to be usable for
controllers with more than 32 channels
- Use the dma-channel-mask instead custom property for available channels for
EDMA.

The original patch was part of the EDMA multicore usage series.

Rob: I'm not sure if I got the dma-common.yaml update correctly...

EDMAs can have 32 or 64 channels depending on the SoC, the dma-channel-mask
needs to be an array to be usable for the driver.

Regards,
Peter
---
Peter Ujfalusi (3):
dt-bindings: dmaengine: dma-common: Change dma-channel-mask to
uint32-array
dt-bindings: dma: ti-edma: Document dma-channel-mask for EDMA
dmaengine: ti: edma: Add support for handling reserved channels

.../devicetree/bindings/dma/dma-common.yaml | 10 +++-
.../devicetree/bindings/dma/ti-edma.txt | 6 ++
drivers/dma/ti/edma.c | 59 +++++++++++++++++--
3 files changed, 68 insertions(+), 7 deletions(-)

--
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


2019-09-10 18:57:14

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v2 3/3] dmaengine: ti: edma: Add support for handling reserved channels

Like paRAM slots, channels could be used by other cores and in this case
we need to make sure that the driver do not alter these channels.

Handle the generic dma-channel-mask property to mark channels in a bitmap
which can not be used by Linux and convert the legacy rsv_chans if it is
provided by platform_data.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/dma/ti/edma.c | 59 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/ti/edma.c b/drivers/dma/ti/edma.c
index ba7c4f07fcd6..03c9c6296006 100644
--- a/drivers/dma/ti/edma.c
+++ b/drivers/dma/ti/edma.c
@@ -260,6 +260,13 @@ struct edma_cc {
*/
unsigned long *slot_inuse;

+ /*
+ * For tracking reserved channels used by DSP.
+ * If the bit is cleared, the channel is allocated to be used by DSP
+ * and Linux must not touch it.
+ */
+ unsigned long *channels_mask;
+
struct dma_device dma_slave;
struct dma_device *dma_memcpy;
struct edma_chan *slave_chans;
@@ -716,6 +723,12 @@ static int edma_alloc_channel(struct edma_chan *echan,
struct edma_cc *ecc = echan->ecc;
int channel = EDMA_CHAN_SLOT(echan->ch_num);

+ if (!test_bit(echan->ch_num, ecc->channels_mask)) {
+ dev_err(ecc->dev, "Channel%d is reserved, can not be used!\n",
+ echan->ch_num);
+ return -EINVAL;
+ }
+
/* ensure access through shadow region 0 */
edma_or_array2(ecc, EDMA_DRAE, 0, EDMA_REG_ARRAY_INDEX(channel),
EDMA_CHANNEL_BIT(channel));
@@ -2250,7 +2263,7 @@ static int edma_probe(struct platform_device *pdev)
struct edma_soc_info *info = pdev->dev.platform_data;
s8 (*queue_priority_mapping)[2];
int i, off;
- const s16 (*rsv_slots)[2];
+ const s16 (*reserved)[2];
const s16 (*xbar_chans)[2];
int irq;
char *irq_name;
@@ -2331,15 +2344,32 @@ static int edma_probe(struct platform_device *pdev)
if (!ecc->slot_inuse)
return -ENOMEM;

+ ecc->channels_mask = devm_kcalloc(dev,
+ BITS_TO_LONGS(ecc->num_channels),
+ sizeof(unsigned long), GFP_KERNEL);
+ if (!ecc->channels_mask)
+ return -ENOMEM;
+
+ /* Mark all channels available initially */
+ bitmap_fill(ecc->channels_mask, ecc->num_channels);
+
ecc->default_queue = info->default_queue;

if (info->rsv) {
/* Set the reserved slots in inuse list */
- rsv_slots = info->rsv->rsv_slots;
- if (rsv_slots) {
- for (i = 0; rsv_slots[i][0] != -1; i++)
- bitmap_set(ecc->slot_inuse, rsv_slots[i][0],
- rsv_slots[i][1]);
+ reserved = info->rsv->rsv_slots;
+ if (reserved) {
+ for (i = 0; reserved[i][0] != -1; i++)
+ bitmap_set(ecc->slot_inuse, reserved[i][0],
+ reserved[i][1]);
+ }
+
+ /* Clear channels not usable for Linux */
+ reserved = info->rsv->rsv_chans;
+ if (reserved) {
+ for (i = 0; reserved[i][0] != -1; i++)
+ bitmap_clear(ecc->channels_mask, reserved[i][0],
+ reserved[i][1]);
}
}

@@ -2399,6 +2429,7 @@ static int edma_probe(struct platform_device *pdev)

if (!ecc->legacy_mode) {
int lowest_priority = 0;
+ unsigned int array_max;
struct of_phandle_args tc_args;

ecc->tc_list = devm_kcalloc(dev, ecc->num_tc,
@@ -2420,6 +2451,18 @@ static int edma_probe(struct platform_device *pdev)
info->default_queue = i;
}
}
+
+ /* See if we have optional dma-channel-mask array */
+ array_max = DIV_ROUND_UP(ecc->num_channels, BITS_PER_TYPE(u32));
+ ret = of_property_read_variable_u32_array(node,
+ "dma-channel-mask",
+ (u32 *)ecc->channels_mask,
+ 1, array_max);
+ if (ret > 0 && ret != array_max)
+ dev_warn(dev, "dma-channel-mask is not complete.\n");
+ else if (ret == -EOVERFLOW || ret == -ENODATA)
+ dev_warn(dev,
+ "dma-channel-mask is out of range or empty\n");
}

/* Event queue priority mapping */
@@ -2437,6 +2480,10 @@ static int edma_probe(struct platform_device *pdev)
edma_dma_init(ecc, legacy_mode);

for (i = 0; i < ecc->num_channels; i++) {
+ /* Do not touch reserved channels */
+ if (!test_bit(i, ecc->channels_mask))
+ continue;
+
/* Assign all channels to the default queue */
edma_assign_channel_eventq(&ecc->slave_chans[i],
info->default_queue);
--
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-10 18:57:15

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v2 1/3] dt-bindings: dmaengine: dma-common: Change dma-channel-mask to uint32-array

Make the dma-channel-mask to be usable for controllers with more than 32
channels.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
Documentation/devicetree/bindings/dma/dma-common.yaml | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/dma/dma-common.yaml b/Documentation/devicetree/bindings/dma/dma-common.yaml
index ed0a49a6f020..41460946be64 100644
--- a/Documentation/devicetree/bindings/dma/dma-common.yaml
+++ b/Documentation/devicetree/bindings/dma/dma-common.yaml
@@ -25,11 +25,19 @@ properties:
Used to provide DMA controller specific information.

dma-channel-mask:
- $ref: /schemas/types.yaml#definitions/uint32
description:
Bitmask of available DMA channels in ascending order that are
not reserved by firmware and are available to the
kernel. i.e. first channel corresponds to LSB.
+ allOf:
+ - $ref: /schemas/types.yaml#/definitions/uint32-array
+ items:
+ minItems = 1
+ maxItems = 255 # Should be enough
+ - description: Mask of channels 0-31
+ - description: Mask of channels 32-63
+ ...
+ - description: Mask of chnanels X-(X+31)

dma-channels:
$ref: /schemas/types.yaml#definitions/uint32
--
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-10 18:58:46

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v2 2/3] dt-bindings: dma: ti-edma: Document dma-channel-mask for EDMA

Similarly to paRAM slots, channels can be used by other cores.

The common dma-channel-mask property can be used for specifying the
available channels.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
Documentation/devicetree/bindings/dma/ti-edma.txt | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/dma/ti-edma.txt b/Documentation/devicetree/bindings/dma/ti-edma.txt
index 4bbc94d829c8..3c7736246354 100644
--- a/Documentation/devicetree/bindings/dma/ti-edma.txt
+++ b/Documentation/devicetree/bindings/dma/ti-edma.txt
@@ -42,6 +42,9 @@ Optional properties:
- ti,edma-reserved-slot-ranges: PaRAM slot ranges which should not be used by
the driver, they are allocated to be used by for example the
DSP. See example.
+- dma-channel-mask: Mask of usable channels, see
+ Documentation/devicetree/bindings/dma/dma-common.yaml
+

------------------------------------------------------------------------------
eDMA3 Transfer Controller
@@ -91,6 +94,9 @@ edma: edma@49000000 {
ti,edma-memcpy-channels = <20 21>;
/* The following PaRAM slots are reserved: 35-44 and 100-109 */
ti,edma-reserved-slot-ranges = <35 10>, <100 10>;
+ /* The following channels are reserved: 35-44 */
+ dma-channel-mask = <0xffffffff>, /* Channel 0-31 */
+ <0xffffe007>; /* Channel 32-63 */
};

edma_tptc0: tptc@49800000 {
--
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-18 14:10:52

by Peter Ujfalusi

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] dt-bindings: dma: ti-edma: Document dma-channel-mask for EDMA



On 18/09/2019 16.29, Rob Herring wrote:
> On Tue, Sep 10, 2019 at 02:45:58PM +0300, Peter Ujfalusi wrote:
>> Similarly to paRAM slots, channels can be used by other cores.
>>
>> The common dma-channel-mask property can be used for specifying the
>> available channels.
>>
>> Signed-off-by: Peter Ujfalusi <[email protected]>
>> ---
>> Documentation/devicetree/bindings/dma/ti-edma.txt | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/dma/ti-edma.txt b/Documentation/devicetree/bindings/dma/ti-edma.txt
>> index 4bbc94d829c8..3c7736246354 100644
>> --- a/Documentation/devicetree/bindings/dma/ti-edma.txt
>> +++ b/Documentation/devicetree/bindings/dma/ti-edma.txt
>> @@ -42,6 +42,9 @@ Optional properties:
>> - ti,edma-reserved-slot-ranges: PaRAM slot ranges which should not be used by
>> the driver, they are allocated to be used by for example the
>> DSP. See example.
>> +- dma-channel-mask: Mask of usable channels, see
>> + Documentation/devicetree/bindings/dma/dma-common.yaml
>> +
>
> What's the size? 2 cells?

Depending on the EDMA, some have 32, some have 64 channels. I'll update
the patch to reflect this.

>>
>> ------------------------------------------------------------------------------
>> eDMA3 Transfer Controller
>> @@ -91,6 +94,9 @@ edma: edma@49000000 {
>> ti,edma-memcpy-channels = <20 21>;
>> /* The following PaRAM slots are reserved: 35-44 and 100-109 */
>> ti,edma-reserved-slot-ranges = <35 10>, <100 10>;
>> + /* The following channels are reserved: 35-44 */
>> + dma-channel-mask = <0xffffffff>, /* Channel 0-31 */
>> + <0xffffe007>; /* Channel 32-63 */
>> };
>>
>> edma_tptc0: tptc@49800000 {
>> --
>> Peter
>>
>> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
>> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
>>

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-18 14:27:03

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] dt-bindings: dmaengine: dma-common: Change dma-channel-mask to uint32-array

On Wed, Sep 18, 2019 at 9:04 AM Peter Ujfalusi <[email protected]> wrote:
>
>
>
> On 18/09/2019 16.28, Rob Herring wrote:
> > On Tue, Sep 10, 2019 at 02:45:57PM +0300, Peter Ujfalusi wrote:
> >> Make the dma-channel-mask to be usable for controllers with more than 32
> >> channels.
> >>
> >> Signed-off-by: Peter Ujfalusi <[email protected]>
> >> ---
> >> Documentation/devicetree/bindings/dma/dma-common.yaml | 10 +++++++++-
> >> 1 file changed, 9 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/Documentation/devicetree/bindings/dma/dma-common.yaml b/Documentation/devicetree/bindings/dma/dma-common.yaml
> >> index ed0a49a6f020..41460946be64 100644
> >> --- a/Documentation/devicetree/bindings/dma/dma-common.yaml
> >> +++ b/Documentation/devicetree/bindings/dma/dma-common.yaml
> >> @@ -25,11 +25,19 @@ properties:
> >> Used to provide DMA controller specific information.
> >>
> >> dma-channel-mask:
> >> - $ref: /schemas/types.yaml#definitions/uint32
> >> description:
> >> Bitmask of available DMA channels in ascending order that are
> >> not reserved by firmware and are available to the
> >> kernel. i.e. first channel corresponds to LSB.
> >> + allOf:
> >> + - $ref: /schemas/types.yaml#/definitions/uint32-array
> >> + items:
> >> + minItems = 1
> >
> > '='? Just making up the syntax?
>
> Opps, sorry.
>
> >
> >> + maxItems = 255 # Should be enough
> >> + - description: Mask of channels 0-31
> >> + - description: Mask of channels 32-63
> >
> > You are mixing a schema and list here...
>
> Should I extend the description with something like this:
> "The first item in the array is for channels 0-31, the second is for
> channels 32-63, etc."
>
> To make sure that it is used in a correct and consistent manner.

Sure.

>
> >> + ...
> >
> > That's end of doc marker in YAML...
>
> I believe I need some reading to do for YAML..
>
> >
> >> + - description: Mask of chnanels X-(X+31)
> >
> > Obviously, this was not validated with 'make dt_binding_check'.
> make dt_bindings_check
> make: *** No rule to make target 'dt_bindings_check'. Stop.

Read Documentation/devicetree/writing-schema.md (or .rst in next).

Either your config doesn't have DTC enabled or you don't have
dt-schema installed.

>
> > What you want is:
> >
> > allOf:
> > - $ref: /schemas/types.yaml#/definitions/uint32-array
> > - minItems: 1
> > maxItems: 255 # Should be enough
>
> OK and thanks for the comments.
>
> - Péter
>
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-18 17:06:47

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] dt-bindings: dma: ti-edma: Document dma-channel-mask for EDMA

On Tue, Sep 10, 2019 at 02:45:58PM +0300, Peter Ujfalusi wrote:
> Similarly to paRAM slots, channels can be used by other cores.
>
> The common dma-channel-mask property can be used for specifying the
> available channels.
>
> Signed-off-by: Peter Ujfalusi <[email protected]>
> ---
> Documentation/devicetree/bindings/dma/ti-edma.txt | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/dma/ti-edma.txt b/Documentation/devicetree/bindings/dma/ti-edma.txt
> index 4bbc94d829c8..3c7736246354 100644
> --- a/Documentation/devicetree/bindings/dma/ti-edma.txt
> +++ b/Documentation/devicetree/bindings/dma/ti-edma.txt
> @@ -42,6 +42,9 @@ Optional properties:
> - ti,edma-reserved-slot-ranges: PaRAM slot ranges which should not be used by
> the driver, they are allocated to be used by for example the
> DSP. See example.
> +- dma-channel-mask: Mask of usable channels, see
> + Documentation/devicetree/bindings/dma/dma-common.yaml
> +

What's the size? 2 cells?

>
> ------------------------------------------------------------------------------
> eDMA3 Transfer Controller
> @@ -91,6 +94,9 @@ edma: edma@49000000 {
> ti,edma-memcpy-channels = <20 21>;
> /* The following PaRAM slots are reserved: 35-44 and 100-109 */
> ti,edma-reserved-slot-ranges = <35 10>, <100 10>;
> + /* The following channels are reserved: 35-44 */
> + dma-channel-mask = <0xffffffff>, /* Channel 0-31 */
> + <0xffffe007>; /* Channel 32-63 */
> };
>
> edma_tptc0: tptc@49800000 {
> --
> Peter
>
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
>

2019-09-18 17:21:21

by Peter Ujfalusi

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] dt-bindings: dmaengine: dma-common: Change dma-channel-mask to uint32-array



On 18/09/2019 16.28, Rob Herring wrote:
> On Tue, Sep 10, 2019 at 02:45:57PM +0300, Peter Ujfalusi wrote:
>> Make the dma-channel-mask to be usable for controllers with more than 32
>> channels.
>>
>> Signed-off-by: Peter Ujfalusi <[email protected]>
>> ---
>> Documentation/devicetree/bindings/dma/dma-common.yaml | 10 +++++++++-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/dma/dma-common.yaml b/Documentation/devicetree/bindings/dma/dma-common.yaml
>> index ed0a49a6f020..41460946be64 100644
>> --- a/Documentation/devicetree/bindings/dma/dma-common.yaml
>> +++ b/Documentation/devicetree/bindings/dma/dma-common.yaml
>> @@ -25,11 +25,19 @@ properties:
>> Used to provide DMA controller specific information.
>>
>> dma-channel-mask:
>> - $ref: /schemas/types.yaml#definitions/uint32
>> description:
>> Bitmask of available DMA channels in ascending order that are
>> not reserved by firmware and are available to the
>> kernel. i.e. first channel corresponds to LSB.
>> + allOf:
>> + - $ref: /schemas/types.yaml#/definitions/uint32-array
>> + items:
>> + minItems = 1
>
> '='? Just making up the syntax?

Opps, sorry.

>
>> + maxItems = 255 # Should be enough
>> + - description: Mask of channels 0-31
>> + - description: Mask of channels 32-63
>
> You are mixing a schema and list here...

Should I extend the description with something like this:
"The first item in the array is for channels 0-31, the second is for
channels 32-63, etc."

To make sure that it is used in a correct and consistent manner.

>> + ...
>
> That's end of doc marker in YAML...

I believe I need some reading to do for YAML..

>
>> + - description: Mask of chnanels X-(X+31)
>
> Obviously, this was not validated with 'make dt_binding_check'.
make dt_bindings_check
make: *** No rule to make target 'dt_bindings_check'. Stop.

> What you want is:
>
> allOf:
> - $ref: /schemas/types.yaml#/definitions/uint32-array
> - minItems: 1
> maxItems: 255 # Should be enough

OK and thanks for the comments.

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-18 19:15:47

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] dt-bindings: dmaengine: dma-common: Change dma-channel-mask to uint32-array

On Tue, Sep 10, 2019 at 02:45:57PM +0300, Peter Ujfalusi wrote:
> Make the dma-channel-mask to be usable for controllers with more than 32
> channels.
>
> Signed-off-by: Peter Ujfalusi <[email protected]>
> ---
> Documentation/devicetree/bindings/dma/dma-common.yaml | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/dma/dma-common.yaml b/Documentation/devicetree/bindings/dma/dma-common.yaml
> index ed0a49a6f020..41460946be64 100644
> --- a/Documentation/devicetree/bindings/dma/dma-common.yaml
> +++ b/Documentation/devicetree/bindings/dma/dma-common.yaml
> @@ -25,11 +25,19 @@ properties:
> Used to provide DMA controller specific information.
>
> dma-channel-mask:
> - $ref: /schemas/types.yaml#definitions/uint32
> description:
> Bitmask of available DMA channels in ascending order that are
> not reserved by firmware and are available to the
> kernel. i.e. first channel corresponds to LSB.
> + allOf:
> + - $ref: /schemas/types.yaml#/definitions/uint32-array
> + items:
> + minItems = 1

'='? Just making up the syntax?

> + maxItems = 255 # Should be enough
> + - description: Mask of channels 0-31
> + - description: Mask of channels 32-63

You are mixing a schema and list here...

> + ...

That's end of doc marker in YAML...

> + - description: Mask of chnanels X-(X+31)

Obviously, this was not validated with 'make dt_binding_check'. What you
want is:

allOf:
- $ref: /schemas/types.yaml#/definitions/uint32-array
- minItems: 1
maxItems: 255 # Should be enough

Rob

2019-09-19 08:46:13

by Peter Ujfalusi

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] dt-bindings: dmaengine: dma-common: Change dma-channel-mask to uint32-array



On 18/09/2019 17.21, Rob Herring wrote:
>>>> + - description: Mask of chnanels X-(X+31)
>>>
>>> Obviously, this was not validated with 'make dt_binding_check'.
>> make dt_bindings_check
>> make: *** No rule to make target 'dt_bindings_check'. Stop.
>
> Read Documentation/devicetree/writing-schema.md (or .rst in next).
>
> Either your config doesn't have DTC enabled or you don't have
> dt-schema installed.

I have reinstalled dt-schema and added $HOME/.local/bin to PATH and now
'make dt_binding_check' is working and passing for dma-common.yaml.

For some reason it did not validate the new dma-domain.yaml from another
series, I guess it need to be added to some list?

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki