How do I alloc multiple memory regions specified in a device tree?

Lee D embaudarm at gmail.com
Sun Dec 17 20:01:04 UTC 2017


Hi everyone.

I have a device driver that must access registers in multiple memory
ranges.  How do I pull those values out of the device tree?

This is for a custom ARM embedded board.

bus_alloc_resource_any() works, but only for the first memory range.
The second time I call it, it crashes the kernel.

If I alloc the same memory resources by hardcoding the values in calls
to bus_alloc_resource(), it works.

The technique of calling bus_alloc_resource_any() multiple times is
used in src/sys/dev/sdhci/sdhci_fdt.c, but I can't get it to work.

Here is a snippet from my device tree:

...
  fabric at 40000000 {
    device_type = "soc";
    compatible = "simple-bus";
    #address-cells = <0x1>;
    #size-cells = <0x1>;
    ranges = <0x0 0x40000000 0x5000000>;

    my_lcd at 3C00000 {
      status = "okay";
      compatible = "xlnx,my_lcd";
      reg = <0x3C00000 0x1000
             0x400000 0x1000
             0x3000000 0x1000>;
      interrupts = <0x0 0x1d 0x1>;
      interrupt-parent = <0x1>;
    };
...

Here is my driver code from my_lcd_attach:

  rid=0;
  sc->lcd_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);

  if (sc->lcd_mem_res == NULL) {
    my_lcd_detach(dev);
    return (ENOMEM);
  }

  rid=0;
  sc->dma_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);

  if (sc->dma_mem_res == NULL) {
    my_lcd_detach(dev);
    return (ENOMEM);
  }

Thank you.


More information about the freebsd-hackers mailing list