Trying to write/read value at PCI BAR address from Kernel Space

Robert Clove cloverobert at gmail.com
Tue Apr 28 05:12:51 EDT 2015


retval = pci_enable_device(dev);
    if (retval)
    {
        printk(KERN_ERR "Unable to enable this PCI device\n");
        return retval;
    }
    else
    {
        printk(KERN_INFO "PCI device enabled\n");
    }

    display_pci_config_space(dev);

    retval = pci_request_regions(dev, "expt_pci");
    if (retval)
    {
        printk(KERN_ERR "Unable to acquire regions of this PCI device\n");
        pci_disable_device(dev);
        return retval;
    }
    else
    {
        printk(KERN_INFO "PCI device regions acquired\n");
    }

    if ((dpv->reg_base = ioremap(pci_resource_start(dev, 2),
pci_resource_len(dev, 2))) == NULL)
    {
        printk(KERN_ERR "Unable to map registers of this PCI device\n");
        pci_release_regions(dev);
        pci_disable_device(dev);
        return -ENODEV;
    }
    printk(KERN_INFO "Register Base: %p\n", dpv->reg_base);

    printk(KERN_INFO "IRQ: %u\n", dev->irq);

    printk(KERN_INFO "dpv->reg_base value is: %x\n",dpv->reg_base);

    pci_set_drvdata(dev, dpv);

printk(KERN_INFO "PCI device registered\n");

    printk(KERN_INFO "Expt: In write\n");
    //iowrite8(MY_BYTE,dev->resource[0].start);
    uint32_t a = 0x01;
    uint32_t addr;
    iowrite8(a, dpv->reg_base);
    printk("value written is %d\n",a);
    printk(KERN_INFO "Expt: In read\n");
    //addr = ioread8(dev->resource[0].start );
    addr = ioread8(dpv->reg_base );
    printk("Value read is %d\n",addr);

THE OUTPUT i am getting is this:

[ 6482.783371] PCI device regions acquired
[ 6482.795801] Register Base: ffffc90015b00000
[ 6482.795803] IRQ: 16
[ 6482.795804] dpv->reg_base value is: 15b00000
[ 6482.795805] PCI device registered



*[ 6482.795806] Expt: In write[ 6482.795807] value written is 1[
6482.795808] Expt: In read[ 6482.795810] Value read is 0*
[ 6482.795836] Expt PCI driver registered


Can you tell me what am i doing wrong?

Regards



On Tue, Apr 28, 2015 at 10:36 AM, Sudip Mukherjee <
sudipm.mukherjee at gmail.com> wrote:

> On Tue, Apr 28, 2015 at 10:25 AM, Robert Clove <cloverobert at gmail.com>
> wrote:
> > Hi,
> >
> > I am trying to write and read PCI BAR address but not getting the
> expected
> > output.
> > I am using the ioremap api to get the address.
> > Any leads will be fruit full.
>
> can you please post what you have tried till now...
>
> regards
> sudip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150428/96183808/attachment-0001.html 


More information about the Kernelnewbies mailing list