• early_init_dt_scan_memory


    /**
     * early_init_dt_scan_memory - Look for and parse memory nodes
     */
    int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
                         int depth, void *data)
    {
        const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
        const __be32 *reg, *endp;
        int l;
        bool hotpluggable;

        /* We are scanning "memory" nodes only */
        if (type == NULL || strcmp(type, "memory") != 0)
            return 0;

        reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
        if (reg == NULL)
            reg = of_get_flat_dt_prop(node, "reg", &l);
        if (reg == NULL)
            return 0;

        endp = reg + (l / sizeof(__be32));
        hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL);

        pr_debug("memory scan node %s, reg size %d,\n", uname, l);

        while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
            u64 base, size;

            base = dt_mem_next_cell(dt_root_addr_cells, ®);
            size = dt_mem_next_cell(dt_root_size_cells, ®);

            if (size == 0)
                continue;
            pr_debug(" - %llx ,  %llx\n", (unsigned long long)base,
                (unsigned long long)size);

            early_init_dt_add_memory_arch(base, size);

            if (!hotpluggable)
                continue;

            if (early_init_dt_mark_hotplug_memory_arch(base, size))
                pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n",
                    base, base + size);
        }

        return 0;
    }

    void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
    {
        const u64 phys_offset = MIN_MEMBLOCK_ADDR;

        if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
            pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
                base, base + size);
            return;
        }

        if (!PAGE_ALIGNED(base)) {
            size -= PAGE_SIZE - (base & ~PAGE_MASK);
            base = PAGE_ALIGN(base);
        }
        size &= PAGE_MASK;

        if (base > MAX_MEMBLOCK_ADDR) {
            pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
                    base, base + size);
            return;
        }

        if (base + size - 1 > MAX_MEMBLOCK_ADDR) {
            pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
                    ((u64)MAX_MEMBLOCK_ADDR) + 1, base + size);
            size = MAX_MEMBLOCK_ADDR - base + 1;
        }

        if (base + size < phys_offset) {
            pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
                   base, base + size);
            return;
        }
        if (base < phys_offset) {
            pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
                   base, phys_offset);
            size -= phys_offset - base;
            base = phys_offset;
        }
        memblock_add(base, size);
    }

    /**
     * memblock_add - add new memblock region
     * @base: base address of the new region
     * @size: size of the new region
     *
     * Add new memblock region [@base, @base + @size) to the "memory"
     * type. See memblock_add_range() description for mode details
     *
     * Return:
     * 0 on success, -errno on failure.
     */
    int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
    {
        phys_addr_t end = base + size - 1;

        memblock_dbg("memblock_add: [%pa-%pa] %pS\n",
                 &base, &end, (void *)_RET_IP_);

        return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0);
    }

        /*
         * the memory node will be overwritten in uboot,
         * here is just the default value.
         */
        memory {
            device_type = "memory";
            reg = <0x00200000 0x09e00000>;
        };

    cat /proc/cat iomem   System RAM

  • 相关阅读:
    2022千元无线蓝牙耳机,音质超高的千元蓝牙耳机品牌
    在使用SpringBoot时遇到的异常总结(持续更新...)
    【重拾C语言】三、分支程序设计(双分支和单分支程序设计、逻辑判断、多分支程序设计、枚举类型表示;典型例题:判断闰年和求一元二次方程根)
    16、window11+visual studio 2022+cuda+ffmpeg进行拉流和解码(RTX3050)
    吴恩达2022机器学习专项课程(一) 6.2 逻辑回归&第三周课后实验:Lab2逻辑回归
    数据仓库的实际应用示例-广告投放平台为例
    【MATLAB高级编程】第一篇 | 矩阵操作
    利用h5py加速数据集读取
    nfs实现共享目录对于集群高可用风险,nfs客户端容易卡死
    Gorm 快速入门:高效掌握 MySQL 数据库操作的实用指南
  • 原文地址:https://blog.csdn.net/wmzjzwlzs/article/details/128009501