Search code examples
linux-device-driverdevice-tree

how to set max-functions in pcie device tree? (about the syntax "max-functions = /bits/ 8 <8>;")


In linux-6.15.68, in Documentation/devicetree/bindings/pci/rockchip-pcie-ep.txt, I see these explanations. (please see the marked line.)

Optional Property:
- num-lanes: number of lanes to use
- max-functions: Maximum number of functions that can be configured (default 1).


pcie0-ep: pcie@f8000000 {
    compatible = "rockchip,rk3399-pcie-ep";
    #address-cells = <3>;
    #size-cells = <2>;
    rockchip,max-outbound-regions = <16>;
    clocks = <&cru ACLK_PCIE>, <&cru ACLK_PERF_PCIE>,
         <&cru PCLK_PCIE>, <&cru SCLK_PCIE_PM>;
    clock-names = "aclk", "aclk-perf",
              "hclk", "pm";
    max-functions = /bits/ 8 <8>;                     // <---- see this line
    num-lanes = <4>;
    reg = <0x0 0xfd000000 0x0 0x1000000>, <0x0 0x80000000 0x0 0x20000>;

<skip>

In the example dts, what does "max-functions = /bins/ 8 <8>;" mean?
I found in Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml, it says

  max-functions:
    $ref: /schemas/types.yaml#/definitions/uint32
    description: maximum number of functions that can be configured

But I don't know how to read the $ref document.

ADD

I found this.

  • The storage size of an element can be changed using the /bits/ prefix. The /bits/ prefix allows for the creation of 8, 16, 32, and 64-bit elements. The resulting array will not be padded to a multiple of the default 32-bit element size.

    e.g. interrupts = /bits/ 8 <17 0xc>; e.g. clock-frequency = /bits/ 64 <0x0000000100000000>;

Does this mean 17 and 0xc are both 8-bit variables and when it is compiled to dtb, it keep the 8-bit format? The linux code will analyze the dtb file, then does the dtb contains the format information too?


Solution

  • The Device Tree Compiler v1.4.0 onwards supports some extra syntaxes for specifying property values that are not present in The Devicetree Specification up to at least version v0.4-rc1. These extra property value syntaxes are documented in the Device Tree Compiler's Device Tree Source Format and include:

    • A number in an array between angle brackets can be specified as a character literal such as 'a', '\r' or '\xFF'.
    • The size of elements in an array between angle brackets can be set using the prefix /bits/ and a bit-width of 8, 16, 32, or 64, defaulting to 32-bit integers.

    The binary Flattened Devicetree (DTB) Format contains no explicit information on the type of a property value. A property value is just a string of bytes. Numbers (and character literals) between angle brackets in the source are converted to bytes in big-endian byte order in accordance with the element size in bits divided by 8. For example:

    1. <0x11 'a'> is encoded in the same way as the bytestring [00 00 00 11 00 00 00 61].
    2. /bits/ 8 <17 0xc> is encoded in the same way as the bytestring [11 0c].

    It is up to the reader of the property value to "know" what type it is expecting. For example, the Rockchip AXI PCIe endpoint controller driver in the Linux kernel ("drivers/pci/controller/pcie-rockchip-ep.c") "knows" that the "max-functions" property should have been specified as a single byte and attempts to read it using the statement err = of_property_read_u8(dev->of_node, "max-functions", &ep->epc->max_functions);. (It is probably encoded as a single byte property for convenience so that it can be copied directly into the u8 max_functions member of a struct pci_epc.)