summaryrefslogtreecommitdiff
path: root/components/drivers/pci/msi/device.c
blob: 36d0d0d3ae03ca56fe02fe0b783c39e658d92844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-10-24     GuEe-GUI     first version
 */

#include <drivers/pci.h>

void rt_pci_msi_init(struct rt_pci_device *pdev)
{
    if (pdev && (pdev->msi_cap = rt_pci_find_capability(pdev, PCIY_MSI)))
    {
        rt_uint16_t ctrl;

        rt_pci_read_config_u16(pdev, pdev->msi_cap + PCIR_MSI_CTRL, &ctrl);

        if (ctrl & PCIM_MSICTRL_MSI_ENABLE)
        {
            rt_pci_write_config_u16(pdev, pdev->msi_cap + PCIR_MSI_CTRL, ctrl & ~PCIM_MSICTRL_MSI_ENABLE);
        }

        if (!(ctrl & PCIM_MSICTRL_64BIT))
        {
            pdev->no_64bit_msi = RT_TRUE;
        }
    }
}

void rt_pci_msix_init(struct rt_pci_device *pdev)
{
    if (pdev && (pdev->msix_cap = rt_pci_find_capability(pdev, PCIY_MSIX)))
    {
        rt_uint16_t ctrl;

        rt_pci_read_config_u16(pdev, pdev->msix_cap + PCIR_MSIX_CTRL, &ctrl);

        if (ctrl & PCIM_MSIXCTRL_MSIX_ENABLE)
        {
            rt_pci_write_config_u16(pdev, pdev->msix_cap + PCIR_MSIX_CTRL, ctrl & ~PCIM_MSIXCTRL_MSIX_ENABLE);
        }
    }
}