This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/66AK2H12: Segmentation fault occurs while reading PCIe bar registers from linux user space

Part Number: 66AK2H12
Other Parts Discussed in Thread: TMS320C6678,

Tool/software: Linux

Hi,

In our custom board, Keystone2 (66AK2H12) is connected to 2 Keystone 1 (tms320c6678) processors thro pcie switch. We tried to boot K1 processors thro PCIe boot. We cross compiled ti provided linux host pcie example (pciedemo.c) and ported in one of K2. It works fine (successfully boots one K1). So we modified the linux host pcie code (pciedemo.c) to support sysfs so that user can load their application (*.out) directly without converting into hex format.

First we created pciedemo.ko module with sysfs which successfully inserted in kernel (known thro pcie bar register read by setpci command and character device creation)

The problem occurs when we try to access application register thro pcie bar0 from user space. While reading the bar registers i am getting unhandled segmentation fault but not in writing. For your reference, I am providing code snippet.

pcie_drv_inst[dev_id].bar_info[0].virtAddr = 

(void *)mmap(NULL, pcie_drv_inst[dev_id].bar_info[0].length,
(PROT_READ | PROT_WRITE),
MAP_SHARED, pcie_drv_inst[dev_id].dev_desc, (off_t)pcie_drv_inst[dev_id].bar_info[0].pcieAddr);

/* PCIe application registers virtual address (mapped to PCI window) */
#define PCI_REGV(minor, reg) (unsigned *) (pcie_drv_inst[minor].bar_info[0].virtAddr + reg)

bar_num =*(PCI_REGV(dsp_id, IB_BAR(ib_trans_num))) /*unhandled  Segmentation fault occurs*/

*(PCI_REGV(dsp_id, IB_BAR(ib_trans_num))) = bar_num; /* No error but dont know where it is writing !!!! */

My doubt is for virtual memory support anything else has to be taken care in pcie base drivers?

Note: we are using Linux 3.10 from ti git repo. PCie BARs configured in 32-bit mode.

Kindly help on this?

Regards,

S.Sivanantham 

 

  • Hi,

    Our board has one Keystone2 and two Keystone1 processors.

    Regards,
    S.Sivanantham
  • We're looking into this. Feedback will be posted here when available.

    Best Regards,
    Yordan
  • I used devmem2 to access the register, and it seems to work if the device is enumerated. When you access through sysfs, I think the device needs to be up first.

    Rex

  • Hi,

    Thanks for the reply. I am able to access the registers with devmem2.

    I have come across advantech board  which is similar to our board (DSPC8682E) ( connectivity : (PC) x86 -> pcie switch -> 8 tms320c6678s)

    Our board connectivity is 66AK2H12 -> PCIe switch -> 2 tms320c6678s. So i modified the code and cross compiled the code and ported in our board.

    The module is inserted successfully it successfully adds the device in sysfs.Log is shown below

    root@tisbc:~/BEL_PCIe#./load.sh
    [  168.975213] dspc868x_pcie_ep: Found TI667x PCIe EP @0xde81f000
    [  168.981143] dspc868x_pcie_ep: detect 1 DSP in this system
    [  168.986707] dspc868x_pcie_ep 0000:04:00.0: DSPC868x probe
    [  168.992308] dspc868x_pcie_ep 0000:04:00.0: Major 246 Minor 0 assigned
    [  168.998932] dspc868x_pcie_ep 0000:04:00.0: Added device to the sys file system
    [  169.006226] dspc868x_pcie_ep 0000:04:00.0:   BAR Configuration:
    [  169.012121] dspc868x_pcie_ep 0000:04:00.0:   Start           |       Length          |       Flags
    [  169.018538] dspc868x_pcie_ep 0000:04:00.0:   0x52000000      |       00004096        |       0x00040200
    [  169.025817] dspc868x_pcie_ep 0000:04:00.0:   0x51800000      |       04194304        |       0x00042208
    [  169.033154] dspc868x_pcie_ep 0000:04:00.0:   0x51c00000      |       04194304        |       0x00042208
    [  169.040434] dspc868x_pcie_ep 0000:04:00.0:   0x51000000      |       08388608        |       0x00042208
    [  169.047709] dspc868x_pcie_ep 0000:04:00.0: TI667X registers mapped to 0xe08bc000
    [  169.055167] dspc868x_pcie_ep 0000:04:00.0: Device operates in little endian mode

    I verified the same with the following command

    "ls /dev/dspc_868x_0"

    root@tisbc:~/BEL_PCIe# ls /dev/dspc868x_dsp_0
    /dev/dspc868x_dsp_0

    When i run the dsp_loader application i am getting the following error which is same as previously i mentioned in the above post
    This error occurs when reading data through virtual memory pointer (allocated by mmap function) in pcie_drv.c (ti667x_ep_init_bar function)

    ./dsp_loader query list
    [  178.457140] Unhandled fault: synchronous external abort (0x1210) at 0xb6f8e300
    Bus error
    2017 Jun 22 01:32:58 tisbc [  178.457140] Unhandled fault: synchronous external abort (0x1210) at 0xb6f8e300

    You can also simulate the above issues by connecting K2 evm and K1 evm thro PCIe.

    Herewith i have attached the modified code.

    Kindly suggest on the virtual memory pointer access.

    Regards,

    S.Sivanantham6354.BEL_PCIe_boot_code.zip

  • Hi, Sivanantham,

    My thought is that if you can access the address using devmem2, may be a comparison to devmem2 will get some helpful info.

    Rex
  • Hi,

    Thanks for the input. I have gone through the code. I think offset is the problem when i made offset as 0. It performs read and write  correctly for few words. But Bulk read and write creates bit errors. Is there any thing else to be taken care  related to  virtual memory cache or virtual page settings?


    Regards,

    S.Sivanantham

  • Hi,

    In addition to the above, Is there any limitation for virtual memory page size? because devmem2.c uses 4096 bytes whereas my code has length as 4KB (bar 0 application), 4MB (bar1 L2SRAM), 4MB (Bar2 MSMC ram),8MB (Bar3 DDR3) respectively. I compared both codes i found the above difference.

    Kindly clarify.

    Regards,

    S.Sivanantham

  • Hi,

    Now i am able to boot the processor thro PCIe. I opened the driver with /dev/mem  as per devmem2.c.

    i assigned the bar and length then it start working. I dont know why /dev/dspc_868x_dsp0 path is not working. I am investigating on that.

    Please share if you have any points on this.

    Regards,

    S.Sivanantham

  • Hi, Sivanatham,

    Glad you have it resolved. My take is you are accessing the physical memory and /dev/mem makes sense.

    Rex