dmaengine: qcom_hidma: add MSI interrupt support
Subsystems (5)
v3 cover dmaengine: qcom_hidma: add MSI interrupt support
The new version of the HW supports MSI interrupts instead of wired interrupts. The MSI interrupts are especially useful for the guest machine execution. The wired interrupts usually trap to the hypervisor and then are relayed to the actual interrupt.
The MSI interrupts can be directly fed into the interrupt controller.
Adding a new OF compat string (qcom,hidma-1.1) and ACPI string (QCOM8062) to distinguish newer HW from the older ones.
v3:
* day 0 fix for when ACPI is not compiled in
v2:
https://patchwork.kernel.org/patch/9326399/
* Documentation update for DT bindings
* Rebased to slave-next
* Dropped dmaengine: qcom_hidma: eliminate processed variables. Replaced it with dmaengine: qcom_hidma: protect common data structures
v1:
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/444167.html
* initial implementation
Sinan Kaya (10):
Documentation: DT: qcom_hidma: update binding for MSI
Documentation: DT: qcom_hidma: correct spelling mistakes
of: irq: make of_msi_configure accessible from modules
dmaengine: qcom_hidma: configure DMA and MSI for OF
dmaengine: qcom_hidma: make pending_tre_count atomic
dmaengine: qcom_hidma: make error and success path common
dmaengine: qcom_hidma: bring out interrupt cause
dmaengine: qcom_hidma: add a common API to setup the interrupt
dmaengine: qcom_hidma: protect common data structures
dmaengine: qcom_hidma: add MSI support for interrupts
.../devicetree/bindings/dma/qcom_hidma_mgmt.txt | 17 +- drivers/dma/qcom/hidma.c | 129 +++++++++- drivers/dma/qcom/hidma.h | 6 +- drivers/dma/qcom/hidma_dbg.c | 3 +- drivers/dma/qcom/hidma_ll.c | 278 ++++++++++----------- drivers/dma/qcom/hidma_mgmt.c | 5 +- drivers/of/irq.c | 1 + 7 files changed, 280 insertions(+), 159 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/10 Documentation: DT: qcom_hidma: update binding for MSI
Adding a new binding for qcom,hidma-1.1 to distinguish HW supporting MSI interrupts from the older revision.
--- Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +12 -1
@@ -47,12 +47,23 @@ When the OS is not in control of the management interface (i.e. it's a guest), the channel nodes appear on their own, not under a management node. Required properties: -- compatible: must contain "qcom,hidma-1.0" +- compatible: must contain "qcom,hidma-1.0" for initial HW or "qcom,hidma-1.1" +for MSI capable HW. - reg: Addresses for the transfer and event channel - interrupts: Should contain the event interrupt - desc-count: Number of asynchronous requests this channel can handle - iommus: required a iommu node +Optional properties for MSI: +- msi-parent: pointer to the MSI controller object with the DeviceID in use. + +Example: + msi_parent: <&msi0 0x80024> + +msi0 is the MSI controller in the system. Bits 0-5 is the channel ID. 4 +is the channel ID. Bits 5-8 is the instance number. This is for the HIDMA +instance 1. + Example: Hypervisor OS configuration:
Signature · 1 line
1.9.1
Rob Herring
maintainerRe: [PATCH V3 01/10] Documentation: DT: qcom_hidma: update binding for MSI
Quoted 13 lines · Sinan Kaya
Adding a new binding for qcom,hidma-1.1 to distinguish HW supporting MSI interrupts from the older revision.
Signed-off-by Sinan Kaya <[email protected]>--- Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +0
-0
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 51
Quoted 6 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +2
-1@@ -47,12 +47,23 @@ When the OS is not in control of the management interface (i.e. it's a guest), the channel nodes appear on their own, not under a management node. Required properties: -- compatible: must contain "qcom,hidma-1.0" +- compatible: must contain "qcom,hidma-1.0" for initial HW or "qcom,hidma-1.1" +for MSI capable HW.
Do you have an SoC part number yet? If so, please use that instead.
Quoted 21 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +10
-0- reg: Addresses for the transfer and event channel - interrupts: Should contain the event interrupt - desc-count: Number of asynchronous requests this channel can handle - iommus: required a iommu node +Optional properties for MSI: +- msi-parent: pointer to the MSI controller object with the DeviceID in use. + +Example: + msi_parent: <&msi0 0x80024> + +msi0 is the MSI controller in the system. Bits 0-5 is the channel ID. 4 +is the channel ID. Bits 5-8 is the instance number. This is for the HIDMA +instance 1. + Example: Hypervisor OS configuration:Signature · 1 line
1.9.1
Re: [PATCH V3 01/10] Documentation: DT: qcom_hidma: update binding for MSI
Quoted 6 lines · Rob Herring
Quoted 4 lines
Required properties:
Quoted 3 lines
-- compatible: must contain "qcom,hidma-1.0"
+- compatible: must contain "qcom,hidma-1.0" for initial HW or "qcom,hidma-1.1" +for MSI capable HW.Do you have an SoC part number yet? If so, please use that instead.
Unfortunately, I have the same problem like "qcom, hidma-1.0". The SoC name is not settled yet and same IP gets used in multiple SoCs. Each IP reports its own version number. This is one of the reasons why I sticked to versioning instead of SoC name.
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH V3 01/10] Documentation: DT: qcom_hidma: update binding for MSI
In reply to Sinan KayaQuoted 16 lines · Sinan Kaya
Adding a new binding for qcom,hidma-1.1 to distinguish HW supporting MSI interrupts from the older revision.
Signed-off-by Sinan Kaya <[email protected]>--- Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +0
-0@@ -47,12 +47,23 @@ When the OS is not in control of the management interface (i.e. it's a guest), the channel nodes appear on their own, not under a management node. Required properties:
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 58
Quoted 10 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +4
-1-- compatible: must contain "qcom,hidma-1.0" +- compatible: must contain "qcom,hidma-1.0" for initial HW or "qcom,hidma-1.1" +for MSI capable HW. - reg: Addresses for the transfer and event channel - interrupts: Should contain the event interrupt - desc-count: Number of asynchronous requests this channel can handle - iommus: required a iommu node +Optional properties for MSI: +- msi-parent: pointer to the MSI controller object with the DeviceID in use.
The format of msi-cells depends on the particular msi-controller, so no need to mention DeviceID here.
Please refer to Documentation/devicetree/bindings/interrupt-controller/msi.txt
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 61
Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +2
-0+Example: + msi_parent: <&msi0 0x80024>
This doesn't match (s/_/-/).
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 65
Quoted 3 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +3
-0+msi0 is the MSI controller in the system. Bits 0-5 is the channel ID. 4 +is the channel ID. Bits 5-8 is the instance number. This is for the HIDMA +instance 1.
I don't think you need any of this text, so long as you refer to the generic MSI binding document, as above.
Thanks,
Mark.
Re: [PATCH V3 01/10] Documentation: DT: qcom_hidma: update binding for MSI
Quoted 25 lines · Mark Rutland
Quoted 24 lines · Sinan Kaya
Adding a new binding for qcom,hidma-1.1 to distinguish HW supporting MSI interrupts from the older revision.
Signed-off-by Sinan Kaya <[email protected]>--- Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +2
-1@@ -47,12 +47,23 @@ When the OS is not in control of the management interface (i.e. it's a guest), the channel nodes appear on their own, not under a management node. Required properties: -- compatible: must contain "qcom,hidma-1.0" +- compatible: must contain "qcom,hidma-1.0" for initial HW or "qcom,hidma-1.1" +for MSI capable HW. - reg: Addresses for the transfer and event channel - interrupts: Should contain the event interrupt - desc-count: Number of asynchronous requests this channel can handle - iommus: required a iommu node
Quoted 8 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 58
Quoted 2 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +2
-0+Optional properties for MSI: +- msi-parent: pointer to the MSI controller object with the DeviceID in use.The format of msi-cells depends on the particular msi-controller, so no need to mention DeviceID here.
Please refer to
Documentation/devicetree/bindings/interrupt-controller/msi.txt
Thanks, let me do some more research.
Quoted 5 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 61
Quoted 3 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +2
-0+Example: + msi_parent: <&msi0 0x80024>This doesn't match (s/_/-/).
ok
Quoted 7 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt When the OS is not in control of the management interface (i.e. it's a guest), · line 65
Quoted 4 lines
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +3
-0+msi0 is the MSI controller in the system. Bits 0-5 is the channel ID. 4 +is the channel ID. Bits 5-8 is the instance number. This is for the HIDMA +instance 1.I don't think you need any of this text, so long as you refer to the generic MSI binding document, as above.
ok
Quoted 4 lines
Thanks,
Mark.
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v3 2/10 Documentation: DT: qcom_hidma: correct spelling mistakes
In reply to Sinan KayaFix the spelling mistakes and extra and statements in the sentences.
--- Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/dma/qcom_hidma_mgmt.txt +2 -2
@@ -5,13 +5,13 @@ memcpy and memset capabilities. It has been designed for virtualized environments. Each HIDMA HW instance consists of multiple DMA channels. These channels -share the same bandwidth. The bandwidth utilization can be parititioned +share the same bandwidth. The bandwidth utilization can be partitioned among channels based on the priority and weight assignments. There are only two priority levels and 15 weigh assignments possible. Other parameters here determine how much of the system bus this HIDMA -instance can use like maximum read/write request and and number of bytes to +instance can use like maximum read/write request and number of bytes to read/write in a single burst. Main node required properties:
Signature · 1 line
1.9.1
PATCH v3 3/10 of: irq: make of_msi_configure accessible from modules
In reply to Sinan KayaThe of_msi_configure routine is only accessible by the built-in kernel drivers. Export this function so that modules can use it too.
This function is useful for configuring MSI on child device tree nodes on hierarchical objects.
--- drivers/of/irq.c | 1 + 1 file changed, 1 insertion(+)
drivers/of/irq.c +1 -0
@@ -767,3 +767,4 @@ void of_msi_configure(struct device *dev, struct device_node *np)dev_set_msi_domain (dev,of_msi_get_domain (dev, np,DOMAIN_BUS_PLATFORM_MSI )); } +EXPORT_SYMBOL_GPL (of_msi_configure);
Signature · 1 line
1.9.1
PATCH v3 4/10 dmaengine: qcom_hidma: configure DMA and MSI for OF
In reply to Sinan KayaConfigure the DMA bindings for the device tree based firmware.
--- drivers/dma/qcom/hidma_mgmt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/dma/qcom/hidma_mgmt.c +4 -1
@@ -375,8 +375,11 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np) ret =PTR_ERR (new_pdev); goto out; } +of_node_get (child); + new_pdev->dev.of_node = child;of_dma_configure (&new_pdev->dev, child); - +of_msi_configure (&new_pdev->dev, child); +of_node_put (child);kfree (res); res =NULL ; }
Signature · 1 line
1.9.1
PATCH v3 5/10 dmaengine: qcom_hidma: make pending_tre_count atomic
In reply to Sinan KayaGetting ready for the MSI interrupts. The pending_tre_count is used in the interrupt handler to make sure all outstanding requests are serviced.
Making it atomic so that it can be updated from multiple contexts.
--- drivers/dma/qcom/hidma.h | 2 +- drivers/dma/qcom/hidma_dbg.c | 3 ++- drivers/dma/qcom/hidma_ll.c | 13 ++++++------- 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/dma/qcom/hidma.h +1 -1
@@ -58,7 +58,7 @@ struct hidma_lldev {void __iomem *evca;/* Event Channel address */ struct hidma_tre **pending_tre_list;/* Pointers to pending TREs */ -s32 pending_tre_count;/* Number of TREs pending */ +atomic_t pending_tre_count;/* Number of TREs pending */ void *tre_ring;/* TRE ring */ dma_addr_t tre_dma;/* TRE ring to be shared with HW */
drivers/dma/qcom/hidma_dbg.c +2 -1
@@ -74,7 +74,8 @@ static void hidma_ll_devstats(struct seq_file *s, void *llhndl)seq_printf (s,"tre_ring_handle=%pap\n" , &lldev->tre_dma);seq_printf (s,"tre_ring_size = 0x%x\n" , lldev->tre_ring_size);seq_printf (s,"tre_processed_off = 0x%x\n" , lldev->tre_processed_off); -seq_printf (s,"pending_tre_count=%d\n" , lldev->pending_tre_count); +seq_printf (s,"pending_tre_count=%d\n" , +atomic_read (&lldev->pending_tre_count));seq_printf (s,"evca=%p\n" , lldev->evca);seq_printf (s,"evre_ring=%p\n" , lldev->evre_ring);seq_printf (s,"evre_ring_handle=%pap\n" , &lldev->evre_dma);
drivers/dma/qcom/hidma_ll.c +6 -7
@@ -218,10 +218,9 @@ static int hidma_post_completed(struct hidma_lldev *lldev, int tre_iterator,* Keep track of pending TREs that SW is expecting to receive * from HW. We got one now. Decrement our counter. */ - lldev->pending_tre_count--; -if (lldev->pending_tre_count <0 ) { +if (atomic_dec_return (&lldev->pending_tre_count) <0 ) {dev_warn (lldev->dev,"tre count mismatch on completion" ); - lldev->pending_tre_count =0 ; +atomic_set (&lldev->pending_tre_count,0 ); }spin_unlock_irqrestore (&lldev->lock, flags);
@@ -321,7 +320,7 @@ void hidma_cleanup_pending_tre(struct hidma_lldev *lldev, u8 err_info,u32 tre_read_off; tre_iterator = lldev->tre_processed_off; -while (lldev->pending_tre_count) { +while (atomic_read (&lldev->pending_tre_count)) {if (hidma_post_completed (lldev, tre_iterator, err_info, err_code))break ;
@@ -548,7 +547,7 @@ void hidma_ll_queue_request(struct hidma_lldev *lldev, u32 tre_ch) tre->err_code =0 ; tre->err_info =0 ; tre->queued =1 ; - lldev->pending_tre_count++; +atomic_inc (&lldev->pending_tre_count); lldev->tre_write_offset = (lldev->tre_write_offset +HIDMA_TRE_SIZE ) % lldev->tre_ring_size;spin_unlock_irqrestore (&lldev->lock, flags);
@@ -654,7 +653,7 @@ int hidma_ll_setup(struct hidma_lldev *lldev)u32 val;u32 nr_tres = lldev->nr_tres; - lldev->pending_tre_count =0 ; +atomic_set (&lldev->pending_tre_count,0 ); lldev->tre_processed_off =0 ; lldev->evre_processed_off =0 ; lldev->tre_write_offset =0 ;
@@ -816,7 +815,7 @@ int hidma_ll_uninit(struct hidma_lldev *lldev)tasklet_kill (&lldev->task);memset (lldev->trepool,0 , required_bytes); lldev->trepool =NULL ; - lldev->pending_tre_count =0 ; +atomic_set (&lldev->pending_tre_count,0 ); lldev->tre_write_offset =0 ; rc =hidma_ll_reset (lldev);
Signature · 1 line
1.9.1
PATCH v3 6/10 dmaengine: qcom_hidma: make error and success path common
In reply to Sinan KayaRemove code duplication by feeding the error code from outside into successful data transfer handler.
--- drivers/dma/qcom/hidma_ll.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
drivers/dma/qcom/hidma_ll.c +10 -24
@@ -241,11 +241,11 @@ static int hidma_post_completed(struct hidma_lldev *lldev, int tre_iterator,* Return a positive number if there are pending TREs or EVREs. * Return 0 if there is nothing to consume or no pending TREs/EVREs found. */ -static int hidma_handle_tre_completion (struct hidma_lldev *lldev) +static int hidma_handle_tre_completion (struct hidma_lldev *lldev,u8 err_info, +u8 err_code) {u32 evre_ring_size = lldev->evre_ring_size;u32 tre_ring_size = lldev->tre_ring_size; -u32 err_info, err_code, evre_write_off;u32 tre_iterator, evre_iterator;u32 num_completed =0 ;
@@ -268,10 +268,13 @@ static int hidma_handle_tre_completion(struct hidma_lldev *lldev)u32 cfg; cfg = current_evre[HIDMA_EVRE_CFG_IDX ]; - err_info = cfg >>HIDMA_EVRE_ERRINFO_BIT_POS ; - err_info &=HIDMA_EVRE_ERRINFO_MASK ; - err_code = - (cfg >>HIDMA_EVRE_CODE_BIT_POS ) &HIDMA_EVRE_CODE_MASK ; +if (!err_info) { + err_info = cfg >>HIDMA_EVRE_ERRINFO_BIT_POS ; + err_info &=HIDMA_EVRE_ERRINFO_MASK ; + } +if (!err_code) + err_code = (cfg >>HIDMA_EVRE_CODE_BIT_POS ) & +HIDMA_EVRE_CODE_MASK ;if (hidma_post_completed (lldev, tre_iterator, err_info, err_code))
@@ -314,27 +317,10 @@ static int hidma_handle_tre_completion(struct hidma_lldev *lldev)void hidma_cleanup_pending_tre (struct hidma_lldev *lldev,u8 err_info,u8 err_code) { -u32 tre_iterator; -u32 tre_ring_size = lldev->tre_ring_size; -int num_completed =0 ; -u32 tre_read_off; - - tre_iterator = lldev->tre_processed_off;while (atomic_read (&lldev->pending_tre_count)) { -if (hidma_post_completed (lldev, tre_iterator, err_info, - err_code)) +if (hidma_handle_tre_completion (lldev, err_info, err_code))break ; -HIDMA_INCREMENT_ITERATOR (tre_iterator,HIDMA_TRE_SIZE , - tre_ring_size); - num_completed++; } - tre_read_off = (lldev->tre_processed_off + -HIDMA_TRE_SIZE * num_completed); - - tre_read_off = tre_read_off % tre_ring_size; - -/* record the last processed tre offset */ - lldev->tre_processed_off = tre_read_off; }static int hidma_ll_reset (struct hidma_lldev *lldev)
Signature · 1 line
1.9.1
PATCH v3 7/10 dmaengine: qcom_hidma: bring out interrupt cause
In reply to Sinan KayaBring out the interrupt cause to the top level so that MSI interrupts can be hooked at a later stage.
--- drivers/dma/qcom/hidma_ll.c | 72 +++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 38 deletions(-)
drivers/dma/qcom/hidma_ll.c +34 -38
@@ -397,12 +397,24 @@ static int hidma_ll_reset(struct hidma_lldev *lldev)* requests traditionally to the destination, this concept does not apply * here for this HW. */ -irqreturn_t hidma_ll_inthandler (int chirq,void *arg) +static void hidma_ll_int_handler_internal (struct hidma_lldev *lldev,int cause) { -struct hidma_lldev *lldev = arg; -u32 status; -u32 enable; -u32 cause; +if (cause &HIDMA_ERR_INT_MASK ) { +dev_err (lldev->dev,"error 0x%x, disabling...\n" , + cause); + +/* Clear out pending interrupts */ +writel (cause, lldev->evca +HIDMA_EVCA_IRQ_CLR_REG ); + +/* No further submissions. */ +hidma_ll_disable (lldev); + +/* Driver completes the txn and intimates the client.*/ +hidma_cleanup_pending_tre (lldev,0xFF , +HIDMA_EVRE_STATUS_ERROR ); + +return ; + }/* * Fine tuned for this HW...
@@ -412,45 +424,29 @@ irqreturn_t hidma_ll_inthandler(int chirq, void *arg)* interrupt delivery guarantees. Do not copy this code blindly and * expect that to work. */ - status =readl_relaxed (lldev->evca +HIDMA_EVCA_IRQ_STAT_REG ); - enable =readl_relaxed (lldev->evca +HIDMA_EVCA_IRQ_EN_REG ); - cause = status & enable; - -while (cause) { -if (cause &HIDMA_ERR_INT_MASK ) { -dev_err (lldev->dev,"error 0x%x, disabling...\n" , - cause); - -/* Clear out pending interrupts */ -writel (cause, lldev->evca +HIDMA_EVCA_IRQ_CLR_REG ); - -/* No further submissions. */ -hidma_ll_disable (lldev); - -/* Driver completes the txn and intimates the client.*/ -hidma_cleanup_pending_tre (lldev,0xFF , -HIDMA_EVRE_STATUS_ERROR ); - goto out; - } - +while (atomic_read (&lldev->pending_tre_count)) {/* * Try to consume as many EVREs as possible. */ -hidma_handle_tre_completion (lldev); +if (hidma_handle_tre_completion (lldev,0 ,0 )) +break ; + } -/* We consumed TREs or there are pending TREs or EVREs. */ -writel_relaxed (cause, lldev->evca +HIDMA_EVCA_IRQ_CLR_REG ); +/* We consumed TREs or there are pending TREs or EVREs. */ +writel_relaxed (cause, lldev->evca +HIDMA_EVCA_IRQ_CLR_REG ); +} -/* -* Another interrupt might have arrived while we are -* processing this one. Read the new cause. -*/ - status =readl_relaxed (lldev->evca +HIDMA_EVCA_IRQ_STAT_REG ); - enable =readl_relaxed (lldev->evca +HIDMA_EVCA_IRQ_EN_REG ); - cause = status & enable; - } +irqreturn_t hidma_ll_inthandler (int chirq,void *arg) +{ +struct hidma_lldev *lldev = arg; +u32 status; +u32 enable; +u32 cause; -out: + status =readl_relaxed (lldev->evca +HIDMA_EVCA_IRQ_STAT_REG ); + enable =readl_relaxed (lldev->evca +HIDMA_EVCA_IRQ_EN_REG ); + cause = status & enable; +hidma_ll_int_handler_internal (lldev, cause);return IRQ_HANDLED ; }
Signature · 1 line
1.9.1
PATCH v3 8/10 dmaengine: qcom_hidma: add a common API to setup the interrupt
In reply to Sinan KayaIntroducing the hidma_ll_setup_irq function to set up the interrupt type externally from the OS interface.
--- drivers/dma/qcom/hidma.h | 2 ++ drivers/dma/qcom/hidma_ll.c | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-)
drivers/dma/qcom/hidma.h +2 -0
@@ -46,6 +46,7 @@ struct hidma_tre { };struct hidma_lldev { +bool msi_support;/* flag indicating MSI support */ bool initialized;/* initialized flag */ u8 trch_state;/* trch_state of the device */ u8 evch_state;/* evch_state of the device */
@@ -145,6 +146,7 @@ int hidma_ll_disable(struct hidma_lldev *lldev);int hidma_ll_enable (struct hidma_lldev *llhndl);void hidma_ll_set_transfer_params (struct hidma_lldev *llhndl,u32 tre_ch,dma_addr_t src,dma_addr_t dest,u32 len,u32 flags); +void hidma_ll_setup_irq (struct hidma_lldev *lldev,bool msi);int hidma_ll_setup (struct hidma_lldev *lldev); struct hidma_lldev *hidma_ll_init(struct device *dev, u32 max_channels, void __iomem *trca, void __iomem *evca,
drivers/dma/qcom/hidma_ll.c +23 -4
@@ -672,17 +672,36 @@ int hidma_ll_setup(struct hidma_lldev *lldev)writel (HIDMA_EVRE_SIZE * nr_tres, lldev->evca +HIDMA_EVCA_RING_LEN_REG ); -/* support IRQ only for now */ +/* configure interrupts */ +hidma_ll_setup_irq (lldev, lldev->msi_support); + + rc =hidma_ll_enable (lldev); +if (rc) +return rc; + +return rc; +} + +void hidma_ll_setup_irq (struct hidma_lldev *lldev,bool msi) +{ +u32 val; + + lldev->msi_support = msi; + +/* disable interrupts again after reset */ +writel (0 , lldev->evca +HIDMA_EVCA_IRQ_CLR_REG ); +writel (0 , lldev->evca +HIDMA_EVCA_IRQ_EN_REG ); + +/* support IRQ by default */ val =readl (lldev->evca +HIDMA_EVCA_INTCTRL_REG ); val &= ~0xF ; - val |=0x1 ; +if (!lldev->msi_support) + val = val |0x1 ;writel (val, lldev->evca +HIDMA_EVCA_INTCTRL_REG );/* clear all pending interrupts and enable them */ writel (ENABLE_IRQS , lldev->evca +HIDMA_EVCA_IRQ_CLR_REG );writel (ENABLE_IRQS , lldev->evca +HIDMA_EVCA_IRQ_EN_REG ); - -return hidma_ll_enable (lldev); } struct hidma_lldev *hidma_ll_init(struct device *dev, u32 nr_tres,
Signature · 1 line
1.9.1
PATCH v3 9/10 dmaengine: qcom_hidma: protect common data structures
In reply to Sinan KayaWhen MSI interrupts are supported, error and the transfer interrupt can come from multiple processor contexts.
Each error interrupt is an MSI interrupt. If the channel is disabled by the first error interrupt, the remaining error interrupts will gracefully return in the interrupt handler.
If an error is observed while servicing the completions in success case, the posting of the completions will be aborted as soon as channel disabled state is observed. The error interrupt handler will take it from there and finish the remaining completions. We don't want to create multiple success and error messages to be delivered to the client in mixed order.
Also got rid of hidma_post_completed method and moved the locks inside hidma_ll_int_handler_internal function. Rearranged the assignments so that variables are updated only when a lock is held.
--- drivers/dma/qcom/hidma_ll.c | 142 ++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 84 deletions(-)
drivers/dma/qcom/hidma_ll.c +58 -84
@@ -198,18 +198,50 @@ static void hidma_ll_tre_complete(unsigned long arg) } } -static int hidma_post_completed (struct hidma_lldev *lldev,int tre_iterator, -u8 err_info,u8 err_code) +/* +* Called to handle the interrupt for the channel. +* Return a positive number if TRE or EVRE were consumed on this run. +* Return a positive number if there are pending TREs or EVREs. +* Return 0 if there is nothing to consume or no pending TREs/EVREs found. +*/ +static int hidma_handle_tre_completion (struct hidma_lldev *lldev,u8 err_info, +u8 err_code) { +u32 *current_evre;struct hidma_tre *tre;unsigned long flags; +u32 evre_write_off; +u32 cfg; +u32 offset; + + evre_write_off =readl_relaxed (lldev->evca +HIDMA_EVCA_WRITE_PTR_REG ); +if ((evre_write_off > lldev->evre_ring_size) || + (evre_write_off %HIDMA_EVRE_SIZE )) { +dev_err (lldev->dev,"HW reports invalid EVRE write offset\n" ); +return -EINVAL ; + }spin_lock_irqsave (&lldev->lock, flags); - tre = lldev->pending_tre_list[tre_iterator /HIDMA_TRE_SIZE ]; +if (lldev->evre_processed_off == evre_write_off) { +spin_unlock_irqrestore (&lldev->lock, flags); +return 0 ; + } + current_evre = lldev->evre_ring + lldev->evre_processed_off; + cfg = current_evre[HIDMA_EVRE_CFG_IDX ]; +if (!err_info) { + err_info = cfg >>HIDMA_EVRE_ERRINFO_BIT_POS ; + err_info &=HIDMA_EVRE_ERRINFO_MASK ; + } +if (!err_code) + err_code = (cfg >>HIDMA_EVRE_CODE_BIT_POS ) & +HIDMA_EVRE_CODE_MASK ; + + offset = lldev->tre_processed_off; + tre = lldev->pending_tre_list[offset /HIDMA_TRE_SIZE ];if (!tre) {spin_unlock_irqrestore (&lldev->lock, flags);dev_warn (lldev->dev,"tre_index [%d] and tre out of sync\n" , - tre_iterator /HIDMA_TRE_SIZE ); + lldev->tre_processed_off /HIDMA_TRE_SIZE );return -EINVAL ; } lldev->pending_tre_list[tre->tre_index] =NULL ;
@@ -223,6 +255,14 @@ static int hidma_post_completed(struct hidma_lldev *lldev, int tre_iterator,atomic_set (&lldev->pending_tre_count,0 ); } + +HIDMA_INCREMENT_ITERATOR (lldev->tre_processed_off,HIDMA_TRE_SIZE , + lldev->tre_ring_size); +HIDMA_INCREMENT_ITERATOR (lldev->evre_processed_off,HIDMA_EVRE_SIZE , + lldev->evre_ring_size); + +writel (lldev->evre_processed_off, + lldev->evca +HIDMA_EVCA_DOORBELL_REG );spin_unlock_irqrestore (&lldev->lock, flags); tre->err_info = err_info;
@@ -232,86 +272,7 @@ static int hidma_post_completed(struct hidma_lldev *lldev, int tre_iterator,kfifo_put (&lldev->handoff_fifo, tre);tasklet_schedule (&lldev->task); -return 0 ; -} - -/* -* Called to handle the interrupt for the channel. -* Return a positive number if TRE or EVRE were consumed on this run. -* Return a positive number if there are pending TREs or EVREs. -* Return 0 if there is nothing to consume or no pending TREs/EVREs found. -*/ -static int hidma_handle_tre_completion (struct hidma_lldev *lldev,u8 err_info, -u8 err_code) -{ -u32 evre_ring_size = lldev->evre_ring_size; -u32 tre_ring_size = lldev->tre_ring_size; -u32 tre_iterator, evre_iterator; -u32 num_completed =0 ; - - evre_write_off =readl_relaxed (lldev->evca +HIDMA_EVCA_WRITE_PTR_REG ); - tre_iterator = lldev->tre_processed_off; - evre_iterator = lldev->evre_processed_off; - -if ((evre_write_off > evre_ring_size) || - (evre_write_off %HIDMA_EVRE_SIZE )) { -dev_err (lldev->dev,"HW reports invalid EVRE write offset\n" ); -return 0 ; - } - -/* -* By the time control reaches here the number of EVREs and TREs -* may not match. Only consume the ones that hardware told us. -*/ -while ((evre_iterator != evre_write_off)) { -u32 *current_evre = lldev->evre_ring + evre_iterator; -u32 cfg; - - cfg = current_evre[HIDMA_EVRE_CFG_IDX ]; -if (!err_info) { - err_info = cfg >>HIDMA_EVRE_ERRINFO_BIT_POS ; - err_info &=HIDMA_EVRE_ERRINFO_MASK ; - } -if (!err_code) - err_code = (cfg >>HIDMA_EVRE_CODE_BIT_POS ) & -HIDMA_EVRE_CODE_MASK ; - -if (hidma_post_completed (lldev, tre_iterator, err_info, - err_code)) -break ; - -HIDMA_INCREMENT_ITERATOR (tre_iterator,HIDMA_TRE_SIZE , - tre_ring_size); -HIDMA_INCREMENT_ITERATOR (evre_iterator,HIDMA_EVRE_SIZE , - evre_ring_size); - -/* -* Read the new event descriptor written by the HW. -* As we are processing the delivered events, other events -* get queued to the SW for processing. -*/ - evre_write_off = -readl_relaxed (lldev->evca +HIDMA_EVCA_WRITE_PTR_REG ); - num_completed++; - } - -if (num_completed) { -u32 evre_read_off = (lldev->evre_processed_off + -HIDMA_EVRE_SIZE * num_completed); -u32 tre_read_off = (lldev->tre_processed_off + -HIDMA_TRE_SIZE * num_completed); - - evre_read_off = evre_read_off % evre_ring_size; - tre_read_off = tre_read_off % tre_ring_size; - -writel (evre_read_off, lldev->evca +HIDMA_EVCA_DOORBELL_REG ); - -/* record the last processed tre offset */ - lldev->tre_processed_off = tre_read_off; - lldev->evre_processed_off = evre_read_off; - } - -return num_completed; +return 1 ; } void hidma_cleanup_pending_tre(struct hidma_lldev *lldev, u8 err_info,
@@ -399,6 +360,16 @@ static int hidma_ll_reset(struct hidma_lldev *lldev)*/ static void hidma_ll_int_handler_internal (struct hidma_lldev *lldev,int cause) { +if ((lldev->trch_state ==HIDMA_CH_DISABLED ) || + (lldev->evch_state ==HIDMA_CH_DISABLED )) { +dev_err (lldev->dev,"error 0x%x, already disabled...\n" , + cause); + +/* Clear out pending interrupts */ +writel (cause, lldev->evca +HIDMA_EVCA_IRQ_CLR_REG ); +return ; + } +if (cause &HIDMA_ERR_INT_MASK ) {dev_err (lldev->dev,"error 0x%x, disabling...\n" , cause);
@@ -430,6 +401,9 @@ static void hidma_ll_int_handler_internal(struct hidma_lldev *lldev, int cause)*/ if (hidma_handle_tre_completion (lldev,0 ,0 ))break ; +if ((lldev->trch_state ==HIDMA_CH_DISABLED ) || + (lldev->evch_state ==HIDMA_CH_DISABLED )) +break ; }/* We consumed TREs or there are pending TREs or EVREs. */
Signature · 1 line
1.9.1
PATCH v3 10/10 dmaengine: qcom_hidma: add MSI support for interrupts
In reply to Sinan KayaThe interrupts can now be delivered as platform MSI interrupts on newer platforms. The code looks for a new OF and ACPI strings in order to enable the functionality.
--- drivers/dma/qcom/hidma.c | 129 ++++++++++++++++++++++++++++++++++++++++++-- drivers/dma/qcom/hidma.h | 2 + drivers/dma/qcom/hidma_ll.c | 8 +++ 3 files changed, 134 insertions(+), 5 deletions(-)
drivers/dma/qcom/hidma.c +124 -5
@@ -56,6 +56,7 @@#include <linux/irq.h> #include <linux/atomic.h> #include <linux/pm_runtime.h> +#include <linux/msi.h> #include "../dmaengine.h" #include "hidma.h"
@@ -70,6 +71,7 @@#define HIDMA_ERR_INFO_SW 0xFF#define HIDMA_ERR_CODE_UNEXPECTED_TERMINATE 0x0#define HIDMA_NR_DEFAULT_DESC 10 +#define HIDMA_MSI_INTS 11static inline struct hidma_dev *to_hidma_dev (struct dma_device *dmadev) {
@@ -553,6 +555,15 @@ static irqreturn_t hidma_chirq_handler(int chirq, void *arg)return hidma_ll_inthandler (chirq, lldev); } +static irqreturn_t hidma_chirq_handler_msi (int chirq,void *arg) +{ +struct hidma_lldev **lldevp = arg; +struct hidma_dev *dmadev =to_hidma_dev_from_lldev (lldevp); + +return hidma_ll_inthandler_msi (chirq, *lldevp, +1 << (chirq - dmadev->msi_virqbase)); +} +static ssize_t hidma_show_values (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -590,6 +601,99 @@ static int hidma_create_sysfs_entry(struct hidma_dev *dev, char *name,return device_create_file (dev->ddev.dev, attrs); } +#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN +static void hidma_write_msi_msg (struct msi_desc *desc,struct msi_msg *msg) +{ +struct device *dev =msi_desc_to_dev (desc); +struct hidma_dev *dmadev =dev_get_drvdata (dev); + +if (!desc->platform.msi_index) { +writel (msg->address_lo, dmadev->dev_evca +0x118 ); +writel (msg->address_hi, dmadev->dev_evca +0x11C ); +writel (msg->data, dmadev->dev_evca +0x120 ); + } +} + +static void hidma_free_msis (void *data) +{ +struct device *dev = data; + +platform_msi_domain_free_irqs (dev); +} +#endif + +static int hidma_request_msi (struct hidma_dev *dmadev, +struct platform_device *pdev) +{ +#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN +int rc; +struct msi_desc *desc; +struct msi_desc *failed_desc =NULL ; + + rc =platform_msi_domain_alloc_irqs (&pdev->dev,HIDMA_MSI_INTS , + hidma_write_msi_msg); +if (rc) +return rc; + +for_each_msi_entry (desc, &pdev->dev) { +if (!desc->platform.msi_index) + dmadev->msi_virqbase = desc->irq; + + rc =devm_request_irq (&pdev->dev, desc->irq, + hidma_chirq_handler_msi, +0 ,"qcom-hidma-msi" , + &dmadev->lldev); +if (rc) { + failed_desc = desc; +break ; + } + } + +if (rc) { +/* free allocated MSI interrupts above */ +for_each_msi_entry (desc, &pdev->dev) { +if (desc == failed_desc) +break ; +devm_free_irq (&pdev->dev, desc->irq, + &dmadev->lldev); + } + }else { +/* Add callback to free MSIs on teardown */ +devm_add_action (&pdev->dev, hidma_free_msis, + &pdev->dev); +hidma_ll_setup_irq (dmadev->lldev, true); + + } +if (rc) +dev_warn (&pdev->dev, +"failed to request MSI irq, falling back to wired IRQ\n" ); +return rc; +#else +return -EINVAL ; +#endif +} + +static bool hidma_msi_capable (struct device *dev) +{ +struct acpi_device *adev =ACPI_COMPANION (dev); +const char *of_compat; +int ret = -EINVAL ; + +if (!adev || acpi_disabled) { + ret =device_property_read_string (dev,"compatible" , + &of_compat); +if (ret) +return false; + + ret =strcmp (of_compat,"qcom,hidma-1.1" ); + }else { +#ifdef CONFIG_ACPI + ret =strcmp (acpi_device_hid (adev),"QCOM8062" ); +#endif + } +return ret ==0 ; +} +static int hidma_probe (struct platform_device *pdev) {struct hidma_dev *dmadev;
@@ -599,6 +703,7 @@ static int hidma_probe(struct platform_device *pdev)void __iomem *evca;void __iomem *trca;int rc; +bool msi;pm_runtime_set_autosuspend_delay (&pdev->dev,HIDMA_AUTOSUSPEND_TIMEOUT );pm_runtime_use_autosuspend (&pdev->dev);
@@ -660,6 +765,12 @@ static int hidma_probe(struct platform_device *pdev) dmadev->ddev.device_terminate_all = hidma_terminate_all; dmadev->ddev.copy_align =8 ; +/* +* Determine the MSI capability of the platform. Old HW doesn't +* support MSI. +*/ + msi =hidma_msi_capable (&pdev->dev); +device_property_read_u32 (&pdev->dev,"desc-count" , &dmadev->nr_descriptors);
@@ -688,10 +799,17 @@ static int hidma_probe(struct platform_device *pdev) goto dmafree; } - rc =devm_request_irq (&pdev->dev, chirq, hidma_chirq_handler,0 , -"qcom-hidma" , dmadev->lldev); -if (rc) - goto uninit; +platform_set_drvdata (pdev, dmadev); +if (msi) + rc =hidma_request_msi (dmadev, pdev); + +if (!msi || rc) { +hidma_ll_setup_irq (dmadev->lldev, false); + rc =devm_request_irq (&pdev->dev, chirq, hidma_chirq_handler, +0 ,"qcom-hidma" , dmadev->lldev); +if (rc) + goto uninit; + }INIT_LIST_HEAD (&dmadev->ddev.channels); rc =hidma_chan_init (dmadev,0 );
@@ -707,7 +825,6 @@ static int hidma_probe(struct platform_device *pdev)hidma_debug_init (dmadev);hidma_create_sysfs_entry (dmadev,"chid" ,S_IRUGO );dev_info (&pdev->dev,"HI-DMA engine driver registration complete\n" ); -platform_set_drvdata (pdev, dmadev);pm_runtime_mark_last_busy (dmadev->ddev.dev);pm_runtime_put_autosuspend (dmadev->ddev.dev);return 0 ;
@@ -746,12 +863,14 @@ static int hidma_remove(struct platform_device *pdev)#if IS_ENABLED (CONFIG_ACPI )static const struct acpi_device_id hidma_acpi_ids[] = { {"QCOM8061" }, + {"QCOM8062" }, {}, };#endif static const struct of_device_id hidma_match[] = { {.compatible ="qcom,hidma-1.0" ,}, + {.compatible ="qcom,hidma-1.1" ,}, {}, };MODULE_DEVICE_TABLE (of, hidma_match);
drivers/dma/qcom/hidma.h +2 -0
@@ -115,6 +115,7 @@ struct hidma_dev {int irq;int chidx;u32 nr_descriptors; +int msi_virqbase;struct hidma_lldev *lldev;void __iomem *dev_trca;
@@ -153,6 +154,7 @@ struct hidma_lldev *hidma_ll_init(struct device *dev, u32 max_channels, u8 chidx);int hidma_ll_uninit (struct hidma_lldev *llhndl);irqreturn_t hidma_ll_inthandler (int irq,void *arg); +irqreturn_t hidma_ll_inthandler_msi (int irq,void *arg,int cause);void hidma_cleanup_pending_tre (struct hidma_lldev *llhndl,u8 err_info,u8 err_code);int hidma_debug_init (struct hidma_dev *dmadev);
drivers/dma/qcom/hidma_ll.c +8 -0
@@ -424,6 +424,14 @@ irqreturn_t hidma_ll_inthandler(int chirq, void *arg)return IRQ_HANDLED ; } +irqreturn_t hidma_ll_inthandler_msi (int chirq,void *arg,int cause) +{ +struct hidma_lldev *lldev = arg; + +hidma_ll_int_handler_internal (lldev, cause); +return IRQ_HANDLED ; +} +int hidma_ll_enable (struct hidma_lldev *lldev) {u32 val;
Signature · 1 line
1.9.1