Lines Matching full:msi

3  * Altera PCIe MSI support
15 #include <linux/msi.h>
41 static inline void msi_writel(struct altera_msi *msi, const u32 value, in msi_writel() argument
44 writel_relaxed(value, msi->csr_base + reg); in msi_writel()
47 static inline u32 msi_readl(struct altera_msi *msi, const u32 reg) in msi_readl() argument
49 return readl_relaxed(msi->csr_base + reg); in msi_readl()
55 struct altera_msi *msi; in altera_msi_isr() local
61 msi = irq_desc_get_handler_data(desc); in altera_msi_isr()
63 while ((status = msi_readl(msi, MSI_STATUS)) != 0) { in altera_msi_isr()
64 for_each_set_bit(bit, &status, msi->num_of_vectors) { in altera_msi_isr()
66 readl_relaxed(msi->vector_base + (bit * sizeof(u32))); in altera_msi_isr()
68 ret = generic_handle_domain_irq(msi->inner_domain, bit); in altera_msi_isr()
70 dev_err_ratelimited(&msi->pdev->dev, "unexpected MSI\n"); in altera_msi_isr()
78 .name = "Altera PCIe MSI",
91 struct altera_msi *msi = irq_data_get_irq_chip_data(data); in altera_compose_msi_msg() local
92 phys_addr_t addr = msi->vector_phy + (data->hwirq * sizeof(u32)); in altera_compose_msi_msg()
98 dev_dbg(&msi->pdev->dev, "msi#%d address_hi %#x address_lo %#x\n", in altera_compose_msi_msg()
103 .name = "Altera MSI",
110 struct altera_msi *msi = domain->host_data; in altera_irq_domain_alloc() local
115 mutex_lock(&msi->lock); in altera_irq_domain_alloc()
117 bit = find_first_zero_bit(msi->used, msi->num_of_vectors); in altera_irq_domain_alloc()
118 if (bit >= msi->num_of_vectors) { in altera_irq_domain_alloc()
119 mutex_unlock(&msi->lock); in altera_irq_domain_alloc()
123 set_bit(bit, msi->used); in altera_irq_domain_alloc()
125 mutex_unlock(&msi->lock); in altera_irq_domain_alloc()
131 mask = msi_readl(msi, MSI_INTMASK); in altera_irq_domain_alloc()
133 msi_writel(msi, mask, MSI_INTMASK); in altera_irq_domain_alloc()
142 struct altera_msi *msi = irq_data_get_irq_chip_data(d); in altera_irq_domain_free() local
145 mutex_lock(&msi->lock); in altera_irq_domain_free()
147 if (!test_bit(d->hwirq, msi->used)) { in altera_irq_domain_free()
148 dev_err(&msi->pdev->dev, "trying to free unused MSI#%lu\n", in altera_irq_domain_free()
151 __clear_bit(d->hwirq, msi->used); in altera_irq_domain_free()
152 mask = msi_readl(msi, MSI_INTMASK); in altera_irq_domain_free()
154 msi_writel(msi, mask, MSI_INTMASK); in altera_irq_domain_free()
157 mutex_unlock(&msi->lock); in altera_irq_domain_free()
165 static int altera_allocate_domains(struct altera_msi *msi) in altera_allocate_domains() argument
167 struct fwnode_handle *fwnode = of_node_to_fwnode(msi->pdev->dev.of_node); in altera_allocate_domains()
169 msi->inner_domain = irq_domain_add_linear(NULL, msi->num_of_vectors, in altera_allocate_domains()
170 &msi_domain_ops, msi); in altera_allocate_domains()
171 if (!msi->inner_domain) { in altera_allocate_domains()
172 dev_err(&msi->pdev->dev, "failed to create IRQ domain\n"); in altera_allocate_domains()
176 msi->msi_domain = pci_msi_create_irq_domain(fwnode, in altera_allocate_domains()
177 &altera_msi_domain_info, msi->inner_domain); in altera_allocate_domains()
178 if (!msi->msi_domain) { in altera_allocate_domains()
179 dev_err(&msi->pdev->dev, "failed to create MSI domain\n"); in altera_allocate_domains()
180 irq_domain_remove(msi->inner_domain); in altera_allocate_domains()
187 static void altera_free_domains(struct altera_msi *msi) in altera_free_domains() argument
189 irq_domain_remove(msi->msi_domain); in altera_free_domains()
190 irq_domain_remove(msi->inner_domain); in altera_free_domains()
195 struct altera_msi *msi = platform_get_drvdata(pdev); in altera_msi_remove() local
197 msi_writel(msi, 0, MSI_INTMASK); in altera_msi_remove()
198 irq_set_chained_handler_and_data(msi->irq, NULL, NULL); in altera_msi_remove()
200 altera_free_domains(msi); in altera_msi_remove()
207 struct altera_msi *msi; in altera_msi_probe() local
212 msi = devm_kzalloc(&pdev->dev, sizeof(struct altera_msi), in altera_msi_probe()
214 if (!msi) in altera_msi_probe()
217 mutex_init(&msi->lock); in altera_msi_probe()
218 msi->pdev = pdev; in altera_msi_probe()
220 msi->csr_base = devm_platform_ioremap_resource_byname(pdev, "csr"); in altera_msi_probe()
221 if (IS_ERR(msi->csr_base)) { in altera_msi_probe()
223 return PTR_ERR(msi->csr_base); in altera_msi_probe()
228 msi->vector_base = devm_ioremap_resource(&pdev->dev, res); in altera_msi_probe()
229 if (IS_ERR(msi->vector_base)) in altera_msi_probe()
230 return PTR_ERR(msi->vector_base); in altera_msi_probe()
232 msi->vector_phy = res->start; in altera_msi_probe()
234 if (of_property_read_u32(np, "num-vectors", &msi->num_of_vectors)) { in altera_msi_probe()
239 ret = altera_allocate_domains(msi); in altera_msi_probe()
243 msi->irq = platform_get_irq(pdev, 0); in altera_msi_probe()
244 if (msi->irq < 0) { in altera_msi_probe()
245 ret = msi->irq; in altera_msi_probe()
249 irq_set_chained_handler_and_data(msi->irq, altera_msi_isr, msi); in altera_msi_probe()
250 platform_set_drvdata(pdev, msi); in altera_msi_probe()
260 { .compatible = "altr,msi-1.0", NULL },
266 .name = "altera-msi",
286 MODULE_DESCRIPTION("Altera PCIe MSI support driver");