Skip to content

Commit 8731289

Browse files
GuEe-GUIRbb666
authored andcommitted
[DM/PCI] Fixup the MSI info shuold free
Signed-off-by: GuEe-GUI <[email protected]>
1 parent 12d0074 commit 8731289

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

components/drivers/include/drivers/pci_msi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct rt_pci_msi_desc
177177
#define rt_pci_msix_table_size(flags) ((flags & PCIM_MSIXCTRL_TABLE_SIZE) + 1)
178178

179179
rt_err_t rt_pci_msi_setup_irqs(struct rt_pci_device *pdev, int nvec, int type);
180+
rt_err_t rt_pci_msi_cleanup_irqs(struct rt_pci_device *pdev);
180181

181182
void rt_pci_msi_shutdown(struct rt_pci_device *pdev);
182183
void rt_pci_msix_shutdown(struct rt_pci_device *pdev);

components/drivers/pci/msi/irq.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,42 @@ rt_err_t rt_pci_msi_setup_irqs(struct rt_pci_device *pdev, int nvec, int type)
144144

145145
return err;
146146
}
147+
148+
rt_err_t rt_pci_msi_cleanup_irqs(struct rt_pci_device *pdev)
149+
{
150+
int type;
151+
struct rt_pic *msi_pic;
152+
struct rt_pci_msi_desc *desc;
153+
154+
if (!pdev)
155+
{
156+
return -RT_EINVAL;
157+
}
158+
159+
msi_pic = pdev->msi_pic;
160+
161+
if (!msi_pic)
162+
{
163+
return -RT_EINVAL;
164+
}
165+
166+
desc = rt_pci_msi_first_desc(pdev);
167+
type = desc->is_msix ? PCIY_MSIX : PCIY_MSI;
168+
169+
if (type == PCIY_MSI)
170+
{
171+
for (int idx = 0; idx < desc->vector_used; ++idx)
172+
{
173+
msi_pic->ops->irq_free_msi(msi_pic, desc->irq + idx);
174+
}
175+
}
176+
else if (type == PCIY_MSIX)
177+
{
178+
rt_pci_msi_for_each_desc(pdev, desc)
179+
{
180+
msi_pic->ops->irq_free_msi(msi_pic, desc->irq);
181+
}
182+
}
183+
184+
return RT_EOK;
185+
}

components/drivers/pci/msi/msi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ void rt_pci_msi_free_irqs(struct rt_pci_device *pdev)
233233
pdev->msix_base = RT_NULL;
234234
}
235235

236+
rt_pci_msi_cleanup_irqs(pdev);
237+
236238
rt_pci_msi_for_each_desc(pdev, desc)
237239
{
238240
/* To safety */

0 commit comments

Comments
 (0)