> For the complete documentation index, see [llms.txt](https://explore-vineeth.gitbook.io/mywiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://explore-vineeth.gitbook.io/mywiki/how-to/access-fifo-registers-as-memory.md).

# Access FIFO Registers as memory

When there are FIFO registers spanning length over 256bytes , it can be a requirement  of the IP to consider this space as memory mapped io.&#x20;

### The steps include

* Map the required register space as sram region
* access the sram node in the ip node
* gen sram\_pool in the driver probe
* pool alloc for the generated sram\_pool

#### DT node&#x20;

```clike
  sram1: sram-reserved@80600040000 {
        compatible = "mmio-sram";
        #address-cells = <2>;
        #size-cells = <2>;
    reg = <0x806 0x00040000 0x00 0xFFFF>;
  };
  mydev:mydev@80600050000 {
          compatible = "cmd,mydev-tmp";
    reg = <0x806 0x00050000 0x00 0x10000>;
    adi,sram = <&sram1>;
  };
```

#### Linux probe code snippet

```c
struct gen_pool *sram_pool;
void __iomem *fifo_base;

/*·Mapping·Funneled·FIFO·as·SRAM·Memory·*/
sram_pool = of_gen_pool_get((&pdev->dev)->of_node, "adi,sram", 0);
if (!sram_pool)·{
    dev_err(&pdev->dev, "Unable·to·get·sram·pool!\n");
    return -ENODEV;
}

/*·Get·the·allocated·virtual·memory·from·sram·pool·*/
fifo_base = (void *)gen_pool_alloc(sram_pool, PAGE_SIZE);
if (!fifo_base) {
    dev_err(&pdev->dev, "Failed·to·alloc·sram·from·sram·pool!\n");
    return PTR_ERR(fifo_base);
}

/* Read the contents. */
if (fifo_base)
    memcpy(buf, fifo_base, size);

/* Free the allocated pool */
if (sram_pool)
    gen_pool_free(sram_pool, (unsigned long)fifo_base, PAGE_SIZE);
```

#### References

<https://wiki.analog.com/resources/tools-software/linuxdsp/docs/linux-kernel-and-drivers/sram>
