Skip to content

Commit bad2094

Browse files
inochisaKAGA-KOKO
authored andcommitted
irqchip/sg2042-msi: Introduce configurable chipinfo for SG2042
As the controller on SG2044 uses different msi_parent_ops and a difffernt irq_chip, it is necessary to provide that information to the probe function. Add a new chipinfo structure to hold that information, implement the necessary logic and make SG2042 use it. Signed-off-by: Inochi Amaoto <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Chen Wang <[email protected]> # SG2042 Reviewed-by: Chen Wang <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent bced554 commit bad2094

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

drivers/irqchip/irq-sg2042-msi.c

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,33 @@
1919

2020
#include "irq-msi-lib.h"
2121

22-
#define SG2042_MAX_MSI_VECTOR 32
22+
struct sg204x_msi_chip_info {
23+
const struct irq_chip *irqchip;
24+
const struct msi_parent_ops *parent_ops;
25+
};
2326

27+
/**
28+
* struct sg204x_msi_chipdata - chip data for the SG204x MSI IRQ controller
29+
* @reg_clr: clear reg, see TRM, 10.1.33, GP_INTR0_CLR
30+
* @doorbell_addr: see TRM, 10.1.32, GP_INTR0_SET
31+
* @irq_first: First vectors number that MSIs starts
32+
* @num_irqs: Number of vectors for MSIs
33+
* @msi_map: mapping for allocated MSI vectors.
34+
* @msi_map_lock: Lock for msi_map
35+
* @chip_info: chip specific infomations
36+
*/
2437
struct sg204x_msi_chipdata {
25-
void __iomem *reg_clr; // clear reg, see TRM, 10.1.33, GP_INTR0_CLR
38+
void __iomem *reg_clr;
39+
40+
phys_addr_t doorbell_addr;
2641

27-
phys_addr_t doorbell_addr; // see TRM, 10.1.32, GP_INTR0_SET
42+
u32 irq_first;
43+
u32 num_irqs;
2844

29-
u32 irq_first; // The vector number that MSIs starts
30-
u32 num_irqs; // The number of vectors for MSIs
45+
unsigned long *msi_map;
46+
struct mutex msi_map_lock;
3147

32-
DECLARE_BITMAP(msi_map, SG2042_MAX_MSI_VECTOR);
33-
struct mutex msi_map_lock; // lock for msi_map
48+
const struct sg204x_msi_chip_info *chip_info;
3449
};
3550

3651
static int sg204x_msi_allocate_hwirq(struct sg204x_msi_chipdata *data, int num_req)
@@ -115,7 +130,7 @@ static int sg204x_msi_middle_domain_alloc(struct irq_domain *domain, unsigned in
115130
goto err_hwirq;
116131

117132
irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
118-
&sg2042_msi_middle_irq_chip, data);
133+
data->chip_info->irqchip, data);
119134
}
120135

121136
return 0;
@@ -173,8 +188,7 @@ static int sg204x_msi_init_domains(struct sg204x_msi_chipdata *data,
173188
irq_domain_update_bus_token(middle_domain, DOMAIN_BUS_NEXUS);
174189

175190
middle_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
176-
middle_domain->msi_parent_ops = &sg2042_msi_parent_ops;
177-
191+
middle_domain->msi_parent_ops = data->chip_info->parent_ops;
178192
return 0;
179193
}
180194

@@ -191,6 +205,12 @@ static int sg2042_msi_probe(struct platform_device *pdev)
191205
if (!data)
192206
return -ENOMEM;
193207

208+
data->chip_info = device_get_match_data(&pdev->dev);
209+
if (!data->chip_info) {
210+
dev_err(&pdev->dev, "Failed to get irqchip\n");
211+
return -EINVAL;
212+
}
213+
194214
data->reg_clr = devm_platform_ioremap_resource_byname(pdev, "clr");
195215
if (IS_ERR(data->reg_clr)) {
196216
dev_err(dev, "Failed to map clear register\n");
@@ -231,11 +251,22 @@ static int sg2042_msi_probe(struct platform_device *pdev)
231251

232252
mutex_init(&data->msi_map_lock);
233253

254+
data->msi_map = devm_bitmap_zalloc(&pdev->dev, data->num_irqs, GFP_KERNEL);
255+
if (!data->msi_map) {
256+
dev_err(&pdev->dev, "Unable to allocate msi mapping\n");
257+
return -ENOMEM;
258+
}
259+
234260
return sg204x_msi_init_domains(data, plic_domain, dev);
235261
}
236262

263+
static const struct sg204x_msi_chip_info sg2042_chip_info = {
264+
.irqchip = &sg2042_msi_middle_irq_chip,
265+
.parent_ops = &sg2042_msi_parent_ops,
266+
};
267+
237268
static const struct of_device_id sg2042_msi_of_match[] = {
238-
{ .compatible = "sophgo,sg2042-msi" },
269+
{ .compatible = "sophgo,sg2042-msi", .data = &sg2042_chip_info },
239270
{ }
240271
};
241272

0 commit comments

Comments
 (0)