• 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

  • 相关阅读:
    【Leetcode】1223. Dice Roll Simulation
    shell脚本的流程控制
    macOS Monterey12.5.1 配置vim
    新手入门MyBatis的问题及如何解决?
    C++个人财务管理系统
    systemd 服务脚本编写与管理
    【二分】Pythagorean Triples—CF1487D
    老司机带带你,教你学会Java中又骚又暴力的“反射”技术
    yolov8 ValueError和RuntimeError
    【Stable Diffusion】(基础篇三)—— 关键词和参数设置
  • 原文地址:https://blog.csdn.net/wmzjzwlzs/article/details/128009501