Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Dec 2017 15:00:22 -0500
From:      Lee D <embaudarm@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   How do I alloc multiple memory regions specified in a device tree?
Message-ID:  <CANC_bnMjPzSKM0q1__or=cTrvoxnM_LXo-avFYgbUZVeZPT9wg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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@40000000 {
    device_type = "soc";
    compatible = "simple-bus";
    #address-cells = <0x1>;
    #size-cells = <0x1>;
    ranges = <0x0 0x40000000 0x5000000>;

    my_lcd@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANC_bnMjPzSKM0q1__or=cTrvoxnM_LXo-avFYgbUZVeZPT9wg>