Lines Matching full:msi
3 * Altera PCIe MSI support
14 #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 virq = irq_find_mapping(msi->inner_domain, bit); in altera_msi_isr()
72 dev_err(&msi->pdev->dev, "unexpected MSI\n"); in altera_msi_isr()
80 .name = "Altera PCIe MSI",
93 struct altera_msi *msi = irq_data_get_irq_chip_data(data); in altera_compose_msi_msg() local
94 phys_addr_t addr = msi->vector_phy + (data->hwirq * sizeof(u32)); in altera_compose_msi_msg()
100 dev_dbg(&msi->pdev->dev, "msi#%d address_hi %#x address_lo %#x\n", in altera_compose_msi_msg()
111 .name = "Altera MSI",
119 struct altera_msi *msi = domain->host_data; in altera_irq_domain_alloc() local
124 mutex_lock(&msi->lock); in altera_irq_domain_alloc()
126 bit = find_first_zero_bit(msi->used, msi->num_of_vectors); in altera_irq_domain_alloc()
127 if (bit >= msi->num_of_vectors) { in altera_irq_domain_alloc()
128 mutex_unlock(&msi->lock); in altera_irq_domain_alloc()
132 set_bit(bit, msi->used); in altera_irq_domain_alloc()
134 mutex_unlock(&msi->lock); in altera_irq_domain_alloc()
140 mask = msi_readl(msi, MSI_INTMASK); in altera_irq_domain_alloc()
142 msi_writel(msi, mask, MSI_INTMASK); in altera_irq_domain_alloc()
151 struct altera_msi *msi = irq_data_get_irq_chip_data(d); in altera_irq_domain_free() local
154 mutex_lock(&msi->lock); in altera_irq_domain_free()
156 if (!test_bit(d->hwirq, msi->used)) { in altera_irq_domain_free()
157 dev_err(&msi->pdev->dev, "trying to free unused MSI#%lu\n", in altera_irq_domain_free()
160 __clear_bit(d->hwirq, msi->used); in altera_irq_domain_free()
161 mask = msi_readl(msi, MSI_INTMASK); in altera_irq_domain_free()
163 msi_writel(msi, mask, MSI_INTMASK); in altera_irq_domain_free()
166 mutex_unlock(&msi->lock); in altera_irq_domain_free()
174 static int altera_allocate_domains(struct altera_msi *msi) in altera_allocate_domains() argument
176 struct fwnode_handle *fwnode = of_node_to_fwnode(msi->pdev->dev.of_node); in altera_allocate_domains()
178 msi->inner_domain = irq_domain_add_linear(NULL, msi->num_of_vectors, in altera_allocate_domains()
179 &msi_domain_ops, msi); in altera_allocate_domains()
180 if (!msi->inner_domain) { in altera_allocate_domains()
181 dev_err(&msi->pdev->dev, "failed to create IRQ domain\n"); in altera_allocate_domains()
185 msi->msi_domain = pci_msi_create_irq_domain(fwnode, in altera_allocate_domains()
186 &altera_msi_domain_info, msi->inner_domain); in altera_allocate_domains()
187 if (!msi->msi_domain) { in altera_allocate_domains()
188 dev_err(&msi->pdev->dev, "failed to create MSI domain\n"); in altera_allocate_domains()
189 irq_domain_remove(msi->inner_domain); in altera_allocate_domains()
196 static void altera_free_domains(struct altera_msi *msi) in altera_free_domains() argument
198 irq_domain_remove(msi->msi_domain); in altera_free_domains()
199 irq_domain_remove(msi->inner_domain); in altera_free_domains()
204 struct altera_msi *msi = platform_get_drvdata(pdev); in altera_msi_remove() local
206 msi_writel(msi, 0, MSI_INTMASK); in altera_msi_remove()
207 irq_set_chained_handler(msi->irq, NULL); in altera_msi_remove()
208 irq_set_handler_data(msi->irq, NULL); in altera_msi_remove()
210 altera_free_domains(msi); in altera_msi_remove()
218 struct altera_msi *msi; in altera_msi_probe() local
223 msi = devm_kzalloc(&pdev->dev, sizeof(struct altera_msi), in altera_msi_probe()
225 if (!msi) in altera_msi_probe()
228 mutex_init(&msi->lock); in altera_msi_probe()
229 msi->pdev = pdev; in altera_msi_probe()
231 msi->csr_base = devm_platform_ioremap_resource_byname(pdev, "csr"); in altera_msi_probe()
232 if (IS_ERR(msi->csr_base)) { in altera_msi_probe()
234 return PTR_ERR(msi->csr_base); in altera_msi_probe()
239 msi->vector_base = devm_ioremap_resource(&pdev->dev, res); in altera_msi_probe()
240 if (IS_ERR(msi->vector_base)) { in altera_msi_probe()
242 return PTR_ERR(msi->vector_base); in altera_msi_probe()
245 msi->vector_phy = res->start; in altera_msi_probe()
247 if (of_property_read_u32(np, "num-vectors", &msi->num_of_vectors)) { in altera_msi_probe()
252 ret = altera_allocate_domains(msi); in altera_msi_probe()
256 msi->irq = platform_get_irq(pdev, 0); in altera_msi_probe()
257 if (msi->irq < 0) { in altera_msi_probe()
258 ret = msi->irq; in altera_msi_probe()
262 irq_set_chained_handler_and_data(msi->irq, altera_msi_isr, msi); in altera_msi_probe()
263 platform_set_drvdata(pdev, msi); in altera_msi_probe()
273 { .compatible = "altr,msi-1.0", NULL },
279 .name = "altera-msi",