Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/drivers/include/drivers/pci_msi.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ struct rt_pci_msi_desc
#define rt_pci_msix_table_size(flags) ((flags & PCIM_MSIXCTRL_TABLE_SIZE) + 1)

rt_err_t rt_pci_msi_setup_irqs(struct rt_pci_device *pdev, int nvec, int type);
rt_err_t rt_pci_msi_cleanup_irqs(struct rt_pci_device *pdev);

void rt_pci_msi_shutdown(struct rt_pci_device *pdev);
void rt_pci_msix_shutdown(struct rt_pci_device *pdev);
Expand Down
2 changes: 2 additions & 0 deletions components/drivers/pci/host/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ config RT_PCI_HOST_GENERIC
default y

rsource "dw/Kconfig"

osource "$(SOC_DM_PCI_DIR)/Kconfig"
14 changes: 12 additions & 2 deletions components/drivers/pci/host/dw/pcie-dw_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void dw_pcie_free_msi(struct dw_pcie_port *port)

rt_dma_free_coherent(pci->dev, sizeof(rt_uint64_t), port->msi_data,
port->msi_data_phy);
port->msi_data = RT_NULL;
}
}

Expand Down Expand Up @@ -331,7 +332,8 @@ rt_err_t dw_pcie_host_init(struct dw_pcie_port *port)
{
LOG_E("Invalid count of irq = %d", port->irq_count);

return -RT_EINVAL;
err = -RT_EINVAL;
goto _err_free_cfg;
}
}

Expand All @@ -341,7 +343,8 @@ rt_err_t dw_pcie_host_init(struct dw_pcie_port *port)

if (!port->msi_pic)
{
return -RT_ENOMEM;
err = -RT_ENOMEM;
goto _err_free_cfg;
}

port->msi_pic->priv_data = port;
Expand Down Expand Up @@ -404,6 +407,13 @@ rt_err_t dw_pcie_host_init(struct dw_pcie_port *port)
rt_pci_host_bridge_free(bridge);
port->bridge = RT_NULL;

_err_free_cfg:
if (port->cfg0_base)
{
rt_iounmap(port->cfg0_base);
port->cfg0_base = RT_NULL;
}

return err;
}

Expand Down
39 changes: 39 additions & 0 deletions components/drivers/pci/msi/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,42 @@ rt_err_t rt_pci_msi_setup_irqs(struct rt_pci_device *pdev, int nvec, int type)

return err;
}

rt_err_t rt_pci_msi_cleanup_irqs(struct rt_pci_device *pdev)
{
int type;
struct rt_pic *msi_pic;
struct rt_pci_msi_desc *desc;

if (!pdev)
{
return -RT_EINVAL;
}

msi_pic = pdev->msi_pic;

if (!msi_pic)
{
return -RT_EINVAL;
}

desc = rt_pci_msi_first_desc(pdev);
type = desc->is_msix ? PCIY_MSIX : PCIY_MSI;

if (type == PCIY_MSI)
{
for (int idx = 0; idx < desc->vector_used; ++idx)
{
msi_pic->ops->irq_free_msi(msi_pic, desc->irq + idx);
}
}
else if (type == PCIY_MSIX)
{
rt_pci_msi_for_each_desc(pdev, desc)
{
msi_pic->ops->irq_free_msi(msi_pic, desc->irq);
}
}

return RT_EOK;
}
2 changes: 2 additions & 0 deletions components/drivers/pci/msi/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ void rt_pci_msi_free_irqs(struct rt_pci_device *pdev)
pdev->msix_base = RT_NULL;
}

rt_pci_msi_cleanup_irqs(pdev);

rt_pci_msi_for_each_desc(pdev, desc)
{
/* To safety */
Expand Down
7 changes: 5 additions & 2 deletions components/drivers/pci/ofw.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ rt_err_t rt_pci_ofw_parse_ranges(struct rt_ofw_node *dev_np,
phy_addr_cells, phy_size_cells, cpu_addr_cells,
&host_bridge->dma_regions, &host_bridge->dma_regions_nr);

if (err != -RT_EEMPTY)
if (err && err != -RT_EEMPTY)
{
rt_free(host_bridge->bus_regions);
host_bridge->bus_regions_nr = 0;
Expand Down Expand Up @@ -314,7 +314,10 @@ rt_err_t rt_pci_ofw_host_bridge_init(struct rt_ofw_node *dev_np,

if (rt_ofw_prop_read_u32_array_index(dev_np, "bus-range", 0, 2, host_bridge->bus_range) < 0)
{
return -RT_EIO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要返回错误码了吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照别的平台的操作系统设备树规范来看,是允许在设备树未定义的情况下,设置总线范围默认值未 0~255,在实际树莓派 5 平台上也确实有这种情况,所以就不再返回错误,而是设定默认值。

host_bridge->bus_range[0] = 0x00;
host_bridge->bus_range[1] = 0xff;
LOG_I("%s: No \"%s\" found, using [%#02x, %#02x]", rt_ofw_node_full_name(dev_np), "bus-range",
host_bridge->bus_range[0], host_bridge->bus_range[1]);
}

propname = rt_ofw_get_prop_fuzzy_name(dev_np, ",pci-domain$");
Expand Down
Loading