• Accessing Memory mapped register in Vxworks

    From Rajat Dongre@21:1/5 to All on Tue Oct 17 05:21:34 2023
    Hi all,
    I have to access the register which are memory mapped for PCIe NTB in VxWorks. I have Linux code for accessing it but I am not able to understand hoe can we do it in VxWorks.

    your guidance in it is highly appreciated by me, Thanks in advance.

    linux pcie ntb driver to access the register is below:
    Note: declaration in one structure :
    struct __iomem *mmio_sys_info;

    static int switchtec_init_pci(struct switchtec_dev *stdev,
    struct pci_dev *pdev)
    {
    int rc;
    void __iomem *map;
    unsigned long res_start, res_len;
    u32 __iomem *part_id;

    rc = pcim_enable_device(pdev);
    if (rc)
    return rc;

    //set mask 64 bit to get DMA transfer device
    rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
    if (rc)
    return rc;

    //enables bus-mastering for device dev
    pci_set_master(pdev);

    res_start = pci_resource_start(pdev, 0); //Returns bus start address for a given PCI region
    res_len = pci_resource_len(pdev, 0); //Returns the byte length of a PCI region

    if (!devm_request_mem_region(&pdev->dev, res_start,
    res_len, KBUILD_MODNAME))
    return -EBUSY;

    stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start,
    SWITCHTEC_GAS_TOP_CFG_OFFSET); //0 - 0x1000 //allocate mmio mrpc region from 0 to cfg offset
    if (!stdev->mmio_mrpc)
    return -ENOMEM;

    map = devm_ioremap(&pdev->dev,
    res_start + SWITCHTEC_GAS_TOP_CFG_OFFSET,
    res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET); //map = 0+0x1000-0x2000-0x1000
    if (!map)
    return -ENOMEM;

    stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET; //mmio = mrpc commands region till (map - 0x1000). mmio considered as a starting loc for GAS.
    stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; // mmio + 0x1800
    stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; //mmio + 0x2000
    stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; //mmio+ 0x2200
    stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; //mmio+0x10000

    if (stdev->gen == SWITCHTEC_GEN3)
    part_id = &stdev->mmio_sys_info->gen3.partition_id;
    else if (stdev->gen >= SWITCHTEC_GEN4)
    part_id = &stdev->mmio_sys_info->gen4.partition_id;
    else
    return -ENOTSUPP;

    stdev->partition = ioread8(part_id);
    stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count);
    stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; //mmio+0x4000
    stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; //could be partition 0
    stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; //mmio + 0x134000

    if (stdev->partition_count < 1)
    stdev->partition_count = 1;

    init_pff(stdev); //doubt

    pci_set_drvdata(pdev, stdev);

    if (!use_dma_mrpc)
    return 0;

    if (!ioread32(&stdev->mmio_mrpc->dma_ver))
    return 0;

    stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev,
    sizeof(*stdev->dma_mrpc),
    &stdev->dma_mrpc_dma_addr,
    GFP_KERNEL);
    if (stdev->dma_mrpc == NULL)
    return -ENOMEM;

    return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)