3

I am trying to develop a simple character device driver that access the reserved memory region as described in the site: http://www.wiki.xilinx.com/Linux+Reserved+Memory

/* Get reserved memory region from Device-tree */

np = of_parse_phandle(dev->of_node, "memory-region", 0);

if (!np) {
    dev_err(dev, "No %s specified\n", "memory-region");
    goto error1;
}

rc = of_address_to_resource(np, 0, &r);

if (rc) {
  dev_err(dev, "No memory address assigned to the region\n");  
  goto error1;
}

lp->paddr = r.start;
lp->vaddr = memremap(r.start, resource_size(&r), MEMREMAP_WB);

dev_info(dev, "Allocated reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX\n", (u64)lp->vaddr, lp->paddr);

The site does not give any information regarding lp->paddr and lp->vaddr

What is the datatype of lp ?

Abdullah
  • 2,015
  • 2
  • 20
  • 29
Chaithanya
  • 31
  • 4
  • lp is object of struct lp_desc. paddr and vaddr represents the physical and virtual address respectively. In your case, lp structure not required. – Rajeshkumar Aug 09 '17 at 15:05
  • They have quite outdated code there (it would work on modern kernels, though not so readable). First of all, you might check `struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);` which more self-explainable. `r->start` will point to the start physical address of memory resource. Second, `memremap()` creates a window for this resource in virtual address space. So, types of `paddr` and `vaddr` are `phys_addr_t` (or `resource_size_t` that is derivative from `phys_addr_t`) and `void *` respectively. Answering to the question, type of `lp` doesn't matter, it's a container. – 0andriy Aug 13 '17 at 16:47

1 Answers1

0

I think "lp" is not a predefined variable. I have declared my own struct with vaddr and paddr as struct elements and defined lp as the struct variable and it worked.

static struct addr_map
{
   __u32 paddr,vaddr;
   ssize_t size;
}*lp;
Chaithanya
  • 31
  • 4