Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of/irq: Add of_msi_xlate() helper function

Add an of_msi_xlate() helper that maps a device ID and returns
the device node of the MSI controller the device ID is mapped to.

Required by core functions that need an MSI controller device node
pointer at the same time as a mapped device ID, of_msi_map_id() is not
sufficient for that purpose.

Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Link: https://lore.kernel.org/r/20250703-gicv5-host-v7-24-12e71f1b3528@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>

authored by

Lorenzo Pieralisi and committed by
Marc Zyngier
31fd3bec 03a28dc3

+22 -5
+17 -5
drivers/of/irq.c
··· 670 670 } 671 671 } 672 672 673 - static u32 __of_msi_map_id(struct device *dev, struct device_node **np, 674 - u32 id_in) 673 + /** 674 + * of_msi_xlate - map a MSI ID and find relevant MSI controller node 675 + * @dev: device for which the mapping is to be done. 676 + * @msi_np: Pointer to store the MSI controller node 677 + * @id_in: Device ID. 678 + * 679 + * Walk up the device hierarchy looking for devices with a "msi-map" 680 + * property. If found, apply the mapping to @id_in. @msi_np pointed 681 + * value must be NULL on entry, if an MSI controller is found @msi_np is 682 + * initialized to the MSI controller node with a reference held. 683 + * 684 + * Returns: The mapped MSI id. 685 + */ 686 + u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in) 675 687 { 676 688 struct device *parent_dev; 677 689 u32 id_out = id_in; ··· 694 682 */ 695 683 for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent) 696 684 if (!of_map_id(parent_dev->of_node, id_in, "msi-map", 697 - "msi-map-mask", np, &id_out)) 685 + "msi-map-mask", msi_np, &id_out)) 698 686 break; 699 687 return id_out; 700 688 } ··· 712 700 */ 713 701 u32 of_msi_map_id(struct device *dev, struct device_node *msi_np, u32 id_in) 714 702 { 715 - return __of_msi_map_id(dev, &msi_np, id_in); 703 + return of_msi_xlate(dev, &msi_np, id_in); 716 704 } 717 705 718 706 /** ··· 731 719 { 732 720 struct device_node *np = NULL; 733 721 734 - __of_msi_map_id(dev, &np, id); 722 + of_msi_xlate(dev, &np, id); 735 723 return irq_find_matching_host(np, bus_token); 736 724 } 737 725
+5
include/linux/of_irq.h
··· 54 54 u32 id, 55 55 u32 bus_token); 56 56 extern void of_msi_configure(struct device *dev, const struct device_node *np); 57 + extern u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in); 57 58 u32 of_msi_map_id(struct device *dev, struct device_node *msi_np, u32 id_in); 58 59 #else 59 60 static inline void of_irq_init(const struct of_device_id *matches) ··· 100 99 } 101 100 static inline void of_msi_configure(struct device *dev, struct device_node *np) 102 101 { 102 + } 103 + static inline u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in) 104 + { 105 + return id_in; 103 106 } 104 107 static inline u32 of_msi_map_id(struct device *dev, 105 108 struct device_node *msi_np, u32 id_in)