Rockchip · AI & Linux Hub

Linux と起動

Rockchip Linux CMA: ドライバー フレームワーク、予約メモリ、およびデバッグ

完全な CMA 構成、DTS、デバイス固有の領域、debugfs ノード、フレームワーク図、およびブート ログ。

ArmSoM の適用性とソース

プラットフォームのリファレンスは、中国V1.1.0から翻訳されたArmSoMを適応させる。 ソーススコープ: RK3588/RK3568/RK3399/RK3288/RK3368/RV1126/PX30、Linux 4.4/ 4.19/ 5.10。 中国語(簡体)、ロシア語(繁体)、ドイツ語(繁体)の中国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(繁体)、韓国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(繁体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、韓国語(簡体)、中国語(簡体)、中国語(簡体字)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、韓国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、中国語(簡体)、韓国語)、韓国語(簡体字、韓国語(簡体字、中国語(簡体)、繁体)、繁体)、中国語(簡体字、繁体字、繁体字、中国語(簡体字、繁体)、繁体字、繁体字、繁体字、中国語(簡体字、中国語(繁体)、繁体字、中国語(簡体字、中国語(簡体字、繁体字、中国語(簡体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体)、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁体字、繁 ドイツの英語記事のイメージURLを再利用します。 特定のArmSoMボード、SDK/BSPまたはドライバーの組み合わせが確認またはハードウェアテスト済みではありません。 実際の SoC、ボードメモリレイアウト、SDK/BSP、カーネル設定、ドライバ実装をチェックします。 コード、アドレス、ログ、測定はArmSoMテスト結果ではなく、ソース例です。

編集メモ · ArmSoM ドキュメント · Rockchip Linux

唯一のフレームワーク図は中国語の PDF ページ 4 からのものです。英語の原文は存在しません。

ソースSoC ソースカーネル
RK3588 / RK3568 / RK3399 / RK3288 / RK3368 / RV1126 / PX30 Linux 4.4 / 4.19 / 5.10

1. . CMA ドライバーフレームワーク {#1-cma-driver-framework}

CMA ドライバーフレームワーク(中国原本 PDF, ページ 4)

CMA ドライバー フレームワーク (オリジナルの中国語 PDF、4 ページ)

CMA ドライバーには 3 つの主要な部分があります。

  1. size@address

パラメータは、ソース BSP の優先順位 DTS > CMDLINE > DEFCONFIG の 3 つの方法で指定できます。有効な DTS ノードによって最終的な構成が決まります。それ以外の場合、ドライバーはコマンド ラインで cma=size@base をチェックし、次にソース defconfig の説明で言及されている 4 つのマクロ定義をチェックします。

  1. reserved cma_areas[]

DTS は複数の CMA ノードを構成できます。 cmdline と defconfig はデフォルト ノードのみを定義できます。すべての予約領域はグローバル cma_areas[] に保存されます。

  1. active cma_area

パラメータの解析とメモリ予約はカーネル setup_arch 中に終了します。アクティベーションは、すべてのドライバーの前に、core_initcall を通じて呼び出されます。主に CMA エリアのビットマップを作成し、CMA ページをバディ システムに追加します。

2. . 保存メモリの割り当て {#2-allocating-reserved-memory}

2.1 方法 1: menuconfig を通じて 16MByte を予約する {#21-method-1-reserve-16mbyte-through-menuconfig}

CONFIG_DMA_CMA=y
CONFIG_CMA_SIZE_MBYTES=16
CONFIG_CMA_SIZE_SEL_MBYTES=y

2.2 方法 2: DTS 予約メモリ ノード {#22-method-2-the-dts-reserved-memory-node}

Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt を参照してください。

reserved-memory {
    #address-cells = <1>;
    #size-cells = <1>;
    ranges;

    /* global autoconfigured region for contiguous allocations */
    linux,cma {
        compatible = "shared-dma-pool";
        reusable;
        size = <0x1000000>;
        alignment = <0x2000>;
        linux,cma-default;
    };
};

3. . デバイス固有のメモリを割り当てる {#3-allocating-device-specific-memory}

上記のメソッドは、システム共有メモリ領域を割り当てます。複数のデバイスで割り当てと解放を繰り返すと、断片化する可能性があります。一部のペリフェラルは大きな連続した CMA ブロックを必要とし、断片化によって割り当てが妨げられると誤動作する可能性があります。このようなデバイスには別の領域を割り当てます。

3.1 方法 1: システムが借用できる別のリージョン {#31-method-1-a-separate-region-that-the-system-can-borrow}

reserved-memory {
    #address-cells = <1>;
    #size-cells = <1>;
    ranges;

    cma_region: region@88000000 {
        compatible = "shared-dma-pool";
        reusable;
        reg = <0x88000000 0x1800000>;
    };
};

of_reserved_mem_device_init を通じて、この領域を特定のデバイスに割り当てます。

#include <linux/of_reserved_mem.h>
static inline int of_reserved_mem_device_init(struct device *dev)
{
    return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
}

3.2 方法 2: メンブロック領域 {#32-method-2-a-memblock-region}

reserved-memory {
    #address-cells = <1>;
    #size-cells = <1>;
    ranges;

    display_reserved: framebuffer@78000000 {
        reg = <0x78000000 0x800000>;
    };
};

/sys/kernel/debug/memblock/reserved を通じて割り当てを検査します。

表示されているメンブロック範囲はマージされ、統合されています。

この割り当ては、カーネル ページ管理によって管理されません。情報源によると、ユーザーは必要に応じて「ページスケールリスト」を作成する必要があるという。この用語は明確になるまで保留されます。

console:/sys/kernel/debug/cma # cat /sys/kernel/debug/memblock/reserved
    0: 0x60004000..0x60007fff
    1: 0x60100000..0x61404a07
    2: 0x62e00000..0x62eeffff
    3: 0x68300000..0x6830d07f
...

4. . 保存メモリのデバッグ {#4-debugging-reserved-memory}

4.1 CMA デバッグ設定スイッチ {#41-cma-debug-configuration-switches}

CONFIG_CMA_DEBUGFS=y #打开调试文件节点
CONFIG_CMA_DEBUG=y #打印CMA日志信息

設定メモ: CONFIG_CMA_DEBUGFS=y はデバッグ ノードを作成します。 CONFIG_CMA_DEBUG=y は CMA ログを出力します。

4.2 CMA デバッグ ノード {#42-cma-debug-nodes}

console:/sys/kernel/debug/cma # ls
cma-region@8800 cma-reserved
console:/sys/kernel/debug/cma/cma-reserved # ls
alloc bitmap free order_per_bit used
base_pfn count maxchunk

alloc: 現在の CMA 領域からメモリをページ単位で割り当てます。

bitmap: 各ページの割り当て状態。 1 は割り当て済みを意味し、0 は未割り当てを意味します。

free: 現在の CMA 領域のメモリをページ単位で解放します。

order_per_bit: 1 ビットで表されるページ数の順序。

used: 現在割り当てられているページ数。

base_pfn: 現在の CMA 領域の最初のページのページ フレーム番号。

maxchunk: 現在の CMA 領域内の連続する空きページの最大数。

5. .. ブート時のメモリ予約メッセージ {#5-memory-reservation-messages-during-boot}

[ 0.000000] Booting Linux on physical CPU 0xf00
[ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[ 0.000000] CPU: div instructions available: patching division code
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: Rockchip RK3126 bnd-d708 board
[ 0.000000] earlycon: uart8250 at MMIO32 0x20068000 (options '')
[ 0.000000] bootconsole [uart8250] enabled
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] Reserved memory: created CMA memory pool at 0x88000000, size 24 MiB
[ 0.000000] OF: reserved mem: initialized node region@88000000, compatible id shared-dma-pool
[ 0.000000] cma: Reserved 16 MiB at 0x9f000000
[ 0.000000] On node 0 totalpages: 258560
[ 0.000000] Normal zone: 1728 pages used for memmap
[ 0.000000] Normal zone: 0 pages reserved
[ 0.000000] Normal zone: 193024 pages, LIFO batch:63
[ 0.000000] HighMem zone: 65536 pages, LIFO batch:15
[ 0.000000] psci: probing for conduit method from DT.
[ 0.000000] psci: PSCIv65535.65535 detected in firmware.
[ 0.000000] psci: Using standard PSCI v0.2 function IDs
[ 0.000000] psci: MIGRATE_INFO_TYPE not supported.
[ 0.000000] psci: SMC Calling Convention v1.0
[ 0.000000] percpu: Embedded 17 pages/cpu s38924 r8192 d22516 u69632
[ 0.000000] pcpu-alloc: s38924 r8192 d22516 u69632 alloc=17*4096
[ 0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 256832
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 960940K/1034240K available (11264K kernel code, 985K rwdata, 3180K rodata, 1024K init, 2104K bss, 32340K reserved, 40960K cma-reserved, 245024K highmem)
...

最初の CMA 領域の割り当てが成功しました。

[ 0.000000] Reserved memory: created CMA memory pool at 0x88000000, size 24 MiB
[ 0.000000] OF: reserved mem: initialized node region@88000000, compatible id shared-dma-pool

2 番目の CMA 領域の割り当てが成功しました (システムのデフォルト):

[ 0.000000] cma: Reserved 16 MiB at 0x9f000000

このトピックを詳しく見る → · 学習ガイド →