All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sui Jingfeng <suijingfeng@loongson.cn>
To: Bjorn Helgaas <helgaas@kernel.org>, Sui Jingfeng <15330273260@189.cn>
Cc: Lucas Stach <l.stach@pengutronix.de>,
	Christian Gmeiner <christian.gmeiner@gmail.com>,
	Daniel Vetter <daniel@ffwll.ch>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	etnaviv@lists.freedesktop.org
Subject: Re: [PATCH v7 7/7] drm/etnaviv: add support for the dma coherent device
Date: Wed, 7 Jun 2023 02:43:27 +0800	[thread overview]
Message-ID: <234586a0-995c-b4c4-3b7b-35afeea1a797@loongson.cn> (raw)
In-Reply-To: <20230606165624.GA1127373@bhelgaas>

Hi, I love your reviews


On 2023/6/7 00:56, Bjorn Helgaas wrote:
> On Sat, Jun 03, 2023 at 06:59:43PM +0800, Sui Jingfeng wrote:
>> From: Sui Jingfeng <suijingfeng@loongson.cn>
>>
>> Loongson CPUs maintain cache coherency by hardware, which means that the
>> data in the CPU cache is identical to the data in main system memory. As
>> for the peripheral device, most of Loongson chips chose to define the
>> peripherals as DMA coherent by default, device drivers do not need to
>> maintain the coherency between a processor and an I/O device manually.
>>
>> There are exceptions, for LS2K1000 SoC, part of peripheral device can be
>> configured as dma non-coherent. But there is no released version of such
>> firmware exist in the market. Peripherals of older ls2k1000 is also DMA
>> non-conherent, but they are nearly outdated. So, those are trivial cases.
> s/dma/DMA/
> s/non-conherent/non-coherent/
> s/ls2k1000/LS2K1000/

So sharpen eyes, as before. :-)


> I guess when you say these are "trivial cases," you mean you don't
> care about supporting those devices?

Not exactly, Its just that its kernel side thing.

the kernel side should tell us whether a peripheral device is dma 
coherent or not.


I do try to support the LSDC/GC1000 as DMA non-coherent peripheral 
device in the past,

It's no fun, Only helps to study knowledge, experiment, testing and 
comparison(with the dma coherent case).


It requires me compile the PMON firmware on myself. And flash it to the 
ROM the board.

change firmware is complex, there a lot of address windows and cross 
bar(control

a access either go the cached path or go the non cached path) setting which

only firmware engineer know about.


If there a user want ask me to do it, I will try to test this driver on 
such old chip again.

Now, I believe that the support is *already* there.

As etnaviv already works on DMA non-coherent platform originally.


The DC in Loongson Mips/LoongArch SoC can scanout from cached system RAM.

low-end application relay on CPU software rendering only.

There no need to do something like flush cache(write the data in the cache

back to system ram), invalid the cache. This is pretty convenient.


The old Ingenic SoC(jz4770 for example, mips32) also has vivante gpu 
integrated.

but  they are dma non-coherent,  see more addition material at [1].

Therefore, still need to consider the support from cross(various) 
devices perspective.


[1]  https://lkml.org/lkml/2021/5/15/177

>> Nevertheless, kernel space still need to do probe work, because vivante GPU
>> IP has been integrated into various platform. Hence, this patch add runtime
>> detection code to probe if a specific gpu is DMA coherent, If the answer is
>> yes, we are going to utilize such features. On Loongson platfform, When a
>> buffer is accesed by both the GPU and the CPU, The driver should prefer
>> ETNA_BO_CACHED over ETNA_BO_WC.
> s/gpu/GPU/
> s/platfform/platform/
> s/accesed/accessed/

OK, will be fixed at next version,

I don't find this on myself. :-(

> I guess the only way to discover this coherency attribute is via the
> DT "vivante,gc" property?  Seems a little weird but I'm really not a
> DT person.

I'm not sure it is *only*, but it is very convenient to achieve such a 
thing with DT.

Just need to put the "dma-coherent;"  or "dma-noncoherent" inside the  
"vivante,gc" node.

see of_dma_is_coherent() function.

DT is flexible. But this is just used to describe the hardware, it don't 
not changing the hardware.

Put any property only has a influence to the software or driver side. 
The hardware still as it is.

Changing hardware to a different working mode probably still need the 
firmware(uefi, uboot, pmon etc) to do it


>> This patch also add a new parameter: etnaviv_param_gpu_coherent, which
>> allow userspace to know if such a feature is available. Because
>> write-combined BO is still preferred in some case, especially where don't
>> need CPU read, for example, uploading shader bin.
>> ...
>> +static struct device_node *etnaviv_of_first_available_node(void)
>> +{
>> +	struct device_node *core_node;
>> +
>> +	for_each_compatible_node(core_node, NULL, "vivante,gc") {
>> +		if (!of_device_is_available(core_node))
>> +			continue;
>> +
>> +		return core_node;
>> +	}
>> +
>> +	return NULL;
> Seems like this would be simpler as:
>
>    for_each_compatible_node(core_node, NULL, "vivante,gc") {
>      if (of_device_is_available(core_node))
>        return core_node;
>    }
>
>    return NULL;
Indeed, I don't realize this when I create this patch.
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
>> @@ -8,6 +8,7 @@
>>   #include <linux/delay.h>
>>   #include <linux/dma-fence.h>
>>   #include <linux/dma-mapping.h>
>> +#include <linux/dma-map-ops.h>
> It looks like this #include might not be needed?

No,

the dev_is_dma_coherent() function is declared and defined in dma-map-ops.h.


if remove it, gcc will complain:


drivers/gpu/drm/etnaviv/etnaviv_drv.c: In function 
‘etnaviv_is_dma_coherent’:
drivers/gpu/drm/etnaviv/etnaviv_drv.c:56:14: error: implicit declaration 
of function ‘dev_is_dma_coherent’; did you mean 
‘etnaviv_is_dma_coherent’? [-Werror=implicit-function-declaration]
    56 |   coherent = dev_is_dma_coherent(dev);
       |              ^~~~~~~~~~~~~~~~~~~


>   You're only adding a
> new reference to priv->dma_coherent, which looks like it was added to
> etnaviv_drv.h.
>
>>   #include <linux/module.h>
>>   #include <linux/of_device.h>
>>   #include <linux/platform_device.h>
>> @@ -164,6 +165,10 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
>>   		*value = gpu->identity.eco_id;
>>   		break;
>>   
>> +	case ETNAVIV_PARAM_GPU_COHERENT:
>> +		*value = priv->dma_coherent;
>> +		break;
>> +
>>   	default:
>>   		DBG("%s: invalid param: %u", dev_name(gpu->dev), param);
>>   		return -EINVAL;
>> @@ -1861,7 +1866,7 @@ static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq)
>>   
>>   	gpu->irq = irq;
>>   
>> -	dev_info(dev, "IRQ handler registered, irq = %d\n", irq);
>> +	dev_info(dev, "irq(%d) handler registered\n", irq);
> Looks possibly unnecessary, or at least unrelated to this patch.

Indeed, catched by you again.

>>   	return 0;
>>   }

-- 
Jingfeng


WARNING: multiple messages have this Message-ID (diff)
From: Sui Jingfeng <suijingfeng@loongson.cn>
To: Bjorn Helgaas <helgaas@kernel.org>, Sui Jingfeng <15330273260@189.cn>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	etnaviv@lists.freedesktop.org,
	Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [PATCH v7 7/7] drm/etnaviv: add support for the dma coherent device
Date: Wed, 7 Jun 2023 02:43:27 +0800	[thread overview]
Message-ID: <234586a0-995c-b4c4-3b7b-35afeea1a797@loongson.cn> (raw)
In-Reply-To: <20230606165624.GA1127373@bhelgaas>

Hi, I love your reviews


On 2023/6/7 00:56, Bjorn Helgaas wrote:
> On Sat, Jun 03, 2023 at 06:59:43PM +0800, Sui Jingfeng wrote:
>> From: Sui Jingfeng <suijingfeng@loongson.cn>
>>
>> Loongson CPUs maintain cache coherency by hardware, which means that the
>> data in the CPU cache is identical to the data in main system memory. As
>> for the peripheral device, most of Loongson chips chose to define the
>> peripherals as DMA coherent by default, device drivers do not need to
>> maintain the coherency between a processor and an I/O device manually.
>>
>> There are exceptions, for LS2K1000 SoC, part of peripheral device can be
>> configured as dma non-coherent. But there is no released version of such
>> firmware exist in the market. Peripherals of older ls2k1000 is also DMA
>> non-conherent, but they are nearly outdated. So, those are trivial cases.
> s/dma/DMA/
> s/non-conherent/non-coherent/
> s/ls2k1000/LS2K1000/

So sharpen eyes, as before. :-)


> I guess when you say these are "trivial cases," you mean you don't
> care about supporting those devices?

Not exactly, Its just that its kernel side thing.

the kernel side should tell us whether a peripheral device is dma 
coherent or not.


I do try to support the LSDC/GC1000 as DMA non-coherent peripheral 
device in the past,

It's no fun, Only helps to study knowledge, experiment, testing and 
comparison(with the dma coherent case).


It requires me compile the PMON firmware on myself. And flash it to the 
ROM the board.

change firmware is complex, there a lot of address windows and cross 
bar(control

a access either go the cached path or go the non cached path) setting which

only firmware engineer know about.


If there a user want ask me to do it, I will try to test this driver on 
such old chip again.

Now, I believe that the support is *already* there.

As etnaviv already works on DMA non-coherent platform originally.


The DC in Loongson Mips/LoongArch SoC can scanout from cached system RAM.

low-end application relay on CPU software rendering only.

There no need to do something like flush cache(write the data in the cache

back to system ram), invalid the cache. This is pretty convenient.


The old Ingenic SoC(jz4770 for example, mips32) also has vivante gpu 
integrated.

but  they are dma non-coherent,  see more addition material at [1].

Therefore, still need to consider the support from cross(various) 
devices perspective.


[1]  https://lkml.org/lkml/2021/5/15/177

>> Nevertheless, kernel space still need to do probe work, because vivante GPU
>> IP has been integrated into various platform. Hence, this patch add runtime
>> detection code to probe if a specific gpu is DMA coherent, If the answer is
>> yes, we are going to utilize such features. On Loongson platfform, When a
>> buffer is accesed by both the GPU and the CPU, The driver should prefer
>> ETNA_BO_CACHED over ETNA_BO_WC.
> s/gpu/GPU/
> s/platfform/platform/
> s/accesed/accessed/

OK, will be fixed at next version,

I don't find this on myself. :-(

> I guess the only way to discover this coherency attribute is via the
> DT "vivante,gc" property?  Seems a little weird but I'm really not a
> DT person.

I'm not sure it is *only*, but it is very convenient to achieve such a 
thing with DT.

Just need to put the "dma-coherent;"  or "dma-noncoherent" inside the  
"vivante,gc" node.

see of_dma_is_coherent() function.

DT is flexible. But this is just used to describe the hardware, it don't 
not changing the hardware.

Put any property only has a influence to the software or driver side. 
The hardware still as it is.

Changing hardware to a different working mode probably still need the 
firmware(uefi, uboot, pmon etc) to do it


>> This patch also add a new parameter: etnaviv_param_gpu_coherent, which
>> allow userspace to know if such a feature is available. Because
>> write-combined BO is still preferred in some case, especially where don't
>> need CPU read, for example, uploading shader bin.
>> ...
>> +static struct device_node *etnaviv_of_first_available_node(void)
>> +{
>> +	struct device_node *core_node;
>> +
>> +	for_each_compatible_node(core_node, NULL, "vivante,gc") {
>> +		if (!of_device_is_available(core_node))
>> +			continue;
>> +
>> +		return core_node;
>> +	}
>> +
>> +	return NULL;
> Seems like this would be simpler as:
>
>    for_each_compatible_node(core_node, NULL, "vivante,gc") {
>      if (of_device_is_available(core_node))
>        return core_node;
>    }
>
>    return NULL;
Indeed, I don't realize this when I create this patch.
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
>> @@ -8,6 +8,7 @@
>>   #include <linux/delay.h>
>>   #include <linux/dma-fence.h>
>>   #include <linux/dma-mapping.h>
>> +#include <linux/dma-map-ops.h>
> It looks like this #include might not be needed?

No,

the dev_is_dma_coherent() function is declared and defined in dma-map-ops.h.


if remove it, gcc will complain:


drivers/gpu/drm/etnaviv/etnaviv_drv.c: In function 
‘etnaviv_is_dma_coherent’:
drivers/gpu/drm/etnaviv/etnaviv_drv.c:56:14: error: implicit declaration 
of function ‘dev_is_dma_coherent’; did you mean 
‘etnaviv_is_dma_coherent’? [-Werror=implicit-function-declaration]
    56 |   coherent = dev_is_dma_coherent(dev);
       |              ^~~~~~~~~~~~~~~~~~~


>   You're only adding a
> new reference to priv->dma_coherent, which looks like it was added to
> etnaviv_drv.h.
>
>>   #include <linux/module.h>
>>   #include <linux/of_device.h>
>>   #include <linux/platform_device.h>
>> @@ -164,6 +165,10 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
>>   		*value = gpu->identity.eco_id;
>>   		break;
>>   
>> +	case ETNAVIV_PARAM_GPU_COHERENT:
>> +		*value = priv->dma_coherent;
>> +		break;
>> +
>>   	default:
>>   		DBG("%s: invalid param: %u", dev_name(gpu->dev), param);
>>   		return -EINVAL;
>> @@ -1861,7 +1866,7 @@ static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq)
>>   
>>   	gpu->irq = irq;
>>   
>> -	dev_info(dev, "IRQ handler registered, irq = %d\n", irq);
>> +	dev_info(dev, "irq(%d) handler registered\n", irq);
> Looks possibly unnecessary, or at least unrelated to this patch.

Indeed, catched by you again.

>>   	return 0;
>>   }

-- 
Jingfeng


  reply	other threads:[~2023-06-06 18:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-03 10:59 [PATCH v7 0/7] drm/etnaviv: add pci device driver support Sui Jingfeng
2023-06-03 10:59 ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 1/7] drm/etnaviv: add a dedicated function to register an irq handler Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 2/7] drm/etnaviv: add a dedicated function to get various clocks Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 3/7] drm/etnaviv: add dedicated functions to create and destroy platform devices Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 4/7] drm/etnaviv: add helpers for private data construction and destruction Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 5/7] drm/etnaviv: allow bypass component framework Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 6/7] drm/etnaviv: add driver support for the PCI devices Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-03 10:59 ` [PATCH v7 7/7] drm/etnaviv: add support for the dma coherent device Sui Jingfeng
2023-06-03 10:59   ` Sui Jingfeng
2023-06-06 16:56   ` Bjorn Helgaas
2023-06-06 16:56     ` Bjorn Helgaas
2023-06-06 18:43     ` Sui Jingfeng [this message]
2023-06-06 18:43       ` Sui Jingfeng
2023-06-06 19:01       ` Bjorn Helgaas
2023-06-06 19:01         ` Bjorn Helgaas
2023-06-03 11:20 ` [PATCH v7 0/7] drm/etnaviv: add pci device driver support Sui Jingfeng
2023-06-03 11:20   ` Sui Jingfeng

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=234586a0-995c-b4c4-3b7b-35afeea1a797@loongson.cn \
    --to=suijingfeng@loongson.cn \
    --cc=15330273260@189.cn \
    --cc=bhelgaas@google.com \
    --cc=christian.gmeiner@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=helgaas@kernel.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux-kernel@vger.kernel.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 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.