[v8,10/15] ACPI: platform-msi: retrieve dev id from IORT
diff mbox

Message ID 1484744105-53140-11-git-send-email-guohanjun@huawei.com
State Not Applicable, archived
Headers show

Commit Message

Hanjun Guo Jan. 18, 2017, 12:55 p.m. UTC
From: Hanjun Guo <hanjun.guo@linaro.org>

For devices connecting to ITS, it needs dev id to identify itself, and
this dev id is represented in the IORT table in named component node
[1] for platform devices, so in this patch we will scan the IORT to
retrieve device's dev id.

With the preparation of iort_node_map_platform_id(), a new API
iort_pmsi_get_dev_id() is introduced for that purpose, call it in
its_pmsi_prepare() to make retrieving dev id ACPI aware.

[1]: https://static.docs.arm.com/den0049/b/DEN0049B_IO_Remapping_Table.pdf

Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Ming Lei <ming.lei@canonical.com>
Tested-by: Wei Xu <xuwei5@hisilicon.com>
Tested-by: Sinan Kaya <okaya@codeaurora.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Tomasz Nowicki <tn@semihalf.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/acpi/arm64/iort.c                     | 24 ++++++++++++++++++++++++
 drivers/irqchip/irq-gic-v3-its-platform-msi.c |  3 ++-
 include/linux/acpi_iort.h                     |  5 +++++
 3 files changed, 31 insertions(+), 1 deletion(-)

Comments

Sinan Kaya April 17, 2017, 9:44 p.m. UTC | #1
On 1/18/2017 7:55 AM, Hanjun Guo wrote:
> --- a/drivers/irqchip/irq-gic-v3-its-platform-msi.c
> +++ b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
> @@ -57,7 +57,8 @@ static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
>  
>  	msi_info = msi_get_domain_info(domain->parent);
>  
> -	ret = of_pmsi_get_dev_id(domain, dev, &dev_id);
> +	ret = dev->of_node ? of_pmsi_get_dev_id(domain, dev, &dev_id) :
> +		iort_pmsi_get_dev_id(dev, &dev_id);
>  	if (ret)
>  		return ret;
>  

Any idea what happened to the change in this function during merge?

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=ae7c18380495ac5c14a614fdb6c452c3bf9148ac

63a52b3 platform-msi: Make platform_msi_create_device_domain() ACPI aware
e07b978 irqchip/gicv3-its: platform-msi: Scan MADT to create platform msi domain
09be1d5 irqchip/gicv3-its: platform-msi: Refactor its_pmsi_init() to prepare for ACPI
4e96df9 irqchip/gicv3-its: platform-msi: Refactor its_pmsi_prepare()
e593828 irqchip/gic-v3-its: Keep the include header files in alphabetic order
e226a74 ACPI: platform: setup MSI domain for ACPI based platform device
79c7533 ACPI: platform-msi: retrieve devid from IORT
43394c9 ACPI/IORT: Introduce iort_node_map_platform_id() to retrieve dev id
e6eaeae ACPI/IORT: Rename iort_node_map_rid() to make it generic
6acbb92 ACPI/IORT: Rework iort_match_node_callback() return value handling
f8e2f50 ACPI/IORT: Add missing comment for iort_dev_find_its_id()
4b1eeee ACPI/IORT: Fix the indentation in iort_scan_node()

I'm getting these warnings when using the above patches on top of 4.11-rc6?
The code is basically trying to read OF attribute on an ACPI system.

[   11.644792] ------------[ cut here ]------------
[   11.649407] WARNING: CPU: 35 PID: 1 at /local/mnt/workspace/projects/caf/kernel/drivers/irqchip/irq-gic-v3-its-platform-msi.c:41 its_pmsi_prepare+0x9c/0xfc
[   11.663305] Modules linked in:
[   11.666353]
[   11.667839] CPU: 35 PID: 1 Comm: swapper/0 Tainted: G        W       4.11.0-00036-g63a52b3 #1
[   11.676355] Hardware name: (null) (DT)
[   11.680097] task: ffff8007dbab8000 task.stack: ffff8007dbab4000
[   11.686009] PC is at its_pmsi_prepare+0x9c/0xfc
[   11.690533] LR is at its_pmsi_prepare+0x5c/0xfc
[   11.695056] pc : [<ffff000008371b68>] lr : [<ffff000008371b28>] pstate: 20400045
[   11.702443] sp : ffff8007dbab7a40
[   11.705750] x29: ffff8007dbab7a40 x28: 0000000000000000
[   11.711057] x27: ffff0000092a9000 x26: 0000000000000000
[   11.716364] x25: ffff8007df02ba00 x24: ffff000008a745a9
[   11.721670] x23: ffff000008a7459e x22: 000000000000000b
[   11.726976] x21: ffff8007dbab7b70 x20: ffff8007d9c48c10
[   11.732282] x19: ffff8007dba8ba80 x18: 000000000000000a
[   11.737588] x17: 0000000000001000 x16: 0000000000000040
[   11.742895] x15: 000000000009bb9b x14: 0040000000000041
[   11.748201] x13: 0140000000000000 x12: 0088000000000000
[   11.753507] x11: ffff000008af0000 x10: ffff0000094ad000
[   11.758814] x9 : 0000000000000000 x8 : ffff8007d977ac00
[   11.764120] x7 : 0000000000000000 x6 : 000000000000003f
[   11.769426] x5 : ffff8007dbab7a90 x4 : 0000000000000000
[   11.774733] x3 : 0000000000000006 x2 : 00000000fffffffe
[   11.780039] x1 : ffff8007df02b760 x0 : 0000000008d8fb70
[   11.785345]
[   11.786830] ---[ end trace 265ed4f0c6d0486b ]---
[   11.791439] Call trace:
[   11.793879] Exception stack(0xffff8007dbab7870 to 0xffff8007dbab79a0)
[   11.800312] 7860:                                   ffff8007dba8ba80 0001000000000000
[   11.808134] 7880: ffff8007dbab7a40 ffff000008371b68 ffff7e0000000000 0000000000000004
[   11.815956] 78a0: ffff000008af0000 0000820000000000 00000000000ff200 ffff8007dbab8000
[   11.823779] 78c0: 00000000000ff000 ffff0000081cb6ec ffff8007dbab78e0 00000000000ff000
[   11.831601] 78e0: 0000000000000040 ffff8007ffff2a80 ffff8007dbab7940 ffff000008166530
[   11.839423] 7900: ffff8007dbab7960 ffff0000081984f4 0000000008d8fb70 ffff8007df02b760
[   11.847245] 7920: 00000000fffffffe 0000000000000006 0000000000000000 ffff8007dbab7a90
[   11.855067] 7940: 000000000000003f 0000000000000000 ffff8007d977ac00 0000000000000000
[   11.862890] 7960: ffff0000094ad000 ffff000008af0000 0088000000000000 0140000000000000
[   11.870712] 7980: 0040000000000041 000000000009bb9b 0000000000000040 0000000000001000
[   11.878535] [<ffff000008371b68>] its_pmsi_prepare+0x9c/0xfc
[   11.884101] [<ffff000008109444>] msi_domain_prepare_irqs+0x54/0x68
[   11.890274] [<ffff0000081095a8>] msi_domain_alloc_irqs+0x30/0x14c
[   11.896361] [<ffff0000084f00cc>] platform_msi_domain_alloc_irqs+0x54/0x8c
[   11.903142] [<ffff0000084566d8>] hidma_probe+0x5ac/0x824
[   11.908448] [<ffff0000084d16c0>] platform_drv_probe+0x54/0xa4
[   11.914186] [<ffff0000084cfb20>] driver_probe_device+0x140/0x2a0
[   11.920185] [<ffff0000084cfcf4>] __driver_attach+0x74/0xa0
[   11.925664] [<ffff0000084ce0dc>] bus_for_each_dev+0x68/0x98
[   11.931229] [<ffff0000084cf5b8>] driver_attach+0x20/0x28
[   11.936534] [<ffff0000084cf16c>] bus_add_driver+0xe0/0x1ec
[   11.942012] [<ffff0000084d05f4>] driver_register+0x90/0xdc
[   11.947490] [<ffff0000084d161c>] __platform_driver_register+0x48/0x50
[   11.953924] [<ffff000008b9781c>] hidma_driver_init+0x18/0x20
[   11.959577] [<ffff00000808318c>] do_one_initcall+0x80/0x108
[   11.965142] [<ffff000008b60d0c>] kernel_init_freeable+0x19c/0x23c
[   11.971228] [<ffff0000087af808>] kernel_init+0x10/0xfc
[   11.976359] [<ffff000008082ec0>] ret_from_fork+0x10/0x50
[   11.981746] hidma QCOM8062:17: HI-DMA engine driver registration complete
Sinan Kaya April 17, 2017, 10:01 p.m. UTC | #2
On 4/17/2017 5:44 PM, Sinan Kaya wrote:
> Any idea what happened to the change in this function during merge?
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=ae7c18380495ac5c14a614fdb6c452c3bf9148ac
> 

I realized that there is a V9 out there. I'm catching up with the work. 

https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?h=irq/irqchip-4.12&id=e6db07d0f3b6da1f8cfd485776bfefa4fcdbfc45

seems to be fixing the issue. 

> 63a52b3 platform-msi: Make platform_msi_create_device_domain() ACPI aware
> e07b978 irqchip/gicv3-its: platform-msi: Scan MADT to create platform msi domain
> 09be1d5 irqchip/gicv3-its: platform-msi: Refactor its_pmsi_init() to prepare for ACPI
> 4e96df9 irqchip/gicv3-its: platform-msi: Refactor its_pmsi_prepare()
> e593828 irqchip/gic-v3-its: Keep the include header files in alphabetic order
> e226a74 ACPI: platform: setup MSI domain for ACPI based platform device
> 79c7533 ACPI: platform-msi: retrieve devid from IORT
> 43394c9 ACPI/IORT: Introduce iort_node_map_platform_id() to retrieve dev id
> e6eaeae ACPI/IORT: Rename iort_node_map_rid() to make it generic
> 6acbb92 ACPI/IORT: Rework iort_match_node_callback() return value handling
> f8e2f50 ACPI/IORT: Add missing comment for iort_dev_find_its_id()
> 4b1eeee ACPI/IORT: Fix the indentation in iort_scan_node()

Apologies for the noise.
Hanjun Guo April 18, 2017, 1:27 a.m. UTC | #3
Hi Sinan,

On 2017/4/18 6:01, Sinan Kaya wrote:
> On 4/17/2017 5:44 PM, Sinan Kaya wrote:
>> Any idea what happened to the change in this function during merge?
>>
>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=ae7c18380495ac5c14a614fdb6c452c3bf9148ac
>>
> I realized that there is a V9 out there. I'm catching up with the work. 
>
> https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?h=irq/irqchip-4.12&id=e6db07d0f3b6da1f8cfd485776bfefa4fcdbfc45
>
> seems to be fixing the issue. 

Patches were merged via two trees:

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=irq/core
https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/core&ofs=50

So please try to merge those two trees and have a try (we tested
those patches on our platform and works), if any issues please let
me know.

Thanks
Hanjun

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sinan Kaya April 18, 2017, 1:30 a.m. UTC | #4
On 4/17/2017 9:27 PM, Hanjun Guo wrote:
> Patches were merged via two trees:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=irq/core
> https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/core&ofs=50
> 
> So please try to merge those two trees and have a try (we tested
> those patches on our platform and works), if any issues please let
> me know.

Yeah, I figure that out eventually. No issues. I finished my testing
today.
Hanjun Guo April 18, 2017, 1:33 a.m. UTC | #5
On 2017/4/18 9:30, Sinan Kaya wrote:
> On 4/17/2017 9:27 PM, Hanjun Guo wrote:
>> Patches were merged via two trees:
>>
>> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=irq/core
>> https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/core&ofs=50
>>
>> So please try to merge those two trees and have a try (we tested
>> those patches on our platform and works), if any issues please let
>> me know.
> Yeah, I figure that out eventually. No issues. I finished my testing
> today.

Great, thank you :)

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index dacf5e1..9aebb14 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -468,6 +468,30 @@  u32 iort_msi_map_rid(struct device *dev, u32 req_id)
 }
 
 /**
+ * iort_pmsi_get_dev_id() - Get the device id for a device
+ * @dev: The device for which the mapping is to be done.
+ * @dev_id: The device ID found.
+ *
+ * Returns: 0 for successful find a dev id, -ENODEV on error
+ */
+int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id)
+{
+	int i;
+	struct acpi_iort_node *node;
+
+	node = iort_find_dev_node(dev);
+	if (!node)
+		return -ENODEV;
+
+	for (i = 0; i < node->mapping_count; i++) {
+		if (iort_node_map_platform_id(node, dev_id, IORT_MSI_TYPE, i))
+			return 0;
+	}
+
+	return -ENODEV;
+}
+
+/**
  * iort_dev_find_its_id() - Find the ITS identifier for a device
  * @dev: The device.
  * @req_id: Device's requester ID
diff --git a/drivers/irqchip/irq-gic-v3-its-platform-msi.c b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
index e4ba9f4..e801fc0 100644
--- a/drivers/irqchip/irq-gic-v3-its-platform-msi.c
+++ b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
@@ -57,7 +57,8 @@  static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
 
 	msi_info = msi_get_domain_info(domain->parent);
 
-	ret = of_pmsi_get_dev_id(domain, dev, &dev_id);
+	ret = dev->of_node ? of_pmsi_get_dev_id(domain, dev, &dev_id) :
+		iort_pmsi_get_dev_id(dev, &dev_id);
 	if (ret)
 		return ret;
 
diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h
index 77e0809..d074c77 100644
--- a/include/linux/acpi_iort.h
+++ b/include/linux/acpi_iort.h
@@ -34,6 +34,7 @@ 
 bool iort_node_match(u8 type);
 u32 iort_msi_map_rid(struct device *dev, u32 req_id);
 struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id);
+int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id);
 /* IOMMU interface */
 void iort_set_dma_mask(struct device *dev);
 const struct iommu_ops *iort_iommu_configure(struct device *dev);
@@ -45,6 +46,10 @@  static inline u32 iort_msi_map_rid(struct device *dev, u32 req_id)
 static inline struct irq_domain *iort_get_device_domain(struct device *dev,
 							u32 req_id)
 { return NULL; }
+
+static inline int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id)
+{ return -ENODEV; }
+
 /* IOMMU interface */
 static inline void iort_set_dma_mask(struct device *dev) { }
 static inline